comparison lisp/gnus/nndoc.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 0d8b17d428b5
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; nndoc.el --- single file access for Gnus 1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 2
3 ;; Free Software Foundation, Inc. 3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
4 5
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> 6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> 7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Keywords: news 8 ;; Keywords: news
8 9
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details. 20 ;; GNU General Public License for more details.
20 21
21 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02110-1301, USA.
25 26
26 ;;; Commentary: 27 ;;; Commentary:
27 28
28 ;; For Outlook mail boxes format, see http://mbx2mbox.sourceforge.net/ 29 ;; For Outlook mail boxes format, see http://mbx2mbox.sourceforge.net/
29 30
56 57
57 (defvar nndoc-type-alist 58 (defvar nndoc-type-alist
58 `((mmdf 59 `((mmdf
59 (article-begin . "^\^A\^A\^A\^A\n") 60 (article-begin . "^\^A\^A\^A\^A\n")
60 (body-end . "^\^A\^A\^A\^A\n")) 61 (body-end . "^\^A\^A\^A\^A\n"))
61 (exim-bounce 62 (mime-digest
62 (article-begin . "^------ This is a copy of the message, including all the headers. ------\n\n") 63 (article-begin . "")
63 (body-end-function . nndoc-exim-bounce-body-end-function)) 64 (head-begin . "^ ?\n")
65 (head-end . "^ ?$")
66 (body-end . "")
67 (file-end . "")
68 (subtype digest guess))
69 (mime-parts
70 (generate-head-function . nndoc-generate-mime-parts-head)
71 (article-transform-function . nndoc-transform-mime-parts))
64 (nsmail 72 (nsmail
65 (article-begin . "^From - ")) 73 (article-begin . "^From - "))
66 (news 74 (news
67 (article-begin . "^Path:")) 75 (article-begin . "^Path:"))
68 (rnews 76 (rnews
74 (babyl 82 (babyl
75 (article-begin . "\^_\^L *\n") 83 (article-begin . "\^_\^L *\n")
76 (body-end . "\^_") 84 (body-end . "\^_")
77 (body-begin-function . nndoc-babyl-body-begin) 85 (body-begin-function . nndoc-babyl-body-begin)
78 (head-begin-function . nndoc-babyl-head-begin)) 86 (head-begin-function . nndoc-babyl-head-begin))
87 (exim-bounce
88 (article-begin . "^------ This is a copy of the message, including all the headers. ------\n\n")
89 (body-end-function . nndoc-exim-bounce-body-end-function))
79 (rfc934 90 (rfc934
80 (article-begin . "^--.*\n+") 91 (article-begin . "^--.*\n+")
81 (body-end . "^--.*$") 92 (body-end . "^--.*$")
82 (prepare-body-function . nndoc-unquote-dashes)) 93 (prepare-body-function . nndoc-unquote-dashes))
83 (mailman 94 (mailman
89 (body-end . "^\t------*[ \t]^*\n^ \\*") 100 (body-end . "^\t------*[ \t]^*\n^ \\*")
90 (body-begin . "^\t") 101 (body-begin . "^\t")
91 (head-end . "^\t") 102 (head-end . "^\t")
92 (generate-head-function . nndoc-generate-clari-briefs-head) 103 (generate-head-function . nndoc-generate-clari-briefs-head)
93 (article-transform-function . nndoc-transform-clari-briefs)) 104 (article-transform-function . nndoc-transform-clari-briefs))
94 (mime-digest 105
95 (article-begin . "")
96 (head-begin . "^ ?\n")
97 (head-end . "^ ?$")
98 (body-end . "")
99 (file-end . "")
100 (subtype digest guess))
101 (mime-parts
102 (generate-head-function . nndoc-generate-mime-parts-head)
103 (article-transform-function . nndoc-transform-mime-parts))
104 (standard-digest 106 (standard-digest
105 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+")) 107 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
106 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+")) 108 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
107 (prepare-body-function . nndoc-unquote-dashes) 109 (prepare-body-function . nndoc-unquote-dashes)
108 (body-end-function . nndoc-digest-body-end) 110 (body-end-function . nndoc-digest-body-end)
127 (file-end . "\\(^Title: Recent Seminal\\|%%%---%%%---%%%---%%%---\\)") 129 (file-end . "\\(^Title: Recent Seminal\\|%%%---%%%---%%%---%%%---\\)")
128 (generate-head-function . nndoc-generate-lanl-gov-head) 130 (generate-head-function . nndoc-generate-lanl-gov-head)
129 (article-transform-function . nndoc-transform-lanl-gov-announce) 131 (article-transform-function . nndoc-transform-lanl-gov-announce)
130 (subtype preprints guess)) 132 (subtype preprints guess))
131 (rfc822-forward 133 (rfc822-forward
132 (article-begin . "^\n") 134 (article-begin . "^\n+")
133 (body-end-function . nndoc-rfc822-forward-body-end-function)) 135 (body-end-function . nndoc-rfc822-forward-body-end-function)
136 (generate-head-function . nndoc-rfc822-forward-generate-head)
137 (generate-article-function . nndoc-rfc822-forward-generate-article))
134 (outlook 138 (outlook
135 (article-begin-function . nndoc-outlook-article-begin) 139 (article-begin-function . nndoc-outlook-article-begin)
136 (body-end . "\0")) 140 (body-end . "\0"))
137 (oe-dbx ;; Outlook Express DBX format 141 (oe-dbx ;; Outlook Express DBX format
138 (dissection-function . nndoc-oe-dbx-dissection) 142 (dissection-function . nndoc-oe-dbx-dissection)
391 (setq result nil)))) 395 (setq result nil))))
392 (unless (or result results) 396 (unless (or result results)
393 (error "Document is not of any recognized type")) 397 (error "Document is not of any recognized type"))
394 (if result 398 (if result
395 (car entry) 399 (car entry)
396 (cadar (sort results 'car-less-than-car))))) 400 (cadar (last (sort results 'car-less-than-car))))))
397 401
398 ;;; 402 ;;;
399 ;;; Built-in type predicates and functions 403 ;;; Built-in type predicates and functions
400 ;;; 404 ;;;
401 405
416 (concat "^" message-unix-mail-delimiter) nil t) 420 (concat "^" message-unix-mail-delimiter) nil t)
417 (setq end (point)) 421 (setq end (point))
418 (search-forward "\n\n" beg t) 422 (search-forward "\n\n" beg t)
419 (re-search-backward 423 (re-search-backward
420 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t) 424 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
421 (setq len (string-to-int (match-string 1))) 425 (setq len (string-to-number (match-string 1)))
422 (search-forward "\n\n" beg t) 426 (search-forward "\n\n" beg t)
423 (unless (= (setq len (+ (point) len)) (point-max)) 427 (unless (= (setq len (+ (point) len)) (point-max))
424 (and (< len (point-max)) 428 (and (< len (point-max))
425 (goto-char len) 429 (goto-char len)
426 (looking-at message-unix-mail-delimiter))))) 430 (looking-at message-unix-mail-delimiter)))))
439 t)) 443 t))
440 444
441 (defun nndoc-rnews-body-end () 445 (defun nndoc-rnews-body-end ()
442 (and (re-search-backward nndoc-article-begin nil t) 446 (and (re-search-backward nndoc-article-begin nil t)
443 (forward-line 1) 447 (forward-line 1)
444 (goto-char (+ (point) (string-to-int (match-string 1)))))) 448 (goto-char (+ (point) (string-to-number (match-string 1))))))
445 449
446 (defun nndoc-babyl-type-p () 450 (defun nndoc-babyl-type-p ()
447 (when (re-search-forward "\^_\^L *\n" nil t) 451 (when (re-search-forward "\^_\^L *\n" nil t)
448 t)) 452 t))
449 453
466 t)) 470 t))
467 471
468 (defun nndoc-forward-type-p () 472 (defun nndoc-forward-type-p ()
469 (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+" 473 (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+"
470 nil t) 474 nil t)
471 (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:")) 475 (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:\\|^>?From "))
472 t)) 476 t))
473 477
474 (defun nndoc-rfc934-type-p () 478 (defun nndoc-rfc934-type-p ()
475 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t) 479 (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
476 (not (re-search-forward "^Subject:.*digest" nil t)) 480 (not (re-search-forward "^Subject:.*digest" nil t))
488 (when (re-search-forward "^Content-Type: *message/rfc822" nil t) 492 (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
489 t))) 493 t)))
490 494
491 (defun nndoc-rfc822-forward-body-end-function () 495 (defun nndoc-rfc822-forward-body-end-function ()
492 (goto-char (point-max))) 496 (goto-char (point-max)))
497
498 (defun nndoc-rfc822-forward-generate-article (article &optional head)
499 (let ((entry (cdr (assq article nndoc-dissection-alist)))
500 (begin (point))
501 encoding)
502 (with-current-buffer nndoc-current-buffer
503 (save-restriction
504 (message-narrow-to-head)
505 (setq encoding (message-fetch-field "content-transfer-encoding"))))
506 (insert-buffer-substring nndoc-current-buffer (car entry) (nth 3 entry))
507 (when encoding
508 (save-restriction
509 (narrow-to-region begin (point-max))
510 (mm-decode-content-transfer-encoding
511 (intern (downcase (mail-header-strip encoding))))))
512 (when head
513 (goto-char begin)
514 (when (search-forward "\n\n" nil t)
515 (delete-region (1- (point)) (point-max)))))
516 t)
517
518 (defun nndoc-rfc822-forward-generate-head (article)
519 (nndoc-rfc822-forward-generate-article article 'head))
493 520
494 (defun nndoc-mime-parts-type-p () 521 (defun nndoc-mime-parts-type-p ()
495 (let ((case-fold-search t) 522 (let ((case-fold-search t)
496 (limit (search-forward "\n\n" nil t))) 523 (limit (search-forward "\n\n" nil t)))
497 (goto-char (point-min)) 524 (goto-char (point-min))
769 796
770 (defun nndoc-dissect-buffer () 797 (defun nndoc-dissect-buffer ()
771 "Go through the document and partition it into heads/bodies/articles." 798 "Go through the document and partition it into heads/bodies/articles."
772 (let ((i 0) 799 (let ((i 0)
773 (first t) 800 (first t)
774 head-begin head-end body-begin body-end) 801 art-begin head-begin head-end body-begin body-end)
775 (setq nndoc-dissection-alist nil) 802 (setq nndoc-dissection-alist nil)
776 (save-excursion 803 (save-excursion
777 (set-buffer nndoc-current-buffer) 804 (set-buffer nndoc-current-buffer)
778 (goto-char (point-min)) 805 (goto-char (point-min))
779 ;; Remove blank lines. 806 ;; Remove blank lines.
785 (when nndoc-file-begin 812 (when nndoc-file-begin
786 (nndoc-search nndoc-file-begin)) 813 (nndoc-search nndoc-file-begin))
787 ;; Go through the file. 814 ;; Go through the file.
788 (while (if (and first nndoc-first-article) 815 (while (if (and first nndoc-first-article)
789 (nndoc-search nndoc-first-article) 816 (nndoc-search nndoc-first-article)
790 (nndoc-article-begin)) 817 (if art-begin
791 (setq first nil) 818 (goto-char art-begin)
819 (nndoc-article-begin)))
820 (setq first nil
821 art-begin nil)
792 (cond (nndoc-head-begin-function 822 (cond (nndoc-head-begin-function
793 (funcall nndoc-head-begin-function)) 823 (funcall nndoc-head-begin-function))
794 (nndoc-head-begin 824 (nndoc-head-begin
795 (nndoc-search nndoc-head-begin))) 825 (nndoc-search nndoc-head-begin)))
796 (if (or (eobp) 826 (if (or (eobp)
806 (setq body-begin (point)) 836 (setq body-begin (point))
807 (or (and nndoc-body-end-function 837 (or (and nndoc-body-end-function
808 (funcall nndoc-body-end-function)) 838 (funcall nndoc-body-end-function))
809 (and nndoc-body-end 839 (and nndoc-body-end
810 (nndoc-search nndoc-body-end)) 840 (nndoc-search nndoc-body-end))
811 (nndoc-article-begin) 841 (and (nndoc-article-begin)
842 (setq art-begin (point)))
812 (progn 843 (progn
813 (goto-char (point-max)) 844 (goto-char (point-max))
814 (when nndoc-file-end 845 (when nndoc-file-end
815 (and (re-search-backward nndoc-file-end nil t) 846 (and (re-search-backward nndoc-file-end nil t)
816 (beginning-of-line))))) 847 (beginning-of-line)))))
888 (unless type 919 (unless type
889 (setq type "text" 920 (setq type "text"
890 subtype "plain")) 921 subtype "plain"))
891 ;; Prepare the article and summary inserts. 922 ;; Prepare the article and summary inserts.
892 (unless article-insert 923 (unless article-insert
893 (setq article-insert (buffer-substring (point-min) (point-max)) 924 (setq article-insert (buffer-string)
894 head-end head-begin)) 925 head-end head-begin))
895 ;; Fix MIME-Version 926 ;; Fix MIME-Version
896 (unless (string-match "MIME-Version:" article-insert) 927 (unless (string-match "MIME-Version:" article-insert)
897 (setq article-insert 928 (setq article-insert
898 (concat article-insert "MIME-Version: 1.0\n"))) 929 (concat article-insert "MIME-Version: 1.0\n")))
991 (error "No such position: %s" position)) 1022 (error "No such position: %s" position))
992 (setcdr list (cons definition (cdr list))))))) 1023 (setcdr list (cons definition (cdr list)))))))
993 1024
994 (provide 'nndoc) 1025 (provide 'nndoc)
995 1026
1027 ;;; arch-tag: f5c2970e-0387-47ac-a0b3-6cc317dffabe
996 ;;; nndoc.el ends here 1028 ;;; nndoc.el ends here