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, 2010
5 ;; Free Software Foundation, Inc.
7 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; Keywords: news, mail
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; For Emacs <22.2 and XEmacs.
31 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (eval-when-compile (require 'cl))
35 (require 'gnus) ; for macro gnus-kill-buffer, at least
39 (require 'mail-source)
43 (autoload 'gnus-add-buffer "gnus")
44 (autoload 'gnus-kill-buffer "gnus")
47 "Reading mail with Gnus."
50 (defgroup nnmail-retrieve nil
51 "Retrieving new mail."
54 (defgroup nnmail-prepare nil
55 "Preparing (or mangling) new mail after retrieval."
58 (defgroup nnmail-duplicate nil
59 "Handling of duplicate mail messages."
62 (defgroup nnmail-split nil
63 "Organizing the incoming mail in folders."
66 (defgroup nnmail-files nil
71 (defgroup nnmail-expire nil
75 (defgroup nnmail-procmail nil
76 "Interfacing with procmail and other mail agents."
79 (defgroup nnmail-various nil
80 "Various mail options."
83 (defcustom nnmail-split-methods '(("mail.misc" ""))
84 "*Incoming mail will be split according to this variable.
86 If you'd like, for instance, one mail group for mail from the
87 \"4ad-l\" mailing list, one group for junk mail and one for everything
88 else, you could do something like this:
90 (setq nnmail-split-methods
91 '((\"mail.4ad\" \"From:.*4ad\")
92 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
93 (\"mail.misc\" \"\")))
95 As you can see, this variable is a list of lists, where the first
96 element in each \"rule\" is the name of the group (which, by the way,
97 does not have to be called anything beginning with \"mail\",
98 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
99 nnmail will try to match on the header to find a fit.
101 The second element can also be a function. In that case, it will be
102 called narrowed to the headers with the first element of the rule as
103 the argument. It should return a non-nil value if it thinks that the
104 mail belongs in that group.
106 The last element should always have \"\" as the regexp.
108 This variable can also have a function as its value, and it can
109 also have a fancy split method as its value. See
110 `nnmail-split-fancy' for an explanation of that syntax."
112 :type '(choice (repeat :tag "Alist" (group (string :tag "Name")
113 (choice regexp function)))
114 (function-item nnmail-split-fancy)
115 (function :tag "Other")))
117 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
118 (defcustom nnmail-crosspost t
119 "If non-nil, do crossposting if several split methods match the mail.
120 If nil, the first match found will be used."
124 (defcustom nnmail-split-fancy-with-parent-ignore-groups nil
125 "Regexp that matches group names to be ignored when applying `nnmail-split-fancy-with-parent'.
126 This can also be a list of regexps."
129 :type '(choice (const :tag "none" nil)
131 (repeat :value (".*") regexp)))
133 (defcustom nnmail-cache-ignore-groups nil
134 "Regexp that matches group names to be ignored when inserting message ids into the cache (`nnmail-cache-insert').
135 This can also be a list of regexps."
138 :type '(choice (const :tag "none" nil)
140 (repeat :value (".*") regexp)))
142 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
143 (defcustom nnmail-keep-last-article nil
144 "If non-nil, nnmail will never delete/move a group's last article.
145 It can be marked expirable, so it will be deleted when it is no longer last.
147 You may need to set this variable if other programs are putting
148 new mail into folder numbers that Gnus has marked as expired."
149 :group 'nnmail-procmail
150 :group 'nnmail-various
153 (defcustom nnmail-use-long-file-names nil
154 "If non-nil the mail backends will use long file and directory names.
155 If nil, groups like \"mail.misc\" will end up in directories like
160 (defcustom nnmail-default-file-modes 384
161 "Set the mode bits of all new mail files to this integer."
165 (defcustom nnmail-expiry-wait 7
166 "*Expirable articles that are older than this will be expired.
167 This variable can either be a number (which will be interpreted as a
168 number of days) -- this doesn't have to be an integer. This variable
169 can also be `immediate' and `never'."
170 :group 'nnmail-expire
171 :type '(choice (const immediate)
175 (defcustom nnmail-expiry-wait-function nil
176 "Variable that holds function to specify how old articles should be before they are expired.
177 The function will be called with the name of the group that the expiry
178 is to be performed in, and it should return an integer that says how
179 many days an article can be stored before it is considered \"old\".
180 It can also return the values `never' and `immediate'.
184 \(setq nnmail-expiry-wait-function
186 (cond ((string-match \"private\" newsgroup) 31)
187 ((string-match \"junk\" newsgroup) 1)
188 ((string-match \"important\" newsgroup) 'never)
190 :group 'nnmail-expire
191 :type '(choice (const :tag "nnmail-expiry-wait" nil)
192 (function :format "%v" nnmail-)))
194 (defcustom nnmail-expiry-target 'delete
195 "*Variable that says where expired messages should end up.
196 The default value is `delete' (which says to delete the messages),
197 but it can also be a string or a function. If it is a string, expired
198 messages end up in that group. If it is a function, the function is
199 called in a buffer narrowed to the message in question. The function
200 receives one argument, the name of the group the message comes from.
201 The return value should be `delete' or a group name (a string)."
203 :group 'nnmail-expire
204 :type '(choice (const delete)
208 (defcustom nnmail-fancy-expiry-targets nil
209 "Determine expiry target based on articles using fancy techniques.
211 This is a list of (\"HEADER\" \"REGEXP\" \"TARGET\") entries. If
212 `nnmail-expiry-target' is set to the function
213 `nnmail-fancy-expiry-target' and HEADER of the article matches REGEXP,
214 the message will be expired to a group determined by invoking
215 `format-time-string' with TARGET used as the format string and the
216 time extracted from the articles' Date header (if missing the current
219 In the special cases that HEADER is the symbol `to-from', the regexp
220 will try to match against both the From and the To header.
224 \(setq nnmail-fancy-expiry-targets
225 '((to-from \"boss\" \"nnfolder:Work\")
226 (\"Subject\" \"IMPORTANT\" \"nnfolder:IMPORTANT.%Y.%b\")
227 (\"from\" \".*\" \"nnfolder:Archive-%Y\")))
229 In this case, articles containing the string \"boss\" in the To or the
230 From header will be expired to the group \"nnfolder:Work\";
231 articles containing the string \"IMPORTANT\" in the Subject header will
232 be expired to the group \"nnfolder:IMPORTANT.YYYY.MMM\"; and
233 everything else will be expired to \"nnfolder:Archive-YYYY\"."
235 :group 'nnmail-expire
236 :type '(repeat (list (choice :tag "Match against"
237 (string :tag "Header")
240 (string :tag "Target group format string"))))
242 (defcustom nnmail-cache-accepted-message-ids nil
243 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache.
244 If non-nil, also update the cache when copy or move articles."
248 (make-obsolete-variable 'nnmail-spool-file 'mail-sources
249 "Gnus 5.9 (Emacs 22.1)")
250 ;; revision 5.29 / p0-85 / Gnus 5.9
251 ;; Variable removed in No Gnus v0.7
253 (defcustom nnmail-resplit-incoming nil
254 "*If non-nil, re-split incoming procmail sorted mail."
255 :group 'nnmail-procmail
258 (defcustom nnmail-scan-directory-mail-source-once nil
259 "*If non-nil, scan all incoming procmail sorted mails once.
260 It scans low-level sorted spools even when not required."
262 :group 'nnmail-procmail
265 (defcustom nnmail-delete-file-function 'delete-file
266 "Function called to delete files in some mail backends."
270 (defcustom nnmail-crosspost-link-function
271 (if (string-match "windows-nt" (symbol-name system-type))
274 "*Function called to create a copy of a file.
275 This is `add-name-to-file' by default, which means that crossposts
276 will use hard links. If your file system doesn't allow hard
277 links, you could set this variable to `copy-file' instead."
279 :type '(radio (function-item add-name-to-file)
280 (function-item copy-file)
281 (function :tag "Other")))
283 (defcustom nnmail-read-incoming-hook
284 (if (eq system-type 'windows-nt)
285 '(nnheader-ms-strip-cr)
287 "*Hook that will be run after the incoming mail has been transferred.
288 The incoming mail is moved from the specified spool file (which normally is
289 something like \"/usr/spool/mail/$user\") to the user's home
290 directory. This hook is called after the incoming mail box has been