1 ;;; nndoc.el --- single file access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; 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 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; For Outlook mail boxes format, see http://mbx2mbox.sourceforge.net/
38 (eval-when-compile (require 'cl))
42 (defvoo nndoc-article-type 'guess
44 One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
45 `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
46 `slack-digest', `clari-briefs', `nsmail', `outlook', `oe-dbx',
47 `mailman', `exim-bounce', or `guess'.")
49 (defvoo nndoc-post-type 'mail
50 "*Whether the nndoc group is `mail' or `post'.")
52 (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
53 "Hook run after opening a document.
54 The default function removes all trailing carriage returns
57 (defvar nndoc-type-alist
59 (article-begin . "^\^A\^A\^A\^A\n")
60 (body-end . "^\^A\^A\^A\^A\n"))
62 (generate-head-function . nndoc-generate-mime-parts-head)
63 (article-transform-function . nndoc-transform-mime-parts))
65 (article-begin . "^From - "))
67 (article-begin . "^Path:"))
69 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
70 (body-end-function . nndoc-rnews-body-end))
72 (article-begin-function . nndoc-mbox-article-begin)
73 (body-end-function . nndoc-mbox-body-end))
75 (article-begin . "\^_\^L *\n")
77 (body-begin-function . nndoc-babyl-body-begin)
78 (head-begin-function . nndoc-babyl-head-begin))
80 (article-begin . "^------ This is a copy of the message, including all the headers. ------\n\n")
81 (body-end-function . nndoc-exim-bounce-body-end-function))
83 (article-begin . "^--.*\n+")
85 (prepare-body-function . nndoc-unquote-dashes))
87 (article-begin . "^--__--__--\n\nMessage:")
88 (body-end . "^--__--__--$")
89 (prepare-body-function . nndoc-unquote-dashes))
91 (article-begin . "^ \\*")
92 (body-end . "^\t------*[ \t]^*\n^ \\*")
95 (generate-head-function . nndoc-generate-clari-briefs-head)
96 (article-transform-function . nndoc-transform-clari-briefs))
99 (head-begin . "^ ?\n")
103 (subtype digest guess))
105 (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
106 (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
107 (prepare-body-function . nndoc-unquote-dashes)
108 (body-end-function . nndoc-digest-body-end)
110 (body-begin . "^ *\n")
111 (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
112 (subtype digest guess))
114 (article-begin . "^------------------------------*[\n \t]+")
116 (body-end-function . nndoc-digest-body-end)
117 (body-begin . "^ ?$")
118 (file-end . "^End of")
119 (prepare-body-function . nndoc-unquote-dashes)
120 (subtype digest guess))
122 (article-begin . "^\\\\\\\\\n")
123 (head-begin . "^Paper.*:")
124 (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
126 (body-end . "\\(-------------------------------------------------\\|%-%-%-%-%-%-%-%-%-%-%-%-%-%-\\|%%--%%--%%--%%--%%--%%--%%--%%--\\|%%%---%%%---%%%---%%%---\\)")
127 (file-end . "\\(^Title: Recent Seminal\\|%%%---%%%---%%%---%%%---\\)")
128 (generate-head-function . nndoc-generate-lanl-gov-head)
129 (article-transform-function . nndoc-transform-lanl-gov-announce)
130 (subtype preprints guess))
132 (article-begin . "^\n")
133 (body-end-function . nndoc-rfc822-forward-body-end-function))
135 (article-begin-function . nndoc-outlook-article-begin)
137 (oe-dbx ;; Outlook Express DBX format
138 (dissection-function . nndoc-oe-dbx-dissection)
139 (generate-head-function . nndoc-oe-dbx-generate-head)
140 (generate-article-function . nndoc-oe-dbx-generate-article))
142 (article-begin . "^-+ \\(Start of \\)?forwarded message.*\n+")
143 (body-end . "^-+ End \\(of \\)?forwarded message.*$")
144 (prepare-body-function . nndoc-unquote-dashes))
145 (mail-in-mail ;; Wild guess on mailer daemon's messages or others
146 (article-begin-function . nndoc-mail-in-mail-article-begin))
157 (defvar nndoc-binary-file-names ".[Dd][Bb][Xx]$"
158 "Regexp for binary nndoc file names.")
161 (defvoo nndoc-file-begin nil)
162 (defvoo nndoc-first-article nil)
163 (defvoo nndoc-article-begin nil)
164 (defvoo nndoc-head-begin nil)
165 (defvoo nndoc-head-end nil)
166 (defvoo nndoc-file-end nil)
167 (defvoo nndoc-body-begin nil)
168 (defvoo nndoc-body-end-function nil)
169 (defvoo nndoc-body-begin-function nil)
170 (defvoo nndoc-head-begin-function nil)
171 (defvoo nndoc-body-end nil)
172 ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
173 ;; following items. ARTICLE acts as the association key and is an ordinal
174 ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
175 ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
176 ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
177 ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
178 ;; generation, respectively. Other headers usually follow directly from the
179 ;; buffer. Value `nil' means no insert.
180 (defvoo nndoc-dissection-alist nil)
181 (defvoo nndoc-prepare-body-function nil)
182 (defvoo nndoc-generate-head-function nil)
183 (defvoo nndoc-article-transform-function nil)
184 (defvoo nndoc-article-begin-function nil)
185 (defvoo nndoc-generate-article-function nil)
186 (defvoo nndoc-dissection-function nil)
188 (defvoo nndoc-status-string "")
189 (defvoo nndoc-group-alist nil)
190 (defvoo nndoc-current-buffer nil
191 "Current nndoc news buffer.")
192 (defvoo nndoc-address nil)
194 (defconst nndoc-version "nndoc 1.0"
199 ;;; Interface functions
201 (nnoo-define-basics nndoc)
203 (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
204 (when (nndoc-possibly-change-buffer newsgroup server)
206 (set-buffer nntp-server-buffer)
209 (if (stringp (car articles))
212 (when (setq entry (cdr (assq (setq article (pop articles))
213 nndoc-dissection-alist)))
214 (insert (format "221 %d Article retrieved.\n" article))
215 (if nndoc-generate-head-function
216 (funcall nndoc-generate-head-function article)
217 (insert-buffer-substring
218 nndoc-current-buffer (car entry) (nth 1 entry)))
219 (goto-char (point-max))
220 (unless (eq (char-after (1- (point))) ?\n)
222 (insert (format "Lines: %d\n" (nth 4 entry)))
225 (nnheader-fold-continuation-lines)
228 (deffoo nndoc-request-article (article &optional newsgroup server buffer)
229 (nndoc-possibly-change-buffer newsgroup server)
231 (let ((buffer (or buffer nntp-server-buffer))
232 (entry (cdr (assq article nndoc-dissection-alist)))
238 ((stringp article) nil)
239 (nndoc-generate-article-function
240 (funcall nndoc-generate-article-function article))
242 (insert-buffer-substring
243 nndoc-current-buffer (car entry) (nth 1 entry))
246 (insert-buffer-substring
247 nndoc-current-buffer (nth 2 entry) (nth 3 entry))
249 (when nndoc-prepare-body-function
250 (funcall nndoc-prepare-body-function))
251 (when nndoc-article-transform-function
252 (funcall nndoc-article-transform-function article))
255 (deffoo nndoc-request-group (group &optional server dont-check)
259 ((not (nndoc-possibly-change-buffer group server))
260 (nnheader-report 'nndoc "No such file or buffer: %s"
263 (nnheader-report 'nndoc "Selected group %s" group)
265 ((zerop (setq number (length nndoc-dissection-alist)))
266 (nndoc-close-group group)
267 (nnheader-report 'nndoc "No articles in group %s" group))
269 (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
271 (deffoo nndoc-request-type (group &optional article)
272 (cond ((not article) 'unknown)
273 (nndoc-post-type nndoc-post-type)