1 ;;; nnfolder.el --- mail folder access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Simon Josefsson <simon@josefsson.org> (adding MARKS)
6 ;; ShengHuo Zhu <zsh@cs.rochester.edu> (adding NOV)
7 ;; Scott Byer <byer@mv.us.adobe.com>
8 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
37 (eval-when-compile (require 'cl))
43 (autoload 'gnus-article-unpropagatable-p "gnus-sum")
44 (autoload 'gnus-intersection "gnus-range"))
46 (nnoo-declare nnfolder)
48 (defvoo nnfolder-directory (expand-file-name message-directory)
49 "The name of the nnfolder directory.")
51 (defvoo nnfolder-nov-directory nil
52 "The name of the nnfolder NOV directory.
53 If nil, `nnfolder-directory' is used.")
55 (defvoo nnfolder-marks-directory nil
56 "The name of the nnfolder MARKS directory.
57 If nil, `nnfolder-directory' is used.")
59 (defvoo nnfolder-active-file
60 (nnheader-concat nnfolder-directory "active")
61 "The name of the active file.")
63 ;; I renamed this variable to something more in keeping with the general GNU
66 (defvoo nnfolder-ignore-active-file nil
67 "If non-nil, the active file is ignored.
68 This causes nnfolder to do some extra work in order to determine the
69 true active ranges of an mbox file. Note that the active file is
70 still saved, but its values are not used. This costs some extra time
71 when scanning an mbox when opening it.")
73 (defvoo nnfolder-distrust-mbox nil
74 "If non-nil, the folder will be distrusted.
75 This means that nnfolder will not trust the user with respect to
76 inserting unaccounted for mail in the middle of an mbox file. This
77 can greatly slow down scans, which now must scan the entire file for
78 unmarked messages. When nil, scans occur forward from the last marked
79 message, a huge time saver for large mailboxes.")
81 (defvoo nnfolder-newsgroups-file
82 (concat (file-name-as-directory nnfolder-directory) "newsgroups")
83 "Mail newsgroups description file.")
85 (defvoo nnfolder-get-new-mail t
86 "If non-nil, nnfolder will check the incoming mail file and split the mail.")
88 (defvoo nnfolder-prepare-save-mail-hook nil
89 "Hook run narrowed to an article before saving.")
91 (defvoo nnfolder-save-buffer-hook nil
92 "Hook run before saving the nnfolder mbox buffer.")
95 (defvoo nnfolder-inhibit-expiry nil
96 "If non-nil, inhibit expiry.")
100 (defconst nnfolder-version "nnfolder 2.0"
103 (defconst nnfolder-article-marker "X-Gnus-Article-Number: "
104 "String used to demarcate what the article number for a message is.")
106 (defvoo nnfolder-current-group nil)
107 (defvoo nnfolder-current-buffer nil)
108 (defvoo nnfolder-status-string "")
109 (defvoo nnfolder-group-alist nil)
110 (defvoo nnfolder-buffer-alist nil)
111 (defvoo nnfolder-scantime-alist nil)
112 (defvoo nnfolder-active-timestamp nil)
113 (defvoo nnfolder-active-file-coding-system mm-text-coding-system)
114 (defvoo nnfolder-active-file-coding-system-for-write
115 nnmail-active-file-coding-system)
116 (defvoo nnfolder-file-coding-system mm-text-coding-system)
117 (defvoo nnfolder-file-coding-system-for-write nnheader-file-coding-system
118 "Coding system for save nnfolder file.
119 if nil, `nnfolder-file-coding-system' is used.") ; FIXME: fill-in the doc-string of this variable
121 (defvoo nnfolder-nov-is-evil nil
122 "If non-nil, Gnus will never generate and use nov databases for mail groups.
123 Using nov databases will speed up header fetching considerably.
124 This variable shouldn't be flipped much. If you have, for some reason,
125 set this to t, and want to set it to nil again, you should always run
126 the `nnfolder-generate-active-file' command. The function will go
127 through all nnfolder directories and generate nov databases for them
128 all. This may very well take some time.")
130 (defvoo nnfolder-nov-file-suffix ".nov")
132 (defvoo nnfolder-nov-buffer-alist nil)
134 (defvar nnfolder-nov-buffer-file-name nil)
136 (defvoo nnfolder-marks-is-evil nil
137 "If non-nil, Gnus will never generate and use marks file for mail groups.
138 Using marks files makes it possible to backup and restore mail groups
139 separately from `.newsrc.eld'. If you have, for some reason, set
140 this to t, and want to set it to nil again, you should always remove
141 the corresponding marks file (usually base nnfolder file name
142 concatenated with `.mrk', but see `nnfolder-marks-file-suffix') for
143 the group. Then the marks file will be regenerated properly by Gnus.")
145 (defvoo nnfolder-marks nil)
147 (defvoo nnfolder-marks-file-suffix ".mrk")
149 (defvar nnfolder-marks-modtime (gnus-make-hashtable))
153 ;;; Interface functions
155 (nnoo-define-basics nnfolder)
157 (deffoo nnfolder-retrieve-headers (articles &optional group server fetch-old)
159 (set-buffer nntp-server-buffer)
161 (let (article start stop)
162 (nnfolder-possibly-change-group group server)
163 (when nnfolder-current-buffer
164 (set-buffer nnfolder-current-buffer)
165 (goto-char (point-min))
166 (if (stringp (car articles))
168 (if (nnfolder-retrieve-headers-with-nov articles fetch-old)
170 (setq articles (gnus-sorted-intersection
171 ;; Is ARTICLES sorted?
173 (nnfolder-existing-articles)))
174 (while (setq article (pop articles))
175 (set-buffer nnfolder-current-buffer)
176 (when (nnfolder-goto-article article)
178 (setq stop (if (search-forward "\n\n" nil t)
181 (set-buffer nntp-server-buffer)
182 (insert (format "221 %d Article retrieved.\n" article))
183 (insert-buffer-substring nnfolder-current-buffer start stop)
184 (goto-char (point-max))
186 (set-buffer nntp-server-buffer)
187 (nnheader-fold-continuation-lines)
190 (deffoo nnfolder-open-server (server &optional defs)
191 (nnoo-change-server 'nnfolder server defs)
192 (nnmail-activate 'nnfolder t)
193 (gnus-make-directory nnfolder-directory)
194 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
195 (and nnfolder-nov-directory
196 (gnus-make-directory nnfolder-nov-directory)))
197 (unless nnfolder-marks-is-evil
198 (and nnfolder-marks-directory
199 (gnus-make-directory nnfolder-marks-directory)))
201 ((not (file-exists-p nnfolder-directory))
202 (nnfolder-close-server)
203 (nnheader-report 'nnfolder "Couldn't create directory: %s"
205 ((not (file-directory-p (file-truename nnfolder-directory)))
206 (nnfolder-close-server)
207 (nnheader-report 'nnfolder "Not a directory: %s" nnfolder-directory))
209 (nnmail-activate 'nnfolder)
210 (nnheader-report 'nnfolder "Opened server %s using directory %s"
211 server nnfolder-directory)
214 (deffoo nnfolder-request-close ()
215 (let ((alist nnfolder-buffer-alist))
217 (nnfolder-close-group (caar alist) nil t)
218 (setq alist (cdr alist))))
219 (nnoo-close-server 'nnfolder)
220 (setq nnfolder-buffer-alist nil
221 nnfolder-group-alist nil))
223 (deffoo nnfolder-request-article (article &optional group server buffer)
224 (nnfolder-possibly-change-group group server)
226 (set-buffer nnfolder-current-buffer)
227 (goto-char (point-min))
228 (when (nnfolder-goto-article article)
232 (unless (and (nnmail-search-unix-mail-delim)
234 (goto-char (point-max)))
236 (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
237 (set-buffer nntp-server-buffer)
239 (insert-buffer-substring nnfolder-current-buffer start stop)
240 (goto-char (point-min))
241 (while (looking-at "From ")