1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
36 (eval-when-compile (require 'cl))
40 (defvoo nndoc-article-type 'guess
42 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
43 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
44 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
46 (defvoo nndoc-post-type 'mail
47 "*Whether the nndoc group is `mail' or `post'.")
49 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
50 "Hook run after opening a document.
51 The default function removes all trailing carriage returns
54 (defvar nndoc-type-alist
56 (article-begin . "^\^A\^A\^A\^A\n")
57 (body-end . "^\^A\^A\^A\^A\n"))
59 (article-begin . "^From - "))
61 (article-begin . "^Path:"))
63 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
64 (body-end-function . nndoc-rnews-body-end))
66 (article-begin-function . nndoc-mbox-article-begin)
67 (body-end-function . nndoc-mbox-body-end))
69 (article-begin . "\^_\^L *\n")
71 (body-begin-function . nndoc-babyl-body-begin)
72 (head-begin-function . nndoc-babyl-head-begin))
74 (article-begin . "^-+ \\(Start of \\)?forwarded message.*\n+")
75 (body-end . "^-+ End \\(of \\)?forwarded message.*$")
76 (prepare-body-function . nndoc-unquote-dashes))
78 (article-begin . "^--.*\n+")
80 (prepare-body-function . nndoc-unquote-dashes))
82 (article-begin . "^ \\*")
83 (body-end . "^\t------*[ \t]^*\n^ \\*")
86 (generate-head-function . nndoc-generate-clari-briefs-head)
87 (article-transform-function . nndoc-transform-clari-briefs))
90 (head-begin . "^ ?\n")
94 (subtype digest guess))
96 (generate-head-function . nndoc-generate-mime-parts-head)
97 (article-transform-function . nndoc-transform-mime-parts))
99 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
100 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
101 (prepare-body-function . nndoc-unquote-dashes)
102 (body-end-function . nndoc-digest-body-end)
104 (body-begin . "^ *\n")
105 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
106 (subtype digest guess))
108 (article-begin . "^------------------------------*[\n \t]+")
110 (body-end-function . nndoc-digest-body-end)
111 (body-begin . "^ ?$")
112 (file-end . "^End of")
113 (prepare-body-function . nndoc-unquote-dashes)
114 (subtype digest guess))
116 (article-begin . "^\\\\\\\\\n")
117 (head-begin . "^Paper.*:")
118 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
120 (body-end . "-------------------------------------------------")
121 (file-end . "^Title: Recent Seminal")
122 (generate-head-function . nndoc-generate-lanl-gov-head)
123 (article-transform-function . nndoc-transform-lanl-gov-announce)
124 (subtype preprints guess))
126 (article-begin . "^\n")
127 (body-end-function . nndoc-rfc822-forward-body-end-function))
139 (defvoo nndoc-file-begin nil)
140 (defvoo nndoc-first-article nil)
141 (defvoo nndoc-article-begin nil)
142 (defvoo nndoc-head-begin nil)
143 (defvoo nndoc-head-end nil)
144 (defvoo nndoc-file-end nil)
145 (defvoo nndoc-body-begin nil)
146 (defvoo nndoc-body-end-function nil)
147 (defvoo nndoc-body-begin-function nil)
148 (defvoo nndoc-head-begin-function nil)
149 (defvoo nndoc-body-end nil)
150 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
151 ;; following items. ARTICLE acts as the association key and is an ordinal
152 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
153 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
154 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
155 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
156 ;; generation, respectively. Other headers usually follow directly from the
157 ;; buffer. Value `nil' means no insert.
158 (defvoo nndoc-dissection-alist nil)
159 (defvoo nndoc-prepare-body-function nil)
160 (defvoo nndoc-generate-head-function nil)
161 (defvoo nndoc-article-transform-function nil)
162 (defvoo nndoc-article-begin-function nil)
164 (defvoo nndoc-status-string "")
165 (defvoo nndoc-group-alist nil)
166 (defvoo nndoc-current-buffer nil
167 "Current nndoc news buffer.")
168 (defvoo nndoc-address nil)
170 (defconst nndoc-version "nndoc 1.0"
175 ;;; Interface functions
177 (nnoo-define-basics nndoc)
179 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
180 (when (nndoc-possibly-change-buffer newsgroup server)
182 (set-buffer nntp-server-buffer)
185 (if (stringp (car articles))
188 (when (setq entry (cdr (assq (setq article (pop articles))
189 nndoc-dissection-alist)))
190 (insert (format "221 %d Article retrieved.\n" article))
191 (if nndoc-generate-head-function
192 (funcall nndoc-generate-head-function article)
193 (insert-buffer-substring
194 nndoc-current-buffer (car entry) (nth 1 entry)))
195 (goto-char (point-max))
196 (unless (eq (char-after (1- (point))) ?\n)
198 (insert (format "Lines: %d\n" (nth 4 entry)))
201 (nnheader-fold-continuation-lines)
204 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
205 (nndoc-possibly-change-buffer newsgroup server)
207 (let ((buffer (or buffer nntp-server-buffer))
208 (entry (cdr (assq article nndoc-dissection-alist)))
213 (if (stringp article)
215 (insert-buffer-substring
216 nndoc-current-buffer (car entry) (nth 1 entry))
219 (insert-buffer-substring
220 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
222 (when nndoc-prepare-body-function
223 (funcall nndoc-prepare-body-function))
224 (when nndoc-article-transform-function
225 (funcall nndoc-article-transform-function article))
228 (deffoo nndoc-request-group (group &optional server dont-check)
232 ((not (nndoc-possibly-change-buffer group server))
233 (nnheader-report 'nndoc "No such file or buffer: %s"
236 (nnheader-report 'nndoc "Selected group %s" group)
238 ((zerop (setq number (length nndoc-dissection-alist)))
239 (nndoc-close-group group)
240 (nnheader-report 'nndoc "No articles in group %s" group))
242 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
244 (deffoo nndoc-request-type (group &optional article)
245 (cond ((not article) 'unknown)
246 (nndoc-post-type nndoc-post-type)
249 (deffoo nndoc-close-group (group &optional server)
250 (nndoc-possibly-change-buffer group server)
251 (and nndoc-current-buffer
252 (buffer-name nndoc-current-buffer)
253 (kill-buffer nndoc-current-buffer))
254 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
256 (setq nndoc-current-buffer nil)
257 (nnoo-close-server 'nndoc server)
258 (setq nndoc-dissection-alist nil)
261 (deffoo nndoc-request-list (&optional server)
264 (deffoo nndoc-request-newgroups (date &optional server)
267 (deffoo nndoc-request-list-newsgroups (&optional server)
271 ;;; Internal functions.
273 (defun nndoc-possibly-change-buffer (group source)
276 ;; The current buffer is this group's buffer.
277 ((and nndoc-current-buffer
278 (buffer-name nndoc-current-buffer)
279 (eq nndoc-current-buffer
280 (setq buf (cdr (assoc group nndoc-group-alist))))))
281 ;; We change buffers by taking an old from the group alist.
282 ;; `source' is either a string (a file name) or a buffer object.
284 (setq nndoc-current-buffer buf))
285 ;; It's a totally new group.
286 ((or (and (bufferp nndoc-address)
287 (buffer-name nndoc-address))
288 (and (stringp nndoc-address)
289 (file-exists-p nndoc-address)
290 (not (file-directory-p nndoc-address))))
291 (push (cons group (setq nndoc-current-buffer
293 (concat " *nndoc " group "*"))))
295 (setq nndoc-dissection-alist nil)
297 (set-buffer nndoc-current-buffer)
298 (mm-enable-multibyte)
300 (if (stringp nndoc-address)
301 (nnheader-insert-file-contents nndoc-address)
302 (insert-buffer-substring nndoc-address))
303 (run-hooks 'nndoc-open-document-hook))))
304 ;; Initialize the nndoc structures according to this new document.
305 (when (and nndoc-current-buffer
306 (not nndoc-dissection-alist))
308 (set-buffer nndoc-current-buffer)
310 (if (eq nndoc-article-type 'mime-parts)
311 (nndoc-dissect-mime-parts)
312 (nndoc-dissect-buffer))))
313 (unless nndoc-current-buffer
314 (nndoc-close-server))
315 ;; Return whether we managed to select a file.
316 nndoc-current-buffer))
319 ;;; Deciding what document type we have
322 (defun nndoc-set-delims ()
323 "Set the nndoc delimiter variables according to the type of the document."
324 (let ((vars '(nndoc-file-begin
326 nndoc-article-begin-function
327 nndoc-head-begin nndoc-head-end
328 nndoc-file-end nndoc-article-begin
329 nndoc-body-begin nndoc-body-end-function nndoc-body-end
330 nndoc-prepare-body-function nndoc-article-transform-function
331 nndoc-generate-head-function nndoc-body-begin-function
332 nndoc-head-begin-function)))
334 (set (pop vars) nil)))
336 ;; Guess away until we find the real file type.
337 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
339 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
340 ;; Set the nndoc variables.
342 (set (intern (format "nndoc-%s" (caar defs)))
345 (defun nndoc-guess-type (subtype)
346 (let ((alist nndoc-type-alist)
347 results result entry)
348 (while (and (not result)
349 (setq entry (pop alist)))
350 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
351 (goto-char (point-min))
352 ;; Remove blank lines.
353 (while (eq (following-char) ?\n)
355 (when (numberp (setq result (funcall (intern
356 (format "nndoc-%s-type-p"
358 (push (cons result entry) results)
360 (unless (or result results)
361 (error "Document is not of any recognized type"))
364 (cadar (sort results 'car-less-than-car)))))
367 ;;; Built-in type predicates and functions
370 (defun nndoc-mbox-type-p ()
371 (when (looking-at message-unix-mail-delimiter)
374 (defun nndoc-mbox-article-begin ()
375 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
376 (goto-char (match-beginning 0))))
378 (defun nndoc-mbox-body-end ()
383 (and (re-search-backward
384 (concat "^" message-unix-mail-delimiter) nil t)
386 (search-forward "\n\n" beg t)
388 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
389 (setq len (string-to-int (match-string 1)))
390 (search-forward "\n\n" beg t)
391 (unless (= (setq len (+ (point) len)) (point-max))
392 (and (< len (point-max))
394 (looking-at message-unix-mail-delimiter)))))
397 (defun nndoc-mmdf-type-p ()
398 (when (looking-at "\^A\^A\^A\^A$")
401 (defun nndoc-news-type-p ()
402 (when (looking-at "^Path:.*\n")
405 (defun nndoc-rnews-type-p ()
406 (when (looking-at "#! *rnews")
409 (defun nndoc-rnews-body-end ()
410 (and (re-search-backward nndoc-article-begin nil t)
412 (goto-char (+ (point) (string-to-int (match-string 1))))))
414 (defun nndoc-babyl-type-p ()
415 (when (re-search-forward "\^_\^L *\n" nil t)
418 (defun nndoc-babyl-body-begin ()
419 (re-search-forward "^\n" nil t)
420 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
421 (let ((next (or (save-excursion
422 (re-search-forward nndoc-article-begin nil t))
424 (unless (re-search-forward "^\n" next t)
428 (forward-line -1)))))
430 (defun nndoc-babyl-head-begin ()
431 (when (re-search-forward "^[0-9].*\n" nil t)
432 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
436 (defun nndoc-forward-type-p ()
437 (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+"
439 (not (re-search-forward "^Subject:.*digest" nil t))
440 (not (re-search-backward "^From:" nil t 2))
441 (not (re-search-forward "^From:" nil t 2)))
444 (defun nndoc-rfc934-type-p ()
445 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
446 (not (re-search-forward "^Subject:.*digest" nil t))
447 (not (re-search-backward "^From:" nil t 2))
448 (not (re-search-forward "^From:" nil t 2)))
451 (defun nndoc-rfc822-forward-type-p ()
453 (message-narrow-to-head)
454 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
457 (defun nndoc-rfc822-forward-body-end-function ()
458 (goto-char (point-max)))
460 (defun nndoc-mime-parts-type-p ()
461 (let ((case-fold-search t)
462 (limit (search-forward "\n\n" nil t)))
463 (goto-char (point-min))
467 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
468 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
472 (defun nndoc-transform-mime-parts (article)
473 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
474 (headers (nth 5 entry)))
476 (goto-char (point-min))
479 (defun nndoc-generate-mime-parts-head (article)
480 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
481 (headers (nth 6 entry)))
483 (narrow-to-region (point) (point))
484 (insert-buffer-substring
485 nndoc-current-buffer (car entry) (nth 1 entry))
486 (goto-char (point-max)))
490 (defun nndoc-clari-briefs-type-p ()
491 (when (let ((case-fold-search nil))
492 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
495 (defun nndoc-transform-clari-briefs (article)
496 (goto-char (point-min))
497 (when (looking-at " *\\*\\(.*\\)\n")
498 (replace-match "" t t))
499 (nndoc-generate-clari-briefs-head article))
501 (defun nndoc-generate-clari-briefs-head (article)
502 (let ((entry (cdr (assq article nndoc-dissection-alist)))
505 (set-buffer nndoc-current-buffer)
507 (narrow-to-region (car entry) (nth 3 entry))
508 (goto-char (point-min))
509 (when (looking-at " *\\*\\(.*\\)$")
510 (setq subject (match-string 1))
511 (when (string-match "[ \t]+$" subject)
512 (setq subject (substring subject 0 (match-beginning 0)))))
514 (let ((case-fold-search nil))
516 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
517 (setq from (match-string 1)))))
518 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
519 "\nSubject: " (or subject "(no subject)") "\n")))
522 (defun nndoc-mime-digest-type-p ()
523 (let ((case-fold-search t)
524 boundary-id b-delimiter entry)
527 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
528 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
531 (setq boundary-id (match-string 1)
532 b-delimiter (concat "\n--" boundary-id "[ \t]*$"))
533 (setq entry (assq 'mime-digest nndoc-type-alist))
536 (cons 'head-begin "^ ?\n")
537 (cons 'head-end "^ ?$")
538 (cons 'body-begin "^ ?\n")
539 (cons 'article-begin b-delimiter)
540 (cons 'body-end-function 'nndoc-digest-body-end)
541 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
544 (defun nndoc-standard-digest-type-p ()
545 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
547 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
550 (defun nndoc-digest-body-end ()
551 (and (re-search-forward nndoc-article-begin nil t)
552 (goto-char (match-beginning 0))))
554 (defun nndoc-slack-digest-type-p ()
557 (defun nndoc-lanl-gov-announce-type-p ()
558 (when (let ((case-fold-search nil))
559 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
562 (defun nndoc-transform-lanl-gov-announce (article)
563 (goto-char (point-max))
564 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
565 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
567 (defun nndoc-generate-lanl-gov-head (article)
568 (let ((entry (cdr (assq article nndoc-dissection-alist)))
569 (e-mail "no address given")
572 (set-buffer nndoc-current-buffer)
574 (narrow-to-region (car entry) (nth 1 entry))
575 (goto-char (point-min))
576 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
577 (setq subject (concat " (" (match-string 1) ")"))
578 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
579 (setq e-mail (match-string 1)))
580 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
582 (setq subject (concat (match-string 1) subject))
583 (setq from (concat (match-string 2) " <" e-mail ">"))))))
584 (while (and from (string-match "(\[^)\]*)" from))
585 (setq from (replace-match "" t t from)))
586 (insert "From: " (or from "unknown")
587 "\nSubject: " (or subject "(no subject)") "\n")))
589 (defun nndoc-nsmail-type-p ()
590 (when (looking-at "From - ")
593 (deffoo nndoc-request-accept-article (group &optional server last)
598 ;;; Functions for dissecting the documents
601 (defun nndoc-search (regexp)
603 (re-search-forward regexp nil t)
604 (beginning-of-line)))
606 (defun nndoc-dissect-buffer ()
607 "Go through the document and partition it into heads/bodies/articles."
610 head-begin head-end body-begin body-end)
611 (setq nndoc-dissection-alist nil)
613 (set-buffer nndoc-current-buffer)
614 (goto-char (point-min))
615 ;; Remove blank lines.
616 (while (eq (following-char) ?\n)
618 ;; Find the beginning of the file.
619 (when nndoc-file-begin
620 (nndoc-search nndoc-file-begin))
621 ;; Go through the file.
622 (while (if (and first nndoc-first-article)
623 (nndoc-search nndoc-first-article)
624 (nndoc-article-begin))
626 (cond (nndoc-head-begin-function
627 (funcall nndoc-head-begin-function))
629 (nndoc-search nndoc-head-begin)))
632 (looking-at nndoc-file-end)))
633 (goto-char (point-max))
634 (setq head-begin (point))
635 (nndoc-search (or nndoc-head-end "^$"))
636 (setq head-end (point))
637 (if nndoc-body-begin-function
638 (funcall nndoc-body-begin-function)
639 (nndoc-search (or nndoc-body-begin "^\n")))
640 (setq body-begin (point))
641 (or (and nndoc-body-end-function
642 (funcall nndoc-body-end-function))
644 (nndoc-search nndoc-body-end))
645 (nndoc-article-begin)
647 (goto-char (point-max))
649 (and (re-search-backward nndoc-file-end nil t)
650 (beginning-of-line)))))
651 (setq body-end (point))
652 (push (list (incf i) head-begin head-end body-begin body-end
653 (count-lines body-begin body-end))
654 nndoc-dissection-alist))))))
656 (defun nndoc-article-begin ()
657 (if nndoc-article-begin-function
658 (funcall nndoc-article-begin-function)
660 (nndoc-search nndoc-article-begin))))
662 (defun nndoc-unquote-dashes ()
663 "Unquote quoted non-separators in digests."
664 (while (re-search-forward "^- -"nil t)
665 (replace-match "-" t t)))
667 ;; Against compiler warnings.
668 (defvar nndoc-mime-split-ordinal)
670 (defun nndoc-dissect-mime-parts ()
671 "Go through a MIME composite article and partition it into sub-articles.
672 When a MIME entity contains sub-entities, dissection produces one article for
673 the header of this entity, and one article per sub-entity."
674 (setq nndoc-dissection-alist nil
675 nndoc-mime-split-ordinal 0)
677 (set-buffer nndoc-current-buffer)
678 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
680 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
682 "Dissect an entity, within a composite MIME message.
683 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
684 ARTICLE-INSERT should be added at beginning for generating a full article.
685 The string POSITION holds a dotted decimal representation of the article
686 position in the hierarchical structure, it is nil for the outer entity.
687 PARENT is the message-ID of the parent summary line, or nil for none."
688 (let ((case-fold-search t)
689 (message-id (nnmail-message-id))
690 head-end body-begin summary-insert message-rfc822 multipart-any
691 subject content-type type subtype boundary-regexp)
692 ;; Gracefully handle a missing body.
693 (goto-char head-begin)
694 (if (search-forward "\n\n" body-end t)
695 (setq head-end (1- (point))
697 (setq head-end body-end
698 body-begin body-end))
699 (narrow-to-region head-begin head-end)
700 ;; Save MIME attributes.
701 (goto-char head-begin)
702 (setq content-type (message-fetch-field "Content-Type"))
705 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
706 (setq type (downcase (match-string 1 content-type))
707 subtype (downcase (match-string 2 content-type))
708 message-rfc822 (and (string= type "message")
709 (string= subtype "rfc822"))
710 multipart-any (string= type "multipart")))
711 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
712 (setq subject (match-string 1 content-type)))
713 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
714 (setq boundary-regexp (concat "^--"
716 (match-string 1 content-type))
717 "\\(--\\)?[ \t]*\n"))))
719 (when (or multipart-any (not article-insert))
720 (setq subject (message-fetch-field "Subject"))))
724 ;; Prepare the article and summary inserts.
725 (unless article-insert
726 (setq article-insert (buffer-substring (point-min) (point-max))
727 head-end head-begin))
728 (setq summary-insert article-insert)
729 ;; - summary Subject.
731 (let ((line (concat "Subject: <" position
732 (and position multipart-any ".")
733 (and multipart-any "*")
734 (and (or position multipart-any) " ")
735 (cond ((string= subtype "plain") type)
736 ((string= subtype "basic") type)
742 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
743 (replace-match line t t summary-insert)
744 (concat summary-insert line))))
745 ;; - summary Message-ID.
747 (let ((line (concat "Message-ID: " message-id "\n")))
748 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
749 (replace-match line t t summary-insert)
750 (concat summary-insert line))))
751 ;; - summary References.
754 (let ((line (concat "References: " parent "\n")))
755 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
757 (replace-match line t t summary-insert)
758 (concat summary-insert line)))))
759 ;; Generate dissection information for this entity.
760 (push (list (incf nndoc-mime-split-ordinal)
761 head-begin head-end body-begin body-end
762 (count-lines body-begin body-end)
763 article-insert summary-insert)
764 nndoc-dissection-alist)
765 ;; Recurse for all sub-entities, if any.
770 (nndoc-dissect-mime-parts-sub body-begin body-end nil
771 position message-id)))
772 ((and multipart-any boundary-regexp)
773 (let ((part-counter 0)
774 part-begin part-end eof-flag)
775 (while (string-match "\
776 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
778 (setq article-insert (replace-match "" t t article-insert)))
779 (let ((case-fold-search nil))
780 (goto-char body-begin)
781 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
782 (while (not eof-flag)
783 (setq part-begin (point))
784 (cond ((re-search-forward boundary-regexp body-end t)
785 (or (not (match-string 1))
786 (string= (match-string 1) "")
789 (setq part-end (point))
791 (t (setq part-end body-end
794 (nndoc-dissect-mime-parts-sub
795 part-begin part-end article-insert
798 (format "%d" (incf part-counter)))
802 (defun nndoc-add-type (definition &optional position)
803 "Add document DEFINITION to the list of nndoc document definitions.
804 If POSITION is nil or `last', the definition will be added
805 as the last checked definition, if t or `first', add as the
806 first definition, and if any other symbol, add after that
807 symbol in the alist."
808 ;; First remove any old instances.
809 (gnus-pull (car definition) nndoc-type-alist)
810 ;; Then enter the new definition in the proper place.
812 ((or (null position) (eq position 'last))
813 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
814 ((or (eq position t) (eq position 'first))
815 (push definition nndoc-type-alist))
817 (let ((list (memq (assq position nndoc-type-alist)
820 (error "No such position: %s" position))
821 (setcdr list (cons definition (cdr list)))))))
825 ;;; nndoc.el ends here