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.
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-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))
85 (generate-head-function . nndoc-generate-mime-parts-head)
86 (article-transform-function . nndoc-transform-mime-parts))
88 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
89 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
90 (prepare-body-function . nndoc-unquote-dashes)
91 (body-end-function . nndoc-digest-body-end)
93 (body-begin . "^ *\n")
94 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
95 (subtype digest guess))
97 (article-begin . "^------------------------------*[\n \t]+")
99 (body-end-function . nndoc-digest-body-end)
100 (body-begin . "^ ?$")
101 (file-end . "^End of")
102 (prepare-body-function . nndoc-unquote-dashes)
103 (subtype digest guess))
105 (article-begin . "^\\\\\\\\\n")
106 (head-begin . "^Paper.*:")
107 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
109 (body-end . "-------------------------------------------------")
110 (file-end . "^Title: Recent Seminal")
111 (generate-head-function . nndoc-generate-lanl-gov-head)
112 (article-transform-function . nndoc-transform-lanl-gov-announce)
113 (subtype preprints guess))
115 (article-begin . "^\n")
116 (body-end-function . nndoc-rfc822-forward-body-end-function))
128 (defvoo nndoc-file-begin nil)
129 (defvoo nndoc-first-article nil)
130 (defvoo nndoc-article-begin nil)
131 (defvoo nndoc-head-begin nil)
132 (defvoo nndoc-head-end nil)
133 (defvoo nndoc-file-end nil)
134 (defvoo nndoc-body-begin nil)
135 (defvoo nndoc-body-end-function nil)
136 (defvoo nndoc-body-begin-function nil)
137 (defvoo nndoc-head-begin-function nil)
138 (defvoo nndoc-body-end nil)
139 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
140 ;; following items. ARTICLE act as the association key and is an ordinal
141 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
142 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
143 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
144 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
145 ;; generation, respectively. Other headers usually follow directly from the
146 ;; buffer. Value `nil' means no insert.
147 (defvoo nndoc-dissection-alist nil)
148 (defvoo nndoc-prepare-body-function nil)
149 (defvoo nndoc-generate-head-function nil)
150 (defvoo nndoc-article-transform-function nil)
151 (defvoo nndoc-article-begin-function nil)
153 (defvoo nndoc-status-string "")
154 (defvoo nndoc-group-alist nil)
155 (defvoo nndoc-current-buffer nil
156 "Current nndoc news buffer.")
157 (defvoo nndoc-address nil)
159 (defconst nndoc-version "nndoc 1.0"
164 ;;; Interface functions
166 (nnoo-define-basics nndoc)
168 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
169 (when (nndoc-possibly-change-buffer newsgroup server)
171 (set-buffer nntp-server-buffer)
174 (if (stringp (car articles))
177 (when (setq entry (cdr (assq (setq article (pop articles))
178 nndoc-dissection-alist)))
179 (insert (format "221 %d Article retrieved.\n" article))
180 (if nndoc-generate-head-function
181 (funcall nndoc-generate-head-function article)
182 (insert-buffer-substring
183 nndoc-current-buffer (car entry) (nth 1 entry)))
184 (goto-char (point-max))
185 (unless (eq (char-after (1- (point))) ?\n)
187 (insert (format "Lines: %d\n" (nth 4 entry)))
190 (nnheader-fold-continuation-lines)
193 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
194 (nndoc-possibly-change-buffer newsgroup server)
196 (let ((buffer (or buffer nntp-server-buffer))
197 (entry (cdr (assq article nndoc-dissection-alist)))
202 (if (stringp article)
204 (insert-buffer-substring
205 nndoc-current-buffer (car entry) (nth 1 entry))
208 (insert-buffer-substring
209 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
211 (when nndoc-prepare-body-function
212 (funcall nndoc-prepare-body-function))
213 (when nndoc-article-transform-function
214 (funcall nndoc-article-transform-function article))
217 (deffoo nndoc-request-group (group &optional server dont-check)
221 ((not (nndoc-possibly-change-buffer group server))
222 (nnheader-report 'nndoc "No such file or buffer: %s"
225 (nnheader-report 'nndoc "Selected group %s" group)
227 ((zerop (setq number (length nndoc-dissection-alist)))
228 (nndoc-close-group group)
229 (nnheader-report 'nndoc "No articles in group %s" group))
231 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
233 (deffoo nndoc-request-type (group &optional article)
234 (cond ((not article) 'unknown)
235 (nndoc-post-type nndoc-post-type)
238 (deffoo nndoc-close-group (group &optional server)
239 (nndoc-possibly-change-buffer group server)
240 (and nndoc-current-buffer
241 (buffer-name nndoc-current-buffer)
242 (kill-buffer nndoc-current-buffer))
243 (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
245 (setq nndoc-current-buffer nil)
246 (nnoo-close-server 'nndoc server)
247 (setq nndoc-dissection-alist nil)
250 (deffoo nndoc-request-list (&optional server)
253 (deffoo nndoc-request-newgroups (date &optional server)
256 (deffoo nndoc-request-list-newsgroups (&optional server)
260 ;;; Internal functions.
262 (defun nndoc-possibly-change-buffer (group source)
265 ;; The current buffer is this group's buffer.
266 ((and nndoc-current-buffer
267 (buffer-name nndoc-current-buffer)
268 (eq nndoc-current-buffer
269 (setq buf (cdr (assoc group nndoc-group-alist))))))
270 ;; We change buffers by taking an old from the group alist.
271 ;; `source' is either a string (a file name) or a buffer object.
273 (setq nndoc-current-buffer buf))
274 ;; It's a totally new group.
275 ((or (and (bufferp nndoc-address)
276 (buffer-name nndoc-address))
277 (and (stringp nndoc-address)
278 (file-exists-p nndoc-address)
279 (not (file-directory-p nndoc-address))))
280 (push (cons group (setq nndoc-current-buffer
282 (concat " *nndoc " group "*"))))
284 (setq nndoc-dissection-alist nil)
286 (set-buffer nndoc-current-buffer)
287 (mm-enable-multibyte)
289 (if (stringp nndoc-address)
290 (nnheader-insert-file-contents nndoc-address)
291 (insert-buffer-substring nndoc-address))
292 (run-hooks 'nndoc-open-document-hook))))
293 ;; Initialize the nndoc structures according to this new document.
294 (when (and nndoc-current-buffer
295 (not nndoc-dissection-alist))
297 (set-buffer nndoc-current-buffer)
299 (if (eq nndoc-article-type 'mime-parts)
300 (nndoc-dissect-mime-parts)
301 (nndoc-dissect-buffer))))
302 (unless nndoc-current-buffer
303 (nndoc-close-server))
304 ;; Return whether we managed to select a file.
305 nndoc-current-buffer))
308 ;;; Deciding what document type we have
311 (defun nndoc-set-delims ()
312 "Set the nndoc delimiter variables according to the type of the document."
313 (let ((vars '(nndoc-file-begin
315 nndoc-article-begin-function
316 nndoc-head-begin nndoc-head-end
317 nndoc-file-end nndoc-article-begin
318 nndoc-body-begin nndoc-body-end-function nndoc-body-end
319 nndoc-prepare-body-function nndoc-article-transform-function
320 nndoc-generate-head-function nndoc-body-begin-function
321 nndoc-head-begin-function)))
323 (set (pop vars) nil)))
325 ;; Guess away until we find the real file type.
326 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
328 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
329 ;; Set the nndoc variables.
331 (set (intern (format "nndoc-%s" (caar defs)))
334 (defun nndoc-guess-type (subtype)
335 (let ((alist nndoc-type-alist)
336 results result entry)
337 (while (and (not result)
338 (setq entry (pop alist)))
339 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
340 (goto-char (point-min))
341 (when (numberp (setq result (funcall (intern
342 (format "nndoc-%s-type-p"
344 (push (cons result entry) results)
346 (unless (or result results)
347 (error "Document is not of any recognized type"))
350 (cadar (sort results 'car-less-than-car)))))
353 ;;; Built-in type predicates and functions
356 (defun nndoc-mbox-type-p ()
357 (when (looking-at message-unix-mail-delimiter)
360 (defun nndoc-mbox-article-begin ()
361 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
362 (goto-char (match-beginning 0))))
364 (defun nndoc-mbox-body-end ()
369 (and (re-search-backward
370 (concat "^" message-unix-mail-delimiter) nil t)
372 (search-forward "\n\n" beg t)
374 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
375 (setq len (string-to-int (match-string 1)))
376 (search-forward "\n\n" beg t)
377 (unless (= (setq len (+ (point) len)) (point-max))
378 (and (< len (point-max))
380 (looking-at message-unix-mail-delimiter)))))
383 (defun nndoc-mmdf-type-p ()
384 (when (looking-at "\^A\^A\^A\^A$")
387 (defun nndoc-news-type-p ()
388 (when (looking-at "^Path:.*\n")
391 (defun nndoc-rnews-type-p ()
392 (when (looking-at "#! *rnews")
395 (defun nndoc-rnews-body-end ()
396 (and (re-search-backward nndoc-article-begin nil t)
398 (goto-char (+ (point) (string-to-int (match-string 1))))))
400 (defun nndoc-babyl-type-p ()
401 (when (re-search-forward "\^_\^L *\n" nil t)
404 (defun nndoc-babyl-body-begin ()
405 (re-search-forward "^\n" nil t)
406 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
407 (let ((next (or (save-excursion
408 (re-search-forward nndoc-article-begin nil t))
410 (unless (re-search-forward "^\n" next t)
414 (forward-line -1)))))
416 (defun nndoc-babyl-head-begin ()
417 (when (re-search-forward "^[0-9].*\n" nil t)
418 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
422 (defun nndoc-forward-type-p ()
423 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
424 (not (re-search-forward "^Subject:.*digest" nil t))
425 (not (re-search-backward "^From:" nil t 2))
426 (not (re-search-forward "^From:" nil t 2)))
429 (defun nndoc-rfc934-type-p ()
430 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
431 (not (re-search-forward "^Subject:.*digest" nil t))
432 (not (re-search-backward "^From:" nil t 2))
433 (not (re-search-forward "^From:" nil t 2)))
436 (defun nndoc-rfc822-forward-type-p ()
438 (message-narrow-to-head)
439 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
442 (defun nndoc-rfc822-forward-body-end-function ()
443 (goto-char (point-max)))
445 (defun nndoc-mime-parts-type-p ()
446 (let ((case-fold-search t)
447 (limit (search-forward "\n\n" nil t)))
448 (goto-char (point-min))
452 ^Content-Type:[ \t]*multipart/[a-z]+ *;\\(\\(\n[ \t]\\)?.*;\\)*"
453 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
457 (defun nndoc-transform-mime-parts (article)
458 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
459 (headers (nth 5 entry)))
461 (goto-char (point-min))
464 (defun nndoc-generate-mime-parts-head (article)
465 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
466 (headers (nth 6 entry)))
469 (insert-buffer-substring
470 nndoc-current-buffer (car entry) (nth 1 entry))))
472 (defun nndoc-clari-briefs-type-p ()
473 (when (let ((case-fold-search nil))
474 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
477 (defun nndoc-transform-clari-briefs (article)
478 (goto-char (point-min))
479 (when (looking-at " *\\*\\(.*\\)\n")
480 (replace-match "" t t))
481 (nndoc-generate-clari-briefs-head article))
483 (defun nndoc-generate-clari-briefs-head (article)
484 (let ((entry (cdr (assq article nndoc-dissection-alist)))
487 (set-buffer nndoc-current-buffer)
489 (narrow-to-region (car entry) (nth 3 entry))
490 (goto-char (point-min))
491 (when (looking-at " *\\*\\(.*\\)$")
492 (setq subject (match-string 1))
493 (when (string-match "[ \t]+$" subject)
494 (setq subject (substring subject 0 (match-beginning 0)))))
496 (let ((case-fold-search nil))
498 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
499 (setq from (match-string 1)))))
500 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
501 "\nSubject: " (or subject "(no subject)") "\n")))
503 (defun nndoc-standard-digest-type-p ()
504 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
506 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
509 (defun nndoc-digest-body-end ()
510 (and (re-search-forward nndoc-article-begin nil t)
511 (goto-char (match-beginning 0))))
513 (defun nndoc-slack-digest-type-p ()
516 (defun nndoc-lanl-gov-announce-type-p ()
517 (when (let ((case-fold-search nil))
518 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
521 (defun nndoc-transform-lanl-gov-announce (article)
522 (goto-char (point-max))
523 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
524 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
525 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
526 ;; (replace-match "" t t))
529 (defun nndoc-generate-lanl-gov-head (article)
530 (let ((entry (cdr (assq article nndoc-dissection-alist)))
531 (e-mail "no address given")
534 (set-buffer nndoc-current-buffer)
536 (narrow-to-region (car entry) (nth 1 entry))
537 (goto-char (point-min))
538 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
539 (setq subject (concat " (" (match-string 1) ")"))
540 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
541 (setq e-mail (match-string 1)))
542 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
544 (setq subject (concat (match-string 1) subject))
545 (setq from (concat (match-string 2) " <" e-mail ">"))))
547 (while (and from (string-match "(\[^)\]*)" from))
548 (setq from (replace-match "" t t from)))
549 (insert "From: " (or from "unknown")
550 "\nSubject: " (or subject "(no subject)") "\n")))
552 (deffoo nndoc-request-accept-article (group &optional server last)
558 ;;; Functions for dissecting the documents
561 (defun nndoc-search (regexp)
563 (re-search-forward regexp nil t)
564 (beginning-of-line)))
566 (defun nndoc-dissect-buffer ()
567 "Go through the document and partition it into heads/bodies/articles."
570 head-begin head-end body-begin body-end)
571 (setq nndoc-dissection-alist nil)
573 (set-buffer nndoc-current-buffer)
574 (goto-char (point-min))
575 ;; Find the beginning of the file.
576 (when nndoc-file-begin
577 (nndoc-search nndoc-file-begin))
578 ;; Go through the file.
579 (while (if (and first nndoc-first-article)
580 (nndoc-search nndoc-first-article)
581 (nndoc-article-begin))
583 (cond (nndoc-head-begin-function
584 (funcall nndoc-head-begin-function))
586 (nndoc-search nndoc-head-begin)))
589 (looking-at nndoc-file-end)))
590 (goto-char (point-max))
591 (setq head-begin (point))
592 (nndoc-search (or nndoc-head-end "^$"))
593 (setq head-end (point))
594 (if nndoc-body-begin-function
595 (funcall nndoc-body-begin-function)
596 (nndoc-search (or nndoc-body-begin "^\n")))
597 (setq body-begin (point))
598 (or (and nndoc-body-end-function
599 (funcall nndoc-body-end-function))
601 (nndoc-search nndoc-body-end))
602 (nndoc-article-begin)
604 (goto-char (point-max))
606 (and (re-search-backward nndoc-file-end nil t)
607 (beginning-of-line)))))
608 (setq body-end (point))
609 (push (list (incf i) head-begin head-end body-begin body-end
610 (count-lines body-begin body-end))
611 nndoc-dissection-alist))))))
613 (defun nndoc-article-begin ()
614 (if nndoc-article-begin-function
615 (funcall nndoc-article-begin-function)
617 (nndoc-search nndoc-article-begin))))
619 (defun nndoc-unquote-dashes ()
620 "Unquote quoted non-separators in digests."
621 (while (re-search-forward "^- -"nil t)
622 (replace-match "-" t t)))
624 ;; Against compiler warnings.
625 (defvar nndoc-mime-split-ordinal)
627 (defun nndoc-dissect-mime-parts ()
628 "Go through a MIME composite article and partition it into sub-articles.
629 When a MIME entity contains sub-entities, dissection produces one article for
630 the header of this entity, and one article per sub-entity."
631 (setq nndoc-dissection-alist nil
632 nndoc-mime-split-ordinal 0)
634 (set-buffer nndoc-current-buffer)
635 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
637 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
639 "Dissect an entity, within a composite MIME message.
640 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
641 ARTICLE-INSERT should be added at beginning for generating a full article.
642 The string POSITION holds a dotted decimal representation of the article
643 position in the hierarchical structure, it is nil for the outer entity.
644 PARENT is the message-ID of the parent summary line, or nil for none."
645 (let ((case-fold-search t)
646 (message-id (nnmail-message-id))
647 head-end body-begin summary-insert message-rfc822 multipart-any
648 subject content-type type subtype boundary-regexp)
649 ;; Gracefully handle a missing body.
650 (goto-char head-begin)
651 (if (search-forward "\n\n" body-end t)
652 (setq head-end (1- (point))
654 (setq head-end body-end
655 body-begin body-end))
656 (narrow-to-region head-begin head-end)
657 ;; Save MIME attributes.
658 (goto-char head-begin)
659 (setq content-type (message-fetch-field "Content-Type"))
662 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
663 (setq type (downcase (match-string 1 content-type))
664 subtype (downcase (match-string 2 content-type))
665 message-rfc822 (and (string= type "message")
666 (string= subtype "rfc822"))
667 multipart-any (string= type "multipart")))
668 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
669 (setq subject (match-string 1 content-type)))
670 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
671 (setq boundary-regexp (concat "^--"
673 (match-string 1 content-type))
674 "\\(--\\)?[ \t]*\n"))))
676 (when (or multipart-any (not article-insert))
677 (setq subject (message-fetch-field "Subject"))))
681 ;; Prepare the article and summary inserts.
682 (unless article-insert
683 (setq article-insert (buffer-substring (point-min) (point-max))
684 head-end head-begin))
685 (setq summary-insert article-insert)
686 ;; - summary Subject.
688 (let ((line (concat "Subject: <" position
689 (and position multipart-any ".")
690 (and multipart-any "*")
691 (and (or position multipart-any) " ")
692 (cond ((string= subtype "plain") type)
693 ((string= subtype "basic") type)
699 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
700 (replace-match line t t summary-insert)
701 (concat summary-insert line))))
702 ;; - summary Message-ID.
704 (let ((line (concat "Message-ID: " message-id "\n")))
705 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
706 (replace-match line t t summary-insert)
707 (concat summary-insert line))))
708 ;; - summary References.
711 (let ((line (concat "References: " parent "\n")))
712 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
714 (replace-match line t t summary-insert)
715 (concat summary-insert line)))))
716 ;; Generate dissection information for this entity.
717 (push (list (incf nndoc-mime-split-ordinal)
718 head-begin head-end body-begin body-end
719 (count-lines body-begin body-end)
720 article-insert summary-insert)
721 nndoc-dissection-alist)
722 ;; Recurse for all sub-entities, if any.
727 (nndoc-dissect-mime-parts-sub body-begin body-end nil
728 position message-id)))
729 ((and multipart-any boundary-regexp)
730 (let ((part-counter 0)
731 part-begin part-end eof-flag)
732 (while (string-match "\
733 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
735 (setq article-insert (replace-match "" t t article-insert)))
736 (let ((case-fold-search nil))
737 (goto-char body-begin)
738 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
739 (while (not eof-flag)
740 (setq part-begin (point))
741 (cond ((re-search-forward boundary-regexp body-end t)
742 (or (not (match-string 1))
743 (string= (match-string 1) "")
746 (setq part-end (point))
748 (t (setq part-end body-end
751 (nndoc-dissect-mime-parts-sub
752 part-begin part-end article-insert
755 (format "%d" (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