1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995,96 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.
31 (eval-when-compile (require 'cl))
34 (defgroup gnus-mail nil
38 (defcustom nnmail-split-methods
40 "Incoming mail will be split according to this variable.
42 If you'd like, for instance, one mail group for mail from the
43 \"4ad-l\" mailing list, one group for junk mail and one for everything
44 else, you could do something like this:
46 (setq nnmail-split-methods
47 '((\"mail.4ad\" \"From:.*4ad\")
48 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
49 (\"mail.misc\" \"\")))
51 As you can see, this variable is a list of lists, where the first
52 element in each \"rule\" is the name of the group (which, by the way,
53 does not have to be called anything beginning with \"mail\",
54 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
55 nnmail will try to match on the header to find a fit.
57 The second element can also be a function. In that case, it will be
58 called narrowed to the headers with the first element of the rule as
59 the argument. It should return a non-nil value if it thinks that the
60 mail belongs in that group.
62 The last element should always have \"\" as the regexp.
64 This variable can also have a function as its value."
66 :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
67 (function-item nnmail-split-fancy)
68 (function :tag "Other")))
70 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
71 (defcustom nnmail-crosspost t
72 "If non-nil, do crossposting if several split methods match the mail.
73 If nil, the first match found will be used."
77 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
78 (defcustom nnmail-keep-last-article nil
79 "If non-nil, nnmail will never delete the last expired article in a directory.
80 You may need to set this variable if other programs are putting
81 new mail into folder numbers that Gnus has marked as expired."
85 (defcustom nnmail-use-long-file-names nil
86 "If non-nil the mail backends will use long file and directory names.
87 If nil, groups like \"mail.misc\" will end up in directories like
92 (defcustom nnmail-default-file-modes 384
93 "Set the mode bits of all new mail files to this integer."
97 (defcustom nnmail-expiry-wait 7
98 "*Expirable articles that are older than this will be expired.
99 This variable can either be a number (which will be interpreted as a
100 number of days) -- this doesn't have to be an integer. This variable
101 can also be `immediate' and `never'."
103 :type '(choice (const immediate)
104 (integer :tag "days")
107 (defcustom nnmail-expiry-wait-function nil
108 "Variable that holds function to specify how old articles should be before they are expired.
109 The function will be called with the name of the group that the
110 expiry is to be performed in, and it should return an integer that
111 says how many days an article can be stored before it is considered
112 \"old\". It can also return the values `never' and `immediate'.
116 \(setq nnmail-expiry-wait-function
118 (cond ((string-match \"private\" newsgroup) 31)
119 ((string-match \"junk\" newsgroup) 1)
120 ((string-match \"important\" newsgroup) 'never)
123 :type '(choice (const :tag "nnmail-expiry-wait" nil)
124 (function :format "%v" nnmail-)))
126 (defcustom nnmail-spool-file
128 (concat "/usr/spool/mail/" (user-login-name)))
129 "Where the mail backends will look for incoming mail.
130 This variable is \"/usr/spool/mail/$user\" by default.
131 If this variable is nil, no mail backends will read incoming mail.
132 If this variable is a list, all files mentioned in this list will be
133 used as incoming mailboxes.
134 If this variable is a directory (i. e., it's name ends with a \"/\"),
135 treat all files in that directory as incoming spool files."
139 (defcustom nnmail-crash-box "~/.gnus-crash-box"
140 "File where Gnus will store mail while processing it."
144 (defcustom nnmail-use-procmail nil
145 "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
146 The file(s) in `nnmail-spool-file' will also be read."
150 (defcustom nnmail-procmail-directory "~/incoming/"
151 "*When using procmail (and the like), incoming mail is put in this directory.
152 The Gnus mail backends will read the mail from this directory."
156 (defcustom nnmail-procmail-suffix "\\.spool"
157 "*Suffix of files created by procmail (and the like).
158 This variable might be a suffix-regexp to match the suffixes of
159 several files - eg. \".spool[0-9]*\"."
163 (defcustom nnmail-resplit-incoming nil
164 "*If non-nil, re-split incoming procmail sorted mail."
168 (defcustom nnmail-delete-file-function 'delete-file
169 "Function called to delete files in some mail backends."
173 (defcustom nnmail-crosspost-link-function 'add-name-to-file
174 "Function called to create a copy of a file.
175 This is `add-name-to-file' by default, which means that crossposts
176 will use hard links. If your file system doesn't allow hard
177 links, you could set this variable to `copy-file' instead."
179 :type '(radio (function-item add-name-to-file)
180 (function-item copy-file)
181 (function :tag "Other")))
183 (defcustom nnmail-movemail-program "movemail"
184 "*A command to be executed to move mail from the inbox.
185 The default is \"movemail\".
187 This can also be a function. In that case, the function will be
188 called with two parameters -- the name of the INBOX file, and the file
193 (defcustom nnmail-pop-password-required nil
194 "*Non-nil if a password is required when reading mail using POP."
198 (defcustom nnmail-read-incoming-hook
199 (if (eq system-type 'windows-nt)
200 '(nnheader-ms-strip-cr)
202 "Hook that will be run after the incoming mail has been transferred.
203 The incoming mail is moved from `nnmail-spool-file' (which normally is
204 something like \"/usr/spool/mail/$user\") to the user's home
205 directory. This hook is called after the incoming mail box has been
206 emptied, and can be used to call any mail box programs you have
207 running (\"xwatch\", etc.)
211 \(add-hook 'nnmail-read-incoming-hook
213 (start-process \"mailsend\" nil
214 \"/local/bin/mailsend\" \"read\" \"mbox\")))
216 If you have xwatch running, this will alert it that mail has been
219 If you use `display-time', you could use something like this:
221 \(add-hook 'nnmail-read-incoming-hook
223 ;; Update the displayed time, since that will clear out
224 ;; the flag that says you have mail.
225 (when (eq (process-status \"display-time\") 'run)
226 (display-time-filter display-time-process \"\"))))"
230 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
231 (defcustom nnmail-prepare-incoming-hook nil
232 "Hook called before treating incoming mail.
233 The hook is run in a buffer with all the new, incoming mail."
237 (defcustom nnmail-prepare-incoming-header-hook nil
238 "Hook called narrowed to the headers of each message.
239 This can be used to remove excessive spaces (and stuff like
240 that) from the headers before splitting and saving the messages."
244 (defcustom nnmail-prepare-incoming-message-hook nil
245 "Hook called narrowed to each message."
249 (defcustom nnmail-list-identifiers nil
250 "Regexp that match list identifiers to be removed.
251 This can also be a list of regexps."
253 :type '(choice regexp
256 (defcustom nnmail-pre-get-new-mail-hook nil
257 "Hook called just before starting to handle new incoming mail."
261 (defcustom nnmail-post-get-new-mail-hook nil
262 "Hook called just after finishing handling new incoming mail."
266 (defcustom nnmail-split-hook nil
267 "Hook called before deciding where to split an article.
268 The functions in this hook are free to modify the buffer
269 contents in any way they choose -- the buffer contents are
270 discarded after running the split process."
274 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
275 (defcustom nnmail-tmp-directory nil
276 "*If non-nil, use this directory for temporary storage when reading incoming mail."
278 :type '(choice (const :tag "default" nil)
279 (directory :format "%v")))
281 (defcustom nnmail-large-newsgroup 50
282 "*The number of the articles which indicates a large newsgroup.
283 If the number of the articles is greater than the value, verbose
284 messages will be shown to indicate the current status."
288 (defcustom nnmail-split-fancy "mail.misc"
289 "Incoming mail can be split according to this fancy variable.
290 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
292 The format is this variable is SPLIT, where SPLIT can be one of
295 GROUP: Mail will be stored in GROUP (a string).
297 \(FIELD VALUE SPLIT): If the message field FIELD (a regexp) contains
298 VALUE (a regexp), store the messages as specified by SPLIT.
300 \(| SPLIT...): Process each SPLIT expression until one of them matches.
301 A SPLIT expression is said to match if it will cause the mail
302 message to be stored in one or more groups.
304 \(& SPLIT...): Process each SPLIT expression.
306 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
307 the buffer containing the message headers. The return value FUNCTION
308 should be a split, which is then recursively processed.
310 FIELD must match a complete field name. VALUE must match a complete
311 word according to the `nnmail-split-fancy-syntax-table' syntax table.
312 You can use .* in the regexps to match partial field names or words.
314 FIELD and VALUE can also be lisp symbols, in that case they are expanded
315 as specified in `nnmail-split-abbrev-alist'.
317 GROUP can contain \\& and \\N which will substitute from matching
318 \\(\\) patterns in the previous VALUE.
322 \(setq nnmail-split-methods 'nnmail-split-fancy
324 ;; Messages from the mailer daemon are not crossposted to any of
325 ;; the ordinary groups. Warnings are put in a separate group
327 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
329 ;; Non-error messages are crossposted to all relevant
330 ;; groups, but we don't crosspost between the group for the
331 ;; (ding) list and the group for other (ding) related mail.
332 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
333 (\"subject\" \"ding\" \"ding.misc\"))
334 ;; Other mailing lists...
335 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
336 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
338 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
339 ;; Unmatched mail goes to the catch all group.
345 (defcustom nnmail-split-abbrev-alist
346 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
347 (mail . "mailer-daemon\\|postmaster\\|uucp"))
348 "Alist of abbreviations allowed in `nnmail-split-fancy'."
350 :type '(repeat (cons :format "%v" symbol regexp)))
352 (defcustom nnmail-delete-incoming nil
353 "*If non-nil, the mail backends will delete incoming files after
358 (defcustom nnmail-message-id-cache-length 1000
359 "*The approximate number of Message-IDs nnmail will keep in its cache.
360 If this variable is nil, no checking on duplicate messages will be
363 :type '(choice (const :tag "disable" nil)
364 (integer :format "%v")))
366 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
367 "*The file name of the nnmail Message-ID cache."
371 (defcustom nnmail-treat-duplicates 'warn
372 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
373 Three values are legal: nil, which means that nnmail is not to keep a
374 Message-ID cache; `warn', which means that nnmail should insert extra
375 headers to warn the user about the duplication (this is the default);
376 and `delete', which means that nnmail will delete duplicated mails.
378 This variable can also be a function. It will be called from a buffer
379 narrowed to the article in question with the Message-ID as a
380 parameter. It should return nil, `warn' or `delete'."
382 :type '(choice (const :tag "off" nil)
386 ;;; Internal variables.
388 (defvar nnmail-split-history nil
389 "List of group/article elements that say where the previous split put messages.")
391 (defvar nnmail-pop-password nil
392 "*Password to use when reading mail from a POP server, if required.")
394 (defvar nnmail-split-fancy-syntax-table nil
395 "Syntax table used by `nnmail-split-fancy'.")
396 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
397 (setq nnmail-split-fancy-syntax-table
398 (copy-syntax-table (standard-syntax-table)))
399 ;; support the %-hack
400 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
402 (defvar nnmail-prepare-save-mail-hook nil
403 "Hook called before saving mail.")
405 (defvar nnmail-moved-inboxes nil
406 "List of inboxes that have been moved.")
408 (defvar nnmail-internal-password nil)
412 (defconst nnmail-version "nnmail 1.0"
417 (defun nnmail-request-post (&optional server)
418 (mail-send-and-exit nil))
420 (defun nnmail-find-file (file)
421 "Insert FILE in server buffer safely."
422 (set-buffer nntp-server-buffer)
424 (let ((format-alist nil)
425 (after-insert-file-functions nil))
427 (progn (insert-file-contents file) t)
430 (defun nnmail-group-pathname (group dir &optional file)
431 "Make pathname for GROUP."
433 (let ((dir (file-name-as-directory (expand-file-name dir))))
434 ;; If this directory exists, we use it directly.
435 (if (or nnmail-use-long-file-names
436 (file-directory-p (concat dir group)))
437 (concat dir group "/")
438 ;; If not, we translate dots into slashes.
439 (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/")))
442 (defun nnmail-date-to-time (date)
443 "Convert DATE into time."
445 (let* ((d1 (timezone-parse-date date))
446 (t1 (timezone-parse-time (aref d1 3))))
449 (and el (string-to-number el)))
451 (aref t1 2) (aref t1 1) (aref t1 0)
452 (aref d1 2) (aref d1 1) (aref d1 0)
454 ;; If we get an error, then we just return a 0 time.
457 (defun nnmail-time-less (t1 t2)
458 "Say whether time T1 is less than time T2."
459 (or (< (car t1) (car t2))
460 (and (= (car t1) (car t2))
461 (< (nth 1 t1) (nth 1 t2)))))
463 (defun nnmail-days-to-time (days)
464 "Convert DAYS into time."
465 (let* ((seconds (* 1.0 days 60 60 24))
467 (ms (condition-case nil (round (/ seconds rest))
468 (range-error (expt 2 16)))))
469 (list ms (condition-case nil (round (- seconds (* ms rest)))
470 (range-error (expt 2 16))))))
472 (defun nnmail-time-since (time)
473 "Return the time since TIME, which is either an internal time or a date."
475 ;; Convert date strings to internal time.
476 (setq time (nnmail-date-to-time time)))
477 (let* ((current (current-time))
478 (rest (when (< (nth 1 current) (nth 1 time))
480 (list (- (+ (car current) (if rest -1 0)) (car time))
481 (- (+ (or rest 0) (nth 1 current)) (nth 1 time)))))
483 ;; Function rewritten from rmail.el.
484 (defun nnmail-move-inbox (inbox)
485 "Move INBOX to `nnmail-crash-box'."
486 (if (not (file-writable-p nnmail-crash-box))
487 (gnus-error 1 "Can't write to crash box %s. Not moving mail."
489 ;; If the crash box exists and is empty, we delete it.
490 (when (and (file-exists-p nnmail-crash-box)
491 (zerop (nnheader-file-size (file-truename nnmail-crash-box))))
492 (delete-file nnmail-crash-box))
493 (let ((inbox (file-truename (expand-file-name inbox)))
494 (tofile (file-truename (expand-file-name nnmail-crash-box)))
495 movemail popmail errors)
496 (if (setq popmail (string-match
497 "^po:" (file-name-nondirectory inbox)))
498 (setq inbox (file-name-nondirectory inbox))
500 ;; On some systems, /usr/spool/mail/foo is a directory
501 ;; and the actual inbox is /usr/spool/mail/foo/foo.
502 (when (file-directory-p inbox)
503 (setq inbox (expand-file-name (user-login-name) inbox))))
504 (if (member inbox nnmail-moved-inboxes)
505 ;; We don't try to move an already moved inbox.
509 (setq nnmail-internal-password nnmail-pop-password)
510 (when (and nnmail-pop-password-required
511 (not nnmail-pop-password))
512 (setq nnmail-internal-password
514 (format "Password for %s: "
515 (substring inbox (+ popmail 3))))))
516 (message "Getting mail from post office ..."))
517 (when (or (and (file-exists-p tofile)
518 (/= 0 (nnheader-file-size tofile)))
519 (and (file-exists-p inbox)
520 (/= 0 (nnheader-file-size inbox))))
521 (message "Getting mail from %s..." inbox)))
522 ;; Set TOFILE if have not already done so, and
523 ;; rename or copy the file INBOX to TOFILE if and as appropriate.
525 ((file-exists-p tofile)
526 ;; The crash box exists already.
529 (not (file-exists-p inbox)))
530 ;; There is no inbox.
533 ;; If getting from mail spool directory, use movemail to move
534 ;; rather than just renaming, so as to interlock with the
538 (setq errors (generate-new-buffer " *nnmail loss*"))
539 (buffer-disable-undo errors)
540 (let ((default-directory "/"))
541 (if (nnheader-functionp nnmail-movemail-program)
542 (funcall nnmail-movemail-program inbox tofile)
547 (expand-file-name nnmail-movemail-program
549 nil errors nil inbox tofile)
550 (when nnmail-internal-password
551 (list nnmail-internal-password))))))
552 (if (not (buffer-modified-p errors))
553 ;; No output => movemail won
556 (set-file-modes tofile nnmail-default-file-modes))
557 (push inbox nnmail-moved-inboxes))
559 ;; There may be a warning about older revisions. We
561 (goto-char (point-min))
562 (if (search-forward "older revision" nil t)
565 (set-file-modes tofile nnmail-default-file-modes))
566 (push inbox nnmail-moved-inboxes))
567 ;; Probably a real error.
568 (subst-char-in-region (point-min) (point-max) ?\n ?\ )
569 (goto-char (point-max))
570 (skip-chars-backward " \t")
571 (delete-region (point) (point-max))
572 (goto-char (point-min))
573 (when (looking-at "movemail: ")
574 (delete-region (point-min) (match-end 0)))
576 (format "movemail: %s. Continue? "
578 (error "%s" (buffer-string)))
579 (setq tofile nil)))))))
580 (message "Getting mail from %s...done" inbox)
583 (kill-buffer errors))
586 (defun nnmail-get-active ()
587 "Returns an assoc of group names and active ranges.
588 nn*-request-list should have been called before calling this function."
590 ;; Go through all groups from the active list.
592 (set-buffer nntp-server-buffer)
593 (goto-char (point-min))
594 (while (re-search-forward
595 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t)
596 ;; We create an alist with `(GROUP (LOW . HIGH))' elements.
597 (push (list (match-string 1)
598 (cons (string-to-int (match-string 3))
599 (string-to-int (match-string 2))))
603 (defun nnmail-save-active (group-assoc file-name)
604 "Save GROUP-ASSOC in ACTIVE-FILE."
606 (nnheader-temp-write file-name
607 (nnmail-generate-active group-assoc))))
609 (defun nnmail-generate-active (alist)
610 "Generate an active file from group-alist ALIST."
613 (while (setq group (pop alist))
614 (insert (format "%s %d %d y\n" (car group) (cdadr group)
617 (defun nnmail-get-split-group (file group)
618 "Find out whether this FILE is to be split into GROUP only.
619 If GROUP is non-nil and we are using procmail, return the group name
620 only when the file is the correct procmail file. When GROUP is nil,
621 return nil if FILE is a spool file or the procmail group for which it
622 is a spool. If not using procmail, return GROUP."
623 (if (or (eq nnmail-spool-file 'procmail)
625 (if (string-match (concat "^" (expand-file-name
626 (file-name-as-directory
627 nnmail-procmail-directory))
628 "\\([^/]*\\)" nnmail-procmail-suffix "$")
629 (expand-file-name file))
630 (let ((procmail-group (substring (expand-file-name file)
634 (if (string-equal group procmail-group)
641 (defun nnmail-process-babyl-mail-format (func artnum-func)
642 (let ((case-fold-search t)
643 start message-id content-length do-search end)
644 (goto-char (point-min))
647 "
\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
648 (goto-char (match-end 0))
649 (delete-region (match-beginning 0) (match-end 0))
653 ;; Skip all the headers in case there are more "From "s...
654 (or (search-forward "\n\n" nil t)
655 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
656 (search-forward "
\1f\f"))
658 (run-hooks 'nnmail-prepare-incoming-header-hook)
660 ;; Find the Message-ID header.
662 (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t)
663 (setq message-id (buffer-substring (match-beginning 1)
665 ;; There is no Message-ID here, so we create one.
667 (when (re-search-backward "^Message-ID:" nil t)
669 (insert "Original-")))
671 (insert "Message-ID: " (setq message-id (nnmail-message-id))
673 ;; Look for a Content-Length header.
674 (if (not (save-excursion
675 (and (re-search-backward
676 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
677 (setq content-length (string-to-int
681 ;; We destroy the header, since none of
682 ;; the backends ever use it, and we do not
683 ;; want to confuse other mailers by having
684 ;; a (possibly) faulty header.
685 (progn (insert "X-") t))))
687 (if (or (= (+ (point) content-length) (point-max))
689 (goto-char (+ (point) content-length))
692 (goto-char (+ (point) content-length))
693 (setq do-search nil))
695 ;; Go to the beginning of the next article - or to the end
698 (if (re-search-forward "^
\1f" nil t)
699 (goto-char (match-beginning 0))
700 (goto-char (1- (point-max)))))
701 (delete-char 1) ; delete ^_
704 (narrow-to-region start (point))
705 (goto-char (point-min))
706 (nnmail-check-duplication message-id func artnum-func)
707 (setq end (point-max))))
710 (defun nnmail-search-unix-mail-delim ()
711 "Put point at the beginning of the next Unix mbox message."
712 ;; Algorithm used to find the the next article in the
713 ;; brain-dead Unix mbox format:
715 ;; 1) Search for "^From ".
716 ;; 2) If we find it, then see whether the previous
717 ;; line is blank and the next line looks like a header.
718 ;; Then it's possible that this is a mail delim, and we use it.
719 (let ((case-fold-search nil)
722 (if (not (re-search-forward "^From " nil t))
726 (when (and (or (bobp)
729 (= (following-char) ?\n)))
732 (while (looking-at ">From ")
734 (looking-at "[^ \t:]+[ \t]*:")))
735 (setq found 'yes)))))
739 (defun nnmail-search-unix-mail-delim-backward ()
740 "Put point at the beginning of the current Unix mbox message."
741 ;; Algorithm used to find the the next article in the
742 ;; brain-dead Unix mbox format:
744 ;; 1) Search for "^From ".
745 ;; 2) If we find it, then see whether the previous
746 ;; line is blank and the next line looks like a header.
747 ;; Then it's possible that this is a mail delim, and we use it.
748 (let ((case-fold-search nil)
751 (if (not (re-search-backward "^From " nil t))
755 (when (and (or (bobp)
758 (= (following-char) ?\n)))
761 (while (looking-at ">From ")
763 (looking-at "[^ \t:]+[ \t]*:")))
764 (setq found 'yes)))))
768 (defun nnmail-process-unix-mail-format (func artnum-func)
769 (let ((case-fold-search t)
770 start message-id content-length end skip head-end)
771 (goto-char (point-min))
772 (if (not (and (re-search-forward "^From " nil t)
773 (goto-char (match-beginning 0))))
774 ;; Possibly wrong format?
775 (error "Error, unknown mail format! (Possibly corrupted.)")
776 ;; Carry on until the bitter end.
780 ;; Find the end of the head.
783 (if (search-forward "\n\n" nil t)
785 ;; This will never happen, but just to be on the safe side --
786 ;; if there is no head-body delimiter, we search a bit manually.
787 (while (and (looking-at "From \\|[^ \t]+:")
791 ;; Find the Message-ID header.
792 (goto-char (point-min))
793 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
794 (setq message-id (match-string 1))
796 (when (re-search-forward "^Message-ID:" nil t)
798 (insert "Original-")))
799 ;; There is no Message-ID here, so we create one.
801 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
802 ;; Look for a Content-Length header.
803 (goto-char (point-min))
804 (if (not (re-search-forward
805 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
806 (setq content-length nil)
807 (setq content-length (string-to-int (match-string 1)))
808 ;; We destroy the header, since none of the backends ever
809 ;; use it, and we do not want to confuse other mailers by
810 ;; having a (possibly) faulty header.
813 (run-hooks 'nnmail-prepare-incoming-header-hook)
814 ;; Find the end of this article.
815 (goto-char (point-max))
817 (setq head-end (point))
818 ;; We try the Content-Length value. The idea: skip over the header
819 ;; separator, then check what happens content-length bytes into the
820 ;; message body. This should be either the end ot the buffer, the
821 ;; message separator or a blank line followed by the separator.
822 ;; The blank line should probably be deleted. If neither of the
823 ;; three is met, the content-length header is probably invalid.
826 (setq skip (+ (point) content-length))
828 (cond ((or (= skip (point-max))
829 (= (1+ skip) (point-max)))
830 (setq end (point-max)))
831 ((looking-at "From ")
833 ((looking-at "[ \t]*\n\\(From \\)")
834 (setq end (match-beginning 1)))
838 ;; No Content-Length, so we find the beginning of the next
839 ;; article or the end of the buffer.
841 (or (nnmail-search-unix-mail-delim)
842 (goto-char (point-max))))
843 ;; Allow the backend to save the article.
846 (narrow-to-region start (point))
847 (goto-char (point-min))
848 (nnmail-check-duplication message-id func artnum-func)
849 (setq end (point-max))))
852 (defun nnmail-process-mmdf-mail-format (func artnum-func)
853 (let ((delim "^\^A\^A\^A\^A$")
855 start message-id end)
856 (goto-char (point-min))
857 (if (not (and (re-search-forward delim nil t)
859 ;; Possibly wrong format?
860 (error "Error, unknown mail format! (Possibly corrupted.)")
861 ;; Carry on until the bitter end.
864 ;; Find the end of the head.
867 (if (search-forward "\n\n" nil t)
869 ;; This will never happen, but just to be on the safe side --
870 ;; if there is no head-body delimiter, we search a bit manually.
871 (while (and (looking-at "From \\|[^ \t]+:")
875 ;; Find the Message-ID header.
876 (goto-char (point-min))
877 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
878 (setq message-id (match-string 1))
879 ;; There is no Message-ID here, so we create one.
881 (when (re-search-backward "^Message-ID:" nil t)
883 (insert "Original-")))
885 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
886 (run-hooks 'nnmail-prepare-incoming-header-hook)
887 ;; Find the end of this article.
888 (goto-char (point-max))
890 (if (re-search-forward delim nil t)
892 (goto-char (point-max)))
893 ;; Allow the backend to save the article.
896 (narrow-to-region start (point))
897 (goto-char (point-min))
898 (nnmail-check-duplication message-id func artnum-func)
899 (setq end (point-max))))
903 (defun nnmail-split-incoming (incoming func &optional exit-func
905 "Go through the entire INCOMING file and pick out each individual mail.
906 FUNC will be called with the buffer narrowed to each mail."
907 (let (;; If this is a group-specific split, we bind the split
908 ;; methods to just this group.
909 (nnmail-split-methods (if (and group
910 (or (eq nnmail-spool-file 'procmail)
912 (not nnmail-resplit-incoming))
913 (list (list group ""))
914 nnmail-split-methods)))
916 ;; Insert the incoming file.
917 (set-buffer (get-buffer-create " *nnmail incoming*"))
918 (buffer-disable-undo (current-buffer))
920 (nnheader-insert-file-contents incoming)
921 (unless (zerop (buffer-size))
922 (goto-char (point-min))
923 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
924 ;; Handle both babyl, MMDF and unix mail formats, since movemail will
925 ;; use the former when fetching from a mailbox, the latter when
926 ;; fetches from a file.
927 (cond ((or (looking-at "\^L")
928 (looking-at "BABYL OPTIONS:"))
929 (nnmail-process-babyl-mail-format func artnum-func))
930 ((looking-at "\^A\^A\^A\^A")
931 (nnmail-process-mmdf-mail-format func artnum-func))
933 (nnmail-process-unix-mail-format func artnum-func))))
936 (kill-buffer (current-buffer)))))
938 ;; Mail crossposts suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
939 (defun nnmail-article-group (func)
940 "Look at the headers and return an alist of groups that match.
941 FUNC will be called with the group name to determine the article number."
942 (let ((methods nnmail-split-methods)
943 (obuf (current-buffer))
945 end group-art method)
946 (if (and (sequencep methods) (= (length methods) 1))
947 ;; If there is only just one group to put everything in, we
948 ;; just return a list with just this one method in.
950 (list (cons (caar methods) (funcall func (caar methods)))))
951 ;; We do actual comparison.
955 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
956 (set-buffer nntp-server-buffer)
958 ;; Copy the headers into the work buffer.
959 (insert-buffer-substring obuf beg end)
960 ;; Fold continuation lines.
961 (goto-char (point-min))
962 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
963 (replace-match " " t t))
965 (run-hooks 'nnmail-split-hook)
966 (if (and (symbolp nnmail-split-methods)
967 (fboundp nnmail-split-methods))
970 (or (funcall nnmail-split-methods)
974 "Error in `nnmail-split-methods'; using `bogus' mail group")
977 (unless (equal split '(junk))
978 ;; `nnmail-split-methods' is a function, so we just call
979 ;; this function here and use the result.
982 (lambda (group) (cons group (funcall func group)))
984 ;; Go through the split methods to find a match.
985 (while (and methods (or nnmail-crosspost (not group-art)))
986 (goto-char (point-max))
987 (setq method (pop methods))
989 (not (equal "" (nth 1 method))))
992 (if (stringp (nth 1 method))
993 (re-search-backward (cadr method) nil t)
994 ;; Function to say whether this is a match.
995 (funcall (nth 1 method) (car method))))
996 ;; Don't enter the article into the same
998 (not (assoc (car method) group-art)))
999 (push (cons (car method) (funcall func (car method)))
1001 ;; This is the final group, which is used as a
1005 (list (cons (car method)
1006 (funcall func (car method)))))))))
1007 ;; See whether the split methods returned `junk'.
1008 (if (equal group-art '(junk))
1010 (nreverse (delq 'junk group-art)))))))
1012 (defun nnmail-insert-lines ()
1013 "Insert how many lines there are in the body of the mail.
1014 Return the number of characters in the body."
1017 (goto-char (point-min))
1018 (when (search-forward "\n\n" nil t)
1019 (setq chars (- (point-max) (point)))
1020 (setq lines (count-lines (point) (point-max)))
1023 (when (re-search-backward "^Lines: " nil t)
1024 (delete-region (point) (progn (forward-line 1) (point)))))
1026 (insert (format "Lines: %d\n" (max lines 0)))
1029 (defun nnmail-insert-xref (group-alist)
1030 "Insert an Xref line based on the (group . article) alist."
1032 (goto-char (point-min))
1033 (when (search-forward "\n\n" nil t)
1035 (when (re-search-backward "^Xref: " nil t)
1036 (delete-region (match-beginning 0)
1037 (progn (forward-line 1) (point))))
1038 (insert (format "Xref: %s" (system-name)))
1040 (insert (format " %s:%d" (caar group-alist) (cdar group-alist)))
1041 (setq group-alist (cdr group-alist)))
1044 ;;; Message washing functions
1046 (defun nnmail-remove-leading-whitespace ()
1047 "Remove excessive whitespace from all headers."
1048 (goto-char (point-min))
1049 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
1050 (replace-match "\\1" t)))
1052 (defun nnmail-remove-list-identifiers ()
1053 "Remove list identifiers from Subject headers."
1054 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
1055 (mapconcat 'identity nnmail-list-identifiers "\\|"))))
1057 (goto-char (point-min))
1058 (when (re-search-forward
1059 (concat "Subject: +\\(Re: +\\)?\\(" regexp "\\) *")
1061 (delete-region (match-beginning 2) (match-end 0))))))
1063 (defun nnmail-remove-tabs ()
1064 "Translate TAB characters into SPACE characters."
1065 (subst-char-in-region (point-min) (point-max) ?\t ? t))
1067 ;;; Utility functions
1069 ;; Written by byer@mv.us.adobe.com (Scott Byer).
1070 (defun nnmail-make-complex-temp-name (prefix)
1071 (let ((newname (make-temp-name prefix))
1073 (while (file-exists-p newname)
1074 (setq newprefix (concat newprefix "x"))
1075 (setq newname (make-temp-name newprefix)))
1078 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
1080 (defun nnmail-split-fancy ()
1081 "Fancy splitting method.
1082 See the documentation for the variable `nnmail-split-fancy' for documentation."
1083 (let ((syntab (syntax-table)))
1086 (set-syntax-table nnmail-split-fancy-syntax-table)
1087 (nnmail-split-it nnmail-split-fancy))
1088 (set-syntax-table syntab))))
1090 (defvar nnmail-split-cache nil)
1091 ;; Alist of split expressions their equivalent regexps.
1093 (defun nnmail-split-it (split)
1094 ;; Return a list of groups matching SPLIT.
1100 ;; A group name. Do the \& and \N subs into the string.
1102 (list (nnmail-expand-newtext split)))
1104 ;; Junk the message.
1108 ;; Builtin & operation.
1109 ((eq (car split) '&)
1110 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
1112 ;; Builtin | operation.
1113 ((eq (car split) '|)
1115 (while (and (not done) (cdr split))
1116 (setq split (cdr split)
1117 done (nnmail-split-it (car split))))
1120 ;; Builtin : operation.
1121 ((eq (car split) ':)
1122 (nnmail-split-it (eval (cdr split))))
1124 ;; Check the cache for the regexp for this split.
1125 ;; FIX FIX FIX could avoid calling assq twice here
1126 ((assq split nnmail-split-cache)
1127 (goto-char (point-max))
1128 ;; FIX FIX FIX problem with re-search-backward is that if you have
1129 ;; a split: (from "foo-\\(bar\\|baz\\)@gnus.org "mail.foo.\\1")
1130 ;; and someone mails a message with 'To: foo-bar@gnus.org' and
1131 ;; 'CC: foo-baz@gnus.org', we'll pick 'mail.foo.baz' as the group
1132 ;; if the cc line is a later header, even though the other choice
1133 ;; is probably better. Also, this routine won't do a crosspost
1134 ;; when there are two different matches.
1135 ;; I guess you could just make this more determined, and it could
1136 ;; look for still more matches prior to this one, and recurse
1137 ;; on each of the multiple matches hit. Of course, then you'd
1138 ;; want to make sure that nnmail-article-group or nnmail-split-fancy
1139 ;; removed duplicates, since there might be more of those.
1140 ;; I guess we could also remove duplicates in the & split case, since
1141 ;; that's the only thing that can introduce them.
1142 (when (re-search-backward (cdr (assq split nnmail-split-cache)) nil t)
1143 ;; Someone might want to do a \N sub on this match, so get the
1144 ;; correct match positions.
1145 (goto-char (match-end 0))
1146 (let ((value (nth 1 split)))
1147 (re-search-backward (if (symbolp value)
1148 (cdr (assq value nnmail-split-abbrev-alist))
1151 (nnmail-split-it (nth 2 split))))
1153 ;; Not in cache, compute a regexp for the field/value pair.
1155 (let* ((field (nth 0 split))
1156 (value (nth 1 split))
1157 (regexp (concat "^\\(\\("
1159 (cdr (assq field nnmail-split-abbrev-alist))
1163 (cdr (assq value nnmail-split-abbrev-alist))
1166 (push (cons split regexp) nnmail-split-cache)
1167 ;; Now that it's in the cache, just call nnmail-split-it again
1168 ;; on the same split, which will find it immediately in the cache.
1169 (nnmail-split-it split)))))
1171 (defun nnmail-expand-newtext (newtext)
1172 (let ((len (length newtext))
1174 c expanded beg N did-expand)
1177 (while (and (< pos len)
1178 (not (= (aref newtext pos) ?\\)))
1179 (setq pos (1+ pos)))
1181 (push (substring newtext beg pos) expanded))
1183 ;; we hit a \, expand it.
1186 (setq c (aref newtext pos))
1187 (if (not (or (= c ?\&)
1190 ;; \ followed by some character we don't expand
1191 (push (char-to-string c) expanded)
1196 (when (match-beginning N)
1197 (push (buffer-substring (match-beginning N) (match-end N))
1199 (setq pos (1+ pos)))
1201 (apply 'concat (nreverse expanded))
1204 ;; Get a list of spool files to read.
1205 (defun nnmail-get-spool-files (&optional group)
1206 (if (null nnmail-spool-file)
1207 ;; No spool file whatsoever.
1210 ;; If procmail is used to get incoming mail, the files
1211 ;; are stored in this directory.
1212 (and (file-exists-p nnmail-procmail-directory)
1213 (or (eq nnmail-spool-file 'procmail)
1214 nnmail-use-procmail)
1216 nnmail-procmail-directory
1217 t (concat (if group (concat "^" group) "")
1218 nnmail-procmail-suffix "$"))))
1220 (crash (when (and (file-exists-p nnmail-crash-box)
1221 (> (nnheader-file-size
1222 (file-truename nnmail-crash-box))
1224 (list nnmail-crash-box))))
1225 ;; Remove any directories that inadvertently match the procmail
1226 ;; suffix, which might happen if the suffix is "".
1228 (when (file-directory-p (car p))
1229 (setq procmails (delete (car p) procmails)))
1231 ;; Return the list of spools.
1235 (or (eq nnmail-spool-file 'procmail)
1236 nnmail-use-procmail)
1240 (eq nnmail-spool-file 'procmail))
1242 ((listp nnmail-spool-file)
1248 (if (file-directory-p file)
1249 (nnheader-directory-regular-files file)
1253 ((and (stringp nnmail-spool-file)
1254 (not (file-directory-p nnmail-spool-file)))
1255 (cons nnmail-spool-file procmails))
1256 ((and (stringp nnmail-spool-file)
1257 (file-directory-p nnmail-spool-file))
1259 (nnheader-directory-regular-files nnmail-spool-file)
1261 ((eq nnmail-spool-file 'pop)
1262 (cons (format "po:%s" (user-login-name)) procmails))
1266 ;; Activate a backend only if it isn't already activated.
1267 ;; If FORCE, re-read the active file even if the backend is
1268 ;; already activated.
1269 (defun nnmail-activate (backend &optional force)
1270 (let (file timestamp file-time)
1271 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
1273 (and (setq file (ignore-errors
1274 (symbol-value (intern (format "%s-active-file"
1276 (setq file-time (nth 5 (file-attributes file)))
1280 (symbol-value (intern
1281 (format "%s-active-timestamp"
1284 (not (consp timestamp))
1285 (equal timestamp '(0 0))
1286 (> (nth 0 file-time) (nth 0 timestamp))
1287 (and (= (nth 0 file-time) (nth 0 timestamp))
1288 (> (nth 1 file-time) (nth 1 timestamp))))))
1290 (or (eq timestamp 'none)
1291 (set (intern (format "%s-active-timestamp" backend))
1292 ;;; dmoore@ucsd.edu 25.10.96
1293 ;;; it's not always the case that current-time
1294 ;;; does correspond to changes in the file's time. So just compare
1295 ;;; the file's new time against its own previous time.
1299 (funcall (intern (format "%s-request-list" backend)))
1300 ;;; dmoore@ucsd.edu 25.10.96
1301 ;;; BACKEND-request-list already does this itself!
1302 ;;; (set (intern (format "%s-group-alist" backend))
1303 ;;; (nnmail-get-active))
1307 (defun nnmail-message-id ()
1308 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1311 ;;; nnmail duplicate handling
1314 (defvar nnmail-cache-buffer nil)
1316 (defun nnmail-cache-open ()
1317 (if (or (not nnmail-treat-duplicates)
1318 (and nnmail-cache-buffer
1319 (buffer-name nnmail-cache-buffer)))
1320 () ; The buffer is open.
1323 (setq nnmail-cache-buffer
1324 (get-buffer-create " *nnmail message-id cache*")))
1325 (buffer-disable-undo (current-buffer))
1326 (when (file-exists-p nnmail-message-id-cache-file)
1327 (nnheader-insert-file-contents nnmail-message-id-cache-file))
1328 (set-buffer-modified-p nil)
1331 (defun nnmail-cache-close ()
1332 (when (and nnmail-cache-buffer
1333 nnmail-treat-duplicates
1334 (buffer-name nnmail-cache-buffer)
1335 (buffer-modified-p nnmail-cache-buffer))
1337 (set-buffer nnmail-cache-buffer)
1338 ;; Weed out the excess number of Message-IDs.
1339 (goto-char (point-max))
1340 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
1343 (delete-region (point-min) (point))))
1345 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
1346 (make-directory (file-name-directory nnmail-message-id-cache-file)
1348 (nnmail-write-region (point-min) (point-max)
1349 nnmail-message-id-cache-file nil 'silent)
1350 (set-buffer-modified-p nil)
1351 (setq nnmail-cache-buffer nil)
1352 ;;(kill-buffer (current-buffer))
1355 (defun nnmail-cache-insert (id)
1356 (when nnmail-treat-duplicates
1358 (set-buffer nnmail-cache-buffer)
1359 (goto-char (point-max))
1362 (defun nnmail-cache-id-exists-p (id)
1363 (when nnmail-treat-duplicates
1365 (set-buffer nnmail-cache-buffer)
1366 (goto-char (point-max))
1367 (search-backward id nil t))))
1369 (defun nnmail-check-duplication (message-id func artnum-func)
1370 (run-hooks 'nnmail-prepare-incoming-message-hook)
1371 ;; If this is a duplicate message, then we do not save it.
1372 (let* ((duplication (nnmail-cache-id-exists-p message-id))
1373 (case-fold-search t)
1374 (action (when duplication
1376 ((memq nnmail-treat-duplicates '(warn delete))
1377 nnmail-treat-duplicates)
1378 ((nnheader-functionp nnmail-treat-duplicates)
1379 (funcall nnmail-treat-duplicates message-id))
1381 nnmail-treat-duplicates))))
1383 ;; Let the backend save the article (or not).
1386 (nnmail-cache-insert message-id)
1387 (funcall func (setq group-art
1388 (nreverse (nnmail-article-group artnum-func)))))
1389 ((eq action 'delete)
1390 (setq group-art nil))
1392 ;; We insert a warning.
1393 (let ((case-fold-search t)
1394 (newid (nnmail-message-id)))
1395 (goto-char (point-min))
1396 (when (re-search-forward "^message-id:" nil t)
1398 (insert "Original-"))
1401 "Message-ID: " newid "\n"
1402 "Gnus-Warning: This is a duplicate of message " message-id "\n")
1403 (nnmail-cache-insert newid)
1404 (funcall func (setq group-art
1405 (nreverse (nnmail-article-group artnum-func))))))
1407 (funcall func (setq group-art
1408 (nreverse (nnmail-article-group artnum-func))))))
1409 ;; Add the group-art list to the history list.
1411 (push group-art nnmail-split-history)
1412 (delete-region (point-min) (point-max)))))
1416 (defun nnmail-get-value (&rest args)
1417 (let ((sym (intern (apply 'format args))))
1419 (symbol-value sym))))
1421 (defun nnmail-get-new-mail (method exit-func temp
1422 &optional group spool-func)
1423 "Read new incoming mail."
1424 ;; Nix out the previous split history.
1426 (setq nnmail-split-history nil))
1427 (let* ((spools (nnmail-get-spool-files group))
1429 incoming incomings spool)
1430 (when (and (nnmail-get-value "%s-get-new-mail" method)
1432 ;; We first activate all the groups.
1433 (nnmail-activate method)
1434 ;; Allow the user to hook.
1435 (run-hooks 'nnmail-pre-get-new-mail-hook)
1436 ;; Open the message-id cache.
1438 ;; The we go through all the existing spool files and split the
1441 (setq spool (pop spools))
1442 ;; We read each spool file if either the spool is a POP-mail
1443 ;; spool, or the file exists. We can't check for the
1444 ;; existence of POPped mail.
1445 (when (or (string-match "^po:" spool)
1446 (and (file-exists-p spool)
1447 (> (nnheader-file-size (file-truename spool)) 0)))
1448 (nnheader-message 3 "%s: Reading incoming mail..." method)
1449 (when (and (nnmail-move-inbox spool)
1450 (file-exists-p nnmail-crash-box))
1451 ;; There is new mail. We first find out if all this mail
1452 ;; is supposed to go to some specific group.
1453 (setq group (nnmail-get-split-group spool group-in))
1454 ;; We split the mail
1455 (nnmail-split-incoming
1456 nnmail-crash-box (intern (format "%s-save-mail" method))
1457 spool-func group (intern (format "%s-active-number" method)))
1458 ;; Check whether the inbox is to be moved to the special tmp dir.
1460 (nnmail-make-complex-temp-name
1462 (if nnmail-tmp-directory
1464 (file-name-as-directory nnmail-tmp-directory)
1465 (file-name-nondirectory (concat temp "Incoming")))
1466 (concat temp "Incoming")))))
1467 (rename-file nnmail-crash-box incoming t)
1468 (push incoming incomings))))
1469 ;; If we did indeed read any incoming spools, we save all info.
1472 (nnmail-get-value "%s-group-alist" method)
1473 (nnmail-get-value "%s-active-file" method))
1475 (funcall exit-func))
1476 (run-hooks 'nnmail-read-incoming-hook)
1477 (nnheader-message 3 "%s: Reading incoming mail...done" method))
1478 ;; Close the message-id cache.
1479 (nnmail-cache-close)
1480 ;; Allow the user to hook.
1481 (run-hooks 'nnmail-post-get-new-mail-hook)
1482 ;; Delete all the temporary files.
1484 (setq incoming (pop incomings))
1485 (and nnmail-delete-incoming
1486 (file-exists-p incoming)
1487 (file-writable-p incoming)
1488 (delete-file incoming))))))
1490 (defun nnmail-expired-article-p (group time force &optional inhibit)
1491 "Say whether an article that is TIME old in GROUP should be expired."
1494 (let ((days (or (and nnmail-expiry-wait-function
1495 (funcall nnmail-expiry-wait-function group))
1496 nnmail-expiry-wait)))
1497 (cond ((or (eq days 'never)
1500 ;; This isn't an expirable group.
1502 ((eq days 'immediate)
1503 ;; We expire all articles on sight.
1505 ((equal time '(0 0))
1506 ;; This is an ange-ftp group, and we don't have any dates.
1509 (setq days (nnmail-days-to-time days))
1510 ;; Compare the time with the current time.
1511 (nnmail-time-less days (nnmail-time-since time)))))))
1513 (defvar nnmail-read-passwd nil)
1514 (defun nnmail-read-passwd (prompt &rest args)
1515 "Read a password using PROMPT.
1516 If ARGS, PROMPT is used as an argument to `format'."
1519 (apply 'format prompt args)
1521 (unless nnmail-read-passwd
1522 (if (load "passwd" t)
1523 (setq nnmail-read-passwd 'read-passwd)
1524 (autoload 'ange-ftp-read-passwd "ange-ftp")
1525 (setq nnmail-read-passwd 'ange-ftp-read-passwd)))
1526 (funcall nnmail-read-passwd prompt)))
1528 (defun nnmail-check-syntax ()
1529 "Check (and modify) the syntax of the message in the current buffer."
1531 (message-narrow-to-head)
1532 (let ((case-fold-search t))
1533 (unless (re-search-forward "^Message-ID:" nil t)
1534 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1536 (defun nnmail-write-region (start end filename &optional append visit lockname)
1537 "Do a `write-region', and then set the file modes."
1538 (write-region start end filename append visit lockname)
1539 (set-file-modes filename nnmail-default-file-modes))
1542 ;;; Status functions
1545 (defun nnmail-replace-status (name value)
1546 "Make status NAME and VALUE part of the current status line."
1548 (message-narrow-to-head)
1549 (let ((status (nnmail-decode-status)))
1550 (setq status (delq (member name status) status))
1552 (push (cons name value) status))
1553 (message-remove-header "status")
1554 (goto-char (point-max))
1555 (insert "Status: " (nnmail-encode-status status) "\n"))))
1557 (defun nnmail-decode-status ()
1558 "Return a status-value alist from STATUS."
1559 (goto-char (point-min))
1560 (when (re-search-forward "^Status: " nil t)
1561 (let (name value status)
1563 ;; Narrow to the status.
1566 (if (re-search-forward "^[^ \t]" nil t)
1569 ;; Go through all elements and add them to the list.
1570 (goto-char (point-min))
1571 (while (re-search-forward "[^ \t=]+" nil t)
1572 (setq name (match-string 0))
1573 (if (not (= (following-char) ?=))
1577 (if (not (= (following-char) ?\"))
1578 (if (not (looking-at "[^ \t]"))
1582 (setq value (match-string 0))
1583 (goto-char (match-end 0)))
1585 (setq value (read (current-buffer)))))
1586 (push (cons name value) status)))
1589 (defun nnmail-encode-status (status)
1590 "Return a status string from STATUS."
1595 (if (string-match "[ \t]" (cdr elem))
1596 (prin1-to-string (cdr elem))
1600 (defun nnmail-split-history ()
1601 "Generate an overview of where the last mail split put articles."
1603 (unless nnmail-split-history
1604 (error "No current split history"))
1605 (with-output-to-temp-buffer "*nnmail split history*"
1606 (let ((history nnmail-split-history)
1608 (while (setq elem (pop history))
1609 (princ (mapconcat (lambda (ga)
1610 (concat (car ga) ":" (int-to-string (cdr ga))))
1615 (defun nnmail-new-mail-p (group)
1616 "Say whether GROUP has new mail."
1617 (let ((his nnmail-split-history)
1620 (when (assoc group (pop his))
1625 (run-hooks 'nnmail-load-hook)
1629 ;;; nnmail.el ends here