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))
129 (article-begin-function . nndoc-outlook-article-begin)
142 (defvoo nndoc-file-begin nil)
143 (defvoo nndoc-first-article nil)
144 (defvoo nndoc-article-begin nil)
145 (defvoo nndoc-head-begin nil)
146 (defvoo nndoc-head-end nil)
147 (defvoo nndoc-file-end nil)
148 (defvoo nndoc-body-begin nil)
149 (defvoo nndoc-body-end-function nil)
150 (defvoo nndoc-body-begin-function nil)
151 (defvoo nndoc-head-begin-function nil)
152 (defvoo nndoc-body-end nil)
153 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
154 ;; following items. ARTICLE acts as the association key and is an ordinal
155 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
156 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
157 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
158 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
159 ;; generation, respectively. Other headers usually follow directly from the
160 ;; buffer. Value `nil' means no insert.
161 (defvoo nndoc-dissection-alist nil)
162 (defvoo nndoc-prepare-body-function nil)
163 (defvoo nndoc-generate-head-function nil)
164 (defvoo nndoc-article-transform-function nil)
165 (defvoo nndoc-article-begin-function nil)
167 (defvoo nndoc-status-string "")
168 (defvoo nndoc-group-alist nil)
169 (defvoo nndoc-current-buffer nil
170 "Current nndoc news buffer.")
171 (defvoo nndoc-address nil)
173 (defconst nndoc-version "nndoc 1.0"
178 ;;; Interface functions
180 (nnoo-define-basics nndoc)
182 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
183 (when (nndoc-possibly-change-buffer newsgroup server)
185 (set-buffer nntp-server-buffer)
188 (if (stringp (car articles))
191 (when (setq entry (cdr (assq (setq article (pop articles))
192 nndoc-dissection-alist)))
193 (insert (format "221 %d Article retrieved.\n" article))
194 (if nndoc-generate-head-function
195 (funcall nndoc-generate-head-function article)
196 (insert-buffer-substring
197 nndoc-current-buffer (car entry) (nth 1 entry)))
198 (goto-char (point-max))
199 (unless (eq (char-after (1- (point))) ?\n)
201 (insert (format "Lines: %d\n" (nth 4 entry)))
204 (nnheader-fold-continuation-lines)
207 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
208 (nndoc-possibly-change-buffer newsgroup server)
210 (let ((buffer (or buffer nntp-server-buffer))
211 (entry (cdr (assq article nndoc-dissection-alist)))
216 (if (stringp article)
218 (insert-buffer-substring
219 nndoc-current-buffer (car entry) (nth 1 entry))
222 (insert-buffer-substring
223 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
225 (when nndoc-prepare-body-function
226 (funcall nndoc-prepare-body-function))
227 (when nndoc-article-transform-function
228 (funcall nndoc-article-transform-function article))
231 (deffoo nndoc-request-group (group &optional server dont-check)
235 ((not (nndoc-possibly-change-buffer group server))
236 (nnheader-report 'nndoc "No such file or buffer: %s"
239 (nnheader-report 'nndoc "Selected group %s" group)
241 ((zerop (setq number (length nndoc-dissection-alist)))
242 (nndoc-close-group group)
243 (nnheader-report 'nndoc "No articles in group %s" group))
245 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
247 (deffoo nndoc-request-type (group &optional article)
248 (cond ((not article) 'unknown)
249 (nndoc-post-type nndoc-post-type)
252 (deffoo nndoc-close-group (group &optional server)
253 (nndoc-possibly-change-buffer group server)
254 (and nndoc-current-buffer
255 (buffer-name nndoc-current-buffer)
256 (kill-buffer nndoc-current-buffer))
257 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
259 (setq nndoc-current-buffer nil)
260 (nnoo-close-server 'nndoc server)
261 (setq nndoc-dissection-alist nil)
264 (deffoo nndoc-request-list (&optional server)
267 (deffoo nndoc-request-newgroups (date &optional server)
270 (deffoo nndoc-request-list-newsgroups (&optional server)
274 ;;; Internal functions.
276 (defun nndoc-possibly-change-buffer (group source)
279 ;; The current buffer is this group's buffer.
280 ((and nndoc-current-buffer
281 (buffer-name nndoc-current-buffer)
282 (eq nndoc-current-buffer
283 (setq buf (cdr (assoc group nndoc-group-alist))))))
284 ;; We change buffers by taking an old from the group alist.
285 ;; `source' is either a string (a file name) or a buffer object.
287 (setq nndoc-current-buffer buf))
288 ;; It's a totally new group.
289 ((or (and (bufferp nndoc-address)
290 (buffer-name nndoc-address))
291 (and (stringp nndoc-address)
292 (file-exists-p nndoc-address)
293 (not (file-directory-p nndoc-address))))
294 (push (cons group (setq nndoc-current-buffer
296 (concat " *nndoc " group "*"))))
298 (setq nndoc-dissection-alist nil)
300 (set-buffer nndoc-current-buffer)
302 (if (stringp nndoc-address)
303 (nnheader-insert-file-contents nndoc-address)
304 (insert-buffer-substring nndoc-address))
305 (run-hooks 'nndoc-open-document-hook))))
306 ;; Initialize the nndoc structures according to this new document.
307 (when (and nndoc-current-buffer
308 (not nndoc-dissection-alist))
310 (set-buffer nndoc-current-buffer)
312 (if (eq nndoc-article-type 'mime-parts)
313 (nndoc-dissect-mime-parts)
314 (nndoc-dissect-buffer))))
315 (unless nndoc-current-buffer
316 (nndoc-close-server))
317 ;; Return whether we managed to select a file.
318 nndoc-current-buffer))
321 ;;; Deciding what document type we have
324 (defun nndoc-set-delims ()
325 "Set the nndoc delimiter variables according to the type of the document."
326 (let ((vars '(nndoc-file-begin
328 nndoc-article-begin-function
329 nndoc-head-begin nndoc-head-end
330 nndoc-file-end nndoc-article-begin
331 nndoc-body-begin nndoc-body-end-function nndoc-body-end
332 nndoc-prepare-body-function nndoc-article-transform-function
333 nndoc-generate-head-function nndoc-body-begin-function
334 nndoc-head-begin-function)))
336 (set (pop vars) nil)))
338 ;; Guess away until we find the real file type.
339 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
341 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
342 ;; Set the nndoc variables.
344 (set (intern (format "nndoc-%s" (caar defs)))
347 (defun nndoc-guess-type (subtype)
348 (let ((alist nndoc-type-alist)
349 results result entry)
350 (while (and (not result)
351 (setq entry (pop alist)))
352 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
353 (goto-char (point-min))
354 ;; Remove blank lines.
355 (while (eq (following-char) ?\n)
357 (when (numberp (setq result (funcall (intern
358 (format "nndoc-%s-type-p"
360 (push (cons result entry) results)
362 (unless (or result results)
363 (error "Document is not of any recognized type"))
366 (cadar (sort results 'car-less-than-car)))))
369 ;;; Built-in type predicates and functions
372 (defun nndoc-mbox-type-p ()
373 (when (looking-at message-unix-mail-delimiter)
376 (defun nndoc-mbox-article-begin ()
377 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
378 (goto-char (match-beginning 0))))
380 (defun nndoc-mbox-body-end ()
385 (and (re-search-backward
386 (concat "^" message-unix-mail-delimiter) nil t)
388 (search-forward "\n\n" beg t)
390 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
391 (setq len (string-to-int (match-string 1)))
392 (search-forward "\n\n" beg t)
393 (unless (= (setq len (+ (point) len)) (point-max))
394 (and (< len (point-max))
396 (looking-at message-unix-mail-delimiter)))))
399 (defun nndoc-mmdf-type-p ()
400 (when (looking-at "\^A\^A\^A\^A$")
403 (defun nndoc-news-type-p ()
404 (when (looking-at "^Path:.*\n")
407 (defun nndoc-rnews-type-p ()
408 (when (looking-at "#! *rnews")
411 (defun nndoc-rnews-body-end ()
412 (and (re-search-backward nndoc-article-begin nil t)
414 (goto-char (+ (point) (string-to-int (match-string 1))))))
416 (defun nndoc-babyl-type-p ()
417 (when (re-search-forward "\^_\^L *\n" nil t)
420 (defun nndoc-babyl-body-begin ()
421 (re-search-forward "^\n" nil t)
422 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
423 (let ((next (or (save-excursion
424 (re-search-forward nndoc-article-begin nil t))
426 (unless (re-search-forward "^\n" next t)
430 (forward-line -1)))))
432 (defun nndoc-babyl-head-begin ()
433 (when (re-search-forward "^[0-9].*\n" nil t)
434 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
438 (defun nndoc-forward-type-p ()
439 (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+"
441 (not (re-search-forward "^Subject:.*digest" nil t))
442 (not (re-search-backward "^From:" nil t 2))
443 (not (re-search-forward "^From:" nil t 2)))
446 (defun nndoc-rfc934-type-p ()
447 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
448 (not (re-search-forward "^Subject:.*digest" nil t))
449 (not (re-search-backward "^From:" nil t 2))
450 (not (re-search-forward "^From:" nil t 2)))
453 (defun nndoc-rfc822-forward-type-p ()
455 (message-narrow-to-head)
456 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
459 (defun nndoc-rfc822-forward-body-end-function ()
460 (goto-char (point-max)))
462 (defun nndoc-mime-parts-type-p ()
463 (let ((case-fold-search t)
464 (limit (search-forward "\n\n" nil t)))
465 (goto-char (point-min))
469 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
470 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
474 (defun nndoc-transform-mime-parts (article)
475 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
476 (headers (nth 5 entry)))
478 (goto-char (point-min))
481 (defun nndoc-generate-mime-parts-head (article)
482 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
483 (headers (nth 6 entry)))
485 (narrow-to-region (point) (point))
486 (insert-buffer-substring
487 nndoc-current-buffer (car entry) (nth 1 entry))
488 (goto-char (point-max)))
492 (defun nndoc-clari-briefs-type-p ()
493 (when (let ((case-fold-search nil))
494 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
497 (defun nndoc-transform-clari-briefs (article)
498 (goto-char (point-min))
499 (when (looking-at " *\\*\\(.*\\)\n")
500 (replace-match "" t t))
501 (nndoc-generate-clari-briefs-head article))
503 (defun nndoc-generate-clari-briefs-head (article)
504 (let ((entry (cdr (assq article nndoc-dissection-alist)))
507 (set-buffer nndoc-current-buffer)
509 (narrow-to-region (car entry) (nth 3 entry))
510 (goto-char (point-min))
511 (when (looking-at " *\\*\\(.*\\)$")
512 (setq subject (match-string 1))
513 (when (string-match "[ \t]+$" subject)
514 (setq subject (substring subject 0 (match-beginning 0)))))
516 (let ((case-fold-search nil))
518 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
519 (setq from (match-string 1)))))
520 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
521 "\nSubject: " (or subject "(no subject)") "\n")))
524 (defun nndoc-mime-digest-type-p ()
525 (let ((case-fold-search t)
526 boundary-id b-delimiter entry)
529 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
530 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
533 (setq boundary-id (match-string 1)
534 b-delimiter (concat "\n--" boundary-id "[ \t]*$"))
535 (setq entry (assq 'mime-digest nndoc-type-alist))
538 (cons 'head-begin "^ ?\n")
539 (cons 'head-end "^ ?$")
540 (cons 'body-begin "^ ?\n")
541 (cons 'article-begin b-delimiter)
542 (cons 'body-end-function 'nndoc-digest-body-end)
543 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
546 (defun nndoc-standard-digest-type-p ()
547 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
549 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
552 (defun nndoc-digest-body-end ()
553 (and (re-search-forward nndoc-article-begin nil t)
554 (goto-char (match-beginning 0))))
556 (defun nndoc-slack-digest-type-p ()
559 (defun nndoc-lanl-gov-announce-type-p ()
560 (when (let ((case-fold-search nil))
561 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
564 (defun nndoc-transform-lanl-gov-announce (article)
565 (goto-char (point-max))
566 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
567 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
569 (defun nndoc-generate-lanl-gov-head (article)
570 (let ((entry (cdr (assq article nndoc-dissection-alist)))
571 (e-mail "no address given")
574 (set-buffer nndoc-current-buffer)
576 (narrow-to-region (car entry) (nth 1 entry))
577 (goto-char (point-min))
578 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
579 (setq subject (concat " (" (match-string 1) ")"))
580 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
581 (setq e-mail (match-string 1)))
582 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
584 (setq subject (concat (match-string 1) subject))
585 (setq from (concat (match-string 2) " <" e-mail ">"))))))
586 (while (and from (string-match "(\[^)\]*)" from))
587 (setq from (replace-match "" t t from)))
588 (insert "From: " (or from "unknown")
589 "\nSubject: " (or subject "(no subject)") "\n")))
591 (defun nndoc-nsmail-type-p ()
592 (when (looking-at "From - ")
595 (defun nndoc-outlook-article-begin ()
596 (prog1 (re-search-forward "From:\\|Received:" nil t)
597 (goto-char (match-beginning 0))))
599 (defun nndoc-outlook-type-p ()
600 ;; FIXME: Is JMF the magic of outlook mailbox? -- ShengHuo.
603 (deffoo nndoc-request-accept-article (group &optional server last)
608 ;;; Functions for dissecting the documents
611 (defun nndoc-search (regexp)
613 (re-search-forward regexp nil t)
614 (beginning-of-line)))
616 (defun nndoc-dissect-buffer ()
617 "Go through the document and partition it into heads/bodies/articles."
620 head-begin head-end body-begin body-end)
621 (setq nndoc-dissection-alist nil)
623 (set-buffer nndoc-current-buffer)
624 (goto-char (point-min))
625 ;; Remove blank lines.
626 (while (eq (following-char) ?\n)
628 ;; Find the beginning of the file.
629 (when nndoc-file-begin
630 (nndoc-search nndoc-file-begin))
631 ;; Go through the file.
632 (while (if (and first nndoc-first-article)
633 (nndoc-search nndoc-first-article)
634 (nndoc-article-begin))
636 (cond (nndoc-head-begin-function
637 (funcall nndoc-head-begin-function))
639 (nndoc-search nndoc-head-begin)))
642 (looking-at nndoc-file-end)))
643 (goto-char (point-max))
644 (setq head-begin (point))
645 (nndoc-search (or nndoc-head-end "^$"))
646 (setq head-end (point))
647 (if nndoc-body-begin-function
648 (funcall nndoc-body-begin-function)
649 (nndoc-search (or nndoc-body-begin "^\n")))
650 (setq body-begin (point))
651 (or (and nndoc-body-end-function
652 (funcall nndoc-body-end-function))
654 (nndoc-search nndoc-body-end))
655 (nndoc-article-begin)
657 (goto-char (point-max))
659 (and (re-search-backward nndoc-file-end nil t)
660 (beginning-of-line)))))
661 (setq body-end (point))
662 (push (list (incf i) head-begin head-end body-begin body-end
663 (count-lines body-begin body-end))
664 nndoc-dissection-alist))))))
666 (defun nndoc-article-begin ()
667 (if nndoc-article-begin-function
668 (funcall nndoc-article-begin-function)
670 (nndoc-search nndoc-article-begin))))
672 (defun nndoc-unquote-dashes ()
673 "Unquote quoted non-separators in digests."
674 (while (re-search-forward "^- -"nil t)
675 (replace-match "-" t t)))
677 ;; Against compiler warnings.
678 (defvar nndoc-mime-split-ordinal)
680 (defun nndoc-dissect-mime-parts ()
681 "Go through a MIME composite article and partition it into sub-articles.
682 When a MIME entity contains sub-entities, dissection produces one article for
683 the header of this entity, and one article per sub-entity."
684 (setq nndoc-dissection-alist nil
685 nndoc-mime-split-ordinal 0)
687 (set-buffer nndoc-current-buffer)
688 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
690 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
692 "Dissect an entity, within a composite MIME message.
693 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
694 ARTICLE-INSERT should be added at beginning for generating a full article.
695 The string POSITION holds a dotted decimal representation of the article
696 position in the hierarchical structure, it is nil for the outer entity.
697 PARENT is the message-ID of the parent summary line, or nil for none."
698 (let ((case-fold-search t)
699 (message-id (nnmail-message-id))
700 head-end body-begin summary-insert message-rfc822 multipart-any
701 subject content-type type subtype boundary-regexp)
702 ;; Gracefully handle a missing body.
703 (goto-char head-begin)
704 (if (or (and (eq (char-after) ?\n) (or (forward-char 1) t))
705 (search-forward "\n\n" body-end t))
706 (setq head-end (1- (point))
708 (setq head-end body-end
709 body-begin body-end))
710 (narrow-to-region head-begin head-end)
711 ;; Save MIME attributes.
712 (goto-char head-begin)
713 (setq content-type (message-fetch-field "Content-Type"))
716 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
717 (setq type (downcase (match-string 1 content-type))
718 subtype (downcase (match-string 2 content-type))
719 message-rfc822 (and (string= type "message")
720 (string= subtype "rfc822"))
721 multipart-any (string= type "multipart")))
722 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
723 (setq subject (match-string 1 content-type)))
724 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
725 (setq boundary-regexp (concat "^--"
727 (match-string 1 content-type))
728 "\\(--\\)?[ \t]*\n"))))
730 (when (or multipart-any (not article-insert))
731 (setq subject (message-fetch-field "Subject"))))
735 ;; Prepare the article and summary inserts.
736 (unless article-insert
737 (setq article-insert (buffer-substring (point-min) (point-max))
738 head-end head-begin))
739 (setq summary-insert article-insert)
740 ;; - summary Subject.
742 (let ((line (concat "Subject: <" position
743 (and position multipart-any ".")
744 (and multipart-any "*")
745 (and (or position multipart-any) " ")
746 (cond ((string= subtype "plain") type)
747 ((string= subtype "basic") type)
753 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
754 (replace-match line t t summary-insert)
755 (concat summary-insert line))))
756 ;; - summary Message-ID.
758 (let ((line (concat "Message-ID: " message-id "\n")))
759 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
760 (replace-match line t t summary-insert)
761 (concat summary-insert line))))
762 ;; - summary References.
765 (let ((line (concat "References: " parent "\n")))
766 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
768 (replace-match line t t summary-insert)
769 (concat summary-insert line)))))
770 ;; Generate dissection information for this entity.
771 (push (list (incf nndoc-mime-split-ordinal)
772 head-begin head-end body-begin body-end
773 (count-lines body-begin body-end)
774 article-insert summary-insert)
775 nndoc-dissection-alist)
776 ;; Recurse for all sub-entities, if any.
781 (nndoc-dissect-mime-parts-sub body-begin body-end nil
782 position message-id)))
783 ((and multipart-any boundary-regexp)
784 (let ((part-counter 0)
785 part-begin part-end eof-flag)
786 (while (string-match "\
787 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\|Disposition\\)\\):.*\n\\([ \t].*\n\\)*"
789 (setq article-insert (replace-match "" t t article-insert)))
790 (let ((case-fold-search nil))
791 (goto-char body-begin)
792 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
793 (while (not eof-flag)
794 (setq part-begin (point))
795 (cond ((re-search-forward boundary-regexp body-end t)
796 (or (not (match-string 1))
797 (string= (match-string 1) "")
800 (setq part-end (point))
802 (t (setq part-end body-end
805 (nndoc-dissect-mime-parts-sub
806 part-begin part-end article-insert
809 (format "%d" (incf part-counter)))
813 (defun nndoc-add-type (definition &optional position)
814 "Add document DEFINITION to the list of nndoc document definitions.
815 If POSITION is nil or `last', the definition will be added
816 as the last checked definition, if t or `first', add as the
817 first definition, and if any other symbol, add after that
818 symbol in the alist."
819 ;; First remove any old instances.
820 (gnus-pull (car definition) nndoc-type-alist)
821 ;; Then enter the new definition in the proper place.
823 ((or (null position) (eq position 'last))
824 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
825 ((or (eq position t) (eq position 'first))
826 (push definition nndoc-type-alist))
828 (let ((list (memq (assq position nndoc-type-alist)
831 (error "No such position: %s" position))
832 (setcdr list (cons definition (cdr list)))))))
836 ;;; nndoc.el ends here