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 acts 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)
288 (if (stringp nndoc-address)
289 (nnheader-insert-file-contents nndoc-address)
290 (insert-buffer-substring nndoc-address))
291 (run-hooks 'nndoc-open-document-hook))))
292 ;; Initialize the nndoc structures according to this new document.
293 (when (and nndoc-current-buffer
294 (not nndoc-dissection-alist))
296 (set-buffer nndoc-current-buffer)
298 (if (eq nndoc-article-type 'mime-parts)
299 (nndoc-dissect-mime-parts)
300 (nndoc-dissect-buffer))))
301 (unless nndoc-current-buffer
302 (nndoc-close-server))
303 ;; Return whether we managed to select a file.
304 nndoc-current-buffer))
307 ;;; Deciding what document type we have
310 (defun nndoc-set-delims ()
311 "Set the nndoc delimiter variables according to the type of the document."
312 (let ((vars '(nndoc-file-begin
314 nndoc-article-begin-function
315 nndoc-head-begin nndoc-head-end
316 nndoc-file-end nndoc-article-begin
317 nndoc-body-begin nndoc-body-end-function nndoc-body-end
318 nndoc-prepare-body-function nndoc-article-transform-function
319 nndoc-generate-head-function nndoc-body-begin-function
320 nndoc-head-begin-function)))
322 (set (pop vars) nil)))
324 ;; Guess away until we find the real file type.
325 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
327 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
328 ;; Set the nndoc variables.
330 (set (intern (format "nndoc-%s" (caar defs)))
333 (defun nndoc-guess-type (subtype)
334 (let ((alist nndoc-type-alist)
335 results result entry)
336 (while (and (not result)
337 (setq entry (pop alist)))
338 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
339 (goto-char (point-min))
340 (when (numberp (setq result (funcall (intern
341 (format "nndoc-%s-type-p"
343 (push (cons result entry) results)
345 (unless (or result results)
346 (error "Document is not of any recognized type"))
349 (cadar (sort results 'car-less-than-car)))))
352 ;;; Built-in type predicates and functions
355 (defun nndoc-mbox-type-p ()
356 (when (looking-at message-unix-mail-delimiter)
359 (defun nndoc-mbox-article-begin ()
360 (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
361 (goto-char (match-beginning 0))))
363 (defun nndoc-mbox-body-end ()
368 (and (re-search-backward
369 (concat "^" message-unix-mail-delimiter) nil t)
371 (search-forward "\n\n" beg t)
373 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
374 (setq len (string-to-int (match-string 1)))
375 (search-forward "\n\n" beg t)
376 (unless (= (setq len (+ (point) len)) (point-max))
377 (and (< len (point-max))
379 (looking-at message-unix-mail-delimiter)))))
382 (defun nndoc-mmdf-type-p ()
383 (when (looking-at "\^A\^A\^A\^A$")
386 (defun nndoc-news-type-p ()
387 (when (looking-at "^Path:.*\n")
390 (defun nndoc-rnews-type-p ()
391 (when (looking-at "#! *rnews")
394 (defun nndoc-rnews-body-end ()
395 (and (re-search-backward nndoc-article-begin nil t)
397 (goto-char (+ (point) (string-to-int (match-string 1))))))
399 (defun nndoc-babyl-type-p ()
400 (when (re-search-forward "\^_\^L *\n" nil t)
403 (defun nndoc-babyl-body-begin ()
404 (re-search-forward "^\n" nil t)
405 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
406 (let ((next (or (save-excursion
407 (re-search-forward nndoc-article-begin nil t))
409 (unless (re-search-forward "^\n" next t)
413 (forward-line -1)))))
415 (defun nndoc-babyl-head-begin ()
416 (when (re-search-forward "^[0-9].*\n" nil t)
417 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
421 (defun nndoc-forward-type-p ()
422 (when (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t)
423 (not (re-search-forward "^Subject:.*digest" nil t))
424 (not (re-search-backward "^From:" nil t 2))
425 (not (re-search-forward "^From:" nil t 2)))
428 (defun nndoc-rfc934-type-p ()
429 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
430 (not (re-search-forward "^Subject:.*digest" nil t))
431 (not (re-search-backward "^From:" nil t 2))
432 (not (re-search-forward "^From:" nil t 2)))
435 (defun nndoc-rfc822-forward-type-p ()
437 (message-narrow-to-head)
438 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
441 (defun nndoc-rfc822-forward-body-end-function ()
442 (goto-char (point-max)))
444 (defun nndoc-mime-parts-type-p ()
445 (let ((case-fold-search t)
446 (limit (search-forward "\n\n" nil t)))
447 (goto-char (point-min))
451 ^Content-Type:[ \t]*multipart/[a-z]+ *;\\(\\(\n[ \t]\\)?.*;\\)*"
452 "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
456 (defun nndoc-transform-mime-parts (article)
457 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
458 (headers (nth 5 entry)))
460 (goto-char (point-min))
463 (defun nndoc-generate-mime-parts-head (article)
464 (let* ((entry (cdr (assq article nndoc-dissection-alist)))
465 (headers (nth 6 entry)))
468 (insert-buffer-substring
469 nndoc-current-buffer (car entry) (nth 1 entry))))
471 (defun nndoc-clari-briefs-type-p ()
472 (when (let ((case-fold-search nil))
473 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
476 (defun nndoc-transform-clari-briefs (article)
477 (goto-char (point-min))
478 (when (looking-at " *\\*\\(.*\\)\n")
479 (replace-match "" t t))
480 (nndoc-generate-clari-briefs-head article))
482 (defun nndoc-generate-clari-briefs-head (article)
483 (let ((entry (cdr (assq article nndoc-dissection-alist)))
486 (set-buffer nndoc-current-buffer)
488 (narrow-to-region (car entry) (nth 3 entry))
489 (goto-char (point-min))
490 (when (looking-at " *\\*\\(.*\\)$")
491 (setq subject (match-string 1))
492 (when (string-match "[ \t]+$" subject)
493 (setq subject (substring subject 0 (match-beginning 0)))))
495 (let ((case-fold-search nil))
497 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
498 (setq from (match-string 1)))))
499 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
500 "\nSubject: " (or subject "(no subject)") "\n")))
502 (defun nndoc-standard-digest-type-p ()
503 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
505 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
508 (defun nndoc-digest-body-end ()
509 (and (re-search-forward nndoc-article-begin nil t)
510 (goto-char (match-beginning 0))))
512 (defun nndoc-slack-digest-type-p ()
515 (defun nndoc-lanl-gov-announce-type-p ()
516 (when (let ((case-fold-search nil))
517 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
520 (defun nndoc-transform-lanl-gov-announce (article)
521 (goto-char (point-max))
522 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
523 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
524 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
525 ;; (replace-match "" t t))
528 (defun nndoc-generate-lanl-gov-head (article)
529 (let ((entry (cdr (assq article nndoc-dissection-alist)))
530 (e-mail "no address given")
533 (set-buffer nndoc-current-buffer)
535 (narrow-to-region (car entry) (nth 1 entry))
536 (goto-char (point-min))
537 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
538 (setq subject (concat " (" (match-string 1) ")"))
539 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
540 (setq e-mail (match-string 1)))
541 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
543 (setq subject (concat (match-string 1) subject))
544 (setq from (concat (match-string 2) " <" e-mail ">"))))
546 (while (and from (string-match "(\[^)\]*)" from))
547 (setq from (replace-match "" t t from)))
548 (insert "From: " (or from "unknown")
549 "\nSubject: " (or subject "(no subject)") "\n")))
551 (deffoo nndoc-request-accept-article (group &optional server last)
557 ;;; Functions for dissecting the documents
560 (defun nndoc-search (regexp)
562 (re-search-forward regexp nil t)
563 (beginning-of-line)))
565 (defun nndoc-dissect-buffer ()
566 "Go through the document and partition it into heads/bodies/articles."
569 head-begin head-end body-begin body-end)
570 (setq nndoc-dissection-alist nil)
572 (set-buffer nndoc-current-buffer)
573 (goto-char (point-min))
574 ;; Find the beginning of the file.
575 (when nndoc-file-begin
576 (nndoc-search nndoc-file-begin))
577 ;; Go through the file.
578 (while (if (and first nndoc-first-article)
579 (nndoc-search nndoc-first-article)
580 (nndoc-article-begin))
582 (cond (nndoc-head-begin-function
583 (funcall nndoc-head-begin-function))
585 (nndoc-search nndoc-head-begin)))
588 (looking-at nndoc-file-end)))
589 (goto-char (point-max))
590 (setq head-begin (point))
591 (nndoc-search (or nndoc-head-end "^$"))
592 (setq head-end (point))
593 (if nndoc-body-begin-function
594 (funcall nndoc-body-begin-function)
595 (nndoc-search (or nndoc-body-begin "^\n")))
596 (setq body-begin (point))
597 (or (and nndoc-body-end-function
598 (funcall nndoc-body-end-function))
600 (nndoc-search nndoc-body-end))
601 (nndoc-article-begin)
603 (goto-char (point-max))
605 (and (re-search-backward nndoc-file-end nil t)
606 (beginning-of-line)))))
607 (setq body-end (point))
608 (push (list (incf i) head-begin head-end body-begin body-end
609 (count-lines body-begin body-end))
610 nndoc-dissection-alist))))))
612 (defun nndoc-article-begin ()
613 (if nndoc-article-begin-function
614 (funcall nndoc-article-begin-function)
616 (nndoc-search nndoc-article-begin))))
618 (defun nndoc-unquote-dashes ()
619 "Unquote quoted non-separators in digests."
620 (while (re-search-forward "^- -"nil t)
621 (replace-match "-" t t)))
623 ;; Against compiler warnings.
624 (defvar nndoc-mime-split-ordinal)
626 (defun nndoc-dissect-mime-parts ()
627 "Go through a MIME composite article and partition it into sub-articles.
628 When a MIME entity contains sub-entities, dissection produces one article for
629 the header of this entity, and one article per sub-entity."
630 (setq nndoc-dissection-alist nil
631 nndoc-mime-split-ordinal 0)
633 (set-buffer nndoc-current-buffer)
634 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
636 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
638 "Dissect an entity, within a composite MIME message.
639 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
640 ARTICLE-INSERT should be added at beginning for generating a full article.
641 The string POSITION holds a dotted decimal representation of the article
642 position in the hierarchical structure, it is nil for the outer entity.
643 PARENT is the message-ID of the parent summary line, or nil for none."
644 (let ((case-fold-search t)
645 (message-id (nnmail-message-id))
646 head-end body-begin summary-insert message-rfc822 multipart-any
647 subject content-type type subtype boundary-regexp)
648 ;; Gracefully handle a missing body.
649 (goto-char head-begin)
650 (if (search-forward "\n\n" body-end t)
651 (setq head-end (1- (point))
653 (setq head-end body-end
654 body-begin body-end))
655 (narrow-to-region head-begin head-end)
656 ;; Save MIME attributes.
657 (goto-char head-begin)
658 (setq content-type (message-fetch-field "Content-Type"))
661 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
662 (setq type (downcase (match-string 1 content-type))
663 subtype (downcase (match-string 2 content-type))
664 message-rfc822 (and (string= type "message")
665 (string= subtype "rfc822"))
666 multipart-any (string= type "multipart")))
667 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
668 (setq subject (match-string 1 content-type)))
669 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
670 (setq boundary-regexp (concat "^--"
672 (match-string 1 content-type))
673 "\\(--\\)?[ \t]*\n"))))
675 (when (or multipart-any (not article-insert))
676 (setq subject (message-fetch-field "Subject"))))
680 ;; Prepare the article and summary inserts.
681 (unless article-insert
682 (setq article-insert (buffer-substring (point-min) (point-max))
683 head-end head-begin))
684 (setq summary-insert article-insert)
685 ;; - summary Subject.
687 (let ((line (concat "Subject: <" position
688 (and position multipart-any ".")
689 (and multipart-any "*")
690 (and (or position multipart-any) " ")
691 (cond ((string= subtype "plain") type)
692 ((string= subtype "basic") type)
698 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
699 (replace-match line t t summary-insert)
700 (concat summary-insert line))))
701 ;; - summary Message-ID.
703 (let ((line (concat "Message-ID: " message-id "\n")))
704 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
705 (replace-match line t t summary-insert)
706 (concat summary-insert line))))
707 ;; - summary References.
710 (let ((line (concat "References: " parent "\n")))
711 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
713 (replace-match line t t summary-insert)
714 (concat summary-insert line)))))
715 ;; Generate dissection information for this entity.
716 (push (list (incf nndoc-mime-split-ordinal)
717 head-begin head-end body-begin body-end
718 (count-lines body-begin body-end)
719 article-insert summary-insert)
720 nndoc-dissection-alist)
721 ;; Recurse for all sub-entities, if any.
726 (nndoc-dissect-mime-parts-sub body-begin body-end nil
727 position message-id)))
728 ((and multipart-any boundary-regexp)
729 (let ((part-counter 0)
730 part-begin part-end eof-flag)
731 (while (string-match "\
732 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
734 (setq article-insert (replace-match "" t t article-insert)))
735 (let ((case-fold-search nil))
736 (goto-char body-begin)
737 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
738 (while (not eof-flag)
739 (setq part-begin (point))
740 (cond ((re-search-forward boundary-regexp body-end t)
741 (or (not (match-string 1))
742 (string= (match-string 1) "")
745 (setq part-end (point))
747 (t (setq part-end body-end
750 (nndoc-dissect-mime-parts-sub
751 part-begin part-end article-insert
754 (format "%d" (incf part-counter)))
758 (defun nndoc-add-type (definition &optional position)
759 "Add document DEFINITION to the list of nndoc document definitions.
760 If POSITION is nil or `last', the definition will be added
761 as the last checked definition, if t or `first', add as the
762 first definition, and if any other symbol, add after that
763 symbol in the alist."
764 ;; First remove any old instances.
765 (gnus-pull (car definition) nndoc-type-alist)
766 ;; Then enter the new definition in the proper place.
768 ((or (null position) (eq position 'last))
769 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
770 ((or (eq position t) (eq position 'first))
771 (push definition nndoc-type-alist))
773 (let ((list (memq (assq position nndoc-type-alist)
776 (error "No such position: %s" position))
777 (setcdr list (cons definition (cdr list)))))))
781 ;;; nndoc.el ends here