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)
297 (mm-enable-multibyte)
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+" 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-rfc934-type-p ()
443 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
444 (not (re-search-forward "^Subject:.*digest" nil t))
445 (not (re-search-backward "^From:" nil t 2))
446 (not (re-search-forward "^From:" nil t 2)))
449 (defun nndoc-rfc822-forward-type-p ()
451 (message-narrow-to-head)
452 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
455 (defun nndoc-rfc822-forward-body-end-function ()
456 (goto-char (point-max)))
458 (defun nndoc-mime-parts-type-p ()
459 (let ((case-fold-search t)
460 (limit (search-forward "\n\n" nil t)))
461 (goto-char (point-min))
465 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
466 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
470 (defun nndoc-transform-mime-parts (article)
471 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
472 (headers (nth 5 entry)))
474 (goto-char (point-min))
477 (defun nndoc-generate-mime-parts-head (article)
478 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
479 (headers (nth 6 entry)))
481 (narrow-to-region (point) (point))
482 (insert-buffer-substring
483 nndoc-current-buffer (car entry) (nth 1 entry))
484 (goto-char (point-max)))
488 (defun nndoc-clari-briefs-type-p ()
489 (when (let ((case-fold-search nil))
490 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
493 (defun nndoc-transform-clari-briefs (article)
494 (goto-char (point-min))
495 (when (looking-at " *\\*\\(.*\\)\n")
496 (replace-match "" t t))
497 (nndoc-generate-clari-briefs-head article))
499 (defun nndoc-generate-clari-briefs-head (article)
500 (let ((entry (cdr (assq article nndoc-dissection-alist)))
503 (set-buffer nndoc-current-buffer)
505 (narrow-to-region (car entry) (nth 3 entry))
506 (goto-char (point-min))
507 (when (looking-at " *\\*\\(.*\\)$")
508 (setq subject (match-string 1))
509 (when (string-match "[ \t]+$" subject)
510 (setq subject (substring subject 0 (match-beginning 0)))))
512 (let ((case-fold-search nil))
514 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
515 (setq from (match-string 1)))))
516 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
517 "\nSubject: " (or subject "(no subject)") "\n")))
520 (defun nndoc-mime-digest-type-p ()
521 (let ((case-fold-search t)
522 boundary-id b-delimiter entry)
525 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
526 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
529 (setq boundary-id (match-string 1)
530 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
531 (setq entry (assq 'mime-digest nndoc-type-alist))
534 (cons 'head-end "^ ?$")
535 (cons 'body-begin "^ ?\n")
536 (cons 'article-begin b-delimiter)
537 (cons 'body-end-function 'nndoc-digest-body-end)
538 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
541 (defun nndoc-standard-digest-type-p ()
542 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
544 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
547 (defun nndoc-digest-body-end ()
548 (and (re-search-forward nndoc-article-begin nil t)
549 (goto-char (match-beginning 0))))
551 (defun nndoc-slack-digest-type-p ()
554 (defun nndoc-lanl-gov-announce-type-p ()
555 (when (let ((case-fold-search nil))
556 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
559 (defun nndoc-transform-lanl-gov-announce (article)
560 (goto-char (point-max))
561 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
562 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
564 (defun nndoc-generate-lanl-gov-head (article)
565 (let ((entry (cdr (assq article nndoc-dissection-alist)))
566 (e-mail "no address given")
569 (set-buffer nndoc-current-buffer)
571 (narrow-to-region (car entry) (nth 1 entry))
572 (goto-char (point-min))
573 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
574 (setq subject (concat " (" (match-string 1) ")"))
575 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
576 (setq e-mail (match-string 1)))
577 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
579 (setq subject (concat (match-string 1) subject))
580 (setq from (concat (match-string 2) " <" e-mail ">"))))))
581 (while (and from (string-match "(\[^)\]*)" from))
582 (setq from (replace-match "" t t from)))
583 (insert "From: " (or from "unknown")
584 "\nSubject: " (or subject "(no subject)") "\n")))
586 (defun nndoc-nsmail-type-p ()
587 (when (looking-at "From - ")
590 (deffoo nndoc-request-accept-article (group &optional server last)
595 ;;; Functions for dissecting the documents
598 (defun nndoc-search (regexp)
600 (re-search-forward regexp nil t)
601 (beginning-of-line)))
603 (defun nndoc-dissect-buffer ()
604 "Go through the document and partition it into heads/bodies/articles."
607 head-begin head-end body-begin body-end)
608 (setq nndoc-dissection-alist nil)
610 (set-buffer nndoc-current-buffer)
611 (goto-char (point-min))
612 ;; Remove blank lines.
613 (while (eq (following-char) ?\n)
615 ;; Find the beginning of the file.
616 (when nndoc-file-begin
617 (nndoc-search nndoc-file-begin))
618 ;; Go through the file.
619 (while (if (and first nndoc-first-article)
620 (nndoc-search nndoc-first-article)
621 (nndoc-article-begin))
623 (cond (nndoc-head-begin-function
624 (funcall nndoc-head-begin-function))
626 (nndoc-search nndoc-head-begin)))
629 (looking-at nndoc-file-end)))
630 (goto-char (point-max))
631 (setq head-begin (point))
632 (nndoc-search (or nndoc-head-end "^$"))
633 (setq head-end (point))
634 (if nndoc-body-begin-function
635 (funcall nndoc-body-begin-function)
636 (nndoc-search (or nndoc-body-begin "^\n")))
637 (setq body-begin (point))
638 (or (and nndoc-body-end-function
639 (funcall nndoc-body-end-function))
641 (nndoc-search nndoc-body-end))
642 (nndoc-article-begin)
644 (goto-char (point-max))
646 (and (re-search-backward nndoc-file-end nil t)
647 (beginning-of-line)))))
648 (setq body-end (point))
649 (push (list (incf i) head-begin head-end body-begin body-end
650 (count-lines body-begin body-end))
651 nndoc-dissection-alist))))))
653 (defun nndoc-article-begin ()
654 (if nndoc-article-begin-function
655 (funcall nndoc-article-begin-function)
657 (nndoc-search nndoc-article-begin))))
659 (defun nndoc-unquote-dashes ()
660 "Unquote quoted non-separators in digests."
661 (while (re-search-forward "^- -"nil t)
662 (replace-match "-" t t)))
664 ;; Against compiler warnings.
665 (defvar nndoc-mime-split-ordinal)
667 (defun nndoc-dissect-mime-parts ()
668 "Go through a MIME composite article and partition it into sub-articles.
669 When a MIME entity contains sub-entities, dissection produces one article for
670 the header of this entity, and one article per sub-entity."
671 (setq nndoc-dissection-alist nil
672 nndoc-mime-split-ordinal 0)
674 (set-buffer nndoc-current-buffer)
675 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
677 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
679 "Dissect an entity, within a composite MIME message.
680 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
681 ARTICLE-INSERT should be added at beginning for generating a full article.
682 The string POSITION holds a dotted decimal representation of the article
683 position in the hierarchical structure, it is nil for the outer entity.
684 PARENT is the message-ID of the parent summary line, or nil for none."
685 (let ((case-fold-search t)
686 (message-id (nnmail-message-id))
687 head-end body-begin summary-insert message-rfc822 multipart-any
688 subject content-type type subtype boundary-regexp)
689 ;; Gracefully handle a missing body.
690 (goto-char head-begin)
691 (if (search-forward "\n\n" body-end t)
692 (setq head-end (1- (point))
694 (setq head-end body-end
695 body-begin body-end))
696 (narrow-to-region head-begin head-end)
697 ;; Save MIME attributes.
698 (goto-char head-begin)
699 (setq content-type (message-fetch-field "Content-Type"))
702 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
703 (setq type (downcase (match-string 1 content-type))
704 subtype (downcase (match-string 2 content-type))
705 message-rfc822 (and (string= type "message")
706 (string= subtype "rfc822"))
707 multipart-any (string= type "multipart")))
708 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
709 (setq subject (match-string 1 content-type)))
710 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
711 (setq boundary-regexp (concat "^--"
713 (match-string 1 content-type))
714 "\\(--\\)?[ \t]*\n"))))
716 (when (or multipart-any (not article-insert))
717 (setq subject (message-fetch-field "Subject"))))
721 ;; Prepare the article and summary inserts.
722 (unless article-insert
723 (setq article-insert (buffer-substring (point-min) (point-max))
724 head-end head-begin))
725 (setq summary-insert article-insert)
726 ;; - summary Subject.
728 (let ((line (concat "Subject: <" position
729 (and position multipart-any ".")
730 (and multipart-any "*")
731 (and (or position multipart-any) " ")
732 (cond ((string= subtype "plain") type)
733 ((string= subtype "basic") type)
739 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
740 (replace-match line t t summary-insert)
741 (concat summary-insert line))))
742 ;; - summary Message-ID.
744 (let ((line (concat "Message-ID: " message-id "\n")))
745 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
746 (replace-match line t t summary-insert)
747 (concat summary-insert line))))
748 ;; - summary References.
751 (let ((line (concat "References: " parent "\n")))
752 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
754 (replace-match line t t summary-insert)
755 (concat summary-insert line)))))
756 ;; Generate dissection information for this entity.
757 (push (list (incf nndoc-mime-split-ordinal)
758 head-begin head-end body-begin body-end
759 (count-lines body-begin body-end)
760 article-insert summary-insert)
761 nndoc-dissection-alist)
762 ;; Recurse for all sub-entities, if any.
767 (nndoc-dissect-mime-parts-sub body-begin body-end nil
768 position message-id)))
769 ((and multipart-any boundary-regexp)
770 (let ((part-counter 0)
771 part-begin part-end eof-flag)
772 (while (string-match "\
773 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
775 (setq article-insert (replace-match "" t t article-insert)))
776 (let ((case-fold-search nil))
777 (goto-char body-begin)
778 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
779 (while (not eof-flag)
780 (setq part-begin (point))
781 (cond ((re-search-forward boundary-regexp body-end t)
782 (or (not (match-string 1))
783 (string= (match-string 1) "")
786 (setq part-end (point))
788 (t (setq part-end body-end
791 (nndoc-dissect-mime-parts-sub
792 part-begin part-end article-insert
795 (format "%d" (incf part-counter)))
799 (defun nndoc-add-type (definition &optional position)
800 "Add document DEFINITION to the list of nndoc document definitions.
801 If POSITION is nil or `last', the definition will be added
802 as the last checked definition, if t or `first', add as the
803 first definition, and if any other symbol, add after that
804 symbol in the alist."
805 ;; First remove any old instances.
806 (gnus-pull (car definition) nndoc-type-alist)
807 ;; Then enter the new definition in the proper place.
809 ((or (null position) (eq position 'last))
810 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
811 ((or (eq position t) (eq position 'first))
812 (push definition nndoc-type-alist))
814 (let ((list (memq (assq position nndoc-type-alist)
817 (error "No such position: %s" position))
818 (setcdr list (cons definition (cdr list)))))))
822 ;;; nndoc.el ends here