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.
35 (eval-when-compile (require 'cl))
39 (defvoo nndoc-article-type 'guess
41 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
42 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
43 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
45 (defvoo nndoc-post-type 'mail
46 "*Whether the nndoc group is `mail' or `post'.")
48 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
49 "Hook run after opening a document.
50 The default function removes all trailing carriage returns
53 (defvar nndoc-type-alist
55 (article-begin . "^\^A\^A\^A\^A\n")
56 (body-end . "^\^A\^A\^A\^A\n"))
58 (article-begin . "^From - "))
60 (article-begin . "^Path:"))
62 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
63 (body-end-function . nndoc-rnews-body-end))
65 (article-begin-function . nndoc-mbox-article-begin)
66 (body-end-function . nndoc-mbox-body-end))
68 (article-begin . "\^_\^L *\n")
70 (body-begin-function . nndoc-babyl-body-begin)
71 (head-begin-function . nndoc-babyl-head-begin))
73 (article-begin . "^-+ Start of forwarded message -+\n+")
74 (body-end . "^-+ End of forwarded message -+$")
75 (prepare-body-function . nndoc-unquote-dashes))
77 (article-begin . "^--.*\n+")
79 (prepare-body-function . nndoc-unquote-dashes))
81 (article-begin . "^ \\*")
82 (body-end . "^\t------*[ \t]^*\n^ \\*")
85 (generate-head-function . nndoc-generate-clari-briefs-head)
86 (article-transform-function . nndoc-transform-clari-briefs))
88 (generate-head-function . nndoc-generate-mime-parts-head)
89 (article-transform-function . nndoc-transform-mime-parts))
91 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
92 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
93 (prepare-body-function . nndoc-unquote-dashes)
94 (body-end-function . nndoc-digest-body-end)
96 (body-begin . "^ *\n")
97 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
98 (subtype digest guess))
100 (article-begin . "^------------------------------*[\n \t]+")
102 (body-end-function . nndoc-digest-body-end)
103 (body-begin . "^ ?$")
104 (file-end . "^End of")
105 (prepare-body-function . nndoc-unquote-dashes)
106 (subtype digest guess))
108 (article-begin . "^\\\\\\\\\n")
109 (head-begin . "^Paper.*:")
110 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
112 (body-end . "-------------------------------------------------")
113 (file-end . "^Title: Recent Seminal")
114 (generate-head-function . nndoc-generate-lanl-gov-head)
115 (article-transform-function . nndoc-transform-lanl-gov-announce)
116 (subtype preprints guess))
118 (article-begin . "^\n")
119 (body-end-function . nndoc-rfc822-forward-body-end-function))
131 (defvoo nndoc-file-begin nil)
132 (defvoo nndoc-first-article nil)
133 (defvoo nndoc-article-begin nil)
134 (defvoo nndoc-head-begin nil)
135 (defvoo nndoc-head-end nil)
136 (defvoo nndoc-file-end nil)
137 (defvoo nndoc-body-begin nil)
138 (defvoo nndoc-body-end-function nil)
139 (defvoo nndoc-body-begin-function nil)
140 (defvoo nndoc-head-begin-function nil)
141 (defvoo nndoc-body-end nil)
142 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
143 ;; following items. ARTICLE acts as the association key and is an ordinal
144 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
145 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
146 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
147 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
148 ;; generation, respectively. Other headers usually follow directly from the
149 ;; buffer. Value `nil' means no insert.
150 (defvoo nndoc-dissection-alist nil)
151 (defvoo nndoc-prepare-body-function nil)
152 (defvoo nndoc-generate-head-function nil)
153 (defvoo nndoc-article-transform-function nil)
154 (defvoo nndoc-article-begin-function nil)
156 (defvoo nndoc-status-string "")
157 (defvoo nndoc-group-alist nil)
158 (defvoo nndoc-current-buffer nil
159 "Current nndoc news buffer.")
160 (defvoo nndoc-address nil)
162 (defconst nndoc-version "nndoc 1.0"
167 ;;; Interface functions
169 (nnoo-define-basics nndoc)
171 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
172 (when (nndoc-possibly-change-buffer newsgroup server)
174 (set-buffer nntp-server-buffer)
177 (if (stringp (car articles))
180 (when (setq entry (cdr (assq (setq article (pop articles))
181 nndoc-dissection-alist)))
182 (insert (format "221 %d Article retrieved.\n" article))
183 (if nndoc-generate-head-function
184 (funcall nndoc-generate-head-function article)
185 (insert-buffer-substring
186 nndoc-current-buffer (car entry) (nth 1 entry)))
187 (goto-char (point-max))
188 (unless (eq (char-after (1- (point))) ?\n)
190 (insert (format "Lines: %d\n" (nth 4 entry)))
193 (nnheader-fold-continuation-lines)
196 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
197 (nndoc-possibly-change-buffer newsgroup server)
199 (let ((buffer (or buffer nntp-server-buffer))
200 (entry (cdr (assq article nndoc-dissection-alist)))
205 (if (stringp article)
207 (insert-buffer-substring
208 nndoc-current-buffer (car entry) (nth 1 entry))
211 (insert-buffer-substring
212 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
214 (when nndoc-prepare-body-function
215 (funcall nndoc-prepare-body-function))
216 (when nndoc-article-transform-function
217 (funcall nndoc-article-transform-function article))
220 (deffoo nndoc-request-group (group &optional server dont-check)
224 ((not (nndoc-possibly-change-buffer group server))
225 (nnheader-report 'nndoc "No such file or buffer: %s"
228 (nnheader-report 'nndoc "Selected group %s" group)
230 ((zerop (setq number (length nndoc-dissection-alist)))
231 (nndoc-close-group group)
232 (nnheader-report 'nndoc "No articles in group %s" group))
234 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
236 (deffoo nndoc-request-type (group &optional article)
237 (cond ((not article) 'unknown)
238 (nndoc-post-type nndoc-post-type)
241 (deffoo nndoc-close-group (group &optional server)
242 (nndoc-possibly-change-buffer group server)
243 (and nndoc-current-buffer
244 (buffer-name nndoc-current-buffer)
245 (kill-buffer nndoc-current-buffer))
246 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
248 (setq nndoc-current-buffer nil)
249 (nnoo-close-server 'nndoc server)
250 (setq nndoc-dissection-alist nil)
253 (deffoo nndoc-request-list (&optional server)
256 (deffoo nndoc-request-newgroups (date &optional server)
259 (deffoo nndoc-request-list-newsgroups (&optional server)
263 ;;; Internal functions.
265 (defun nndoc-possibly-change-buffer (group source)
268 ;; The current buffer is this group's buffer.
269 ((and nndoc-current-buffer
270 (buffer-name nndoc-current-buffer)
271 (eq nndoc-current-buffer
272 (setq buf (cdr (assoc group nndoc-group-alist))))))
273 ;; We change buffers by taking an old from the group alist.
274 ;; `source' is either a string (a file name) or a buffer object.
276 (setq nndoc-current-buffer buf))
277 ;; It's a totally new group.
278 ((or (and (bufferp nndoc-address)
279 (buffer-name nndoc-address))
280 (and (stringp nndoc-address)
281 (file-exists-p nndoc-address)
282 (not (file-directory-p nndoc-address))))
283 (push (cons group (setq nndoc-current-buffer
285 (concat " *nndoc " group "*"))))
287 (setq nndoc-dissection-alist nil)
289 (set-buffer nndoc-current-buffer)
290 (mm-enable-multibyte)
292 (if (stringp nndoc-address)
293 (mm-insert-file-contents nndoc-address)
294 (insert-buffer-substring nndoc-address))
295 (run-hooks 'nndoc-open-document-hook))))
296 ;; Initialize the nndoc structures according to this new document.
297 (when (and nndoc-current-buffer
298 (not nndoc-dissection-alist))
300 (set-buffer nndoc-current-buffer)
302 (if (eq nndoc-article-type 'mime-parts)
303 (nndoc-dissect-mime-parts)
304 (nndoc-dissect-buffer))))
305 (unless nndoc-current-buffer
306 (nndoc-close-server))
307 ;; Return whether we managed to select a file.
308 nndoc-current-buffer))
311 ;;; Deciding what document type we have
314 (defun nndoc-set-delims ()
315 "Set the nndoc delimiter variables according to the type of the document."
316 (let ((vars '(nndoc-file-begin
318 nndoc-article-begin-function
319 nndoc-head-begin nndoc-head-end
320 nndoc-file-end nndoc-article-begin
321 nndoc-body-begin nndoc-body-end-function nndoc-body-end
322 nndoc-prepare-body-function nndoc-article-transform-function
323 nndoc-generate-head-function nndoc-body-begin-function
324 nndoc-head-begin-function)))
326 (set (pop vars) nil)))
328 ;; Guess away until we find the real file type.
329 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
331 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
332 ;; Set the nndoc variables.
334 (set (intern (format "nndoc-%s" (caar defs)))
337 (defun nndoc-guess-type (subtype)
338 (let ((alist nndoc-type-alist)
339 results result entry)
340 (while (and (not result)
341 (setq entry (pop alist)))
342 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
343 (goto-char (point-min))
344 (when (numberp (setq result (funcall (intern
345 (format "nndoc-%s-type-p"
347 (push (cons result entry) results)
349 (unless (or result results)
350 (error "Document is not of any recognized type"))
353 (cadar (sort results 'car-less-than-car)))))
356 ;;; Built-in type predicates and functions
359 (defun nndoc-mbox-type-p ()
360 (when (looking-at message-unix-mail-delimiter)
363 (defun nndoc-mbox-article-begin ()
364 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
365 (goto-char (match-beginning 0))))
367 (defun nndoc-mbox-body-end ()
372 (and (re-search-backward
373 (concat "^" message-unix-mail-delimiter) nil t)
375 (search-forward "\n\n" beg t)
377 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
378 (setq len (string-to-int (match-string 1)))
379 (search-forward "\n\n" beg t)
380 (unless (= (setq len (+ (point) len)) (point-max))
381 (and (< len (point-max))
383 (looking-at message-unix-mail-delimiter)))))
386 (defun nndoc-mmdf-type-p ()
387 (when (looking-at "\^A\^A\^A\^A$")
390 (defun nndoc-news-type-p ()
391 (when (looking-at "^Path:.*\n")
394 (defun nndoc-rnews-type-p ()
395 (when (looking-at "#! *rnews")
398 (defun nndoc-rnews-body-end ()
399 (and (re-search-backward nndoc-article-begin nil t)
401 (goto-char (+ (point) (string-to-int (match-string 1))))))
403 (defun nndoc-babyl-type-p ()
404 (when (re-search-forward "\^_\^L *\n" nil t)
407 (defun nndoc-babyl-body-begin ()
408 (re-search-forward "^\n" nil t)
409 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
410 (let ((next (or (save-excursion
411 (re-search-forward nndoc-article-begin nil t))
413 (unless (re-search-forward "^\n" next t)
417 (forward-line -1)))))
419 (defun nndoc-babyl-head-begin ()
420 (when (re-search-forward "^[0-9].*\n" nil t)
421 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
425 (defun nndoc-forward-type-p ()
426 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
427 (not (re-search-forward "^Subject:.*digest" nil t))
428 (not (re-search-backward "^From:" nil t 2))
429 (not (re-search-forward "^From:" nil t 2)))
432 (defun nndoc-rfc934-type-p ()
433 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
434 (not (re-search-forward "^Subject:.*digest" nil t))
435 (not (re-search-backward "^From:" nil t 2))
436 (not (re-search-forward "^From:" nil t 2)))
439 (defun nndoc-rfc822-forward-type-p ()
441 (message-narrow-to-head)
442 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
445 (defun nndoc-rfc822-forward-body-end-function ()
446 (goto-char (point-max)))
448 (defun nndoc-mime-parts-type-p ()
449 (let ((case-fold-search t)
450 (limit (search-forward "\n\n" nil t)))
451 (goto-char (point-min))
455 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
456 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
460 (defun nndoc-transform-mime-parts (article)
461 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
462 (headers (nth 5 entry)))
464 (goto-char (point-min))
467 (defun nndoc-generate-mime-parts-head (article)
468 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
469 (headers (nth 6 entry)))
471 (narrow-to-region (point) (point))
472 (insert-buffer-substring
473 nndoc-current-buffer (car entry) (nth 1 entry))
474 (goto-char (point-max)))
478 (defun nndoc-clari-briefs-type-p ()
479 (when (let ((case-fold-search nil))
480 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
483 (defun nndoc-transform-clari-briefs (article)
484 (goto-char (point-min))
485 (when (looking-at " *\\*\\(.*\\)\n")
486 (replace-match "" t t))
487 (nndoc-generate-clari-briefs-head article))
489 (defun nndoc-generate-clari-briefs-head (article)
490 (let ((entry (cdr (assq article nndoc-dissection-alist)))
493 (set-buffer nndoc-current-buffer)
495 (narrow-to-region (car entry) (nth 3 entry))
496 (goto-char (point-min))
497 (when (looking-at " *\\*\\(.*\\)$")
498 (setq subject (match-string 1))
499 (when (string-match "[ \t]+$" subject)
500 (setq subject (substring subject 0 (match-beginning 0)))))
502 (let ((case-fold-search nil))
504 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
505 (setq from (match-string 1)))))
506 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
507 "\nSubject: " (or subject "(no subject)") "\n")))
509 (defun nndoc-standard-digest-type-p ()
510 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
512 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
515 (defun nndoc-digest-body-end ()
516 (and (re-search-forward nndoc-article-begin nil t)
517 (goto-char (match-beginning 0))))
519 (defun nndoc-slack-digest-type-p ()
522 (defun nndoc-lanl-gov-announce-type-p ()
523 (when (let ((case-fold-search nil))
524 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
527 (defun nndoc-transform-lanl-gov-announce (article)
528 (goto-char (point-max))
529 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
530 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
531 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
532 ;; (replace-match "" t t))
535 (defun nndoc-generate-lanl-gov-head (article)
536 (let ((entry (cdr (assq article nndoc-dissection-alist)))
537 (e-mail "no address given")
540 (set-buffer nndoc-current-buffer)
542 (narrow-to-region (car entry) (nth 1 entry))
543 (goto-char (point-min))
544 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
545 (setq subject (concat " (" (match-string 1) ")"))
546 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
547 (setq e-mail (match-string 1)))
548 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
550 (setq subject (concat (match-string 1) subject))
551 (setq from (concat (match-string 2) " <" e-mail ">"))))
553 (while (and from (string-match "(\[^)\]*)" from))
554 (setq from (replace-match "" t t from)))
555 (insert "From: " (or from "unknown")
556 "\nSubject: " (or subject "(no subject)") "\n")))
558 (defun nndoc-nsmail-type-p ()
559 (when (looking-at "From - ")
562 (deffoo nndoc-request-accept-article (group &optional server last)
567 ;;; Functions for dissecting the documents
570 (defun nndoc-search (regexp)
572 (re-search-forward regexp nil t)
573 (beginning-of-line)))
575 (defun nndoc-dissect-buffer ()
576 "Go through the document and partition it into heads/bodies/articles."
579 head-begin head-end body-begin body-end)
580 (setq nndoc-dissection-alist nil)
582 (set-buffer nndoc-current-buffer)
583 (goto-char (point-min))
584 ;; Find the beginning of the file.
585 (when nndoc-file-begin
586 (nndoc-search nndoc-file-begin))
587 ;; Go through the file.
588 (while (if (and first nndoc-first-article)
589 (nndoc-search nndoc-first-article)
590 (nndoc-article-begin))
592 (cond (nndoc-head-begin-function
593 (funcall nndoc-head-begin-function))
595 (nndoc-search nndoc-head-begin)))
598 (looking-at nndoc-file-end)))
599 (goto-char (point-max))
600 (setq head-begin (point))
601 (nndoc-search (or nndoc-head-end "^$"))
602 (setq head-end (point))
603 (if nndoc-body-begin-function
604 (funcall nndoc-body-begin-function)
605 (nndoc-search (or nndoc-body-begin "^\n")))
606 (setq body-begin (point))
607 (or (and nndoc-body-end-function
608 (funcall nndoc-body-end-function))
610 (nndoc-search nndoc-body-end))
611 (nndoc-article-begin)
613 (goto-char (point-max))
615 (and (re-search-backward nndoc-file-end nil t)
616 (beginning-of-line)))))
617 (setq body-end (point))
618 (push (list (incf i) head-begin head-end body-begin body-end
619 (count-lines body-begin body-end))
620 nndoc-dissection-alist))))))
622 (defun nndoc-article-begin ()
623 (if nndoc-article-begin-function
624 (funcall nndoc-article-begin-function)
626 (nndoc-search nndoc-article-begin))))
628 (defun nndoc-unquote-dashes ()
629 "Unquote quoted non-separators in digests."
630 (while (re-search-forward "^- -"nil t)
631 (replace-match "-" t t)))
633 ;; Against compiler warnings.
634 (defvar nndoc-mime-split-ordinal)
636 (defun nndoc-dissect-mime-parts ()
637 "Go through a MIME composite article and partition it into sub-articles.
638 When a MIME entity contains sub-entities, dissection produces one article for
639 the header of this entity, and one article per sub-entity."
640 (setq nndoc-dissection-alist nil
641 nndoc-mime-split-ordinal 0)
643 (set-buffer nndoc-current-buffer)
644 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
646 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
648 "Dissect an entity, within a composite MIME message.
649 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
650 ARTICLE-INSERT should be added at beginning for generating a full article.
651 The string POSITION holds a dotted decimal representation of the article
652 position in the hierarchical structure, it is nil for the outer entity.
653 PARENT is the message-ID of the parent summary line, or nil for none."
654 (let ((case-fold-search t)
655 (message-id (nnmail-message-id))
656 head-end body-begin summary-insert message-rfc822 multipart-any
657 subject content-type type subtype boundary-regexp)
658 ;; Gracefully handle a missing body.
659 (goto-char head-begin)
660 (if (search-forward "\n\n" body-end t)
661 (setq head-end (1- (point))
663 (setq head-end body-end
664 body-begin body-end))
665 (narrow-to-region head-begin head-end)
666 ;; Save MIME attributes.
667 (goto-char head-begin)
668 (setq content-type (message-fetch-field "Content-Type"))
671 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
672 (setq type (downcase (match-string 1 content-type))
673 subtype (downcase (match-string 2 content-type))
674 message-rfc822 (and (string= type "message")
675 (string= subtype "rfc822"))
676 multipart-any (string= type "multipart")))
677 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
678 (setq subject (match-string 1 content-type)))
679 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
680 (setq boundary-regexp (concat "^--"
682 (match-string 1 content-type))
683 "\\(--\\)?[ \t]*\n"))))
685 (when (or multipart-any (not article-insert))
686 (setq subject (message-fetch-field "Subject"))))
690 ;; Prepare the article and summary inserts.
691 (unless article-insert
692 (setq article-insert (buffer-substring (point-min) (point-max))
693 head-end head-begin))
694 (setq summary-insert article-insert)
695 ;; - summary Subject.
697 (let ((line (concat "Subject: <" position
698 (and position multipart-any ".")
699 (and multipart-any "*")
700 (and (or position multipart-any) " ")
701 (cond ((string= subtype "plain") type)
702 ((string= subtype "basic") type)
708 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
709 (replace-match line t t summary-insert)
710 (concat summary-insert line))))
711 ;; - summary Message-ID.
713 (let ((line (concat "Message-ID: " message-id "\n")))
714 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
715 (replace-match line t t summary-insert)
716 (concat summary-insert line))))
717 ;; - summary References.
720 (let ((line (concat "References: " parent "\n")))
721 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
723 (replace-match line t t summary-insert)
724 (concat summary-insert line)))))
725 ;; Generate dissection information for this entity.
726 (push (list (incf nndoc-mime-split-ordinal)
727 head-begin head-end body-begin body-end
728 (count-lines body-begin body-end)
729 article-insert summary-insert)
730 nndoc-dissection-alist)
731 ;; Recurse for all sub-entities, if any.
736 (nndoc-dissect-mime-parts-sub body-begin body-end nil
737 position message-id)))
738 ((and multipart-any boundary-regexp)
739 (let ((part-counter 0)
740 part-begin part-end eof-flag)
741 (while (string-match "\
742 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
744 (setq article-insert (replace-match "" t t article-insert)))
745 (let ((case-fold-search nil))
746 (goto-char body-begin)
747 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
748 (while (not eof-flag)
749 (setq part-begin (point))
750 (cond ((re-search-forward boundary-regexp body-end t)
751 (or (not (match-string 1))
752 (string= (match-string 1) "")
755 (setq part-end (point))
757 (t (setq part-end body-end
760 (nndoc-dissect-mime-parts-sub
761 part-begin part-end article-insert
764 (format "%d" (incf part-counter)))
768 (defun nndoc-add-type (definition &optional position)
769 "Add document DEFINITION to the list of nndoc document definitions.
770 If POSITION is nil or `last', the definition will be added
771 as the last checked definition, if t or `first', add as the
772 first definition, and if any other symbol, add after that
773 symbol in the alist."
774 ;; First remove any old instances.
775 (gnus-pull (car definition) nndoc-type-alist)
776 ;; Then enter the new definition in the proper place.
778 ((or (null position) (eq position 'last))
779 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
780 ((or (eq position t) (eq position 'first))
781 (push definition nndoc-type-alist))
783 (let ((list (memq (assq position nndoc-type-alist)
786 (error "No such position: %s" position))
787 (setcdr list (cons definition (cdr list)))))))
791 ;;; nndoc.el ends here