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))
93 (subtype digest guess))
95 (generate-head-function . nndoc-generate-mime-parts-head)
96 (article-transform-function . nndoc-transform-mime-parts))
98 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
99 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
100 (prepare-body-function . nndoc-unquote-dashes)
101 (body-end-function . nndoc-digest-body-end)
103 (body-begin . "^ *\n")
104 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
105 (subtype digest guess))
107 (article-begin . "^------------------------------*[\n \t]+")
109 (body-end-function . nndoc-digest-body-end)
110 (body-begin . "^ ?$")
111 (file-end . "^End of")
112 (prepare-body-function . nndoc-unquote-dashes)
113 (subtype digest guess))
115 (article-begin . "^\\\\\\\\\n")
116 (head-begin . "^Paper.*:")
117 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
119 (body-end . "-------------------------------------------------")
120 (file-end . "^Title: Recent Seminal")
121 (generate-head-function . nndoc-generate-lanl-gov-head)
122 (article-transform-function . nndoc-transform-lanl-gov-announce)
123 (subtype preprints guess))
125 (article-begin . "^\n")
126 (body-end-function . nndoc-rfc822-forward-body-end-function))
138 (defvoo nndoc-file-begin nil)
139 (defvoo nndoc-first-article nil)
140 (defvoo nndoc-article-begin nil)
141 (defvoo nndoc-head-begin nil)
142 (defvoo nndoc-head-end nil)
143 (defvoo nndoc-file-end nil)
144 (defvoo nndoc-body-begin nil)
145 (defvoo nndoc-body-end-function nil)
146 (defvoo nndoc-body-begin-function nil)
147 (defvoo nndoc-head-begin-function nil)
148 (defvoo nndoc-body-end nil)
149 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
150 ;; following items. ARTICLE acts as the association key and is an ordinal
151 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
152 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
153 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
154 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
155 ;; generation, respectively. Other headers usually follow directly from the
156 ;; buffer. Value `nil' means no insert.
157 (defvoo nndoc-dissection-alist nil)
158 (defvoo nndoc-prepare-body-function nil)
159 (defvoo nndoc-generate-head-function nil)
160 (defvoo nndoc-article-transform-function nil)
161 (defvoo nndoc-article-begin-function nil)
163 (defvoo nndoc-status-string "")
164 (defvoo nndoc-group-alist nil)
165 (defvoo nndoc-current-buffer nil
166 "Current nndoc news buffer.")
167 (defvoo nndoc-address nil)
169 (defconst nndoc-version "nndoc 1.0"
174 ;;; Interface functions
176 (nnoo-define-basics nndoc)
178 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
179 (when (nndoc-possibly-change-buffer newsgroup server)
181 (set-buffer nntp-server-buffer)
184 (if (stringp (car articles))
187 (when (setq entry (cdr (assq (setq article (pop articles))
188 nndoc-dissection-alist)))
189 (insert (format "221 %d Article retrieved.\n" article))
190 (if nndoc-generate-head-function
191 (funcall nndoc-generate-head-function article)
192 (insert-buffer-substring
193 nndoc-current-buffer (car entry) (nth 1 entry)))
194 (goto-char (point-max))
195 (unless (eq (char-after (1- (point))) ?\n)
197 (insert (format "Lines: %d\n" (nth 4 entry)))
200 (nnheader-fold-continuation-lines)
203 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
204 (nndoc-possibly-change-buffer newsgroup server)
206 (let ((buffer (or buffer nntp-server-buffer))
207 (entry (cdr (assq article nndoc-dissection-alist)))
212 (if (stringp article)
214 (insert-buffer-substring
215 nndoc-current-buffer (car entry) (nth 1 entry))
218 (insert-buffer-substring
219 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
221 (when nndoc-prepare-body-function
222 (funcall nndoc-prepare-body-function))
223 (when nndoc-article-transform-function
224 (funcall nndoc-article-transform-function article))
227 (deffoo nndoc-request-group (group &optional server dont-check)
231 ((not (nndoc-possibly-change-buffer group server))
232 (nnheader-report 'nndoc "No such file or buffer: %s"
235 (nnheader-report 'nndoc "Selected group %s" group)
237 ((zerop (setq number (length nndoc-dissection-alist)))
238 (nndoc-close-group group)
239 (nnheader-report 'nndoc "No articles in group %s" group))
241 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
243 (deffoo nndoc-request-type (group &optional article)
244 (cond ((not article) 'unknown)
245 (nndoc-post-type nndoc-post-type)
248 (deffoo nndoc-close-group (group &optional server)
249 (nndoc-possibly-change-buffer group server)
250 (and nndoc-current-buffer
251 (buffer-name nndoc-current-buffer)
252 (kill-buffer nndoc-current-buffer))
253 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
255 (setq nndoc-current-buffer nil)
256 (nnoo-close-server 'nndoc server)
257 (setq nndoc-dissection-alist nil)
260 (deffoo nndoc-request-list (&optional server)
263 (deffoo nndoc-request-newgroups (date &optional server)
266 (deffoo nndoc-request-list-newsgroups (&optional server)
270 ;;; Internal functions.
272 (defun nndoc-possibly-change-buffer (group source)
275 ;; The current buffer is this group's buffer.
276 ((and nndoc-current-buffer
277 (buffer-name nndoc-current-buffer)
278 (eq nndoc-current-buffer
279 (setq buf (cdr (assoc group nndoc-group-alist))))))
280 ;; We change buffers by taking an old from the group alist.
281 ;; `source' is either a string (a file name) or a buffer object.
283 (setq nndoc-current-buffer buf))
284 ;; It's a totally new group.
285 ((or (and (bufferp nndoc-address)
286 (buffer-name nndoc-address))
287 (and (stringp nndoc-address)
288 (file-exists-p nndoc-address)
289 (not (file-directory-p nndoc-address))))
290 (push (cons group (setq nndoc-current-buffer
292 (concat " *nndoc " group "*"))))
294 (setq nndoc-dissection-alist nil)
296 (set-buffer nndoc-current-buffer)
298 (if (stringp nndoc-address)
299 (nnheader-insert-file-contents nndoc-address)
300 (insert-buffer-substring nndoc-address))
301 (run-hooks 'nndoc-open-document-hook))))
302 ;; Initialize the nndoc structures according to this new document.
303 (when (and nndoc-current-buffer
304 (not nndoc-dissection-alist))
306 (set-buffer nndoc-current-buffer)
308 (if (eq nndoc-article-type 'mime-parts)
309 (nndoc-dissect-mime-parts)
310 (nndoc-dissect-buffer))))
311 (unless nndoc-current-buffer
312 (nndoc-close-server))
313 ;; Return whether we managed to select a file.
314 nndoc-current-buffer))
317 ;;; Deciding what document type we have
320 (defun nndoc-set-delims ()
321 "Set the nndoc delimiter variables according to the type of the document."
322 (let ((vars '(nndoc-file-begin
324 nndoc-article-begin-function
325 nndoc-head-begin nndoc-head-end
326 nndoc-file-end nndoc-article-begin
327 nndoc-body-begin nndoc-body-end-function nndoc-body-end
328 nndoc-prepare-body-function nndoc-article-transform-function
329 nndoc-generate-head-function nndoc-body-begin-function
330 nndoc-head-begin-function)))
332 (set (pop vars) nil)))
334 ;; Guess away until we find the real file type.
335 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
337 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
338 ;; Set the nndoc variables.
340 (set (intern (format "nndoc-%s" (caar defs)))
343 (defun nndoc-guess-type (subtype)
344 (let ((alist nndoc-type-alist)
345 results result entry)
346 (while (and (not result)
347 (setq entry (pop alist)))
348 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
349 (goto-char (point-min))
350 ;; Remove blank lines.
351 (while (eq (following-char) ?\n)
353 (when (numberp (setq result (funcall (intern
354 (format "nndoc-%s-type-p"
356 (push (cons result entry) results)
358 (unless (or result results)
359 (error "Document is not of any recognized type"))
362 (cadar (sort results 'car-less-than-car)))))
365 ;;; Built-in type predicates and functions
368 (defun nndoc-mbox-type-p ()
369 (when (looking-at message-unix-mail-delimiter)
372 (defun nndoc-mbox-article-begin ()
373 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
374 (goto-char (match-beginning 0))))
376 (defun nndoc-mbox-body-end ()
381 (and (re-search-backward
382 (concat "^" message-unix-mail-delimiter) nil t)
384 (search-forward "\n\n" beg t)
386 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
387 (setq len (string-to-int (match-string 1)))
388 (search-forward "\n\n" beg t)
389 (unless (= (setq len (+ (point) len)) (point-max))
390 (and (< len (point-max))
392 (looking-at message-unix-mail-delimiter)))))
395 (defun nndoc-mmdf-type-p ()
396 (when (looking-at "\^A\^A\^A\^A$")
399 (defun nndoc-news-type-p ()
400 (when (looking-at "^Path:.*\n")
403 (defun nndoc-rnews-type-p ()
404 (when (looking-at "#! *rnews")
407 (defun nndoc-rnews-body-end ()
408 (and (re-search-backward nndoc-article-begin nil t)
410 (goto-char (+ (point) (string-to-int (match-string 1))))))
412 (defun nndoc-babyl-type-p ()
413 (when (re-search-forward "\^_\^L *\n" nil t)
416 (defun nndoc-babyl-body-begin ()
417 (re-search-forward "^\n" nil t)
418 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
419 (let ((next (or (save-excursion
420 (re-search-forward nndoc-article-begin nil t))
422 (unless (re-search-forward "^\n" next t)
426 (forward-line -1)))))
428 (defun nndoc-babyl-head-begin ()
429 (when (re-search-forward "^[0-9].*\n" nil t)
430 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
434 (defun nndoc-forward-type-p ()
435 (when (and (re-search-forward "^-+ Start of forwarded message -+\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-rfc934-type-p ()
442 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
443 (not (re-search-forward "^Subject:.*digest" nil t))
444 (not (re-search-backward "^From:" nil t 2))
445 (not (re-search-forward "^From:" nil t 2)))
448 (defun nndoc-rfc822-forward-type-p ()
450 (message-narrow-to-head)
451 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
454 (defun nndoc-rfc822-forward-body-end-function ()
455 (goto-char (point-max)))
457 (defun nndoc-mime-parts-type-p ()
458 (let ((case-fold-search t)
459 (limit (search-forward "\n\n" nil t)))
460 (goto-char (point-min))
464 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
465 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
469 (defun nndoc-transform-mime-parts (article)
470 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
471 (headers (nth 5 entry)))
473 (goto-char (point-min))
476 (defun nndoc-generate-mime-parts-head (article)
477 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
478 (headers (nth 6 entry)))
480 (narrow-to-region (point) (point))
481 (insert-buffer-substring
482 nndoc-current-buffer (car entry) (nth 1 entry))
483 (goto-char (point-max)))
487 (defun nndoc-clari-briefs-type-p ()
488 (when (let ((case-fold-search nil))
489 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
492 (defun nndoc-transform-clari-briefs (article)
493 (goto-char (point-min))
494 (when (looking-at " *\\*\\(.*\\)\n")
495 (replace-match "" t t))
496 (nndoc-generate-clari-briefs-head article))
498 (defun nndoc-generate-clari-briefs-head (article)
499 (let ((entry (cdr (assq article nndoc-dissection-alist)))
502 (set-buffer nndoc-current-buffer)
504 (narrow-to-region (car entry) (nth 3 entry))
505 (goto-char (point-min))
506 (when (looking-at " *\\*\\(.*\\)$")
507 (setq subject (match-string 1))
508 (when (string-match "[ \t]+$" subject)
509 (setq subject (substring subject 0 (match-beginning 0)))))
511 (let ((case-fold-search nil))
513 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
514 (setq from (match-string 1)))))
515 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
516 "\nSubject: " (or subject "(no subject)") "\n")))
519 (defun nndoc-mime-digest-type-p ()
520 (let ((case-fold-search t)
521 boundary-id b-delimiter entry)
524 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
525 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
528 (setq boundary-id (match-string 1)
529 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
530 (setq entry (assq 'mime-digest nndoc-type-alist))
533 (cons 'head-end "^ ?$")
534 (cons 'body-begin "^ ?\n")
535 (cons 'article-begin b-delimiter)
536 (cons 'body-end-function 'nndoc-digest-body-end)
537 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
540 (defun nndoc-standard-digest-type-p ()
541 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
543 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
546 (defun nndoc-digest-body-end ()
547 (and (re-search-forward nndoc-article-begin nil t)
548 (goto-char (match-beginning 0))))
550 (defun nndoc-slack-digest-type-p ()
553 (defun nndoc-lanl-gov-announce-type-p ()
554 (when (let ((case-fold-search nil))
555 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
558 (defun nndoc-transform-lanl-gov-announce (article)
559 (goto-char (point-max))
560 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
561 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
563 (defun nndoc-generate-lanl-gov-head (article)
564 (let ((entry (cdr (assq article nndoc-dissection-alist)))
565 (e-mail "no address given")
568 (set-buffer nndoc-current-buffer)
570 (narrow-to-region (car entry) (nth 1 entry))
571 (goto-char (point-min))
572 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
573 (setq subject (concat " (" (match-string 1) ")"))
574 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
575 (setq e-mail (match-string 1)))
576 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
578 (setq subject (concat (match-string 1) subject))
579 (setq from (concat (match-string 2) " <" e-mail ">"))))))
580 (while (and from (string-match "(\[^)\]*)" from))
581 (setq from (replace-match "" t t from)))
582 (insert "From: " (or from "unknown")
583 "\nSubject: " (or subject "(no subject)") "\n")))
585 (defun nndoc-nsmail-type-p ()
586 (when (looking-at "From - ")
589 (deffoo nndoc-request-accept-article (group &optional server last)
594 ;;; Functions for dissecting the documents
597 (defun nndoc-search (regexp)
599 (re-search-forward regexp nil t)
600 (beginning-of-line)))
602 (defun nndoc-dissect-buffer ()
603 "Go through the document and partition it into heads/bodies/articles."
606 head-begin head-end body-begin body-end)
607 (setq nndoc-dissection-alist nil)
609 (set-buffer nndoc-current-buffer)
610 (goto-char (point-min))
611 ;; Remove blank lines.
612 (while (eq (following-char) ?\n)
614 ;; Find the beginning of the file.
615 (when nndoc-file-begin
616 (nndoc-search nndoc-file-begin))
617 ;; Go through the file.
618 (while (if (and first nndoc-first-article)
619 (nndoc-search nndoc-first-article)
620 (nndoc-article-begin))
622 (cond (nndoc-head-begin-function
623 (funcall nndoc-head-begin-function))
625 (nndoc-search nndoc-head-begin)))
628 (looking-at nndoc-file-end)))
629 (goto-char (point-max))
630 (setq head-begin (point))
631 (nndoc-search (or nndoc-head-end "^$"))
632 (setq head-end (point))
633 (if nndoc-body-begin-function
634 (funcall nndoc-body-begin-function)
635 (nndoc-search (or nndoc-body-begin "^\n")))
636 (setq body-begin (point))
637 (or (and nndoc-body-end-function
638 (funcall nndoc-body-end-function))
640 (nndoc-search nndoc-body-end))
641 (nndoc-article-begin)
643 (goto-char (point-max))
645 (and (re-search-backward nndoc-file-end nil t)
646 (beginning-of-line)))))
647 (setq body-end (point))
648 (push (list (incf i) head-begin head-end body-begin body-end
649 (count-lines body-begin body-end))
650 nndoc-dissection-alist))))))
652 (defun nndoc-article-begin ()
653 (if nndoc-article-begin-function
654 (funcall nndoc-article-begin-function)
656 (nndoc-search nndoc-article-begin))))
658 (defun nndoc-unquote-dashes ()
659 "Unquote quoted non-separators in digests."
660 (while (re-search-forward "^- -"nil t)
661 (replace-match "-" t t)))
663 ;; Against compiler warnings.
664 (defvar nndoc-mime-split-ordinal)
666 (defun nndoc-dissect-mime-parts ()
667 "Go through a MIME composite article and partition it into sub-articles.
668 When a MIME entity contains sub-entities, dissection produces one article for
669 the header of this entity, and one article per sub-entity."
670 (setq nndoc-dissection-alist nil
671 nndoc-mime-split-ordinal 0)
673 (set-buffer nndoc-current-buffer)
674 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
676 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
678 "Dissect an entity, within a composite MIME message.
679 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
680 ARTICLE-INSERT should be added at beginning for generating a full article.
681 The string POSITION holds a dotted decimal representation of the article
682 position in the hierarchical structure, it is nil for the outer entity.
683 PARENT is the message-ID of the parent summary line, or nil for none."
684 (let ((case-fold-search t)
685 (message-id (nnmail-message-id))
686 head-end body-begin summary-insert message-rfc822 multipart-any
687 subject content-type type subtype boundary-regexp)
688 ;; Gracefully handle a missing body.
689 (goto-char head-begin)
690 (if (search-forward "\n\n" body-end t)
691 (setq head-end (1- (point))
693 (setq head-end body-end
694 body-begin body-end))
695 (narrow-to-region head-begin head-end)
696 ;; Save MIME attributes.
697 (goto-char head-begin)
698 (setq content-type (message-fetch-field "Content-Type"))
701 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
702 (setq type (downcase (match-string 1 content-type))
703 subtype (downcase (match-string 2 content-type))
704 message-rfc822 (and (string= type "message")
705 (string= subtype "rfc822"))
706 multipart-any (string= type "multipart")))
707 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
708 (setq subject (match-string 1 content-type)))
709 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
710 (setq boundary-regexp (concat "^--"
712 (match-string 1 content-type))
713 "\\(--\\)?[ \t]*\n"))))
715 (when (or multipart-any (not article-insert))
716 (setq subject (message-fetch-field "Subject"))))
720 ;; Prepare the article and summary inserts.
721 (unless article-insert
722 (setq article-insert (buffer-substring (point-min) (point-max))
723 head-end head-begin))
724 (setq summary-insert article-insert)
725 ;; - summary Subject.
727 (let ((line (concat "Subject: <" position
728 (and position multipart-any ".")
729 (and multipart-any "*")
730 (and (or position multipart-any) " ")
731 (cond ((string= subtype "plain") type)
732 ((string= subtype "basic") type)
738 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
739 (replace-match line t t summary-insert)
740 (concat summary-insert line))))
741 ;; - summary Message-ID.
743 (let ((line (concat "Message-ID: " message-id "\n")))
744 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
745 (replace-match line t t summary-insert)
746 (concat summary-insert line))))
747 ;; - summary References.
750 (let ((line (concat "References: " parent "\n")))
751 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
753 (replace-match line t t summary-insert)
754 (concat summary-insert line)))))
755 ;; Generate dissection information for this entity.
756 (push (list (incf nndoc-mime-split-ordinal)
757 head-begin head-end body-begin body-end
758 (count-lines body-begin body-end)
759 article-insert summary-insert)
760 nndoc-dissection-alist)
761 ;; Recurse for all sub-entities, if any.
766 (nndoc-dissect-mime-parts-sub body-begin body-end nil
767 position message-id)))
768 ((and multipart-any boundary-regexp)
769 (let ((part-counter 0)
770 part-begin part-end eof-flag)
771 (while (string-match "\
772 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
774 (setq article-insert (replace-match "" t t article-insert)))
775 (let ((case-fold-search nil))
776 (goto-char body-begin)
777 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
778 (while (not eof-flag)
779 (setq part-begin (point))
780 (cond ((re-search-forward boundary-regexp body-end t)
781 (or (not (match-string 1))
782 (string= (match-string 1) "")
785 (setq part-end (point))
787 (t (setq part-end body-end
790 (nndoc-dissect-mime-parts-sub
791 part-begin part-end article-insert
794 (format "%d" (incf part-counter)))
798 (defun nndoc-add-type (definition &optional position)
799 "Add document DEFINITION to the list of nndoc document definitions.
800 If POSITION is nil or `last', the definition will be added
801 as the last checked definition, if t or `first', add as the
802 first definition, and if any other symbol, add after that
803 symbol in the alist."
804 ;; First remove any old instances.
805 (gnus-pull (car definition) nndoc-type-alist)
806 ;; Then enter the new definition in the proper place.
808 ((or (null position) (eq position 'last))
809 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
810 ((or (eq position t) (eq position 'first))
811 (push definition nndoc-type-alist))
813 (let ((list (memq (assq position nndoc-type-alist)
816 (error "No such position: %s" position))
817 (setcdr list (cons definition (cdr list)))))))
821 ;;; nndoc.el ends here