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)
292 (buffer-disable-undo (current-buffer))
294 (if (stringp nndoc-address)
295 (nnheader-insert-file-contents nndoc-address)
296 (insert-buffer-substring nndoc-address))
297 (run-hooks 'nndoc-open-document-hook))))
298 ;; Initialize the nndoc structures according to this new document.
299 (when (and nndoc-current-buffer
300 (not nndoc-dissection-alist))
302 (set-buffer nndoc-current-buffer)
304 (if (eq nndoc-article-type 'mime-parts)
305 (nndoc-dissect-mime-parts)
306 (nndoc-dissect-buffer))))
307 (unless nndoc-current-buffer
308 (nndoc-close-server))
309 ;; Return whether we managed to select a file.
310 nndoc-current-buffer))
313 ;;; Deciding what document type we have
316 (defun nndoc-set-delims ()
317 "Set the nndoc delimiter variables according to the type of the document."
318 (let ((vars '(nndoc-file-begin
320 nndoc-article-begin-function
321 nndoc-head-begin nndoc-head-end
322 nndoc-file-end nndoc-article-begin
323 nndoc-body-begin nndoc-body-end-function nndoc-body-end
324 nndoc-prepare-body-function nndoc-article-transform-function
325 nndoc-generate-head-function nndoc-body-begin-function
326 nndoc-head-begin-function)))
328 (set (pop vars) nil)))
330 ;; Guess away until we find the real file type.
331 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
333 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
334 ;; Set the nndoc variables.
336 (set (intern (format "nndoc-%s" (caar defs)))
339 (defun nndoc-guess-type (subtype)
340 (let ((alist nndoc-type-alist)
341 results result entry)
342 (while (and (not result)
343 (setq entry (pop alist)))
344 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
345 (goto-char (point-min))
346 (when (numberp (setq result (funcall (intern
347 (format "nndoc-%s-type-p"
349 (push (cons result entry) results)
351 (unless (or result results)
352 (error "Document is not of any recognized type"))
355 (cadar (sort results 'car-less-than-car)))))
358 ;;; Built-in type predicates and functions
361 (defun nndoc-mbox-type-p ()
362 (when (looking-at message-unix-mail-delimiter)
365 (defun nndoc-mbox-article-begin ()
366 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
367 (goto-char (match-beginning 0))))
369 (defun nndoc-mbox-body-end ()
374 (and (re-search-backward
375 (concat "^" message-unix-mail-delimiter) nil t)
377 (search-forward "\n\n" beg t)
379 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
380 (setq len (string-to-int (match-string 1)))
381 (search-forward "\n\n" beg t)
382 (unless (= (setq len (+ (point) len)) (point-max))
383 (and (< len (point-max))
385 (looking-at message-unix-mail-delimiter)))))
388 (defun nndoc-mmdf-type-p ()
389 (when (looking-at "\^A\^A\^A\^A$")
392 (defun nndoc-news-type-p ()
393 (when (looking-at "^Path:.*\n")
396 (defun nndoc-rnews-type-p ()
397 (when (looking-at "#! *rnews")
400 (defun nndoc-rnews-body-end ()
401 (and (re-search-backward nndoc-article-begin nil t)
403 (goto-char (+ (point) (string-to-int (match-string 1))))))
405 (defun nndoc-babyl-type-p ()
406 (when (re-search-forward "\^_\^L *\n" nil t)
409 (defun nndoc-babyl-body-begin ()
410 (re-search-forward "^\n" nil t)
411 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
412 (let ((next (or (save-excursion
413 (re-search-forward nndoc-article-begin nil t))
415 (unless (re-search-forward "^\n" next t)
419 (forward-line -1)))))
421 (defun nndoc-babyl-head-begin ()
422 (when (re-search-forward "^[0-9].*\n" nil t)
423 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
427 (defun nndoc-forward-type-p ()
428 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
429 (not (re-search-forward "^Subject:.*digest" nil t))
430 (not (re-search-backward "^From:" nil t 2))
431 (not (re-search-forward "^From:" nil t 2)))
434 (defun nndoc-rfc934-type-p ()
435 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
436 (not (re-search-forward "^Subject:.*digest" nil t))
437 (not (re-search-backward "^From:" nil t 2))
438 (not (re-search-forward "^From:" nil t 2)))
441 (defun nndoc-rfc822-forward-type-p ()
443 (message-narrow-to-head)
444 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
447 (defun nndoc-rfc822-forward-body-end-function ()
448 (goto-char (point-max)))
450 (defun nndoc-mime-parts-type-p ()
451 (let ((case-fold-search t)
452 (limit (search-forward "\n\n" nil t)))
453 (goto-char (point-min))
457 ^Content-Type:[ \t]*multipart/[a-z]+;\\(.*;\\)*"
458 "[ \t\n]*[ \t]boundary=\"?[^\"\n]*[^\" \t\n]")
462 (defun nndoc-transform-mime-parts (article)
463 (unless (= article 1)
464 ;; Ensure some MIME-Version.
465 (goto-char (point-min))
466 (search-forward "\n\n")
467 (let ((case-fold-search nil)
469 (goto-char (point-min))
470 (or (save-excursion (re-search-forward "^MIME-Version:" limit t))
471 (insert "Mime-Version: 1.0\n")))
472 ;; Generate default header before entity fields.
473 (goto-char (point-min))
474 (nndoc-generate-mime-parts-head article t)))
476 (defun nndoc-generate-mime-parts-head (article &optional body-present)
477 (let ((entry (cdr (assq (if body-present 1 article) nndoc-dissection-alist))))
478 (let ((subject (if body-present
480 (concat "<" (nth 5 entry) ">")))
481 (message-id (nth 6 entry))
482 (references (nth 7 entry)))
483 (insert nndoc-mime-header)
484 (and subject (insert "Subject: " subject "\n"))
485 (and message-id (insert "Message-ID: " message-id "\n"))
486 (and references (insert "References: " references "\n")))))
488 (defun nndoc-clari-briefs-type-p ()
489 (when (let ((case-fold-search nil))
490 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
493 (defun nndoc-transform-clari-briefs (article)
494 (goto-char (point-min))
495 (when (looking-at " *\\*\\(.*\\)\n")
496 (replace-match "" t t))
497 (nndoc-generate-clari-briefs-head article))
499 (defun nndoc-generate-clari-briefs-head (article)
500 (let ((entry (cdr (assq article nndoc-dissection-alist)))
503 (set-buffer nndoc-current-buffer)
505 (narrow-to-region (car entry) (nth 3 entry))
506 (goto-char (point-min))
507 (when (looking-at " *\\*\\(.*\\)$")
508 (setq subject (match-string 1))
509 (when (string-match "[ \t]+$" subject)
510 (setq subject (substring subject 0 (match-beginning 0)))))
512 (let ((case-fold-search nil))
514 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
515 (setq from (match-string 1)))))
516 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
517 "\nSubject: " (or subject "(no subject)") "\n")))
519 (defun nndoc-mime-digest-type-p ()
520 (let ((case-fold-search t)
521 boundary-id b-delimiter entry)
524 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
525 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
528 (setq boundary-id (match-string 1)
529 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
530 (setq entry (assq 'mime-digest nndoc-type-alist))
533 (cons 'head-end "^ ?$")
534 (cons 'body-begin "^ ?\n")
535 (cons 'article-begin b-delimiter)
536 (cons 'body-end-function 'nndoc-digest-body-end)
537 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
540 (defun nndoc-standard-digest-type-p ()
541 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
543 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
546 (defun nndoc-digest-body-end ()
547 (and (re-search-forward nndoc-article-begin nil t)
548 (goto-char (match-beginning 0))))
550 (defun nndoc-slack-digest-type-p ()
553 (defun nndoc-lanl-gov-announce-type-p ()
554 (when (let ((case-fold-search nil))
555 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
558 (defun nndoc-transform-lanl-gov-announce (article)
559 (goto-char (point-max))
560 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
561 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
562 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
563 ;; (replace-match "" t t))
566 (defun nndoc-generate-lanl-gov-head (article)
567 (let ((entry (cdr (assq article nndoc-dissection-alist)))
568 (e-mail "no address given")
571 (set-buffer nndoc-current-buffer)
573 (narrow-to-region (car entry) (nth 1 entry))
574 (goto-char (point-min))
575 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
576 (setq subject (concat " (" (match-string 1) ")"))
577 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
578 (setq e-mail (match-string 1)))
579 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
581 (setq subject (concat (match-string 1) subject))
582 (setq from (concat (match-string 2) " <" e-mail ">"))))
584 (while (and from (string-match "(\[^)\]*)" from))
585 (setq from (replace-match "" t t from)))
586 (insert "From: " (or from "unknown")
587 "\nSubject: " (or subject "(no subject)") "\n")))
589 (deffoo nndoc-request-accept-article (group &optional server last)
595 ;;; Functions for dissecting the documents
598 (defun nndoc-search (regexp)
600 (re-search-forward regexp nil t)
601 (beginning-of-line)))
603 (defun nndoc-dissect-buffer ()
604 "Go through the document and partition it into heads/bodies/articles."
607 head-begin head-end body-begin body-end)
608 (setq nndoc-dissection-alist nil)
610 (set-buffer nndoc-current-buffer)
611 (goto-char (point-min))
612 ;; Find the beginning of the file.
613 (when nndoc-file-begin
614 (nndoc-search nndoc-file-begin))
615 ;; Go through the file.
616 (while (if (and first nndoc-first-article)
617 (nndoc-search nndoc-first-article)
618 (nndoc-article-begin))
620 (cond (nndoc-head-begin-function
621 (funcall nndoc-head-begin-function))
623 (nndoc-search nndoc-head-begin)))
626 (looking-at nndoc-file-end)))
627 (goto-char (point-max))
628 (setq head-begin (point))
629 (nndoc-search (or nndoc-head-end "^$"))
630 (setq head-end (point))
631 (if nndoc-body-begin-function
632 (funcall nndoc-body-begin-function)
633 (nndoc-search (or nndoc-body-begin "^\n")))
634 (setq body-begin (point))
635 (or (and nndoc-body-end-function
636 (funcall nndoc-body-end-function))
638 (nndoc-search nndoc-body-end))
639 (nndoc-article-begin)
641 (goto-char (point-max))
643 (and (re-search-backward nndoc-file-end nil t)
644 (beginning-of-line)))))
645 (setq body-end (point))
646 (push (list (incf i) head-begin head-end body-begin body-end
647 (count-lines body-begin body-end))
648 nndoc-dissection-alist))))))
650 (defun nndoc-article-begin ()
651 (if nndoc-article-begin-function
652 (funcall nndoc-article-begin-function)
654 (nndoc-search nndoc-article-begin))))
656 (defun nndoc-unquote-dashes ()
657 "Unquote quoted non-separators in digests."
658 (while (re-search-forward "^- -"nil t)
659 (replace-match "-" t t)))
661 ;; Against compiler warnings.
662 (defvar nndoc-mime-split-ordinal)
664 (defun nndoc-dissect-mime-parts ()
665 "Go through a MIME composite article and partition it into sub-articles.
666 When a MIME entity contains sub-entities, dissection produces one article for
667 the header of this entity, and one article per sub-entity."
668 (setq nndoc-dissection-alist nil
669 nndoc-mime-split-ordinal 0)
671 (set-buffer nndoc-current-buffer)
672 (message-narrow-to-head)
673 (let ((case-fold-search t)
674 (message-id (message-fetch-field "Message-ID"))
675 (references (message-fetch-field "References")))
676 (setq nndoc-mime-header (buffer-substring (point-min) (point-max))
677 nndoc-mime-subject (message-fetch-field "Subject"))
678 (while (string-match "\
679 ^\\(Subject\\|Message-ID\\|References\\|Lines\\|\
680 MIME-Version\\|Content-Type\\|Content-Transfer-Encoding\\|\
681 \\):.*\n\\([ \t].*\n\\)*"
683 (setq nndoc-mime-header (replace-match "" t t nndoc-mime-header)))
685 (nndoc-dissect-mime-parts-sub (point-min) (point-max)
686 nil message-id references))))
688 (defun nndoc-dissect-mime-parts-sub (begin end position message-id references)
689 "Dissect an entity within a composite MIME message.
690 The article, which corresponds to a MIME entity, extends from BEGIN to END.
691 The string POSITION holds a dotted decimal representation of the article
692 position in the hierarchical structure, it is nil for the outer entity.
693 The generated article should use MESSAGE-ID and REFERENCES field values."
694 ;; Note: `case-fold-search' is already `t' from the calling function.
695 (let ((head-begin begin)
697 head-end body-begin type subtype composite comment)
699 ;; Gracefully handle a missing body.
700 (goto-char head-begin)
701 (if (search-forward "\n\n" body-end t)
702 (setq head-end (1- (point))
706 ;; Save MIME attributes.
707 (goto-char head-begin)
708 (if (re-search-forward "\
709 ^Content-Type: *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)"
711 (setq type (downcase (match-string 1))
712 subtype (downcase (match-string 2)))
715 (setq composite (string= type "multipart")
716 comment (concat position
717 (when (and position composite) ".")
719 (when (or position composite) " ")
720 (cond ((string= subtype "plain") type)
721 ((string= subtype "basic") type)
723 ;; Generate dissection information for this entity.
724 (push (list (incf nndoc-mime-split-ordinal)
725 head-begin head-end body-begin body-end
726 (count-lines body-begin body-end)
727 comment message-id references)
728 nndoc-dissection-alist)
729 ;; Recurse for all sub-entities, if any.
730 (goto-char head-begin)
731 (when (re-search-forward
733 ^Content-Type: *multipart/\\([a-z]+\\);\\(.*;\\)*"
734 "[ \t\n]*[ \t]boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
736 (let ((boundary (concat "\n--" (match-string 3) "\\(--\\)?[ \t]*\n"))
740 (setq eof-flag (not (re-search-forward boundary body-end t)))
741 (while (not eof-flag)
743 (cond ((re-search-forward boundary body-end t)
744 (or (not (match-string 1))
745 (string= (match-string 1) "")
750 (t (setq end body-end
752 (nndoc-dissect-mime-parts-sub begin end
753 (concat position (when position ".")
755 (incf part-counter)))
760 (defun nndoc-add-type (definition &optional position)
761 "Add document DEFINITION to the list of nndoc document definitions.
762 If POSITION is nil or `last', the definition will be added
763 as the last checked definition, if t or `first', add as the
764 first definition, and if any other symbol, add after that
765 symbol in the alist."
766 ;; First remove any old instances.
767 (gnus-pull (car definition) nndoc-type-alist)
768 ;; Then enter the new definition in the proper place.
770 ((or (null position) (eq position 'last))
771 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
772 ((or (eq position t) (eq position 'first))
773 (push definition nndoc-type-alist))
775 (let ((list (memq (assq position nndoc-type-alist)
778 (error "No such position: %s" position))
779 (setcdr list (cons definition (cdr list)))))))
783 ;;; nndoc.el ends here