1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
36 (eval-when-compile (require 'cl))
40 (defvoo nndoc-article-type 'guess
42 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
43 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
44 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
46 (defvoo nndoc-post-type 'mail
47 "*Whether the nndoc group is `mail' or `post'.")
49 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
50 "Hook run after opening a document.
51 The default function removes all trailing carriage returns
54 (defvar nndoc-type-alist
56 (article-begin . "^\^A\^A\^A\^A\n")
57 (body-end . "^\^A\^A\^A\^A\n"))
59 (article-begin . "^From - "))
61 (article-begin . "^Path:"))
63 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
64 (body-end-function . nndoc-rnews-body-end))
66 (article-begin-function . nndoc-mbox-article-begin)
67 (body-end-function . nndoc-mbox-body-end))
69 (article-begin . "\^_\^L *\n")
71 (body-begin-function . nndoc-babyl-body-begin)
72 (head-begin-function . nndoc-babyl-head-begin))
74 (article-begin . "^-+ \\(Start of \\)?forwarded message.*\n+")
75 (body-end . "^-+ End \\(of \\)?forwarded message.*$")
76 (prepare-body-function . nndoc-unquote-dashes))
78 (article-begin . "^--.*\n+")
80 (prepare-body-function . nndoc-unquote-dashes))
82 (article-begin . "^ \\*")
83 (body-end . "^\t------*[ \t]^*\n^ \\*")
86 (generate-head-function . nndoc-generate-clari-briefs-head)
87 (article-transform-function . nndoc-transform-clari-briefs))
90 (head-begin . "^ ?\n")
94 (subtype digest guess))
96 (generate-head-function . nndoc-generate-mime-parts-head)
97 (article-transform-function . nndoc-transform-mime-parts))
99 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
100 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
101 (prepare-body-function . nndoc-unquote-dashes)
102 (body-end-function . nndoc-digest-body-end)
104 (body-begin . "^ *\n")
105 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
106 (subtype digest guess))
108 (article-begin . "^------------------------------*[\n \t]+")
110 (body-end-function . nndoc-digest-body-end)
111 (body-begin . "^ ?$")
112 (file-end . "^End of")
113 (prepare-body-function . nndoc-unquote-dashes)
114 (subtype digest guess))
116 (article-begin . "^\\\\\\\\\n")
117 (head-begin . "^Paper.*:")
118 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
120 (body-end . "-------------------------------------------------")
121 (file-end . "^Title: Recent Seminal")
122 (generate-head-function . nndoc-generate-lanl-gov-head)
123 (article-transform-function . nndoc-transform-lanl-gov-announce)
124 (subtype preprints guess))
126 (article-begin . "^\n")
127 (body-end-function . nndoc-rfc822-forward-body-end-function))
139 (defvoo nndoc-file-begin nil)
140 (defvoo nndoc-first-article nil)
141 (defvoo nndoc-article-begin nil)
142 (defvoo nndoc-head-begin nil)
143 (defvoo nndoc-head-end nil)
144 (defvoo nndoc-file-end nil)
145 (defvoo nndoc-body-begin nil)
146 (defvoo nndoc-body-end-function nil)
147 (defvoo nndoc-body-begin-function nil)
148 (defvoo nndoc-head-begin-function nil)
149 (defvoo nndoc-body-end nil)
150 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
151 ;; following items. ARTICLE acts as the association key and is an ordinal
152 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
153 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
154 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
155 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
156 ;; generation, respectively. Other headers usually follow directly from the
157 ;; buffer. Value `nil' means no insert.
158 (defvoo nndoc-dissection-alist nil)
159 (defvoo nndoc-prepare-body-function nil)
160 (defvoo nndoc-generate-head-function nil)
161 (defvoo nndoc-article-transform-function nil)
162 (defvoo nndoc-article-begin-function nil)
164 (defvoo nndoc-status-string "")
165 (defvoo nndoc-group-alist nil)
166 (defvoo nndoc-current-buffer nil
167 "Current nndoc news buffer.")
168 (defvoo nndoc-address nil)
170 (defconst nndoc-version "nndoc 1.0"
175 ;;; Interface functions
177 (nnoo-define-basics nndoc)
179 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
180 (when (nndoc-possibly-change-buffer newsgroup server)
182 (set-buffer nntp-server-buffer)
185 (if (stringp (car articles))
188 (when (setq entry (cdr (assq (setq article (pop articles))
189 nndoc-dissection-alist)))
190 (insert (format "221 %d Article retrieved.\n" article))
191 (if nndoc-generate-head-function
192 (funcall nndoc-generate-head-function article)
193 (insert-buffer-substring
194 nndoc-current-buffer (car entry) (nth 1 entry)))
195 (goto-char (point-max))
196 (unless (eq (char-after (1- (point))) ?\n)
198 (insert (format "Lines: %d\n" (nth 4 entry)))
201 (nnheader-fold-continuation-lines)
204 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
205 (nndoc-possibly-change-buffer newsgroup server)
207 (let ((buffer (or buffer nntp-server-buffer))
208 (entry (cdr (assq article nndoc-dissection-alist)))
213 (if (stringp article)
215 (insert-buffer-substring
216 nndoc-current-buffer (car entry) (nth 1 entry))
219 (insert-buffer-substring
220 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
222 (when nndoc-prepare-body-function
223 (funcall nndoc-prepare-body-function))
224 (when nndoc-article-transform-function
225 (funcall nndoc-article-transform-function article))
228 (deffoo nndoc-request-group (group &optional server dont-check)
232 ((not (nndoc-possibly-change-buffer group server))
233 (nnheader-report 'nndoc "No such file or buffer: %s"
236 (nnheader-report 'nndoc "Selected group %s" group)
238 ((zerop (setq number (length nndoc-dissection-alist)))
239 (nndoc-close-group group)
240 (nnheader-report 'nndoc "No articles in group %s" group))
242 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
244 (deffoo nndoc-request-type (group &optional article)
245 (cond ((not article) 'unknown)
246 (nndoc-post-type nndoc-post-type)
249 (deffoo nndoc-close-group (group &optional server)
250 (nndoc-possibly-change-buffer group server)
251 (and nndoc-current-buffer
252 (buffer-name nndoc-current-buffer)
253 (kill-buffer nndoc-current-buffer))
254 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
256 (setq nndoc-current-buffer nil)
257 (nnoo-close-server 'nndoc server)
258 (setq nndoc-dissection-alist nil)
261 (deffoo nndoc-request-list (&optional server)
264 (deffoo nndoc-request-newgroups (date &optional server)
267 (deffoo nndoc-request-list-newsgroups (&optional server)
271 ;;; Internal functions.
273 (defun nndoc-possibly-change-buffer (group source)
276 ;; The current buffer is this group's buffer.
277 ((and nndoc-current-buffer
278 (buffer-name nndoc-current-buffer)
279 (eq nndoc-current-buffer
280 (setq buf (cdr (assoc group nndoc-group-alist))))))
281 ;; We change buffers by taking an old from the group alist.
282 ;; `source' is either a string (a file name) or a buffer object.
284 (setq nndoc-current-buffer buf))
285 ;; It's a totally new group.
286 ((or (and (bufferp nndoc-address)
287 (buffer-name nndoc-address))
288 (and (stringp nndoc-address)
289 (file-exists-p nndoc-address)
290 (not (file-directory-p nndoc-address))))
291 (push (cons group (setq nndoc-current-buffer
293 (concat " *nndoc " group "*"))))
295 (setq nndoc-dissection-alist nil)
297 (set-buffer nndoc-current-buffer)
299 (if (stringp nndoc-address)
300 (nnheader-insert-file-contents nndoc-address)
301 (insert-buffer-substring nndoc-address))
302 (run-hooks 'nndoc-open-document-hook))))
303 ;; Initialize the nndoc structures according to this new document.
304 (when (and nndoc-current-buffer
305 (not nndoc-dissection-alist))
307 (set-buffer nndoc-current-buffer)
309 (if (eq nndoc-article-type 'mime-parts)
310 (nndoc-dissect-mime-parts)
311 (nndoc-dissect-buffer))))
312 (unless nndoc-current-buffer
313 (nndoc-close-server))
314 ;; Return whether we managed to select a file.
315 nndoc-current-buffer))
318 ;;; Deciding what document type we have
321 (defun nndoc-set-delims ()
322 "Set the nndoc delimiter variables according to the type of the document."
323 (let ((vars '(nndoc-file-begin
325 nndoc-article-begin-function
326 nndoc-head-begin nndoc-head-end
327 nndoc-file-end nndoc-article-begin
328 nndoc-body-begin nndoc-body-end-function nndoc-body-end
329 nndoc-prepare-body-function nndoc-article-transform-function
330 nndoc-generate-head-function nndoc-body-begin-function
331 nndoc-head-begin-function)))
333 (set (pop vars) nil)))
335 ;; Guess away until we find the real file type.
336 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
338 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
339 ;; Set the nndoc variables.
341 (set (intern (format "nndoc-%s" (caar defs)))
344 (defun nndoc-guess-type (subtype)
345 (let ((alist nndoc-type-alist)
346 results result entry)
347 (while (and (not result)
348 (setq entry (pop alist)))
349 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
350 (goto-char (point-min))
351 ;; Remove blank lines.
352 (while (eq (following-char) ?\n)
354 (when (numberp (setq result (funcall (intern
355 (format "nndoc-%s-type-p"
357 (push (cons result entry) results)
359 (unless (or result results)
360 (error "Document is not of any recognized type"))
363 (cadar (sort results 'car-less-than-car)))))
366 ;;; Built-in type predicates and functions
369 (defun nndoc-mbox-type-p ()
370 (when (looking-at message-unix-mail-delimiter)
373 (defun nndoc-mbox-article-begin ()
374 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
375 (goto-char (match-beginning 0))))
377 (defun nndoc-mbox-body-end ()
382 (and (re-search-backward
383 (concat "^" message-unix-mail-delimiter) nil t)
385 (search-forward "\n\n" beg t)
387 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
388 (setq len (string-to-int (match-string 1)))
389 (search-forward "\n\n" beg t)
390 (unless (= (setq len (+ (point) len)) (point-max))
391 (and (< len (point-max))
393 (looking-at message-unix-mail-delimiter)))))
396 (defun nndoc-mmdf-type-p ()
397 (when (looking-at "\^A\^A\^A\^A$")
400 (defun nndoc-news-type-p ()
401 (when (looking-at "^Path:.*\n")
404 (defun nndoc-rnews-type-p ()
405 (when (looking-at "#! *rnews")
408 (defun nndoc-rnews-body-end ()
409 (and (re-search-backward nndoc-article-begin nil t)
411 (goto-char (+ (point) (string-to-int (match-string 1))))))
413 (defun nndoc-babyl-type-p ()
414 (when (re-search-forward "\^_\^L *\n" nil t)
417 (defun nndoc-babyl-body-begin ()
418 (re-search-forward "^\n" nil t)
419 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
420 (let ((next (or (save-excursion
421 (re-search-forward nndoc-article-begin nil t))
423 (unless (re-search-forward "^\n" next t)
427 (forward-line -1)))))
429 (defun nndoc-babyl-head-begin ()
430 (when (re-search-forward "^[0-9].*\n" nil t)
431 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
435 (defun nndoc-forward-type-p ()
436 (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+"
438 (not (re-search-forward "^Subject:.*digest" nil t))
439 (not (re-search-backward "^From:" nil t 2))
440 (not (re-search-forward "^From:" nil t 2)))
443 (defun nndoc-rfc934-type-p ()
444 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
445 (not (re-search-forward "^Subject:.*digest" nil t))
446 (not (re-search-backward "^From:" nil t 2))
447 (not (re-search-forward "^From:" nil t 2)))
450 (defun nndoc-rfc822-forward-type-p ()
452 (message-narrow-to-head)
453 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
456 (defun nndoc-rfc822-forward-body-end-function ()
457 (goto-char (point-max)))
459 (defun nndoc-mime-parts-type-p ()
460 (let ((case-fold-search t)
461 (limit (search-forward "\n\n" nil t)))
462 (goto-char (point-min))
466 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
467 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
471 (defun nndoc-transform-mime-parts (article)
472 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
473 (headers (nth 5 entry)))
475 (goto-char (point-min))
478 (defun nndoc-generate-mime-parts-head (article)
479 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
480 (headers (nth 6 entry)))
482 (narrow-to-region (point) (point))
483 (insert-buffer-substring
484 nndoc-current-buffer (car entry) (nth 1 entry))
485 (goto-char (point-max)))
489 (defun nndoc-clari-briefs-type-p ()
490 (when (let ((case-fold-search nil))
491 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
494 (defun nndoc-transform-clari-briefs (article)
495 (goto-char (point-min))
496 (when (looking-at " *\\*\\(.*\\)\n")
497 (replace-match "" t t))
498 (nndoc-generate-clari-briefs-head article))
500 (defun nndoc-generate-clari-briefs-head (article)
501 (let ((entry (cdr (assq article nndoc-dissection-alist)))
504 (set-buffer nndoc-current-buffer)
506 (narrow-to-region (car entry) (nth 3 entry))
507 (goto-char (point-min))
508 (when (looking-at " *\\*\\(.*\\)$")
509 (setq subject (match-string 1))
510 (when (string-match "[ \t]+$" subject)
511 (setq subject (substring subject 0 (match-beginning 0)))))
513 (let ((case-fold-search nil))
515 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
516 (setq from (match-string 1)))))
517 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
518 "\nSubject: " (or subject "(no subject)") "\n")))
521 (defun nndoc-mime-digest-type-p ()
522 (let ((case-fold-search t)
523 boundary-id b-delimiter entry)
526 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
527 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
530 (setq boundary-id (match-string 1)
531 b-delimiter (concat "\n--" boundary-id "[ \t]*$"))
532 (setq entry (assq 'mime-digest nndoc-type-alist))
535 (cons 'head-begin "^ ?\n")
536 (cons 'head-end "^ ?$")
537 (cons 'body-begin "^ ?\n")
538 (cons 'article-begin b-delimiter)
539 (cons 'body-end-function 'nndoc-digest-body-end)
540 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
543 (defun nndoc-standard-digest-type-p ()
544 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
546 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
549 (defun nndoc-digest-body-end ()
550 (and (re-search-forward nndoc-article-begin nil t)
551 (goto-char (match-beginning 0))))
553 (defun nndoc-slack-digest-type-p ()
556 (defun nndoc-lanl-gov-announce-type-p ()
557 (when (let ((case-fold-search nil))
558 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
561 (defun nndoc-transform-lanl-gov-announce (article)
562 (goto-char (point-max))
563 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
564 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
566 (defun nndoc-generate-lanl-gov-head (article)
567 (let ((entry (cdr (assq article nndoc-dissection-alist)))
568 (e-mail "no address given")
571 (set-buffer nndoc-current-buffer)
573 (narrow-to-region (car entry) (nth 1 entry))
574 (goto-char (point-min))
575 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
576 (setq subject (concat " (" (match-string 1) ")"))
577 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
578 (setq e-mail (match-string 1)))
579 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
581 (setq subject (concat (match-string 1) subject))
582 (setq from (concat (match-string 2) " <" e-mail ">"))))))
583 (while (and from (string-match "(\[^)\]*)" from))
584 (setq from (replace-match "" t t from)))
585 (insert "From: " (or from "unknown")
586 "\nSubject: " (or subject "(no subject)") "\n")))
588 (defun nndoc-nsmail-type-p ()
589 (when (looking-at "From - ")
592 (deffoo nndoc-request-accept-article (group &optional server last)
597 ;;; Functions for dissecting the documents
600 (defun nndoc-search (regexp)
602 (re-search-forward regexp nil t)
603 (beginning-of-line)))
605 (defun nndoc-dissect-buffer ()
606 "Go through the document and partition it into heads/bodies/articles."
609 head-begin head-end body-begin body-end)
610 (setq nndoc-dissection-alist nil)
612 (set-buffer nndoc-current-buffer)
613 (goto-char (point-min))
614 ;; Remove blank lines.
615 (while (eq (following-char) ?\n)
617 ;; Find the beginning of the file.
618 (when nndoc-file-begin
619 (nndoc-search nndoc-file-begin))
620 ;; Go through the file.
621 (while (if (and first nndoc-first-article)
622 (nndoc-search nndoc-first-article)
623 (nndoc-article-begin))
625 (cond (nndoc-head-begin-function
626 (funcall nndoc-head-begin-function))
628 (nndoc-search nndoc-head-begin)))
631 (looking-at nndoc-file-end)))
632 (goto-char (point-max))
633 (setq head-begin (point))
634 (nndoc-search (or nndoc-head-end "^$"))
635 (setq head-end (point))
636 (if nndoc-body-begin-function
637 (funcall nndoc-body-begin-function)
638 (nndoc-search (or nndoc-body-begin "^\n")))
639 (setq body-begin (point))
640 (or (and nndoc-body-end-function
641 (funcall nndoc-body-end-function))
643 (nndoc-search nndoc-body-end))
644 (nndoc-article-begin)
646 (goto-char (point-max))
648 (and (re-search-backward nndoc-file-end nil t)
649 (beginning-of-line)))))
650 (setq body-end (point))
651 (push (list (incf i) head-begin head-end body-begin body-end
652 (count-lines body-begin body-end))
653 nndoc-dissection-alist))))))
655 (defun nndoc-article-begin ()
656 (if nndoc-article-begin-function
657 (funcall nndoc-article-begin-function)
659 (nndoc-search nndoc-article-begin))))
661 (defun nndoc-unquote-dashes ()
662 "Unquote quoted non-separators in digests."
663 (while (re-search-forward "^- -"nil t)
664 (replace-match "-" t t)))
666 ;; Against compiler warnings.
667 (defvar nndoc-mime-split-ordinal)
669 (defun nndoc-dissect-mime-parts ()
670 "Go through a MIME composite article and partition it into sub-articles.
671 When a MIME entity contains sub-entities, dissection produces one article for
672 the header of this entity, and one article per sub-entity."
673 (setq nndoc-dissection-alist nil
674 nndoc-mime-split-ordinal 0)
676 (set-buffer nndoc-current-buffer)
677 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
679 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
681 "Dissect an entity, within a composite MIME message.
682 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
683 ARTICLE-INSERT should be added at beginning for generating a full article.
684 The string POSITION holds a dotted decimal representation of the article
685 position in the hierarchical structure, it is nil for the outer entity.
686 PARENT is the message-ID of the parent summary line, or nil for none."
687 (let ((case-fold-search t)
688 (message-id (nnmail-message-id))
689 head-end body-begin summary-insert message-rfc822 multipart-any
690 subject content-type type subtype boundary-regexp)
691 ;; Gracefully handle a missing body.
692 (goto-char head-begin)
693 (if (search-forward "\n\n" body-end t)
694 (setq head-end (1- (point))
696 (setq head-end body-end
697 body-begin body-end))
698 (narrow-to-region head-begin head-end)
699 ;; Save MIME attributes.
700 (goto-char head-begin)
701 (setq content-type (message-fetch-field "Content-Type"))
704 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
705 (setq type (downcase (match-string 1 content-type))
706 subtype (downcase (match-string 2 content-type))
707 message-rfc822 (and (string= type "message")
708 (string= subtype "rfc822"))
709 multipart-any (string= type "multipart")))
710 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
711 (setq subject (match-string 1 content-type)))
712 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
713 (setq boundary-regexp (concat "^--"
715 (match-string 1 content-type))
716 "\\(--\\)?[ \t]*\n"))))
718 (when (or multipart-any (not article-insert))
719 (setq subject (message-fetch-field "Subject"))))
723 ;; Prepare the article and summary inserts.
724 (unless article-insert
725 (setq article-insert (buffer-substring (point-min) (point-max))
726 head-end head-begin))
727 (setq summary-insert article-insert)
728 ;; - summary Subject.
730 (let ((line (concat "Subject: <" position
731 (and position multipart-any ".")
732 (and multipart-any "*")
733 (and (or position multipart-any) " ")
734 (cond ((string= subtype "plain") type)
735 ((string= subtype "basic") type)
741 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
742 (replace-match line t t summary-insert)
743 (concat summary-insert line))))
744 ;; - summary Message-ID.
746 (let ((line (concat "Message-ID: " message-id "\n")))
747 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
748 (replace-match line t t summary-insert)
749 (concat summary-insert line))))
750 ;; - summary References.
753 (let ((line (concat "References: " parent "\n")))
754 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
756 (replace-match line t t summary-insert)
757 (concat summary-insert line)))))
758 ;; Generate dissection information for this entity.
759 (push (list (incf nndoc-mime-split-ordinal)
760 head-begin head-end body-begin body-end
761 (count-lines body-begin body-end)
762 article-insert summary-insert)
763 nndoc-dissection-alist)
764 ;; Recurse for all sub-entities, if any.
769 (nndoc-dissect-mime-parts-sub body-begin body-end nil
770 position message-id)))
771 ((and multipart-any boundary-regexp)
772 (let ((part-counter 0)
773 part-begin part-end eof-flag)
774 (while (string-match "\
775 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
777 (setq article-insert (replace-match "" t t article-insert)))
778 (let ((case-fold-search nil))
779 (goto-char body-begin)
780 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
781 (while (not eof-flag)
782 (setq part-begin (point))
783 (cond ((re-search-forward boundary-regexp body-end t)
784 (or (not (match-string 1))
785 (string= (match-string 1) "")
788 (setq part-end (point))
790 (t (setq part-end body-end
793 (nndoc-dissect-mime-parts-sub
794 part-begin part-end article-insert
797 (format "%d" (incf part-counter)))
801 (defun nndoc-add-type (definition &optional position)
802 "Add document DEFINITION to the list of nndoc document definitions.
803 If POSITION is nil or `last', the definition will be added
804 as the last checked definition, if t or `first', add as the
805 first definition, and if any other symbol, add after that
806 symbol in the alist."
807 ;; First remove any old instances.
808 (gnus-pull (car definition) nndoc-type-alist)
809 ;; Then enter the new definition in the proper place.
811 ((or (null position) (eq position 'last))
812 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
813 ((or (eq position t) (eq position 'first))
814 (push definition nndoc-type-alist))
816 (let ((list (memq (assq position nndoc-type-alist)
819 (error "No such position: %s" position))
820 (setcdr list (cons definition (cdr list)))))))
824 ;;; nndoc.el ends here