mm-util.el (gnus-completing-read): Autoload.
[gnus] / lisp / nnmail.el
1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2
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.
6
7 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; Keywords: news, mail
9
10 ;; This file is part of GNU Emacs.
11
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.
16
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.
21
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/>.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 ;; For Emacs <22.2 and XEmacs.
30 (eval-and-compile
31   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
32
33 (eval-when-compile (require 'cl))
34
35 (require 'gnus)                         ; for macro gnus-kill-buffer, at least
36 (require 'nnheader)
37 (require 'message)
38 (require 'gnus-util)
39 (require 'mail-source)
40 (require 'mm-util)
41 (require 'gnus-int)
42
43 (autoload 'gnus-add-buffer "gnus")
44 (autoload 'gnus-kill-buffer "gnus")
45
46 (defgroup nnmail nil
47   "Reading mail with Gnus."
48   :group 'gnus)
49
50 (defgroup nnmail-retrieve nil
51   "Retrieving new mail."
52   :group 'nnmail)
53
54 (defgroup nnmail-prepare nil
55   "Preparing (or mangling) new mail after retrieval."
56   :group 'nnmail)
57
58 (defgroup nnmail-duplicate nil
59   "Handling of duplicate mail messages."
60   :group 'nnmail)
61
62 (defgroup nnmail-split nil
63   "Organizing the incoming mail in folders."
64   :group 'nnmail)
65
66 (defgroup nnmail-files nil
67   "Mail files."
68   :group 'gnus-files
69   :group 'nnmail)
70
71 (defgroup nnmail-expire nil
72   "Expiring old mail."
73   :group 'nnmail)
74
75 (defgroup nnmail-procmail nil
76   "Interfacing with procmail and other mail agents."
77   :group 'nnmail)
78
79 (defgroup nnmail-various nil
80   "Various mail options."
81   :group 'nnmail)
82
83 (defcustom nnmail-split-methods '(("mail.misc" ""))
84   "*Incoming mail will be split according to this variable.
85
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:
89
90  (setq nnmail-split-methods
91        '((\"mail.4ad\" \"From:.*4ad\")
92          (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
93          (\"mail.misc\" \"\")))
94
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.
100
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.
105
106 The last element should always have \"\" as the regexp.
107
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."
111   :group 'nnmail-split
112   :type '(choice (repeat :tag "Alist" (group (string :tag "Name")
113                                              (choice regexp function)))
114                  (function-item nnmail-split-fancy)
115                  (function :tag "Other")))
116
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."
121   :group 'nnmail-split
122   :type 'boolean)
123
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."
127   :version "22.1"
128   :group 'nnmail-split
129   :type '(choice (const :tag "none" nil)
130                  (regexp :value ".*")
131                  (repeat :value (".*") regexp)))
132
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."
136   :version "22.1"
137   :group 'nnmail-split
138   :type '(choice (const :tag "none" nil)
139                  (regexp :value ".*")
140                  (repeat :value (".*") regexp)))
141
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.
146
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
151   :type 'boolean)
152
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
156 \"mail/misc/\"."
157   :group 'nnmail-files
158   :type 'boolean)
159
160 (defcustom nnmail-default-file-modes 384
161   "Set the mode bits of all new mail files to this integer."
162   :group 'nnmail-files
163   :type 'integer)
164
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)
172                  (number :tag "days")
173                  (const never)))
174
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'.
181
182 Eg.:
183
184 \(setq nnmail-expiry-wait-function
185       (lambda (newsgroup)
186         (cond ((string-match \"private\" newsgroup) 31)
187               ((string-match \"junk\" newsgroup) 1)
188               ((string-match \"important\" newsgroup) 'never)
189               (t 7))))"
190   :group 'nnmail-expire
191   :type '(choice (const :tag "nnmail-expiry-wait" nil)
192                  (function :format "%v" nnmail-)))
193
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)."
202   :version "21.1"
203   :group 'nnmail-expire
204   :type '(choice (const delete)
205                  function
206                  string))
207
208 (defcustom nnmail-fancy-expiry-targets nil
209   "Determine expiry target based on articles using fancy techniques.
210
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
217 time is used).
218
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.
221
222 Example:
223
224 \(setq nnmail-fancy-expiry-targets
225       '((to-from \"boss\" \"nnfolder:Work\")
226         (\"Subject\" \"IMPORTANT\" \"nnfolder:IMPORTANT.%Y.%b\")
227         (\"from\" \".*\" \"nnfolder:Archive-%Y\")))
228
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\"."
234   :version "22.1"
235   :group 'nnmail-expire
236   :type '(repeat (list (choice :tag "Match against"
237                                (string :tag "Header")
238                                (const to-from))
239                        regexp
240                        (string :tag "Target group format string"))))
241
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."
245   :group 'nnmail
246   :type 'boolean)
247
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
252
253 (defcustom nnmail-resplit-incoming nil
254   "*If non-nil, re-split incoming procmail sorted mail."
255   :group 'nnmail-procmail
256   :type 'boolean)
257
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."
261   :version "21.1"
262   :group 'nnmail-procmail
263   :type 'boolean)
264
265 (defcustom nnmail-delete-file-function 'delete-file
266   "Function called to delete files in some mail backends."
267   :group 'nnmail-files
268   :type 'function)
269
270 (defcustom nnmail-crosspost-link-function
271   (if (string-match "windows-nt" (symbol-name system-type))
272       'copy-file
273     'add-name-to-file)
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."
278   :group 'nnmail-files
279   :type '(radio (function-item add-name-to-file)
280                 (function-item copy-file)
281                 (function :tag "Other")))
282
283 (defcustom nnmail-read-incoming-hook
284   (if (eq system-type 'windows-nt)
285       '(nnheader-ms-strip-cr)
286     nil)
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