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.
38 (defvoo nndoc-article-type 'guess
40 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
41 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
42 `slack-digest', `clari-briefs', `nsmail' or `guess'.")
44 (defvoo nndoc-post-type 'mail
45 "*Whether the nndoc group is `mail' or `post'.")
47 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
48 "Hook run after opening a document.
49 The default function removes all trailing carriage returns
52 (defvar nndoc-type-alist
54 (article-begin . "^\^A\^A\^A\^A\n")
55 (body-end . "^\^A\^A\^A\^A\n"))
57 (article-begin . "^From - "))
59 (article-begin . "^Path:"))
61 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
62 (body-end-function . nndoc-rnews-body-end))
64 (article-begin-function . nndoc-mbox-article-begin)
65 (body-end-function . nndoc-mbox-body-end))
67 (article-begin . "\^_\^L *\n")
69 (body-begin-function . nndoc-babyl-body-begin)
70 (head-begin-function . nndoc-babyl-head-begin))
72 (article-begin . "^-+ Start of forwarded message -+\n+")
73 (body-end . "^-+ End of forwarded message -+$")
74 (prepare-body-function . nndoc-unquote-dashes))
76 (article-begin . "^--.*\n+")
78 (prepare-body-function . nndoc-unquote-dashes))
80 (article-begin . "^ \\*")
81 (body-end . "^\t------*[ \t]^*\n^ \\*")
84 (generate-head-function . nndoc-generate-clari-briefs-head)
85 (article-transform-function . nndoc-transform-clari-briefs))
87 (generate-head-function . nndoc-generate-mime-parts-head)
88 (article-transform-function . nndoc-transform-mime-parts))
90 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
91 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
92 (prepare-body-function . nndoc-unquote-dashes)
93 (body-end-function . nndoc-digest-body-end)
95 (body-begin . "^ *\n")
96 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
97 (subtype digest guess))
99 (article-begin . "^------------------------------*[\n \t]+")
101 (body-end-function . nndoc-digest-body-end)
102 (body-begin . "^ ?$")
103 (file-end . "^End of")
104 (prepare-body-function . nndoc-unquote-dashes)
105 (subtype digest guess))
107 (article-begin . "^\\\\\\\\\n")
108 (head-begin . "^Paper.*:")
109 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
111 (body-end . "-------------------------------------------------")
112 (file-end . "^Title: Recent Seminal")
113 (generate-head-function . nndoc-generate-lanl-gov-head)
114 (article-transform-function . nndoc-transform-lanl-gov-announce)
115 (subtype preprints guess))
117 (article-begin . "^\n")
118 (body-end-function . nndoc-rfc822-forward-body-end-function))
130 (defvoo nndoc-file-begin nil)
131 (defvoo nndoc-first-article nil)
132 (defvoo nndoc-article-begin nil)
133 (defvoo nndoc-head-begin nil)
134 (defvoo nndoc-head-end nil)
135 (defvoo nndoc-file-end nil)
136 (defvoo nndoc-body-begin nil)
137 (defvoo nndoc-body-end-function nil)
138 (defvoo nndoc-body-begin-function nil)
139 (defvoo nndoc-head-begin-function nil)
140 (defvoo nndoc-body-end nil)
141 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
142 ;; following items. ARTICLE acts as the association key and is an ordinal
143 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
144 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
145 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
146 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
147 ;; generation, respectively. Other headers usually follow directly from the
148 ;; buffer. Value `nil' means no insert.
149 (defvoo nndoc-dissection-alist nil)
150 (defvoo nndoc-prepare-body-function nil)
151 (defvoo nndoc-generate-head-function nil)
152 (defvoo nndoc-article-transform-function nil)
153 (defvoo nndoc-article-begin-function nil)
155 (defvoo nndoc-status-string "")
156 (defvoo nndoc-group-alist nil)
157 (defvoo nndoc-current-buffer nil
158 "Current nndoc news buffer.")
159 (defvoo nndoc-address nil)
161 (defconst nndoc-version "nndoc 1.0"
166 ;;; Interface functions
168 (nnoo-define-basics nndoc)
170 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
171 (when (nndoc-possibly-change-buffer newsgroup server)
173 (set-buffer nntp-server-buffer)
176 (if (stringp (car articles))
179 (when (setq entry (cdr (assq (setq article (pop articles))
180 nndoc-dissection-alist)))
181 (insert (format "221 %d Article retrieved.\n" article))
182 (if nndoc-generate-head-function
183 (funcall nndoc-generate-head-function article)
184 (insert-buffer-substring
185 nndoc-current-buffer (car entry) (nth 1 entry)))
186 (goto-char (point-max))
187 (unless (eq (char-after (1- (point))) ?\n)
189 (insert (format "Lines: %d\n" (nth 4 entry)))
192 (nnheader-fold-continuation-lines)
195 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
196 (nndoc-possibly-change-buffer newsgroup server)
198 (let ((buffer (or buffer nntp-server-buffer))
199 (entry (cdr (assq article nndoc-dissection-alist)))
204 (if (stringp article)
206 (insert-buffer-substring
207 nndoc-current-buffer (car entry) (nth 1 entry))
210 (insert-buffer-substring
211 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
213 (when nndoc-prepare-body-function
214 (funcall nndoc-prepare-body-function))
215 (when nndoc-article-transform-function
216 (funcall nndoc-article-transform-function article))
219 (deffoo nndoc-request-group (group &optional server dont-check)
223 ((not (nndoc-possibly-change-buffer group server))
224 (nnheader-report 'nndoc "No such file or buffer: %s"
227 (nnheader-report 'nndoc "Selected group %s" group)
229 ((zerop (setq number (length nndoc-dissection-alist)))
230 (nndoc-close-group group)
231 (nnheader-report 'nndoc "No articles in group %s" group))
233 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
235 (deffoo nndoc-request-type (group &optional article)
236 (cond ((not article) 'unknown)
237 (nndoc-post-type nndoc-post-type)
240 (deffoo nndoc-close-group (group &optional server)
241 (nndoc-possibly-change-buffer group server)
242 (and nndoc-current-buffer
243 (buffer-name nndoc-current-buffer)
244 (kill-buffer nndoc-current-buffer))
245 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
247 (setq nndoc-current-buffer nil)
248 (nnoo-close-server 'nndoc server)
249 (setq nndoc-dissection-alist nil)
252 (deffoo nndoc-request-list (&optional server)
255 (deffoo nndoc-request-newgroups (date &optional server)
258 (deffoo nndoc-request-list-newsgroups (&optional server)
262 ;;; Internal functions.
264 (defun nndoc-possibly-change-buffer (group source)
267 ;; The current buffer is this group's buffer.
268 ((and nndoc-current-buffer
269 (buffer-name nndoc-current-buffer)
270 (eq nndoc-current-buffer
271 (setq buf (cdr (assoc group nndoc-group-alist))))))
272 ;; We change buffers by taking an old from the group alist.
273 ;; `source' is either a string (a file name) or a buffer object.
275 (setq nndoc-current-buffer buf))
276 ;; It's a totally new group.
277 ((or (and (bufferp nndoc-address)
278 (buffer-name nndoc-address))
279 (and (stringp nndoc-address)
280 (file-exists-p nndoc-address)
281 (not (file-directory-p nndoc-address))))
282 (push (cons group (setq nndoc-current-buffer
284 (concat " *nndoc " group "*"))))
286 (setq nndoc-dissection-alist nil)
288 (set-buffer nndoc-current-buffer)
290 (if (stringp nndoc-address)
291 (nnheader-insert-file-contents nndoc-address)
292 (insert-buffer-substring nndoc-address))
293 (run-hooks 'nndoc-open-document-hook))))
294 ;; Initialize the nndoc structures according to this new document.
295 (when (and nndoc-current-buffer
296 (not nndoc-dissection-alist))
298 (set-buffer nndoc-current-buffer)
300 (if (eq nndoc-article-type 'mime-parts)
301 (nndoc-dissect-mime-parts)
302 (nndoc-dissect-buffer))))
303 (unless nndoc-current-buffer
304 (nndoc-close-server))
305 ;; Return whether we managed to select a file.
306 nndoc-current-buffer))
309 ;;; Deciding what document type we have
312 (defun nndoc-set-delims ()
313 "Set the nndoc delimiter variables according to the type of the document."
314 (let ((vars '(nndoc-file-begin
316 nndoc-article-begin-function
317 nndoc-head-begin nndoc-head-end
318 nndoc-file-end nndoc-article-begin
319 nndoc-body-begin nndoc-body-end-function nndoc-body-end
320 nndoc-prepare-body-function nndoc-article-transform-function
321 nndoc-generate-head-function nndoc-body-begin-function
322 nndoc-head-begin-function)))
324 (set (pop vars) nil)))
326 ;; Guess away until we find the real file type.
327 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
329 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
330 ;; Set the nndoc variables.
332 (set (intern (format "nndoc-%s" (caar defs)))
335 (defun nndoc-guess-type (subtype)
336 (let ((alist nndoc-type-alist)
337 results result entry)
338 (while (and (not result)
339 (setq entry (pop alist)))
340 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
341 (goto-char (point-min))
342 ;; Remove blank lines.
343 (while (eq (following-char) ?\n)
345 (when (numberp (setq result (funcall (intern
346 (format "nndoc-%s-type-p"
348 (push (cons result entry) results)
350 (unless (or result results)
351 (error "Document is not of any recognized type"))
354 (cadar (sort results 'car-less-than-car)))))
357 ;;; Built-in type predicates and functions
360 (defun nndoc-mbox-type-p ()
361 (when (looking-at message-unix-mail-delimiter)
364 (defun nndoc-mbox-article-begin ()
365 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
366 (goto-char (match-beginning 0))))
368 (defun nndoc-mbox-body-end ()
373 (and (re-search-backward
374 (concat "^" message-unix-mail-delimiter) nil t)
376 (search-forward "\n\n" beg t)
378 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
379 (setq len (string-to-int (match-string 1)))
380 (search-forward "\n\n" beg t)
381 (unless (= (setq len (+ (point) len)) (point-max))
382 (and (< len (point-max))
384 (looking-at message-unix-mail-delimiter)))))
387 (defun nndoc-mmdf-type-p ()
388 (when (looking-at "\^A\^A\^A\^A$")
391 (defun nndoc-news-type-p ()
392 (when (looking-at "^Path:.*\n")
395 (defun nndoc-rnews-type-p ()
396 (when (looking-at "#! *rnews")
399 (defun nndoc-rnews-body-end ()
400 (and (re-search-backward nndoc-article-begin nil t)
402 (goto-char (+ (point) (string-to-int (match-string 1))))))
404 (defun nndoc-babyl-type-p ()
405 (when (re-search-forward "\^_\^L *\n" nil t)
408 (defun nndoc-babyl-body-begin ()
409 (re-search-forward "^\n" nil t)
410 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
411 (let ((next (or (save-excursion
412 (re-search-forward nndoc-article-begin nil t))
414 (unless (re-search-forward "^\n" next t)
418 (forward-line -1)))))
420 (defun nndoc-babyl-head-begin ()
421 (when (re-search-forward "^[0-9].*\n" nil t)
422 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
426 (defun nndoc-forward-type-p ()
427 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
428 (not (re-search-forward "^Subject:.*digest" nil t))
429 (not (re-search-backward "^From:" nil t 2))
430 (not (re-search-forward "^From:" nil t 2)))
433 (defun nndoc-rfc934-type-p ()
434 (when (and (re-search-forward "^-+ Start of forwarded.*\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-rfc822-forward-type-p ()
442 (message-narrow-to-head)
443 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
446 (defun nndoc-rfc822-forward-body-end-function ()
447 (goto-char (point-max)))
449 (defun nndoc-mime-parts-type-p ()
450 (let ((case-fold-search t)
451 (limit (search-forward "\n\n" nil t)))
452 (goto-char (point-min))
456 ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
457 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
461 (defun nndoc-transform-mime-parts (article)
462 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
463 (headers (nth 5 entry)))
465 (goto-char (point-min))
468 (defun nndoc-generate-mime-parts-head (article)
469 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
470 (headers (nth 6 entry)))
472 (narrow-to-region (point) (point))
473 (insert-buffer-substring
474 nndoc-current-buffer (car entry) (nth 1 entry))
475 (goto-char (point-max)))
479 (defun nndoc-clari-briefs-type-p ()
480 (when (let ((case-fold-search nil))
481 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
484 (defun nndoc-transform-clari-briefs (article)
485 (goto-char (point-min))
486 (when (looking-at " *\\*\\(.*\\)\n")
487 (replace-match "" t t))
488 (nndoc-generate-clari-briefs-head article))
490 (defun nndoc-generate-clari-briefs-head (article)
491 (let ((entry (cdr (assq article nndoc-dissection-alist)))
494 (set-buffer nndoc-current-buffer)
496 (narrow-to-region (car entry) (nth 3 entry))
497 (goto-char (point-min))
498 (when (looking-at " *\\*\\(.*\\)$")
499 (setq subject (match-string 1))
500 (when (string-match "[ \t]+$" subject)
501 (setq subject (substring subject 0 (match-beginning 0)))))
503 (let ((case-fold-search nil))
505 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
506 (setq from (match-string 1)))))
507 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
508 "\nSubject: " (or subject "(no subject)") "\n")))
510 (defun nndoc-standard-digest-type-p ()
511 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
513 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
516 (defun nndoc-digest-body-end ()
517 (and (re-search-forward nndoc-article-begin nil t)
518 (goto-char (match-beginning 0))))
520 (defun nndoc-slack-digest-type-p ()
523 (defun nndoc-lanl-gov-announce-type-p ()
524 (when (let ((case-fold-search nil))
525 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
528 (defun nndoc-transform-lanl-gov-announce (article)
529 (goto-char (point-max))
530 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
531 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
532 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
533 ;; (replace-match "" t t))
536 (defun nndoc-generate-lanl-gov-head (article)
537 (let ((entry (cdr (assq article nndoc-dissection-alist)))
538 (e-mail "no address given")
541 (set-buffer nndoc-current-buffer)
543 (narrow-to-region (car entry) (nth 1 entry))
544 (goto-char (point-min))
545 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
546 (setq subject (concat " (" (match-string 1) ")"))
547 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
548 (setq e-mail (match-string 1)))
549 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
551 (setq subject (concat (match-string 1) subject))
552 (setq from (concat (match-string 2) " <" e-mail ">"))))
554 (while (and from (string-match "(\[^)\]*)" from))
555 (setq from (replace-match "" t t from)))
556 (insert "From: " (or from "unknown")
557 "\nSubject: " (or subject "(no subject)") "\n")))
559 (defun nndoc-nsmail-type-p ()
560 (when (looking-at "From - ")
563 (deffoo nndoc-request-accept-article (group &optional server last)
568 ;;; Functions for dissecting the documents
571 (defun nndoc-search (regexp)
573 (re-search-forward regexp nil t)
574 (beginning-of-line)))
576 (defun nndoc-dissect-buffer ()
577 "Go through the document and partition it into heads/bodies/articles."
580 head-begin head-end body-begin body-end)
581 (setq nndoc-dissection-alist nil)
583 (set-buffer nndoc-current-buffer)
584 (goto-char (point-min))
585 ;; Remove blank lines.
586 (while (eq (following-char) ?\n)
588 ;; Find the beginning of the file.
589 (when nndoc-file-begin
590 (nndoc-search nndoc-file-begin))
591 ;; Go through the file.
592 (while (if (and first nndoc-first-article)
593 (nndoc-search nndoc-first-article)
594 (nndoc-article-begin))
596 (cond (nndoc-head-begin-function
597 (funcall nndoc-head-begin-function))
599 (nndoc-search nndoc-head-begin)))
602 (looking-at nndoc-file-end)))
603 (goto-char (point-max))
604 (setq head-begin (point))
605 (nndoc-search (or nndoc-head-end "^$"))
606 (setq head-end (point))
607 (if nndoc-body-begin-function
608 (funcall nndoc-body-begin-function)
609 (nndoc-search (or nndoc-body-begin "^\n")))
610 (setq body-begin (point))
611 (or (and nndoc-body-end-function
612 (funcall nndoc-body-end-function))
614 (nndoc-search nndoc-body-end))
615 (nndoc-article-begin)
617 (goto-char (point-max))
619 (and (re-search-backward nndoc-file-end nil t)
620 (beginning-of-line)))))
621 (setq body-end (point))
622 (push (list (incf i) head-begin head-end body-begin body-end
623 (count-lines body-begin body-end))
624 nndoc-dissection-alist))))))
626 (defun nndoc-article-begin ()
627 (if nndoc-article-begin-function
628 (funcall nndoc-article-begin-function)
630 (nndoc-search nndoc-article-begin))))
632 (defun nndoc-unquote-dashes ()
633 "Unquote quoted non-separators in digests."
634 (while (re-search-forward "^- -"nil t)
635 (replace-match "-" t t)))
637 ;; Against compiler warnings.
638 (defvar nndoc-mime-split-ordinal)
640 (defun nndoc-dissect-mime-parts ()
641 "Go through a MIME composite article and partition it into sub-articles.
642 When a MIME entity contains sub-entities, dissection produces one article for
643 the header of this entity, and one article per sub-entity."
644 (setq nndoc-dissection-alist nil
645 nndoc-mime-split-ordinal 0)
647 (set-buffer nndoc-current-buffer)
648 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
650 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
652 "Dissect an entity, within a composite MIME message.
653 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
654 ARTICLE-INSERT should be added at beginning for generating a full article.
655 The string POSITION holds a dotted decimal representation of the article
656 position in the hierarchical structure, it is nil for the outer entity.
657 PARENT is the message-ID of the parent summary line, or nil for none."
658 (let ((case-fold-search t)
659 (message-id (nnmail-message-id))
660 head-end body-begin summary-insert message-rfc822 multipart-any
661 subject content-type type subtype boundary-regexp)
662 ;; Gracefully handle a missing body.
663 (goto-char head-begin)
664 (if (search-forward "\n\n" body-end t)
665 (setq head-end (1- (point))
667 (setq head-end body-end
668 body-begin body-end))
669 (narrow-to-region head-begin head-end)
670 ;; Save MIME attributes.
671 (goto-char head-begin)
672 (setq content-type (message-fetch-field "Content-Type"))
675 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
676 (setq type (downcase (match-string 1 content-type))
677 subtype (downcase (match-string 2 content-type))
678 message-rfc822 (and (string= type "message")
679 (string= subtype "rfc822"))
680 multipart-any (string= type "multipart")))
681 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
682 (setq subject (match-string 1 content-type)))
683 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
684 (setq boundary-regexp (concat "^--"
686 (match-string 1 content-type))
687 "\\(--\\)?[ \t]*\n"))))
689 (when (or multipart-any (not article-insert))
690 (setq subject (message-fetch-field "Subject"))))
694 ;; Prepare the article and summary inserts.
695 (unless article-insert
696 (setq article-insert (buffer-substring (point-min) (point-max))
697 head-end head-begin))
698 (setq summary-insert article-insert)
699 ;; - summary Subject.
701 (let ((line (concat "Subject: <" position
702 (and position multipart-any ".")
703 (and multipart-any "*")
704 (and (or position multipart-any) " ")
705 (cond ((string= subtype "plain") type)
706 ((string= subtype "basic") type)
712 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
713 (replace-match line t t summary-insert)
714 (concat summary-insert line))))
715 ;; - summary Message-ID.
717 (let ((line (concat "Message-ID: " message-id "\n")))
718 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
719 (replace-match line t t summary-insert)
720 (concat summary-insert line))))
721 ;; - summary References.
724 (let ((line (concat "References: " parent "\n")))
725 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
727 (replace-match line t t summary-insert)
728 (concat summary-insert line)))))
729 ;; Generate dissection information for this entity.
730 (push (list (incf nndoc-mime-split-ordinal)
731 head-begin head-end body-begin body-end
732 (count-lines body-begin body-end)
733 article-insert summary-insert)
734 nndoc-dissection-alist)
735 ;; Recurse for all sub-entities, if any.
740 (nndoc-dissect-mime-parts-sub body-begin body-end nil
741 position message-id)))
742 ((and multipart-any boundary-regexp)
743 (let ((part-counter 0)
744 part-begin part-end eof-flag)
745 (while (string-match "\
746 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
748 (setq article-insert (replace-match "" t t article-insert)))
749 (let ((case-fold-search nil))
750 (goto-char body-begin)
751 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
752 (while (not eof-flag)
753 (setq part-begin (point))
754 (cond ((re-search-forward boundary-regexp body-end t)
755 (or (not (match-string 1))
756 (string= (match-string 1) "")
759 (setq part-end (point))
761 (t (setq part-end body-end
764 (nndoc-dissect-mime-parts-sub
765 part-begin part-end article-insert
768 (format "%d" (incf part-counter)))
772 (defun nndoc-add-type (definition &optional position)
773 "Add document DEFINITION to the list of nndoc document definitions.
774 If POSITION is nil or `last', the definition will be added
775 as the last checked definition, if t or `first', add as the
776 first definition, and if any other symbol, add after that
777 symbol in the alist."
778 ;; First remove any old instances.
779 (gnus-pull (car definition) nndoc-type-alist)
780 ;; Then enter the new definition in the proper place.
782 ((or (null position) (eq position 'last))
783 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
784 ((or (eq position t) (eq position 'first))
785 (push definition nndoc-type-alist))
787 (let ((list (memq (assq position nndoc-type-alist)
790 (error "No such position: %s" position))
791 (setcdr list (cons definition (cdr list)))))))
795 ;;; nndoc.el ends here