1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995,96,97,98,99 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))
561 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
562 ;; (replace-match "" t t))
565 (defun nndoc-generate-lanl-gov-head (article)
566 (let ((entry (cdr (assq article nndoc-dissection-alist)))
567 (e-mail "no address given")
570 (set-buffer nndoc-current-buffer)
572 (narrow-to-region (car entry) (nth 1 entry))
573 (goto-char (point-min))
574 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
575 (setq subject (concat " (" (match-string 1) ")"))
576 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
577 (setq e-mail (match-string 1)))
578 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
580 (setq subject (concat (match-string 1) subject))
581 (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