1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
34 (require 'mail-source)
37 (autoload 'gnus-error "gnus-util")
38 (autoload 'gnus-buffer-live-p "gnus-util"))
40 (eval-when-compile (require 'static))
42 (static-condition-case nil
43 :symbol-for-testing-whether-colon-keyword-is-available-or-not
45 (defconst :user ':user)
46 (defconst :path ':path)
47 (defconst :predicate ':predicate)))
50 "Reading mail with Gnus."
53 (defgroup nnmail-retrieve nil
54 "Retrieving new mail."
57 (defgroup nnmail-prepare nil
58 "Preparing (or mangling) new mail after retrival."
61 (defgroup nnmail-duplicate nil
62 "Handling of duplicate mail messages."
65 (defgroup nnmail-split nil
66 "Organizing the incomming mail in folders."
69 (defgroup nnmail-files nil
74 (defgroup nnmail-expire nil
78 (defgroup nnmail-procmail nil
79 "Interfacing with procmail and other mail agents."
82 (defgroup nnmail-various nil
83 "Various mail options."
86 (defcustom nnmail-split-methods
88 "*Incoming mail will be split according to this variable.
90 If you'd like, for instance, one mail group for mail from the
91 \"4ad-l\" mailing list, one group for junk mail and one for everything
92 else, you could do something like this:
94 (setq nnmail-split-methods
95 '((\"mail.4ad\" \"From:.*4ad\")
96 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
97 (\"mail.misc\" \"\")))
99 As you can see, this variable is a list of lists, where the first
100 element in each \"rule\" is the name of the group (which, by the way,
101 does not have to be called anything beginning with \"mail\",
102 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
103 nnmail will try to match on the header to find a fit.
105 The second element can also be a function. In that case, it will be
106 called narrowed to the headers with the first element of the rule as
107 the argument. It should return a non-nil value if it thinks that the
108 mail belongs in that group.
110 The last element should always have \"\" as the regexp.
112 This variable can also have a function as its value."
114 :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
115 (function-item nnmail-split-fancy)
116 (function :tag "Other")))
118 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
119 (defcustom nnmail-crosspost t
120 "If non-nil, do crossposting if several split methods match the mail.
121 If nil, the first match found will be used."
125 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
126 (defcustom nnmail-keep-last-article nil
127 "If non-nil, nnmail will never delete/move a group's last article.
128 It can be marked expirable, so it will be deleted when it is no longer last.
130 You may need to set this variable if other programs are putting
131 new mail into folder numbers that Gnus has marked as expired."
132 :group 'nnmail-procmail
133 :group 'nnmail-various
136 (defcustom nnmail-use-long-file-names nil
137 "If non-nil the mail backends will use long file and directory names.
138 If nil, groups like \"mail.misc\" will end up in directories like
143 (defcustom nnmail-default-file-modes 384
144 "Set the mode bits of all new mail files to this integer."
148 (defcustom nnmail-expiry-wait 7
149 "*Expirable articles that are older than this will be expired.
150 This variable can either be a number (which will be interpreted as a
151 number of days) -- this doesn't have to be an integer. This variable
152 can also be `immediate' and `never'."
153 :group 'nnmail-expire
154 :type '(choice (const immediate)
155 (integer :tag "days")
158 (defcustom nnmail-expiry-wait-function nil
159 "Variable that holds function to specify how old articles should be before they are expired.
160 The function will be called with the name of the group that the
161 expiry is to be performed in, and it should return an integer that
162 says how many days an article can be stored before it is considered
163 \"old\". It can also return the values `never' and `immediate'.
167 \(setq nnmail-expiry-wait-function
169 (cond ((string-match \"private\" newsgroup) 31)
170 ((string-match \"junk\" newsgroup) 1)
171 ((string-match \"important\" newsgroup) 'never)
173 :group 'nnmail-expire
174 :type '(choice (const :tag "nnmail-expiry-wait" nil)
175 (function :format "%v" nnmail-)))
177 (defcustom nnmail-cache-accepted-message-ids nil
178 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache."
182 (defcustom nnmail-spool-file '((file))
183 "*Where the mail backends will look for incoming mail.
184 This variable is a list of mail source specifiers.
185 This variable is obsolete; `mail-sources' should be used instead."
189 (defcustom nnmail-resplit-incoming nil
190 "*If non-nil, re-split incoming procmail sorted mail."
191 :group 'nnmail-procmail
194 (defcustom nnmail-delete-file-function 'delete-file
195 "Function called to delete files in some mail backends."
199 (defcustom nnmail-crosspost-link-function
200 (if (string-match "windows-nt\\|emx" (symbol-name system-type))
203 "*Function called to create a copy of a file.
204 This is `add-name-to-file' by default, which means that crossposts
205 will use hard links. If your file system doesn't allow hard
206 links, you could set this variable to `copy-file' instead."
208 :type '(radio (function-item add-name-to-file)
209 (function-item copy-file)
210 (function :tag "Other")))
212 (defcustom nnmail-read-incoming-hook
213 (if (eq system-type 'windows-nt)
214 '(nnheader-ms-strip-cr)
216 "*Hook that will be run after the incoming mail has been transferred.
217 The incoming mail is moved from `nnmail-spool-file' (which normally is
218 something like \"/usr/spool/mail/$user\") to the user's home
219 directory. This hook is called after the incoming mail box has been
220 emptied, and can be used to call any mail box programs you have
221 running (\"xwatch\", etc.)
225 \(add-hook 'nnmail-read-incoming-hook
227 (start-process \"mailsend\" nil
228 \"/local/bin/mailsend\" \"read\" \"mbox\")))
230 If you have xwatch running, this will alert it that mail has been
233 If you use `display-time', you could use something like this:
235 \(add-hook 'nnmail-read-incoming-hook
237 ;; Update the displayed time, since that will clear out
238 ;; the flag that says you have mail.
239 (when (eq (process-status \"display-time\") 'run)
240 (display-time-filter display-time-process \"\"))))"
241 :group 'nnmail-prepare
244 (defcustom nnmail-prepare-incoming-hook nil
245 "Hook called before treating incoming mail.
246 The hook is run in a buffer with all the new, incoming mail."
247 :group 'nnmail-prepare
250 (defcustom nnmail-prepare-incoming-header-hook nil
251 "Hook called narrowed to the headers of each message.
252 This can be used to remove excessive spaces (and stuff like
253 that) from the headers before splitting and saving the messages."
254 :group 'nnmail-prepare
257 (defcustom nnmail-prepare-incoming-message-hook nil
258 "Hook called narrowed to each message."
259 :group 'nnmail-prepare
262 (defcustom nnmail-list-identifiers nil
263 "Regexp that matches list identifiers to be removed.
264 This can also be a list of regexps."
265 :group 'nnmail-prepare
266 :type '(choice (const :tag "none" nil)
268 (repeat :value (".*") regexp)))
270 (defcustom nnmail-pre-get-new-mail-hook nil
271 "Hook called just before starting to handle new incoming mail."
272 :group 'nnmail-retrieve
275 (defcustom nnmail-post-get-new-mail-hook nil
276 "Hook called just after finishing handling new incoming mail."
277 :group 'nnmail-retrieve
280 (defcustom nnmail-split-hook nil
281 "Hook called before deciding where to split an article.
282 The functions in this hook are free to modify the buffer
283 contents in any way they choose -- the buffer contents are
284 discarded after running the split process."
288 (defcustom nnmail-large-newsgroup 50
289 "*The number of the articles which indicates a large newsgroup.
290 If the number of the articles is greater than the value, verbose
291 messages will be shown to indicate the current status."
292 :group 'nnmail-various
295 (defcustom nnmail-split-fancy "mail.misc"
296 "Incoming mail can be split according to this fancy variable.
297 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
299 The format of this variable is SPLIT, where SPLIT can be one of
302 GROUP: Mail will be stored in GROUP (a string).
304 \(FIELD VALUE [- RESTRICT [- RESTRICT [...]]] SPLIT): If the message
305 field FIELD (a regexp) contains VALUE (a regexp), store the messages
306 as specified by SPLIT. If RESTRICT (a regexp) matches some string
307 after FIELD and before the end of the matched VALUE, return NIL,
308 otherwise process SPLIT. Multiple RESTRICTs add up, further
309 restricting the possibility of processing SPLIT.
311 \(| SPLIT...): Process each SPLIT expression until one of them matches.
312 A SPLIT expression is said to match if it will cause the mail
313 message to be stored in one or more groups.
315 \(& SPLIT...): Process each SPLIT expression.
317 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
318 the buffer containing the message headers. The return value FUNCTION
319 should be a split, which is then recursively processed.
321 \(! FUNCTION SPLIT): Call FUNCTION with the result of SPLIT. The
322 return value FUNCTION should be a split, which is then recursively
325 FIELD must match a complete field name. VALUE must match a complete
326 word according to the `nnmail-split-fancy-syntax-table' syntax table.
327 You can use \".*\" in the regexps to match partial field names or words.
329 FIELD and VALUE can also be lisp symbols, in that case they are expanded
330 as specified in `nnmail-split-abbrev-alist'.
332 GROUP can contain \\& and \\N which will substitute from matching
333 \\(\\) patterns in the previous VALUE.
337 \(setq nnmail-split-methods 'nnmail-split-fancy
339 ;; Messages from the mailer daemon are not crossposted to any of
340 ;; the ordinary groups. Warnings are put in a separate group
342 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
344 ;; Non-error messages are crossposted to all relevant
345 ;; groups, but we don't crosspost between the group for the
346 ;; (ding) list and the group for other (ding) related mail.
347 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
348 (\"subject\" \"ding\" \"ding.misc\"))
349 ;; Other mailing lists...
350 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
351 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
352 ;; Both lists below have the same suffix, so prevent
353 ;; cross-posting to mkpkg.list of messages posted only to
354 ;; the bugs- list, but allow cross-posting when the
355 ;; message was really cross-posted.
356 (any \"bugs-mypackage@somewhere\" \"mypkg.bugs\")
357 (any \"mypackage@somewhere\" - \"bugs-mypackage\" \"mypkg.list\")
360 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
361 ;; Unmatched mail goes to the catch all group.
367 (defcustom nnmail-split-abbrev-alist
368 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
369 (mail . "mailer-daemon\\|postmaster\\|uucp")
370 (to . "to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
371 (from . "from\\|sender\\|resent-from")
372 (nato . "to\\|cc\\|resent-to\\|resent-cc")
373 (naany . "from\\|to\\|cc\\|sender\\|resent-from\\|resent-to\\|resent-cc"))
374 "*Alist of abbreviations allowed in `nnmail-split-fancy'."
376 :type '(repeat (cons :format "%v" symbol regexp)))
378 (defcustom nnmail-message-id-cache-length 1000
379 "*The approximate number of Message-IDs nnmail will keep in its cache.
380 If this variable is nil, no checking on duplicate messages will be
382 :group 'nnmail-duplicate
383 :type '(choice (const :tag "disable" nil)
384 (integer :format "%v")))
386 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
387 "*The file name of the nnmail Message-ID cache."
388 :group 'nnmail-duplicate
392 (defcustom nnmail-treat-duplicates 'warn
393 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
394 Three values are valid: nil, which means that nnmail is not to keep a
395 Message-ID cache; `warn', which means that nnmail should insert extra
396 headers to warn the user about the duplication (this is the default);
397 and `delete', which means that nnmail will delete duplicated mails.
399 This variable can also be a function. It will be called from a buffer
400 narrowed to the article in question with the Message-ID as a
401 parameter. It should return nil, `warn' or `delete'."
402 :group 'nnmail-duplicate
403 :type '(choice (const :tag "off" nil)
407 (defcustom nnmail-extra-headers nil
408 "*Extra headers to parse."
410 :type '(repeat symbol))
412 (defcustom nnmail-split-header-length-limit 512
413 "Header lines longer than this limit are excluded from the split function."
417 ;;; Internal variables.
419 (defvar nnmail-split-history nil
420 "List of group/article elements that say where the previous split put messages.")
422 (defvar nnmail-split-fancy-syntax-table nil
423 "Syntax table used by `nnmail-split-fancy'.")
424 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
425 (setq nnmail-split-fancy-syntax-table
426 (copy-syntax-table (standard-syntax-table)))
427 ;; support the %-hack
428 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
430 (defvar nnmail-prepare-save-mail-hook nil
431 "Hook called before saving mail.")
433 (defvar nnmail-split-tracing nil)
434 (defvar nnmail-split-trace nil)
438 (defconst nnmail-version "nnmail 1.0"
443 (defun nnmail-request-post (&optional server)
444 (mail-send-and-exit nil))
446 (defvar nnmail-file-coding-system 'raw-text
447 "Coding system used in nnmail.")
449 (defvar nnmail-incoming-coding-system 'raw-text
450 "Coding system used in reading inbox")
452 (defvar nnmail-pathname-coding-system 'binary
453 "*Coding system for pathname.")
455 (defun nnmail-find-file (file)
456 "Insert FILE in server buffer safely."
457 (set-buffer nntp-server-buffer)
458 (delete-region (point-min) (point-max))
459 (let ((format-alist nil)
460 (after-insert-file-functions nil))
462 (let ((auto-mode-alist (nnheader-auto-mode-alist))
463 (pathname-coding-system nnmail-pathname-coding-system))
464 (insert-file-contents-as-coding-system
465 nnmail-file-coding-system file)
469 (defun nnmail-group-pathname (group dir &optional file)
470 "Make pathname for GROUP."
472 (let ((dir (file-name-as-directory (expand-file-name dir))))
473 (setq group (nnheader-translate-file-chars group))
474 ;; If this directory exists, we use it directly.
475 (if (or nnmail-use-long-file-names
476 (file-directory-p (concat dir group)))
477 (concat dir group "/")
478 ;; If not, we translate dots into slashes.
480 (encode-coding-string
481 (nnheader-replace-chars-in-string group ?. ?/)
482 nnmail-pathname-coding-system)
486 (defun nnmail-get-active ()
487 "Returns an assoc of group names and active ranges.
488 nn*-request-list should have been called before calling this function."
490 ;; Go through all groups from the active list.
492 (set-buffer nntp-server-buffer)
493 (goto-char (point-min))
494 (while (re-search-forward
495 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t)
496 ;; We create an alist with `(GROUP (LOW . HIGH))' elements.
497 (push (list (match-string 1)
498 (cons (string-to-int (match-string 3))
499 (string-to-int (match-string 2))))
503 (defvar nnmail-active-file-coding-system 'raw-text
504 "*Coding system for active file.")
506 (defun nnmail-save-active (group-assoc file-name)
507 "Save GROUP-ASSOC in ACTIVE-FILE."
508 (let ((coding-system-for-write nnmail-active-file-coding-system)
509 (output-coding-system nnmail-active-file-coding-system))
511 (with-temp-file file-name
512 (nnmail-generate-active group-assoc)))))
514 (defun nnmail-generate-active (alist)
515 "Generate an active file from group-alist ALIST."
518 (while (setq group (pop alist))
519 (insert (format "%s %d %d y\n" (car group) (cdadr group)
522 (defun nnmail-get-split-group (file source)
523 "Find out whether this FILE is to be split into GROUP only.
524 If SOURCE is a directory spec, try to return the group name component."
525 (if (eq (car source) 'directory)
526 (let ((file (file-name-nondirectory file)))
527 (mail-source-bind (directory source)
528 (if (string-match (concat (regexp-quote suffix) "$") file)
529 (substring file 0 (match-beginning 0))
533 (defun nnmail-process-babyl-mail-format (func artnum-func)
534 (let ((case-fold-search t)
536 start message-id content-length do-search end)
538 (goto-char (point-min))
540 "
\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
541 (goto-char (match-end 0))
542 (delete-region (match-beginning 0) (match-end 0))
546 ;; Skip all the headers in case there are more "From "s...
547 (or (search-forward "\n\n" nil t)
548 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
549 (search-forward "
\1f\f"))
551 ;; Unquote the ">From " line, if any.
552 (goto-char (point-min))
553 (when (looking-at ">From ")
554 (replace-match "X-From-Line: ") )
555 (run-hooks 'nnmail-prepare-incoming-header-hook)
556 (goto-char (point-max))
557 ;; Find the Message-ID header.
559 (if (re-search-backward
560 "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]*>\\)" nil t)
561 (setq message-id (buffer-substring (match-beginning 1)
563 ;; There is no Message-ID here, so we create one.
565 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
567 (insert "Original-")))
569 (insert "Message-ID: " (setq message-id (nnmail-message-id))
571 ;; Look for a Content-Length header.
572 (if (not (save-excursion
573 (and (re-search-backward
574 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
575 (setq content-length (string-to-int
579 ;; We destroy the header, since none of
580 ;; the backends ever use it, and we do not
581 ;; want to confuse other mailers by having
582 ;; a (possibly) faulty header.
583 (progn (insert "X-") t))))
586 (if (or (= (+ (point) content-length) (point-max))
588 (goto-char (+ (point) content-length))
591 (goto-char (+ (point) content-length))
592 (setq do-search nil))
595 ;; Go to the beginning of the next article - or to the end
598 (if (re-search-forward "^
\1f" nil t)
599 (goto-char (match-beginning 0))
600 (goto-char (1- (point-max)))))
601 (delete-char 1) ; delete ^_
604 (narrow-to-region start (point))
605 (goto-char (point-min))
606 (nnmail-check-duplication message-id func artnum-func)
608 (setq end (point-max))))
612 (defsubst nnmail-search-unix-mail-delim ()
613 "Put point at the beginning of the next Unix mbox message."
614 ;; Algorithm used to find the the next article in the
615 ;; brain-dead Unix mbox format:
617 ;; 1) Search for "^From ".
618 ;; 2) If we find it, then see whether the previous
619 ;; line is blank and the next line looks like a header.
620 ;; Then it's possible that this is a mail delim, and we use it.
621 (let ((case-fold-search nil)
624 (if (not (re-search-forward "^From " nil t))
628 (when (and (or (bobp)
631 (eq (char-after) ?\n)))
634 (while (looking-at ">From \\|From ")
636 (looking-at "[^ \n\t:]+[ \n\t]*:")))
637 (setq found 'yes)))))
641 (defun nnmail-search-unix-mail-delim-backward ()
642 "Put point at the beginning of the current Unix mbox message."
643 ;; Algorithm used to find the the next article in the
644 ;; brain-dead Unix mbox format:
646 ;; 1) Search for "^From ".
647 ;; 2) If we find it, then see whether the previous
648 ;; line is blank and the next line looks like a header.
649 ;; Then it's possible that this is a mail delim, and we use it.
650 (let ((case-fold-search nil)
653 (if (not (re-search-backward "^From " nil t))
657 (when (and (or (bobp)
660 (eq (char-after) ?\n)))
663 (while (looking-at ">From \\|From ")
665 (looking-at "[^ \n\t:]+[ \n\t]*:")))
666 (setq found 'yes)))))
670 (defun nnmail-process-unix-mail-format (func artnum-func)
671 (let ((case-fold-search t)
673 start message-id content-length end skip head-end)
674 (goto-char (point-min))
675 (if (not (and (re-search-forward "^From " nil t)
676 (goto-char (match-beginning 0))))
677 ;; Possibly wrong format?
678 (error "Error, unknown mail format! (Possibly corrupted.)")
679 ;; Carry on until the bitter end.
683 ;; Find the end of the head.
686 (if (search-forward "\n\n" nil t)
688 ;; This will never happen, but just to be on the safe side --
689 ;; if there is no head-body delimiter, we search a bit manually.
690 (while (and (looking-at "From \\|[^ \t]+:")
694 ;; Find the Message-ID header.
695 (goto-char (point-min))
696 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
697 (setq message-id (match-string 1))
699 (when (re-search-forward "^Message-ID[ \t]*:" nil t)
701 (insert "Original-")))
702 ;; There is no Message-ID here, so we create one.
704 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
705 ;; Look for a Content-Length header.
706 (goto-char (point-min))
707 (if (not (re-search-forward
708 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
709 (setq content-length nil)
710 (setq content-length (string-to-int (match-string 1)))
711 ;; We destroy the header, since none of the backends ever
712 ;; use it, and we do not want to confuse other mailers by
713 ;; having a (possibly) faulty header.
716 (run-hooks 'nnmail-prepare-incoming-header-hook)
717 ;; Find the end of this article.
718 (goto-char (point-max))
720 (setq head-end (point))
721 ;; We try the Content-Length value. The idea: skip over the header
722 ;; separator, then check what happens content-length bytes into the
723 ;; message body. This should be either the end ot the buffer, the
724 ;; message separator or a blank line followed by the separator.
725 ;; The blank line should probably be deleted. If neither of the
726 ;; three is met, the content-length header is probably invalid.
729 (setq skip (+ (point) content-length))
731 (cond ((or (= skip (point-max))
732 (= (1+ skip) (point-max)))
733 (setq end (point-max)))
734 ((looking-at "From ")
736 ((looking-at "[ \t]*\n\\(From \\)")
737 (setq end (match-beginning 1)))
741 ;; No Content-Length, so we find the beginning of the next
742 ;; article or the end of the buffer.
744 (or (nnmail-search-unix-mail-delim)
745 (goto-char (point-max))))
746 ;; Allow the backend to save the article.
749 (narrow-to-region start (point))
750 (goto-char (point-min))
752 (nnmail-check-duplication message-id func artnum-func)
753 (setq end (point-max))))
757 (defun nnmail-process-mmdf-mail-format (func artnum-func)
758 (let ((delim "^\^A\^A\^A\^A$")
761 start message-id end)
762 (goto-char (point-min))
763 (if (not (and (re-search-forward delim nil t)
765 ;; Possibly wrong format?
766 (error "Error, unknown mail format! (Possibly corrupted.)")
767 ;; Carry on until the bitter end.
770 ;; Find the end of the head.
773 (if (search-forward "\n\n" nil t)
775 ;; This will never happen, but just to be on the safe side --
776 ;; if there is no head-body delimiter, we search a bit manually.
777 (while (and (looking-at "From \\|[^ \t]+:")
781 ;; Find the Message-ID header.
782 (goto-char (point-min))
783 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t)
784 (setq message-id (match-string 1))
785 ;; There is no Message-ID here, so we create one.
787 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
789 (insert "Original-")))
791 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
792 (run-hooks 'nnmail-prepare-incoming-header-hook)
793 ;; Find the end of this article.
794 (goto-char (point-max))
796 (if (re-search-forward delim nil t)
798 (goto-char (point-max)))
799 ;; Allow the backend to save the article.
802 (narrow-to-region start (point))
803 (goto-char (point-min))
805 (nnmail-check-duplication message-id func artnum-func)
806 (setq end (point-max))))
811 (defun nnmail-process-maildir-mail-format (func artnum-func)
812 ;; In a maildir, every file contains exactly one mail.
813 (let ((case-fold-search t)
815 (goto-char (point-min))
816 ;; Find the end of the head.
819 (if (search-forward "\n\n" nil t)
821 ;; This will never happen, but just to be on the safe side --
822 ;; if there is no head-body delimiter, we search a bit manually.
823 (while (and (looking-at "From \\|[^ \t]+:")
827 ;; Find the Message-ID header.
828 (goto-char (point-min))
829 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
830 (setq message-id (match-string 1))
831 ;; There is no Message-ID here, so we create one.
833 (when (re-search-backward "^Message-ID[ \t]*:" nil t)
835 (insert "Original-")))
837 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
838 (run-hooks 'nnmail-prepare-incoming-header-hook)
839 ;; Allow the backend to save the article.
842 (goto-char (point-min))
843 (nnmail-check-duplication message-id func artnum-func))
846 (defun nnmail-split-incoming (incoming func &optional exit-func
848 "Go through the entire INCOMING file and pick out each individual mail.
849 FUNC will be called with the buffer narrowed to each mail."
850 (let (;; If this is a group-specific split, we bind the split
851 ;; methods to just this group.
852 (nnmail-split-methods (if (and group
853 (not nnmail-resplit-incoming))
854 (list (list group ""))
855 nnmail-split-methods)))
857 ;; Insert the incoming file.
858 (set-buffer (get-buffer-create " *nnmail incoming*"))
860 (let ((nnheader-file-coding-system nnmail-incoming-coding-system))
861 (nnheader-insert-file-contents incoming))
863 (if (zerop (buffer-size))
865 (goto-char (point-min))
866 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
867 ;; Handle both babyl, MMDF and unix mail formats, since
868 ;; movemail will use the former when fetching from a
869 ;; mailbox, the latter when fetching from a file.
870 (cond ((or (looking-at "\^L")
871 (looking-at "BABYL OPTIONS:"))
872 (nnmail-process-babyl-mail-format func artnum-func))
873 ((looking-at "\^A\^A\^A\^A")
874 (nnmail-process-mmdf-mail-format func artnum-func))
875 ((looking-at "Return-Path:")
876 (nnmail-process-maildir-mail-format func artnum-func))
878 (nnmail-process-unix-mail-format func artnum-func))))
881 (kill-buffer (current-buffer))))))
883 (defun nnmail-article-group (func &optional trace)
884 "Look at the headers and return an alist of groups that match.
885 FUNC will be called with the group name to determine the article number."
886 (let ((methods nnmail-split-methods)
887 (obuf (current-buffer))
889 end group-art method grp)
890 (if (and (sequencep methods)
891 (= (length methods) 1))
892 ;; If there is only just one group to put everything in, we
893 ;; just return a list with just this one method in.
895 (list (cons (caar methods) (funcall func (caar methods)))))
896 ;; We do actual comparison.
900 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
901 (set-buffer nntp-server-buffer)
903 ;; Copy the headers into the work buffer.
904 (insert-buffer-substring obuf beg end)
905 ;; Fold continuation lines.
906 (goto-char (point-min))
907 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
908 (replace-match " " t t))
909 ;; Nuke pathologically long headers. Since Gnus applies
910 ;; pathologically complex regexps to the buffer, lines
911 ;; that are looong will take longer than the Universe's
912 ;; existence to process.
913 (goto-char (point-min))
915 (unless (< (move-to-column nnmail-split-header-length-limit)
916 nnmail-split-header-length-limit)
917 (delete-region (point) (progn (end-of-line) (point))))
920 (goto-char (point-min))
921 (run-hooks 'nnmail-split-hook)
922 (when (setq nnmail-split-tracing trace)
923 (setq nnmail-split-trace nil))
924 (if (and (symbolp nnmail-split-methods)
925 (fboundp nnmail-split-methods))
928 ;; `nnmail-split-methods' is a function, so we
929 ;; just call this function here and use the
931 (or (funcall nnmail-split-methods)
935 "Error in `nnmail-split-methods'; using `bogus' mail group")
938 (setq split (gnus-remove-duplicates split))
939 ;; The article may be "cross-posted" to `junk'. What
940 ;; to do? Just remove the `junk' spec. Don't really
941 ;; see anything else to do...
943 (while (setq elem (car (memq 'junk split)))
944 (setq split (delq elem split))))
948 (lambda (group) (cons group (funcall func group)))
950 ;; Go through the split methods to find a match.
954 (goto-char (point-max))
955 (setq method (pop methods)
958 (not (equal "" (nth 1 method))))
961 (if (stringp (nth 1 method))
962 (let ((expand (string-match "\\\\[0-9&]" grp))
963 (pos (re-search-backward (cadr method)
966 (setq grp (nnmail-expand-newtext grp)))
968 ;; Function to say whether this is a match.
969 (funcall (nth 1 method) grp)))
970 ;; Don't enter the article into the same
972 (not (assoc grp group-art)))
973 (push (cons grp (funcall func grp))
975 ;; This is the final group, which is used as a
979 (list (cons (car method)
980 (funcall func (car method)))))))))
981 ;; Produce a trace if non-empty.
982 (when (and trace nnmail-split-trace)
983 (let ((trace (nreverse nnmail-split-trace))
984 (restore (current-buffer)))
985 (nnheader-set-temp-buffer "*Split Trace*")
988 (insert (car trace) "\n")
989 (setq trace (cdr trace)))
990 (goto-char (point-min))
991 (gnus-configure-windows 'split-trace)
992 (set-buffer restore)))
993 ;; See whether the split methods returned `junk'.
994 (if (equal group-art '(junk))
996 ;; The article may be "cross-posted" to `junk'. What
997 ;; to do? Just remove the `junk' spec. Don't really
998 ;; see anything else to do...
1000 (while (setq elem (car (memq 'junk group-art)))
1001 (setq group-art (delq elem group-art)))
1002 (nreverse group-art)))))))
1004 (defun nnmail-insert-lines ()
1005 "Insert how many lines there are in the body of the mail.
1006 Return the number of characters in the body."
1009 (goto-char (point-min))
1010 (unless (search-forward "\n\n" nil t)
1011 (goto-char (point-max))
1013 (setq chars (- (point-max) (point)))
1014 (setq lines (count-lines (point) (point-max)))
1017 (when (re-search-backward "^Lines: " nil t)
1018 (delete-region (point) (progn (forward-line 1) (point)))))
1020 (insert (format "Lines: %d\n" (max lines 0)))
1023 (defun nnmail-insert-xref (group-alist)
1024 "Insert an Xref line based on the (group . article) alist."
1026 (goto-char (point-min))
1027 (unless (search-forward "\n\n" nil t)
1028 (goto-char (point-max))
1031 (when (re-search-backward "^Xref: " nil t)
1032 (delete-region (match-beginning 0)
1033 (progn (forward-line 1) (point))))
1034 (insert (format "Xref: %s" (system-name)))
1036 (insert (format " %s:%d"
1037 (encode-coding-string
1039 nnmail-pathname-coding-system)
1040 (cdar group-alist)))
1041 (setq group-alist (cdr group-alist)))
1044 ;;; Message washing functions
1046 (defun nnmail-remove-leading-whitespace ()
1047 "Remove excessive whitespace from all headers."
1048 (goto-char (point-min))
1049 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
1050 (replace-match "\\1" t)))
1052 (defun nnmail-remove-list-identifiers ()
1053 "Remove list identifiers from Subject headers."
1054 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
1055 (mapconcat 'identity nnmail-list-identifiers " *\\|"))))
1057 (goto-char (point-min))
1058 (when (re-search-forward
1059 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1061 (delete-region (match-beginning 2) (match-end 0))))))
1063 (defun nnmail-remove-tabs ()
1064 "Translate TAB characters into SPACE characters."
1065 (subst-char-in-region (point-min) (point-max) ?\t ? t))
1067 (defun nnmail-fix-eudora-headers ()
1068 "Eudora has a broken References line, but an OK In-Reply-To."
1069 (goto-char (point-min))
1070 (when (re-search-forward "^X-Mailer:.*Eudora" nil t)
1071 (goto-char (point-min))
1072 (when (re-search-forward "^References:" nil t)
1074 (insert "X-Gnus-Broken-Eudora-"))))
1076 (custom-add-option 'nnmail-prepare-incoming-header-hook
1077 'nnmail-fix-eudora-headers)
1079 ;;; Utility functions
1081 (defun nnmail-split-fancy ()
1082 "Fancy splitting method.
1083 See the documentation for the variable `nnmail-split-fancy' for documentation."
1084 (let ((syntab (syntax-table)))
1087 (set-syntax-table nnmail-split-fancy-syntax-table)
1088 (nnmail-split-it nnmail-split-fancy))
1089 (set-syntax-table syntab))))
1091 (defvar nnmail-split-cache nil)
1092 ;; Alist of split expressions their equivalent regexps.
1094 (defun nnmail-split-it (split)
1095 ;; Return a list of groups matching SPLIT.
1102 ;; A group name. Do the \& and \N subs into the string.
1104 (when nnmail-split-tracing
1105 (push (format "\"%s\"" split) nnmail-split-trace))
1106 (list (nnmail-expand-newtext split)))
1108 ;; Junk the message.
1110 (when nnmail-split-tracing
1111 (push "junk" nnmail-split-trace))
1114 ;; Builtin & operation.
1115 ((eq (car split) '&)
1116 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
1118 ;; Builtin | operation.
1119 ((eq (car split) '|)
1121 (while (and (not done) (cdr split))
1122 (setq split (cdr split)
1123 done (nnmail-split-it (car split))))
1126 ;; Builtin : operation.
1127 ((eq (car split) ':)
1128 (nnmail-split-it (save-excursion (eval (cdr split)))))
1130 ;; Builtin ! operation.
1131 ((eq (car split) '!)
1132 (funcall (cadr split) (nnmail-split-it (caddr split))))
1134 ;; Check the cache for the regexp for this split.
1135 ((setq cached-pair (assq split nnmail-split-cache))
1137 (end-point (point-max))
1138 (value (nth 1 split)))
1140 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1141 (while (and (goto-char end-point)
1142 (re-search-backward (cdr cached-pair) nil t))
1143 (when nnmail-split-tracing
1144 (push (cdr cached-pair) nnmail-split-trace))
1145 (let ((split-rest (cddr split))
1147 ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\). So,
1148 ;; start-of-value is the the point just before the
1149 ;; beginning of the value, whereas after-header-name is
1150 ;; the point just after the field name.
1151 (start-of-value (match-end 1))
1152 (after-header-name (match-end 2)))
1153 ;; Start the next search just before the beginning of the
1155 (setq end-point (1- start-of-value))
1156 ;; Handle - RESTRICTs
1157 (while (eq (car split-rest) '-)
1158 ;; RESTRICT must start after-header-name and
1159 ;; end after start-of-value, so that, for
1160 ;; (any "foo" - "x-foo" "foo.list")
1161 ;; we do not exclude foo.list just because
1162 ;; the header is: ``To: x-foo, foo''
1164 (if (and (re-search-backward (cadr split-rest)
1165 after-header-name t)
1166 (> (match-end 0) start-of-value))
1167 (setq split-rest nil)
1168 (setq split-rest (cddr split-rest))))
1171 (let ((value (nth 1 split)))
1173 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1174 ;; Someone might want to do a \N sub on this match, so get the
1175 ;; correct match positions.
1176 (re-search-backward (concat "\\<" value "\\>") start-of-value))
1177 (dolist (sp (nnmail-split-it (car split-rest)))
1178 (unless (memq sp split-result)
1179 (push sp split-result))))))
1182 ;; Not in cache, compute a regexp for the field/value pair.
1184 (let* ((field (nth 0 split))
1185 (value (nth 1 split))
1188 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
1189 (if (and (>= (length value) 2)
1190 (string= ".*" (substring value 0 2)))
1191 (setq value (substring value 2)
1193 (setq regexp (concat "^\\(\\("
1195 (cdr (assq field nnmail-split-abbrev-alist))
1202 (push (cons split regexp) nnmail-split-cache)
1203 ;; Now that it's in the cache, just call nnmail-split-it again
1204 ;; on the same split, which will find it immediately in the cache.
1205 (nnmail-split-it split))))))
1207 (defun nnmail-expand-newtext (newtext)
1208 (let ((len (length newtext))
1210 c expanded beg N did-expand)
1213 (while (and (< pos len)
1214 (not (= (aref newtext pos) ?\\)))
1215 (setq pos (1+ pos)))
1217 (push (substring newtext beg pos) expanded))
1219 ;; We hit a \; expand it.
1222 c (aref newtext pos))
1223 (if (not (or (= c ?\&)
1226 ;; \ followed by some character we don't expand.
1227 (push (char-to-string c) expanded)
1232 (when (match-beginning N)
1233 (push (buffer-substring (match-beginning N) (match-end N))
1235 (setq pos (1+ pos)))
1237 (apply 'concat (nreverse expanded))
1240 ;; Activate a backend only if it isn't already activated.
1241 ;; If FORCE, re-read the active file even if the backend is
1242 ;; already activated.
1243 (defun nnmail-activate (backend &optional force)
1244 (nnheader-init-server-buffer)
1245 (let (file timestamp file-time)
1246 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
1248 (and (setq file (ignore-errors
1249 (symbol-value (intern (format "%s-active-file"
1251 (setq file-time (nth 5 (file-attributes file)))
1255 (symbol-value (intern
1256 (format "%s-active-timestamp"
1259 (not (consp timestamp))
1260 (equal timestamp '(0 0))
1261 (> (nth 0 file-time) (nth 0 timestamp))
1262 (and (= (nth 0 file-time) (nth 0 timestamp))
1263 (> (nth 1 file-time) (nth 1 timestamp))))))
1265 (or (eq timestamp 'none)
1266 (set (intern (format "%s-active-timestamp" backend))
1268 (funcall (intern (format "%s-request-list" backend)))))
1271 (defun nnmail-message-id ()
1272 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1275 ;;; nnmail duplicate handling
1278 (defvar nnmail-cache-buffer nil)
1280 (defun nnmail-cache-open ()
1281 (if (or (not nnmail-treat-duplicates)
1282 (and nnmail-cache-buffer
1283 (buffer-name nnmail-cache-buffer)))
1284 () ; The buffer is open.
1287 (setq nnmail-cache-buffer
1288 (get-buffer-create " *nnmail message-id cache*")))
1289 (when (file-exists-p nnmail-message-id-cache-file)
1290 (nnheader-insert-file-contents nnmail-message-id-cache-file))
1291 (set-buffer-modified-p nil)
1294 (defun nnmail-cache-close ()
1295 (when (and nnmail-cache-buffer
1296 nnmail-treat-duplicates
1297 (buffer-name nnmail-cache-buffer)
1298 (buffer-modified-p nnmail-cache-buffer))
1300 (set-buffer nnmail-cache-buffer)
1301 ;; Weed out the excess number of Message-IDs.
1302 (goto-char (point-max))
1303 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
1306 (delete-region (point-min) (point))))
1308 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
1309 (make-directory (file-name-directory nnmail-message-id-cache-file)
1311 (nnmail-write-region (point-min) (point-max)
1312 nnmail-message-id-cache-file nil 'silent)
1313 (set-buffer-modified-p nil)
1314 (setq nnmail-cache-buffer nil)
1315 (kill-buffer (current-buffer)))))
1317 (defun nnmail-cache-insert (id)
1318 (when nnmail-treat-duplicates
1319 (unless (gnus-buffer-live-p nnmail-cache-buffer)
1320 (nnmail-cache-open))
1322 (set-buffer nnmail-cache-buffer)
1323 (goto-char (point-max))
1326 (defun nnmail-cache-id-exists-p (id)
1327 (when nnmail-treat-duplicates
1329 (set-buffer nnmail-cache-buffer)
1330 (goto-char (point-max))
1331 (search-backward id nil t))))
1333 (defun nnmail-fetch-field (header)
1336 (message-narrow-to-head)
1337 (message-fetch-field header))))
1339 (defun nnmail-check-duplication (message-id func artnum-func)
1340 (run-hooks 'nnmail-prepare-incoming-message-hook)
1341 ;; If this is a duplicate message, then we do not save it.
1342 (let* ((duplication (nnmail-cache-id-exists-p message-id))
1343 (case-fold-search t)
1344 (action (when duplication
1346 ((memq nnmail-treat-duplicates '(warn delete))
1347 nnmail-treat-duplicates)
1348 ((nnheader-functionp nnmail-treat-duplicates)
1349 (funcall nnmail-treat-duplicates message-id))
1351 nnmail-treat-duplicates))))
1353 ;; We insert a line that says what the mail source is.
1354 (let ((case-fold-search t))
1355 (goto-char (point-min))
1356 (re-search-forward "^message-id[ \t]*:" nil t)
1358 (insert (format "X-Gnus-Mail-Source: %s\n" mail-source-string)))
1360 ;; Let the backend save the article (or not).
1363 (funcall func (setq group-art
1364 (nreverse (nnmail-article-group artnum-func))))
1365 (nnmail-cache-insert message-id))
1366 ((eq action 'delete)
1367 (setq group-art nil))
1369 ;; We insert a warning.
1370 (let ((case-fold-search t))
1371 (goto-char (point-min))
1372 (re-search-forward "^message-id[ \t]*:" nil t)
1375 "Gnus-Warning: This is a duplicate of message " message-id "\n")
1376 (funcall func (setq group-art
1377 (nreverse (nnmail-article-group artnum-func))))))
1379 (funcall func (setq group-art
1380 (nreverse (nnmail-article-group artnum-func))))))
1381 ;; Add the group-art list to the history list.
1383 (push group-art nnmail-split-history)
1384 (delete-region (point-min) (point-max)))))
1388 (defvar nnmail-fetched-sources nil)
1390 (defun nnmail-get-value (&rest args)
1391 (let ((sym (intern (apply 'format args))))
1393 (symbol-value sym))))
1395 (defun nnmail-get-new-mail (method exit-func temp
1396 &optional group spool-func)
1397 "Read new incoming mail."
1398 (let* ((sources (or mail-sources
1399 (if (listp nnmail-spool-file) nnmail-spool-file
1400 (list nnmail-spool-file))))
1405 incoming incomings source)
1406 (when (and (nnmail-get-value "%s-get-new-mail" method)
1408 ;; We first activate all the groups.
1409 (nnmail-activate method)
1410 ;; Allow the user to hook.
1411 (run-hooks 'nnmail-pre-get-new-mail-hook)
1412 ;; Open the message-id cache.
1414 ;; The we go through all the existing mail source specification
1415 ;; and fetch the mail from each.
1416 (while (setq source (pop sources))
1417 ;; Be compatible with old values.
1422 ((string-match "^po:" source)
1423 (list 'pop :user (substring source (match-end 0))))
1424 ((file-directory-p source)
1425 (list 'directory :path source))
1427 (list 'file :path source)))))
1428 ((eq source 'procmail)
1429 (message "Invalid value for nnmail-spool-file: `procmail'")
1431 ;; Hack to only fetch the contents of a single group's spool file.
1432 (when (and (eq (car source) 'directory)
1434 (mail-source-bind (directory source)
1435 (setq source (append source
1441 (regexp-quote (concat group suffix))
1444 (when nnmail-fetched-sources
1445 (if (member source nnmail-fetched-sources)
1447 (push source nnmail-fetched-sources)))
1449 (nnheader-message 4 "%s: Reading incoming mail from %s..."
1450 method (car source))
1454 `(lambda (file orig-file)
1455 (nnmail-split-incoming
1456 file ',(intern (format "%s-save-mail" method))
1458 (nnmail-get-split-group orig-file source)
1459 ',(intern (format "%s-active-number" method))))))
1462 ;; If we did indeed read any incoming spools, we save all info.
1464 (nnheader-message 4 "%s: Reading incoming mail (no new mail)...done"
1465 method (car source))
1467 (nnmail-get-value "%s-group-alist" method)
1468 (nnmail-get-value "%s-active-file" method))
1470 (funcall exit-func))
1471 (run-hooks 'nnmail-read-incoming-hook)
1472 (nnheader-message 4 "%s: Reading incoming mail (%d new)...done" method
1474 ;; Close the message-id cache.
1475 (nnmail-cache-close)
1476 ;; Allow the user to hook.
1477 (run-hooks 'nnmail-post-get-new-mail-hook))))
1479 (defun nnmail-expired-article-p (group time force &optional inhibit)
1480 "Say whether an article that is TIME old in GROUP should be expired."
1483 (let ((days (or (and nnmail-expiry-wait-function
1484 (funcall nnmail-expiry-wait-function group))
1485 nnmail-expiry-wait)))
1486 (cond ((or (eq days 'never)
1489 ;; This isn't an expirable group.
1491 ((eq days 'immediate)
1492 ;; We expire all articles on sight.
1494 ((equal time '(0 0))
1495 ;; This is an ange-ftp group, and we don't have any dates.
1498 (setq days (days-to-time days))
1499 ;; Compare the time with the current time.
1500 (ignore-errors (time-less-p days (time-since time))))))))
1502 (defun nnmail-check-syntax ()
1503 "Check (and modify) the syntax of the message in the current buffer."
1505 (message-narrow-to-head)
1506 (let ((case-fold-search t))
1507 (unless (re-search-forward "^Message-ID[ \t]*:" nil t)
1508 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1510 (defun nnmail-write-region (start end filename &optional append visit lockname)
1511 "Do a `write-region', and then set the file modes."
1512 (let ((pathname-coding-system nnmail-pathname-coding-system))
1514 (write-region-as-coding-system
1515 nnmail-file-coding-system start end filename append visit lockname)
1516 (set-file-modes filename nnmail-default-file-modes)))
1519 ;;; Status functions
1522 (defun nnmail-replace-status (name value)
1523 "Make status NAME and VALUE part of the current status line."
1525 (message-narrow-to-head)
1526 (let ((status (nnmail-decode-status)))
1527 (setq status (delq (member name status) status))
1529 (push (cons name value) status))
1530 (message-remove-header "status")
1531 (goto-char (point-max))
1532 (insert "Status: " (nnmail-encode-status status) "\n"))))
1534 (defun nnmail-decode-status ()
1535 "Return a status-value alist from STATUS."
1536 (goto-char (point-min))
1537 (when (re-search-forward "^Status: " nil t)
1538 (let (name value status)
1540 ;; Narrow to the status.
1543 (if (re-search-forward "^[^ \t]" nil t)
1546 ;; Go through all elements and add them to the list.
1547 (goto-char (point-min))
1548 (while (re-search-forward "[^ \t=]+" nil t)
1549 (setq name (match-string 0))
1550 (if (not (eq (char-after) ?=))
1554 (if (not (eq (char-after) ?\"))
1555 (if (not (looking-at "[^ \t]"))
1559 (setq value (match-string 0))
1560 (goto-char (match-end 0)))
1562 (setq value (read (current-buffer)))))
1563 (push (cons name value) status)))
1566 (defun nnmail-encode-status (status)
1567 "Return a status string from STATUS."
1572 (if (string-match "[ \t]" (cdr elem))
1573 (prin1-to-string (cdr elem))
1577 (defun nnmail-split-history ()
1578 "Generate an overview of where the last mail split put articles."
1580 (unless nnmail-split-history
1581 (error "No current split history"))
1582 (with-output-to-temp-buffer "*nnmail split history*"
1583 (let ((history nnmail-split-history)
1585 (while (setq elem (pop history))
1586 (princ (mapconcat (lambda (ga)
1587 (concat (car ga) ":" (int-to-string (cdr ga))))
1592 (defun nnmail-purge-split-history (group)
1593 "Remove all instances of GROUP from `nnmail-split-history'."
1594 (let ((history nnmail-split-history))
1596 (setcar history (gnus-delete-if (lambda (e) (string= (car e) group))
1599 (setq nnmail-split-history (delq nil nnmail-split-history))))
1601 (defun nnmail-new-mail-p (group)
1602 "Say whether GROUP has new mail."
1603 (let ((his nnmail-split-history)
1606 (when (assoc group (pop his))
1611 (defun nnmail-new-mail-numbers (group)
1612 "Say how many articles has been incorporated to GROUP."
1613 (let ((his (apply 'append nnmail-split-history))
1616 (when (string= group (caar his))
1617 (push (cdar his) numbers))
1618 (setq his (cdr his)))
1621 (defun nnmail-within-headers-p ()
1622 "Check to see if point is within the headers of a unix mail message.
1623 Doesn't change point."
1624 (let ((pos (point)))
1626 (and (nnmail-search-unix-mail-delim-backward)
1627 (not (search-forward "\n\n" pos t))))))
1629 (run-hooks 'nnmail-load-hook)
1633 ;;; nnmail.el ends here