1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995-2000 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.
35 (eval-when-compile (require 'cl))
39 (defvoo nndoc-article-type 'guess
41 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
42 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
43 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
45 (defvoo nndoc-post-type 'mail
46 "*Whether the nndoc group is `mail' or `post'.")
48 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
49 "Hook run after opening a document.
50 The default function removes all trailing carriage returns
53 (defvar nndoc-type-alist
55 (article-begin . "^\^A\^A\^A\^A\n")
56 (body-end . "^\^A\^A\^A\^A\n"))
58 (article-begin . "^From - "))
60 (article-begin . "^Path:"))
62 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
63 (body-end-function . nndoc-rnews-body-end))
65 (article-begin-function . nndoc-mbox-article-begin)
66 (body-end-function . nndoc-mbox-body-end))
68 (article-begin . "\^_\^L *\n")
70 (body-begin-function . nndoc-babyl-body-begin)
71 (head-begin-function . nndoc-babyl-head-begin))
73 (article-begin . "^-+ Start of forwarded message -+\n+")
74 (body-end . "^-+ End of forwarded message -+$")
75 (prepare-body-function . nndoc-unquote-dashes))
77 (article-begin . "^--.*\n+")
79 (prepare-body-function . nndoc-unquote-dashes))
81 (article-begin . "^ \\*")
82 (body-end . "^\t------*[ \t]^*\n^ \\*")
85 (generate-head-function . nndoc-generate-clari-briefs-head)
86 (article-transform-function . nndoc-transform-clari-briefs))
92 (subtype digest guess))
94 (generate-head-function . nndoc-generate-mime-parts-head)
95 (article-transform-function . nndoc-transform-mime-parts))
97 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
98 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
99 (prepare-body-function . nndoc-unquote-dashes)
100 (body-end-function . nndoc-digest-body-end)
102 (body-begin . "^ *\n")
103 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
104 (subtype digest guess))
106 (article-begin . "^------------------------------*[\n \t]+")
108 (body-end-function . nndoc-digest-body-end)
109 (body-begin . "^ ?$")
110 (file-end . "^End of")
111 (prepare-body-function . nndoc-unquote-dashes)
112 (subtype digest guess))
114 (article-begin . "^\\\\\\\\\n")
115 (head-begin . "^Paper.*:")
116 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
118 (body-end . "-------------------------------------------------")
119 (file-end . "^Title: Recent Seminal")
120 (generate-head-function . nndoc-generate-lanl-gov-head)
121 (article-transform-function . nndoc-transform-lanl-gov-announce)
122 (subtype preprints guess))
124 (article-begin . "^\n")
125 (body-end-function . nndoc-rfc822-forward-body-end-function))
137 (defvoo nndoc-file-begin nil)
138 (defvoo nndoc-first-article nil)
139 (defvoo nndoc-article-begin nil)
140 (defvoo nndoc-head-begin nil)
141 (defvoo nndoc-head-end nil)
142 (defvoo nndoc-file-end nil)
143 (defvoo nndoc-body-begin nil)
144 (defvoo nndoc-body-end-function nil)
145 (defvoo nndoc-body-begin-function nil)
146 (defvoo nndoc-head-begin-function nil)
147 (defvoo nndoc-body-end nil)
148 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
149 ;; following items. ARTICLE acts as the association key and is an ordinal
150 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
151 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
152 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
153 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
154 ;; generation, respectively. Other headers usually follow directly from the
155 ;; buffer. Value `nil' means no insert.
156 (defvoo nndoc-dissection-alist nil)
157 (defvoo nndoc-prepare-body-function nil)
158 (defvoo nndoc-generate-head-function nil)
159 (defvoo nndoc-article-transform-function nil)
160 (defvoo nndoc-article-begin-function nil)
162 (defvoo nndoc-status-string "")
163 (defvoo nndoc-group-alist nil)
164 (defvoo nndoc-current-buffer nil
165 "Current nndoc news buffer.")
166 (defvoo nndoc-address nil)
168 (defconst nndoc-version "nndoc 1.0"
173 ;;; Interface functions
175 (nnoo-define-basics nndoc)
177 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
178 (when (nndoc-possibly-change-buffer newsgroup server)
180 (set-buffer nntp-server-buffer)
183 (if (stringp (car articles))
186 (when (setq entry (cdr (assq (setq article (pop articles))
187 nndoc-dissection-alist)))
188 (insert (format "221 %d Article retrieved.\n" article))
189 (if nndoc-generate-head-function
190 (funcall nndoc-generate-head-function article)
191 (insert-buffer-substring
192 nndoc-current-buffer (car entry) (nth 1 entry)))
193 (goto-char (point-max))
194 (unless (eq (char-after (1- (point))) ?\n)
196 (insert (format "Lines: %d\n" (nth 4 entry)))
199 (nnheader-fold-continuation-lines)
202 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
203 (nndoc-possibly-change-buffer newsgroup server)
205 (let ((buffer (or buffer nntp-server-buffer))
206 (entry (cdr (assq article nndoc-dissection-alist)))
211 (if (stringp article)
213 (insert-buffer-substring
214 nndoc-current-buffer (car entry) (nth 1 entry))
217 (insert-buffer-substring
218 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
220 (when nndoc-prepare-body-function
221 (funcall nndoc-prepare-body-function))
222 (when nndoc-article-transform-function
223 (funcall nndoc-article-transform-function article))
226 (deffoo nndoc-request-group (group &optional server dont-check)
230 ((not (nndoc-possibly-change-buffer group server))
231 (nnheader-report 'nndoc "No such file or buffer: %s"
234 (nnheader-report 'nndoc "Selected group %s" group)
236 ((zerop (setq number (length nndoc-dissection-alist)))
237 (nndoc-close-group group)
238 (nnheader-report 'nndoc "No articles in group %s" group))
240 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
242 (deffoo nndoc-request-type (group &optional article)
243 (cond ((not article) 'unknown)
244 (nndoc-post-type nndoc-post-type)
247 (deffoo nndoc-close-group (group &optional server)
248 (nndoc-possibly-change-buffer group server)
249 (and nndoc-current-buffer
250 (buffer-name nndoc-current-buffer)
251 (kill-buffer nndoc-current-buffer))
252 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
254 (setq nndoc-current-buffer nil)
255 (nnoo-close-server 'nndoc server)
256 (setq nndoc-dissection-alist nil)
259 (deffoo nndoc-request-list (&optional server)
262 (deffoo nndoc-request-newgroups (date &optional server)
265 (deffoo nndoc-request-list-newsgroups (&optional server)
269 ;;; Internal functions.
271 (defun nndoc-possibly-change-buffer (group source)
274 ;; The current buffer is this group's buffer.
275 ((and nndoc-current-buffer
276 (buffer-name nndoc-current-buffer)
277 (eq nndoc-current-buffer
278 (setq buf (cdr (assoc group nndoc-group-alist))))))
279 ;; We change buffers by taking an old from the group alist.
280 ;; `source' is either a string (a file name) or a buffer object.
282 (setq nndoc-current-buffer buf))
283 ;; It's a totally new group.
284 ((or (and (bufferp nndoc-address)
285 (buffer-name nndoc-address))
286 (and (stringp nndoc-address)
287 (file-exists-p nndoc-address)
288 (not (file-directory-p nndoc-address))))
289 (push (cons group (setq nndoc-current-buffer
291 (concat " *nndoc " group "*"))))
293 (setq nndoc-dissection-alist nil)
295 (set-buffer nndoc-current-buffer)
297 (if (stringp nndoc-address)
298 (nnheader-insert-file-contents nndoc-address)
299 (insert-buffer-substring nndoc-address))
300 (run-hooks 'nndoc-open-document-hook))))
301 ;; Initialize the nndoc structures according to this new document.
302 (when (and nndoc-current-buffer
303 (not nndoc-dissection-alist))
305 (set-buffer nndoc-current-buffer)
307 (if (eq nndoc-article-type 'mime-parts)
308 (nndoc-dissect-mime-parts)
309 (nndoc-dissect-buffer))))
310 (unless nndoc-current-buffer
311 (nndoc-close-server))
312 ;; Return whether we managed to select a file.
313 nndoc-current-buffer))
316 ;;; Deciding what document type we have
319 (defun nndoc-set-delims ()
320 "Set the nndoc delimiter variables according to the type of the document."
321 (let ((vars '(nndoc-file-begin
323 nndoc-article-begin-function
324 nndoc-head-begin nndoc-head-end
325 nndoc-file-end nndoc-article-begin
326 nndoc-body-begin nndoc-body-end-function nndoc-body-end
327 nndoc-prepare-body-function nndoc-article-transform-function
328 nndoc-generate-head-function nndoc-body-begin-function
329 nndoc-head-begin-function)))
331 (set (pop vars) nil)))
333 ;; Guess away until we find the real file type.
334 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
336 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
337 ;; Set the nndoc variables.
339 (set (intern (format "nndoc-%s" (caar defs)))
342 (defun nndoc-guess-type (subtype)
343 (let ((alist nndoc-type-alist)
344 results result entry)
345 (while (and (not result)
346 (setq entry (pop alist)))
347 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
348 (goto-char (point-min))
349 ;; Remove blank lines.
350 (while (eq (following-char) ?\n)
352 (when (numberp (setq result (funcall (intern
353 (format "nndoc-%s-type-p"
355 (push (cons result entry) results)
357 (unless (or result results)
358 (error "Document is not of any recognized type"))
361 (cadar (sort results 'car-less-than-car)))))
364 ;;; Built-in type predicates and functions
367 (defun nndoc-mbox-type-p ()
368 (when (looking-at message-unix-mail-delimiter)
371 (defun nndoc-mbox-article-begin ()
372 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
373 (goto-char (match-beginning 0))))
375 (defun nndoc-mbox-body-end ()
380 (and (re-search-backward
381 (concat "^" message-unix-mail-delimiter) nil t)
383 (search-forward "\n\n" beg t)
385 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
386 (setq len (string-to-int (match-string 1)))
387 (search-forward "\n\n" beg t)
388 (unless (= (setq len (+ (point) len)) (point-max))
389 (and (< len (point-max))
391 (looking-at message-unix-mail-delimiter)))))
394 (defun nndoc-mmdf-type-p ()
395 (when (looking-at "\^A\^A\^A\^A$")
398 (defun nndoc-news-type-p ()
399 (when (looking-at "^Path:.*\n")
402 (defun nndoc-rnews-type-p ()
403 (when (looking-at "#! *rnews")
406 (defun nndoc-rnews-body-end ()
407 (and (re-search-backward nndoc-article-begin nil t)
409 (goto-char (+ (point) (string-to-int (match-string 1))))))
411 (defun nndoc-babyl-type-p ()
412 (when (re-search-forward "\^_\^L *\n" nil t)
415 (defun nndoc-babyl-body-begin ()
416 (re-search-forward "^\n" nil t)
417 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
418 (let ((next (or (save-excursion
419 (re-search-forward nndoc-article-begin nil t))
421 (unless (re-search-forward "^\n" next t)
425 (forward-line -1)))))
427 (defun nndoc-babyl-head-begin ()
428 (when (re-search-forward "^[0-9].*\n" nil t)
429 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
433 (defun nndoc-forward-type-p ()
434 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
435 (not (re-search-forward "^Subject:.*digest" nil t))
436 (not (re-search-backward "^From:" nil t 2))
437 (not (re-search-forward "^From:" nil t 2)))
440 (defun nndoc-rfc934-type-p ()
441 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
442 (not (re-search-forward "^Subject:.*digest" nil t))
443 (not (re-search-backward "^From:" nil t 2))
444 (not (re-search-forward "^From:" nil t 2)))
447 (defun nndoc-rfc822-forward-type-p ()
449 (message-narrow-to-head)
450 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
453 (defun nndoc-rfc822-forward-body-end-function ()
454 (goto-char (point-max)))
456 (defun nndoc-mime-parts-type-p ()
457 (let ((case-fold-search t)
458 (limit (search-forward "\n\n" nil t)))
459 (goto-char (point-min))
463 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
464 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
468 (defun nndoc-transform-mime-parts (article)
469 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
470 (headers (nth 5 entry)))
472 (goto-char (point-min))
475 (defun nndoc-generate-mime-parts-head (article)
476 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
477 (headers (nth 6 entry)))
479 (narrow-to-region (point) (point))
480 (insert-buffer-substring
481 nndoc-current-buffer (car entry) (nth 1 entry))
482 (goto-char (point-max)))
486 (defun nndoc-clari-briefs-type-p ()
487 (when (let ((case-fold-search nil))
488 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
491 (defun nndoc-transform-clari-briefs (article)
492 (goto-char (point-min))
493 (when (looking-at " *\\*\\(.*\\)\n")
494 (replace-match "" t t))
495 (nndoc-generate-clari-briefs-head article))
497 (defun nndoc-generate-clari-briefs-head (article)
498 (let ((entry (cdr (assq article nndoc-dissection-alist)))
501 (set-buffer nndoc-current-buffer)
503 (narrow-to-region (car entry) (nth 3 entry))
504 (goto-char (point-min))
505 (when (looking-at " *\\*\\(.*\\)$")
506 (setq subject (match-string 1))
507 (when (string-match "[ \t]+$" subject)
508 (setq subject (substring subject 0 (match-beginning 0)))))
510 (let ((case-fold-search nil))
512 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
513 (setq from (match-string 1)))))
514 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
515 "\nSubject: " (or subject "(no subject)") "\n")))
518 (defun nndoc-mime-digest-type-p ()
519 (let ((case-fold-search t)
520 boundary-id b-delimiter entry)
523 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
524 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
527 (setq boundary-id (match-string 1)
528 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
529 (setq entry (assq 'mime-digest nndoc-type-alist))
532 (cons 'head-end "^ ?$")
533 (cons 'body-begin "^ ?\n")
534 (cons 'article-begin b-delimiter)
535 (cons 'body-end-function 'nndoc-digest-body-end)
536 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
539 (defun nndoc-standard-digest-type-p ()
540 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
542 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
545 (defun nndoc-digest-body-end ()
546 (and (re-search-forward nndoc-article-begin nil t)
547 (goto-char (match-beginning 0))))
549 (defun nndoc-slack-digest-type-p ()
552 (defun nndoc-lanl-gov-announce-type-p ()
553 (when (let ((case-fold-search nil))
554 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
557 (defun nndoc-transform-lanl-gov-announce (article)
558 (goto-char (point-max))
559 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
560 (replace-match "\n\nGet it at \\1 (\\2)" t nil)))
562 (defun nndoc-generate-lanl-gov-head (article)
563 (let ((entry (cdr (assq article nndoc-dissection-alist)))
564 (e-mail "no address given")
567 (set-buffer nndoc-current-buffer)
569 (narrow-to-region (car entry) (nth 1 entry))
570 (goto-char (point-min))
571 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
572 (setq subject (concat " (" (match-string 1) ")"))
573 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
574 (setq e-mail (match-string 1)))
575 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
577 (setq subject (concat (match-string 1) subject))
578 (setq from (concat (match-string 2) " <" e-mail ">"))))))
579 (while (and from (string-match "(\[^)\]*)" from))
580 (setq from (replace-match "" t t from)))
581 (insert "From: " (or from "unknown")
582 "\nSubject: " (or subject "(no subject)") "\n")))
584 (defun nndoc-nsmail-type-p ()
585 (when (looking-at "From - ")
588 (deffoo nndoc-request-accept-article (group &optional server last)
593 ;;; Functions for dissecting the documents
596 (defun nndoc-search (regexp)
598 (re-search-forward regexp nil t)
599 (beginning-of-line)))
601 (defun nndoc-dissect-buffer ()
602 "Go through the document and partition it into heads/bodies/articles."
605 head-begin head-end body-begin body-end)
606 (setq nndoc-dissection-alist nil)
608 (set-buffer nndoc-current-buffer)
609 (goto-char (point-min))
610 ;; Remove blank lines.
611 (while (eq (following-char) ?\n)
613 ;; Find the beginning of the file.
614 (when nndoc-file-begin
615 (nndoc-search nndoc-file-begin))
616 ;; Go through the file.
617 (while (if (and first nndoc-first-article)
618 (nndoc-search nndoc-first-article)
619 (nndoc-article-begin))
621 (cond (nndoc-head-begin-function
622 (funcall nndoc-head-begin-function))
624 (nndoc-search nndoc-head-begin)))
627 (looking-at nndoc-file-end)))
628 (goto-char (point-max))
629 (setq head-begin (point))
630 (nndoc-search (or nndoc-head-end "^$"))
631 (setq head-end (point))
632 (if nndoc-body-begin-function
633 (funcall nndoc-body-begin-function)
634 (nndoc-search (or nndoc-body-begin "^\n")))
635 (setq body-begin (point))
636 (or (and nndoc-body-end-function
637 (funcall nndoc-body-end-function))
639 (nndoc-search nndoc-body-end))
640 (nndoc-article-begin)
642 (goto-char (point-max))
644 (and (re-search-backward nndoc-file-end nil t)
645 (beginning-of-line)))))
646 (setq body-end (point))
647 (push (list (incf i) head-begin head-end body-begin body-end
648 (count-lines body-begin body-end))
649 nndoc-dissection-alist))))))
651 (defun nndoc-article-begin ()
652 (if nndoc-article-begin-function
653 (funcall nndoc-article-begin-function)
655 (nndoc-search nndoc-article-begin))))
657 (defun nndoc-unquote-dashes ()
658 "Unquote quoted non-separators in digests."
659 (while (re-search-forward "^- -"nil t)
660 (replace-match "-" t t)))
662 ;; Against compiler warnings.
663 (defvar nndoc-mime-split-ordinal)
665 (defun nndoc-dissect-mime-parts ()
666 "Go through a MIME composite article and partition it into sub-articles.
667 When a MIME entity contains sub-entities, dissection produces one article for
668 the header of this entity, and one article per sub-entity."
669 (setq nndoc-dissection-alist nil
670 nndoc-mime-split-ordinal 0)
672 (set-buffer nndoc-current-buffer)
673 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
675 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
677 "Dissect an entity, within a composite MIME message.
678 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
679 ARTICLE-INSERT should be added at beginning for generating a full article.
680 The string POSITION holds a dotted decimal representation of the article
681 position in the hierarchical structure, it is nil for the outer entity.
682 PARENT is the message-ID of the parent summary line, or nil for none."
683 (let ((case-fold-search t)
684 (message-id (nnmail-message-id))
685 head-end body-begin summary-insert message-rfc822 multipart-any
686 subject content-type type subtype boundary-regexp)
687 ;; Gracefully handle a missing body.
688 (goto-char head-begin)
689 (if (search-forward "\n\n" body-end t)
690 (setq head-end (1- (point))
692 (setq head-end body-end
693 body-begin body-end))
694 (narrow-to-region head-begin head-end)
695 ;; Save MIME attributes.
696 (goto-char head-begin)
697 (setq content-type (message-fetch-field "Content-Type"))
700 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
701 (setq type (downcase (match-string 1 content-type))
702 subtype (downcase (match-string 2 content-type))
703 message-rfc822 (and (string= type "message")
704 (string= subtype "rfc822"))
705 multipart-any (string= type "multipart")))
706 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
707 (setq subject (match-string 1 content-type)))
708 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
709 (setq boundary-regexp (concat "^--"
711 (match-string 1 content-type))
712 "\\(--\\)?[ \t]*\n"))))
714 (when (or multipart-any (not article-insert))
715 (setq subject (message-fetch-field "Subject"))))
719 ;; Prepare the article and summary inserts.
720 (unless article-insert
721 (setq article-insert (buffer-substring (point-min) (point-max))
722 head-end head-begin))
723 (setq summary-insert article-insert)
724 ;; - summary Subject.
726 (let ((line (concat "Subject: <" position
727 (and position multipart-any ".")
728 (and multipart-any "*")
729 (and (or position multipart-any) " ")
730 (cond ((string= subtype "plain") type)
731 ((string= subtype "basic") type)
737 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
738 (replace-match line t t summary-insert)
739 (concat summary-insert line))))
740 ;; - summary Message-ID.
742 (let ((line (concat "Message-ID: " message-id "\n")))
743 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
744 (replace-match line t t summary-insert)
745 (concat summary-insert line))))
746 ;; - summary References.
749 (let ((line (concat "References: " parent "\n")))
750 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
752 (replace-match line t t summary-insert)
753 (concat summary-insert line)))))
754 ;; Generate dissection information for this entity.
755 (push (list (incf nndoc-mime-split-ordinal)
756 head-begin head-end body-begin body-end
757 (count-lines body-begin body-end)
758 article-insert summary-insert)
759 nndoc-dissection-alist)
760 ;; Recurse for all sub-entities, if any.
765 (nndoc-dissect-mime-parts-sub body-begin body-end nil
766 position message-id)))
767 ((and multipart-any boundary-regexp)
768 (let ((part-counter 0)
769 part-begin part-end eof-flag)
770 (while (string-match "\
771 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
773 (setq article-insert (replace-match "" t t article-insert)))
774 (let ((case-fold-search nil))
775 (goto-char body-begin)
776 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
777 (while (not eof-flag)
778 (setq part-begin (point))
779 (cond ((re-search-forward boundary-regexp body-end t)
780 (or (not (match-string 1))
781 (string= (match-string 1) "")
784 (setq part-end (point))
786 (t (setq part-end body-end
789 (nndoc-dissect-mime-parts-sub
790 part-begin part-end article-insert
793 (format "%d" (incf part-counter)))
797 (defun nndoc-add-type (definition &optional position)
798 "Add document DEFINITION to the list of nndoc document definitions.
799 If POSITION is nil or `last', the definition will be added
800 as the last checked definition, if t or `first', add as the
801 first definition, and if any other symbol, add after that
802 symbol in the alist."
803 ;; First remove any old instances.
804 (gnus-pull (car definition) nndoc-type-alist)
805 ;; Then enter the new definition in the proper place.
807 ((or (null position) (eq position 'last))
808 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
809 ((or (eq position t) (eq position 'first))
810 (push definition nndoc-type-alist))
812 (let ((list (memq (assq position nndoc-type-alist)
815 (error "No such position: %s" position))
816 (setcdr list (cons definition (cdr list)))))))
820 ;;; nndoc.el ends here