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)
293 (mm-enable-multibyte)
295 (if (stringp nndoc-address)
296 (nnheader-insert-file-contents nndoc-address)
297 (insert-buffer-substring nndoc-address))
298 (run-hooks 'nndoc-open-document-hook))))
299 ;; Initialize the nndoc structures according to this new document.
300 (when (and nndoc-current-buffer
301 (not nndoc-dissection-alist))
303 (set-buffer nndoc-current-buffer)
305 (if (eq nndoc-article-type 'mime-parts)
306 (nndoc-dissect-mime-parts)
307 (nndoc-dissect-buffer))))
308 (unless nndoc-current-buffer
309 (nndoc-close-server))
310 ;; Return whether we managed to select a file.
311 nndoc-current-buffer))
314 ;;; Deciding what document type we have
317 (defun nndoc-set-delims ()
318 "Set the nndoc delimiter variables according to the type of the document."
319 (let ((vars '(nndoc-file-begin
321 nndoc-article-begin-function
322 nndoc-head-begin nndoc-head-end
323 nndoc-file-end nndoc-article-begin
324 nndoc-body-begin nndoc-body-end-function nndoc-body-end
325 nndoc-prepare-body-function nndoc-article-transform-function
326 nndoc-generate-head-function nndoc-body-begin-function
327 nndoc-head-begin-function)))
329 (set (pop vars) nil)))
331 ;; Guess away until we find the real file type.
332 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
334 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
335 ;; Set the nndoc variables.
337 (set (intern (format "nndoc-%s" (caar defs)))
340 (defun nndoc-guess-type (subtype)
341 (let ((alist nndoc-type-alist)
342 results result entry)
343 (while (and (not result)
344 (setq entry (pop alist)))
345 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
346 (goto-char (point-min))
347 (when (numberp (setq result (funcall (intern
348 (format "nndoc-%s-type-p"
350 (push (cons result entry) results)
352 (unless (or result results)
353 (error "Document is not of any recognized type"))
356 (cadar (sort results 'car-less-than-car)))))
359 ;;; Built-in type predicates and functions
362 (defun nndoc-mbox-type-p ()
363 (when (looking-at message-unix-mail-delimiter)
366 (defun nndoc-mbox-article-begin ()
367 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
368 (goto-char (match-beginning 0))))
370 (defun nndoc-mbox-body-end ()
375 (and (re-search-backward
376 (concat "^" message-unix-mail-delimiter) nil t)
378 (search-forward "\n\n" beg t)
380 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
381 (setq len (string-to-int (match-string 1)))
382 (search-forward "\n\n" beg t)
383 (unless (= (setq len (+ (point) len)) (point-max))
384 (and (< len (point-max))
386 (looking-at message-unix-mail-delimiter)))))
389 (defun nndoc-mmdf-type-p ()
390 (when (looking-at "\^A\^A\^A\^A$")
393 (defun nndoc-news-type-p ()
394 (when (looking-at "^Path:.*\n")
397 (defun nndoc-rnews-type-p ()
398 (when (looking-at "#! *rnews")
401 (defun nndoc-rnews-body-end ()
402 (and (re-search-backward nndoc-article-begin nil t)
404 (goto-char (+ (point) (string-to-int (match-string 1))))))
406 (defun nndoc-babyl-type-p ()
407 (when (re-search-forward "\^_\^L *\n" nil t)
410 (defun nndoc-babyl-body-begin ()
411 (re-search-forward "^\n" nil t)
412 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
413 (let ((next (or (save-excursion
414 (re-search-forward nndoc-article-begin nil t))
416 (unless (re-search-forward "^\n" next t)
420 (forward-line -1)))))
422 (defun nndoc-babyl-head-begin ()
423 (when (re-search-forward "^[0-9].*\n" nil t)
424 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
428 (defun nndoc-forward-type-p ()
429 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
430 (not (re-search-forward "^Subject:.*digest" nil t))
431 (not (re-search-backward "^From:" nil t 2))
432 (not (re-search-forward "^From:" nil t 2)))
435 (defun nndoc-rfc934-type-p ()
436 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
437 (not (re-search-forward "^Subject:.*digest" nil t))
438 (not (re-search-backward "^From:" nil t 2))
439 (not (re-search-forward "^From:" nil t 2)))
442 (defun nndoc-rfc822-forward-type-p ()
444 (message-narrow-to-head)
445 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
448 (defun nndoc-rfc822-forward-body-end-function ()
449 (goto-char (point-max)))
451 (defun nndoc-mime-parts-type-p ()
452 (let ((case-fold-search t)
453 (limit (search-forward "\n\n" nil t)))
454 (goto-char (point-min))
458 ^Content-Type:[ \t]*multipart/[a-z]+;\\(.*;\\)*"
459 "[ \t\n]*[ \t]boundary=\"?[^\"\n]*[^\" \t\n]")
463 (defun nndoc-transform-mime-parts (article)
464 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
465 (headers (nth 5 entry)))
467 (goto-char (point-min))
470 (defun nndoc-generate-mime-parts-head (article)
471 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
472 (headers (nth 6 entry)))
475 (insert-buffer-substring
476 nndoc-current-buffer (car entry) (nth 1 entry))))
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-mime-digest-type-p ()
510 (let ((case-fold-search t)
511 boundary-id b-delimiter entry)
514 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
515 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
518 (setq boundary-id (match-string 1)
519 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
520 (setq entry (assq 'mime-digest nndoc-type-alist))
523 (cons 'head-end "^ ?$")
524 (cons 'body-begin "^ ?\n")
525 (cons 'article-begin b-delimiter)
526 (cons 'body-end-function 'nndoc-digest-body-end)
527 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
530 (defun nndoc-standard-digest-type-p ()
531 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
533 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
536 (defun nndoc-digest-body-end ()
537 (and (re-search-forward nndoc-article-begin nil t)
538 (goto-char (match-beginning 0))))
540 (defun nndoc-slack-digest-type-p ()
543 (defun nndoc-lanl-gov-announce-type-p ()
544 (when (let ((case-fold-search nil))
545 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
548 (defun nndoc-transform-lanl-gov-announce (article)
549 (goto-char (point-max))
550 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
551 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
552 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
553 ;; (replace-match "" t t))
556 (defun nndoc-generate-lanl-gov-head (article)
557 (let ((entry (cdr (assq article nndoc-dissection-alist)))
558 (e-mail "no address given")
561 (set-buffer nndoc-current-buffer)
563 (narrow-to-region (car entry) (nth 1 entry))
564 (goto-char (point-min))
565 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
566 (setq subject (concat " (" (match-string 1) ")"))
567 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
568 (setq e-mail (match-string 1)))
569 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
571 (setq subject (concat (match-string 1) subject))
572 (setq from (concat (match-string 2) " <" e-mail ">"))))
574 (while (and from (string-match "(\[^)\]*)" from))
575 (setq from (replace-match "" t t from)))
576 (insert "From: " (or from "unknown")
577 "\nSubject: " (or subject "(no subject)") "\n")))
579 (deffoo nndoc-request-accept-article (group &optional server last)
585 ;;; Functions for dissecting the documents
588 (defun nndoc-search (regexp)
590 (re-search-forward regexp nil t)
591 (beginning-of-line)))
593 (defun nndoc-dissect-buffer ()
594 "Go through the document and partition it into heads/bodies/articles."
597 head-begin head-end body-begin body-end)
598 (setq nndoc-dissection-alist nil)
600 (set-buffer nndoc-current-buffer)
601 (goto-char (point-min))
602 ;; Find the beginning of the file.
603 (when nndoc-file-begin
604 (nndoc-search nndoc-file-begin))
605 ;; Go through the file.
606 (while (if (and first nndoc-first-article)
607 (nndoc-search nndoc-first-article)
608 (nndoc-article-begin))
610 (cond (nndoc-head-begin-function
611 (funcall nndoc-head-begin-function))
613 (nndoc-search nndoc-head-begin)))
616 (looking-at nndoc-file-end)))
617 (goto-char (point-max))
618 (setq head-begin (point))
619 (nndoc-search (or nndoc-head-end "^$"))
620 (setq head-end (point))
621 (if nndoc-body-begin-function
622 (funcall nndoc-body-begin-function)
623 (nndoc-search (or nndoc-body-begin "^\n")))
624 (setq body-begin (point))
625 (or (and nndoc-body-end-function
626 (funcall nndoc-body-end-function))
628 (nndoc-search nndoc-body-end))
629 (nndoc-article-begin)
631 (goto-char (point-max))
633 (and (re-search-backward nndoc-file-end nil t)
634 (beginning-of-line)))))
635 (setq body-end (point))
636 (push (list (incf i) head-begin head-end body-begin body-end
637 (count-lines body-begin body-end))
638 nndoc-dissection-alist))))))
640 (defun nndoc-article-begin ()
641 (if nndoc-article-begin-function
642 (funcall nndoc-article-begin-function)
644 (nndoc-search nndoc-article-begin))))
646 (defun nndoc-unquote-dashes ()
647 "Unquote quoted non-separators in digests."
648 (while (re-search-forward "^- -"nil t)
649 (replace-match "-" t t)))
651 ;; Against compiler warnings.
652 (defvar nndoc-mime-split-ordinal)
654 (defun nndoc-dissect-mime-parts ()
655 "Go through a MIME composite article and partition it into sub-articles.
656 When a MIME entity contains sub-entities, dissection produces one article for
657 the header of this entity, and one article per sub-entity."
658 (setq nndoc-dissection-alist nil
659 nndoc-mime-split-ordinal 0)
661 (set-buffer nndoc-current-buffer)
662 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
664 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
666 "Dissect an entity, within a composite MIME message.
667 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
668 ARTICLE-INSERT should be added at beginning for generating a full article.
669 The string POSITION holds a dotted decimal representation of the article
670 position in the hierarchical structure, it is nil for the outer entity.
671 PARENT is the message-ID of the parent summary line, or nil for none."
672 (let ((case-fold-search t)
673 (message-id (nnmail-message-id))
674 head-end body-begin summary-insert message-rfc822 multipart-any
675 subject content-type type subtype boundary-regexp)
676 ;; Gracefully handle a missing body.
677 (goto-char head-begin)
678 (if (search-forward "\n\n" body-end t)
679 (setq head-end (1- (point))
681 (setq head-end body-end
682 body-begin body-end))
683 (narrow-to-region head-begin head-end)
684 ;; Save MIME attributes.
685 (goto-char head-begin)
686 (setq content-type (message-fetch-field "Content-Type"))
688 (when (string-match "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
689 (setq type (downcase (match-string 1 content-type))
690 subtype (downcase (match-string 2 content-type))
691 message-rfc822 (and (string= type "message")
692 (string= subtype "rfc822"))
693 multipart-any (string= type "multipart")))
694 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
695 (setq subject (match-string 1 content-type)))
696 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
697 (setq boundary-regexp (concat "\n--"
699 (match-string 1 content-type))
700 "\\(--\\)?[ \t]*\n"))))
702 (when (or multipart-any (not article-insert))
703 (setq subject (message-fetch-field "Subject"))))
707 ;; Prepare the article and summary inserts.
708 (unless article-insert
709 (setq article-insert (buffer-substring (point-min) (point-max))
710 head-end head-begin))
711 (setq summary-insert article-insert)
712 ;; - summary Subject.
714 (let ((line (concat "Subject: <" position
715 (and position multipart-any ".")
716 (and multipart-any "*")
717 (and (or position multipart-any) " ")
718 (cond ((string= subtype "plain") type)
719 ((string= subtype "basic") type)
725 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
726 (replace-match line t t summary-insert)
727 (concat summary-insert line))))
728 ;; - summary Message-ID.
730 (let ((line (concat "Message-ID: " message-id "\n")))
731 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
732 (replace-match line t t summary-insert)
733 (concat summary-insert line))))
734 ;; - summary References.
737 (let ((line (concat "References: " parent "\n")))
738 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
740 (replace-match line t t summary-insert)
741 (concat summary-insert line)))))
742 ;; Generate dissection information for this entity.
743 (push (list (incf nndoc-mime-split-ordinal)
744 head-begin head-end body-begin body-end
745 (count-lines body-begin body-end)
746 article-insert summary-insert)
747 nndoc-dissection-alist)
748 ;; Recurse for all sub-entities, if any.
753 (nndoc-dissect-mime-parts-sub body-begin body-end nil
754 position message-id)))
755 ((and multipart-any boundary-regexp)
756 (let ((part-counter 0)
757 part-begin part-end eof-flag)
758 (while (string-match "\
759 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
761 (setq article-insert (replace-match "" t t article-insert)))
762 (let ((case-fold-search nil))
763 (goto-char body-begin)
764 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
765 (while (not eof-flag)
766 (setq part-begin (point))
767 (cond ((re-search-forward boundary-regexp body-end t)
768 (or (not (match-string 1))
769 (string= (match-string 1) "")
772 (setq part-end (point))
774 (t (setq part-end body-end
777 (nndoc-dissect-mime-parts-sub
778 part-begin part-end article-insert
781 (format "%d" (incf part-counter)))
785 (defun nndoc-add-type (definition &optional position)
786 "Add document DEFINITION to the list of nndoc document definitions.
787 If POSITION is nil or `last', the definition will be added
788 as the last checked definition, if t or `first', add as the
789 first definition, and if any other symbol, add after that
790 symbol in the alist."
791 ;; First remove any old instances.
792 (gnus-pull (car definition) nndoc-type-alist)
793 ;; Then enter the new definition in the proper place.
795 ((or (null position) (eq position 'last))
796 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
797 ((or (eq position t) (eq position 'first))
798 (push definition nndoc-type-alist))
800 (let ((list (memq (assq position nndoc-type-alist)
803 (error "No such position: %s" position))
804 (setcdr list (cons definition (cdr list)))))))
808 ;;; nndoc.el ends here