Update copyright year to 2015
[gnus] / lisp / nnmail.el
1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2
3 ;; Copyright (C) 1995-2015 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile (require 'cl))
28
29 (require 'gnus)                         ; for macro gnus-kill-buffer, at least
30 (require 'nnheader)
31 (require 'message)
32 (require 'gnus-util)
33 (require 'mail-source)
34 (require 'mm-util)
35 (require 'gnus-int)
36
37 (autoload 'gnus-add-buffer "gnus")
38 (autoload 'gnus-kill-buffer "gnus")
39 (eval-when-compile
40   (autoload 'mail-send-and-exit "sendmail" nil t))
41
42 (defgroup nnmail nil
43   "Reading mail with Gnus."
44   :group 'gnus)
45
46 (defgroup nnmail-retrieve nil
47   "Retrieving new mail."
48   :group 'nnmail)
49
50 (defgroup nnmail-prepare nil
51   "Preparing (or mangling) new mail after retrieval."
52   :group 'nnmail)
53
54 (defgroup nnmail-duplicate nil
55   "Handling of duplicate mail messages."
56   :group 'nnmail)
57
58 (defgroup nnmail-split nil
59   "Organizing the incoming mail in folders."
60   :group 'nnmail)
61
62 (defgroup nnmail-files nil
63   "Mail files."
64   :group 'gnus-files
65   :group 'nnmail)
66
67 (defgroup nnmail-expire nil
68   "Expiring old mail."
69   :group 'nnmail)
70
71 (defgroup nnmail-procmail nil
72   "Interfacing with procmail and other mail agents."
73   :group 'nnmail)
74
75 (defgroup nnmail-various nil
76   "Various mail options."
77   :group 'nnmail)
78
79 (defcustom nnmail-split-methods '(("mail.misc" ""))
80   "*Incoming mail will be split according to this variable.
81
82 If you'd like, for instance, one mail group for mail from the
83 \"4ad-l\" mailing list, one group for junk mail and one for everything
84 else, you could do something like this:
85
86  (setq nnmail-split-methods
87        '((\"mail.4ad\" \"From:.*4ad\")
88          (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
89          (\"mail.misc\" \"\")))
90
91 As you can see, this variable is a list of lists, where the first
92 element in each \"rule\" is the name of the group (which, by the way,
93 does not have to be called anything beginning with \"mail\",
94 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
95 nnmail will try to match on the header to find a fit.
96
97 The second element can also be a function.  In that case, it will be
98 called narrowed to the headers with the first element of the rule as
99 the argument.  It should return a non-nil value if it thinks that the
100 mail belongs in that group.
101
102 The last element should always have \"\" as the regexp.
103
104 This variable can also have a function as its value, and it can
105 also have a fancy split method as its value.  See
106 `nnmail-split-fancy' for an explanation of that syntax."
107   :group 'nnmail-split
108   :type '(choice (repeat :tag "Alist" (group (string :tag "Name")
109                                              (choice regexp function)))
110                  (function-item nnmail-split-fancy)
111                  (function :tag "Other")))
112
113 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
114 (defcustom nnmail-crosspost t
115   "If non-nil, do crossposting if several split methods match the mail.
116 If nil, the first match found will be used."
117   :group 'nnmail-split
118   :type 'boolean)
119
120 (defcustom nnmail-split-fancy-with-parent-ignore-groups nil
121   "Regexp that matches group names to be ignored when applying `nnmail-split-fancy-with-parent'.
122 This can also be a list of regexps."
123   :version "22.1"
124   :group 'nnmail-split
125   :type '(choice (const :tag "none" nil)
126                  (regexp :value ".*")
127                  (repeat :value (".*") regexp)))
128
129 (defcustom nnmail-cache-ignore-groups nil
130   "Regexp that matches group names to be ignored when inserting message ids into the cache (`nnmail-cache-insert').
131 This can also be a list of regexps."
132   :version "22.1"
133   :group 'nnmail-split
134   :type '(choice (const :tag "none" nil)
135                  (regexp :value ".*")
136                  (repeat :value (".*") regexp)))
137
138 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
139 (defcustom nnmail-keep-last-article nil
140   "If non-nil, nnmail will never delete/move a group's last article.
141 It can be marked expirable, so it will be deleted when it is no longer last.
142
143 You may need to set this variable if other programs are putting
144 new mail into folder numbers that Gnus has marked as expired."
145   :group 'nnmail-procmail
146   :group 'nnmail-various
147   :type 'boolean)
148
149 (defcustom nnmail-use-long-file-names nil
150   "If non-nil the mail backends will use long file and directory names.
151 If nil, groups like \"mail.misc\" will end up in directories like
152 \"mail/misc/\"."
153   :group 'nnmail-files
154   :type 'boolean)
155
156 (defcustom nnmail-default-file-modes 384
157   "Set the mode bits of all new mail files to this integer."
158   :group 'nnmail-files
159   :type 'integer)
160
161 (defcustom nnmail-expiry-wait 7
162   "*Expirable articles that are older than this will be expired.
163 This variable can either be a number (which will be interpreted as a
164 number of days) -- this doesn't have to be an integer.  This variable
165 can also be `immediate' and `never'."
166   :group 'nnmail-expire
167   :type '(choice (const immediate)
168                  (number :tag "days")
169                  (const never)))
170
171 (defcustom nnmail-expiry-wait-function nil
172   "Variable that holds function to specify how old articles should be before they are expired.
173 The function will be called with the name of the group that the expiry
174 is to be performed in, and it should return an integer that says how
175 many days an article can be stored before it is considered \"old\".
176 It can also return the values `never' and `immediate'.
177
178 E.g.:
179
180 \(setq nnmail-expiry-wait-function
181       (lambda (newsgroup)
182         (cond ((string-match \"private\" newsgroup) 31)
183               ((string-match \"junk\" newsgroup) 1)
184               ((string-match \"important\" newsgroup) 'never)
185               (t 7))))"
186   :group 'nnmail-expire
187   :type '(choice (const :tag "nnmail-expiry-wait" nil)
188                  (function :format "%v" nnmail-)))
189
190 (defcustom nnmail-expiry-target 'delete
191   "*Variable that says where expired messages should end up.
192 The default value is `delete' (which says to delete the messages),
193 but it can also be a string or a function.  If it is a string, expired
194 messages end up in that group.  If it is a function, the function is
195 called in a buffer narrowed to the message in question.  The function
196 receives one argument, the name of the group the message comes from.
197 The return value should be `delete' or a group name (a string)."
198   :version "21.1"
199   :group 'nnmail-expire
200   :type '(choice (const delete)
201                  function
202                  string))
203
204 (defcustom nnmail-fancy-expiry-targets nil
205   "Determine expiry target based on articles using fancy techniques.
206
207 This is a list of (\"HEADER\" \"REGEXP\" \"TARGET\") entries.  If
208 `nnmail-expiry-target' is set to the function
209 `nnmail-fancy-expiry-target' and HEADER of the article matches REGEXP,
210 the message will be expired to a group determined by invoking
211 `format-time-string' with TARGET used as the format string and the
212 time extracted from the articles' Date header (if missing the current
213 time is used).
214
215 In the special cases that HEADER is the symbol `to-from', the regexp
216 will try to match against both the From and the To header.
217
218 Example:
219
220 \(setq nnmail-fancy-expiry-targets
221       '((to-from \"boss\" \"nnfolder:Work\")
222         (\"Subject\" \"IMPORTANT\" \"nnfolder:IMPORTANT.%Y.%b\")
223         (\"from\" \".*\" \"nnfolder:Archive-%Y\")))
224
225 In this case, articles containing the string \"boss\" in the To or the
226 From header will be expired to the group \"nnfolder:Work\";
227 articles containing the string \"IMPORTANT\" in the Subject header will
228 be expired to the group \"nnfolder:IMPORTANT.YYYY.MMM\"; and
229 everything else will be expired to \"nnfolder:Archive-YYYY\"."
230   :version "22.1"
231   :group 'nnmail-expire
232   :type '(repeat (list (choice :tag "Match against"
233                                (string :tag "Header")
234                                (const to-from))
235                        regexp
236                        (string :tag "Target group format string"))))
237
238 (defcustom nnmail-cache-accepted-message-ids nil
239   "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache.
240 If non-nil, also update the cache when copy or move articles."
241   :group 'nnmail
242   :type 'boolean)
243
244 (make-obsolete-variable 'nnmail-spool-file 'mail-sources
245                         "Gnus 5.9 (Emacs 22.1)")
246 ;; revision 5.29 / p0-85 / Gnus 5.9
247 ;; Variable removed in No Gnus v0.7
248
249 (defcustom nnmail-resplit-incoming nil
250   "*If non-nil, re-split incoming procmail sorted mail."
251   :group 'nnmail-procmail
252   :type 'boolean)
253
254 (defcustom nnmail-scan-directory-mail-source-once nil
255   "*If non-nil, scan all incoming procmail sorted mails once.
256 It scans low-level sorted spools even when not required."
257   :version "21.1"
258   :group 'nnmail-procmail
259   :type 'boolean)
260
261 (defcustom nnmail-delete-file-function 'delete-file
262   "Function called to delete files in some mail backends."
263   :group 'nnmail-files
264   :type 'function)
265
266 (defcustom nnmail-crosspost-link-function
267   (if (string-match "windows-nt" (symbol-name system-type))
268       'copy-file
269     'add-name-to-file)
270   "*Function called to create a copy of a file.
271 This is `add-name-to-file' by default, which means that crossposts
272 will use hard links.  If your file system doesn't allow hard
273 links, you could set this variable to `copy-file' instead."
274   :group 'nnmail-files
275   :type '(radio (function-item add-name-to-file)
276                 (function-item copy-file)
277                 (function :tag "Other")))
278
279 (defcustom nnmail-read-incoming-hook
280   (if (eq system-type 'windows-nt)
281       '(nnheader-ms-strip-cr)
282     nil)
283   "*Hook that will be run after the incoming mail has been transferred.
284 The incoming mail is moved from the specified spool file (which normally is
285 something like \"/usr/spool/mail/$user\") to the user's home
286 directory.  This hook is called after the incoming mail box has been
287 emptied, and can be used to call any mail box programs you have
288 running (\"xwatch\", etc.)
289
290 E.g.:
291
292 \(add-hook 'nnmail-read-incoming-hook
293           (lambda ()
294             (call-process \"/local/bin/mailsend\" nil nil nil
295                           \"read\"
296                           ;; The incoming mail box file.
297                           (expand-file-name (user-login-name)
298                                             rmail-spool-directory))))
299
300 If you have xwatch running, this will alert it that mail has been
301 read.
302
303 If you use `display-time', you could use something like this:
304
305 \(add-hook 'nnmail-read-incoming-hook
306           (lambda ()
307             ;; Update the displayed time, since that will clear out
308             ;; the flag that says you have mail.
309             (when (eq (process-status \"display-time\") 'run)
310               (display-time-filter display-time-process \"\"))))"
311   :group 'nnmail-prepare
312   :type 'hook)
313
314 (defcustom nnmail-prepare-incoming-hook nil
315   "Hook called before treating incoming mail.
316 The hook is run in a buffer with all the new, incoming mail."
317   :group 'nnmail-prepare
318   :type 'hook)
319
320 (defcustom nnmail-prepare-incoming-header-hook nil
321   "Hook called narrowed to the headers of each message.
322 This can be used to remove excessive spaces (and stuff like
323 that) from the headers before splitting and saving the messages."
324   :group 'nnmail-prepare
325   :type 'hook)