1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
35 (require 'mail-source)
38 (autoload 'gnus-error "gnus-util")
39 (autoload 'gnus-buffer-live-p "gnus-util"))
41 (eval-when-compile (require 'static))
43 (static-condition-case nil
44 :symbol-for-testing-whether-colon-keyword-is-available-or-not
46 (defconst :user ':user)
47 (defconst :path ':path)
48 (defconst :predicate ':predicate)))
51 "Reading mail with Gnus."
54 (defgroup nnmail-retrieve nil
55 "Retrieving new mail."
58 (defgroup nnmail-prepare nil
59 "Preparing (or mangling) new mail after retrival."
62 (defgroup nnmail-duplicate nil
63 "Handling of duplicate mail messages."
66 (defgroup nnmail-split nil
67 "Organizing the incomming mail in folders."
70 (defgroup nnmail-files nil
75 (defgroup nnmail-expire nil
79 (defgroup nnmail-procmail nil
80 "Interfacing with procmail and other mail agents."
83 (defgroup nnmail-various nil
84 "Various mail options."
87 (defcustom nnmail-split-methods
89 "*Incoming mail will be split according to this variable.
91 If you'd like, for instance, one mail group for mail from the
92 \"4ad-l\" mailing list, one group for junk mail and one for everything
93 else, you could do something like this:
95 (setq nnmail-split-methods
96 '((\"mail.4ad\" \"From:.*4ad\")
97 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
98 (\"mail.misc\" \"\")))
100 As you can see, this variable is a list of lists, where the first
101 element in each \"rule\" is the name of the group (which, by the way,
102 does not have to be called anything beginning with \"mail\",
103 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
104 nnmail will try to match on the header to find a fit.
106 The second element can also be a function. In that case, it will be
107 called narrowed to the headers with the first element of the rule as
108 the argument. It should return a non-nil value if it thinks that the
109 mail belongs in that group.
111 The last element should always have \"\" as the regexp.
113 This variable can also have a function as its value."
115 :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
116 (function-item nnmail-split-fancy)
117 (function :tag "Other")))
119 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
120 (defcustom nnmail-crosspost t
121 "If non-nil, do crossposting if several split methods match the mail.
122 If nil, the first match found will be used."
126 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
127 (defcustom nnmail-keep-last-article nil
128 "If non-nil, nnmail will never delete/move a group's last article.
129 It can be marked expirable, so it will be deleted when it is no longer last.
131 You may need to set this variable if other programs are putting
132 new mail into folder numbers that Gnus has marked as expired."
133 :group 'nnmail-procmail
134 :group 'nnmail-various
137 (defcustom nnmail-use-long-file-names nil
138 "If non-nil the mail backends will use long file and directory names.
139 If nil, groups like \"mail.misc\" will end up in directories like
144 (defcustom nnmail-default-file-modes 384
145 "Set the mode bits of all new mail files to this integer."
149 (defcustom nnmail-expiry-wait 7
150 "*Expirable articles that are older than this will be expired.
151 This variable can either be a number (which will be interpreted as a
152 number of days) -- this doesn't have to be an integer. This variable
153 can also be `immediate' and `never'."
154 :group 'nnmail-expire
155 :type '(choice (const immediate)
156 (integer :tag "days")
159 (defcustom nnmail-expiry-wait-function nil
160 "Variable that holds function to specify how old articles should be before they are expired.
161 The function will be called with the name of the group that the
162 expiry is to be performed in, and it should return an integer that
163 says how many days an article can be stored before it is considered
164 \"old\". It can also return the values `never' and `immediate'.
168 \(setq nnmail-expiry-wait-function
170 (cond ((string-match \"private\" newsgroup) 31)
171 ((string-match \"junk\" newsgroup) 1)
172 ((string-match \"important\" newsgroup) 'never)
174 :group 'nnmail-expire
175 :type '(choice (const :tag "nnmail-expiry-wait" nil)
176 (function :format "%v" nnmail-)))
178 (defcustom nnmail-expiry-target 'delete
179 "*Variable that says where expired messages should end up."
180 :group 'nnmail-expire
181 :type '(choice (const delete)
182 (function :format "%v" nnmail-)
185 (defcustom nnmail-cache-accepted-message-ids nil
186 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache."
190 (defcustom nnmail-spool-file '((file))
191 "*Where the mail backends will look for incoming mail.
192 This variable is a list of mail source specifiers.
193 This variable is obsolete; `mail-sources' should be used instead."
197 (defcustom nnmail-resplit-incoming nil
198 "*If non-nil, re-split incoming procmail sorted mail."
199 :group 'nnmail-procmail
202 (defcustom nnmail-scan-directory-mail-source-once nil
203 "*If non-nil, scan all incoming procmail sorted mails once.
204 It scans low-level sorted spools even when not required."
205 :group 'nnmail-procmail
208 (defcustom nnmail-delete-file-function 'delete-file
209 "Function called to delete files in some mail backends."
213 (defcustom nnmail-crosspost-link-function
214 (if (string-match "windows-nt\\|emx" (symbol-name system-type))
217 "*Function called to create a copy of a file.
218 This is `add-name-to-file' by default, which means that crossposts
219 will use hard links. If your file system doesn't allow hard
220 links, you could set this variable to `copy-file' instead."
222 :type '(radio (function-item add-name-to-file)
223 (function-item copy-file)
224 (function :tag "Other")))
226 (defcustom nnmail-read-incoming-hook
227 (if (eq system-type 'windows-nt)
228 '(nnheader-ms-strip-cr)
230 "*Hook that will be run after the incoming mail has been transferred.
231 The incoming mail is moved from `nnmail-spool-file' (which normally is
232 something like \"/usr/spool/mail/$user\") to the user's home
233 directory. This hook is called after the incoming mail box has been
234 emptied, and can be used to call any mail box programs you have
235 running (\"xwatch\", etc.)
239 \(add-hook 'nnmail-read-incoming-hook
241 (start-process \"mailsend\" nil
242 \"/local/bin/mailsend\" \"read\" \"mbox\")))
244 If you have xwatch running, this will alert it that mail has been
247 If you use `display-time', you could use something like this:
249 \(add-hook 'nnmail-read-incoming-hook
251 ;; Update the displayed time, since that will clear out
252 ;; the flag that says you have mail.
253 (when (eq (process-status \"display-time\") 'run)
254 (display-time-filter display-time-process \"\"))))"
255 :group 'nnmail-prepare
258 (defcustom nnmail-prepare-incoming-hook nil
259 "Hook called before treating incoming mail.
260 The hook is run in a buffer with all the new, incoming mail."
261 :group 'nnmail-prepare
264 (defcustom nnmail-prepare-incoming-header-hook nil
265 "Hook called narrowed to the headers of each message.
266 This can be used to remove excessive spaces (and stuff like
267 that) from the headers before splitting and saving the messages."
268 :group 'nnmail-prepare
271 (defcustom nnmail-prepare-incoming-message-hook nil
272 "Hook called narrowed to each message."
273 :group 'nnmail-prepare
276 (defcustom nnmail-list-identifiers nil
277 "Regexp that matches list identifiers to be removed.
278 This can also be a list of regexps."
279 :group 'nnmail-prepare
280 :type '(choice (const :tag "none" nil)
282 (repeat :value (".*") regexp)))
284 (defcustom nnmail-pre-get-new-mail-hook nil
285 "Hook called just before starting to handle new incoming mail."
286 :group 'nnmail-retrieve
289 (defcustom nnmail-post-get-new-mail-hook nil
290 "Hook called just after finishing handling new incoming mail."
291 :group 'nnmail-retrieve
294 (defcustom nnmail-split-hook nil
295 "Hook called before deciding where to split an article.
296 The functions in this hook are free to modify the buffer
297 contents in any way they choose -- the buffer contents are
298 discarded after running the split process."
302 (defcustom nnmail-large-newsgroup 50
303 "*The number of the articles which indicates a large newsgroup.
304 If the number of the articles is greater than the value, verbose
305 messages will be shown to indicate the current status."
306 :group 'nnmail-various
309 (defcustom nnmail-split-fancy "mail.misc"
310 "Incoming mail can be split according to this fancy variable.
311 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
313 The format of this variable is SPLIT, where SPLIT can be one of
316 GROUP: Mail will be stored in GROUP (a string).
318 \(FIELD VALUE [- RESTRICT [- RESTRICT [...]]] SPLIT): If the message
319 field FIELD (a regexp) contains VALUE (a regexp), store the messages
320 as specified by SPLIT. If RESTRICT (a regexp) matches some string
321 after FIELD and before the end of the matched VALUE, return NIL,
322 otherwise process SPLIT. Multiple RESTRICTs add up, further
323 restricting the possibility of processing SPLIT.
325 \(| SPLIT...): Process each SPLIT expression until one of them matches.
326 A SPLIT expression is said to match if it will cause the mail
327 message to be stored in one or more groups.
329 \(& SPLIT...): Process each SPLIT expression.
331 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
332 the buffer containing the message headers. The return value FUNCTION
333 should be a split, which is then recursively processed.
335 \(! FUNCTION SPLIT): Call FUNCTION with the result of SPLIT. The
336 return value FUNCTION should be a split, which is then recursively
339 FIELD must match a complete field name. VALUE must match a complete
340 word according to the `nnmail-split-fancy-syntax-table' syntax table.
341 You can use \".*\" in the regexps to match partial field names or words.
343 FIELD and VALUE can also be lisp symbols, in that case they are expanded
344 as specified in `nnmail-split-abbrev-alist'.
346 GROUP can contain \\& and \\N which will substitute from matching
347 \\(\\) patterns in the previous VALUE.
351 \(setq nnmail-split-methods 'nnmail-split-fancy
353 ;; Messages from the mailer daemon are not crossposted to any of
354 ;; the ordinary groups. Warnings are put in a separate group
356 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
358 ;; Non-error messages are crossposted to all relevant
359 ;; groups, but we don't crosspost between the group for the
360 ;; (ding) list and the group for other (ding) related mail.
361 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
362 (\"subject\" \"ding\" \"ding.misc\"))
363 ;; Other mailing lists...
364 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
365 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
366 ;; Both lists below have the same suffix, so prevent
367 ;; cross-posting to mkpkg.list of messages posted only to
368 ;; the bugs- list, but allow cross-posting when the
369 ;; message was really cross-posted.
370 (any \"bugs-mypackage@somewhere\" \"mypkg.bugs\")
371 (any \"mypackage@somewhere\" - \"bugs-mypackage\" \"mypkg.list\")
374 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
375 ;; Unmatched mail goes to the catch all group.
381 (defcustom nnmail-split-abbrev-alist
382 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
383 (mail . "mailer-daemon\\|postmaster\\|uucp")
384 (to . "to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
385 (from . "from\\|sender\\|resent-from")
386 (nato . "to\\|cc\\|resent-to\\|resent-cc")
387 (naany . "from\\|to\\|cc\\|sender\\|resent-from\\|resent-to\\|resent-cc"))
388 "*Alist of abbreviations allowed in `nnmail-split-fancy'."
390 :type '(repeat (cons :format "%v" symbol regexp)))
392 (defcustom nnmail-message-id-cache-length 1000
393 "*The approximate number of Message-IDs nnmail will keep in its cache.
394 If this variable is nil, no checking on duplicate messages will be
396 :group 'nnmail-duplicate
397 :type '(choice (const :tag "disable" nil)
398 (integer :format "%v")))
400 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
401 "*The file name of the nnmail Message-ID cache."
402 :group 'nnmail-duplicate
406 (defcustom nnmail-treat-duplicates 'warn
407 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
408 Three values are valid: nil, which means that nnmail is not to keep a
409 Message-ID cache; `warn', which means that nnmail should insert extra
410 headers to warn the user about the duplication (this is the default);
411 and `delete', which means that nnmail will delete duplicated mails.
413 This variable can also be a function. It will be called from a buffer
414 narrowed to the article in question with the Message-ID as a
415 parameter. It should return nil, `warn' or `delete'."
416 :group 'nnmail-duplicate
417 :type '(choice (const :tag "off" nil)
421 (defcustom nnmail-extra-headers nil
422 "*Extra headers to parse."
424 :type '(repeat symbol))
426 (defcustom nnmail-split-header-length-limit 512
427 "Header lines longer than this limit are excluded from the split function."
431 ;;; Internal variables.
433 (defvar nnmail-split-history nil
434 "List of group/article elements that say where the previous split put messages.")
436 (defvar nnmail-split-fancy-syntax-table nil
437 "Syntax table used by `nnmail-split-fancy'.")
438 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
439 (setq nnmail-split-fancy-syntax-table
440 (copy-syntax-table (standard-syntax-table)))
441 ;; support the %-hack
442 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
444 (defvar nnmail-prepare-save-mail-hook nil
445 "Hook called before saving mail.")
447 (defvar nnmail-split-tracing nil)
448 (defvar nnmail-split-trace nil)
452 (defconst nnmail-version "nnmail 1.0"
457 (defun nnmail-request-post (&optional server)
458 (mail-send-and-exit nil))
460 (defvar nnmail-file-coding-system 'raw-text
461 "Coding system used in nnmail.")
463 (defvar nnmail-incoming-coding-system 'raw-text
464 "Coding system used in reading inbox")
466 (defvar nnmail-pathname-coding-system 'binary
467 "*Coding system for pathname.")
469 (defun nnmail-find-file (file)
470 "Insert FILE in server buffer safely."
471 (set-buffer nntp-server-buffer)
472 (delete-region (point-min) (point-max))
473 (let ((format-alist nil)
474 (after-insert-file-functions nil))
476 (let ((auto-mode-alist (nnheader-auto-mode-alist))
477 (file-name-coding-system nnmail-pathname-coding-system)
478 (pathname-coding-system nnmail-pathname-coding-system))
479 (insert-file-contents-as-coding-system
480 nnmail-file-coding-system file)
484 (defun nnmail-group-pathname (group dir &optional file)
485 "Make pathname for GROUP."
487 (let ((dir (file-name-as-directory (expand-file-name dir))))
488 (setq group (nnheader-replace-duplicate-chars-in-string
489 (nnheader-replace-chars-in-string group ?/ ?_)
491 (setq group (nnheader-translate-file-chars group))
492 ;; If this directory exists, we use it directly.
493 (file-name-as-directory
494 (if (or nnmail-use-long-file-names
495 (file-directory-p (concat dir group)))
496 (expand-file-name group dir)
497 ;; If not, we translate dots into slashes.
499 (encode-coding-string
500 (nnheader-replace-chars-in-string group ?. ?/)
501 nnmail-pathname-coding-system)
505 (defun nnmail-get-active ()
506 "Returns an assoc of group names and active ranges.
507 nn*-request-list should have been called before calling this function."
508 ;; Go through all groups from the active list.
510 (set-buffer nntp-server-buffer)
511 (nnmail-parse-active)))
513 (defun nnmail-parse-active ()
514 "Parse the active file in the current buffer and return an alist."
515 (goto-char (point-min))
516 (unless (re-search-forward "[\\\"]" nil t)
517 (goto-char (point-max))
518 (while (re-search-backward "[][';?()#]" nil t)
520 (goto-char (point-min))
521 (let ((buffer (current-buffer))
522 group-assoc group max min)
526 (narrow-to-region (point) (gnus-point-at-eol))
527 (setq group (read buffer))
528 (unless (stringp group)
529 (setq group (symbol-name group)))
530 (if (and (numberp (setq max (read nntp-server-buffer)))
531 (numberp (setq min (read nntp-server-buffer))))
532 (push (list group (cons min max))
539 (defvar nnmail-active-file-coding-system 'raw-text
540 "*Coding system for active file.")
542 (defun nnmail-save-active (group-assoc file-name)
543 "Save GROUP-ASSOC in ACTIVE-FILE."
544 (let ((coding-system-for-write nnmail-active-file-coding-system)
545 (output-coding-system nnmail-active-file-coding-system))
547 (with-temp-file file-name
548 (nnmail-generate-active group-assoc)))))
550 (defun nnmail-generate-active (alist)
551 "Generate an active file from group-alist ALIST."
554 (while (setq group (pop alist))
555 (insert (format "%S %d %d y\n" (intern (car group)) (cdadr group)
557 (goto-char (point-max))
558 (while (search-backward "\\." nil t)
561 (defun nnmail-get-split-group (file source)
562 "Find out whether this FILE is to be split into GROUP only.
563 If SOURCE is a directory spec, try to return the group name component."
564 (if (eq (car source) 'directory)
565 (let ((file (file-name-nondirectory file)))
566 (mail-source-bind (directory source)
567 (if (string-match (concat (regexp-quote suffix) "$") file)
568 (substring file 0 (match-beginning 0))
572 (defun nnmail-process-babyl-mail-format (func artnum-func)
573 (let ((case-fold-search t)
575 start message-id content-length do-search end)
577 (goto-char (point-min))
579 "
\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
580 (goto-char (match-end 0))
581 (delete-region (match-beginning 0) (match-end 0))
585 ;; Skip all the headers in case there are more "From "s...
586 (or (search-forward "\n\n" nil t)
587 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
588 (search-forward "
\1f\f"))
590 ;; Unquote the ">From " line, if any.
591 (goto-char (point-min))
592 (when (looking-at ">From ")
593 (replace-match "X-From-Line: ") )
594 (run-hooks 'nnmail-prepare-incoming-header-hook)
595 (goto-char (point-max))
596 ;; Find the Message-ID header.
598 (if (re-search-backward
599 "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]*>\\)" nil t)
600 (setq message-id (buffer-substring (match-beginning 1)
602 ;; There is no Message-ID here, so we create one.
604 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
606 (insert "Original-")))
608 (insert "Message-ID: " (setq message-id (nnmail-message-id))
610 ;; Look for a Content-Length header.
611 (if (not (save-excursion
612 (and (re-search-backward
613 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
614 (setq content-length (string-to-int
618 ;; We destroy the header, since none of
619 ;; the backends ever use it, and we do not
620 ;; want to confuse other mailers by having
621 ;; a (possibly) faulty header.
622 (progn (insert "X-") t))))
625 (if (or (= (+ (point) content-length) (point-max))
627 (goto-char (+ (point) content-length))
630 (goto-char (+ (point) content-length))
631 (setq do-search nil))
634 ;; Go to the beginning of the next article - or to the end
637 (if (re-search-forward "^
\1f" nil t)
638 (goto-char (match-beginning 0))
639 (goto-char (1- (point-max)))))
640 (delete-char 1) ; delete ^_
643 (narrow-to-region start (point))
644 (goto-char (point-min))
645 (nnmail-check-duplication message-id func artnum-func)
647 (setq end (point-max))))
651 (defsubst nnmail-search-unix-mail-delim ()
652 "Put point at the beginning of the next Unix mbox message."
653 ;; Algorithm used to find the the next article in the
654 ;; brain-dead Unix mbox format:
656 ;; 1) Search for "^From ".
657 ;; 2) If we find it, then see whether the previous
658 ;; line is blank and the next line looks like a header.
659 ;; Then it's possible that this is a mail delim, and we use it.
660 (let ((case-fold-search nil)
663 (if (not (re-search-forward "^From " nil t))
667 (when (and (or (bobp)
670 (eq (char-after) ?\n)))
673 (while (looking-at ">From \\|From ")
675 (looking-at "[^ \n\t:]+[ \n\t]*:")))
676 (setq found 'yes)))))
680 (defun nnmail-search-unix-mail-delim-backward ()
681 "Put point at the beginning of the current Unix mbox message."
682 ;; Algorithm used to find the the next article in the
683 ;; brain-dead Unix mbox format:
685 ;; 1) Search for "^From ".
686 ;; 2) If we find it, then see whether the previous
687 ;; line is blank and the next line looks like a header.
688 ;; Then it's possible that this is a mail delim, and we use it.
689 (let ((case-fold-search nil)
692 (if (not (re-search-backward "^From " nil t))
696 (when (and (or (bobp)
699 (eq (char-after) ?\n)))
702 (while (looking-at ">From \\|From ")
704 (looking-at "[^ \n\t:]+[ \n\t]*:")))
705 (setq found 'yes)))))
709 (defun nnmail-process-unix-mail-format (func artnum-func)
710 (let ((case-fold-search t)
712 start message-id content-length end skip head-end)
713 (goto-char (point-min))
714 (if (not (and (re-search-forward "^From " nil t)
715 (goto-char (match-beginning 0))))
716 ;; Possibly wrong format?
717 (error "Error, unknown mail format! (Possibly corrupted.)")
718 ;; Carry on until the bitter end.
722 ;; Find the end of the head.
725 (if (search-forward "\n\n" nil t)
727 ;; This will never happen, but just to be on the safe side --
728 ;; if there is no head-body delimiter, we search a bit manually.
729 (while (and (looking-at "From \\|[^ \t]+:")
733 ;; Find the Message-ID header.
734 (goto-char (point-min))
735 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
736 (setq message-id (match-string 1))
738 (when (re-search-forward "^Message-ID[ \t]*:" nil t)
740 (insert "Original-")))
741 ;; There is no Message-ID here, so we create one.
743 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
744 ;; Look for a Content-Length header.
745 (goto-char (point-min))
746 (if (not (re-search-forward
747 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
748 (setq content-length nil)
749 (setq content-length (string-to-int (match-string 1)))
750 ;; We destroy the header, since none of the backends ever
751 ;; use it, and we do not want to confuse other mailers by
752 ;; having a (possibly) faulty header.
755 (run-hooks 'nnmail-prepare-incoming-header-hook)
756 ;; Find the end of this article.
757 (goto-char (point-max))
759 (setq head-end (point))
760 ;; We try the Content-Length value. The idea: skip over the header
761 ;; separator, then check what happens content-length bytes into the
762 ;; message body. This should be either the end ot the buffer, the
763 ;; message separator or a blank line followed by the separator.
764 ;; The blank line should probably be deleted. If neither of the
765 ;; three is met, the content-length header is probably invalid.
768 (setq skip (+ (point) content-length))
770 (cond ((or (= skip (point-max))
771 (= (1+ skip) (point-max)))
772 (setq end (point-max)))
773 ((looking-at "From ")
775 ((looking-at "[ \t]*\n\\(From \\)")
776 (setq end (match-beginning 1)))
780 ;; No Content-Length, so we find the beginning of the next
781 ;; article or the end of the buffer.
783 (or (nnmail-search-unix-mail-delim)
784 (goto-char (point-max))))
785 ;; Allow the backend to save the article.
788 (narrow-to-region start (point))
789 (goto-char (point-min))
791 (nnmail-check-duplication message-id func artnum-func)
792 (setq end (point-max))))
796 (defun nnmail-process-mmdf-mail-format (func artnum-func)
797 (let ((delim "^\^A\^A\^A\^A$")
800 start message-id end)
801 (goto-char (point-min))
802 (if (not (and (re-search-forward delim nil t)
804 ;; Possibly wrong format?
805 (error "Error, unknown mail format! (Possibly corrupted.)")
806 ;; Carry on until the bitter end.
809 ;; Find the end of the head.
812 (if (search-forward "\n\n" nil t)
814 ;; This will never happen, but just to be on the safe side --
815 ;; if there is no head-body delimiter, we search a bit manually.
816 (while (and (looking-at "From \\|[^ \t]+:")
820 ;; Find the Message-ID header.
821 (goto-char (point-min))
822 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
823 (setq message-id (match-string 1))
824 ;; There is no Message-ID here, so we create one.
826 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
828 (insert "Original-")))
830 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
831 (run-hooks 'nnmail-prepare-incoming-header-hook)
832 ;; Find the end of this article.
833 (goto-char (point-max))
835 (if (re-search-forward delim nil t)
837 (goto-char (point-max)))
838 ;; Allow the backend to save the article.
841 (narrow-to-region start (point))
842 (goto-char (point-min))
844 (nnmail-check-duplication message-id func artnum-func)
845 (setq end (point-max))))
850 (defun nnmail-process-maildir-mail-format (func artnum-func)
851 ;; In a maildir, every file contains exactly one mail.
852 (let ((case-fold-search t)
854 (goto-char (point-min))
855 ;; Find the end of the head.
858 (if (search-forward "\n\n" nil t)
860 ;; This will never happen, but just to be on the safe side --
861 ;; if there is no head-body delimiter, we search a bit manually.
862 (while (and (looking-at "From \\|[^ \t]+:")
866 ;; Find the Message-ID header.
867 (goto-char (point-min))
868 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
869 (setq message-id (match-string 1))
870 ;; There is no Message-ID here, so we create one.
872 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
874 (insert "Original-")))
876 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
877 (run-hooks 'nnmail-prepare-incoming-header-hook)
878 ;; Allow the backend to save the article.
881 (goto-char (point-min))
882 (nnmail-check-duplication message-id func artnum-func))
885 (defun nnmail-split-incoming (incoming func &optional exit-func
887 "Go through the entire INCOMING file and pick out each individual mail.
888 FUNC will be called with the buffer narrowed to each mail."
889 (let (;; If this is a group-specific split, we bind the split
890 ;; methods to just this group.
891 (nnmail-split-methods (if (and group
892 (not nnmail-resplit-incoming))
893 (list (list group ""))
894 nnmail-split-methods)))
896 ;; Insert the incoming file.
897 (set-buffer (get-buffer-create " *nnmail incoming*"))
899 (let ((nnheader-file-coding-system nnmail-incoming-coding-system))
900 (nnheader-insert-file-contents incoming))
902 (if (zerop (buffer-size))
904 (goto-char (point-min))
905 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
906 ;; Handle both babyl, MMDF and unix mail formats, since
907 ;; movemail will use the former when fetching from a
908 ;; mailbox, the latter when fetching from a file.
909 (cond ((or (looking-at "\^L")
910 (looking-at "BABYL OPTIONS:"))
911 (nnmail-process-babyl-mail-format func artnum-func))
912 ((looking-at "\^A\^A\^A\^A")
913 (nnmail-process-mmdf-mail-format func artnum-func))
914 ((looking-at "Return-Path:")
915 (nnmail-process-maildir-mail-format func artnum-func))
917 (nnmail-process-unix-mail-format func artnum-func))))
920 (kill-buffer (current-buffer))))))
922 (defun nnmail-article-group (func &optional trace)
923 "Look at the headers and return an alist of groups that match.
924 FUNC will be called with the group name to determine the article number."
925 (let ((methods nnmail-split-methods)
926 (obuf (current-buffer))
928 end group-art method grp)
929 (if (and (sequencep methods)
930 (= (length methods) 1))
931 ;; If there is only just one group to put everything in, we
932 ;; just return a list with just this one method in.
934 (list (cons (caar methods) (funcall func (caar methods)))))
935 ;; We do actual comparison.
939 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
940 (set-buffer nntp-server-buffer)
942 ;; Copy the headers into the work buffer.
943 (insert-buffer-substring obuf beg end)
944 ;; Fold continuation lines.
945 (goto-char (point-min))
946 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
947 (replace-match " " t t))
948 ;; Nuke pathologically long headers. Since Gnus applies
949 ;; pathologically complex regexps to the buffer, lines
950 ;; that are looong will take longer than the Universe's
951 ;; existence to process.
952 (goto-char (point-min))
954 (unless (< (move-to-column nnmail-split-header-length-limit)
955 nnmail-split-header-length-limit)
956 (delete-region (point) (progn (end-of-line) (point))))
959 (goto-char (point-min))
960 (run-hooks 'nnmail-split-hook)
961 (when (setq nnmail-split-tracing trace)
962 (setq nnmail-split-trace nil))
963 (if (and (symbolp nnmail-split-methods)
964 (fboundp nnmail-split-methods))
967 ;; `nnmail-split-methods' is a function, so we
968 ;; just call this function here and use the
970 (or (funcall nnmail-split-methods)
974 "Error in `nnmail-split-methods'; using `bogus' mail group")
977 (setq split (gnus-remove-duplicates split))
978 ;; The article may be "cross-posted" to `junk'. What
979 ;; to do? Just remove the `junk' spec. Don't really
980 ;; see anything else to do...
982 (while (setq elem (car (memq 'junk split)))
983 (setq split (delq elem split))))
987 (lambda (group) (cons group (funcall func group)))
989 ;; Go through the split methods to find a match.
993 (goto-char (point-max))
994 (setq method (pop methods)
997 (not (equal "" (nth 1 method))))
1000 (if (stringp (nth 1 method))
1001 (let ((expand (string-match "\\\\[0-9&]" grp))
1002 (pos (re-search-backward (cadr method)
1005 (setq grp (nnmail-expand-newtext grp)))
1007 ;; Function to say whether this is a match.
1008 (funcall (nth 1 method) grp)))
1009 ;; Don't enter the article into the same
1011 (not (assoc grp group-art)))
1012 (push (cons grp (funcall func grp))
1014 ;; This is the final group, which is used as a
1018 (list (cons (car method)
1019 (funcall func (car method)))))))))
1020 ;; Produce a trace if non-empty.
1021 (when (and trace nnmail-split-trace)
1022 (let ((trace (nreverse nnmail-split-trace))
1023 (restore (current-buffer)))
1024 (nnheader-set-temp-buffer "*Split Trace*")
1027 (insert (car trace) "\n")
1028 (setq trace (cdr trace)))
1029 (goto-char (point-min))
1030 (gnus-configure-windows 'split-trace)
1031 (set-buffer restore)))
1032 ;; See whether the split methods returned `junk'.
1033 (if (equal group-art '(junk))
1035 ;; The article may be "cross-posted" to `junk'. What
1036 ;; to do? Just remove the `junk' spec. Don't really
1037 ;; see anything else to do...
1039 (while (setq elem (car (memq 'junk group-art)))
1040 (setq group-art (delq elem group-art)))
1041 (nreverse group-art)))))))
1043 (defun nnmail-insert-lines ()
1044 "Insert how many lines there are in the body of the mail.
1045 Return the number of characters in the body."
1048 (goto-char (point-min))
1049 (unless (search-forward "\n\n" nil t)
1050 (goto-char (point-max))
1052 (setq chars (- (point-max) (point)))
1053 (setq lines (count-lines (point) (point-max)))
1056 (when (re-search-backward "^Lines: " nil t)
1057 (delete-region (point) (progn (forward-line 1) (point)))))
1059 (insert (format "Lines: %d\n" (max lines 0)))
1062 (defun nnmail-insert-xref (group-alist)
1063 "Insert an Xref line based on the (group . article) alist."
1065 (goto-char (point-min))
1066 (unless (search-forward "\n\n" nil t)
1067 (goto-char (point-max))
1070 (when (re-search-backward "^Xref: " nil t)
1071 (delete-region (match-beginning 0)
1072 (progn (forward-line 1) (point))))
1073 (insert (format "Xref: %s" (system-name)))
1075 (insert (format " %s:%d"
1076 (encode-coding-string
1078 nnmail-pathname-coding-system)
1079 (cdar group-alist)))
1080 (setq group-alist (cdr group-alist)))
1083 ;;; Message washing functions
1085 (defun nnmail-remove-leading-whitespace ()
1086 "Remove excessive whitespace from all headers."
1087 (goto-char (point-min))
1088 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
1089 (replace-match "\\1" t)))
1091 (defun nnmail-remove-list-identifiers ()
1092 "Remove list identifiers from Subject headers."
1093 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
1094 (mapconcat 'identity nnmail-list-identifiers " *\\|"))))
1096 (goto-char (point-min))
1097 (when (re-search-forward
1098 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1100 (delete-region (match-beginning 2) (match-end 0))))))
1102 (defun nnmail-remove-tabs ()
1103 "Translate TAB characters into SPACE characters."
1104 (subst-char-in-region (point-min) (point-max) ?\t ? t))
1106 (defun nnmail-fix-eudora-headers ()
1107 "Eudora has a broken References line, but an OK In-Reply-To."
1108 (goto-char (point-min))
1109 (when (re-search-forward "^X-Mailer:.*Eudora" nil t)
1110 (goto-char (point-min))
1111 (when (re-search-forward "^References:" nil t)
1113 (insert "X-Gnus-Broken-Eudora-"))
1114 (goto-char (point-min))
1115 (when (re-search-forward "^In-Reply-To:[^\n]+\\(\n[ \t]+\\)" nil t)
1116 (replace-match "" t t nil 1))))
1118 (custom-add-option 'nnmail-prepare-incoming-header-hook
1119 'nnmail-fix-eudora-headers)
1121 ;;; Utility functions
1123 (defun nnmail-split-fancy ()
1124 "Fancy splitting method.
1125 See the documentation for the variable `nnmail-split-fancy' for documentation."
1126 (let ((syntab (syntax-table)))
1129 (set-syntax-table nnmail-split-fancy-syntax-table)
1130 (nnmail-split-it nnmail-split-fancy))
1131 (set-syntax-table syntab))))
1133 (defvar nnmail-split-cache nil)
1134 ;; Alist of split expressions their equivalent regexps.
1136 (defun nnmail-split-it (split)
1137 ;; Return a list of groups matching SPLIT.
1144 ;; A group name. Do the \& and \N subs into the string.
1146 (when nnmail-split-tracing
1147 (push (format "\"%s\"" split) nnmail-split-trace))
1148 (list (nnmail-expand-newtext split)))
1150 ;; Junk the message.
1152 (when nnmail-split-tracing
1153 (push "junk" nnmail-split-trace))
1156 ;; Builtin & operation.
1157 ((eq (car split) '&)
1158 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
1160 ;; Builtin | operation.
1161 ((eq (car split) '|)
1163 (while (and (not done) (cdr split))
1164 (setq split (cdr split)
1165 done (nnmail-split-it (car split))))
1168 ;; Builtin : operation.
1169 ((eq (car split) ':)
1170 (nnmail-split-it (save-excursion (eval (cdr split)))))
1172 ;; Builtin ! operation.
1173 ((eq (car split) '!)
1174 (funcall (cadr split) (nnmail-split-it (caddr split))))
1176 ;; Check the cache for the regexp for this split.
1177 ((setq cached-pair (assq split nnmail-split-cache))
1179 (end-point (point-max))
1180 (value (nth 1 split)))
1182 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1183 (while (and (goto-char end-point)
1184 (re-search-backward (cdr cached-pair) nil t))
1185 (when nnmail-split-tracing
1186 (push (cdr cached-pair) nnmail-split-trace))
1187 (let ((split-rest (cddr split))
1189 ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\). So,
1190 ;; start-of-value is the the point just before the
1191 ;; beginning of the value, whereas after-header-name is
1192 ;; the point just after the field name.
1193 (start-of-value (match-end 1))
1194 (after-header-name (match-end 2)))
1195 ;; Start the next search just before the beginning of the
1197 (setq end-point (1- start-of-value))
1198 ;; Handle - RESTRICTs
1199 (while (eq (car split-rest) '-)
1200 ;; RESTRICT must start after-header-name and
1201 ;; end after start-of-value, so that, for
1202 ;; (any "foo" - "x-foo" "foo.list")
1203 ;; we do not exclude foo.list just because
1204 ;; the header is: ``To: x-foo, foo''
1206 (if (and (re-search-backward (cadr split-rest)
1207 after-header-name t)
1208 (> (match-end 0) start-of-value))
1209 (setq split-rest nil)
1210 (setq split-rest (cddr split-rest))))
1213 (let ((value (nth 1 split)))
1215 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1216 ;; Someone might want to do a \N sub on this match, so get the
1217 ;; correct match positions.
1218 (re-search-backward (concat "\\<" value "\\>") start-of-value))
1219 (dolist (sp (nnmail-split-it (car split-rest)))
1220 (unless (memq sp split-result)
1221 (push sp split-result))))))
1224 ;; Not in cache, compute a regexp for the field/value pair.
1226 (let* ((field (nth 0 split))
1227 (value (nth 1 split))
1230 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1231 (if (and (>= (length value) 2)
1232 (string= ".*" (substring value 0 2)))
1233 (setq value (substring value 2)
1235 (setq regexp (concat "^\\(\\("
1237 (cdr (assq field nnmail-split-abbrev-alist))
1244 (push (cons split regexp) nnmail-split-cache)
1245 ;; Now that it's in the cache, just call nnmail-split-it again
1246 ;; on the same split, which will find it immediately in the cache.
1247 (nnmail-split-it split))))))
1249 (defun nnmail-expand-newtext (newtext)
1250 (let ((len (length newtext))
1252 c expanded beg N did-expand)
1255 (while (and (< pos len)
1256 (not (= (aref newtext pos) ?\\)))
1257 (setq pos (1+ pos)))
1259 (push (substring newtext beg pos) expanded))
1261 ;; We hit a \; expand it.
1264 c (aref newtext pos))
1265 (if (not (or (= c ?\&)
1268 ;; \ followed by some character we don't expand.
1269 (push (char-to-string c) expanded)
1274 (when (match-beginning N)
1275 (push (buffer-substring (match-beginning N) (match-end N))
1277 (setq pos (1+ pos)))
1279 (apply 'concat (nreverse expanded))
1282 ;; Activate a backend only if it isn't already activated.
1283 ;; If FORCE, re-read the active file even if the backend is
1284 ;; already activated.
1285 (defun nnmail-activate (backend &optional force)
1286 (nnheader-init-server-buffer)
1287 (let (file timestamp file-time)
1288 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
1290 (and (setq file (ignore-errors
1291 (symbol-value (intern (format "%s-active-file"
1293 (setq file-time (nth 5 (file-attributes file)))
1297 (symbol-value (intern
1298 (format "%s-active-timestamp"
1301 (not (consp timestamp))
1302 (equal timestamp '(0 0))
1303 (> (nth 0 file-time) (nth 0 timestamp))
1304 (and (= (nth 0 file-time) (nth 0 timestamp))
1305 (> (nth 1 file-time) (nth 1 timestamp))))))
1307 (or (eq timestamp 'none)
1308 (set (intern (format "%s-active-timestamp" backend))
1310 (funcall (intern (format "%s-request-list" backend)))))
1313 (defun nnmail-message-id ()
1314 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1317 ;;; nnmail duplicate handling
1320 (defvar nnmail-cache-buffer nil)
1322 (defun nnmail-cache-open ()
1323 (if (or (not nnmail-treat-duplicates)
1324 (and nnmail-cache-buffer
1325 (buffer-name nnmail-cache-buffer)))
1326 () ; The buffer is open.
1329 (setq nnmail-cache-buffer
1330 (get-buffer-create " *nnmail message-id cache*")))
1331 (when (file-exists-p nnmail-message-id-cache-file)
1332 (nnheader-insert-file-contents nnmail-message-id-cache-file))
1333 (set-buffer-modified-p nil)
1336 (defun nnmail-cache-close ()
1337 (when (and nnmail-cache-buffer
1338 nnmail-treat-duplicates
1339 (buffer-name nnmail-cache-buffer)
1340 (buffer-modified-p nnmail-cache-buffer))
1342 (set-buffer nnmail-cache-buffer)
1343 ;; Weed out the excess number of Message-IDs.
1344 (goto-char (point-max))
1345 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
1348 (delete-region (point-min) (point))))
1350 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
1351 (make-directory (file-name-directory nnmail-message-id-cache-file)
1353 (nnmail-write-region (point-min) (point-max)
1354 nnmail-message-id-cache-file nil 'silent)
1355 (set-buffer-modified-p nil)
1356 (setq nnmail-cache-buffer nil)
1357 (kill-buffer (current-buffer)))))
1359 ;; Compiler directives.
1361 (defvar group-art-list)
1363 (defun nnmail-cache-insert (id)
1364 (when nnmail-treat-duplicates
1365 ;; Store some information about the group this message is written
1366 ;; to. This function might have been called from various places.
1367 ;; Sometimes, a function up in the calling sequence has an
1368 ;; argument GROUP which is bound to a string, the group name. At
1369 ;; other times, there is a function up in the calling sequence
1370 ;; which has an argument GROUP-ART which is a list of pairs, and
1371 ;; the car of a pair is a group name. Should we check that the
1372 ;; length of the list is equal to 1? -- kai
1374 (cond ((and (boundp 'group) group)
1376 ((and (boundp 'group-art-list) group-art-list
1377 (listp group-art-list))
1378 (setq g (caar group-art-list)))
1379 ((and (boundp 'group-art) group-art (listp group-art))
1380 (setq g (caar group-art)))
1382 (unless (gnus-buffer-live-p nnmail-cache-buffer)
1383 (nnmail-cache-open))
1385 (set-buffer nnmail-cache-buffer)
1386 (goto-char (point-max))
1387 (if (and g (not (string= "" g))
1388 (gnus-methods-equal-p gnus-command-method
1389 (nnmail-cache-primary-mail-backend)))
1390 (insert id "\t" g "\n")
1391 (insert id "\n"))))))
1393 (defun nnmail-cache-primary-mail-backend ()
1394 (let ((be-list (cons gnus-select-method gnus-secondary-select-methods))
1397 (while (and (null res) be-list)
1398 (setq be (car be-list))
1399 (setq be-list (cdr be-list))
1400 (when (and (gnus-method-option-p be 'respool)
1401 (eval (intern (format "%s-get-new-mail" (car be)))))
1405 ;; Fetch the group name corresponding to the message id stored in the
1407 (defun nnmail-cache-fetch-group (id)
1408 (when (and nnmail-treat-duplicates nnmail-cache-buffer)
1410 (set-buffer nnmail-cache-buffer)
1411 (goto-char (point-max))
1412 (when (search-backward id nil t)
1414 (skip-chars-forward "^\n\r\t")
1417 (buffer-substring (point)
1418 (progn (end-of-line) (point))))))))
1420 ;; Function for nnmail-split-fancy: look up all references in the
1421 ;; cache and if a match is found, return that group.
1422 (defun nnmail-split-fancy-with-parent ()
1423 (let* ((refstr (or (message-fetch-field "references")
1424 (message-fetch-field "in-reply-to")))
1428 (setq references (nreverse (gnus-split-references refstr)))
1429 (unless (gnus-buffer-live-p nnmail-cache-buffer)
1430 (nnmail-cache-open))
1432 (setq res (or (nnmail-cache-fetch-group x) res))
1433 (when (string= "drafts" res)
1438 (defun nnmail-cache-id-exists-p (id)
1439 (when nnmail-treat-duplicates
1441 (set-buffer nnmail-cache-buffer)
1442 (goto-char (point-max))
1443 (search-backward id nil t))))
1445 (defun nnmail-fetch-field (header)
1448 (message-narrow-to-head)
1449 (message-fetch-field header))))
1451 (defun nnmail-check-duplication (message-id func artnum-func)
1452 (run-hooks 'nnmail-prepare-incoming-message-hook)
1453 ;; If this is a duplicate message, then we do not save it.
1454 (let* ((duplication (nnmail-cache-id-exists-p message-id))
1455 (case-fold-search t)
1456 (action (when duplication
1458 ((memq nnmail-treat-duplicates '(warn delete))
1459 nnmail-treat-duplicates)
1460 ((nnheader-functionp nnmail-treat-duplicates)
1461 (funcall nnmail-treat-duplicates message-id))
1463 nnmail-treat-duplicates))))
1465 ;; We insert a line that says what the mail source is.
1466 (let ((case-fold-search t))
1467 (goto-char (point-min))
1468 (re-search-forward "^message-id[ \t]*:" nil t)
1470 (insert (format "X-Gnus-Mail-Source: %s\n" mail-source-string)))
1472 ;; Let the backend save the article (or not).
1475 (funcall func (setq group-art
1476 (nreverse (nnmail-article-group artnum-func))))
1477 (nnmail-cache-insert message-id))
1478 ((eq action 'delete)
1479 (setq group-art nil))
1481 ;; We insert a warning.
1482 (let ((case-fold-search t))
1483 (goto-char (point-min))
1484 (re-search-forward "^message-id[ \t]*:" nil t)
1487 "Gnus-Warning: This is a duplicate of message " message-id "\n")
1488 (funcall func (setq group-art
1489 (nreverse (nnmail-article-group artnum-func))))))
1491 (funcall func (setq group-art
1492 (nreverse (nnmail-article-group artnum-func))))))
1493 ;; Add the group-art list to the history list.
1495 (push group-art nnmail-split-history)
1496 (delete-region (point-min) (point-max)))))
1500 (defvar nnmail-fetched-sources nil)
1502 (defun nnmail-get-value (&rest args)
1503 (let ((sym (intern (apply 'format args))))
1505 (symbol-value sym))))
1507 (defun nnmail-get-new-mail (method exit-func temp
1508 &optional group spool-func)
1509 "Read new incoming mail."
1510 (let* ((sources (or mail-sources
1511 (if (listp nnmail-spool-file) nnmail-spool-file
1512 (list nnmail-spool-file))))
1518 incoming incomings source)
1519 (when (and (nnmail-get-value "%s-get-new-mail" method)
1521 (while (setq source (pop sources))
1522 ;; Be compatible with old values.
1527 ((string-match "^po:" source)
1528 (list 'pop :user (substring source (match-end 0))))
1529 ((file-directory-p source)
1530 (list 'directory :path source))
1532 (list 'file :path source)))))
1533 ((eq source 'procmail)
1534 (message "Invalid value for nnmail-spool-file: `procmail'")
1536 ;; Hack to only fetch the contents of a single group's spool file.
1537 (when (and (eq (car source) 'directory)
1538 (null nnmail-scan-directory-mail-source-once)
1540 (mail-source-bind (directory source)
1541 (setq source (append source
1547 (regexp-quote (concat group suffix))
1550 (when nnmail-fetched-sources
1551 (if (member source nnmail-fetched-sources)
1553 (push source nnmail-fetched-sources)
1554 (push source fetching-sources)))))
1555 (when fetching-sources
1556 ;; We first activate all the groups.
1557 (nnmail-activate method)
1558 ;; Allow the user to hook.
1559 (run-hooks 'nnmail-pre-get-new-mail-hook)
1560 ;; Open the message-id cache.
1562 ;; The we go through all the existing mail source specification
1563 ;; and fetch the mail from each.
1564 (while (setq source (pop fetching-sources))
1565 (nnheader-message 4 "%s: Reading incoming mail from %s..."
1566 method (car source))
1570 `(lambda (file orig-file)
1571 (nnmail-split-incoming
1572 file ',(intern (format "%s-save-mail" method))
1574 (nnmail-get-split-group orig-file source)
1575 ',(intern (format "%s-active-number" method))))))
1578 ;; If we did indeed read any incoming spools, we save all info.
1580 (nnheader-message 4 "%s: Reading incoming mail (no new mail)...done"
1581 method (car source))
1583 (nnmail-get-value "%s-group-alist" method)
1584 (nnmail-get-value "%s-active-file" method))
1586 (funcall exit-func))
1587 (run-hooks 'nnmail-read-incoming-hook)
1588 (nnheader-message 4 "%s: Reading incoming mail (%d new)...done" method
1590 ;; Close the message-id cache.
1591 (nnmail-cache-close)
1592 ;; Allow the user to hook.
1593 (run-hooks 'nnmail-post-get-new-mail-hook))))
1595 (defun nnmail-expired-article-p (group time force &optional inhibit)
1596 "Say whether an article that is TIME old in GROUP should be expired."
1599 (let ((days (or (and nnmail-expiry-wait-function
1600 (funcall nnmail-expiry-wait-function group))
1601 nnmail-expiry-wait)))
1602 (cond ((or (eq days 'never)
1605 ;; This isn't an expirable group.
1607 ((eq days 'immediate)
1608 ;; We expire all articles on sight.
1610 ((equal time '(0 0))
1611 ;; This is an ange-ftp group, and we don't have any dates.
1614 (setq days (days-to-time days))
1615 ;; Compare the time with the current time.
1616 (ignore-errors (time-less-p days (time-since time))))))))
1618 (defun nnmail-expiry-target-group (target group)
1619 (when (nnheader-functionp target)
1620 (setq target (funcall target group)))
1621 (unless (eq target 'delete)
1622 (gnus-request-accept-article target)))
1624 (defun nnmail-check-syntax ()
1625 "Check (and modify) the syntax of the message in the current buffer."
1627 (message-narrow-to-head)
1628 (let ((case-fold-search t))
1629 (unless (re-search-forward "^Message-ID[ \t]*:" nil t)
1630 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1632 (defun nnmail-write-region (start end filename &optional append visit lockname)
1633 "Do a `write-region', and then set the file modes."
1634 (let ((file-name-coding-system nnmail-pathname-coding-system)
1635 (pathname-coding-system nnmail-pathname-coding-system))
1636 (write-region-as-coding-system
1637 nnmail-file-coding-system start end filename append visit lockname)
1638 (set-file-modes filename nnmail-default-file-modes)))
1641 ;;; Status functions
1644 (defun nnmail-replace-status (name value)
1645 "Make status NAME and VALUE part of the current status line."
1647 (message-narrow-to-head)
1648 (let ((status (nnmail-decode-status)))
1649 (setq status (delq (member name status) status))
1651 (push (cons name value) status))
1652 (message-remove-header "status")
1653 (goto-char (point-max))
1654 (insert "Status: " (nnmail-encode-status status) "\n"))))
1656 (defun nnmail-decode-status ()
1657 "Return a status-value alist from STATUS."
1658 (goto-char (point-min))
1659 (when (re-search-forward "^Status: " nil t)
1660 (let (name value status)
1662 ;; Narrow to the status.
1665 (if (re-search-forward "^[^ \t]" nil t)
1668 ;; Go through all elements and add them to the list.
1669 (goto-char (point-min))
1670 (while (re-search-forward "[^ \t=]+" nil t)
1671 (setq name (match-string 0))
1672 (if (not (eq (char-after) ?=))
1676 (if (not (eq (char-after) ?\"))
1677 (if (not (looking-at "[^ \t]"))
1681 (setq value (match-string 0))
1682 (goto-char (match-end 0)))
1684 (setq value (read (current-buffer)))))
1685 (push (cons name value) status)))
1688 (defun nnmail-encode-status (status)
1689 "Return a status string from STATUS."
1694 (if (string-match "[ \t]" (cdr elem))
1695 (prin1-to-string (cdr elem))
1699 (defun nnmail-split-history ()
1700 "Generate an overview of where the last mail split put articles."
1702 (unless nnmail-split-history
1703 (error "No current split history"))
1704 (with-output-to-temp-buffer "*nnmail split history*"
1705 (with-current-buffer standard-output
1706 (fundamental-mode)) ; for Emacs 20.4+
1707 (let ((history nnmail-split-history)
1709 (while (setq elem (pop history))
1710 (princ (mapconcat (lambda (ga)
1711 (concat (car ga) ":" (int-to-string (cdr ga))))
1716 (defun nnmail-purge-split-history (group)
1717 "Remove all instances of GROUP from `nnmail-split-history'."
1718 (let ((history nnmail-split-history))
1720 (setcar history (gnus-delete-if (lambda (e) (string= (car e) group))
1723 (setq nnmail-split-history (delq nil nnmail-split-history))))
1725 (defun nnmail-new-mail-p (group)
1726 "Say whether GROUP has new mail."
1727 (let ((his nnmail-split-history)
1730 (when (assoc group (pop his))
1735 (defun nnmail-new-mail-numbers (group)
1736 "Say how many articles has been incorporated to GROUP."
1737 (let ((his (apply 'append nnmail-split-history))
1740 (when (string= group (caar his))
1741 (push (cdar his) numbers))
1742 (setq his (cdr his)))
1745 (defun nnmail-within-headers-p ()
1746 "Check to see if point is within the headers of a unix mail message.
1747 Doesn't change point."
1748 (let ((pos (point)))
1750 (and (nnmail-search-unix-mail-delim-backward)
1751 (not (search-forward "\n\n" pos t))))))
1753 (run-hooks 'nnmail-load-hook)
1757 ;;; nnmail.el ends here