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 full-subject)
477 (let ((entry (cdr (assq article nndoc-dissection-alist))))
478 (let ((subject (concat "<" (nth 5 entry) ">"))
479 (message-id (nth 6 entry))
480 (references (nth 7 entry)))
481 (insert nndoc-mime-header
483 (cond ((not full-subject) subject)
484 (nndoc-mime-subject (concat nndoc-mime-subject " " subject))
487 (and message-id (insert "Message-ID: " message-id "\n"))
488 (and references (insert "References: " references "\n")))))
490 (defun nndoc-clari-briefs-type-p ()
491 (when (let ((case-fold-search nil))
492 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
495 (defun nndoc-transform-clari-briefs (article)
496 (goto-char (point-min))
497 (when (looking-at " *\\*\\(.*\\)\n")
498 (replace-match "" t t))
499 (nndoc-generate-clari-briefs-head article))
501 (defun nndoc-generate-clari-briefs-head (article)
502 (let ((entry (cdr (assq article nndoc-dissection-alist)))
505 (set-buffer nndoc-current-buffer)
507 (narrow-to-region (car entry) (nth 3 entry))
508 (goto-char (point-min))
509 (when (looking-at " *\\*\\(.*\\)$")
510 (setq subject (match-string 1))
511 (when (string-match "[ \t]+$" subject)
512 (setq subject (substring subject 0 (match-beginning 0)))))
514 (let ((case-fold-search nil))
516 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
517 (setq from (match-string 1)))))
518 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
519 "\nSubject: " (or subject "(no subject)") "\n")))
521 (defun nndoc-mime-digest-type-p ()
522 (let ((case-fold-search t)
523 boundary-id b-delimiter entry)
526 (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
527 "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
530 (setq boundary-id (match-string 1)
531 b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
532 (setq entry (assq 'mime-digest nndoc-type-alist))
535 (cons 'head-end "^ ?$")
536 (cons 'body-begin "^ ?\n")
537 (cons 'article-begin b-delimiter)
538 (cons 'body-end-function 'nndoc-digest-body-end)
539 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$"))))
542 (defun nndoc-standard-digest-type-p ()
543 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
545 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
548 (defun nndoc-digest-body-end ()
549 (and (re-search-forward nndoc-article-begin nil t)
550 (goto-char (match-beginning 0))))
552 (defun nndoc-slack-digest-type-p ()
555 (defun nndoc-lanl-gov-announce-type-p ()
556 (when (let ((case-fold-search nil))
557 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
560 (defun nndoc-transform-lanl-gov-announce (article)
561 (goto-char (point-max))
562 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
563 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
564 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
565 ;; (replace-match "" t t))
568 (defun nndoc-generate-lanl-gov-head (article)
569 (let ((entry (cdr (assq article nndoc-dissection-alist)))
570 (e-mail "no address given")
573 (set-buffer nndoc-current-buffer)
575 (narrow-to-region (car entry) (nth 1 entry))
576 (goto-char (point-min))
577 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
578 (setq subject (concat " (" (match-string 1) ")"))
579 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
580 (setq e-mail (match-string 1)))
581 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
583 (setq subject (concat (match-string 1) subject))
584 (setq from (concat (match-string 2) " <" e-mail ">"))))
586 (while (and from (string-match "(\[^)\]*)" from))
587 (setq from (replace-match "" t t from)))
588 (insert "From: " (or from "unknown")
589 "\nSubject: " (or subject "(no subject)") "\n")))
591 (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 ;; Find the beginning of the file.
615 (when nndoc-file-begin
616 (nndoc-search nndoc-file-begin))
617 ;; Go through the file.
618 (while (if (and first nndoc-first-article)
619 (nndoc-search nndoc-first-article)
620 (nndoc-article-begin))
622 (cond (nndoc-head-begin-function
623 (funcall nndoc-head-begin-function))
625 (nndoc-search nndoc-head-begin)))
628 (looking-at nndoc-file-end)))
629 (goto-char (point-max))
630 (setq head-begin (point))
631 (nndoc-search (or nndoc-head-end "^$"))
632 (setq head-end (point))
633 (if nndoc-body-begin-function
634 (funcall nndoc-body-begin-function)
635 (nndoc-search (or nndoc-body-begin "^\n")))
636 (setq body-begin (point))
637 (or (and nndoc-body-end-function
638 (funcall nndoc-body-end-function))
640 (nndoc-search nndoc-body-end))
641 (nndoc-article-begin)
643 (goto-char (point-max))
645 (and (re-search-backward nndoc-file-end nil t)
646 (beginning-of-line)))))
647 (setq body-end (point))
648 (push (list (incf i) head-begin head-end body-begin body-end
649 (count-lines body-begin body-end))
650 nndoc-dissection-alist))))))
652 (defun nndoc-article-begin ()
653 (if nndoc-article-begin-function
654 (funcall nndoc-article-begin-function)
656 (nndoc-search nndoc-article-begin))))
658 (defun nndoc-unquote-dashes ()
659 "Unquote quoted non-separators in digests."
660 (while (re-search-forward "^- -"nil t)
661 (replace-match "-" t t)))
663 ;; Against compiler warnings.
664 (defvar nndoc-mime-split-ordinal)
666 (defun nndoc-dissect-mime-parts ()
667 "Go through a MIME composite article and partition it into sub-articles.
668 When a MIME entity contains sub-entities, dissection produces one article for
669 the header of this entity, and one article per sub-entity."
670 (setq nndoc-dissection-alist nil
671 nndoc-mime-split-ordinal 0)
673 (set-buffer nndoc-current-buffer)
674 (message-narrow-to-head)
675 (let ((case-fold-search t)
676 (message-id (message-fetch-field "Message-ID"))
677 (references (message-fetch-field "References")))
678 (setq nndoc-mime-header (buffer-substring (point-min) (point-max))
679 nndoc-mime-subject (message-fetch-field "Subject"))
680 (while (string-match "\
681 ^\\(Subject\\|Message-ID\\|References\\|Lines\\|\
682 MIME-Version\\|Content-Type\\|Content-Transfer-Encoding\\|\
683 \\):.*\n\\([ \t].*\n\\)*"
685 (setq nndoc-mime-header (replace-match "" t t nndoc-mime-header)))
687 (nndoc-dissect-mime-parts-sub (point-min) (point-max)
688 nil message-id references))))
690 (defun nndoc-dissect-mime-parts-sub (begin end position message-id references)
691 "Dissect an entity within a composite MIME message.
692 The article, which corresponds to a MIME entity, extends from BEGIN to END.
693 The string POSITION holds a dotted decimal representation of the article
694 position in the hierarchical structure, it is nil for the outer entity.
695 The generated article should use MESSAGE-ID and REFERENCES field values."
696 ;; Note: `case-fold-search' is already `t' from the calling function.
697 (let ((head-begin begin)
699 head-end body-begin type subtype composite comment)
701 ;; Gracefully handle a missing body.
702 (goto-char head-begin)
703 (if (search-forward "\n\n" body-end t)
704 (setq head-end (1- (point))
708 ;; Save MIME attributes.
709 (goto-char head-begin)
710 (if (re-search-forward "\
711 ^Content-Type: *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)"
713 (setq type (downcase (match-string 1))
714 subtype (downcase (match-string 2)))
717 (setq composite (string= type "multipart")
718 comment (concat position
719 (when (and position composite) ".")
721 (when (or position composite) " ")
722 (cond ((string= subtype "plain") type)
723 ((string= subtype "basic") type)
725 ;; Generate dissection information for this entity.
726 (push (list (incf nndoc-mime-split-ordinal)
727 head-begin head-end body-begin body-end
728 (count-lines body-begin body-end)
729 comment message-id references)
730 nndoc-dissection-alist)
731 ;; Recurse for all sub-entities, if any.
732 (goto-char head-begin)
733 (when (re-search-forward
735 ^Content-Type: *multipart/\\([a-z]+\\);\\(.*;\\)*"
736 "[ \t\n]*[ \t]boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
738 (let ((boundary (concat "\n--" (match-string 3) "\\(--\\)?[ \t]*\n"))
742 (setq eof-flag (not (re-search-forward boundary body-end t)))
743 (while (not eof-flag)
745 (cond ((re-search-forward boundary body-end t)
746 (or (not (match-string 1))
747 (string= (match-string 1) "")
752 (t (setq end body-end
754 (nndoc-dissect-mime-parts-sub begin end
755 (concat position (when position ".")
757 (incf part-counter)))
762 (defun nndoc-add-type (definition &optional position)
763 "Add document DEFINITION to the list of nndoc document definitions.
764 If POSITION is nil or `last', the definition will be added
765 as the last checked definition, if t or `first', add as the
766 first definition, and if any other symbol, add after that
767 symbol in the alist."
768 ;; First remove any old instances.
769 (gnus-pull (car definition) nndoc-type-alist)
770 ;; Then enter the new definition in the proper place.
772 ((or (null position) (eq position 'last))
773 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
774 ((or (eq position t) (eq position 'first))
775 (push definition nndoc-type-alist))
777 (let ((list (memq (assq position nndoc-type-alist)
780 (error "No such position: %s" position))
781 (setcdr list (cons definition (cdr list)))))))
785 ;;; nndoc.el ends here