1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
3 ;; Copyright (C) 1995-2015 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
27 (eval-when-compile (require 'cl))
29 (require 'gnus) ; for macro gnus-kill-buffer, at least
33 (require 'mail-source)
37 (autoload 'gnus-add-buffer "gnus")
38 (autoload 'gnus-kill-buffer "gnus")
40 (autoload 'mail-send-and-exit "sendmail" nil t))
43 "Reading mail with Gnus."
46 (defgroup nnmail-retrieve nil
47 "Retrieving new mail."
50 (defgroup nnmail-prepare nil
51 "Preparing (or mangling) new mail after retrieval."
54 (defgroup nnmail-duplicate nil
55 "Handling of duplicate mail messages."
58 (defgroup nnmail-split nil
59 "Organizing the incoming mail in folders."
62 (defgroup nnmail-files nil
67 (defgroup nnmail-expire nil
71 (defgroup nnmail-procmail nil
72 "Interfacing with procmail and other mail agents."
75 (defgroup nnmail-various nil
76 "Various mail options."
79 (defcustom nnmail-split-methods '(("mail.misc" ""))
80 "*Incoming mail will be split according to this variable.
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:
86 (setq nnmail-split-methods
87 '((\"mail.4ad\" \"From:.*4ad\")
88 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
89 (\"mail.misc\" \"\")))
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.
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.
102 The last element should always have \"\" as the regexp.
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."
108 :type '(choice (repeat :tag "Alist" (group (string :tag "Name")
109 (choice regexp function)))
110 (function-item nnmail-split-fancy)
111 (function :tag "Other")))
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."
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."
125 :type '(choice (const :tag "none" nil)
127 (repeat :value (".*") regexp)))
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."
134 :type '(choice (const :tag "none" nil)
136 (repeat :value (".*") regexp)))
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.
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
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
156 (defcustom nnmail-default-file-modes 384
157 "Set the mode bits of all new mail files to this integer."
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)
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'.
180 \(setq nnmail-expiry-wait-function
182 (cond ((string-match \"private\" newsgroup) 31)
183 ((string-match \"junk\" newsgroup) 1)
184 ((string-match \"important\" newsgroup) 'never)
186 :group 'nnmail-expire
187 :type '(choice (const :tag "nnmail-expiry-wait" nil)
188 (function :format "%v" nnmail-)))
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)."
199 :group 'nnmail-expire
200 :type '(choice (const delete)
204 (defcustom nnmail-fancy-expiry-targets nil
205 "Determine expiry target based on articles using fancy techniques.
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
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.
220 \(setq nnmail-fancy-expiry-targets
221 '((to-from \"boss\" \"nnfolder:Work\")
222 (\"Subject\" \"IMPORTANT\" \"nnfolder:IMPORTANT.%Y.%b\")
223 (\"from\" \".*\" \"nnfolder:Archive-%Y\")))
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\"."
231 :group 'nnmail-expire
232 :type '(repeat (list (choice :tag "Match against"
233 (string :tag "Header")
236 (string :tag "Target group format string"))))
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."
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
249 (defcustom nnmail-resplit-incoming nil
250 "*If non-nil, re-split incoming procmail sorted mail."
251 :group 'nnmail-procmail
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."
258 :group 'nnmail-procmail
261 (defcustom nnmail-delete-file-function 'delete-file
262 "Function called to delete files in some mail backends."
266 (defcustom nnmail-crosspost-link-function
267 (if (string-match "windows-nt" (symbol-name system-type))
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."
275 :type '(radio (function-item add-name-to-file)
276 (function-item copy-file)
277 (function :tag "Other")))
279 (defcustom nnmail-read-incoming-hook
280 (if (eq system-type 'windows-nt)
281 '(nnheader-ms-strip-cr)
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.)
292 \(add-hook 'nnmail-read-incoming-hook
294 (call-process \"/local/bin/mailsend\" nil nil nil
296 ;; The incoming mail box file.
297 (expand-file-name (user-login-name)
298 rmail-spool-directory))))
300 If you have xwatch running, this will alert it that mail has been
303 If you use `display-time', you could use something like this:
305 \(add-hook 'nnmail-read-incoming-hook
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
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
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