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-delete-file-function 'delete-file
203 "Function called to delete files in some mail backends."
207 (defcustom nnmail-crosspost-link-function
208 (if (string-match "windows-nt\\|emx" (symbol-name system-type))
211 "*Function called to create a copy of a file.
212 This is `add-name-to-file' by default, which means that crossposts
213 will use hard links. If your file system doesn't allow hard
214 links, you could set this variable to `copy-file' instead."
216 :type '(radio (function-item add-name-to-file)
217 (function-item copy-file)
218 (function :tag "Other")))
220 (defcustom nnmail-read-incoming-hook
221 (if (eq system-type 'windows-nt)
222 '(nnheader-ms-strip-cr)
224 "*Hook that will be run after the incoming mail has been transferred.
225 The incoming mail is moved from `nnmail-spool-file' (which normally is
226 something like \"/usr/spool/mail/$user\") to the user's home
227 directory. This hook is called after the incoming mail box has been
228 emptied, and can be used to call any mail box programs you have
229 running (\"xwatch\", etc.)
233 \(add-hook 'nnmail-read-incoming-hook
235 (start-process \"mailsend\" nil
236 \"/local/bin/mailsend\" \"read\" \"mbox\")))
238 If you have xwatch running, this will alert it that mail has been
241 If you use `display-time', you could use something like this:
243 \(add-hook 'nnmail-read-incoming-hook
245 ;; Update the displayed time, since that will clear out
246 ;; the flag that says you have mail.
247 (when (eq (process-status \"display-time\") 'run)
248 (display-time-filter display-time-process \"\"))))"
249 :group 'nnmail-prepare
252 (defcustom nnmail-prepare-incoming-hook nil
253 "Hook called before treating incoming mail.
254 The hook is run in a buffer with all the new, incoming mail."
255 :group 'nnmail-prepare
258 (defcustom nnmail-prepare-incoming-header-hook nil
259 "Hook called narrowed to the headers of each message.
260 This can be used to remove excessive spaces (and stuff like
261 that) from the headers before splitting and saving the messages."
262 :group 'nnmail-prepare
265 (defcustom nnmail-prepare-incoming-message-hook nil
266 "Hook called narrowed to each message."
267 :group 'nnmail-prepare
270 (defcustom nnmail-list-identifiers nil
271 "Regexp that matches list identifiers to be removed.
272 This can also be a list of regexps."
273 :group 'nnmail-prepare
274 :type '(choice (const :tag "none" nil)
276 (repeat :value (".*") regexp)))
278 (defcustom nnmail-pre-get-new-mail-hook nil
279 "Hook called just before starting to handle new incoming mail."
280 :group 'nnmail-retrieve
283 (defcustom nnmail-post-get-new-mail-hook nil
284 "Hook called just after finishing handling new incoming mail."
285 :group 'nnmail-retrieve
288 (defcustom nnmail-split-hook nil
289 "Hook called before deciding where to split an article.
290 The functions in this hook are free to modify the buffer
291 contents in any way they choose -- the buffer contents are
292 discarded after running the split process."
296 (defcustom nnmail-large-newsgroup 50
297 "*The number of the articles which indicates a large newsgroup.
298 If the number of the articles is greater than the value, verbose
299 messages will be shown to indicate the current status."
300 :group 'nnmail-various
303 (defcustom nnmail-split-fancy "mail.misc"
304 "Incoming mail can be split according to this fancy variable.
305 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
307 The format of this variable is SPLIT, where SPLIT can be one of
310 GROUP: Mail will be stored in GROUP (a string).
312 \(FIELD VALUE [- RESTRICT [- RESTRICT [...]]] SPLIT): If the message
313 field FIELD (a regexp) contains VALUE (a regexp), store the messages
314 as specified by SPLIT. If RESTRICT (a regexp) matches some string
315 after FIELD and before the end of the matched VALUE, return NIL,
316 otherwise process SPLIT. Multiple RESTRICTs add up, further
317 restricting the possibility of processing SPLIT.
319 \(| SPLIT...): Process each SPLIT expression until one of them matches.
320 A SPLIT expression is said to match if it will cause the mail
321 message to be stored in one or more groups.
323 \(& SPLIT...): Process each SPLIT expression.
325 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
326 the buffer containing the message headers. The return value FUNCTION
327 should be a split, which is then recursively processed.
329 \(! FUNCTION SPLIT): Call FUNCTION with the result of SPLIT. The
330 return value FUNCTION should be a split, which is then recursively
333 FIELD must match a complete field name. VALUE must match a complete
334 word according to the `nnmail-split-fancy-syntax-table' syntax table.
335 You can use \".*\" in the regexps to match partial field names or words.
337 FIELD and VALUE can also be lisp symbols, in that case they are expanded
338 as specified in `nnmail-split-abbrev-alist'.
340 GROUP can contain \\& and \\N which will substitute from matching
341 \\(\\) patterns in the previous VALUE.
345 \(setq nnmail-split-methods 'nnmail-split-fancy
347 ;; Messages from the mailer daemon are not crossposted to any of
348 ;; the ordinary groups. Warnings are put in a separate group
350 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
352 ;; Non-error messages are crossposted to all relevant
353 ;; groups, but we don't crosspost between the group for the
354 ;; (ding) list and the group for other (ding) related mail.
355 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
356 (\"subject\" \"ding\" \"ding.misc\"))
357 ;; Other mailing lists...
358 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
359 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
360 ;; Both lists below have the same suffix, so prevent
361 ;; cross-posting to mkpkg.list of messages posted only to
362 ;; the bugs- list, but allow cross-posting when the
363 ;; message was really cross-posted.
364 (any \"bugs-mypackage@somewhere\" \"mypkg.bugs\")
365 (any \"mypackage@somewhere\" - \"bugs-mypackage\" \"mypkg.list\")
368 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
369 ;; Unmatched mail goes to the catch all group.
375 (defcustom nnmail-split-abbrev-alist
376 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
377 (mail . "mailer-daemon\\|postmaster\\|uucp")
378 (to . "to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
379 (from . "from\\|sender\\|resent-from")
380 (nato . "to\\|cc\\|resent-to\\|resent-cc")
381 (naany . "from\\|to\\|cc\\|sender\\|resent-from\\|resent-to\\|resent-cc"))
382 "*Alist of abbreviations allowed in `nnmail-split-fancy'."
384 :type '(repeat (cons :format "%v" symbol regexp)))
386 (defcustom nnmail-message-id-cache-length 1000
387 "*The approximate number of Message-IDs nnmail will keep in its cache.
388 If this variable is nil, no checking on duplicate messages will be
390 :group 'nnmail-duplicate
391 :type '(choice (const :tag "disable" nil)
392 (integer :format "%v")))
394 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
395 "*The file name of the nnmail Message-ID cache."
396 :group 'nnmail-duplicate
400 (defcustom nnmail-treat-duplicates 'warn
401 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
402 Three values are valid: nil, which means that nnmail is not to keep a
403 Message-ID cache; `warn', which means that nnmail should insert extra
404 headers to warn the user about the duplication (this is the default);
405 and `delete', which means that nnmail will delete duplicated mails.
407 This variable can also be a function. It will be called from a buffer
408 narrowed to the article in question with the Message-ID as a
409 parameter. It should return nil, `warn' or `delete'."
410 :group 'nnmail-duplicate
411 :type '(choice (const :tag "off" nil)
415 (defcustom nnmail-extra-headers nil
416 "*Extra headers to parse."
418 :type '(repeat symbol))
420 (defcustom nnmail-split-header-length-limit 512
421 "Header lines longer than this limit are excluded from the split function."
425 ;;; Internal variables.
427 (defvar nnmail-split-history nil
428 "List of group/article elements that say where the previous split put messages.")
430 (defvar nnmail-split-fancy-syntax-table nil
431 "Syntax table used by `nnmail-split-fancy'.")
432 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
433 (setq nnmail-split-fancy-syntax-table
434 (copy-syntax-table (standard-syntax-table)))
435 ;; support the %-hack
436 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
438 (defvar nnmail-prepare-save-mail-hook nil
439 "Hook called before saving mail.")
441 (defvar nnmail-split-tracing nil)
442 (defvar nnmail-split-trace nil)
446 (defconst nnmail-version "nnmail 1.0"
451 (defun nnmail-request-post (&optional server)
452 (mail-send-and-exit nil))
454 (defvar nnmail-file-coding-system 'raw-text
455 "Coding system used in nnmail.")
457 (defvar nnmail-incoming-coding-system 'raw-text
458 "Coding system used in reading inbox")
460 (defvar nnmail-pathname-coding-system 'binary
461 "*Coding system for pathname.")
463 (defun nnmail-find-file (file)
464 "Insert FILE in server buffer safely."
465 (set-buffer nntp-server-buffer)
466 (delete-region (point-min) (point-max))
467 (let ((format-alist nil)
468 (after-insert-file-functions nil))
470 (let ((auto-mode-alist (nnheader-auto-mode-alist))
471 (pathname-coding-system nnmail-pathname-coding-system))
472 (insert-file-contents-as-coding-system
473 nnmail-file-coding-system file)
477 (defun nnmail-group-pathname (group dir &optional file)
478 "Make pathname for GROUP."
480 (let ((dir (file-name-as-directory (expand-file-name dir))))
481 (setq group (nnheader-replace-duplicate-chars-in-string
482 (nnheader-replace-chars-in-string group ?/ ?_)
484 (setq group (nnheader-translate-file-chars group))
485 ;; If this directory exists, we use it directly.
486 (file-name-as-directory
487 (if (or nnmail-use-long-file-names
488 (file-directory-p (concat dir group)))
489 (expand-file-name group dir)
490 ;; If not, we translate dots into slashes.
492 (encode-coding-string
493 (nnheader-replace-chars-in-string group ?. ?/)
494 nnmail-pathname-coding-system)
498 (defun nnmail-get-active ()
499 "Returns an assoc of group names and active ranges.
500 nn*-request-list should have been called before calling this function."
501 ;; Go through all groups from the active list.
503 (set-buffer nntp-server-buffer)
504 (nnmail-parse-active)))
506 (defun nnmail-parse-active ()
507 "Parse the active file in the current buffer and return an alist."
508 (goto-char (point-min))
509 (unless (re-search-forward "[\\\"]" nil t)
510 (goto-char (point-max))
511 (while (re-search-backward "[][';?()#]" nil t)
513 (goto-char (point-min))
514 (let ((buffer (current-buffer))
515 group-assoc group max min)
519 (narrow-to-region (point) (gnus-point-at-eol))
520 (setq group (read buffer))
521 (unless (stringp group)
522 (setq group (symbol-name group)))
523 (if (and (numberp (setq max (read nntp-server-buffer)))
524 (numberp (setq min (read nntp-server-buffer))))
525 (push (list group (cons min max))
532 (defvar nnmail-active-file-coding-system 'raw-text
533 "*Coding system for active file.")
535 (defun nnmail-save-active (group-assoc file-name)
536 "Save GROUP-ASSOC in ACTIVE-FILE."
537 (let ((coding-system-for-write nnmail-active-file-coding-system)
538 (output-coding-system nnmail-active-file-coding-system))
540 (with-temp-file file-name
541 (nnmail-generate-active group-assoc)))))
543 (defun nnmail-generate-active (alist)
544 "Generate an active file from group-alist ALIST."
547 (while (setq group (pop alist))
548 (insert (format "%S %d %d y\n" (intern (car group)) (cdadr group)
550 (goto-char (point-max))
551 (while (search-backward "\\." nil t)
554 (defun nnmail-get-split-group (file source)
555 "Find out whether this FILE is to be split into GROUP only.
556 If SOURCE is a directory spec, try to return the group name component."
557 (if (eq (car source) 'directory)
558 (let ((file (file-name-nondirectory file)))
559 (mail-source-bind (directory source)
560 (if (string-match (concat (regexp-quote suffix) "$") file)
561 (substring file 0 (match-beginning 0))
565 (defun nnmail-process-babyl-mail-format (func artnum-func)
566 (let ((case-fold-search t)
568 start message-id content-length do-search end)
570 (goto-char (point-min))
572 "
\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
573 (goto-char (match-end 0))
574 (delete-region (match-beginning 0) (match-end 0))
578 ;; Skip all the headers in case there are more "From "s...
579 (or (search-forward "\n\n" nil t)
580 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
581 (search-forward "
\1f\f"))
583 ;; Unquote the ">From " line, if any.
584 (goto-char (point-min))
585 (when (looking-at ">From ")
586 (replace-match "X-From-Line: ") )
587 (run-hooks 'nnmail-prepare-incoming-header-hook)
588 (goto-char (point-max))
589 ;; Find the Message-ID header.
591 (if (re-search-backward
592 "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]*>\\)" nil t)
593 (setq message-id (buffer-substring (match-beginning 1)
595 ;; There is no Message-ID here, so we create one.
597 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
599 (insert "Original-")))
601 (insert "Message-ID: " (setq message-id (nnmail-message-id))
603 ;; Look for a Content-Length header.
604 (if (not (save-excursion
605 (and (re-search-backward
606 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
607 (setq content-length (string-to-int
611 ;; We destroy the header, since none of
612 ;; the backends ever use it, and we do not
613 ;; want to confuse other mailers by having
614 ;; a (possibly) faulty header.
615 (progn (insert "X-") t))))
618 (if (or (= (+ (point) content-length) (point-max))
620 (goto-char (+ (point) content-length))
623 (goto-char (+ (point) content-length))
624 (setq do-search nil))
627 ;; Go to the beginning of the next article - or to the end
630 (if (re-search-forward "^
\1f" nil t)
631 (goto-char (match-beginning 0))
632 (goto-char (1- (point-max)))))
633 (delete-char 1) ; delete ^_
636 (narrow-to-region start (point))
637 (goto-char (point-min))
638 (nnmail-check-duplication message-id func artnum-func)
640 (setq end (point-max))))
644 (defsubst nnmail-search-unix-mail-delim ()
645 "Put point at the beginning of the next Unix mbox message."
646 ;; Algorithm used to find the the next article in the
647 ;; brain-dead Unix mbox format:
649 ;; 1) Search for "^From ".
650 ;; 2) If we find it, then see whether the previous
651 ;; line is blank and the next line looks like a header.
652 ;; Then it's possible that this is a mail delim, and we use it.
653 (let ((case-fold-search nil)
656 (if (not (re-search-forward "^From " nil t))
660 (when (and (or (bobp)
663 (eq (char-after) ?\n)))
666 (while (looking-at ">From \\|From ")
668 (looking-at "[^ \n\t:]+[ \n\t]*:")))
669 (setq found 'yes)))))
673 (defun nnmail-search-unix-mail-delim-backward ()
674 "Put point at the beginning of the current Unix mbox message."
675 ;; Algorithm used to find the the next article in the
676 ;; brain-dead Unix mbox format:
678 ;; 1) Search for "^From ".
679 ;; 2) If we find it, then see whether the previous
680 ;; line is blank and the next line looks like a header.
681 ;; Then it's possible that this is a mail delim, and we use it.
682 (let ((case-fold-search nil)
685 (if (not (re-search-backward "^From " nil t))
689 (when (and (or (bobp)
692 (eq (char-after) ?\n)))
695 (while (looking-at ">From \\|From ")
697 (looking-at "[^ \n\t:]+[ \n\t]*:")))
698 (setq found 'yes)))))
702 (defun nnmail-process-unix-mail-format (func artnum-func)
703 (let ((case-fold-search t)
705 start message-id content-length end skip head-end)
706 (goto-char (point-min))
707 (if (not (and (re-search-forward "^From " nil t)
708 (goto-char (match-beginning 0))))
709 ;; Possibly wrong format?
710 (error "Error, unknown mail format! (Possibly corrupted.)")
711 ;; Carry on until the bitter end.
715 ;; Find the end of the head.
718 (if (search-forward "\n\n" nil t)
720 ;; This will never happen, but just to be on the safe side --
721 ;; if there is no head-body delimiter, we search a bit manually.
722 (while (and (looking-at "From \\|[^ \t]+:")
726 ;; Find the Message-ID header.
727 (goto-char (point-min))
728 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
729 (setq message-id (match-string 1))
731 (when (re-search-forward "^Message-ID[ \t]*:" nil t)
733 (insert "Original-")))
734 ;; There is no Message-ID here, so we create one.
736 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
737 ;; Look for a Content-Length header.
738 (goto-char (point-min))
739 (if (not (re-search-forward
740 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
741 (setq content-length nil)
742 (setq content-length (string-to-int (match-string 1)))
743 ;; We destroy the header, since none of the backends ever
744 ;; use it, and we do not want to confuse other mailers by
745 ;; having a (possibly) faulty header.
748 (run-hooks 'nnmail-prepare-incoming-header-hook)
749 ;; Find the end of this article.
750 (goto-char (point-max))
752 (setq head-end (point))
753 ;; We try the Content-Length value. The idea: skip over the header
754 ;; separator, then check what happens content-length bytes into the
755 ;; message body. This should be either the end ot the buffer, the
756 ;; message separator or a blank line followed by the separator.
757 ;; The blank line should probably be deleted. If neither of the
758 ;; three is met, the content-length header is probably invalid.
761 (setq skip (+ (point) content-length))
763 (cond ((or (= skip (point-max))
764 (= (1+ skip) (point-max)))
765 (setq end (point-max)))
766 ((looking-at "From ")
768 ((looking-at "[ \t]*\n\\(From \\)")
769 (setq end (match-beginning 1)))
773 ;; No Content-Length, so we find the beginning of the next
774 ;; article or the end of the buffer.
776 (or (nnmail-search-unix-mail-delim)
777 (goto-char (point-max))))
778 ;; Allow the backend to save the article.
781 (narrow-to-region start (point))
782 (goto-char (point-min))
784 (nnmail-check-duplication message-id func artnum-func)
785 (setq end (point-max))))
789 (defun nnmail-process-mmdf-mail-format (func artnum-func)
790 (let ((delim "^\^A\^A\^A\^A$")
793 start message-id end)
794 (goto-char (point-min))
795 (if (not (and (re-search-forward delim nil t)
797 ;; Possibly wrong format?
798 (error "Error, unknown mail format! (Possibly corrupted.)")
799 ;; Carry on until the bitter end.
802 ;; Find the end of the head.
805 (if (search-forward "\n\n" nil t)
807 ;; This will never happen, but just to be on the safe side --
808 ;; if there is no head-body delimiter, we search a bit manually.
809 (while (and (looking-at "From \\|[^ \t]+:")
813 ;; Find the Message-ID header.
814 (goto-char (point-min))
815 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
816 (setq message-id (match-string 1))
817 ;; There is no Message-ID here, so we create one.
819 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
821 (insert "Original-")))
823 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
824 (run-hooks 'nnmail-prepare-incoming-header-hook)
825 ;; Find the end of this article.
826 (goto-char (point-max))
828 (if (re-search-forward delim nil t)
830 (goto-char (point-max)))
831 ;; Allow the backend to save the article.
834 (narrow-to-region start (point))
835 (goto-char (point-min))
837 (nnmail-check-duplication message-id func artnum-func)
838 (setq end (point-max))))
843 (defun nnmail-process-maildir-mail-format (func artnum-func)
844 ;; In a maildir, every file contains exactly one mail.
845 (let ((case-fold-search t)
847 (goto-char (point-min))
848 ;; Find the end of the head.
851 (if (search-forward "\n\n" nil t)
853 ;; This will never happen, but just to be on the safe side --
854 ;; if there is no head-body delimiter, we search a bit manually.
855 (while (and (looking-at "From \\|[^ \t]+:")
859 ;; Find the Message-ID header.
860 (goto-char (point-min))
861 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
862 (setq message-id (match-string 1))
863 ;; There is no Message-ID here, so we create one.
865 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
867 (insert "Original-")))
869 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
870 (run-hooks 'nnmail-prepare-incoming-header-hook)
871 ;; Allow the backend to save the article.
874 (goto-char (point-min))
875 (nnmail-check-duplication message-id func artnum-func))
878 (defun nnmail-split-incoming (incoming func &optional exit-func
880 "Go through the entire INCOMING file and pick out each individual mail.
881 FUNC will be called with the buffer narrowed to each mail."
882 (let (;; If this is a group-specific split, we bind the split
883 ;; methods to just this group.
884 (nnmail-split-methods (if (and group
885 (not nnmail-resplit-incoming))
886 (list (list group ""))
887 nnmail-split-methods)))
889 ;; Insert the incoming file.
890 (set-buffer (get-buffer-create " *nnmail incoming*"))
892 (let ((nnheader-file-coding-system nnmail-incoming-coding-system))
893 (nnheader-insert-file-contents incoming))
895 (if (zerop (buffer-size))
897 (goto-char (point-min))
898 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
899 ;; Handle both babyl, MMDF and unix mail formats, since
900 ;; movemail will use the former when fetching from a
901 ;; mailbox, the latter when fetching from a file.
902 (cond ((or (looking-at "\^L")
903 (looking-at "BABYL OPTIONS:"))
904 (nnmail-process-babyl-mail-format func artnum-func))
905 ((looking-at "\^A\^A\^A\^A")
906 (nnmail-process-mmdf-mail-format func artnum-func))
907 ((looking-at "Return-Path:")
908 (nnmail-process-maildir-mail-format func artnum-func))
910 (nnmail-process-unix-mail-format func artnum-func))))
913 (kill-buffer (current-buffer))))))
915 (defun nnmail-article-group (func &optional trace)
916 "Look at the headers and return an alist of groups that match.
917 FUNC will be called with the group name to determine the article number."
918 (let ((methods nnmail-split-methods)
919 (obuf (current-buffer))
921 end group-art method grp)
922 (if (and (sequencep methods)
923 (= (length methods) 1))
924 ;; If there is only just one group to put everything in, we
925 ;; just return a list with just this one method in.
927 (list (cons (caar methods) (funcall func (caar methods)))))
928 ;; We do actual comparison.
932 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
933 (set-buffer nntp-server-buffer)
935 ;; Copy the headers into the work buffer.
936 (insert-buffer-substring obuf beg end)
937 ;; Fold continuation lines.
938 (goto-char (point-min))
939 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
940 (replace-match " " t t))
941 ;; Nuke pathologically long headers. Since Gnus applies
942 ;; pathologically complex regexps to the buffer, lines
943 ;; that are looong will take longer than the Universe's
944 ;; existence to process.
945 (goto-char (point-min))
947 (unless (< (move-to-column nnmail-split-header-length-limit)
948 nnmail-split-header-length-limit)
949 (delete-region (point) (progn (end-of-line) (point))))
952 (goto-char (point-min))
953 (run-hooks 'nnmail-split-hook)
954 (when (setq nnmail-split-tracing trace)
955 (setq nnmail-split-trace nil))
956 (if (and (symbolp nnmail-split-methods)
957 (fboundp nnmail-split-methods))
960 ;; `nnmail-split-methods' is a function, so we
961 ;; just call this function here and use the
963 (or (funcall nnmail-split-methods)
967 "Error in `nnmail-split-methods'; using `bogus' mail group")
970 (setq split (gnus-remove-duplicates split))
971 ;; The article may be "cross-posted" to `junk'. What
972 ;; to do? Just remove the `junk' spec. Don't really
973 ;; see anything else to do...
975 (while (setq elem (car (memq 'junk split)))
976 (setq split (delq elem split))))
980 (lambda (group) (cons group (funcall func group)))
982 ;; Go through the split methods to find a match.
986 (goto-char (point-max))
987 (setq method (pop methods)
990 (not (equal "" (nth 1 method))))
993 (if (stringp (nth 1 method))
994 (let ((expand (string-match "\\\\[0-9&]" grp))
995 (pos (re-search-backward (cadr method)
998 (setq grp (nnmail-expand-newtext grp)))
1000 ;; Function to say whether this is a match.
1001 (funcall (nth 1 method) grp)))
1002 ;; Don't enter the article into the same
1004 (not (assoc grp group-art)))
1005 (push (cons grp (funcall func grp))
1007 ;; This is the final group, which is used as a
1011 (list (cons (car method)
1012 (funcall func (car method)))))))))
1013 ;; Produce a trace if non-empty.
1014 (when (and trace nnmail-split-trace)
1015 (let ((trace (nreverse nnmail-split-trace))
1016 (restore (current-buffer)))
1017 (nnheader-set-temp-buffer "*Split Trace*")
1020 (insert (car trace) "\n")
1021 (setq trace (cdr trace)))
1022 (goto-char (point-min))
1023 (gnus-configure-windows 'split-trace)
1024 (set-buffer restore)))
1025 ;; See whether the split methods returned `junk'.
1026 (if (equal group-art '(junk))
1028 ;; The article may be "cross-posted" to `junk'. What
1029 ;; to do? Just remove the `junk' spec. Don't really
1030 ;; see anything else to do...
1032 (while (setq elem (car (memq 'junk group-art)))
1033 (setq group-art (delq elem group-art)))
1034 (nreverse group-art)))))))
1036 (defun nnmail-insert-lines ()
1037 "Insert how many lines there are in the body of the mail.
1038 Return the number of characters in the body."
1041 (goto-char (point-min))
1042 (unless (search-forward "\n\n" nil t)
1043 (goto-char (point-max))
1045 (setq chars (- (point-max) (point)))
1046 (setq lines (count-lines (point) (point-max)))
1049 (when (re-search-backward "^Lines: " nil t)
1050 (delete-region (point) (progn (forward-line 1) (point)))))
1052 (insert (format "Lines: %d\n" (max lines 0)))
1055 (defun nnmail-insert-xref (group-alist)
1056 "Insert an Xref line based on the (group . article) alist."
1058 (goto-char (point-min))
1059 (unless (search-forward "\n\n" nil t)
1060 (goto-char (point-max))
1063 (when (re-search-backward "^Xref: " nil t)
1064 (delete-region (match-beginning 0)
1065 (progn (forward-line 1) (point))))
1066 (insert (format "Xref: %s" (system-name)))
1068 (insert (format " %s:%d"
1069 (encode-coding-string
1071 nnmail-pathname-coding-system)
1072 (cdar group-alist)))
1073 (setq group-alist (cdr group-alist)))
1076 ;;; Message washing functions
1078 (defun nnmail-remove-leading-whitespace ()
1079 "Remove excessive whitespace from all headers."
1080 (goto-char (point-min))
1081 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
1082 (replace-match "\\1" t)))
1084 (defun nnmail-remove-list-identifiers ()
1085 "Remove list identifiers from Subject headers."
1086 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
1087 (mapconcat 'identity nnmail-list-identifiers " *\\|"))))
1089 (goto-char (point-min))
1090 (when (re-search-forward
1091 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1093 (delete-region (match-beginning 2) (match-end 0))))))
1095 (defun nnmail-remove-tabs ()
1096 "Translate TAB characters into SPACE characters."
1097 (subst-char-in-region (point-min) (point-max) ?\t ? t))
1099 (defun nnmail-fix-eudora-headers ()
1100 "Eudora has a broken References line, but an OK In-Reply-To."
1101 (goto-char (point-min))
1102 (when (re-search-forward "^X-Mailer:.*Eudora" nil t)
1103 (goto-char (point-min))
1104 (when (re-search-forward "^References:" nil t)
1106 (insert "X-Gnus-Broken-Eudora-"))
1107 (goto-char (point-min))
1108 (when (re-search-forward "^In-Reply-To:[^\n]+\\(\n[ \t]+\\)" nil t)
1109 (replace-match "" t t nil 1))))
1111 (custom-add-option 'nnmail-prepare-incoming-header-hook
1112 'nnmail-fix-eudora-headers)
1114 ;;; Utility functions
1116 (defun nnmail-split-fancy ()
1117 "Fancy splitting method.
1118 See the documentation for the variable `nnmail-split-fancy' for documentation."
1119 (let ((syntab (syntax-table)))
1122 (set-syntax-table nnmail-split-fancy-syntax-table)
1123 (nnmail-split-it nnmail-split-fancy))
1124 (set-syntax-table syntab))))
1126 (defvar nnmail-split-cache nil)
1127 ;; Alist of split expressions their equivalent regexps.
1129 (defun nnmail-split-it (split)
1130 ;; Return a list of groups matching SPLIT.
1137 ;; A group name. Do the \& and \N subs into the string.
1139 (when nnmail-split-tracing
1140 (push (format "\"%s\"" split) nnmail-split-trace))
1141 (list (nnmail-expand-newtext split)))
1143 ;; Junk the message.
1145 (when nnmail-split-tracing
1146 (push "junk" nnmail-split-trace))
1149 ;; Builtin & operation.
1150 ((eq (car split) '&)
1151 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
1153 ;; Builtin | operation.
1154 ((eq (car split) '|)
1156 (while (and (not done) (cdr split))
1157 (setq split (cdr split)
1158 done (nnmail-split-it (car split))))
1161 ;; Builtin : operation.
1162 ((eq (car split) ':)
1163 (nnmail-split-it (save-excursion (eval (cdr split)))))
1165 ;; Builtin ! operation.
1166 ((eq (car split) '!)
1167 (funcall (cadr split) (nnmail-split-it (caddr split))))
1169 ;; Check the cache for the regexp for this split.
1170 ((setq cached-pair (assq split nnmail-split-cache))
1172 (end-point (point-max))
1173 (value (nth 1 split)))
1175 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1176 (while (and (goto-char end-point)
1177 (re-search-backward (cdr cached-pair) nil t))
1178 (when nnmail-split-tracing
1179 (push (cdr cached-pair) nnmail-split-trace))
1180 (let ((split-rest (cddr split))
1182 ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\). So,
1183 ;; start-of-value is the the point just before the
1184 ;; beginning of the value, whereas after-header-name is
1185 ;; the point just after the field name.
1186 (start-of-value (match-end 1))
1187 (after-header-name (match-end 2)))
1188 ;; Start the next search just before the beginning of the
1190 (setq end-point (1- start-of-value))
1191 ;; Handle - RESTRICTs
1192 (while (eq (car split-rest) '-)
1193 ;; RESTRICT must start after-header-name and
1194 ;; end after start-of-value, so that, for
1195 ;; (any "foo" - "x-foo" "foo.list")
1196 ;; we do not exclude foo.list just because
1197 ;; the header is: ``To: x-foo, foo''
1199 (if (and (re-search-backward (cadr split-rest)
1200 after-header-name t)
1201 (> (match-end 0) start-of-value))
1202 (setq split-rest nil)
1203 (setq split-rest (cddr split-rest))))
1206 (let ((value (nth 1 split)))
1208 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1209 ;; Someone might want to do a \N sub on this match, so get the
1210 ;; correct match positions.
1211 (re-search-backward (concat "\\<" value "\\>") start-of-value))
1212 (dolist (sp (nnmail-split-it (car split-rest)))
1213 (unless (memq sp split-result)
1214 (push sp split-result))))))
1217 ;; Not in cache, compute a regexp for the field/value pair.
1219 (let* ((field (nth 0 split))
1220 (value (nth 1 split))
1223 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1224 (if (and (>= (length value) 2)
1225 (string= ".*" (substring value 0 2)))
1226 (setq value (substring value 2)
1228 (setq regexp (concat "^\\(\\("
1230 (cdr (assq field nnmail-split-abbrev-alist))
1237 (push (cons split regexp) nnmail-split-cache)
1238 ;; Now that it's in the cache, just call nnmail-split-it again
1239 ;; on the same split, which will find it immediately in the cache.
1240 (nnmail-split-it split))))))
1242 (defun nnmail-expand-newtext (newtext)
1243 (let ((len (length newtext))
1245 c expanded beg N did-expand)
1248 (while (and (< pos len)
1249 (not (= (aref newtext pos) ?\\)))
1250 (setq pos (1+ pos)))
1252 (push (substring newtext beg pos) expanded))
1254 ;; We hit a \; expand it.
1257 c (aref newtext pos))
1258 (if (not (or (= c ?\&)
1261 ;; \ followed by some character we don't expand.
1262 (push (char-to-string c) expanded)
1267 (when (match-beginning N)
1268 (push (buffer-substring (match-beginning N) (match-end N))
1270 (setq pos (1+ pos)))
1272 (apply 'concat (nreverse expanded))
1275 ;; Activate a backend only if it isn't already activated.
1276 ;; If FORCE, re-read the active file even if the backend is
1277 ;; already activated.
1278 (defun nnmail-activate (backend &optional force)
1279 (nnheader-init-server-buffer)
1280 (let (file timestamp file-time)
1281 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
1283 (and (setq file (ignore-errors
1284 (symbol-value (intern (format "%s-active-file"
1286 (setq file-time (nth 5 (file-attributes file)))
1290 (symbol-value (intern
1291 (format "%s-active-timestamp"
1294 (not (consp timestamp))
1295 (equal timestamp '(0 0))
1296 (> (nth 0 file-time) (nth 0 timestamp))
1297 (and (= (nth 0 file-time) (nth 0 timestamp))
1298 (> (nth 1 file-time) (nth 1 timestamp))))))
1300 (or (eq timestamp 'none)
1301 (set (intern (format "%s-active-timestamp" backend))
1303 (funcall (intern (format "%s-request-list" backend)))))
1306 (defun nnmail-message-id ()
1307 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1310 ;;; nnmail duplicate handling
1313 (defvar nnmail-cache-buffer nil)
1315 (defun nnmail-cache-open ()
1316 (if (or (not nnmail-treat-duplicates)
1317 (and nnmail-cache-buffer
1318 (buffer-name nnmail-cache-buffer)))
1319 () ; The buffer is open.
1322 (setq nnmail-cache-buffer
1323 (get-buffer-create " *nnmail message-id cache*")))
1324 (when (file-exists-p nnmail-message-id-cache-file)
1325 (nnheader-insert-file-contents nnmail-message-id-cache-file))
1326 (set-buffer-modified-p nil)
1329 (defun nnmail-cache-close ()
1330 (when (and nnmail-cache-buffer
1331 nnmail-treat-duplicates
1332 (buffer-name nnmail-cache-buffer)
1333 (buffer-modified-p nnmail-cache-buffer))
1335 (set-buffer nnmail-cache-buffer)
1336 ;; Weed out the excess number of Message-IDs.
1337 (goto-char (point-max))
1338 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
1341 (delete-region (point-min) (point))))
1343 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
1344 (make-directory (file-name-directory nnmail-message-id-cache-file)
1346 (nnmail-write-region (point-min) (point-max)
1347 nnmail-message-id-cache-file nil 'silent)
1348 (set-buffer-modified-p nil)
1349 (setq nnmail-cache-buffer nil)
1350 (kill-buffer (current-buffer)))))
1352 ;; Compiler directives.
1354 (defvar group-art-list)
1356 (defun nnmail-cache-insert (id)
1357 (when nnmail-treat-duplicates
1358 ;; Store some information about the group this message is written
1359 ;; to. This function might have been called from various places.
1360 ;; Sometimes, a function up in the calling sequence has an
1361 ;; argument GROUP which is bound to a string, the group name. At
1362 ;; other times, there is a function up in the calling sequence
1363 ;; which has an argument GROUP-ART which is a list of pairs, and
1364 ;; the car of a pair is a group name. Should we check that the
1365 ;; length of the list is equal to 1? -- kai
1367 (cond ((and (boundp 'group) group)
1369 ((and (boundp 'group-art-list) group-art-list
1370 (listp group-art-list))
1371 (setq g (caar group-art-list)))
1372 ((and (boundp 'group-art) group-art (listp group-art))
1373 (setq g (caar group-art)))
1375 (unless (gnus-buffer-live-p nnmail-cache-buffer)
1376 (nnmail-cache-open))
1378 (set-buffer nnmail-cache-buffer)
1379 (goto-char (point-max))
1380 (if (and g (not (string= "" g))
1381 (gnus-methods-equal-p gnus-command-method
1382 (nnmail-cache-primary-mail-backend)))
1383 (insert id "\t" g "\n")
1384 (insert id "\n"))))))
1386 (defun nnmail-cache-primary-mail-backend ()
1387 (let ((be-list (cons gnus-select-method gnus-secondary-select-methods))
1390 (while (and (null res) be-list)
1391 (setq be (car be-list))
1392 (setq be-list (cdr be-list))
1393 (when (and (gnus-method-option-p be 'respool)
1394 (eval (intern (format "%s-get-new-mail" (car be)))))
1398 ;; Fetch the group name corresponding to the message id stored in the
1400 (defun nnmail-cache-fetch-group (id)
1401 (when (and nnmail-treat-duplicates nnmail-cache-buffer)
1403 (set-buffer nnmail-cache-buffer)
1404 (goto-char (point-max))
1405 (when (search-backward id nil t)
1407 (skip-chars-forward "^\n\r\t")
1410 (buffer-substring (point)
1411 (progn (end-of-line) (point))))))))
1413 ;; Function for nnmail-split-fancy: look up all references in the
1414 ;; cache and if a match is found, return that group.
1415 (defun nnmail-split-fancy-with-parent ()
1416 (let* ((refstr (or (message-fetch-field "references")
1417 (message-fetch-field "in-reply-to")))
1421 (setq references (nreverse (gnus-split-references refstr)))
1422 (unless (gnus-buffer-live-p nnmail-cache-buffer)
1423 (nnmail-cache-open))
1425 (setq res (or (nnmail-cache-fetch-group x) res))
1426 (when (string= "drafts" res)
1431 (defun nnmail-cache-id-exists-p (id)
1432 (when nnmail-treat-duplicates
1434 (set-buffer nnmail-cache-buffer)
1435 (goto-char (point-max))
1436 (search-backward id nil t))))
1438 (defun nnmail-fetch-field (header)
1441 (message-narrow-to-head)
1442 (message-fetch-field header))))
1444 (defun nnmail-check-duplication (message-id func artnum-func)
1445 (run-hooks 'nnmail-prepare-incoming-message-hook)
1446 ;; If this is a duplicate message, then we do not save it.
1447 (let* ((duplication (nnmail-cache-id-exists-p message-id))
1448 (case-fold-search t)
1449 (action (when duplication
1451 ((memq nnmail-treat-duplicates '(warn delete))
1452 nnmail-treat-duplicates)
1453 ((nnheader-functionp nnmail-treat-duplicates)
1454 (funcall nnmail-treat-duplicates message-id))
1456 nnmail-treat-duplicates))))
1458 ;; We insert a line that says what the mail source is.
1459 (let ((case-fold-search t))
1460 (goto-char (point-min))
1461 (re-search-forward "^message-id[ \t]*:" nil t)
1463 (insert (format "X-Gnus-Mail-Source: %s\n" mail-source-string)))
1465 ;; Let the backend save the article (or not).
1468 (funcall func (setq group-art
1469 (nreverse (nnmail-article-group artnum-func))))
1470 (nnmail-cache-insert message-id))
1471 ((eq action 'delete)
1472 (setq group-art nil))
1474 ;; We insert a warning.
1475 (let ((case-fold-search t))
1476 (goto-char (point-min))
1477 (re-search-forward "^message-id[ \t]*:" nil t)
1480 "Gnus-Warning: This is a duplicate of message " message-id "\n")
1481 (funcall func (setq group-art
1482 (nreverse (nnmail-article-group artnum-func))))))
1484 (funcall func (setq group-art
1485 (nreverse (nnmail-article-group artnum-func))))))
1486 ;; Add the group-art list to the history list.
1488 (push group-art nnmail-split-history)
1489 (delete-region (point-min) (point-max)))))
1493 (defvar nnmail-fetched-sources nil)
1495 (defun nnmail-get-value (&rest args)
1496 (let ((sym (intern (apply 'format args))))
1498 (symbol-value sym))))
1500 (defun nnmail-get-new-mail (method exit-func temp
1501 &optional group spool-func)
1502 "Read new incoming mail."
1503 (let* ((sources (or mail-sources
1504 (if (listp nnmail-spool-file) nnmail-spool-file
1505 (list nnmail-spool-file))))
1511 incoming incomings source)
1512 (when (and (nnmail-get-value "%s-get-new-mail" method)
1514 (while (setq source (pop sources))
1515 ;; Be compatible with old values.
1520 ((string-match "^po:" source)
1521 (list 'pop :user (substring source (match-end 0))))
1522 ((file-directory-p source)
1523 (list 'directory :path source))
1525 (list 'file :path source)))))
1526 ((eq source 'procmail)
1527 (message "Invalid value for nnmail-spool-file: `procmail'")
1529 ;; Hack to only fetch the contents of a single group's spool file.
1530 (when (and (eq (car source) 'directory)
1532 (mail-source-bind (directory source)
1533 (setq source (append source
1539 (regexp-quote (concat group suffix))
1542 (when nnmail-fetched-sources
1543 (if (member source nnmail-fetched-sources)
1545 (push source nnmail-fetched-sources)
1546 (push source fetching-sources)))))
1547 (when fetching-sources
1548 ;; We first activate all the groups.
1549 (nnmail-activate method)
1550 ;; Allow the user to hook.
1551 (run-hooks 'nnmail-pre-get-new-mail-hook)
1552 ;; Open the message-id cache.
1554 ;; The we go through all the existing mail source specification
1555 ;; and fetch the mail from each.
1556 (while (setq source (pop fetching-sources))
1557 (nnheader-message 4 "%s: Reading incoming mail from %s..."
1558 method (car source))
1562 `(lambda (file orig-file)
1563 (nnmail-split-incoming
1564 file ',(intern (format "%s-save-mail" method))
1566 (nnmail-get-split-group orig-file source)
1567 ',(intern (format "%s-active-number" method))))))
1570 ;; If we did indeed read any incoming spools, we save all info.
1572 (nnheader-message 4 "%s: Reading incoming mail (no new mail)...done"
1573 method (car source))
1575 (nnmail-get-value "%s-group-alist" method)
1576 (nnmail-get-value "%s-active-file" method))
1578 (funcall exit-func))
1579 (run-hooks 'nnmail-read-incoming-hook)
1580 (nnheader-message 4 "%s: Reading incoming mail (%d new)...done" method
1582 ;; Close the message-id cache.
1583 (nnmail-cache-close)
1584 ;; Allow the user to hook.
1585 (run-hooks 'nnmail-post-get-new-mail-hook))))
1587 (defun nnmail-expired-article-p (group time force &optional inhibit)
1588 "Say whether an article that is TIME old in GROUP should be expired."
1591 (let ((days (or (and nnmail-expiry-wait-function
1592 (funcall nnmail-expiry-wait-function group))
1593 nnmail-expiry-wait)))
1594 (cond ((or (eq days 'never)
1597 ;; This isn't an expirable group.
1599 ((eq days 'immediate)
1600 ;; We expire all articles on sight.
1602 ((equal time '(0 0))
1603 ;; This is an ange-ftp group, and we don't have any dates.
1606 (setq days (days-to-time days))
1607 ;; Compare the time with the current time.
1608 (ignore-errors (time-less-p days (time-since time))))))))
1610 (defun nnmail-expiry-target-group (target group)
1611 (when (nnheader-functionp target)
1612 (setq target (funcall target group)))
1613 (unless (eq target 'delete)
1614 (gnus-request-accept-article target)))
1616 (defun nnmail-check-syntax ()
1617 "Check (and modify) the syntax of the message in the current buffer."
1619 (message-narrow-to-head)
1620 (let ((case-fold-search t))
1621 (unless (re-search-forward "^Message-ID[ \t]*:" nil t)
1622 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1624 (defun nnmail-write-region (start end filename &optional append visit lockname)
1625 "Do a `write-region', and then set the file modes."
1626 (let ((pathname-coding-system nnmail-pathname-coding-system))
1628 (write-region-as-coding-system
1629 nnmail-file-coding-system start end filename append visit lockname)
1630 (set-file-modes filename nnmail-default-file-modes)))
1633 ;;; Status functions
1636 (defun nnmail-replace-status (name value)
1637 "Make status NAME and VALUE part of the current status line."
1639 (message-narrow-to-head)
1640 (let ((status (nnmail-decode-status)))
1641 (setq status (delq (member name status) status))
1643 (push (cons name value) status))
1644 (message-remove-header "status")
1645 (goto-char (point-max))
1646 (insert "Status: " (nnmail-encode-status status) "\n"))))
1648 (defun nnmail-decode-status ()
1649 "Return a status-value alist from STATUS."
1650 (goto-char (point-min))
1651 (when (re-search-forward "^Status: " nil t)
1652 (let (name value status)
1654 ;; Narrow to the status.
1657 (if (re-search-forward "^[^ \t]" nil t)
1660 ;; Go through all elements and add them to the list.
1661 (goto-char (point-min))
1662 (while (re-search-forward "[^ \t=]+" nil t)
1663 (setq name (match-string 0))
1664 (if (not (eq (char-after) ?=))
1668 (if (not (eq (char-after) ?\"))
1669 (if (not (looking-at "[^ \t]"))
1673 (setq value (match-string 0))
1674 (goto-char (match-end 0)))
1676 (setq value (read (current-buffer)))))
1677 (push (cons name value) status)))
1680 (defun nnmail-encode-status (status)
1681 "Return a status string from STATUS."
1686 (if (string-match "[ \t]" (cdr elem))
1687 (prin1-to-string (cdr elem))
1691 (defun nnmail-split-history ()
1692 "Generate an overview of where the last mail split put articles."
1694 (unless nnmail-split-history
1695 (error "No current split history"))
1696 (with-output-to-temp-buffer "*nnmail split history*"
1697 (with-current-buffer standard-output
1698 (fundamental-mode)) ; for Emacs 20.4+
1699 (let ((history nnmail-split-history)
1701 (while (setq elem (pop history))
1702 (princ (mapconcat (lambda (ga)
1703 (concat (car ga) ":" (int-to-string (cdr ga))))
1708 (defun nnmail-purge-split-history (group)
1709 "Remove all instances of GROUP from `nnmail-split-history'."
1710 (let ((history nnmail-split-history))
1712 (setcar history (gnus-delete-if (lambda (e) (string= (car e) group))
1715 (setq nnmail-split-history (delq nil nnmail-split-history))))
1717 (defun nnmail-new-mail-p (group)
1718 "Say whether GROUP has new mail."
1719 (let ((his nnmail-split-history)
1722 (when (assoc group (pop his))
1727 (defun nnmail-new-mail-numbers (group)
1728 "Say how many articles has been incorporated to GROUP."
1729 (let ((his (apply 'append nnmail-split-history))
1732 (when (string= group (caar his))
1733 (push (cdar his) numbers))
1734 (setq his (cdr his)))
1737 (defun nnmail-within-headers-p ()
1738 "Check to see if point is within the headers of a unix mail message.
1739 Doesn't change point."
1740 (let ((pos (point)))
1742 (and (nnmail-search-unix-mail-delim-backward)
1743 (not (search-forward "\n\n" pos t))))))
1745 (run-hooks 'nnmail-load-hook)
1749 ;;; nnmail.el ends here