1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
38 (defvoo nndoc-article-type 'guess
40 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
41 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
42 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
44 (defvoo nndoc-post-type 'mail
45 "*Whether the nndoc group is `mail' or `post'.")
47 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
48 "Hook run after opening a document.
49 The default function removes all trailing carriage returns
52 (defvar nndoc-type-alist
54 (article-begin . "^\^A\^A\^A\^A\n")
55 (body-end . "^\^A\^A\^A\^A\n"))
57 (article-begin . "^From - "))
59 (article-begin . "^Path:"))
61 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
62 (body-end-function . nndoc-rnews-body-end))
64 (article-begin-function . nndoc-mbox-article-begin)
65 (body-end-function . nndoc-mbox-body-end))
67 (article-begin . "\^_\^L *\n")
69 (body-begin-function . nndoc-babyl-body-begin)
70 (head-begin-function . nndoc-babyl-head-begin))
72 (article-begin . "^-+ Start of forwarded message -+\n+")
73 (body-end . "^-+ End of forwarded message -+$")
74 (prepare-body-function . nndoc-unquote-dashes))
76 (article-begin . "^--.*\n+")
78 (prepare-body-function . nndoc-unquote-dashes))
80 (article-begin . "^ \\*")
81 (body-end . "^\t------*[ \t]^*\n^ \\*")
84 (generate-head-function . nndoc-generate-clari-briefs-head)
85 (article-transform-function . nndoc-transform-clari-briefs))
87 (generate-head-function . nndoc-generate-mime-parts-head)
88 (article-transform-function . nndoc-transform-mime-parts))
90 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
91 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
92 (prepare-body-function . nndoc-unquote-dashes)
93 (body-end-function . nndoc-digest-body-end)
95 (body-begin . "^ *\n")
96 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
97 (subtype digest guess))
99 (article-begin . "^------------------------------*[\n \t]+")
101 (body-end-function . nndoc-digest-body-end)
102 (body-begin . "^ ?$")
103 (file-end . "^End of")
104 (prepare-body-function . nndoc-unquote-dashes)
105 (subtype digest guess))
107 (article-begin . "^\\\\\\\\\n")
108 (head-begin . "^Paper.*:")
109 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
111 (body-end . "-------------------------------------------------")
112 (file-end . "^Title: Recent Seminal")
113 (generate-head-function . nndoc-generate-lanl-gov-head)
114 (article-transform-function . nndoc-transform-lanl-gov-announce)
115 (subtype preprints guess))
117 (article-begin . "^\n")
118 (body-end-function . nndoc-rfc822-forward-body-end-function))
130 (defvoo nndoc-file-begin nil)
131 (defvoo nndoc-first-article nil)
132 (defvoo nndoc-article-begin nil)
133 (defvoo nndoc-head-begin nil)
134 (defvoo nndoc-head-end nil)
135 (defvoo nndoc-file-end nil)
136 (defvoo nndoc-body-begin nil)
137 (defvoo nndoc-body-end-function nil)
138 (defvoo nndoc-body-begin-function nil)
139 (defvoo nndoc-head-begin-function nil)
140 (defvoo nndoc-body-end nil)
141 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
142 ;; following items. ARTICLE acts as the association key and is an ordinal
143 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
144 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
145 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
146 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
147 ;; generation, respectively. Other headers usually follow directly from the
148 ;; buffer. Value `nil' means no insert.
149 (defvoo nndoc-dissection-alist nil)
150 (defvoo nndoc-prepare-body-function nil)
151 (defvoo nndoc-generate-head-function nil)
152 (defvoo nndoc-article-transform-function nil)
153 (defvoo nndoc-article-begin-function nil)
155 (defvoo nndoc-status-string "")
156 (defvoo nndoc-group-alist nil)
157 (defvoo nndoc-current-buffer nil
158 "Current nndoc news buffer.")
159 (defvoo nndoc-address nil)
161 (defconst nndoc-version "nndoc 1.0"
166 ;;; Interface functions
168 (nnoo-define-basics nndoc)
170 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
171 (when (nndoc-possibly-change-buffer newsgroup server)
173 (set-buffer nntp-server-buffer)
176 (if (stringp (car articles))
179 (when (setq entry (cdr (assq (setq article (pop articles))
180 nndoc-dissection-alist)))
181 (insert (format "221 %d Article retrieved.\n" article))
182 (if nndoc-generate-head-function
183 (funcall nndoc-generate-head-function article)
184 (insert-buffer-substring
185 nndoc-current-buffer (car entry) (nth 1 entry)))
186 (goto-char (point-max))
187 (unless (eq (char-after (1- (point))) ?\n)
189 (insert (format "Lines: %d\n" (nth 4 entry)))
192 (nnheader-fold-continuation-lines)
195 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
196 (nndoc-possibly-change-buffer newsgroup server)
198 (let ((buffer (or buffer nntp-server-buffer))
199 (entry (cdr (assq article nndoc-dissection-alist)))
204 (if (stringp article)
206 (insert-buffer-substring
207 nndoc-current-buffer (car entry) (nth 1 entry))
210 (insert-buffer-substring
211 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
213 (when nndoc-prepare-body-function
214 (funcall nndoc-prepare-body-function))
215 (when nndoc-article-transform-function
216 (funcall nndoc-article-transform-function article))
219 (deffoo nndoc-request-group (group &optional server dont-check)
223 ((not (nndoc-possibly-change-buffer group server))
224 (nnheader-report 'nndoc "No such file or buffer: %s"
227 (nnheader-report 'nndoc "Selected group %s" group)
229 ((zerop (setq number (length nndoc-dissection-alist)))
230 (nndoc-close-group group)
231 (nnheader-report 'nndoc "No articles in group %s" group))
233 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
235 (deffoo nndoc-request-type (group &optional article)
236 (cond ((not article) 'unknown)
237 (nndoc-post-type nndoc-post-type)
240 (deffoo nndoc-close-group (group &optional server)
241 (nndoc-possibly-change-buffer group server)
242 (and nndoc-current-buffer
243 (buffer-name nndoc-current-buffer)
244 (kill-buffer nndoc-current-buffer))
245 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
247 (setq nndoc-current-buffer nil)
248 (nnoo-close-server 'nndoc server)
249 (setq nndoc-dissection-alist nil)
252 (deffoo nndoc-request-list (&optional server)
255 (deffoo nndoc-request-newgroups (date &optional server)
258 (deffoo nndoc-request-list-newsgroups (&optional server)
262 ;;; Internal functions.
264 (defun nndoc-possibly-change-buffer (group source)
267 ;; The current buffer is this group's buffer.
268 ((and nndoc-current-buffer
269 (buffer-name nndoc-current-buffer)
270 (eq nndoc-current-buffer
271 (setq buf (cdr (assoc group nndoc-group-alist))))))
272 ;; We change buffers by taking an old from the group alist.
273 ;; `source' is either a string (a file name) or a buffer object.
275 (setq nndoc-current-buffer buf))
276 ;; It's a totally new group.
277 ((or (and (bufferp nndoc-address)
278 (buffer-name nndoc-address))
279 (and (stringp nndoc-address)
280 (file-exists-p nndoc-address)
281 (not (file-directory-p nndoc-address))))
282 (push (cons group (setq nndoc-current-buffer
284 (concat " *nndoc " group "*"))))
286 (setq nndoc-dissection-alist nil)
288 (set-buffer nndoc-current-buffer)
290 (if (stringp nndoc-address)
291 (nnheader-insert-file-contents nndoc-address)
292 (insert-buffer-substring nndoc-address))
293 (run-hooks 'nndoc-open-document-hook))))
294 ;; Initialize the nndoc structures according to this new document.
295 (when (and nndoc-current-buffer
296 (not nndoc-dissection-alist))
298 (set-buffer nndoc-current-buffer)
300 (if (eq nndoc-article-type 'mime-parts)
301 (nndoc-dissect-mime-parts)
302 (nndoc-dissect-buffer))))
303 (unless nndoc-current-buffer
304 (nndoc-close-server))
305 ;; Return whether we managed to select a file.
306 nndoc-current-buffer))
309 ;;; Deciding what document type we have
312 (defun nndoc-set-delims ()
313 "Set the nndoc delimiter variables according to the type of the document."
314 (let ((vars '(nndoc-file-begin
316 nndoc-article-begin-function
317 nndoc-head-begin nndoc-head-end
318 nndoc-file-end nndoc-article-begin
319 nndoc-body-begin nndoc-body-end-function nndoc-body-end
320 nndoc-prepare-body-function nndoc-article-transform-function
321 nndoc-generate-head-function nndoc-body-begin-function
322 nndoc-head-begin-function)))
324 (set (pop vars) nil)))
326 ;; Guess away until we find the real file type.
327 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
329 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
330 ;; Set the nndoc variables.
332 (set (intern (format "nndoc-%s" (caar defs)))
335 (defun nndoc-guess-type (subtype)
336 (let ((alist nndoc-type-alist)
337 results result entry)
338 (while (and (not result)
339 (setq entry (pop alist)))
340 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
341 (goto-char (point-min))
342 (when (numberp (setq result (funcall (intern
343 (format "nndoc-%s-type-p"
345 (push (cons result entry) results)
347 (unless (or result results)
348 (error "Document is not of any recognized type"))
351 (cadar (sort results 'car-less-than-car)))))
354 ;;; Built-in type predicates and functions
357 (defun nndoc-mbox-type-p ()
358 (when (looking-at message-unix-mail-delimiter)
361 (defun nndoc-mbox-article-begin ()
362 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
363 (goto-char (match-beginning 0))))
365 (defun nndoc-mbox-body-end ()
370 (and (re-search-backward
371 (concat "^" message-unix-mail-delimiter) nil t)
373 (search-forward "\n\n" beg t)
375 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
376 (setq len (string-to-int (match-string 1)))
377 (search-forward "\n\n" beg t)
378 (unless (= (setq len (+ (point) len)) (point-max))
379 (and (< len (point-max))
381 (looking-at message-unix-mail-delimiter)))))
384 (defun nndoc-mmdf-type-p ()
385 (when (looking-at "\^A\^A\^A\^A$")
388 (defun nndoc-news-type-p ()
389 (when (looking-at "^Path:.*\n")
392 (defun nndoc-rnews-type-p ()
393 (when (looking-at "#! *rnews")
396 (defun nndoc-rnews-body-end ()
397 (and (re-search-backward nndoc-article-begin nil t)
399 (goto-char (+ (point) (string-to-int (match-string 1))))))
401 (defun nndoc-babyl-type-p ()
402 (when (re-search-forward "\^_\^L *\n" nil t)
405 (defun nndoc-babyl-body-begin ()
406 (re-search-forward "^\n" nil t)
407 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
408 (let ((next (or (save-excursion
409 (re-search-forward nndoc-article-begin nil t))
411 (unless (re-search-forward "^\n" next t)
415 (forward-line -1)))))
417 (defun nndoc-babyl-head-begin ()
418 (when (re-search-forward "^[0-9].*\n" nil t)
419 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
423 (defun nndoc-forward-type-p ()
424 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
425 (not (re-search-forward "^Subject:.*digest" nil t))
426 (not (re-search-backward "^From:" nil t 2))
427 (not (re-search-forward "^From:" nil t 2)))
430 (defun nndoc-rfc934-type-p ()
431 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
432 (not (re-search-forward "^Subject:.*digest" nil t))
433 (not (re-search-backward "^From:" nil t 2))
434 (not (re-search-forward "^From:" nil t 2)))
437 (defun nndoc-rfc822-forward-type-p ()
439 (message-narrow-to-head)
440 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
443 (defun nndoc-rfc822-forward-body-end-function ()
444 (goto-char (point-max)))
446 (defun nndoc-mime-parts-type-p ()
447 (let ((case-fold-search t)
448 (limit (search-forward "\n\n" nil t)))
449 (goto-char (point-min))
453 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
454 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
458 (defun nndoc-transform-mime-parts (article)
459 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
460 (headers (nth 5 entry)))
462 (goto-char (point-min))
465 (defun nndoc-generate-mime-parts-head (article)
466 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
467 (headers (nth 6 entry)))
469 (narrow-to-region (point) (point))
470 (insert-buffer-substring
471 nndoc-current-buffer (car entry) (nth 1 entry))
472 (goto-char (point-max)))
476 (defun nndoc-clari-briefs-type-p ()
477 (when (let ((case-fold-search nil))
478 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
481 (defun nndoc-transform-clari-briefs (article)
482 (goto-char (point-min))
483 (when (looking-at " *\\*\\(.*\\)\n")
484 (replace-match "" t t))
485 (nndoc-generate-clari-briefs-head article))
487 (defun nndoc-generate-clari-briefs-head (article)
488 (let ((entry (cdr (assq article nndoc-dissection-alist)))
491 (set-buffer nndoc-current-buffer)
493 (narrow-to-region (car entry) (nth 3 entry))
494 (goto-char (point-min))
495 (when (looking-at " *\\*\\(.*\\)$")
496 (setq subject (match-string 1))
497 (when (string-match "[ \t]+$" subject)
498 (setq subject (substring subject 0 (match-beginning 0)))))
500 (let ((case-fold-search nil))
502 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
503 (setq from (match-string 1)))))
504 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
505 "\nSubject: " (or subject "(no subject)") "\n")))
507 (defun nndoc-standard-digest-type-p ()
508 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
510 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
513 (defun nndoc-digest-body-end ()
514 (and (re-search-forward nndoc-article-begin nil t)
515 (goto-char (match-beginning 0))))
517 (defun nndoc-slack-digest-type-p ()
520 (defun nndoc-lanl-gov-announce-type-p ()
521 (when (let ((case-fold-search nil))
522 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
525 (defun nndoc-transform-lanl-gov-announce (article)
526 (goto-char (point-max))
527 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
528 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
529 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
530 ;; (replace-match "" t t))
533 (defun nndoc-generate-lanl-gov-head (article)
534 (let ((entry (cdr (assq article nndoc-dissection-alist)))
535 (e-mail "no address given")
538 (set-buffer nndoc-current-buffer)
540 (narrow-to-region (car entry) (nth 1 entry))
541 (goto-char (point-min))
542 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
543 (setq subject (concat " (" (match-string 1) ")"))
544 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
545 (setq e-mail (match-string 1)))
546 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
548 (setq subject (concat (match-string 1) subject))
549 (setq from (concat (match-string 2) " <" e-mail ">"))))
551 (while (and from (string-match "(\[^)\]*)" from))
552 (setq from (replace-match "" t t from)))
553 (insert "From: " (or from "unknown")
554 "\nSubject: " (or subject "(no subject)") "\n")))
556 (defun nndoc-nsmail-type-p ()
557 (when (looking-at "From - ")
560 (deffoo nndoc-request-accept-article (group &optional server last)
565 ;;; Functions for dissecting the documents
568 (defun nndoc-search (regexp)
570 (re-search-forward regexp nil t)
571 (beginning-of-line)))
573 (defun nndoc-dissect-buffer ()
574 "Go through the document and partition it into heads/bodies/articles."
577 head-begin head-end body-begin body-end)
578 (setq nndoc-dissection-alist nil)
580 (set-buffer nndoc-current-buffer)
581 (goto-char (point-min))
582 ;; Find the beginning of the file.
583 (when nndoc-file-begin
584 (nndoc-search nndoc-file-begin))
585 ;; Go through the file.
586 (while (if (and first nndoc-first-article)
587 (nndoc-search nndoc-first-article)
588 (nndoc-article-begin))
590 (cond (nndoc-head-begin-function
591 (funcall nndoc-head-begin-function))
593 (nndoc-search nndoc-head-begin)))
596 (looking-at nndoc-file-end)))
597 (goto-char (point-max))
598 (setq head-begin (point))
599 (nndoc-search (or nndoc-head-end "^$"))
600 (setq head-end (point))
601 (if nndoc-body-begin-function
602 (funcall nndoc-body-begin-function)
603 (nndoc-search (or nndoc-body-begin "^\n")))
604 (setq body-begin (point))
605 (or (and nndoc-body-end-function
606 (funcall nndoc-body-end-function))
608 (nndoc-search nndoc-body-end))
609 (nndoc-article-begin)
611 (goto-char (point-max))
613 (and (re-search-backward nndoc-file-end nil t)
614 (beginning-of-line)))))
615 (setq body-end (point))
616 (push (list (incf i) head-begin head-end body-begin body-end
617 (count-lines body-begin body-end))
618 nndoc-dissection-alist))))))
620 (defun nndoc-article-begin ()
621 (if nndoc-article-begin-function
622 (funcall nndoc-article-begin-function)
624 (nndoc-search nndoc-article-begin))))
626 (defun nndoc-unquote-dashes ()
627 "Unquote quoted non-separators in digests."
628 (while (re-search-forward "^- -"nil t)
629 (replace-match "-" t t)))
631 ;; Against compiler warnings.
632 (defvar nndoc-mime-split-ordinal)
634 (defun nndoc-dissect-mime-parts ()
635 "Go through a MIME composite article and partition it into sub-articles.
636 When a MIME entity contains sub-entities, dissection produces one article for
637 the header of this entity, and one article per sub-entity."
638 (setq nndoc-dissection-alist nil
639 nndoc-mime-split-ordinal 0)
641 (set-buffer nndoc-current-buffer)
642 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
644 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
646 "Dissect an entity, within a composite MIME message.
647 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
648 ARTICLE-INSERT should be added at beginning for generating a full article.
649 The string POSITION holds a dotted decimal representation of the article
650 position in the hierarchical structure, it is nil for the outer entity.
651 PARENT is the message-ID of the parent summary line, or nil for none."
652 (let ((case-fold-search t)
653 (message-id (nnmail-message-id))
654 head-end body-begin summary-insert message-rfc822 multipart-any
655 subject content-type type subtype boundary-regexp)
656 ;; Gracefully handle a missing body.
657 (goto-char head-begin)
658 (if (search-forward "\n\n" body-end t)
659 (setq head-end (1- (point))
661 (setq head-end body-end
662 body-begin body-end))
663 (narrow-to-region head-begin head-end)
664 ;; Save MIME attributes.
665 (goto-char head-begin)
666 (setq content-type (message-fetch-field "Content-Type"))
669 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
670 (setq type (downcase (match-string 1 content-type))
671 subtype (downcase (match-string 2 content-type))
672 message-rfc822 (and (string= type "message")
673 (string= subtype "rfc822"))
674 multipart-any (string= type "multipart")))
675 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
676 (setq subject (match-string 1 content-type)))
677 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
678 (setq boundary-regexp (concat "^--"
680 (match-string 1 content-type))
681 "\\(--\\)?[ \t]*\n"))))
683 (when (or multipart-any (not article-insert))
684 (setq subject (message-fetch-field "Subject"))))
688 ;; Prepare the article and summary inserts.
689 (unless article-insert
690 (setq article-insert (buffer-substring (point-min) (point-max))
691 head-end head-begin))
692 (setq summary-insert article-insert)
693 ;; - summary Subject.
695 (let ((line (concat "Subject: <" position
696 (and position multipart-any ".")
697 (and multipart-any "*")
698 (and (or position multipart-any) " ")
699 (cond ((string= subtype "plain") type)
700 ((string= subtype "basic") type)
706 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
707 (replace-match line t t summary-insert)
708 (concat summary-insert line))))
709 ;; - summary Message-ID.
711 (let ((line (concat "Message-ID: " message-id "\n")))
712 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
713 (replace-match line t t summary-insert)
714 (concat summary-insert line))))
715 ;; - summary References.
718 (let ((line (concat "References: " parent "\n")))
719 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
721 (replace-match line t t summary-insert)
722 (concat summary-insert line)))))
723 ;; Generate dissection information for this entity.
724 (push (list (incf nndoc-mime-split-ordinal)
725 head-begin head-end body-begin body-end
726 (count-lines body-begin body-end)
727 article-insert summary-insert)
728 nndoc-dissection-alist)
729 ;; Recurse for all sub-entities, if any.
734 (nndoc-dissect-mime-parts-sub body-begin body-end nil
735 position message-id)))
736 ((and multipart-any boundary-regexp)
737 (let ((part-counter 0)
738 part-begin part-end eof-flag)
739 (while (string-match "\
740 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
742 (setq article-insert (replace-match "" t t article-insert)))
743 (let ((case-fold-search nil))
744 (goto-char body-begin)
745 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
746 (while (not eof-flag)
747 (setq part-begin (point))
748 (cond ((re-search-forward boundary-regexp body-end t)
749 (or (not (match-string 1))
750 (string= (match-string 1) "")
753 (setq part-end (point))
755 (t (setq part-end body-end
758 (nndoc-dissect-mime-parts-sub
759 part-begin part-end article-insert
762 (format "%d" (incf part-counter)))
766 (defun nndoc-add-type (definition &optional position)
767 "Add document DEFINITION to the list of nndoc document definitions.
768 If POSITION is nil or `last', the definition will be added
769 as the last checked definition, if t or `first', add as the
770 first definition, and if any other symbol, add after that
771 symbol in the alist."
772 ;; First remove any old instances.
773 (gnus-pull (car definition) nndoc-type-alist)
774 ;; Then enter the new definition in the proper place.
776 ((or (null position) (eq position 'last))
777 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
778 ((or (eq position t) (eq position 'first))
779 (push definition nndoc-type-alist))
781 (let ((list (memq (assq position nndoc-type-alist)
784 (error "No such position: %s" position))
785 (setcdr list (cons definition (cdr list)))))))
789 ;;; nndoc.el ends here