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)))
467 (narrow-to-region (point) (point))
468 (insert-buffer-substring
469 nndoc-current-buffer (car entry) (nth 1 entry))
470 (goto-char (point-max)))
474 (defun nndoc-clari-briefs-type-p ()
475 (when (let ((case-fold-search nil))
476 (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
479 (defun nndoc-transform-clari-briefs (article)
480 (goto-char (point-min))
481 (when (looking-at " *\\*\\(.*\\)\n")
482 (replace-match "" t t))
483 (nndoc-generate-clari-briefs-head article))
485 (defun nndoc-generate-clari-briefs-head (article)
486 (let ((entry (cdr (assq article nndoc-dissection-alist)))
489 (set-buffer nndoc-current-buffer)
491 (narrow-to-region (car entry) (nth 3 entry))
492 (goto-char (point-min))
493 (when (looking-at " *\\*\\(.*\\)$")
494 (setq subject (match-string 1))
495 (when (string-match "[ \t]+$" subject)
496 (setq subject (substring subject 0 (match-beginning 0)))))
498 (let ((case-fold-search nil))
500 "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
501 (setq from (match-string 1)))))
502 (insert "From: " "clari@clari.net (" (or from "unknown") ")"
503 "\nSubject: " (or subject "(no subject)") "\n")))
505 (defun nndoc-standard-digest-type-p ()
506 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
508 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
511 (defun nndoc-digest-body-end ()
512 (and (re-search-forward nndoc-article-begin nil t)
513 (goto-char (match-beginning 0))))
515 (defun nndoc-slack-digest-type-p ()
518 (defun nndoc-lanl-gov-announce-type-p ()
519 (when (let ((case-fold-search nil))
520 (re-search-forward "^\\\\\\\\\nPaper: [a-z-]+/[0-9]+" nil t))
523 (defun nndoc-transform-lanl-gov-announce (article)
524 (goto-char (point-max))
525 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
526 (replace-match "\n\nGet it at \\1 (\\2)" t nil))
527 ;; (when (re-search-backward "^\\\\\\\\$" nil t)
528 ;; (replace-match "" t t))
531 (defun nndoc-generate-lanl-gov-head (article)
532 (let ((entry (cdr (assq article nndoc-dissection-alist)))
533 (e-mail "no address given")
536 (set-buffer nndoc-current-buffer)
538 (narrow-to-region (car entry) (nth 1 entry))
539 (goto-char (point-min))
540 (when (looking-at "^Paper.*: \\([a-z-]+/[0-9]+\\)")
541 (setq subject (concat " (" (match-string 1) ")"))
542 (when (re-search-forward "^From: \\([^ ]+\\)" nil t)
543 (setq e-mail (match-string 1)))
544 (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
546 (setq subject (concat (match-string 1) subject))
547 (setq from (concat (match-string 2) " <" e-mail ">"))))
549 (while (and from (string-match "(\[^)\]*)" from))
550 (setq from (replace-match "" t t from)))
551 (insert "From: " (or from "unknown")
552 "\nSubject: " (or subject "(no subject)") "\n")))
554 (deffoo nndoc-request-accept-article (group &optional server last)
560 ;;; Functions for dissecting the documents
563 (defun nndoc-search (regexp)
565 (re-search-forward regexp nil t)
566 (beginning-of-line)))
568 (defun nndoc-dissect-buffer ()
569 "Go through the document and partition it into heads/bodies/articles."
572 head-begin head-end body-begin body-end)
573 (setq nndoc-dissection-alist nil)
575 (set-buffer nndoc-current-buffer)
576 (goto-char (point-min))
577 ;; Find the beginning of the file.
578 (when nndoc-file-begin
579 (nndoc-search nndoc-file-begin))
580 ;; Go through the file.
581 (while (if (and first nndoc-first-article)
582 (nndoc-search nndoc-first-article)
583 (nndoc-article-begin))
585 (cond (nndoc-head-begin-function
586 (funcall nndoc-head-begin-function))
588 (nndoc-search nndoc-head-begin)))
591 (looking-at nndoc-file-end)))
592 (goto-char (point-max))
593 (setq head-begin (point))
594 (nndoc-search (or nndoc-head-end "^$"))
595 (setq head-end (point))
596 (if nndoc-body-begin-function
597 (funcall nndoc-body-begin-function)
598 (nndoc-search (or nndoc-body-begin "^\n")))
599 (setq body-begin (point))
600 (or (and nndoc-body-end-function
601 (funcall nndoc-body-end-function))
603 (nndoc-search nndoc-body-end))
604 (nndoc-article-begin)
606 (goto-char (point-max))
608 (and (re-search-backward nndoc-file-end nil t)
609 (beginning-of-line)))))
610 (setq body-end (point))
611 (push (list (incf i) head-begin head-end body-begin body-end
612 (count-lines body-begin body-end))
613 nndoc-dissection-alist))))))
615 (defun nndoc-article-begin ()
616 (if nndoc-article-begin-function
617 (funcall nndoc-article-begin-function)
619 (nndoc-search nndoc-article-begin))))
621 (defun nndoc-unquote-dashes ()
622 "Unquote quoted non-separators in digests."
623 (while (re-search-forward "^- -"nil t)
624 (replace-match "-" t t)))
626 ;; Against compiler warnings.
627 (defvar nndoc-mime-split-ordinal)
629 (defun nndoc-dissect-mime-parts ()
630 "Go through a MIME composite article and partition it into sub-articles.
631 When a MIME entity contains sub-entities, dissection produces one article for
632 the header of this entity, and one article per sub-entity."
633 (setq nndoc-dissection-alist nil
634 nndoc-mime-split-ordinal 0)
636 (set-buffer nndoc-current-buffer)
637 (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
639 (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
641 "Dissect an entity, within a composite MIME message.
642 The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
643 ARTICLE-INSERT should be added at beginning for generating a full article.
644 The string POSITION holds a dotted decimal representation of the article
645 position in the hierarchical structure, it is nil for the outer entity.
646 PARENT is the message-ID of the parent summary line, or nil for none."
647 (let ((case-fold-search t)
648 (message-id (nnmail-message-id))
649 head-end body-begin summary-insert message-rfc822 multipart-any
650 subject content-type type subtype boundary-regexp)
651 ;; Gracefully handle a missing body.
652 (goto-char head-begin)
653 (if (search-forward "\n\n" body-end t)
654 (setq head-end (1- (point))
656 (setq head-end body-end
657 body-begin body-end))
658 (narrow-to-region head-begin head-end)
659 ;; Save MIME attributes.
660 (goto-char head-begin)
661 (setq content-type (message-fetch-field "Content-Type"))
664 "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
665 (setq type (downcase (match-string 1 content-type))
666 subtype (downcase (match-string 2 content-type))
667 message-rfc822 (and (string= type "message")
668 (string= subtype "rfc822"))
669 multipart-any (string= type "multipart")))
670 (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
671 (setq subject (match-string 1 content-type)))
672 (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
673 (setq boundary-regexp (concat "^--"
675 (match-string 1 content-type))
676 "\\(--\\)?[ \t]*\n"))))
678 (when (or multipart-any (not article-insert))
679 (setq subject (message-fetch-field "Subject"))))
683 ;; Prepare the article and summary inserts.
684 (unless article-insert
685 (setq article-insert (buffer-substring (point-min) (point-max))
686 head-end head-begin))
687 (setq summary-insert article-insert)
688 ;; - summary Subject.
690 (let ((line (concat "Subject: <" position
691 (and position multipart-any ".")
692 (and multipart-any "*")
693 (and (or position multipart-any) " ")
694 (cond ((string= subtype "plain") type)
695 ((string= subtype "basic") type)
701 (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
702 (replace-match line t t summary-insert)
703 (concat summary-insert line))))
704 ;; - summary Message-ID.
706 (let ((line (concat "Message-ID: " message-id "\n")))
707 (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
708 (replace-match line t t summary-insert)
709 (concat summary-insert line))))
710 ;; - summary References.
713 (let ((line (concat "References: " parent "\n")))
714 (if (string-match "References:.*\n\\([ \t].*\n\\)*"
716 (replace-match line t t summary-insert)
717 (concat summary-insert line)))))
718 ;; Generate dissection information for this entity.
719 (push (list (incf nndoc-mime-split-ordinal)
720 head-begin head-end body-begin body-end
721 (count-lines body-begin body-end)
722 article-insert summary-insert)
723 nndoc-dissection-alist)
724 ;; Recurse for all sub-entities, if any.
729 (nndoc-dissect-mime-parts-sub body-begin body-end nil
730 position message-id)))
731 ((and multipart-any boundary-regexp)
732 (let ((part-counter 0)
733 part-begin part-end eof-flag)
734 (while (string-match "\
735 ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\)\\):.*\n\\([ \t].*\n\\)*"
737 (setq article-insert (replace-match "" t t article-insert)))
738 (let ((case-fold-search nil))
739 (goto-char body-begin)
740 (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
741 (while (not eof-flag)
742 (setq part-begin (point))
743 (cond ((re-search-forward boundary-regexp body-end t)
744 (or (not (match-string 1))
745 (string= (match-string 1) "")
748 (setq part-end (point))
750 (t (setq part-end body-end
753 (nndoc-dissect-mime-parts-sub
754 part-begin part-end article-insert
757 (format "%d" (incf part-counter)))
761 (defun nndoc-add-type (definition &optional position)
762 "Add document DEFINITION to the list of nndoc document definitions.
763 If POSITION is nil or `last', the definition will be added
764 as the last checked definition, if t or `first', add as the
765 first definition, and if any other symbol, add after that
766 symbol in the alist."
767 ;; First remove any old instances.
768 (gnus-pull (car definition) nndoc-type-alist)
769 ;; Then enter the new definition in the proper place.
771 ((or (null position) (eq position 'last))
772 (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
773 ((or (eq position t) (eq position 'first))
774 (push definition nndoc-type-alist))
776 (let ((list (memq (assq position nndoc-type-alist)
779 (error "No such position: %s" position))
780 (setcdr list (cons definition (cdr list)))))))
784 ;;; nndoc.el ends here