1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995,96,97,98 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-digest', `mime-parts', `standard-digest',
42 `slack-digest', `clari-briefs' 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 . "^Path:"))
59 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
60 (body-end-function . nndoc-rnews-body-end))
62 (article-begin-function . nndoc-mbox-article-begin)
63 (body-end-function . nndoc-mbox-body-end))
65 (article-begin . "\^_\^L *\n")
67 (body-begin-function . nndoc-babyl-body-begin)
68 (head-begin-function . nndoc-babyl-head-begin))
70 (article-begin . "^-+ Start of forwarded message -+\n+")
71 (body-end . "^-+ End of forwarded message -+$")
72 (prepare-body-function . nndoc-unquote-dashes))
74 (article-begin . "^--.*\n+")
76 (prepare-body-function . nndoc-unquote-dashes))
78 (article-begin . "^ \\*")
79 (body-end . "^\t------*[ \t]^*\n^ \\*")
82 (generate-head-function . nndoc-generate-clari-briefs-head)
83 (article-transform-function . nndoc-transform-clari-briefs))
89 (subtype digest guess))
91 (generate-head-function . nndoc-generate-mime-parts-head)
92 (article-transform-function . nndoc-transform-mime-parts))
94 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
95 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
96 (prepare-body-function . nndoc-unquote-dashes)
97 (body-end-function . nndoc-digest-body-end)
99 (body-begin . "^ *\n")
100 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
101 (subtype digest guess))
103 (article-begin . "^------------------------------*[\n \t]+")
105 (body-end-function . nndoc-digest-body-end)
106 (body-begin . "^ ?$")
107 (file-end . "^End of")
108 (prepare-body-function . nndoc-unquote-dashes)
109 (subtype digest guess))
111 (article-begin . "^\\\\\\\\\n")
112 (head-begin . "^Paper.*:")
113 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
115 (body-end . "-------------------------------------------------")
116 (file-end . "^Title: Recent Seminal")
117 (generate-head-function . nndoc-generate-lanl-gov-head)
118 (article-transform-function . nndoc-transform-lanl-gov-announce)
119 (subtype preprints guess))
121 (article-begin . "^\n")
122 (body-end-function . nndoc-rfc822-forward-body-end-function))
134 (defvoo nndoc-file-begin nil)
135 (defvoo nndoc-first-article nil)
136 (defvoo nndoc-article-begin nil)
137 (defvoo nndoc-head-begin nil)
138 (defvoo nndoc-head-end nil)
139 (defvoo nndoc-file-end nil)
140 (defvoo nndoc-body-begin nil)
141 (defvoo nndoc-body-end-function nil)
142 (defvoo nndoc-body-begin-function nil)
143 (defvoo nndoc-head-begin-function nil)
144 (defvoo nndoc-body-end nil)
145 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
146 ;; following items. ARTICLE act as the association key and is an ordinal
147 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
148 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
149 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
150 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
151 ;; generation, respectively. Other headers usually follow directly from the
152 ;; buffer. Value `nil' means no insert.
153 (defvoo nndoc-dissection-alist nil)
154 (defvoo nndoc-prepare-body-function nil)
155 (defvoo nndoc-generate-head-function nil)
156 (defvoo nndoc-article-transform-function nil)
157 (defvoo nndoc-article-begin-function nil)
159 (defvoo nndoc-status-string "")
160 (defvoo nndoc-group-alist nil)
161 (defvoo nndoc-current-buffer nil
162 "Current nndoc news buffer.")
163 (defvoo nndoc-address nil)
165 (defconst nndoc-version "nndoc 1.0"
170 ;;; Interface functions
172 (nnoo-define-basics nndoc)
174 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
175 (when (nndoc-possibly-change-buffer newsgroup server)
177 (set-buffer nntp-server-buffer)
180 (if (stringp (car articles))
183 (when (setq entry (cdr (assq (setq article (pop articles))
184 nndoc-dissection-alist)))
185 (insert (format "221 %d Article retrieved.\n" article))
186 (if nndoc-generate-head-function
187 (funcall nndoc-generate-head-function article)
188 (insert-buffer-substring
189 nndoc-current-buffer (car entry) (nth 1 entry)))
190 (goto-char (point-max))
191 (unless (= (char-after (1- (point))) ?\n)
193 (insert (format "Lines: %d\n" (nth 4 entry)))
196 (nnheader-fold-continuation-lines)
199 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
200 (nndoc-possibly-change-buffer newsgroup server)
202 (let ((buffer (or buffer nntp-server-buffer))
203 (entry (cdr (assq article nndoc-dissection-alist)))
208 (if (stringp article)
210 (insert-buffer-substring
211 nndoc-current-buffer (car entry) (nth 1 entry))
214 (insert-buffer-substring
215 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
217 (when nndoc-prepare-body-function
218 (funcall nndoc-prepare-body-function))
219 (when nndoc-article-transform-function
220 (funcall nndoc-article-transform-function article))
223 (deffoo nndoc-request-group (group &optional server dont-check)
227 ((not (nndoc-possibly-change-buffer group server))
228 (nnheader-report 'nndoc "No such file or buffer: %s"
231 (nnheader-report 'nndoc "Selected group %s" group)
233 ((zerop (setq number (length nndoc-dissection-alist)))
234 (nndoc-close-group group)
235 (nnheader-report 'nndoc "No articles in group %s" group))
237 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
239 (deffoo nndoc-request-type (group &optional article)
240 (cond ((not article) 'unknown)
241 (nndoc-post-type nndoc-post-type)
244 (deffoo nndoc-close-group (group &optional server)
245 (nndoc-possibly-change-buffer group server)
246 (and nndoc-current-buffer
247 (buffer-name nndoc-current-buffer)
248 (kill-buffer nndoc-current-buffer))
249 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
251 (setq nndoc-current-buffer nil)
252 (nnoo-close-server 'nndoc server)
253 (setq nndoc-dissection-alist nil)
256 (deffoo nndoc-request-list (&optional server)
259 (deffoo nndoc-request-newgroups (date &optional server)
262 (deffoo nndoc-request-list-newsgroups (&optional server)
266 ;;; Internal functions.
268 (defun nndoc-possibly-change-buffer (group source)
271 ;; The current buffer is this group's buffer.
272 ((and nndoc-current-buffer
273 (buffer-name nndoc-current-buffer)
274 (eq nndoc-current-buffer
275 (setq buf (cdr (assoc group nndoc-group-alist))))))
276 ;; We change buffers by taking an old from the group alist.
277 ;; `source' is either a string (a file name) or a buffer object.
279 (setq nndoc-current-buffer buf))
280 ;; It's a totally new group.
281 ((or (and (bufferp nndoc-address)
282 (buffer-name nndoc-address))
283 (and (stringp nndoc-address)
284 (file-exists-p nndoc-address)
285 (not (file-directory-p nndoc-address))))
286 (push (cons group (setq nndoc-current-buffer
288 (concat " *nndoc " group "*"))))
290 (setq nndoc-dissection-alist nil)
292 (set-buffer nndoc-current-buffer)
294 (if (stringp nndoc-address)
295 (nnheader-insert-file-contents nndoc-address)
296 (insert-buffer-substring nndoc-address))
297 (run-hooks 'nndoc-open-document-hook))))
298 ;; Initialize the nndoc structures according to this new document.
299 (when (and nndoc-current-buffer
300 (not nndoc-dissection-alist))
302 (set-buffer nndoc-current-buffer)
304 (if (eq nndoc-article-type 'mime-parts)
305 (nndoc-dissect-mime-parts)
306 (nndoc-dissect-buffer))))
307 (unless nndoc-current-buffer
308 (nndoc-close-server))
309 ;; Return whether we managed to select a file.
310 nndoc-current-buffer))
313 ;;; Deciding what document type we have
316 (defun nndoc-set-delims ()
317 "Set the nndoc delimiter variables according to the type of the document."
318 (let ((vars '(nndoc-file-begin
320 nndoc-article-begin-function
321 nndoc-head-begin nndoc-head-end
322 nndoc-file-end nndoc-article-begin
323 nndoc-body-begin nndoc-body-end-function nndoc-body-end
324 nndoc-prepare-body-function nndoc-article-transform-function
325 nndoc-generate-head-function nndoc-body-begin-function
326 nndoc-head-begin-function)))
328 (set (pop vars) nil)))
330 ;; Guess away until we find the real file type.
331 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
333 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
334 ;; Set the nndoc variables.
336 (set (intern (format "nndoc-%s" (caar defs)))
339 (defun nndoc-guess-type (subtype)
340 (let ((alist nndoc-type-alist)
341 results result entry)
342 (while (and (not result)
343 (setq entry (pop alist)))
344 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
345 (goto-char (point-min))
346 (when (numberp (setq result (funcall (intern
347 (format "nndoc-%s-type-p"
349 (push (cons result entry) results)
351 (unless (or result results)
352 (error "Document is not of any recognized type"))
355 (cadar (sort results 'car-less-than-car)))))
358 ;;; Built-in type predicates and functions
361 (defun nndoc-mbox-type-p ()
362 (when (looking-at message-unix-mail-delimiter)
365 (defun nndoc-mbox-article-begin ()
366 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
367 (goto-char (match-beginning 0))))
369 (defun nndoc-mbox-body-end ()
374 (and (re-search-backward
375 (concat "^" message-unix-mail-delimiter) nil t)
377 (search-forward "\n\n" beg t)
379 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
380 (setq len (string-to-int (match-string 1)))
381 (search-forward "\n\n" beg t)
382 (unless (= (setq len (+ (point) len)) (point-max))
383 (and (< len (point-max))
385 (looking-at message-unix-mail-delimiter)))))
388 (defun nndoc-mmdf-type-p ()
389 (when (looking-at "\^A\^A\^A\^A$")
392 (defun nndoc-news-type-p ()
393 (when (looking-at "^Path:.*\n")
396 (defun nndoc-rnews-type-p ()
397 (when (looking-at "#! *rnews")
400 (defun nndoc-rnews-body-end ()
401 (and (re-search-backward nndoc-article-begin nil t)
403 (goto-char (+ (point) (string-to-int (match-string 1))))))
405 (defun nndoc-babyl-type-p ()
406 (when (re-search-forward "\^_\^L *\n" nil t)
409 (defun nndoc-babyl-body-begin ()
410 (re-search-forward "^\n" nil t)
411 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
412 (let ((next (or (save-excursion
413 (re-search-forward nndoc-article-begin nil t))
415 (unless (re-search-forward "^\n" next t)
419 (forward-line -1)))))
421 (defun nndoc-babyl-head-begin ()
422 (when (re-search-forward "^[0-9].*\n" nil t)
423 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
427 (defun nndoc-forward-type-p ()
428 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
429 (not (re-search-forward "^Subject:.*digest" nil t))
430 (not (re-search-backward "^From:" nil t 2))
431 (not (re-search-forward "^From:" nil t 2)))
434 (defun nndoc-rfc934-type-p ()
435 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
436 (not (re-search-forward "^Subject:.*digest" nil t))
437 (not (re-search-backward "^From:" nil t 2))
438 (not (re-search-forward "^From:" nil t 2)))
441 (defun nndoc-rfc822-forward-type-p ()
443 (message-narrow-to-head)
444 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
447 (defun nndoc-rfc822-forward-body-end-function ()
448 (goto-char (point-max)))
450 (defun nndoc-mime-parts-type-p ()
451 (let ((case-fold-search t)
452 (limit (search-forward "\n\n" nil t)))
453 (goto-char (point-min))
457 ^Content-Type:[ \t]*multipart/[a-z]+ *;\\(.*;\\)*"
458 "[ \t\n]*[ \t]boundary=\"?[^\"\n]*[^\" \t\n]")
462 (defun nndoc-transform-mime-parts (article)
463 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
464 (headers (nth 5 entry)))
466 (goto-char (point-min))
469 (defun nndoc-generate-mime-parts-head (article)
470 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
471 (headers (nth 6 entry)))
474 (insert-buffer-substring
475 nndoc-current-buffer (car entry) (nth 1 entry))))
477 (defun nndoc-clari-briefs-type-p ()
478 (when (let ((case-fold-search nil))
479 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
482 (defun nndoc-transform-clari-briefs (article)
483 (goto-char (point-min))
484 (when (looking-at " *\\*\\(.*\\)\n")
485 (replace-match "" t t))
486 (nndoc-generate-clari-briefs-head article))
488 (defun nndoc-generate-clari-briefs-head (article)
489 (let ((entry (cdr (assq article nndoc-dissection-alist)))
492 (set-buffer nndoc-current-buffer)
494 (narrow-to-region (car entry) (nth 3 entry))
495 (goto-char (point-min))
496 (when (looking-at " *\\*\\(.*\\)$")
497 (setq subject (match-string 1))
498 (when (string-match "[ \t]+$" subject)
499 (setq subject (substring subject 0 (match-beginning 0)))))
501 (let ((case-fold-search nil))
503 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
504 (setq from (match-string 1)))))
505 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
506 "\nSubject: " (or subject "(no subject)") "\n")))
508 (defun nndoc-mime-digest-type-p ()
509 (let ((case-fold-search t)
510 boundary-id b-delimiter entry)
513 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
514 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
517 (setq boundary-id (match-string 1)
518 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
519 (setq entry (assq 'mime-digest nndoc-type-alist))
522 (cons 'head-end "^ ?$")
523 (cons 'body-begin "^ ?\n")
524 (cons 'article-begin b-delimiter)
525 (cons 'body-end-function 'nndoc-digest-body-end)
526 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
529 (defun nndoc-standard-digest-type-p ()
530 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
532 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
535 (defun nndoc-digest-body-end ()
536 (and (re-search-forward nndoc-article-begin nil t)
537 (goto-char (match-beginning 0))))
539 (defun nndoc-slack-digest-type-p ()
542 (defun nndoc-lanl-gov-announce-type-p ()
543 (when (let ((case-fold-search nil))
544 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
547 (defun nndoc-transform-lanl-gov-announce (article)
548 (goto-char (point-max))
549 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
550 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
551 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
552 ;; (replace-match "" t t))
555 (defun nndoc-generate-lanl-gov-head (article)
556 (let ((entry (cdr (assq article nndoc-dissection-alist)))
557 (e-mail "no address given")
560 (set-buffer nndoc-current-buffer)
562 (narrow-to-region (car entry) (nth 1 entry))
563 (goto-char (point-min))
564 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
565 (setq subject (concat " (" (match-string 1) ")"))
566 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
567 (setq e-mail (match-string 1)))
568 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
570 (setq subject (concat (match-string 1) subject))
571 (setq from (concat (match-string 2) " <" e-mail ">"))))
573 (while (and from (string-match "(\[^)\]*)" from))
574 (setq from (replace-match "" t t from)))
575 (insert "From: " (or from "unknown")
576 "\nSubject: " (or subject "(no subject)") "\n")))
578 (deffoo nndoc-request-accept-article (group &optional server last)
584 ;;; Functions for dissecting the documents
587 (defun nndoc-search (regexp)
589 (re-search-forward regexp nil t)
590 (beginning-of-line)))
592 (defun nndoc-dissect-buffer ()
593 "Go through the document and partition it into heads/bodies/articles."
596 head-begin head-end body-begin body-end)
597 (setq nndoc-dissection-alist nil)
599 (set-buffer nndoc-current-buffer)
600 (goto-char (point-min))
601 ;; Find the beginning of the file.
602 (when nndoc-file-begin
603 (nndoc-search nndoc-file-begin))
604 ;; Go through the file.
605 (while (if (and first nndoc-first-article)
606 (nndoc-search nndoc-first-article)
607 (nndoc-article-begin))
609 (cond (nndoc-head-begin-function
610 (funcall nndoc-head-begin-function))
612 (nndoc-search nndoc-head-begin)))
615 (looking-at nndoc-file-end)))
616 (goto-char (point-max))
617 (setq head-begin (point))
618 (nndoc-search (or nndoc-head-end "^$"))
619 (setq head-end (point))
620 (if nndoc-body-begin-function
621 (funcall nndoc-body-begin-function)
622 (nndoc-search (or nndoc-body-begin "^\n")))
623 (setq body-begin (point))
624 (or (and nndoc-body-end-function
625 (funcall nndoc-body-end-function))
627 (nndoc-search nndoc-body-end))
628 (nndoc-article-begin)
630 (goto-char (point-max))
632 (and (re-search-backward nndoc-file-end nil t)
633 (beginning-of-line)))))
634 (setq body-end (point))
635 (push (list (incf i) head-begin head-end body-begin body-end
636 (count-lines body-begin body-end))
637 nndoc-dissection-alist))))))
639 (defun nndoc-article-begin ()
640 (if nndoc-article-begin-function
641 (funcall nndoc-article-begin-function)
643 (nndoc-search nndoc-article-begin))))
645 (defun nndoc-unquote-dashes ()
646 "Unquote quoted non-separators in digests."
647 (while (re-search-forward "^- -"nil t)
648 (replace-match "-" t t)))
650 ;; Against compiler warnings.
651 (defvar nndoc-mime-split-ordinal)
653 (defun nndoc-dissect-mime-parts ()
654 "Go through a MIME composite article and partition it into sub-articles.
655 When a MIME entity contains sub-entities, dissection produces one article for
656 the header of this entity, and one article per sub-entity."
657 (setq nndoc-dissection-alist nil
658 nndoc-mime-split-ordinal 0)
660 (set-buffer nndoc-current-buffer)
661 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
663 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
665 "Dissect an entity, within a composite MIME message.
666 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
667 ARTICLE-INSERT should be added at beginning for generating a full article.
668 The string POSITION holds a dotted decimal representation of the article
669 position in the hierarchical structure, it is nil for the outer entity.
670 PARENT is the message-ID of the parent summary line, or nil for none."
671 (let ((case-fold-search t)
672 (message-id (nnmail-message-id))
673 head-end body-begin summary-insert message-rfc822 multipart-any
674 subject content-type type subtype boundary-regexp)
675 ;; Gracefully handle a missing body.
676 (goto-char head-begin)
677 (if (search-forward "\n\n" body-end t)
678 (setq head-end (1- (point))
680 (setq head-end body-end
681 body-begin body-end))
682 (narrow-to-region head-begin head-end)
683 ;; Save MIME attributes.
684 (goto-char head-begin)
685 (setq content-type (message-fetch-field "Content-Type"))
687 (when (string-match "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
688 (setq type (downcase (match-string 1 content-type))
689 subtype (downcase (match-string 2 content-type))
690 message-rfc822 (and (string= type "message")
691 (string= subtype "rfc822"))
692 multipart-any (string= type "multipart")))
693 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
694 (setq subject (match-string 1 content-type)))
695 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
696 (setq boundary-regexp (concat "\n--"
698 (match-string 1 content-type))
699 "\\(--\\)?[ \t]*\n"))))
701 (when (or multipart-any (not article-insert))
702 (setq subject (message-fetch-field "Subject"))))
706 ;; Prepare the article and summary inserts.
707 (unless article-insert
708 (setq article-insert (buffer-substring (point-min) (point-max))
709 head-end head-begin))
710 (setq summary-insert article-insert)
711 ;; - summary Subject.
713 (let ((line (concat "Subject: <" position
714 (and position multipart-any ".")
715 (and multipart-any "*")
716 (and (or position multipart-any) " ")
717 (cond ((string= subtype "plain") type)
718 ((string= subtype "basic") type)
724 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
725 (replace-match line t t summary-insert)
726 (concat summary-insert line))))
727 ;; - summary Message-ID.
729 (let ((line (concat "Message-ID: " message-id "\n")))
730 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
731 (replace-match line t t summary-insert)
732 (concat summary-insert line))))
733 ;; - summary References.
736 (let ((line (concat "References: " parent "\n")))
737 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
739 (replace-match line t t summary-insert)
740 (concat summary-insert line)))))
741 ;; Generate dissection information for this entity.
742 (push (list (incf nndoc-mime-split-ordinal)
743 head-begin head-end body-begin body-end
744 (count-lines body-begin body-end)
745 article-insert summary-insert)
746 nndoc-dissection-alist)
747 ;; Recurse for all sub-entities, if any.
752 (nndoc-dissect-mime-parts-sub body-begin body-end nil
753 position message-id)))
754 ((and multipart-any boundary-regexp)
755 (let ((part-counter 0)
756 part-begin part-end eof-flag)
757 (while (string-match "\
758 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
760 (setq article-insert (replace-match "" t t article-insert)))
761 (let ((case-fold-search nil))
762 (goto-char body-begin)
763 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
764 (while (not eof-flag)
765 (setq part-begin (point))
766 (cond ((re-search-forward boundary-regexp body-end t)
767 (or (not (match-string 1))
768 (string= (match-string 1) "")
771 (setq part-end (point))
773 (t (setq part-end body-end
776 (nndoc-dissect-mime-parts-sub
777 part-begin part-end article-insert
780 (format "%d" (incf part-counter)))
784 (defun nndoc-add-type (definition &optional position)
785 "Add document DEFINITION to the list of nndoc document definitions.
786 If POSITION is nil or `last', the definition will be added
787 as the last checked definition, if t or `first', add as the
788 first definition, and if any other symbol, add after that
789 symbol in the alist."
790 ;; First remove any old instances.
791 (gnus-pull (car definition) nndoc-type-alist)
792 ;; Then enter the new definition in the proper place.
794 ((or (null position) (eq position 'last))
795 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
796 ((or (eq position t) (eq position 'first))
797 (push definition nndoc-type-alist))
799 (let ((list (memq (assq position nndoc-type-alist)
802 (error "No such position: %s" position))
803 (setcdr list (cons definition (cdr list)))))))
807 ;;; nndoc.el ends here