1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995,96,97,98 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.
34 (eval-when-compile (require 'cl))
38 (defvoo nndoc-article-type 'guess
40 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
41 `rfc934', `rfc822-forward', `mime-digest', `mime-parts', `standard-digest',
42 `slack-digest', `clari-briefs' 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 . "^Path:"))
59 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
60 (body-end-function . nndoc-rnews-body-end))
62 (article-begin-function . nndoc-mbox-article-begin)
63 (body-end-function . nndoc-mbox-body-end))
65 (article-begin . "\^_\^L *\n")
67 (body-begin-function . nndoc-babyl-body-begin)
68 (head-begin-function . nndoc-babyl-head-begin))
70 (article-begin . "^-+ Start of forwarded message -+\n+")
71 (body-end . "^-+ End of forwarded message -+$")
72 (prepare-body-function . nndoc-unquote-dashes))
74 (article-begin . "^--.*\n+")
76 (prepare-body-function . nndoc-unquote-dashes))
78 (article-begin . "^ \\*")
79 (body-end . "^\t------*[ \t]^*\n^ \\*")
82 (generate-head-function . nndoc-generate-clari-briefs-head)
83 (article-transform-function . nndoc-transform-clari-briefs))
89 (subtype digest guess))
91 (generate-head-function . nndoc-generate-mime-parts-head)
92 (article-transform-function . nndoc-transform-mime-parts))
94 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
95 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
96 (prepare-body-function . nndoc-unquote-dashes)
97 (body-end-function . nndoc-digest-body-end)
99 (body-begin . "^ *\n")
100 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
101 (subtype digest guess))
103 (article-begin . "^------------------------------*[\n \t]+")
105 (body-end-function . nndoc-digest-body-end)
106 (body-begin . "^ ?$")
107 (file-end . "^End of")
108 (prepare-body-function . nndoc-unquote-dashes)
109 (subtype digest guess))
111 (article-begin . "^\\\\\\\\\n")
112 (head-begin . "^Paper.*:")
113 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
115 (body-end . "-------------------------------------------------")
116 (file-end . "^Title: Recent Seminal")
117 (generate-head-function . nndoc-generate-lanl-gov-head)
118 (article-transform-function . nndoc-transform-lanl-gov-announce)
119 (subtype preprints guess))
121 (article-begin . "^\n")
122 (body-end-function . nndoc-rfc822-forward-body-end-function))
134 (defvoo nndoc-file-begin nil)
135 (defvoo nndoc-first-article nil)
136 (defvoo nndoc-article-begin nil)
137 (defvoo nndoc-head-begin nil)
138 (defvoo nndoc-head-end nil)
139 (defvoo nndoc-file-end nil)
140 (defvoo nndoc-body-begin nil)
141 (defvoo nndoc-body-end-function nil)
142 (defvoo nndoc-body-begin-function nil)
143 (defvoo nndoc-head-begin-function nil)
144 (defvoo nndoc-body-end nil)
145 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
146 ;; following items. ARTICLE is an ordinal starting at 1. HEAD-BEGIN,
147 ;; HEAD-END, BODY-BEGIN and BODY-END are positions in the `nndoc' buffer.
148 ;; LINE-COUNT is a count of lines in the body. SUBJECT, MESSAGE-ID and
149 ;; REFERENCES, only present for MIME dissections, are field values.
150 (defvoo nndoc-dissection-alist nil)
151 (defvoo nndoc-prepare-body-function nil)
152 (defvoo nndoc-generate-head-function nil)
153 (defvoo nndoc-article-transform-function nil)
154 (defvoo nndoc-article-begin-function nil)
156 (defvoo nndoc-status-string "")
157 (defvoo nndoc-group-alist nil)
158 (defvoo nndoc-current-buffer nil
159 "Current nndoc news buffer.")
160 (defvoo nndoc-address nil)
161 (defvoo nndoc-mime-header nil)
162 (defvoo nndoc-mime-subject nil)
164 (defconst nndoc-version "nndoc 1.0"
169 ;;; Interface functions
171 (nnoo-define-basics nndoc)
173 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
174 (when (nndoc-possibly-change-buffer newsgroup server)
176 (set-buffer nntp-server-buffer)
179 (if (stringp (car articles))
182 (when (setq entry (cdr (assq (setq article (pop articles))
183 nndoc-dissection-alist)))
184 (insert (format "221 %d Article retrieved.\n" article))
185 (if nndoc-generate-head-function
186 (funcall nndoc-generate-head-function article)
187 (insert-buffer-substring
188 nndoc-current-buffer (car entry) (nth 1 entry)))
189 (goto-char (point-max))
190 (unless (= (char-after (1- (point))) ?\n)
192 (insert (format "Lines: %d\n" (nth 4 entry)))
195 (nnheader-fold-continuation-lines)
198 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
199 (nndoc-possibly-change-buffer newsgroup server)
201 (let ((buffer (or buffer nntp-server-buffer))
202 (entry (cdr (assq article nndoc-dissection-alist)))
207 (if (stringp article)
209 (insert-buffer-substring
210 nndoc-current-buffer (car entry) (nth 1 entry))
213 (insert-buffer-substring
214 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
216 (when nndoc-prepare-body-function
217 (funcall nndoc-prepare-body-function))
218 (when nndoc-article-transform-function
219 (funcall nndoc-article-transform-function article))
222 (deffoo nndoc-request-group (group &optional server dont-check)
226 ((not (nndoc-possibly-change-buffer group server))
227 (nnheader-report 'nndoc "No such file or buffer: %s"
230 (nnheader-report 'nndoc "Selected group %s" group)
232 ((zerop (setq number (length nndoc-dissection-alist)))
233 (nndoc-close-group group)
234 (nnheader-report 'nndoc "No articles in group %s" group))
236 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
238 (deffoo nndoc-request-type (group &optional article)
239 (cond ((not article) 'unknown)
240 (nndoc-post-type nndoc-post-type)
243 (deffoo nndoc-close-group (group &optional server)
244 (nndoc-possibly-change-buffer group server)
245 (and nndoc-current-buffer
246 (buffer-name nndoc-current-buffer)
247 (kill-buffer nndoc-current-buffer))
248 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
250 (setq nndoc-current-buffer nil)
251 (nnoo-close-server 'nndoc server)
252 (setq nndoc-dissection-alist nil)
255 (deffoo nndoc-request-list (&optional server)
258 (deffoo nndoc-request-newgroups (date &optional server)
261 (deffoo nndoc-request-list-newsgroups (&optional server)
265 ;;; Internal functions.
267 (defun nndoc-possibly-change-buffer (group source)
270 ;; The current buffer is this group's buffer.
271 ((and nndoc-current-buffer
272 (buffer-name nndoc-current-buffer)
273 (eq nndoc-current-buffer
274 (setq buf (cdr (assoc group nndoc-group-alist))))))
275 ;; We change buffers by taking an old from the group alist.
276 ;; `source' is either a string (a file name) or a buffer object.
278 (setq nndoc-current-buffer buf))
279 ;; It's a totally new group.
280 ((or (and (bufferp nndoc-address)
281 (buffer-name nndoc-address))
282 (and (stringp nndoc-address)
283 (file-exists-p nndoc-address)
284 (not (file-directory-p nndoc-address))))
285 (push (cons group (setq nndoc-current-buffer
287 (concat " *nndoc " group "*"))))
289 (setq nndoc-dissection-alist nil)
291 (set-buffer nndoc-current-buffer)
293 (if (stringp nndoc-address)
294 (nnheader-insert-file-contents nndoc-address)
295 (insert-buffer-substring nndoc-address))
296 (run-hooks 'nndoc-open-document-hook))))
297 ;; Initialize the nndoc structures according to this new document.
298 (when (and nndoc-current-buffer
299 (not nndoc-dissection-alist))
301 (set-buffer nndoc-current-buffer)
303 (if (eq nndoc-article-type 'mime-parts)
304 (nndoc-dissect-mime-parts)
305 (nndoc-dissect-buffer))))
306 (unless nndoc-current-buffer
307 (nndoc-close-server))
308 ;; Return whether we managed to select a file.
309 nndoc-current-buffer))
312 ;;; Deciding what document type we have
315 (defun nndoc-set-delims ()
316 "Set the nndoc delimiter variables according to the type of the document."
317 (let ((vars '(nndoc-file-begin
319 nndoc-article-begin-function
320 nndoc-head-begin nndoc-head-end
321 nndoc-file-end nndoc-article-begin
322 nndoc-body-begin nndoc-body-end-function nndoc-body-end
323 nndoc-prepare-body-function nndoc-article-transform-function
324 nndoc-generate-head-function nndoc-body-begin-function
325 nndoc-head-begin-function)))
327 (set (pop vars) nil)))
329 ;; Guess away until we find the real file type.
330 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
332 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
333 ;; Set the nndoc variables.
335 (set (intern (format "nndoc-%s" (caar defs)))
338 (defun nndoc-guess-type (subtype)
339 (let ((alist nndoc-type-alist)
340 results result entry)
341 (while (and (not result)
342 (setq entry (pop alist)))
343 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
344 (goto-char (point-min))
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]+;\\(.*;\\)*"
457 "[ \t\n]*[ \t]boundary=\"?[^\"\n]*[^\" \t\n]")
461 (defun nndoc-transform-mime-parts (article)
462 (unless (= article 1)
463 ;; Ensure some MIME-Version.
464 (goto-char (point-min))
465 (search-forward "\n\n")
466 (let ((case-fold-search nil)
468 (goto-char (point-min))
469 (or (save-excursion (re-search-forward "^MIME-Version:" limit t))
470 (insert "Mime-Version: 1.0\n")))
471 ;; Generate default header before entity fields.
472 (goto-char (point-min))
473 (nndoc-generate-mime-parts-head article t)))
475 (defun nndoc-generate-mime-parts-head (article &optional body-present)
476 (let ((entry (cdr (assq (if body-present 1 article) nndoc-dissection-alist))))
477 (let ((subject (if body-present
479 (concat "<" (nth 5 entry) ">")))
480 (message-id (nth 6 entry))
481 (references (nth 7 entry)))
482 (insert nndoc-mime-header)
483 (and subject (insert "Subject: " subject "\n"))
484 (and message-id (insert "Message-ID: " message-id "\n"))
485 (and references (insert "References: " references "\n")))))
487 (defun nndoc-clari-briefs-type-p ()
488 (when (let ((case-fold-search nil))
489 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
492 (defun nndoc-transform-clari-briefs (article)
493 (goto-char (point-min))
494 (when (looking-at " *\\*\\(.*\\)\n")
495 (replace-match "" t t))
496 (nndoc-generate-clari-briefs-head article))
498 (defun nndoc-generate-clari-briefs-head (article)
499 (let ((entry (cdr (assq article nndoc-dissection-alist)))
502 (set-buffer nndoc-current-buffer)
504 (narrow-to-region (car entry) (nth 3 entry))
505 (goto-char (point-min))
506 (when (looking-at " *\\*\\(.*\\)$")
507 (setq subject (match-string 1))
508 (when (string-match "[ \t]+$" subject)
509 (setq subject (substring subject 0 (match-beginning 0)))))
511 (let ((case-fold-search nil))
513 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
514 (setq from (match-string 1)))))
515 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
516 "\nSubject: " (or subject "(no subject)") "\n")))
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 (deffoo nndoc-request-accept-article (group &optional server last)
594 ;;; Functions for dissecting the documents
597 (defun nndoc-search (regexp)
599 (re-search-forward regexp nil t)
600 (beginning-of-line)))
602 (defun nndoc-dissect-buffer ()
603 "Go through the document and partition it into heads/bodies/articles."
606 head-begin head-end body-begin body-end)
607 (setq nndoc-dissection-alist nil)
609 (set-buffer nndoc-current-buffer)
610 (goto-char (point-min))
611 ;; Find the beginning of the file.
612 (when nndoc-file-begin
613 (nndoc-search nndoc-file-begin))
614 ;; Go through the file.
615 (while (if (and first nndoc-first-article)
616 (nndoc-search nndoc-first-article)
617 (nndoc-article-begin))
619 (cond (nndoc-head-begin-function
620 (funcall nndoc-head-begin-function))
622 (nndoc-search nndoc-head-begin)))
625 (looking-at nndoc-file-end)))
626 (goto-char (point-max))
627 (setq head-begin (point))
628 (nndoc-search (or nndoc-head-end "^$"))
629 (setq head-end (point))
630 (if nndoc-body-begin-function
631 (funcall nndoc-body-begin-function)
632 (nndoc-search (or nndoc-body-begin "^\n")))
633 (setq body-begin (point))
634 (or (and nndoc-body-end-function
635 (funcall nndoc-body-end-function))
637 (nndoc-search nndoc-body-end))
638 (nndoc-article-begin)
640 (goto-char (point-max))
642 (and (re-search-backward nndoc-file-end nil t)
643 (beginning-of-line)))))
644 (setq body-end (point))
645 (push (list (incf i) head-begin head-end body-begin body-end
646 (count-lines body-begin body-end))
647 nndoc-dissection-alist))))))
649 (defun nndoc-article-begin ()
650 (if nndoc-article-begin-function
651 (funcall nndoc-article-begin-function)
653 (nndoc-search nndoc-article-begin))))
655 (defun nndoc-unquote-dashes ()
656 "Unquote quoted non-separators in digests."
657 (while (re-search-forward "^- -"nil t)
658 (replace-match "-" t t)))
660 ;; Against compiler warnings.
661 (defvar nndoc-mime-split-ordinal)
663 (defun nndoc-dissect-mime-parts ()
664 "Go through a MIME composite article and partition it into sub-articles.
665 When a MIME entity contains sub-entities, dissection produces one article for
666 the header of this entity, and one article per sub-entity."
667 (setq nndoc-dissection-alist nil
668 nndoc-mime-split-ordinal 0)
670 (set-buffer nndoc-current-buffer)
671 (message-narrow-to-head)
672 (let ((case-fold-search t)
673 (message-id (message-fetch-field "Message-ID"))
674 (references (message-fetch-field "References")))
675 (setq nndoc-mime-header (buffer-substring (point-min) (point-max))
676 nndoc-mime-subject (message-fetch-field "Subject"))
677 (while (string-match "\
678 ^\\(Subject\\|Message-ID\\|References\\|Lines\\|\
679 MIME-Version\\|Content-Type\\|Content-Transfer-Encoding\\|\
680 \\):.*\n\\([ \t].*\n\\)*"
682 (setq nndoc-mime-header (replace-match "" t t nndoc-mime-header)))
684 (nndoc-dissect-mime-parts-sub (point-min) (point-max)
685 nil message-id references))))
687 (defun nndoc-dissect-mime-parts-sub (begin end position message-id references)
688 "Dissect an entity within a composite MIME message.
689 The article, which corresponds to a MIME entity, extends from BEGIN to END.
690 The string POSITION holds a dotted decimal representation of the article
691 position in the hierarchical structure, it is nil for the outer entity.
692 The generated article should use MESSAGE-ID and REFERENCES field values."
693 ;; Note: `case-fold-search' is already `t' from the calling function.
694 (let ((head-begin begin)
696 head-end body-begin type subtype composite comment)
698 ;; Gracefully handle a missing body.
699 (goto-char head-begin)
700 (if (search-forward "\n\n" body-end t)
701 (setq head-end (1- (point))
705 ;; Save MIME attributes.
706 (goto-char head-begin)
707 (if (re-search-forward "\
708 ^Content-Type: *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)"
710 (setq type (downcase (match-string 1))
711 subtype (downcase (match-string 2)))
714 (setq composite (string= type "multipart")
715 comment (concat position
716 (when (and position composite) ".")
718 (when (or position composite) " ")
719 (cond ((string= subtype "plain") type)
720 ((string= subtype "basic") type)
722 ;; Generate dissection information for this entity.
723 (push (list (incf nndoc-mime-split-ordinal)
724 head-begin head-end body-begin body-end
725 (count-lines body-begin body-end)
726 comment message-id references)
727 nndoc-dissection-alist)
728 ;; Recurse for all sub-entities, if any.
729 (goto-char head-begin)
730 (when (re-search-forward
732 ^Content-Type: *multipart/\\([a-z]+\\);\\(.*;\\)*"
733 "[ \t\n]*[ \t]boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
735 (let ((boundary (concat "\n--" (match-string 3) "\\(--\\)?[ \t]*\n"))
739 (setq eof-flag (not (re-search-forward boundary body-end t)))
740 (while (not eof-flag)
742 (cond ((re-search-forward boundary body-end t)
743 (or (not (match-string 1))
744 (string= (match-string 1) "")
749 (t (setq end body-end
751 (nndoc-dissect-mime-parts-sub begin end
752 (concat position (when position ".")
754 (incf part-counter)))
759 (defun nndoc-add-type (definition &optional position)
760 "Add document DEFINITION to the list of nndoc document definitions.
761 If POSITION is nil or `last', the definition will be added
762 as the last checked definition, if t or `first', add as the
763 first definition, and if any other symbol, add after that
764 symbol in the alist."
765 ;; First remove any old instances.
766 (gnus-pull (car definition) nndoc-type-alist)
767 ;; Then enter the new definition in the proper place.
769 ((or (null position) (eq position 'last))
770 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
771 ((or (eq position t) (eq position 'first))
772 (push definition nndoc-type-alist))
774 (let ((list (memq (assq position nndoc-type-alist)
777 (error "No such position: %s" position))
778 (setcdr list (cons definition (cdr list)))))))
782 ;;; nndoc.el ends here