1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail
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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
32 (eval-when-compile (require 'cl))
34 (require 'gnus) ; for macro gnus-kill-buffer, at least
38 (require 'mail-source)
42 (autoload 'gnus-add-buffer "gnus")
43 (autoload 'gnus-kill-buffer "gnus")
46 "Reading mail with Gnus."
49 (defgroup nnmail-retrieve nil
50 "Retrieving new mail."
53 (defgroup nnmail-prepare nil
54 "Preparing (or mangling) new mail after retrieval."
57 (defgroup nnmail-duplicate nil
58 "Handling of duplicate mail messages."
61 (defgroup nnmail-split nil
62 "Organizing the incoming mail in folders."
65 (defgroup nnmail-files nil
70 (defgroup nnmail-expire nil
74 (defgroup nnmail-procmail nil
75 "Interfacing with procmail and other mail agents."
78 (defgroup nnmail-various nil
79 "Various mail options."
82 (defcustom nnmail-split-methods '(("mail.misc" ""))
83 "*Incoming mail will be split according to this variable.
85 If you'd like, for instance, one mail group for mail from the
86 \"4ad-l\" mailing list, one group for junk mail and one for everything
87 else, you could do something like this:
89 (setq nnmail-split-methods
90 '((\"mail.4ad\" \"From:.*4ad\")
91 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
92 (\"mail.misc\" \"\")))
94 As you can see, this variable is a list of lists, where the first
95 element in each \"rule\" is the name of the group (which, by the way,
96 does not have to be called anything beginning with \"mail\",
97 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
98 nnmail will try to match on the header to find a fit.
100 The second element can also be a function. In that case, it will be
101 called narrowed to the headers with the first element of the rule as
102 the argument. It should return a non-nil value if it thinks that the
103 mail belongs in that group.
105 The last element should always have \"\" as the regexp.
107 This variable can also have a function as its value."
109 :type '(choice (repeat :tag "Alist" (group (string :tag "Name")
110 (choice regexp function)))
111 (function-item nnmail-split-fancy)
112 (function :tag "Other")))
114 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
115 (defcustom nnmail-crosspost t
116 "If non-nil, do crossposting if several split methods match the mail.
117 If nil, the first match found will be used."
121 (defcustom nnmail-split-fancy-with-parent-ignore-groups nil
122 "Regexp that matches group names to be ignored when applying `nnmail-split-fancy-with-parent'.
123 This can also be a list of regexps."
126 :type '(choice (const :tag "none" nil)
128 (repeat :value (".*") regexp)))
130 (defcustom nnmail-cache-ignore-groups nil
131 "Regexp that matches group names to be ignored when inserting message ids into the cache (`nnmail-cache-insert').
132 This can also be a list of regexps."
135 :type '(choice (const :tag "none" nil)
137 (repeat :value (".*") regexp)))
139 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
140 (defcustom nnmail-keep-last-article nil
141 "If non-nil, nnmail will never delete/move a group's last article.
142 It can be marked expirable, so it will be deleted when it is no longer last.
144 You may need to set this variable if other programs are putting
145 new mail into folder numbers that Gnus has marked as expired."
146 :group 'nnmail-procmail
147 :group 'nnmail-various
150 (defcustom nnmail-use-long-file-names nil
151 "If non-nil the mail backends will use long file and directory names.
152 If nil, groups like \"mail.misc\" will end up in directories like
157 (defcustom nnmail-default-file-modes 384
158 "Set the mode bits of all new mail files to this integer."
162 (defcustom nnmail-expiry-wait 7
163 "*Expirable articles that are older than this will be expired.
164 This variable can either be a number (which will be interpreted as a
165 number of days) -- this doesn't have to be an integer. This variable
166 can also be `immediate' and `never'."
167 :group 'nnmail-expire
168 :type '(choice (const immediate)
172 (defcustom nnmail-expiry-wait-function nil
173 "Variable that holds function to specify how old articles should be before they are expired.
174 The function will be called with the name of the group that the expiry
175 is to be performed in, and it should return an integer that says how
176 many days an article can be stored before it is considered \"old\".
177 It can also return the values `never' and `immediate'.
181 \(setq nnmail-expiry-wait-function
183 (cond ((string-match \"private\" newsgroup) 31)
184 ((string-match \"junk\" newsgroup) 1)
185 ((string-match \"important\" newsgroup) 'never)
187 :group 'nnmail-expire
188 :type '(choice (const :tag "nnmail-expiry-wait" nil)
189 (function :format "%v" nnmail-)))
191 (defcustom nnmail-expiry-target 'delete
192 "*Variable that says where expired messages should end up.
193 The default value is `delete' (which says to delete the messages),
194 but it can also be a string or a function. If it is a string, expired
195 messages end up in that group. If it is a function, the function is
196 called in a buffer narrowed to the message in question. The function
197 receives one argument, the name of the group the message comes from.
198 The return value should be `delete' or a group name (a string)."
200 :group 'nnmail-expire
201 :type '(choice (const delete)
205 (defcustom nnmail-fancy-expiry-targets nil
206 "Determine expiry target based on articles using fancy techniques.
208 This is a list of (\"HEADER\" \"REGEXP\" \"TARGET\") entries. If
209 `nnmail-expiry-target' is set to the function
210 `nnmail-fancy-expiry-target' and HEADER of the article matches REGEXP,
211 the message will be expired to a group determined by invoking
212 `format-time-string' with TARGET used as the format string and the
213 time extracted from the articles' Date header (if missing the current
216 In the special cases that HEADER is the symbol `to-from', the regexp
217 will try to match against both the From and the To header.
221 \(setq nnmail-fancy-expiry-targets
222 '((to-from \"boss\" \"nnfolder:Work\")
223 (\"Subject\" \"IMPORTANT\" \"nnfolder:IMPORTANT.%Y.%b\")
224 (\"from\" \".*\" \"nnfolder:Archive-%Y\")))
226 In this case, articles containing the string \"boss\" in the To or the
227 From header will be expired to the group \"nnfolder:Work\";
228 articles containing the sting \"IMPORTANT\" in the Subject header will
229 be expired to the group \"nnfolder:IMPORTANT.YYYY.MMM\"; and
230 everything else will be expired to \"nnfolder:Archive-YYYY\"."
232 :group 'nnmail-expire
233 :type '(repeat (list (choice :tag "Match against"
234 (string :tag "Header")
237 (string :tag "Target group format string"))))
239 (defcustom nnmail-cache-accepted-message-ids nil
240 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache.
241 If non-nil, also update the cache when copy or move articles."
245 (make-obsolete-variable 'nnmail-spool-file
246 "This option is obsolete in Gnus 5.9. \
247 Use `mail-sources' instead.")
248 ;; revision 5.29 / p0-85 / Gnus 5.9
249 ;; Variable removed in No Gnus v0.7
251 (defcustom nnmail-resplit-incoming nil
252 "*If non-nil, re-split incoming procmail sorted mail."
253 :group 'nnmail-procmail
256 (defcustom nnmail-scan-directory-mail-source-once nil
257 "*If non-nil, scan all incoming procmail sorted mails once.
258 It scans low-level sorted spools even when not required."
260 :group 'nnmail-procmail
263 (defcustom nnmail-delete-file-function 'delete-file
264 "Function called to delete files in some mail backends."
268 (defcustom nnmail-crosspost-link-function
269 (if (string-match "windows-nt\\|emx" (symbol-name system-type))
272 "*Function called to create a copy of a file.
273 This is `add-name-to-file' by default, which means that crossposts
274 will use hard links. If your file system doesn't allow hard
275 links, you could set this variable to `copy-file' instead."
277 :type '(radio (function-item add-name-to-file)
278 (function-item copy-file)
279 (function :tag "Other")))
281 (defcustom nnmail-read-incoming-hook
282 (if (eq system-type 'windows-nt)
283 '(nnheader-ms-strip-cr)
285 "*Hook that will be run after the incoming mail has been transferred.
286 The incoming mail is moved from the specified spool file (which normally is
287 something like \"/usr/spool/mail/$user\") to the user's home
288 directory. This hook is called after the incoming mail box has been
289 emptied, and can be used to call any mail box programs you have
290 running (\"xwatch\", etc.)
294 \(add-hook 'nnmail-read-incoming-hook
296 (call-process \"/local/bin/mailsend\" nil nil nil
298 ;; The incoming mail box file.
299 (expand-file-name (user-login-name)
300 rmail-spool-directory))))
302 If you have xwatch running, this will alert it that mail has been
305 If you use `display-time', you could use something like this:
307 \(add-hook 'nnmail-read-incoming-hook
309 ;; Update the displayed time, since that will clear out
310 ;; the flag that says you have mail.
311 (when (eq (process-status \"display-time\") 'run)
312 (display-time-filter display-time-process \"\"))))"
313 :group 'nnmail-prepare
316 (defcustom nnmail-prepare-incoming-hook nil
317 "Hook called before treating incoming mail.
318 The hook is run in a buffer with all the new, incoming mail."
319 :group 'nnmail-prepare
322 (defcustom nnmail-prepare-incoming-header-hook nil
323 "Hook called narrowed to the headers of each message.
324 This can be used to remove excessive spaces (and stuff like
325 that) from the headers before splitting and saving the messages."
326 :group 'nnmail-prepare
329 (defcustom nnmail-prepare-incoming-message-hook nil
330 "Hook called narrowed to each message."
331 :group 'nnmail-prepare
334 (defcustom nnmail-list-identifiers nil
335 "Regexp that matches list identifiers to be removed.
336 This can also be a list of regexps."
337 :group 'nnmail-prepare
338 :type '(choice (const :tag "none" nil)
340 (repeat :value (".*") regexp)))
342 (defcustom nnmail-pre-get-new-mail-hook nil
343 "Hook called just before starting to handle new incoming mail."
344 :group 'nnmail-retrieve
347 (defcustom nnmail-post-get-new-mail-hook nil
348 "Hook called just after finishing handling new incoming mail."
349 :group 'nnmail-retrieve
352 (defcustom nnmail-split-hook nil
353 "Hook called before deciding where to split an article.
354 The functions in this hook are free to modify the buffer
355 contents in any way they choose -- the buffer contents are
356 discarded after running the split process."
360 (defcustom nnmail-spool-hook nil
361 "*A hook called when a new article is spooled."
366 (defcustom nnmail-large-newsgroup 50
367 "*The number of articles which indicates a large newsgroup or nil.