gnus-sum.el (gnus-summary-expire-articles): Reinstall improved version of the 2014...
[gnus] / lisp / nnmail.el
1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2
3 ;; Copyright (C) 1995-2014 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)
326
327 (defcustom nnmail-prepare-incoming-message-hook nil
328   "Hook called narrowed to each message."
329   :group 'nnmail-prepare
330   :type 'hook)
331
332 (defcustom nnmail-list-identifiers nil
333   "Regexp that matches list identifiers to be removed.
334 This can also be a list of regexps."
335   :group 'nnmail-prepare
336   :type '(choice (const :tag "none" nil)
337                  (regexp :value ".*")
338                  (repeat :value (".*") regexp)))
339
340 (defcustom nnmail-pre-get-new-mail-hook nil
341   "Hook called just before starting to handle new incoming mail."
342   :group 'nnmail-retrieve
343   :type 'hook)
344
345 (defcustom nnmail-post-get-new-mail-hook nil
346   "Hook called just after finishing handling new incoming mail."
347   :group 'nnmail-retrieve
348   :type 'hook)
349
350 (defcustom nnmail-split-hook nil
351   "Hook called before deciding where to split an article.
352 The functions in this hook are free to modify the buffer
353 contents in any way they choose -- the buffer contents are
354 discarded after running the split process."
355   :group 'nnmail-split
356   :type 'hook)
357
358 (defcustom nnmail-spool-hook nil
359   "*A hook called when a new article is spooled."
360   :version "22.1"
361   :group 'nnmail
362   :type 'hook)
363
364 (defcustom nnmail-large-newsgroup 50
365   "*The number of articles which indicates a large newsgroup or nil.
366 If the number of articles is greater than the value, verbose
367 messages will be shown to indicate the current status."
368   :group 'nnmail-various
369   :type '(choice (const :tag "infinite" nil)
370                  (number :tag "count")))
371
372 (define-widget 'nnmail-lazy 'default
373   "Base widget for recursive data structures.
374
375 This is copy of the `lazy' widget in Emacs 22.1 provided for compatibility."
376   :format "%{%t%}: %v"
377   :convert-widget 'widget-value-convert-widget
378   :value-create (lambda (widget)
379                   (let ((value (widget-get widget :value))
380                         (type (widget-get widget :type)))
381                     (widget-put widget :children
382                                 (list (widget-create-child-value
383                                        widget (widget-convert type) value)))))
384   :value-delete 'widget-children-value-delete
385   :value-get (lambda (widget)
386                (widget-value (car (widget-get widget :children))))
387   :value-inline (lambda (widget)
388                   (widget-apply (car (widget-get widget :children))
389                                 :value-inline))
390   :default-get (lambda (widget)
391                  (widget-default-get
392                   (widget-convert (widget-get widget :type))))
393   :match (lambda (widget value)
394            (widget-apply (widget-convert (widget-get widget :type))
395                          :match value))
396   :validate (lambda (widget)
397               (widget-apply (car (widget-get widget :children)) :validate)))
398
399 (define-widget 'nnmail-split-fancy 'nnmail-lazy
400   "Widget for customizing splits in the variable of the same name."
401   :tag "Split"
402   :type '(menu-choice :value (any ".*value.*" "misc")
403                       :tag "Type"
404                       (string :tag "Destination")
405                       (list :tag "Use first match (|)" :value (|)
406                             (const :format "" |)
407                             (editable-list :inline t nnmail-split-fancy))
408                       (list :tag "Use all matches (&)" :value (&)
409                             (const :format "" &)
410                             (editable-list :inline t nnmail-split-fancy))
411                       (list :tag "Function with fixed arguments (:)"
412                             :value (:)
413                             (const :format "" :value :)
414                             function
415                             (editable-list :inline t (sexp :tag "Arg"))
416                             )
417                       (list :tag "Function with split arguments (!)"
418                             :value (!)
419                             (const :format "" !)
420                             function
421                             (editable-list :inline t nnmail-split-fancy))
422                       (list :tag "Field match"
423                             (choice :tag "Field"
424                                     regexp symbol)
425                             (choice :tag "Match"
426                                     regexp
427                                     (symbol :value mail))
428                             (repeat :inline t
429                                     :tag "Restrictions"
430                                     (group :inline t
431                                            (const :format "" -)
432                                            regexp))
433                             nnmail-split-fancy)
434                       (const :tag "Junk (delete mail)" junk)))
435
436 (defcustom nnmail-split-fancy "mail.misc"
437   "Incoming mail can be split according to this fancy variable.
438 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
439
440 The format of this variable is SPLIT, where SPLIT can be one of
441 the following:
442
443 GROUP: Mail will be stored in GROUP (a string).
444
445 \(FIELD VALUE [- RESTRICT [- RESTRICT [...]]] SPLIT): If the message
446   field FIELD (a regexp) contains VALUE (a regexp), store the messages
447   as specified by SPLIT.  If RESTRICT (a regexp) matches some string
448   after FIELD and before the end of the matched VALUE, return nil,
449   otherwise process SPLIT.  Multiple RESTRICTs add up, further
450   restricting the possibility of processing SPLIT.
451
452 \(| SPLIT...): Process each SPLIT expression until one of them matches.
453   A SPLIT expression is said to match if it will cause the mail
454   message to be stored in one or more groups.
455
456 \(& SPLIT...): Process each SPLIT expression.
457
458 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
459   the buffer containing the message headers.  The return value FUNCTION
460   should be a split, which is then recursively processed.
461
462 \(! FUNCTION SPLIT): Call FUNCTION with the result of SPLIT.  The
463   return value FUNCTION should be a split, which is then recursively
464   processed.
465
466 junk: Mail will be deleted.  Use with care!  Do not submerge in water!
467   Example:
468   (setq nnmail-split-fancy
469         '(| (\"Subject\" \"MAKE MONEY FAST\" junk)
470             ...other.rules.omitted...))
471
472 FIELD must match a complete field name.  VALUE must match a complete
473 word according to the `nnmail-split-fancy-syntax-table' syntax table.
474 You can use \".*\" in the regexps to match partial field names or words.
475
476 FIELD and VALUE can also be Lisp symbols, in that case they are expanded
477 as specified in `nnmail-split-abbrev-alist'.
478
479 GROUP can contain \\& and \\N which will substitute from matching
480 \\(\\) patterns in the previous VALUE.
481
482 Example:
483
484 \(setq nnmail-split-methods 'nnmail-split-fancy
485       nnmail-split-fancy
486       ;; Messages from the mailer daemon are not crossposted to any of
487       ;; the ordinary groups.  Warnings are put in a separate group
488       ;; from real errors.
489       '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
490                           \"mail.misc\"))
491           ;; Non-error messages are crossposted to all relevant
492           ;; groups, but we don't crosspost between the group for the
493           ;; (ding) list and the group for other (ding) related mail.
494           (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
495                 (\"subject\" \"ding\" \"ding.misc\"))
496              ;; Other mailing lists...
497              (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
498              (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
499              ;; Both lists below have the same suffix, so prevent
500              ;; cross-posting to mkpkg.list of messages posted only to
501              ;; the bugs- list, but allow cross-posting when the
502              ;; message was really cross-posted.
503              (any \"bugs-mypackage@somewhere\" \"mypkg.bugs\")
504              (any \"mypackage@somewhere\" - \"bugs-mypackage\" \"mypkg.list\")
505              ;;
506              ;; People...
507              (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
508           ;; Unmatched mail goes to the catch all group.
509           \"misc.misc\"))"
510   :group 'nnmail-split
511   :type 'nnmail-split-fancy)
512
513 (defcustom nnmail-split-abbrev-alist
514   '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
515     (mail . "mailer-daemon\\|postmaster\\|uucp")
516     (to . "to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
517     (from . "from\\|sender\\|resent-from")
518     (nato . "to\\|cc\\|resent-to\\|resent-cc")
519     (naany . "from\\|to\\|cc\\|sender\\|resent-from\\|resent-to\\|resent-cc"))
520   "*Alist of abbreviations allowed in `nnmail-split-fancy'."
521   :group 'nnmail-split
522   :type '(repeat (cons :format "%v" symbol regexp)))
523
524 (defcustom nnmail-message-id-cache-length 1000
525   "*The approximate number of Message-IDs nnmail will keep in its cache.
526 If this variable is nil, no checking on duplicate messages will be
527 performed."
528   :group 'nnmail-duplicate
529   :type '(choice (const :tag "disable" nil)
530                  (integer :format "%v")))
531
532 (defcustom nnmail-message-id-cache-file
533   (nnheader-concat gnus-home-directory ".nnmail-cache")
534   "The file name of the nnmail Message-ID cache."
535   :group 'nnmail-duplicate
536   :group 'nnmail-files
537   :type 'file)
538
539 (defcustom nnmail-treat-duplicates 'warn
540   "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
541 Three values are valid: nil, which means that nnmail is not to keep a
542 Message-ID cache; `warn', which means that nnmail should insert extra
543 headers to warn the user about the duplication (this is the default);
544 and `delete', which means that nnmail will delete duplicated mails.
545
546 This variable can also be a function.  It will be called from a buffer
547 narrowed to the article in question with the Message-ID as a
548 parameter.  It should return nil, `warn' or `delete'."
549   :group 'nnmail-duplicate
550   :type '(choice (const :tag "off" nil)
551                  (const warn)
552                  (const delete)))
553
554 (defcustom nnmail-extra-headers '(To Newsgroups Cc)
555   "Extra headers to parse.
556 In addition to the standard headers, these extra headers will be
557 included in NOV headers (and the like) when backends parse headers."
558   :version "24.3"
559   :group 'nnmail
560   :type '(repeat symbol))
561
562 (defcustom nnmail-split-header-length-limit 2048
563   "Header lines longer than this limit are excluded from the split function."
564   :version "21.1"
565   :group 'nnmail
566   :type 'integer)
567
568 (defcustom nnmail-mail-splitting-charset nil
569   "Default charset to be used when splitting incoming mail."
570   :version "22.1"
571   :group 'nnmail
572   :type 'symbol)
573
574 (defcustom nnmail-mail-splitting-decodes nil
575   "Whether the nnmail splitting functionality should MIME decode headers."
576   :version "22.1"
577   :group 'nnmail
578   :type 'boolean)
579
580 (defcustom nnmail-split-fancy-match-partial-words nil
581   "Whether to match partial words when fancy splitting.
582 Normally, regexes given in `nnmail-split-fancy' are implicitly surrounded
583 by \"\\=\\<...\\>\".  If this variable is true, they are not implicitly\
584  surrounded
585 by anything."
586   :version "22.1"
587   :group 'nnmail
588   :type 'boolean)
589
590 (defcustom nnmail-split-lowercase-expanded t
591   "Whether to lowercase expanded entries (i.e. \\N) when splitting mails.
592 This avoids the creation of multiple groups when users send to an address
593 using different case (i.e. mailing-list@domain vs Mailing-List@Domain)."
594   :version "22.1"
595   :group 'nnmail
596   :type 'boolean)
597
598 ;;; Internal variables.
599
600 (defvar nnmail-article-buffer " *nnmail incoming*"
601   "The buffer used for splitting incoming mails.")
602
603 (defvar nnmail-split-history nil
604   "List of group/article elements that say where the previous split put messages.")
605
606 (defvar nnmail-split-fancy-syntax-table
607   (let ((table (make-syntax-table)))
608     ;; support the %-hack
609     (modify-syntax-entry ?\% "." table)
610     table)
611   "Syntax table used by `nnmail-split-fancy'.")
612
613 (defvar nnmail-prepare-save-mail-hook nil
614   "Hook called before saving mail.")
615
616 (defvar nnmail-split-tracing nil)
617 (defvar nnmail-split-trace nil)
618 (defvar nnmail-inhibit-default-split-group nil)
619
620 \f
621
622 (defun nnmail-request-post (&optional server)
623   (mail-send-and-exit nil))
624
625 (defvar nnmail-file-coding-system 'raw-text
626   "Coding system used in nnmail.")
627
628 (defvar nnmail-incoming-coding-system
629   mm-text-coding-system
630   "Coding system used in reading inbox")
631
632 (defvar nnmail-pathname-coding-system
633   ;; This causes Emacs 22.2 and 22.3 to issue a useless warning.
634   ;;(if (and (featurep 'xemacs) (featurep 'file-coding))
635   (if (featurep 'xemacs)
636       (if (featurep 'file-coding)
637           ;; Work around a bug in many XEmacs 21.5 betas.
638           ;; Cf. http://thread.gmane.org/gmane.emacs.gnus.general/68134
639           (setq file-name-coding-system (coding-system-aliasee 'file-name))))
640   "*Coding system for file name.")
641
642 (defun nnmail-find-file (file)
643   "Insert FILE in server buffer safely."
644   (set-buffer nntp-server-buffer)
645   (delete-region (point-min) (point-max))
646   (let ((format-alist nil)
647         (after-insert-file-functions nil))
648     (condition-case ()
649         (let ((coding-system-for-read nnmail-file-coding-system)
650               (auto-mode-alist (mm-auto-mode-alist))
651               (file-name-coding-system nnmail-pathname-coding-system))
652           (insert-file-contents file)
653           t)
654       (file-error nil))))
655
656 (defun nnmail-group-pathname (group dir &optional file)
657   "Make file name for GROUP."
658   (concat
659    (let ((dir (file-name-as-directory (expand-file-name dir))))
660      (setq group (nnheader-replace-duplicate-chars-in-string
661                   (nnheader-replace-chars-in-string group ?/ ?_)
662                   ?. ?_))
663      (setq group (nnheader-translate-file-chars group))
664      ;; If this directory exists, we use it directly.
665      (file-name-as-directory
666       (if (or nnmail-use-long-file-names
667               (file-directory-p (concat dir group)))
668           (expand-file-name group dir)
669         ;; If not, we translate dots into slashes.
670         (expand-file-name
671          (nnheader-replace-chars-in-string group ?. ?/)
672          dir))))
673    (or file "")))
674
675 (defun nnmail-get-active ()
676   "Returns an assoc of group names and active ranges.
677 nn*-request-list should have been called before calling this function."
678   ;; Go through all groups from the active list.
679   (with-current-buffer nntp-server-buffer
680     (nnmail-parse-active)))
681
682 (defun nnmail-parse-active ()
683   "Parse the active file in the current buffer and return an alist."
684   (goto-char (point-min))
685   (unless (re-search-forward "[\\\"]" nil t)
686     (goto-char (point-max))
687     (while (re-search-backward "[][';?()#]" nil t)
688       (insert ?\\)))
689   (goto-char (point-min))
690   (let ((buffer (current-buffer))
691         group-assoc group max min)
692     (while (not (eobp))
693       (condition-case err
694           (progn
695             (narrow-to-region (point) (point-at-eol))
696             (setq group (read buffer))
697             (unless (stringp group)
698               (setq group (symbol-name group)))
699             (if (and (numberp (setq max (read buffer)))
700                      (numberp (setq min (read buffer))))
701                 (push (list (mm-string-as-unibyte group) (cons min max))
702                       group-assoc)))
703         (error nil))
704       (widen)
705       (forward-line 1))
706     group-assoc))
707
708 (defvar nnmail-active-file-coding-system 'raw-text
709   "*Coding system for active file.")
710
711 (defun nnmail-save-active (group-assoc file-name)