1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
35 (autoload 'gnus-error "gnus-util"))
38 "Reading mail with Gnus."
41 (defgroup nnmail-retrieve nil
42 "Retrieving new mail."
45 (defgroup nnmail-prepare nil
46 "Preparing (or mangling) new mail after retrival."
49 (defgroup nnmail-duplicate nil
50 "Handling of duplicate mail messages."
53 (defgroup nnmail-split nil
54 "Organizing the incomming mail in folders."
57 (defgroup nnmail-files nil
62 (defgroup nnmail-expire nil
66 (defgroup nnmail-procmail nil
67 "Interfacing with procmail and other mail agents."
70 (defgroup nnmail-various nil
71 "Various mail options."
74 (defcustom nnmail-split-methods
76 "Incoming mail will be split according to this variable.
78 If you'd like, for instance, one mail group for mail from the
79 \"4ad-l\" mailing list, one group for junk mail and one for everything
80 else, you could do something like this:
82 (setq nnmail-split-methods
83 '((\"mail.4ad\" \"From:.*4ad\")
84 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
85 (\"mail.misc\" \"\")))
87 As you can see, this variable is a list of lists, where the first
88 element in each \"rule\" is the name of the group (which, by the way,
89 does not have to be called anything beginning with \"mail\",
90 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
91 nnmail will try to match on the header to find a fit.
93 The second element can also be a function. In that case, it will be
94 called narrowed to the headers with the first element of the rule as
95 the argument. It should return a non-nil value if it thinks that the
96 mail belongs in that group.
98 The last element should always have \"\" as the regexp.
100 This variable can also have a function as its value."
102 :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
103 (function-item nnmail-split-fancy)
104 (function :tag "Other")))
106 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
107 (defcustom nnmail-crosspost t
108 "If non-nil, do crossposting if several split methods match the mail.
109 If nil, the first match found will be used."
113 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
114 (defcustom nnmail-keep-last-article nil
115 "If non-nil, nnmail will never delete the last expired article in a directory.
116 You may need to set this variable if other programs are putting
117 new mail into folder numbers that Gnus has marked as expired."
118 :group 'nnmail-procmail
119 :group 'nnmail-various
122 (defcustom nnmail-use-long-file-names nil
123 "If non-nil the mail backends will use long file and directory names.
124 If nil, groups like \"mail.misc\" will end up in directories like
129 (defcustom nnmail-default-file-modes 384
130 "Set the mode bits of all new mail files to this integer."
134 (defcustom nnmail-expiry-wait 7
135 "*Expirable articles that are older than this will be expired.
136 This variable can either be a number (which will be interpreted as a
137 number of days) -- this doesn't have to be an integer. This variable
138 can also be `immediate' and `never'."
139 :group 'nnmail-expire
140 :type '(choice (const immediate)
141 (integer :tag "days")
144 (defcustom nnmail-expiry-wait-function nil
145 "Variable that holds function to specify how old articles should be before they are expired.
146 The function will be called with the name of the group that the
147 expiry is to be performed in, and it should return an integer that
148 says how many days an article can be stored before it is considered
149 \"old\". It can also return the values `never' and `immediate'.
153 \(setq nnmail-expiry-wait-function
155 (cond ((string-match \"private\" newsgroup) 31)
156 ((string-match \"junk\" newsgroup) 1)
157 ((string-match \"important\" newsgroup) 'never)
159 :group 'nnmail-expire
160 :type '(choice (const :tag "nnmail-expiry-wait" nil)
161 (function :format "%v" nnmail-)))
163 (defcustom nnmail-cache-accepted-message-ids nil
164 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache."
168 (defcustom nnmail-spool-file
170 (concat "/usr/spool/mail/" (user-login-name)))
171 "Where the mail backends will look for incoming mail.
172 This variable is \"/usr/spool/mail/$user\" by default.
173 If this variable is nil, no mail backends will read incoming mail.
174 If this variable is a list, all files mentioned in this list will be
175 used as incoming mailboxes.
176 If this variable is a directory (i. e., it's name ends with a \"/\"),
177 treat all files in that directory as incoming spool files."
181 (defcustom nnmail-crash-box "~/.gnus-crash-box"
182 "File where Gnus will store mail while processing it."
186 (defcustom nnmail-use-procmail nil
187 "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
188 The file(s) in `nnmail-spool-file' will also be read."
189 :group 'nnmail-procmail
192 (defcustom nnmail-procmail-directory "~/incoming/"
193 "*When using procmail (and the like), incoming mail is put in this directory.
194 The Gnus mail backends will read the mail from this directory."
195 :group 'nnmail-procmail
198 (defcustom nnmail-procmail-suffix "\\.spool"
199 "*Suffix of files created by procmail (and the like).
200 This variable might be a suffix-regexp to match the suffixes of
201 several files - eg. \".spool[0-9]*\"."
202 :group 'nnmail-procmail
205 (defcustom nnmail-resplit-incoming nil
206 "*If non-nil, re-split incoming procmail sorted mail."
207 :group 'nnmail-procmail
210 (defcustom nnmail-delete-file-function 'delete-file
211 "Function called to delete files in some mail backends."
215 (defcustom nnmail-crosspost-link-function
216 (if (string-match "windows-nt\\|emx" (format "%s" system-type))
219 "Function called to create a copy of a file.
220 This is `add-name-to-file' by default, which means that crossposts
221 will use hard links. If your file system doesn't allow hard
222 links, you could set this variable to `copy-file' instead."
224 :type '(radio (function-item add-name-to-file)
225 (function-item copy-file)
226 (function :tag "Other")))
228 (defcustom nnmail-movemail-program "movemail"
229 "*A command to be executed to move mail from the inbox.
230 The default is \"movemail\".
232 This can also be a function. In that case, the function will be
233 called with two parameters -- the name of the INBOX file, and the file
236 :group 'nnmail-retrieve
239 (defcustom nnmail-pop-password-required nil
240 "*Non-nil if a password is required when reading mail using POP."
241 :group 'nnmail-retrieve
244 (defcustom nnmail-read-incoming-hook
245 (if (eq system-type 'windows-nt)
246 '(nnheader-ms-strip-cr)
248 "Hook that will be run after the incoming mail has been transferred.
249 The incoming mail is moved from `nnmail-spool-file' (which normally is
250 something like \"/usr/spool/mail/$user\") to the user's home
251 directory. This hook is called after the incoming mail box has been
252 emptied, and can be used to call any mail box programs you have
253 running (\"xwatch\", etc.)
257 \(add-hook 'nnmail-read-incoming-hook
259 (start-process \"mailsend\" nil
260 \"/local/bin/mailsend\" \"read\" \"mbox\")))
262 If you have xwatch running, this will alert it that mail has been
265 If you use `display-time', you could use something like this:
267 \(add-hook 'nnmail-read-incoming-hook
269 ;; Update the displayed time, since that will clear out
270 ;; the flag that says you have mail.
271 (when (eq (process-status \"display-time\") 'run)
272 (display-time-filter display-time-process \"\"))))"
273 :group 'nnmail-prepare
276 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
277 (defcustom nnmail-prepare-incoming-hook nil
278 "Hook called before treating incoming mail.
279 The hook is run in a buffer with all the new, incoming mail."
280 :group 'nnmail-prepare
283 (defcustom nnmail-prepare-incoming-header-hook nil
284 "Hook called narrowed to the headers of each message.
285 This can be used to remove excessive spaces (and stuff like
286 that) from the headers before splitting and saving the messages."
287 :group 'nnmail-prepare
290 (defcustom nnmail-prepare-incoming-message-hook nil
291 "Hook called narrowed to each message."
292 :group 'nnmail-prepare
295 (defcustom nnmail-list-identifiers nil
296 "Regexp that matches list identifiers to be removed.
297 This can also be a list of regexps."
298 :group 'nnmail-prepare
299 :type '(choice (const :tag "none" nil)
303 (defcustom nnmail-pre-get-new-mail-hook nil
304 "Hook called just before starting to handle new incoming mail."
305 :group 'nnmail-retrieve
308 (defcustom nnmail-post-get-new-mail-hook nil
309 "Hook called just after finishing handling new incoming mail."
310 :group 'nnmail-retrieve
313 (defcustom nnmail-split-hook nil
314 "Hook called before deciding where to split an article.
315 The functions in this hook are free to modify the buffer
316 contents in any way they choose -- the buffer contents are
317 discarded after running the split process."
321 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
322 (defcustom nnmail-tmp-directory nil
323 "*If non-nil, use this directory for temporary storage.
324 Used when reading incoming mail."
326 :group 'nnmail-retrieve
327 :type '(choice (const :tag "default" nil)
328 (directory :format "%v")))
330 (defcustom nnmail-large-newsgroup 50
331 "*The number of the articles which indicates a large newsgroup.
332 If the number of the articles is greater than the value, verbose
333 messages will be shown to indicate the current status."
334 :group 'nnmail-various
337 (defcustom nnmail-split-fancy "mail.misc"
338 "Incoming mail can be split according to this fancy variable.
339 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
341 The format is this variable is SPLIT, where SPLIT can be one of
344 GROUP: Mail will be stored in GROUP (a string).
346 \(FIELD VALUE SPLIT): If the message field FIELD (a regexp) contains
347 VALUE (a regexp), store the messages as specified by SPLIT.
349 \(| SPLIT...): Process each SPLIT expression until one of them matches.
350 A SPLIT expression is said to match if it will cause the mail
351 message to be stored in one or more groups.
353 \(& SPLIT...): Process each SPLIT expression.
355 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
356 the buffer containing the message headers. The return value FUNCTION
357 should be a split, which is then recursively processed.
359 FIELD must match a complete field name. VALUE must match a complete
360 word according to the `nnmail-split-fancy-syntax-table' syntax table.
361 You can use \".*\" in the regexps to match partial field names or words.
363 FIELD and VALUE can also be lisp symbols, in that case they are expanded
364 as specified in `nnmail-split-abbrev-alist'.
366 GROUP can contain \\& and \\N which will substitute from matching
367 \\(\\) patterns in the previous VALUE.
371 \(setq nnmail-split-methods 'nnmail-split-fancy
373 ;; Messages from the mailer daemon are not crossposted to any of
374 ;; the ordinary groups. Warnings are put in a separate group
376 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
378 ;; Non-error messages are crossposted to all relevant
379 ;; groups, but we don't crosspost between the group for the
380 ;; (ding) list and the group for other (ding) related mail.
381 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
382 (\"subject\" \"ding\" \"ding.misc\"))
383 ;; Other mailing lists...
384 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
385 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
387 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
388 ;; Unmatched mail goes to the catch all group.
394 (defcustom nnmail-split-abbrev-alist
395 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
396 (mail . "mailer-daemon\\|postmaster\\|uucp")
397 (to . "to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
398 (from . "from\\|sender\\|resent-from"))
399 "Alist of abbreviations allowed in `nnmail-split-fancy'."
401 :type '(repeat (cons :format "%v" symbol regexp)))
403 (defcustom nnmail-delete-incoming t
404 "*If non-nil, the mail backends will delete incoming files after
406 :group 'nnmail-retrieve
409 (defcustom nnmail-message-id-cache-length 1000
410 "*The approximate number of Message-IDs nnmail will keep in its cache.
411 If this variable is nil, no checking on duplicate messages will be
413 :group 'nnmail-duplicate
414 :type '(choice (const :tag "disable" nil)
415 (integer :format "%v")))
417 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
418 "*The file name of the nnmail Message-ID cache."
419 :group 'nnmail-duplicate
423 (defcustom nnmail-treat-duplicates 'warn
424 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
425 Three values are legal: nil, which means that nnmail is not to keep a
426 Message-ID cache; `warn', which means that nnmail should insert extra
427 headers to warn the user about the duplication (this is the default);
428 and `delete', which means that nnmail will delete duplicated mails.
430 This variable can also be a function. It will be called from a buffer
431 narrowed to the article in question with the Message-ID as a
432 parameter. It should return nil, `warn' or `delete'."
433 :group 'nnmail-duplicate
434 :type '(choice (const :tag "off" nil)
438 ;;; Internal variables.
440 (defvar nnmail-split-history nil
441 "List of group/article elements that say where the previous split put messages.")
443 (defvar nnmail-pop-password nil
444 "*Password to use when reading mail from a POP server, if required.")
446 (defvar nnmail-split-fancy-syntax-table nil
447 "Syntax table used by `nnmail-split-fancy'.")
448 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
449 (setq nnmail-split-fancy-syntax-table
450 (copy-syntax-table (standard-syntax-table)))
451 ;; support the %-hack
452 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
454 (defvar nnmail-prepare-save-mail-hook nil
455 "Hook called before saving mail.")
457 (defvar nnmail-moved-inboxes nil
458 "List of inboxes that have been moved.")
460 (defvar nnmail-internal-password nil)
464 (defconst nnmail-version "nnmail 1.0"
469 (defun nnmail-request-post (&optional server)
470 (mail-send-and-exit nil))
472 (defun nnmail-find-file (file)
473 "Insert FILE in server buffer safely."
474 (set-buffer nntp-server-buffer)
476 (let ((format-alist nil)
477 (after-insert-file-functions nil))
479 (progn (insert-file-contents file) t)
482 (defun nnmail-group-pathname (group dir &optional file)
483 "Make pathname for GROUP."
485 (let ((dir (file-name-as-directory (expand-file-name dir))))
486 ;; If this directory exists, we use it directly.
487 (if (or nnmail-use-long-file-names
488 (file-directory-p (concat dir group)))
489 (concat dir group "/")
490 ;; If not, we translate dots into slashes.
491 (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/")))
494 (defun nnmail-date-to-time (date)
495 "Convert DATE into time."
497 (let* ((d1 (timezone-parse-date date))
498 (t1 (timezone-parse-time (aref d1 3))))
501 (and el (string-to-number el)))
503 (aref t1 2) (aref t1 1) (aref t1 0)
504 (aref d1 2) (aref d1 1) (aref d1 0)
506 (* 60 (timezone-zone-to-minute (aref d1 4))))))))
507 ;; If we get an error, then we just return a 0 time.
510 (defun nnmail-time-less (t1 t2)
511 "Say whether time T1 is less than time T2."
512 (or (< (car t1) (car t2))
513 (and (= (car t1) (car t2))
514 (< (nth 1 t1) (nth 1 t2)))))
516 (defun nnmail-days-to-time (days)
517 "Convert DAYS into time."
518 (let* ((seconds (* 1.0 days 60 60 24))
520 (ms (condition-case nil (round (/ seconds rest))
521 (range-error (expt 2 16)))))
522 (list ms (condition-case nil (round (- seconds (* ms rest)))
523 (range-error (expt 2 16))))))
525 (defun nnmail-time-since (time)
526 "Return the time since TIME, which is either an internal time or a date."
528 ;; Convert date strings to internal time.
529 (setq time (nnmail-date-to-time time)))
530 (let* ((current (current-time))
531 (rest (when (< (nth 1 current) (nth 1 time))
533 (list (- (+ (car current) (if rest -1 0)) (car time))
534 (- (+ (or rest 0) (nth 1 current)) (nth 1 time)))))
536 ;; Function rewritten from rmail.el.
537 (defun nnmail-move-inbox (inbox)
538 "Move INBOX to `nnmail-crash-box'."
539 (if (not (file-writable-p nnmail-crash-box))
540 (gnus-error 1 "Can't write to crash box %s. Not moving mail."
542 ;; If the crash box exists and is empty, we delete it.
543 (when (and (file-exists-p nnmail-crash-box)
544 (zerop (nnheader-file-size (file-truename nnmail-crash-box))))
545 (delete-file nnmail-crash-box))
546 (let ((inbox (file-truename (expand-file-name inbox)))
547 (tofile (file-truename (expand-file-name nnmail-crash-box)))
548 movemail popmail errors result)
549 (if (setq popmail (string-match
550 "^po:" (file-name-nondirectory inbox)))
551 (setq inbox (file-name-nondirectory inbox))
553 ;; On some systems, /usr/spool/mail/foo is a directory
554 ;; and the actual inbox is /usr/spool/mail/foo/foo.
555 (when (file-directory-p inbox)
556 (setq inbox (expand-file-name (user-login-name) inbox))))
557 (if (member inbox nnmail-moved-inboxes)
558 ;; We don't try to move an already moved inbox.
562 (when (and nnmail-pop-password
563 (not nnmail-internal-password))
564 (setq nnmail-internal-password nnmail-pop-password))
565 (when (and nnmail-pop-password-required
566 (not nnmail-internal-password))
567 (setq nnmail-internal-password
569 (format "Password for %s: "
570 (substring inbox (+ popmail 3))))))
571 (message "Getting mail from post office ..."))
572 (when (or (and (file-exists-p tofile)
573 (/= 0 (nnheader-file-size tofile)))
574 (and (file-exists-p inbox)
575 (/= 0 (nnheader-file-size inbox))))
576 (message "Getting mail from %s..." inbox)))
577 ;; Set TOFILE if have not already done so, and
578 ;; rename or copy the file INBOX to TOFILE if and as appropriate.
580 ((file-exists-p tofile)
581 ;; The crash box exists already.
584 (not (file-exists-p inbox)))
585 ;; There is no inbox.
588 ;; If getting from mail spool directory, use movemail to move
589 ;; rather than just renaming, so as to interlock with the
593 (setq errors (generate-new-buffer " *nnmail loss*"))
594 (buffer-disable-undo errors)
595 (let ((default-directory "/"))
596 (if (nnheader-functionp nnmail-movemail-program)
599 (funcall nnmail-movemail-program inbox tofile)
604 (insert (prin1-to-string err))
612 nnmail-movemail-program exec-directory)
613 nil errors nil inbox tofile)
614 (when nnmail-internal-password
615 (list nnmail-internal-password)))))))
616 (if (and (not (buffer-modified-p errors))
618 ;; No output => movemail won
621 (when (file-exists-p tofile)
622 (set-file-modes tofile nnmail-default-file-modes)))
623 (push inbox nnmail-moved-inboxes))
625 ;; There may be a warning about older revisions. We
627 (goto-char (point-min))
628 (if (search-forward "older revision" nil t)
631 (when (file-exists-p tofile)
632 (set-file-modes tofile nnmail-default-file-modes)))
633 (push inbox nnmail-moved-inboxes))
634 ;; Probably a real error.
635 (subst-char-in-region (point-min) (point-max) ?\n ?\ )
636 (goto-char (point-max))
637 (skip-chars-backward " \t")
638 (delete-region (point) (point-max))
639 (goto-char (point-min))
640 (when (looking-at "movemail: ")
641 (delete-region (point-min) (match-end 0)))
643 (format "movemail: %s (%d return). Continue? "
644 (buffer-string) result))
645 (error "%s" (buffer-string)))
646 (setq tofile nil)))))))
647 (message "Getting mail from %s...done" inbox)
650 (kill-buffer errors))
653 (defun nnmail-get-active ()
654 "Returns an assoc of group names and active ranges.
655 nn*-request-list should have been called before calling this function."
657 ;; Go through all groups from the active list.
659 (set-buffer nntp-server-buffer)
660 (goto-char (point-min))
661 (while (re-search-forward
662 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t)
663 ;; We create an alist with `(GROUP (LOW . HIGH))' elements.
664 (push (list (match-string 1)
665 (cons (string-to-int (match-string 3))
666 (string-to-int (match-string 2))))
670 (defun nnmail-save-active (group-assoc file-name)
671 "Save GROUP-ASSOC in ACTIVE-FILE."
673 (nnheader-temp-write file-name
674 (nnmail-generate-active group-assoc))))
676 (defun nnmail-generate-active (alist)
677 "Generate an active file from group-alist ALIST."
680 (while (setq group (pop alist))
681 (insert (format "%s %d %d y\n" (car group) (cdadr group)
684 (defun nnmail-get-split-group (file group)
685 "Find out whether this FILE is to be split into GROUP only.
686 If GROUP is non-nil and we are using procmail, return the group name
687 only when the file is the correct procmail file. When GROUP is nil,
688 return nil if FILE is a spool file or the procmail group for which it
689 is a spool. If not using procmail, return GROUP."
690 (if (or (eq nnmail-spool-file 'procmail)
692 (if (string-match (concat "^" (expand-file-name
693 (file-name-as-directory
694 nnmail-procmail-directory))
695 "\\([^/]*\\)" nnmail-procmail-suffix "$")
696 (expand-file-name file))
697 (let ((procmail-group (substring (expand-file-name file)
701 (if (string-equal group procmail-group)
708 (defun nnmail-process-babyl-mail-format (func artnum-func)
709 (let ((case-fold-search t)
710 start message-id content-length do-search end)
711 (goto-char (point-min))
714 "
\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
715 (goto-char (match-end 0))
716 (delete-region (match-beginning 0) (match-end 0))
720 ;; Skip all the headers in case there are more "From "s...
721 (or (search-forward "\n\n" nil t)
722 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
723 (search-forward "
\1f\f"))
725 ;; Unquote the ">From " line, if any.
726 (goto-char (point-min))
727 (when (looking-at ">From ")
728 (replace-match "X-From-Line: ") )
729 (run-hooks 'nnmail-prepare-incoming-header-hook)
730 (goto-char (point-max))
731 ;; Find the Message-ID header.
733 (if (re-search-backward
734 "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]*>\\)" nil t)
735 (setq message-id (buffer-substring (match-beginning 1)
737 ;; There is no Message-ID here, so we create one.
739 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
741 (insert "Original-")))
743 (insert "Message-ID: " (setq message-id (nnmail-message-id))
745 ;; Look for a Content-Length header.
746 (if (not (save-excursion
747 (and (re-search-backward
748 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
749 (setq content-length (string-to-int
753 ;; We destroy the header, since none of
754 ;; the backends ever use it, and we do not
755 ;; want to confuse other mailers by having
756 ;; a (possibly) faulty header.
757 (progn (insert "X-") t))))
760 (if (or (= (+ (point) content-length) (point-max))
762 (goto-char (+ (point) content-length))
765 (goto-char (+ (point) content-length))
766 (setq do-search nil))
769 ;; Go to the beginning of the next article - or to the end
772 (if (re-search-forward "^
\1f" nil t)
773 (goto-char (match-beginning 0))
774 (goto-char (1- (point-max)))))
775 (delete-char 1) ; delete ^_
778 (narrow-to-region start (point))
779 (goto-char (point-min))
780 (nnmail-check-duplication message-id func artnum-func)
781 (setq end (point-max))))
784 (defsubst nnmail-search-unix-mail-delim ()
785 "Put point at the beginning of the next Unix mbox message."
786 ;; Algorithm used to find the the next article in the
787 ;; brain-dead Unix mbox format:
789 ;; 1) Search for "^From ".
790 ;; 2) If we find it, then see whether the previous
791 ;; line is blank and the next line looks like a header.
792 ;; Then it's possible that this is a mail delim, and we use it.
793 (let ((case-fold-search nil)
796 (if (not (re-search-forward "^From " nil t))
800 (when (and (or (bobp)
803 (= (following-char) ?\n)))
806 (while (looking-at ">From ")
808 (looking-at "[^ \n\t:]+[ \n\t]*:")))
809 (setq found 'yes)))))
813 (defun nnmail-search-unix-mail-delim-backward ()
814 "Put point at the beginning of the current Unix mbox message."
815 ;; Algorithm used to find the the next article in the
816 ;; brain-dead Unix mbox format:
818 ;; 1) Search for "^From ".
819 ;; 2) If we find it, then see whether the previous
820 ;; line is blank and the next line looks like a header.
821 ;; Then it's possible that this is a mail delim, and we use it.
822 (let ((case-fold-search nil)
825 (if (not (re-search-backward "^From " nil t))
829 (when (and (or (bobp)
832 (= (following-char) ?\n)))
835 (while (looking-at ">From ")
837 (looking-at "[^ \n\t:]+[ \n\t]*:")))
838 (setq found 'yes)))))
842 (defun nnmail-process-unix-mail-format (func artnum-func)
843 (let ((case-fold-search t)
844 start message-id content-length end skip head-end)
845 (goto-char (point-min))
846 (if (not (and (re-search-forward "^From " nil t)
847 (goto-char (match-beginning 0))))
848 ;; Possibly wrong format?
849 (error "Error, unknown mail format! (Possibly corrupted.)")
850 ;; Carry on until the bitter end.
854 ;; Find the end of the head.
857 (if (search-forward "\n\n" nil t)
859 ;; This will never happen, but just to be on the safe side --
860 ;; if there is no head-body delimiter, we search a bit manually.
861 (while (and (looking-at "From \\|[^ \t]+:")
865 ;; Find the Message-ID header.
866 (goto-char (point-min))
867 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
868 (setq message-id (match-string 1))
870 (when (re-search-forward "^Message-ID[ \t]*:" nil t)
872 (insert "Original-")))
873 ;; There is no Message-ID here, so we create one.
875 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
876 ;; Look for a Content-Length header.
877 (goto-char (point-min))
878 (if (not (re-search-forward
879 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
880 (setq content-length nil)
881 (setq content-length (string-to-int (match-string 1)))
882 ;; We destroy the header, since none of the backends ever
883 ;; use it, and we do not want to confuse other mailers by
884 ;; having a (possibly) faulty header.
887 (run-hooks 'nnmail-prepare-incoming-header-hook)
888 ;; Find the end of this article.
889 (goto-char (point-max))
891 (setq head-end (point))
892 ;; We try the Content-Length value. The idea: skip over the header
893 ;; separator, then check what happens content-length bytes into the
894 ;; message body. This should be either the end ot the buffer, the
895 ;; message separator or a blank line followed by the separator.
896 ;; The blank line should probably be deleted. If neither of the
897 ;; three is met, the content-length header is probably invalid.
900 (setq skip (+ (point) content-length))
902 (cond ((or (= skip (point-max))
903 (= (1+ skip) (point-max)))
904 (setq end (point-max)))
905 ((looking-at "From ")
907 ((looking-at "[ \t]*\n\\(From \\)")
908 (setq end (match-beginning 1)))
912 ;; No Content-Length, so we find the beginning of the next
913 ;; article or the end of the buffer.
915 (or (nnmail-search-unix-mail-delim)
916 (goto-char (point-max))))
917 ;; Allow the backend to save the article.
920 (narrow-to-region start (point))
921 (goto-char (point-min))
922 (nnmail-check-duplication message-id func artnum-func)
923 (setq end (point-max))))
926 (defun nnmail-process-mmdf-mail-format (func artnum-func)
927 (let ((delim "^\^A\^A\^A\^A$")
929 start message-id end)
930 (goto-char (point-min))
931 (if (not (and (re-search-forward delim nil t)
933 ;; Possibly wrong format?
934 (error "Error, unknown mail format! (Possibly corrupted.)")
935 ;; Carry on until the bitter end.
938 ;; Find the end of the head.
941 (if (search-forward "\n\n" nil t)
943 ;; This will never happen, but just to be on the safe side --
944 ;; if there is no head-body delimiter, we search a bit manually.
945 (while (and (looking-at "From \\|[^ \t]+:")
949 ;; Find the Message-ID header.
950 (goto-char (point-min))
951 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
952 (setq message-id (match-string 1))
953 ;; There is no Message-ID here, so we create one.
955 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
957 (insert "Original-")))
959 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
960 (run-hooks 'nnmail-prepare-incoming-header-hook)
961 ;; Find the end of this article.
962 (goto-char (point-max))
964 (if (re-search-forward delim nil t)
966 (goto-char (point-max)))
967 ;; Allow the backend to save the article.
970 (narrow-to-region start (point))
971 (goto-char (point-min))
972 (nnmail-check-duplication message-id func artnum-func)
973 (setq end (point-max))))
977 (defun nnmail-split-incoming (incoming func &optional exit-func
979 "Go through the entire INCOMING file and pick out each individual mail.
980 FUNC will be called with the buffer narrowed to each mail."
981 (let (;; If this is a group-specific split, we bind the split
982 ;; methods to just this group.
983 (nnmail-split-methods (if (and group
984 (or (eq nnmail-spool-file 'procmail)
986 (not nnmail-resplit-incoming))
987 (list (list group ""))
988 nnmail-split-methods)))
990 ;; Insert the incoming file.
991 (set-buffer (get-buffer-create " *nnmail incoming*"))
992 (buffer-disable-undo (current-buffer))
994 (nnheader-insert-file-contents incoming)
995 (unless (zerop (buffer-size))
996 (goto-char (point-min))
997 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
998 ;; Handle both babyl, MMDF and unix mail formats, since movemail will
999 ;; use the former when fetching from a mailbox, the latter when
1000 ;; fetching from a file.
1001 (cond ((or (looking-at "\^L")
1002 (looking-at "BABYL OPTIONS:"))
1003 (nnmail-process-babyl-mail-format func artnum-func))
1004 ((looking-at "\^A\^A\^A\^A")
1005 (nnmail-process-mmdf-mail-format func artnum-func))
1007 (nnmail-process-unix-mail-format func artnum-func))))
1009 (funcall exit-func))
1010 (kill-buffer (current-buffer)))))
1012 ;; Mail crossposts suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1013 (defun nnmail-article-group (func)
1014 "Look at the headers and return an alist of groups that match.
1015 FUNC will be called with the group name to determine the article number."
1016 (let ((methods nnmail-split-methods)
1017 (obuf (current-buffer))
1019 end group-art method)
1020 (if (and (sequencep methods) (= (length methods) 1))
1021 ;; If there is only just one group to put everything in, we
1022 ;; just return a list with just this one method in.
1024 (list (cons (caar methods) (funcall func (caar methods)))))
1025 ;; We do actual comparison.
1029 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
1030 (set-buffer nntp-server-buffer)
1032 ;; Copy the headers into the work buffer.
1033 (insert-buffer-substring obuf beg end)
1034 ;; Fold continuation lines.
1035 (goto-char (point-min))
1036 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
1037 (replace-match " " t t))
1039 (run-hooks 'nnmail-split-hook)
1040 (if (and (symbolp nnmail-split-methods)
1041 (fboundp nnmail-split-methods))
1044 (or (funcall nnmail-split-methods)
1048 "Error in `nnmail-split-methods'; using `bogus' mail group")
1051 (unless (equal split '(junk))
1052 ;; `nnmail-split-methods' is a function, so we just call
1053 ;; this function here and use the result.
1056 (lambda (group) (cons group (funcall func group)))
1058 ;; Go through the split methods to find a match.
1059 (while (and methods (or nnmail-crosspost (not group-art)))
1060 (goto-char (point-max))
1061 (setq method (pop methods))
1063 (not (equal "" (nth 1 method))))
1066 (if (stringp (nth 1 method))
1067 (re-search-backward (cadr method) nil t)
1068 ;; Function to say whether this is a match.
1069 (funcall (nth 1 method) (car method))))
1070 ;; Don't enter the article into the same
1072 (not (assoc (car method) group-art)))
1073 (push (cons (car method) (funcall func (car method)))
1075 ;; This is the final group, which is used as a
1079 (list (cons (car method)
1080 (funcall func (car method)))))))))
1081 ;; See whether the split methods returned `junk'.
1082 (if (equal group-art '(junk))
1084 (nreverse (delq 'junk group-art)))))))
1086 (defun nnmail-insert-lines ()
1087 "Insert how many lines there are in the body of the mail.
1088 Return the number of characters in the body."
1091 (goto-char (point-min))
1092 (when (search-forward "\n\n" nil t)
1093 (setq chars (- (point-max) (point)))
1094 (setq lines (count-lines (point) (point-max)))
1097 (when (re-search-backward "^Lines: " nil t)
1098 (delete-region (point) (progn (forward-line 1) (point)))))
1100 (insert (format "Lines: %d\n" (max lines 0)))
1103 (defun nnmail-insert-xref (group-alist)
1104 "Insert an Xref line based on the (group . article) alist."
1106 (goto-char (point-min))
1107 (when (search-forward "\n\n" nil t)
1109 (when (re-search-backward "^Xref: " nil t)
1110 (delete-region (match-beginning 0)
1111 (progn (forward-line 1) (point))))
1112 (insert (format "Xref: %s" (system-name)))
1114 (insert (format " %s:%d" (caar group-alist) (cdar group-alist)))
1115 (setq group-alist (cdr group-alist)))
1118 ;;; Message washing functions
1120 (defun nnmail-remove-leading-whitespace ()
1121 "Remove excessive whitespace from all headers."
1122 (goto-char (point-min))
1123 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
1124 (replace-match "\\1" t)))
1126 (defun nnmail-remove-list-identifiers ()
1127 "Remove list identifiers from Subject headers."
1128 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
1129 (mapconcat 'identity nnmail-list-identifiers "\\|"))))
1131 (goto-char (point-min))
1132 (when (re-search-forward
1133 (concat "^Subject: +\\(Re: +\\)?\\(" regexp "\\) *")
1135 (delete-region (match-beginning 2) (match-end 0))))))
1137 (defun nnmail-remove-tabs ()
1138 "Translate TAB characters into SPACE characters."
1139 (subst-char-in-region (point-min) (point-max) ?\t ? t))
1141 ;;; Utility functions
1143 ;; Written by byer@mv.us.adobe.com (Scott Byer).
1144 (defun nnmail-make-complex-temp-name (prefix)
1145 (let ((newname (make-temp-name prefix))
1147 (while (file-exists-p newname)
1148 (setq newprefix (concat newprefix "x"))
1149 (setq newname (make-temp-name newprefix)))
1152 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
1154 (defun nnmail-split-fancy ()
1155 "Fancy splitting method.
1156 See the documentation for the variable `nnmail-split-fancy' for documentation."
1157 (let ((syntab (syntax-table)))
1160 (set-syntax-table nnmail-split-fancy-syntax-table)
1161 (nnmail-split-it nnmail-split-fancy))
1162 (set-syntax-table syntab))))
1164 (defvar nnmail-split-cache nil)
1165 ;; Alist of split expressions their equivalent regexps.
1167 (defun nnmail-split-it (split)
1168 ;; Return a list of groups matching SPLIT.
1174 ;; A group name. Do the \& and \N subs into the string.
1176 (list (nnmail-expand-newtext split)))
1178 ;; Junk the message.
1182 ;; Builtin & operation.
1183 ((eq (car split) '&)
1184 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
1186 ;; Builtin | operation.
1187 ((eq (car split) '|)
1189 (while (and (not done) (cdr split))
1190 (setq split (cdr split)
1191 done (nnmail-split-it (car split))))
1194 ;; Builtin : operation.
1195 ((eq (car split) ':)
1196 (nnmail-split-it (eval (cdr split))))
1198 ;; Check the cache for the regexp for this split.
1199 ;; FIX FIX FIX could avoid calling assq twice here
1200 ((assq split nnmail-split-cache)
1201 (goto-char (point-max))
1202 ;; FIX FIX FIX problem with re-search-backward is that if you have
1203 ;; a split: (from "foo-\\(bar\\|baz\\)@gnus.org "mail.foo.\\1")
1204 ;; and someone mails a message with 'To: foo-bar@gnus.org' and
1205 ;; 'CC: foo-baz@gnus.org', we'll pick 'mail.foo.baz' as the group
1206 ;; if the cc line is a later header, even though the other choice
1207 ;; is probably better. Also, this routine won't do a crosspost
1208 ;; when there are two different matches.
1209 ;; I guess you could just make this more determined, and it could
1210 ;; look for still more matches prior to this one, and recurse
1211 ;; on each of the multiple matches hit. Of course, then you'd
1212 ;; want to make sure that nnmail-article-group or nnmail-split-fancy
1213 ;; removed duplicates, since there might be more of those.
1214 ;; I guess we could also remove duplicates in the & split case, since
1215 ;; that's the only thing that can introduce them.
1216 (when (re-search-backward (cdr (assq split nnmail-split-cache)) nil t)
1217 ;; Someone might want to do a \N sub on this match, so get the
1218 ;; correct match positions.
1219 (goto-char (match-end 0))
1220 (let ((value (nth 1 split)))
1221 (re-search-backward (if (symbolp value)
1222 (cdr (assq value nnmail-split-abbrev-alist))
1225 (nnmail-split-it (nth 2 split))))
1227 ;; Not in cache, compute a regexp for the field/value pair.
1229 (let* ((field (nth 0 split))
1230 (value (nth 1 split))
1231 (regexp (concat "^\\(\\("
1233 (cdr (assq field nnmail-split-abbrev-alist))
1237 (cdr (assq value nnmail-split-abbrev-alist))
1240 (push (cons split regexp) nnmail-split-cache)
1241 ;; Now that it's in the cache, just call nnmail-split-it again
1242 ;; on the same split, which will find it immediately in the cache.
1243 (nnmail-split-it split)))))
1245 (defun nnmail-expand-newtext (newtext)
1246 (let ((len (length newtext))
1248 c expanded beg N did-expand)
1251 (while (and (< pos len)
1252 (not (= (aref newtext pos) ?\\)))
1253 (setq pos (1+ pos)))
1255 (push (substring newtext beg pos) expanded))
1257 ;; we hit a \, expand it.
1260 (setq c (aref newtext pos))
1261 (if (not (or (= c ?\&)
1264 ;; \ followed by some character we don't expand
1265 (push (char-to-string c) expanded)
1270 (when (match-beginning N)
1271 (push (buffer-substring (match-beginning N) (match-end N))
1273 (setq pos (1+ pos)))
1275 (apply 'concat (nreverse expanded))
1278 ;; Get a list of spool files to read.
1279 (defun nnmail-get-spool-files (&optional group)
1280 (if (null nnmail-spool-file)
1281 ;; No spool file whatsoever.
1284 ;; If procmail is used to get incoming mail, the files
1285 ;; are stored in this directory.
1286 (and (file-exists-p nnmail-procmail-directory)
1287 (or (eq nnmail-spool-file 'procmail)
1288 nnmail-use-procmail)
1290 nnmail-procmail-directory
1291 t (concat (if group (concat "^" group) "")
1292 nnmail-procmail-suffix "$"))))
1294 (crash (when (and (file-exists-p nnmail-crash-box)
1295 (> (nnheader-file-size
1296 (file-truename nnmail-crash-box))
1298 (list nnmail-crash-box))))
1299 ;; Remove any directories that inadvertently match the procmail
1300 ;; suffix, which might happen if the suffix is "".
1302 (when (file-directory-p (car p))
1303 (setq procmails (delete (car p) procmails)))
1305 ;; Return the list of spools.
1309 (or (eq nnmail-spool-file 'procmail)
1310 nnmail-use-procmail)
1314 (eq nnmail-spool-file 'procmail))
1316 ((listp nnmail-spool-file)
1322 (if (and (not (string-match "^po:" file))
1323 (file-directory-p file))
1324 (nnheader-directory-regular-files file)
1328 ((stringp nnmail-spool-file)
1329 (if (and (not (string-match "^po:" nnmail-spool-file))
1330 (file-directory-p nnmail-spool-file))
1332 (nnheader-directory-regular-files nnmail-spool-file)
1334 (cons nnmail-spool-file procmails)))
1335 ((eq nnmail-spool-file 'pop)
1336 (cons (format "po:%s" (user-login-name)) procmails))
1340 ;; Activate a backend only if it isn't already activated.
1341 ;; If FORCE, re-read the active file even if the backend is
1342 ;; already activated.
1343 (defun nnmail-activate (backend &optional force)
1344 (let (file timestamp file-time)
1345 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
1347 (and (setq file (ignore-errors
1348 (symbol-value (intern (format "%s-active-file"
1350 (setq file-time (nth 5 (file-attributes file)))
1354 (symbol-value (intern
1355 (format "%s-active-timestamp"
1358 (not (consp timestamp))
1359 (equal timestamp '(0 0))
1360 (> (nth 0 file-time) (nth 0 timestamp))
1361 (and (= (nth 0 file-time) (nth 0 timestamp))
1362 (> (nth 1 file-time) (nth 1 timestamp))))))
1364 (or (eq timestamp 'none)
1365 (set (intern (format "%s-active-timestamp" backend))
1367 (funcall (intern (format "%s-request-list" backend)))))
1370 (defun nnmail-message-id ()
1371 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1374 ;;; nnmail duplicate handling
1377 (defvar nnmail-cache-buffer nil)
1379 (defun nnmail-cache-open ()
1380 (if (or (not nnmail-treat-duplicates)
1381 (and nnmail-cache-buffer
1382 (buffer-name nnmail-cache-buffer)))
1383 () ; The buffer is open.
1386 (setq nnmail-cache-buffer
1387 (get-buffer-create " *nnmail message-id cache*")))
1388 (buffer-disable-undo (current-buffer))
1389 (when (file-exists-p nnmail-message-id-cache-file)
1390 (nnheader-insert-file-contents nnmail-message-id-cache-file))
1391 (set-buffer-modified-p nil)
1394 (defun nnmail-cache-close ()
1395 (when (and nnmail-cache-buffer
1396 nnmail-treat-duplicates
1397 (buffer-name nnmail-cache-buffer)
1398 (buffer-modified-p nnmail-cache-buffer))
1400 (set-buffer nnmail-cache-buffer)
1401 ;; Weed out the excess number of Message-IDs.
1402 (goto-char (point-max))
1403 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
1406 (delete-region (point-min) (point))))
1408 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
1409 (make-directory (file-name-directory nnmail-message-id-cache-file)
1411 (nnmail-write-region (point-min) (point-max)
1412 nnmail-message-id-cache-file nil 'silent)
1413 (set-buffer-modified-p nil)
1414 (setq nnmail-cache-buffer nil)
1415 (kill-buffer (current-buffer)))))
1417 (defun nnmail-cache-insert (id)
1418 (when nnmail-treat-duplicates
1419 (unless (buffer-live-p nnmail-cache-buffer)
1420 (nnmail-cache-open))
1422 (set-buffer nnmail-cache-buffer)
1423 (goto-char (point-max))
1426 (defun nnmail-cache-id-exists-p (id)
1427 (when nnmail-treat-duplicates
1429 (set-buffer nnmail-cache-buffer)
1430 (goto-char (point-max))
1431 (search-backward id nil t))))
1433 (defun nnmail-fetch-field (header)
1436 (message-narrow-to-head)
1437 (message-fetch-field header))))
1439 (defun nnmail-check-duplication (message-id func artnum-func)
1440 (run-hooks 'nnmail-prepare-incoming-message-hook)
1441 ;; If this is a duplicate message, then we do not save it.
1442 (let* ((duplication (nnmail-cache-id-exists-p message-id))
1443 (case-fold-search t)
1444 (action (when duplication
1446 ((memq nnmail-treat-duplicates '(warn delete))
1447 nnmail-treat-duplicates)
1448 ((nnheader-functionp nnmail-treat-duplicates)
1449 (funcall nnmail-treat-duplicates message-id))
1451 nnmail-treat-duplicates))))
1453 ;; Let the backend save the article (or not).
1456 (nnmail-cache-insert message-id)
1457 (funcall func (setq group-art
1458 (nreverse (nnmail-article-group artnum-func)))))
1459 ((eq action 'delete)
1460 (setq group-art nil))
1462 ;; We insert a warning.
1463 (let ((case-fold-search t))
1464 (goto-char (point-min))
1465 (re-search-forward "^message-id[ \t]*:" nil t)
1468 "Gnus-Warning: This is a duplicate of message " message-id "\n")
1469 (funcall func (setq group-art
1470 (nreverse (nnmail-article-group artnum-func))))))
1472 (funcall func (setq group-art
1473 (nreverse (nnmail-article-group artnum-func))))))
1474 ;; Add the group-art list to the history list.
1476 (push group-art nnmail-split-history)
1477 (delete-region (point-min) (point-max)))))
1481 (defun nnmail-get-value (&rest args)
1482 (let ((sym (intern (apply 'format args))))
1484 (symbol-value sym))))
1486 (defun nnmail-get-new-mail (method exit-func temp
1487 &optional group spool-func)
1488 "Read new incoming mail."
1489 ;; Nix out the previous split history.
1491 (setq nnmail-split-history nil))
1492 (let* ((spools (nnmail-get-spool-files group))
1494 incoming incomings spool)
1495 (when (and (nnmail-get-value "%s-get-new-mail" method)
1497 ;; We first activate all the groups.
1498 (nnmail-activate method)
1499 ;; Allow the user to hook.
1500 (run-hooks 'nnmail-pre-get-new-mail-hook)
1501 ;; Open the message-id cache.
1503 ;; The we go through all the existing spool files and split the
1506 (setq spool (pop spools))
1507 ;; We read each spool file if either the spool is a POP-mail
1508 ;; spool, or the file exists. We can't check for the
1509 ;; existence of POPped mail.
1510 (when (or (string-match "^po:" spool)
1511 (and (file-exists-p (file-truename spool))
1512 (> (nnheader-file-size (file-truename spool)) 0)))
1513 (nnheader-message 3 "%s: Reading incoming mail..." method)
1514 (when (and (nnmail-move-inbox spool)
1515 (file-exists-p nnmail-crash-box))
1516 ;; There is new mail. We first find out if all this mail
1517 ;; is supposed to go to some specific group.
1518 (setq group (nnmail-get-split-group spool group-in))
1519 ;; We split the mail
1520 (nnmail-split-incoming
1521 nnmail-crash-box (intern (format "%s-save-mail" method))
1522 spool-func group (intern (format "%s-active-number" method)))
1523 ;; Check whether the inbox is to be moved to the special tmp dir.
1525 (nnmail-make-complex-temp-name
1527 (if nnmail-tmp-directory
1529 (file-name-as-directory nnmail-tmp-directory)
1530 (file-name-nondirectory
1531 (concat (file-name-as-directory temp) "Incoming")))
1532 (concat (file-name-as-directory temp) "Incoming")))))
1533 (rename-file nnmail-crash-box incoming t)
1534 (push incoming incomings))))
1535 ;; If we did indeed read any incoming spools, we save all info.
1538 (nnmail-get-value "%s-group-alist" method)
1539 (nnmail-get-value "%s-active-file" method))
1541 (funcall exit-func))
1542 (run-hooks 'nnmail-read-incoming-hook)
1543 (nnheader-message 3 "%s: Reading incoming mail...done" method))
1544 ;; Close the message-id cache.
1545 (nnmail-cache-close)
1546 ;; Allow the user to hook.
1547 (run-hooks 'nnmail-post-get-new-mail-hook)
1548 ;; Delete all the temporary files.
1550 (setq incoming (pop incomings))
1551 (and nnmail-delete-incoming
1552 (file-exists-p incoming)
1553 (file-writable-p incoming)
1554 (delete-file incoming))))))
1556 (defun nnmail-expired-article-p (group time force &optional inhibit)
1557 "Say whether an article that is TIME old in GROUP should be expired."
1560 (let ((days (or (and nnmail-expiry-wait-function
1561 (funcall nnmail-expiry-wait-function group))
1562 nnmail-expiry-wait)))
1563 (cond ((or (eq days 'never)
1566 ;; This isn't an expirable group.
1568 ((eq days 'immediate)
1569 ;; We expire all articles on sight.
1571 ((equal time '(0 0))
1572 ;; This is an ange-ftp group, and we don't have any dates.
1575 (setq days (nnmail-days-to-time days))
1576 ;; Compare the time with the current time.
1577 (nnmail-time-less days (nnmail-time-since time)))))))
1579 (defvar nnmail-read-passwd nil)
1580 (defun nnmail-read-passwd (prompt &rest args)
1581 "Read a password using PROMPT.
1582 If ARGS, PROMPT is used as an argument to `format'."
1585 (apply 'format prompt args)
1587 (unless nnmail-read-passwd
1588 (if (load "passwd" t)
1589 (setq nnmail-read-passwd 'read-passwd)
1590 (unless (fboundp 'ange-ftp-read-passwd)
1591 (autoload 'ange-ftp-read-passwd "ange-ftp"))
1592 (setq nnmail-read-passwd 'ange-ftp-read-passwd)))
1593 (funcall nnmail-read-passwd prompt)))
1595 (defun nnmail-check-syntax ()
1596 "Check (and modify) the syntax of the message in the current buffer."
1598 (message-narrow-to-head)
1599 (let ((case-fold-search t))
1600 (unless (re-search-forward "^Message-ID[ \t]*:" nil t)
1601 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1603 (defun nnmail-write-region (start end filename &optional append visit lockname)
1604 "Do a `write-region', and then set the file modes."
1605 (write-region start end filename append visit lockname)
1606 (set-file-modes filename nnmail-default-file-modes))
1609 ;;; Status functions
1612 (defun nnmail-replace-status (name value)
1613 "Make status NAME and VALUE part of the current status line."
1615 (message-narrow-to-head)
1616 (let ((status (nnmail-decode-status)))
1617 (setq status (delq (member name status) status))
1619 (push (cons name value) status))
1620 (message-remove-header "status")
1621 (goto-char (point-max))
1622 (insert "Status: " (nnmail-encode-status status) "\n"))))
1624 (defun nnmail-decode-status ()
1625 "Return a status-value alist from STATUS."
1626 (goto-char (point-min))
1627 (when (re-search-forward "^Status: " nil t)
1628 (let (name value status)
1630 ;; Narrow to the status.
1633 (if (re-search-forward "^[^ \t]" nil t)
1636 ;; Go through all elements and add them to the list.
1637 (goto-char (point-min))
1638 (while (re-search-forward "[^ \t=]+" nil t)
1639 (setq name (match-string 0))
1640 (if (not (= (following-char) ?=))
1644 (if (not (= (following-char) ?\"))
1645 (if (not (looking-at "[^ \t]"))
1649 (setq value (match-string 0))
1650 (goto-char (match-end 0)))
1652 (setq value (read (current-buffer)))))
1653 (push (cons name value) status)))
1656 (defun nnmail-encode-status (status)
1657 "Return a status string from STATUS."
1662 (if (string-match "[ \t]" (cdr elem))
1663 (prin1-to-string (cdr elem))
1667 (defun nnmail-split-history ()
1668 "Generate an overview of where the last mail split put articles."
1670 (unless nnmail-split-history
1671 (error "No current split history"))
1672 (with-output-to-temp-buffer "*nnmail split history*"
1673 (let ((history nnmail-split-history)
1675 (while (setq elem (pop history))
1676 (princ (mapconcat (lambda (ga)
1677 (concat (car ga) ":" (int-to-string (cdr ga))))
1682 (defun nnmail-new-mail-p (group)
1683 "Say whether GROUP has new mail."
1684 (let ((his nnmail-split-history)
1687 (when (assoc group (pop his))
1693 (autoload 'pop3-movemail "pop3"))
1695 (defun nnmail-pop3-movemail (inbox crashbox)
1696 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
1697 (let ((pop3-maildrop
1698 (substring inbox (match-end (string-match "^po:" inbox)))))
1699 (pop3-movemail crashbox)))
1701 (run-hooks 'nnmail-load-hook)
1705 ;;; nnmail.el ends here