1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002
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
)
39 (autoload 'gnus-error
"gnus-util")
40 (autoload 'gnus-buffer-live-p
"gnus-util"))
43 "Reading mail with Gnus."
46 (defgroup nnmail-retrieve nil
47 "Retrieving new mail."
50 (defgroup nnmail-prepare nil
51 "Preparing (or mangling) new mail after retrival."
54 (defgroup nnmail-duplicate nil
55 "Handling of duplicate mail messages."
58 (defgroup nnmail-split nil
59 "Organizing the incoming mail in folders."
62 (defgroup nnmail-files nil
67 (defgroup nnmail-expire nil
71 (defgroup nnmail-procmail nil
72 "Interfacing with procmail and other mail agents."
75 (defgroup nnmail-various nil
76 "Various mail options."
79 (defcustom nnmail-split-methods
81 "*Incoming mail will be split according to this variable.
83 If you'd like, for instance, one mail group for mail from the
84 \"4ad-l\" mailing list, one group for junk mail and one for everything
85 else, you could do something like this:
87 (setq nnmail-split-methods
88 '((\"mail.4ad\" \"From:.*4ad\")
89 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
90 (\"mail.misc\" \"\")))
92 As you can see, this variable is a list of lists, where the first
93 element in each \"rule\" is the name of the group (which, by the way,
94 does not have to be called anything beginning with \"mail\",
95 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
96 nnmail will try to match on the header to find a fit.
98 The second element can also be a function. In that case, it will be
99 called narrowed to the headers with the first element of the rule as
100 the argument. It should return a non-nil value if it thinks that the
101 mail belongs in that group.
103 The last element should always have \"\" as the regexp.
105 This variable can also have a function as its value."
107 :type
'(choice (repeat :tag
"Alist" (group (string :tag
"Name") regexp
))
108 (function-item nnmail-split-fancy
)
109 (function :tag
"Other")))
111 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
112 (defcustom nnmail-crosspost t
113 "If non-nil, do crossposting if several split methods match the mail.
114 If nil, the first match found will be used."
118 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
119 (defcustom nnmail-keep-last-article nil
120 "If non-nil, nnmail will never delete/move a group's last article.
121 It can be marked expirable, so it will be deleted when it is no longer last.
123 You may need to set this variable if other programs are putting
124 new mail into folder numbers that Gnus has marked as expired."
125 :group
'nnmail-procmail
126 :group
'nnmail-various
129 (defcustom nnmail-use-long-file-names nil
130 "If non-nil the mail backends will use long file and directory names.
131 If nil, groups like \"mail.misc\" will end up in directories like
136 (defcustom nnmail-default-file-modes
384
137 "Set the mode bits of all new mail files to this integer."
141 (defcustom nnmail-expiry-wait
7
142 "*Expirable articles that are older than this will be expired.
143 This variable can either be a number (which will be interpreted as a
144 number of days) -- this doesn't have to be an integer. This variable
145 can also be `immediate' and `never'."
146 :group
'nnmail-expire
147 :type
'(choice (const immediate
)
148 (integer :tag
"days")
151 (defcustom nnmail-expiry-wait-function nil
152 "Variable that holds function to specify how old articles should be before they are expired.
153 The function will be called with the name of the group that the
154 expiry is to be performed in, and it should return an integer that
155 says how many days an article can be stored before it is considered
156 \"old\". It can also return the values `never' and `immediate'.
160 \(setq nnmail-expiry-wait-function
162 (cond ((string-match \"private\" newsgroup) 31)
163 ((string-match \"junk\" newsgroup) 1)
164 ((string-match \"important\" newsgroup) 'never)
166 :group
'nnmail-expire
167 :type
'(choice (const :tag
"nnmail-expiry-wait" nil
)
168 (function :format
"%v" nnmail-
)))
170 (defcustom nnmail-expiry-target
'delete
171 "*Variable that says where expired messages should end up.
172 The default value is `delete' (which says to delete the messages),
173 but it can also be a string or a function. If it is a string, expired
174 messages end up in that group. If it is a function, the function is
175 called in a buffer narrowed to the message in question. The function
176 receives one argument, the name of the group the message comes from.
177 The return value should be `delete' or a group name (a string)."
179 :group
'nnmail-expire
180 :type
'(choice (const delete
)
181 (function :format
"%v" nnmail-
)
184 (defcustom nnmail-cache-accepted-message-ids nil
185 "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache."
189 (defcustom nnmail-spool-file
'((file))
190 "*Where the mail backends will look for incoming mail.
191 This variable is a list of mail source specifiers.
192 This variable is obsolete; `mail-sources' should be used instead."
196 (defcustom nnmail-resplit-incoming nil
197 "*If non-nil, re-split incoming procmail sorted mail."
198 :group
'nnmail-procmail
201 (defcustom nnmail-scan-directory-mail-source-once nil
202 "*If non-nil, scan all incoming procmail sorted mails once.
203 It scans low-level sorted spools even when not required."
205 :group
'nnmail-procmail
208 (defcustom nnmail-delete-file-function
'delete-file
209 "Function called to delete files in some mail backends."
213 (defcustom nnmail-crosspost-link-function
214 (if (string-match "windows-nt\\|emx" (symbol-name system-type
))
217 "*Function called to create a copy of a file.
218 This is `add-name-to-file' by default, which means that crossposts
219 will use hard links. If your file system doesn't allow hard
220 links, you could set this variable to `copy-file' instead."
222 :type
'(radio (function-item add-name-to-file
)
223 (function-item copy-file
)
224 (function :tag
"Other")))
226 (defcustom nnmail-read-incoming-hook
227 (if (eq system-type
'windows-nt
)
228 '(nnheader-ms-strip-cr)
230 "*Hook that will be run after the incoming mail has been transferred.
231 The incoming mail is moved from the specified spool file (which normally is
232 something like \"/usr/spool/mail/$user\") to the user's home
233 directory. This hook is called after the incoming mail box has been
234 emptied, and can be used to call any mail box programs you have
235 running (\"xwatch\", etc.)
239 \(add-hook 'nnmail-read-incoming-hook
241 (call-process \"/local/bin/mailsend\" nil nil nil
242 \"read\" nnmail-spool-file)))
244 If you have xwatch running, this will alert it that mail has been
247 If you use `display-time', you could use something like this:
249 \(add-hook 'nnmail-read-incoming-hook
251 ;; Update the displayed time, since that will clear out
252 ;; the flag that says you have mail.
253 (when (eq (process-status \"display-time\") 'run)
254 (display-time-filter display-time-process \"\"))))"
255 :group
'nnmail-prepare
258 (defcustom nnmail-prepare-incoming-hook nil
259 "Hook called before treating incoming mail.
260 The hook is run in a buffer with all the new, incoming mail."
261 :group
'nnmail-prepare
264 (defcustom nnmail-prepare-incoming-header-hook nil
265 "Hook called narrowed to the headers of each message.
266 This can be used to remove excessive spaces (and stuff like
267 that) from the headers before splitting and saving the messages."
268 :group
'nnmail-prepare
271 (defcustom nnmail-prepare-incoming-message-hook nil
272 "Hook called narrowed to each message."
273 :group
'nnmail-prepare
276 (defcustom nnmail-list-identifiers nil
277 "Regexp that matches list identifiers to be removed.
278 This can also be a list of regexps."
279 :group
'nnmail-prepare
280 :type
'(choice (const :tag
"none" nil
)
282 (repeat :value
(".*") regexp
)))
284 (defcustom nnmail-pre-get-new-mail-hook nil
285 "Hook called just before starting to handle new incoming mail."
286 :group
'nnmail-retrieve
289 (defcustom nnmail-post-get-new-mail-hook nil
290 "Hook called just after finishing handling new incoming mail."
291 :group
'nnmail-retrieve
294 (defcustom nnmail-split-hook nil
295 "Hook called before deciding where to split an article.
296 The functions in this hook are free to modify the buffer
297 contents in any way they choose -- the buffer contents are
298 discarded after running the split process."
302 (defcustom nnmail-large-newsgroup
50
303 "*The number of the articles which indicates a large newsgroup.
304 If the number of the articles is greater than the value, verbose
305 messages will be shown to indicate the current status."
306 :group
'nnmail-various
309 (defcustom nnmail-split-fancy
"mail.misc"
310 "Incoming mail can be split according to this fancy variable.
311 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
313 The format of this variable is SPLIT, where SPLIT can be one of
316 GROUP: Mail will be stored in GROUP (a string).
318 \(FIELD VALUE [- RESTRICT [- RESTRICT [...]]] SPLIT): If the message
319 field FIELD (a regexp) contains VALUE (a regexp), store the messages
320 as specified by SPLIT. If RESTRICT (a regexp) matches some string
321 after FIELD and before the end of the matched VALUE, return nil,
322 otherwise process SPLIT. Multiple RESTRICTs add up, further
323 restricting the possibility of processing SPLIT.
325 \(| SPLIT...): Process each SPLIT expression until one of them matches.
326 A SPLIT expression is said to match if it will cause the mail
327 message to be stored in one or more groups.
329 \(& SPLIT...): Process each SPLIT expression.
331 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
332 the buffer containing the message headers. The return value FUNCTION
333 should be a split, which is then recursively processed.
335 \(! FUNCTION SPLIT): Call FUNCTION with the result of SPLIT. The
336 return value FUNCTION should be a split, which is then recursively
339 FIELD must match a complete field name. VALUE must match a complete
340 word according to the `nnmail-split-fancy-syntax-table' syntax table.
341 You can use \".*\" in the regexps to match partial field names or words.
343 FIELD and VALUE can also be lisp symbols, in that case they are expanded
344 as specified in `nnmail-split-abbrev-alist'.
346 GROUP can contain \\& and \\N which will substitute from matching
347 \\(\\) patterns in the previous VALUE.
351 \(setq nnmail-split-methods 'nnmail-split-fancy
353 ;; Messages from the mailer daemon are not crossposted to any of
354 ;; the ordinary groups. Warnings are put in a separate group
356 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
358 ;; Non-error messages are crossposted to all relevant
359 ;; groups, but we don't crosspost between the group for the
360 ;; (ding) list and the group for other (ding) related mail.
361 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
362 (\"subject\" \"ding\" \"ding.misc\"))
363 ;; Other mailing lists...
364 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
365 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
366 ;; Both lists below have the same suffix, so prevent
367 ;; cross-posting to mkpkg.list of messages posted only to
368 ;; the bugs- list, but allow cross-posting when the
369 ;; message was really cross-posted.
370 (any \"bugs-mypackage@somewhere\" \"mypkg.bugs\")
371 (any \"mypackage@somewhere\" - \"bugs-mypackage\" \"mypkg.list\")
374 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
375 ;; Unmatched mail goes to the catch all group.
381 (defcustom nnmail-split-abbrev-alist
382 '((any .
"from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
383 (mail .
"mailer-daemon\\|postmaster\\|uucp")
384 (to .
"to\\|cc\\|apparently-to\\|resent-to\\|resent-cc")
385 (from .
"from\\|sender\\|resent-from")
386 (nato .
"to\\|cc\\|resent-to\\|resent-cc")
387 (naany .
"from\\|to\\|cc\\|sender\\|resent-from\\|resent-to\\|resent-cc"))
388 "*Alist of abbreviations allowed in `nnmail-split-fancy'."
390 :type
'(repeat (cons :format
"%v" symbol regexp
)))
392 (defcustom nnmail-message-id-cache-length
1000
393 "*The approximate number of Message-IDs nnmail will keep in its cache.
394 If this variable is nil, no checking on duplicate messages will be
396 :group
'nnmail-duplicate
397 :type
'(choice (const :tag
"disable" nil
)
398 (integer :format
"%v")))
400 (defcustom nnmail-message-id-cache-file
"~/.nnmail-cache"
401 "*The file name of the nnmail Message-ID cache."
402 :group
'nnmail-duplicate
406 (defcustom nnmail-treat-duplicates
'warn
407 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
408 Three values are valid: nil, which means that nnmail is not to keep a
409 Message-ID cache; `warn', which means that nnmail should insert extra
410 headers to warn the user about the duplication (this is the default);
411 and `delete', which means that nnmail will delete duplicated mails.
413 This variable can also be a function. It will be called from a buffer
414 narrowed to the article in question with the Message-ID as a
415 parameter. It should return nil, `warn' or `delete'."
416 :group
'nnmail-duplicate
417 :type
'(choice (const :tag
"off" nil
)
421 (defcustom nnmail-extra-headers nil
422 "*Extra headers to parse."
425 :type
'(repeat symbol
))
427 (defcustom nnmail-split-header-length-limit
512
428 "Header lines longer than this limit are excluded from the split function."
433 ;;; Internal variables.
435 (defvar nnmail-split-history nil
436 "List of group/article elements that say where the previous split put messages.")
438 (defvar nnmail-split-fancy-syntax-table nil
439 "Syntax table used by `nnmail-split-fancy'.")
440 (unless (syntax-table-p nnmail-split-fancy-syntax-table
)
441 (setq nnmail-split-fancy-syntax-table
442 (copy-syntax-table (standard-syntax-table)))
443 ;; support the %-hack
444 (modify-syntax-entry ?\%
"." nnmail-split-fancy-syntax-table
))
446 (defvar nnmail-prepare-save-mail-hook nil
447 "Hook called before saving mail.")
449 (defvar nnmail-split-tracing nil
)
450 (defvar nnmail-split-trace nil
)
454 (defconst nnmail-version
"nnmail 1.0"
459 (defun nnmail-request-post (&optional server
)
460 (mail-send-and-exit nil
))
462 (defvar nnmail-file-coding-system
'raw-text
463 "Coding system used in nnmail.")
465 (defvar nnmail-incoming-coding-system
466 mm-text-coding-system
467 "Coding system used in reading inbox")
469 (defvar nnmail-pathname-coding-system nil
470 "*Coding system for file name.")
472 (defun nnmail-find-file (file)
473 "Insert FILE in server buffer safely."
474 (set-buffer nntp-server-buffer
)
475 (delete-region (point-min) (point-max))
476 (let ((format-alist nil
)
477 (after-insert-file-functions nil
))
479 (let ((coding-system-for-read nnmail-file-coding-system
)
480 (auto-mode-alist (mm-auto-mode-alist))
481 (file-name-coding-system nnmail-pathname-coding-system
))
482 (insert-file-contents file
)
486 (defun nnmail-group-pathname (group dir
&optional file
)
487 "Make file name for GROUP."
489 (let ((dir (file-name-as-directory (expand-file-name dir
))))
490 (setq group
(nnheader-replace-duplicate-chars-in-string
491 (nnheader-replace-chars-in-string group ?
/ ?_
)
493 (setq group
(nnheader-translate-file-chars group
))
494 ;; If this directory exists, we use it directly.
495 (file-name-as-directory
496 (if (or nnmail-use-long-file-names
497 (file-directory-p (concat dir group
)))
498 (expand-file-name group dir
)
499 ;; If not, we translate dots into slashes.
501 (mm-encode-coding-string
502 (nnheader-replace-chars-in-string group ?. ?
/)
503 nnmail-pathname-coding-system
)
507 (defun nnmail-get-active ()
508 "Returns an assoc of group names and active ranges.
509 nn*-request-list should have been called before calling this function."
510 ;; Go through all groups from the active list.
512 (set-buffer nntp-server-buffer
)
513 (nnmail-parse-active)))
515 (defun nnmail-parse-active ()
516 "Parse the active file in the current buffer and return an alist."
517 (goto-char (point-min))
518 (unless (re-search-forward "[\\\"]" nil t
)
519 (goto-char (point-max))
520 (while (re-search-backward "[][';?()#]" nil t
)
522 (goto-char (point-min))
523 (let ((buffer (current-buffer))
524 group-assoc group max min
)
528 (narrow-to-region (point) (gnus-point-at-eol))
529 (setq group
(read buffer
))
530 (unless (stringp group
)
531 (setq group
(symbol-name group
)))
532 (if (and (numberp (setq max
(read nntp-server-buffer
)))
533 (numberp (setq min
(read nntp-server-buffer
))))
534 (push (list group
(cons min max
))
541 (defvar nnmail-active-file-coding-system
'raw-text
542 "*Coding system for active file.")
544 (defun nnmail-save-active (group-assoc file-name
)
545 "Save GROUP-ASSOC in ACTIVE-FILE."
546 (let ((coding-system-for-write nnmail-active-file-coding-system
))
548 (with-temp-file file-name
549 (nnmail-generate-active group-assoc
)))))
551 (defun nnmail-generate-active (alist)
552 "Generate an active file from group-alist ALIST."
555 (while (setq group
(pop alist
))
556 (insert (format "%S %d %d y\n" (intern (car group
)) (cdadr group
)
558 (goto-char (point-max))
559 (while (search-backward "\\." nil t
)
562 (defun nnmail-get-split-group (file source
)
563 "Find out whether this FILE is to be split into GROUP only.
564 If SOURCE is a directory spec, try to return the group name component."
565 (if (eq (car source
) 'directory
)
566 (let ((file (file-name-nondirectory file
)))
567 (mail-source-bind (directory source
)
568 (if (string-match (concat (regexp-quote suffix
) "$") file
)
569 (substring file
0 (match-beginning 0))
573 (defun nnmail-process-babyl-mail-format (func artnum-func
)
574 (let ((case-fold-search t
)
576 start message-id content-length do-search end
)
578 (goto-char (point-min))
580 "\f\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t
)
581 (goto-char (match-end 0))
582 (delete-region (match-beginning 0) (match-end 0))
586 ;; Skip all the headers in case there are more "From "s...
587 (or (search-forward "\n\n" nil t
)
588 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t
)
589 (search-forward "\x1f\f"))
591 ;; Unquote the ">From " line, if any.
592 (goto-char (point-min))
593 (when (looking-at ">From ")
594 (replace-match "X-From-Line: ") )
595 (run-hooks 'nnmail-prepare-incoming-header-hook
)
596 (goto-char (point-max))
597 ;; Find the Message-ID header.
599 (if (re-search-backward
600 "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]*>\\)" nil t
)
601 (setq message-id
(buffer-substring (match-beginning 1)
603 ;; There is no Message-ID here, so we create one.
605 (when (re-search-backward "^Message-ID[ \t]*:" nil t
)
607 (insert "Original-")))
609 (insert "Message-ID: " (setq message-id
(nnmail-message-id))
611 ;; Look for a Content-Length header.
612 (if (not (save-excursion
613 (and (re-search-backward
614 "^Content-Length:[ \t]*\\([0-9]+\\)" start t
)
615 (setq content-length
(string-to-int
619 ;; We destroy the header, since none of
620 ;; the backends ever use it, and we do not
621 ;; want to confuse other mailers by having
622 ;; a (possibly) faulty header.
623 (progn (insert "X-") t
))))
626 (if (or (= (+ (point) content-length
) (point-max))
628 (goto-char (+ (point) content-length
))
629 (looking-at "\x1f")))
631 (goto-char (+ (point) content-length
))
632 (setq do-search nil
))
635 ;; Go to the beginning of the next article - or to the end
638 (if (re-search-forward "^\x1f" nil t
)
639 (goto-char (match-beginning 0))
640 (goto-char (1- (point-max)))))
641 (delete-char 1) ; delete ^_
644 (narrow-to-region start
(point))
645 (goto-char (point-min))
646 (nnmail-check-duplication message-id func artnum-func
)
648 (setq end
(point-max))))
652 (defsubst nnmail-search-unix-mail-delim
()
653 "Put point at the beginning of the next Unix mbox message."
654 ;; Algorithm used to find the next article in the
655 ;; brain-dead Unix mbox format:
657 ;; 1) Search for "^From ".
658 ;; 2) If we find it, then see whether the previous
659 ;; line is blank and the next line looks like a header.
660 ;; Then it's possible that this is a mail delim, and we use it.
661 (let ((case-fold-search nil
)
664 (if (not (re-search-forward "^From " nil t
))
668 (when (and (or (bobp)
671 (eq (char-after) ?
\n)))
674 (while (looking-at ">From \\|From ")
676 (looking-at "[^ \n\t:]+[ \n\t]*:")))
677 (setq found
'yes
)))))
681 (defun nnmail-search-unix-mail-delim-backward ()
682 "Put point at the beginning of the current Unix mbox message."
683 ;; Algorithm used to find the next article in the
684 ;; brain-dead Unix mbox format:
686 ;; 1) Search for "^From ".
687 ;; 2) If we find it, then see whether the previous
688 ;; line is blank and the next line looks like a header.
689 ;; Then it's possible that this is a mail delim, and we use it.
690 (let ((case-fold-search nil
)
693 (if (not (re-search-backward "^From " nil t
))
697 (when (and (or (bobp)
700 (eq (char-after) ?
\n)))
703 (while (looking-at ">From \\|From ")
705 (looking-at "[^ \n\t:]+[ \n\t]*:")))
706 (setq found
'yes
)))))
710 (defun nnmail-process-unix-mail-format (func artnum-func
)
711 (let ((case-fold-search t
)
713 start message-id content-length end skip head-end
)
714 (goto-char (point-min))
715 (if (not (and (re-search-forward "^From " nil t
)
716 (goto-char (match-beginning 0))))
717 ;; Possibly wrong format?
718 (error "Error, unknown mail format! (Possibly corrupted.)")
719 ;; Carry on until the bitter end.
723 ;; Find the end of the head.
726 (if (search-forward "\n\n" nil t
)
728 ;; This will never happen, but just to be on the safe side --
729 ;; if there is no head-body delimiter, we search a bit manually.
730 (while (and (looking-at "From \\|[^ \t]+:")
734 ;; Find the Message-ID header.
735 (goto-char (point-min))
736 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t
)
737 (setq message-id
(match-string 1))
739 (when (re-search-forward "^Message-ID[ \t]*:" nil t
)
741 (insert "Original-")))
742 ;; There is no Message-ID here, so we create one.
744 (insert "Message-ID: " (setq message-id
(nnmail-message-id)) "\n"))
745 ;; Look for a Content-Length header.
746 (goto-char (point-min))
747 (if (not (re-search-forward
748 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t
))
749 (setq content-length nil
)
750 (setq content-length
(string-to-int (match-string 1)))
751 ;; We destroy the header, since none of the backends ever
752 ;; use it, and we do not want to confuse other mailers by
753 ;; having a (possibly) faulty header.
756 (run-hooks 'nnmail-prepare-incoming-header-hook
)
757 ;; Find the end of this article.
758 (goto-char (point-max))
760 (setq head-end
(point))
761 ;; We try the Content-Length value. The idea: skip over the header
762 ;; separator, then check what happens content-length bytes into the
763 ;; message body. This should be either the end of the buffer, the
764 ;; message separator or a blank line followed by the separator.
765 ;; The blank line should probably be deleted. If neither of the
766 ;; three is met, the content-length header is probably invalid.
769 (setq skip
(+ (point) content-length
))
771 (cond ((or (= skip
(point-max))
772 (= (1+ skip
) (point-max)))
773 (setq end
(point-max)))
774 ((looking-at "From ")
776 ((looking-at "[ \t]*\n\\(From \\)")
777 (setq end
(match-beginning 1)))
781 ;; No Content-Length, so we find the beginning of the next
782 ;; article or the end of the buffer.
784 (or (nnmail-search-unix-mail-delim)
785 (goto-char (point-max))))
786 ;; Allow the backend to save the article.
789 (narrow-to-region start
(point))
790 (goto-char (point-min))
792 (nnmail-check-duplication message-id func artnum-func
)
793 (setq end
(point-max))))
797 (defun nnmail-process-mmdf-mail-format (func artnum-func
)
798 (let ((delim "^\^A\^A\^A\^A$")
801 start message-id end
)
802 (goto-char (point-min))
803 (if (not (and (re-search-forward delim nil t
)
805 ;; Possibly wrong format?
806 (error "Error, unknown mail format! (Possibly corrupted.)")
807 ;; Carry on until the bitter end.
810 ;; Find the end of the head.
813 (if (search-forward "\n\n" nil t
)
815 ;; This will never happen, but just to be on the safe side --
816 ;; if there is no head-body delimiter, we search a bit manually.
817 (while (and (looking-at "From \\|[^ \t]+:")
821 ;; Find the Message-ID header.
822 (goto-char (point-min))
823 (if (re-search-forward "^Message-ID[ \t]*:[ \n\t]*\\(<[^>]+>\\)" nil t
)
824 (setq message-id
(match-string 1))
825 ;; There is no Message-ID here, so we create one.
827 (when (re-search-backward "^Message-ID[ \t]*:" nil t
)
829 (insert "Original-")))
831 (insert "Message-ID: " (setq message-id
(nnmail-message-id)) "\n"))
832 (run-hooks 'nnmail-prepare-incoming-header-hook
)
833 ;; Find the end of this article.
834 (goto-char (point-max))
836 (if (re-search-forward delim nil t
)
838 (goto-char (point-max)))
839 ;; Allow the backend to save the article.
842 (narrow-to-region start
(point))
843 (goto-char (point-min))
845 (nnmail-check-duplication message-id func artnum-func
)
846 (setq end
(point-max))))
851 (defun nnmail-process-maildir-mail-format (func artnum-func
)
852 ;; In a maildir, every file contains exactly one mail.
853 (let ((case-fold-search t
)
855 (goto-char (point-min))
856 ;; Find the end of the head.
859 (if (search-forward "\n\n" nil t
)
861 ;; This will never happen, but just to be on the safe side --
862 ;; if there is no head-body delimiter, we search a bit manually.
863 (while (and (looking-at "From \\|[^ \t]+:")
867 ;; Find the Message-ID header.
868 (goto-char (point-min))
869 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t
)
870 (setq message-id
(match-string 1))
871 ;; There is no Message-ID here, so we create one.
873 (when (re-search-backward "^Message-ID[ \t]*:" nil t
)
875 (insert "Original-")))
877 (insert "Message-ID: " (setq message-id
(nnmail-message-id)) "\n"))
878 (run-hooks 'nnmail-prepare-incoming-header-hook
)
879 ;; Allow the backend to save the article.
882 (goto-char (point-min))
883 (nnmail-check-duplication message-id func artnum-func
))
886 (defun nnmail-split-incoming (incoming func
&optional exit-func
888 "Go through the entire INCOMING file and pick out each individual mail.
889 FUNC will be called with the buffer narrowed to each mail."
890 (let (;; If this is a group-specific split, we bind the split
891 ;; methods to just this group.
892 (nnmail-split-methods (if (and group
893 (not nnmail-resplit-incoming
))
894 (list (list group
""))
895 nnmail-split-methods
)))
897 ;; Insert the incoming file.
898 (set-buffer (get-buffer-create " *nnmail incoming*"))
900 (let ((coding-system-for-read nnmail-incoming-coding-system
))
901 (mm-insert-file-contents incoming
))
903 (if (zerop (buffer-size))
905 (goto-char (point-min))
906 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook
))
907 ;; Handle both babyl, MMDF and unix mail formats, since
908 ;; movemail will use the former when fetching from a
909 ;; mailbox, the latter when fetching from a file.
910 (cond ((or (looking-at "\^L")
911 (looking-at "BABYL OPTIONS:"))
912 (nnmail-process-babyl-mail-format func artnum-func
))
913 ((looking-at "\^A\^A\^A\^A")
914 (nnmail-process-mmdf-mail-format func artnum-func
))
915 ((looking-at "Return-Path:")
916 (nnmail-process-maildir-mail-format func artnum-func
))
918 (nnmail-process-unix-mail-format func artnum-func
))))
921 (kill-buffer (current-buffer))))))
923 (defun nnmail-article-group (func &optional trace
)
924 "Look at the headers and return an alist of groups that match.
925 FUNC will be called with the group name to determine the article number."
926 (let ((methods nnmail-split-methods
)
927 (obuf (current-buffer))
929 end group-art method grp
)
930 (if (and (sequencep methods
)
931 (= (length methods
) 1))
932 ;; If there is only just one group to put everything in, we
933 ;; just return a list with just this one method in.
935 (list (cons (caar methods
) (funcall func
(caar methods
)))))
936 ;; We do actual comparison.
940 (setq end
(if (search-forward "\n\n" nil t
) (point) (point-max)))
941 (set-buffer nntp-server-buffer
)
943 ;; Copy the headers into the work buffer.
944 (insert-buffer-substring obuf beg end
)
945 ;; Fold continuation lines.
946 (goto-char (point-min))
947 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t
)
948 (replace-match " " t t
))
949 ;; Nuke pathologically long headers. Since Gnus applies
950 ;; pathologically complex regexps to the buffer, lines
951 ;; that are looong will take longer than the Universe's
952 ;; existence to process.
953 (goto-char (point-min))
955 (unless (< (move-to-column nnmail-split-header-length-limit
)
956 nnmail-split-header-length-limit
)
957 (delete-region (point) (progn (end-of-line) (point))))
960 (goto-char (point-min))
961 (run-hooks 'nnmail-split-hook
)
962 (when (setq nnmail-split-tracing trace
)
963 (setq nnmail-split-trace nil
))
964 (if (and (symbolp nnmail-split-methods
)
965 (fboundp nnmail-split-methods
))
968 ;; `nnmail-split-methods' is a function, so we
969 ;; just call this function here and use the
971 (or (funcall nnmail-split-methods
)
975 "Error in `nnmail-split-methods'; using `bogus' mail group")
978 (setq split
(gnus-remove-duplicates split
))
979 ;; The article may be "cross-posted" to `junk'. What
980 ;; to do? Just remove the `junk' spec. Don't really
981 ;; see anything else to do...
983 (while (setq elem
(car (memq 'junk split
)))
984 (setq split
(delq elem split
))))
988 (lambda (group) (cons group
(funcall func group
)))
990 ;; Go through the split methods to find a match.
994 (goto-char (point-max))
995 (setq method
(pop methods
)
998 (not (equal "" (nth 1 method
))))
1001 (if (stringp (nth 1 method
))
1002 (let ((expand (string-match "\\\\[0-9&]" grp
))
1003 (pos (re-search-backward (cadr method
)
1006 (setq grp
(nnmail-expand-newtext grp
)))
1008 ;; Function to say whether this is a match.
1009 (funcall (nth 1 method
) grp
)))
1010 ;; Don't enter the article into the same
1012 (not (assoc grp group-art
)))
1013 (push (cons grp
(funcall func grp
))
1015 ;; This is the final group, which is used as a
1019 (list (cons (car method
)
1020 (funcall func
(car method
)))))))))
1021 ;; Produce a trace if non-empty.
1022 (when (and trace nnmail-split-trace
)
1023 (let ((trace (nreverse nnmail-split-trace
))
1024 (restore (current-buffer)))
1025 (nnheader-set-temp-buffer "*Split Trace*")
1028 (insert (car trace
) "\n")
1029 (setq trace
(cdr trace
)))
1030 (goto-char (point-min))
1031 (gnus-configure-windows 'split-trace
)
1032 (set-buffer restore
)))
1033 ;; See whether the split methods returned `junk'.
1034 (if (equal group-art
'(junk))
1036 ;; The article may be "cross-posted" to `junk'. What
1037 ;; to do? Just remove the `junk' spec. Don't really
1038 ;; see anything else to do...
1040 (while (setq elem
(car (memq 'junk group-art
)))
1041 (setq group-art
(delq elem group-art
)))
1042 (nreverse group-art
)))))))
1044 (defun nnmail-insert-lines ()
1045 "Insert how many lines there are in the body of the mail.
1046 Return the number of characters in the body."
1049 (goto-char (point-min))
1050 (unless (search-forward "\n\n" nil t
)
1051 (goto-char (point-max))
1053 (setq chars
(- (point-max) (point)))
1054 (setq lines
(count-lines (point) (point-max)))
1057 (when (re-search-backward "^Lines: " nil t
)
1058 (delete-region (point) (progn (forward-line 1) (point)))))
1060 (insert (format "Lines: %d\n" (max lines
0)))
1063 (defun nnmail-insert-xref (group-alist)
1064 "Insert an Xref line based on the (group . article) alist."
1066 (goto-char (point-min))
1067 (unless (search-forward "\n\n" nil t
)
1068 (goto-char (point-max))
1071 (when (re-search-backward "^Xref: " nil t
)
1072 (delete-region (match-beginning 0)
1073 (progn (forward-line 1) (point))))
1074 (insert (format "Xref: %s" (system-name)))
1076 (insert (format " %s:%d"
1077 (mm-encode-coding-string
1079 nnmail-pathname-coding-system
)
1080 (cdar group-alist
)))
1081 (setq group-alist
(cdr group-alist
)))
1084 ;;; Message washing functions
1086 (defun nnmail-remove-leading-whitespace ()
1087 "Remove excessive whitespace from all headers."
1088 (goto-char (point-min))
1089 (while (re-search-forward "^\\([^ :]+: \\) +" nil t
)
1090 (replace-match "\\1" t
)))
1092 (defun nnmail-remove-list-identifiers ()
1093 "Remove list identifiers from Subject headers."
1094 (let ((regexp (if (stringp nnmail-list-identifiers
) nnmail-list-identifiers
1095 (mapconcat 'identity nnmail-list-identifiers
" *\\|"))))
1097 (goto-char (point-min))
1098 (when (re-search-forward
1099 (concat "^Subject: +\\(Re: +\\)?\\(" regexp
" *\\)")
1101 (delete-region (match-beginning 2) (match-end 0))))))
1103 (defun nnmail-remove-tabs ()
1104 "Translate TAB characters into SPACE characters."
1105 (subst-char-in-region (point-min) (point-max) ?
\t ? t
))
1107 (defun nnmail-fix-eudora-headers ()
1108 "Eudora has a broken References line, but an OK In-Reply-To."
1109 (goto-char (point-min))
1110 (when (re-search-forward "^X-Mailer:.*Eudora" nil t
)
1111 (goto-char (point-min))
1112 (when (re-search-forward "^References:" nil t
)
1114 (insert "X-Gnus-Broken-Eudora-"))
1115 (goto-char (point-min))
1116 (when (re-search-forward "^In-Reply-To:[^\n]+\\(\n[ \t]+\\)" nil t
)
1117 (replace-match "" t t nil
1))))
1119 (custom-add-option 'nnmail-prepare-incoming-header-hook
1120 'nnmail-fix-eudora-headers
)
1122 ;;; Utility functions
1124 (defun nnmail-split-fancy ()
1125 "Fancy splitting method.
1126 See the documentation for the variable `nnmail-split-fancy' for documentation."
1127 (let ((syntab (syntax-table)))
1130 (set-syntax-table nnmail-split-fancy-syntax-table
)
1131 (nnmail-split-it nnmail-split-fancy
))
1132 (set-syntax-table syntab
))))
1134 (defvar nnmail-split-cache nil
)
1135 ;; Alist of split expressions their equivalent regexps.
1137 (defun nnmail-split-it (split)
1138 ;; Return a list of groups matching SPLIT.
1145 ;; A group name. Do the \& and \N subs into the string.
1147 (when nnmail-split-tracing
1148 (push (format "\"%s\"" split
) nnmail-split-trace
))
1149 (list (nnmail-expand-newtext split
)))
1151 ;; Junk the message.
1153 (when nnmail-split-tracing
1154 (push "junk" nnmail-split-trace
))
1157 ;; Builtin & operation.
1158 ((eq (car split
) '&)
1159 (apply 'nconc
(mapcar 'nnmail-split-it
(cdr split
))))
1161 ;; Builtin | operation.
1162 ((eq (car split
) '|
)
1164 (while (and (not done
) (cdr split
))
1165 (setq split
(cdr split
)
1166 done
(nnmail-split-it (car split
))))
1169 ;; Builtin : operation.
1170 ((eq (car split
) ':)
1171 (nnmail-split-it (save-excursion (eval (cdr split
)))))
1173 ;; Builtin ! operation.
1174 ((eq (car split
) '!)
1175 (funcall (cadr split
) (nnmail-split-it (caddr split
))))
1177 ;; Check the cache for the regexp for this split.
1178 ((setq cached-pair
(assq split nnmail-split-cache
))
1180 (end-point (point-max))
1181 (value (nth 1 split
)))
1183 (setq value
(cdr (assq value nnmail-split-abbrev-alist
))))
1184 (while (and (goto-char end-point
)
1185 (re-search-backward (cdr cached-pair
) nil t
))
1186 (when nnmail-split-tracing
1187 (push (cdr cached-pair
) nnmail-split-trace
))
1188 (let ((split-rest (cddr split
))
1190 ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\). So,
1191 ;; start-of-value is the point just before the
1192 ;; beginning of the value, whereas after-header-name is
1193 ;; the point just after the field name.
1194 (start-of-value (match-end 1))
1195 (after-header-name (match-end 2)))
1196 ;; Start the next search just before the beginning of the
1198 (setq end-point
(1- start-of-value
))
1199 ;; Handle - RESTRICTs
1200 (while (eq (car split-rest
) '-
)
1201 ;; RESTRICT must start after-header-name and
1202 ;; end after start-of-value, so that, for
1203 ;; (any "foo" - "x-foo" "foo.list")
1204 ;; we do not exclude foo.list just because
1205 ;; the header is: ``To: x-foo, foo''
1207 (if (and (re-search-backward (cadr split-rest
)
1208 after-header-name t
)
1209 (> (match-end 0) start-of-value
))
1210 (setq split-rest nil
)
1211 (setq split-rest
(cddr split-rest
))))
1214 (let ((value (nth 1 split
)))
1216 (setq value
(cdr (assq value nnmail-split-abbrev-alist
))))
1217 ;; Someone might want to do a \N sub on this match, so get the
1218 ;; correct match positions.
1219 (re-search-backward value start-of-value
))
1220 (dolist (sp (nnmail-split-it (car split-rest
)))
1221 (unless (memq sp split-result
)
1222 (push sp split-result
))))))
1225 ;; Not in cache, compute a regexp for the field/value pair.
1227 (let* ((field (nth 0 split
))
1228 (value (nth 1 split
))
1231 (setq value
(cdr (assq value nnmail-split-abbrev-alist
))))
1232 (if (and (>= (length value
) 2)
1233 (string= ".*" (substring value
0 2)))
1234 (setq value
(substring value
2)
1236 (setq regexp
(concat "^\\(\\("
1238 (cdr (assq field nnmail-split-abbrev-alist
))
1245 (push (cons split regexp
) nnmail-split-cache
)
1246 ;; Now that it's in the cache, just call nnmail-split-it again
1247 ;; on the same split, which will find it immediately in the cache.
1248 (nnmail-split-it split
))))))
1250 (defun nnmail-expand-newtext (newtext)
1251 (let ((len (length newtext
))
1253 c expanded beg N did-expand
)
1256 (while (and (< pos len
)
1257 (not (= (aref newtext pos
) ?
\\)))
1258 (setq pos
(1+ pos
)))
1260 (push (substring newtext beg pos
) expanded
))
1262 ;; We hit a \; expand it.
1265 c
(aref newtext pos
))
1266 (if (not (or (= c ?\
&)
1269 ;; \ followed by some character we don't expand.
1270 (push (char-to-string c
) expanded
)
1275 (when (match-beginning N
)
1276 (push (buffer-substring (match-beginning N
) (match-end N
))
1278 (setq pos
(1+ pos
)))
1280 (apply 'concat
(nreverse expanded
))
1283 ;; Activate a backend only if it isn't already activated.
1284 ;; If FORCE, re-read the active file even if the backend is
1285 ;; already activated.
1286 (defun nnmail-activate (backend &optional force
)
1287 (nnheader-init-server-buffer)
1288 (let (file timestamp file-time
)
1289 (if (or (not (symbol-value (intern (format "%s-group-alist" backend
))))
1291 (and (setq file
(ignore-errors
1292 (symbol-value (intern (format "%s-active-file"
1294 (setq file-time
(nth 5 (file-attributes file
)))
1298 (symbol-value (intern
1299 (format "%s-active-timestamp"
1302 (not (consp timestamp
))
1303 (equal timestamp
'(0 0))
1304 (> (nth 0 file-time
) (nth 0 timestamp
))
1305 (and (= (nth 0 file-time
) (nth 0 timestamp
))
1306 (> (nth 1 file-time
) (nth 1 timestamp
))))))
1308 (or (eq timestamp
'none
)
1309 (set (intern (format "%s-active-timestamp" backend
))
1311 (funcall (intern (format "%s-request-list" backend
)))))
1314 (defun nnmail-message-id ()
1315 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
1318 ;;; nnmail duplicate handling
1321 (defvar nnmail-cache-buffer nil
)
1323 (defun nnmail-cache-open ()
1324 (if (or (not nnmail-treat-duplicates
)
1325 (and nnmail-cache-buffer
1326 (buffer-name nnmail-cache-buffer
)))
1327 () ; The buffer is open.
1330 (setq nnmail-cache-buffer
1331 (get-buffer-create " *nnmail message-id cache*")))
1332 (when (file-exists-p nnmail-message-id-cache-file
)
1333 (nnheader-insert-file-contents nnmail-message-id-cache-file
))
1334 (set-buffer-modified-p nil
)
1337 (defun nnmail-cache-close ()
1338 (when (and nnmail-cache-buffer
1339 nnmail-treat-duplicates
1340 (buffer-name nnmail-cache-buffer
)
1341 (buffer-modified-p nnmail-cache-buffer
))
1343 (set-buffer nnmail-cache-buffer
)
1344 ;; Weed out the excess number of Message-IDs.
1345 (goto-char (point-max))
1346 (when (search-backward "\n" nil t nnmail-message-id-cache-length
)
1349 (delete-region (point-min) (point))))
1351 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file
))
1352 (make-directory (file-name-directory nnmail-message-id-cache-file
)
1354 (nnmail-write-region (point-min) (point-max)
1355 nnmail-message-id-cache-file nil
'silent
)
1356 (set-buffer-modified-p nil
)
1357 (setq nnmail-cache-buffer nil
)
1358 (kill-buffer (current-buffer)))))
1360 ;; Compiler directives.
1362 (defvar group-art-list
)
1364 (defun nnmail-cache-insert (id)
1365 (when nnmail-treat-duplicates
1366 ;; Store some information about the group this message is written
1367 ;; to. This function might have been called from various places.
1368 ;; Sometimes, a function up in the calling sequence has an
1369 ;; argument GROUP which is bound to a string, the group name. At
1370 ;; other times, there is a function up in the calling sequence
1371 ;; which has an argument GROUP-ART which is a list of pairs, and
1372 ;; the car of a pair is a group name. Should we check that the
1373 ;; length of the list is equal to 1? -- kai
1375 (cond ((and (boundp 'group
) group
)
1377 ((and (boundp 'group-art-list
) group-art-list
1378 (listp group-art-list
))
1379 (setq g
(caar group-art-list
)))
1380 ((and (boundp 'group-art
) group-art
(listp group-art
))
1381 (setq g
(caar group-art
)))
1383 (unless (gnus-buffer-live-p nnmail-cache-buffer
)
1384 (nnmail-cache-open))
1386 (set-buffer nnmail-cache-buffer
)
1387 (goto-char (point-max))
1388 (if (and g
(not (string= "" g
))
1389 (gnus-methods-equal-p gnus-command-method
1390 (nnmail-cache-primary-mail-backend)))
1391 (insert id
"\t" g
"\n")
1392 (insert id
"\n"))))))
1394 (defun nnmail-cache-primary-mail-backend ()
1395 (let ((be-list (cons gnus-select-method gnus-secondary-select-methods
))
1398 (while (and (null res
) be-list
)
1399 (setq be
(car be-list
))
1400 (setq be-list
(cdr be-list
))
1401 (when (and (gnus-method-option-p be
'respool
)
1402 (eval (intern (format "%s-get-new-mail" (car be
)))))
1406 ;; Fetch the group name corresponding to the message id stored in the
1408 (defun nnmail-cache-fetch-group (id)
1409 (when (and nnmail-treat-duplicates nnmail-cache-buffer
)
1411 (set-buffer nnmail-cache-buffer
)
1412 (goto-char (point-max))
1413 (when (search-backward id nil t
)
1415 (skip-chars-forward "^\n\r\t")
1418 (buffer-substring (point)
1419 (progn (end-of-line) (point))))))))
1421 ;; Function for nnmail-split-fancy: look up all references in the
1422 ;; cache and if a match is found, return that group.
1423 (defun nnmail-split-fancy-with-parent ()
1424 (let* ((refstr (or (message-fetch-field "references")
1425 (message-fetch-field "in-reply-to")))
1429 (setq references
(nreverse (gnus-split-references refstr
)))
1430 (unless (gnus-buffer-live-p nnmail-cache-buffer
)
1431 (nnmail-cache-open))
1433 (setq res
(or (nnmail-cache-fetch-group x
) res
))
1434 (when (string= "drafts" res
)
1439 (defun nnmail-cache-id-exists-p (id)
1440 (when nnmail-treat-duplicates
1442 (set-buffer nnmail-cache-buffer
)
1443 (goto-char (point-max))
1444 (search-backward id nil t
))))
1446 (defun nnmail-fetch-field (header)
1449 (message-narrow-to-head)
1450 (message-fetch-field header
))))
1452 (defun nnmail-check-duplication (message-id func artnum-func
)
1453 (run-hooks 'nnmail-prepare-incoming-message-hook
)
1454 ;; If this is a duplicate message, then we do not save it.
1455 (let* ((duplication (nnmail-cache-id-exists-p message-id
))
1456 (case-fold-search t
)
1457 (action (when duplication
1459 ((memq nnmail-treat-duplicates
'(warn delete
))
1460 nnmail-treat-duplicates
)
1461 ((nnheader-functionp nnmail-treat-duplicates
)
1462 (funcall nnmail-treat-duplicates message-id
))
1464 nnmail-treat-duplicates
))))
1466 ;; We insert a line that says what the mail source is.
1467 (let ((case-fold-search t
))
1468 (goto-char (point-min))
1469 (re-search-forward "^message-id[ \t]*:" nil t
)
1471 (insert (format "X-Gnus-Mail-Source: %s\n" mail-source-string
)))
1473 ;; Let the backend save the article (or not).
1476 (funcall func
(setq group-art
1477 (nreverse (nnmail-article-group artnum-func
))))
1478 (nnmail-cache-insert message-id
))
1479 ((eq action
'delete
)
1480 (setq group-art nil
))
1482 ;; We insert a warning.
1483 (let ((case-fold-search t
))
1484 (goto-char (point-min))
1485 (re-search-forward "^message-id[ \t]*:" nil t
)
1488 "Gnus-Warning: This is a duplicate of message " message-id
"\n")
1489 (funcall func
(setq group-art
1490 (nreverse (nnmail-article-group artnum-func
))))))
1492 (funcall func
(setq group-art
1493 (nreverse (nnmail-article-group artnum-func
))))))
1494 ;; Add the group-art list to the history list.
1496 (push group-art nnmail-split-history
)
1497 (delete-region (point-min) (point-max)))))
1501 (defvar nnmail-fetched-sources nil
)
1503 (defun nnmail-get-value (&rest args
)
1504 (let ((sym (intern (apply 'format args
))))
1506 (symbol-value sym
))))
1508 (defun nnmail-get-new-mail (method exit-func temp
1509 &optional group spool-func
)
1510 "Read new incoming mail."
1511 (let* ((sources (or mail-sources
1512 (if (listp nnmail-spool-file
) nnmail-spool-file
1513 (list nnmail-spool-file
))))
1519 incoming incomings source
)
1520 (when (and (nnmail-get-value "%s-get-new-mail" method
)
1522 (while (setq source
(pop sources
))
1523 ;; Be compatible with old values.
1528 ((string-match "^po:" source
)
1529 (list 'pop
:user
(substring source
(match-end 0))))
1530 ((file-directory-p source
)
1531 (list 'directory
:path source
))
1533 (list 'file
:path source
)))))
1534 ((eq source
'procmail
)
1535 (message "Invalid value for nnmail-spool-file: `procmail'")
1537 ;; Hack to only fetch the contents of a single group's spool file.
1538 (when (and (eq (car source
) 'directory
)
1539 (null nnmail-scan-directory-mail-source-once
)
1541 (mail-source-bind (directory source
)
1542 (setq source
(append source
1548 (regexp-quote (concat group suffix
))
1551 (when nnmail-fetched-sources
1552 (if (member source nnmail-fetched-sources
)
1554 (push source nnmail-fetched-sources
)
1555 (push source fetching-sources
)))))
1556 (when fetching-sources
1557 ;; We first activate all the groups.
1558 (nnmail-activate method
)
1559 ;; Allow the user to hook.
1560 (run-hooks 'nnmail-pre-get-new-mail-hook
)
1561 ;; Open the message-id cache.
1563 ;; The we go through all the existing mail source specification
1564 ;; and fetch the mail from each.
1565 (while (setq source
(pop fetching-sources
))
1566 (nnheader-message 4 "%s: Reading incoming mail from %s..."
1567 method
(car source
))
1571 `(lambda (file orig-file
)
1572 (nnmail-split-incoming
1573 file
',(intern (format "%s-save-mail" method
))
1575 (if (equal file orig-file
)
1577 (nnmail-get-split-group orig-file
',source
))
1578 ',(intern (format "%s-active-number" method
))))))
1581 ;; If we did indeed read any incoming spools, we save all info.
1583 (nnheader-message 4 "%s: Reading incoming mail (no new mail)...done"
1584 method
(car source
))
1586 (nnmail-get-value "%s-group-alist" method
)
1587 (nnmail-get-value "%s-active-file" method
))
1589 (funcall exit-func
))
1590 (run-hooks 'nnmail-read-incoming-hook
)
1591 (nnheader-message 4 "%s: Reading incoming mail (%d new)...done" method
1593 ;; Close the message-id cache.
1594 (nnmail-cache-close)
1595 ;; Allow the user to hook.
1596 (run-hooks 'nnmail-post-get-new-mail-hook
))))
1598 (defun nnmail-expired-article-p (group time force
&optional inhibit
)
1599 "Say whether an article that is TIME old in GROUP should be expired."
1602 (let ((days (or (and nnmail-expiry-wait-function
1603 (funcall nnmail-expiry-wait-function group
))
1604 nnmail-expiry-wait
)))
1605 (cond ((or (eq days
'never
)
1608 ;; This isn't an expirable group.
1610 ((eq days
'immediate
)
1611 ;; We expire all articles on sight.
1613 ((equal time
'(0 0))
1614 ;; This is an ange-ftp group, and we don't have any dates.
1617 (setq days
(days-to-time days
))
1618 ;; Compare the time with the current time.
1619 (ignore-errors (time-less-p days
(time-since time
))))))))
1621 (defun nnmail-expiry-target-group (target group
)
1622 (when (nnheader-functionp target
)
1623 (setq target
(funcall target group
)))
1624 (unless (eq target
'delete
)
1625 (gnus-request-accept-article target nil nil t
)))
1627 (defun nnmail-check-syntax ()
1628 "Check (and modify) the syntax of the message in the current buffer."
1630 (message-narrow-to-head)
1631 (let ((case-fold-search t
))
1632 (unless (re-search-forward "^Message-ID[ \t]*:" nil t
)
1633 (insert "Message-ID: " (nnmail-message-id) "\n")))))
1635 (defun nnmail-write-region (start end filename
&optional append visit lockname
)
1636 "Do a `write-region', and then set the file modes."
1637 (let ((coding-system-for-write nnmail-file-coding-system
)
1638 (file-name-coding-system nnmail-pathname-coding-system
))
1639 (write-region start end filename append visit lockname
)
1640 (set-file-modes filename nnmail-default-file-modes
)))
1643 ;;; Status functions
1646 (defun nnmail-replace-status (name value
)
1647 "Make status NAME and VALUE part of the current status line."
1649 (message-narrow-to-head)
1650 (let ((status (nnmail-decode-status)))
1651 (setq status
(delq (member name status
) status
))
1653 (push (cons name value
) status
))
1654 (message-remove-header "status")
1655 (goto-char (point-max))
1656 (insert "Status: " (nnmail-encode-status status
) "\n"))))
1658 (defun nnmail-decode-status ()
1659 "Return a status-value alist from STATUS."
1660 (goto-char (point-min))
1661 (when (re-search-forward "^Status: " nil t
)
1662 (let (name value status
)
1664 ;; Narrow to the status.
1667 (if (re-search-forward "^[^ \t]" nil t
)
1670 ;; Go through all elements and add them to the list.
1671 (goto-char (point-min))
1672 (while (re-search-forward "[^ \t=]+" nil t
)
1673 (setq name
(match-string 0))
1674 (if (not (eq (char-after) ?
=))
1678 (if (not (eq (char-after) ?
\"))
1679 (if (not (looking-at "[^ \t]"))
1683 (setq value
(match-string 0))
1684 (goto-char (match-end 0)))
1686 (setq value
(read (current-buffer)))))
1687 (push (cons name value
) status
)))
1690 (defun nnmail-encode-status (status)
1691 "Return a status string from STATUS."
1696 (if (string-match "[ \t]" (cdr elem
))
1697 (prin1-to-string (cdr elem
))
1701 (defun nnmail-split-history ()
1702 "Generate an overview of where the last mail split put articles."
1704 (unless nnmail-split-history
1705 (error "No current split history"))
1706 (with-output-to-temp-buffer "*nnmail split history*"
1707 (with-current-buffer standard-output
1708 (fundamental-mode)) ; for Emacs 20.4+
1709 (let ((history nnmail-split-history
)
1711 (while (setq elem
(pop history
))
1712 (princ (mapconcat (lambda (ga)
1713 (concat (car ga
) ":" (int-to-string (cdr ga
))))
1718 (defun nnmail-purge-split-history (group)
1719 "Remove all instances of GROUP from `nnmail-split-history'."
1720 (let ((history nnmail-split-history
))
1722 (setcar history
(gnus-delete-if (lambda (e) (string= (car e
) group
))
1725 (setq nnmail-split-history
(delq nil nnmail-split-history
))))
1727 (defun nnmail-new-mail-p (group)
1728 "Say whether GROUP has new mail."
1729 (let ((his nnmail-split-history
)
1732 (when (assoc group
(pop 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 ;;; arch-tag: fe8f671a-50db-428a-bb5d-f00462f72ed7
1750 ;;; nnmail.el ends here