1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32 (defvar nnmail-split-methods
34 "*Incoming mail will be split according to this variable.
36 If you'd like, for instance, one mail group for mail from the
37 \"4ad-l\" mailing list, one group for junk mail and one for everything
38 else, you could do something like this:
40 (setq nnmail-split-methods
41 '((\"mail.4ad\" \"From:.*4ad\")
42 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
43 (\"mail.misc\" \"\")))
45 As you can see, this variable is a list of lists, where the first
46 element in each \"rule\" is the name of the group (which, by the way,
47 does not have to be called anything beginning with \"mail\",
48 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
49 nnmail will try to match on the header to find a fit.
51 The second element can also be a function. In that case, it will be
52 called narrowed to the headers with the first element of the rule as
53 the argument. It should return a non-nil value if it thinks that the
54 mail belongs in that group.
56 The last element should always have \"\" as the regexp.
58 This variable can also have a function as its value.")
60 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
61 (defvar nnmail-crosspost t
62 "*If non-nil, do crossposting if several split methods match the mail.
63 If nil, the first match found will be used.")
65 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
66 (defvar nnmail-keep-last-article nil
67 "*If non-nil, nnmail will never delete the last expired article in a
68 directory. You may need to set this variable if other programs are putting
69 new mail into folder numbers that Gnus has marked as expired.")
71 (defvar nnmail-expiry-wait
7
72 "*Articles that are older than `nnmail-expiry-wait' days will be expired.")
74 (defvar nnmail-expiry-wait-function nil
75 "*Variable that holds function to specify how old articles should be before they are expired.
76 The function will be called with the name of the group that the
77 expiry is to be performed in, and it should return an integer that
78 says how many days an article can be stored before it is considered
83 (setq nnmail-expiry-wait-function
85 (cond ((string-match \"private\" newsgroup) 31)
86 ((string-match \"junk\" newsgroup) 1)
89 (defvar nnmail-spool-file
91 (concat "/usr/spool/mail/" (user-login-name)))
92 "Where the mail backends will look for incoming mail.
93 This variable is \"/usr/spool/mail/$user\" by default.
94 If this variable is nil, no mail backends will read incoming mail.
95 If this variable is a list, all files mentioned in this list will be
96 used as incoming mailboxes.")
98 (defvar nnmail-use-procmail nil
99 "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
100 The file(s) in `nnmail-spool-file' will also be read.")
102 (defvar nnmail-procmail-directory
"~/incoming/"
103 "*When using procmail (and the like), incoming mail is put in this directory.
104 The Gnus mail backends will read the mail from this directory.")
106 (defvar nnmail-procmail-suffix
".spool"
107 "*Suffix of files created by procmail (and the like).
108 This variable might be a suffix-regexp to match the suffixes of
109 several files - eg. \".spool[0-9]*\".")
111 (defvar nnmail-resplit-incoming nil
112 "*If non-nil, re-split incoming procmail sorted mail.")
114 (defvar nnmail-movemail-program
"movemail"
115 "*A command to be executed to move mail from the inbox.
116 The default is \"movemail\".")
118 (defvar nnmail-read-incoming-hook nil
119 "*Hook that will be run after the incoming mail has been transferred.
120 The incoming mail is moved from `nnmail-spool-file' (which normally is
121 something like \"/usr/spool/mail/$user\") to the user's home
122 directory. This hook is called after the incoming mail box has been
123 emptied, and can be used to call any mail box programs you have
124 running (\"xwatch\", etc.)
128 (add-hook 'nnmail-read-incoming-hook
130 (start-process \"mailsend\" nil
131 \"/local/bin/mailsend\" \"read\" \"mbox\")))")
133 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
134 (defvar nnmail-prepare-incoming-hook nil
135 "*Hook called before treating incoming mail.
136 The hook is run in a buffer with all the new, incoming mail.")
138 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
139 (defvar nnmail-tmp-directory nil
140 "*If non-nil, use this directory for temporary storage when reading incoming mail.")
142 (defvar nnmail-large-newsgroup
50
143 "*The number of the articles which indicates a large newsgroup.
144 If the number of the articles is greater than the value, verbose
145 messages will be shown to indicate the current status.")
147 (defvar nnmail-split-fancy
"mail.misc"
148 "*Incoming mail can be split according to this fancy variable.
149 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
151 The format is this variable is SPLIT, where SPLIT can be one of
154 GROUP: Mail will be stored in GROUP (a string).
156 \(FIELD VALUE SPLIT): If the message field FIELD (a regexp) contains
157 VALUE (a regexp), store the messages as specified by SPLIT.
159 \(| SPLIT...): Process each SPLIT expression until one of them matches.
160 A SPLIT expression is said to match if it will cause the mail
161 message to be stored in one or more groups.
163 \(& SPLIT...): Process each SPLIT expression.
165 FIELD must match a complete field name. VALUE must match a complete
166 word according to the fundamental mode syntax table. You can use .*
167 in the regexps to match partial field names or words.
169 FIELD and VALUE can also be lisp symbols, in that case they are expanded
170 as specified in `nnmail-split-abbrev-alist'.
174 \(setq nnmail-split-methods 'nnmail-split-fancy
176 ;; Messages from the mailer deamon are not crossposted to any of
177 ;; the ordinary groups. Warnings are put in a separate group
179 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
181 ;; Non-error messages are crossposted to all relevant
182 ;; groups, but we don't crosspost between the group for the
183 ;; (ding) list and the group for other (ding) related mail.
184 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
185 (\"subject\" \"ding\" \"ding.misc\"))
186 ;; Other mailing lists...
187 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
188 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
190 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
191 ;; Unmatched mail goes to the catch all group.
194 (defvar nnmail-split-abbrev-alist
195 '((any .
"from\\|to\\|cc\\|sender\\|apparently-to")
196 (mail .
"mailer-daemon\\|postmaster"))
197 "*Alist of abbreviations allowed in `nnmail-split-fancy'.")
199 (defvar nnmail-delete-incoming t
200 "*If non-nil, the mail backends will delete incoming files after splitting.")
202 (defvar nnmail-message-id-cache-length
1000
203 "*The approximate number of Message-IDs nnmail will keep in its cache.
204 If this variable is nil, no checking on duplicate messages will be
207 (defvar nnmail-message-id-cache-file
"~/.nnmail-cache"
208 "*The file name of the nnmail Message-ID cache.")
210 (defvar nnmail-delete-duplicates nil
211 "*If non-nil, nnmail will delete any duplicate mails it sees.")
215 (defconst nnmail-version
"nnmail 1.0"
220 (defun nnmail-request-post (&optional server
)
221 (mail-send-and-exit nil
))
223 (defun nnmail-request-post-buffer (post group subject header article-buffer
224 info follow-to respect-poster
)
225 (let ((method-address (cdr (assq 'to-address
(nth 5 info
))))
226 from date to reply-to message-of
227 references message-id cc new-cc sendto elt
)
229 (if (and (stringp method-address
)
230 (string= method-address
""))
233 (set-buffer (get-buffer-create "*mail*"))
235 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit
)
236 (if (and (buffer-modified-p)
238 (not (y-or-n-p "Unsent mail being composed; erase it? ")))
243 (mail-setup method-address subject nil nil nil nil
)
244 (auto-save-mode auto-save-default
))
246 (set-buffer article-buffer
)
247 (goto-char (point-min))
248 (narrow-to-region (point-min)
249 (progn (search-forward "\n\n") (point)))
250 (let ((buffer-read-only nil
))
251 (set-text-properties (point-min) (point-max) nil
))
252 (setq from
(mail-header-from header
))
253 (setq date
(mail-header-date header
))
256 (string-match " *at \\| *@ \\| *(\\| *<" from
)))
258 (concat (if stop-pos
(substring from
0 stop-pos
) from
)
259 "'s message of " date
))))
260 (setq cc
(mail-strip-quoted-names (or (mail-fetch-field "cc") "")))
261 (setq to
(mail-strip-quoted-names (or (mail-fetch-field "to") "")))
262 (setq new-cc
(rmail-dont-reply-to
264 (if cc
(concat (if to
", " "") cc
) ""))))
265 (let ((rmail-dont-reply-to-names
266 (regexp-quote (mail-strip-quoted-names
267 (or method-address reply-to from
"")))))
268 (setq new-cc
(rmail-dont-reply-to new-cc
)))
269 (setq subject
(mail-header-subject header
))
270 (or (string-match "^[Rr][Ee]:" subject
)
271 (setq subject
(concat "Re: " subject
)))
272 (setq reply-to
(mail-fetch-field "reply-to"))
273 (setq references
(mail-header-references header
))
274 (setq message-id
(mail-header-id header
))
276 (setq news-reply-yank-from from
)
277 (setq news-reply-yank-message-id message-id
)
279 ;; Gather the "to" addresses out of the follow-to list and remove
281 (if (and follow-to
(listp follow-to
))
282 (while (setq elt
(assoc "To" follow-to
))
283 (setq sendto
(concat sendto
(and sendto
", ") (cdr elt
)))
284 (setq follow-to
(delq elt follow-to
))))
285 (mail-setup (if (and follow-to
(listp follow-to
))
287 (or method-address reply-to from
""))
289 (if (zerop (length new-cc
)) nil new-cc
)
291 (auto-save-mode auto-save-default
)
292 ;; Note that "To" elements should already be in the message.
293 (if (and follow-to
(listp follow-to
))
295 (goto-char (point-min))
296 (re-search-forward "^To:" nil t
)
301 (car (car follow-to
)) ": " (cdr (car follow-to
)) "\n")
302 (setq follow-to
(cdr follow-to
)))))
303 (nnheader-insert-references references message-id
)))
306 (defun nnmail-find-file (file)
307 "Insert FILE in server buffer safely."
308 (set-buffer nntp-server-buffer
)
311 (progn (insert-file-contents file
) t
)
314 (defun nnmail-article-pathname (group mail-dir
)
315 "Make pathname for GROUP."
316 (concat (file-name-as-directory (expand-file-name mail-dir
))
317 (nnmail-replace-chars-in-string group ?. ?
/) "/"))
319 (defun nnmail-replace-chars-in-string (string from to
)
320 "Replace characters in STRING from FROM to TO."
321 (let ((string (substring string
0)) ;Copy string.
322 (len (length string
))
324 ;; Replace all occurrences of FROM with TO.
326 (if (= (aref string idx
) from
)
327 (aset string idx to
))
331 (defun nnmail-days-between (date1 date2
)
332 ;; Return the number of days between date1 and date2.
333 (let ((d1 (mapcar (lambda (s) (and s
(string-to-int s
)) )
334 (timezone-parse-date date1
)))
335 (d2 (mapcar (lambda (s) (and s
(string-to-int s
)) )
336 (timezone-parse-date date2
))))
337 (- (timezone-absolute-from-gregorian
338 (nth 1 d1
) (nth 2 d1
) (car d1
))
339 (timezone-absolute-from-gregorian
340 (nth 1 d2
) (nth 2 d2
) (car d2
)))))
342 ;; Function taken from rmail.el.
343 (defun nnmail-move-inbox (inbox tofile
)
344 (let ((inbox (file-truename
345 (expand-file-name (substitute-in-file-name inbox
))))
346 movemail popmail errors
)
347 ;; Check whether the inbox is to be moved to the special tmp dir.
348 (if nnmail-tmp-directory
349 (setq tofile
(concat (file-name-as-directory nnmail-tmp-directory
)
350 (file-name-nondirectory tofile
))))
351 ;; Make the filename unique.
352 (setq tofile
(nnmail-make-complex-temp-name (expand-file-name tofile
)))
353 ;; We create the directory the tofile is to reside in if it
355 (or (file-exists-p (file-name-directory tofile
))
356 (make-directory tofile
'parents
))
357 ;; If getting from mail spool directory,
358 ;; use movemail to move rather than just renaming,
359 ;; so as to interlock with the mailer.
360 (or (setq popmail
(string-match "^po:" (file-name-nondirectory inbox
)))
362 (if popmail
(setq inbox
(file-name-nondirectory inbox
)))
364 ;; On some systems, /usr/spool/mail/foo is a directory
365 ;; and the actual inbox is /usr/spool/mail/foo/foo.
366 (if (file-directory-p inbox
)
367 (setq inbox
(expand-file-name (user-login-name) inbox
))))
369 (message "Getting mail from post office ...")
370 (if (or (and (file-exists-p tofile
)
371 (/= 0 (nth 7 (file-attributes tofile
))))
372 (and (file-exists-p inbox
)
373 (/= 0 (nth 7 (file-attributes inbox
)))))
374 (message "Getting mail from %s..." inbox
)))
375 ;; Set TOFILE if have not already done so, and
376 ;; rename or copy the file INBOX to TOFILE if and as appropriate.
377 (cond ((or (file-exists-p tofile
) (and (not popmail
)
378 (not (file-exists-p inbox
))))
380 ((and (not movemail
) (not popmail
))
381 ;; Try copying. If that fails (perhaps no space),
384 (copy-file inbox tofile nil
)
386 ;; Third arg is t so we can replace existing file TOFILE.
387 (rename-file inbox tofile t
)))
388 ;; Make the real inbox file empty.
389 ;; Leaving it deleted could cause lossage
390 ;; because mailers often won't create the file.
392 (write-region (point) (point) inbox
)
397 (setq errors
(generate-new-buffer " *nnmail loss*"))
398 (buffer-disable-undo errors
)
400 (expand-file-name nnmail-movemail-program exec-directory
)
401 nil errors nil inbox tofile
)
402 (if (not (buffer-modified-p errors
))
403 ;; No output => movemail won
406 (subst-char-in-region (point-min) (point-max) ?
\n ?\
)
407 (goto-char (point-max))
408 (skip-chars-backward " \t")
409 (delete-region (point) (point-max))
410 (goto-char (point-min))
411 (if (looking-at "movemail: ")
412 (delete-region (point-min) (match-end 0)))
414 (message (concat "movemail: "
415 (buffer-substring (point-min)
421 (kill-buffer errors
))
425 (defun nnmail-get-active ()
426 "Returns an assoc of group names and active ranges.
427 nn*-request-list should have been called before calling this function."
429 ;; Go through all groups from the active list.
431 (set-buffer nntp-server-buffer
)
432 (goto-char (point-min))
433 (while (re-search-forward
434 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t
)
436 (cons (list (buffer-substring (match-beginning 1)
439 (buffer-substring (match-beginning 3)
442 (buffer-substring (match-beginning 2)
446 ;; ;; In addition, add all groups mentioned in `nnmail-split-methods'.
447 ;; (let ((methods (and (not (symbolp nnmail-split-methods))
448 ;; nnmail-split-methods)))
450 ;; (if (not (assoc (car (car methods)) group-assoc))
452 ;; (cons (list (car (car methods)) (cons 1 0))
454 ;; (setq methods (cdr methods)))
458 (defun nnmail-save-active (group-assoc file-name
)
461 (set-buffer (get-buffer-create " *nnmail active*"))
462 (buffer-disable-undo (current-buffer))
465 (setq group
(car group-assoc
))
466 (insert (format "%s %d %d y\n" (car group
) (cdr (car (cdr group
)) )
467 (car (car (cdr group
)))))
468 (setq group-assoc
(cdr group-assoc
)))
469 (write-region 1 (point-max) (expand-file-name file-name
) nil
'nomesg
)
470 (kill-buffer (current-buffer)))))
472 (defun nnmail-get-split-group (file group
)
473 (if (or (eq nnmail-spool-file
'procmail
)
476 ((string-match (concat "^" (expand-file-name
477 (file-name-as-directory
478 nnmail-procmail-directory
))
479 "\\(.*\\)" nnmail-procmail-suffix
"$")
480 (expand-file-name file
))
481 (substring (expand-file-name file
)
482 (match-beginning 1) (match-end 1)))
487 (defun nnmail-split-incoming (incoming func
&optional dont-kill group
)
488 "Go through the entire INCOMING file and pick out each individual mail.
489 FUNC will be called with the buffer narrowed to each mail."
490 (let ((delim (concat "^" rmail-unix-mail-delimiter
))
491 ;; If this is a group-specific split, we bind the split
492 ;; methods to just this group.
493 (nnmail-split-methods (if (and group
494 (or (eq nnmail-spool-file
'procmail
)
496 (not nnmail-resplit-incoming
))
497 (list (list group
""))
498 nnmail-split-methods
))
499 start end content-length do-search message-id
)
501 ;; Open the message-id cache.
503 ;; Insert the incoming file.
504 (set-buffer (get-buffer-create " *nnmail incoming*"))
505 (buffer-disable-undo (current-buffer))
507 (insert-file-contents incoming
)
508 (goto-char (point-min))
509 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook
))
510 ;; Go to the beginning of the first mail...
511 (if (and (re-search-forward delim nil t
)
512 (goto-char (match-beginning 0)))
513 ;; and then carry on until the bitter end.
516 ;; Skip all the headers in case there are more "From "s...
517 (if (not (search-forward "\n\n" nil t
))
519 ;; Find the Message-ID header.
521 (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t
)
522 (setq message-id
(buffer-substring (match-beginning 1)
524 ;; There is no Message-ID here, so we create one.
526 (insert "Message-ID: " (setq message-id
(nnmail-message-id))
528 ;; Look for a Content-Length header.
529 (if (not (save-excursion
530 (and (re-search-backward
531 "^Content-Length: \\([0-9]+\\)" start t
)
532 (setq content-length
(string-to-int
536 ;; We destroy the header, since none of
537 ;; the backends ever use it, and we do not
538 ;; want to confuse other mailers by having
539 ;; a (possibly) faulty header.
540 (progn (insert "X-") t
))))
542 (if (or (= (+ (point) content-length
) (point-max))
544 (goto-char (+ (point) content-length
))
547 (goto-char (+ (point) content-length
))
548 (setq do-search nil
))
550 ;; Go to the beginning of the next article - or to the end
553 (if (re-search-forward delim nil t
)
554 (goto-char (match-beginning 0))
555 (goto-char (point-max))))
558 (narrow-to-region start
(point))
559 (goto-char (point-min))
560 ;; If this is a duplicate message, then we do not save it.
561 (if (nnmail-cache-id-exists-p message-id
)
562 (delete-region (point-min) (point-max))
563 (nnmail-cache-insert message-id
)
565 (setq end
(point-max))))
567 ;; Close the message-id cache.
571 (kill-buffer (current-buffer))))))
573 ;; Mail crossposts syggested by Brian Edmonds <edmonds@cs.ubc.ca>.
574 (defun nnmail-article-group (func)
575 "Look at the headers and return an alist of groups that match.
576 FUNC will be called with the group name to determine the article number."
577 (let ((methods nnmail-split-methods
)
578 (obuf (current-buffer))
581 (if (and (sequencep methods
) (= (length methods
) 1))
582 ;; If there is only just one group to put everything in, we
583 ;; just return a list with just this one method in.
585 (list (cons (car (car methods
))
586 (funcall func
(car (car methods
))))))
587 ;; We do actual comparison.
591 (setq end
(if (search-forward "\n\n" nil t
) (point) (point-max)))
592 (set-buffer (get-buffer-create " *nnmail work*"))
593 (buffer-disable-undo (current-buffer))
595 ;; Copy the headers into the work buffer.
596 (insert-buffer-substring obuf beg end
)
597 ;; Fold continuation lines.
598 (goto-char (point-min))
599 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t
)
600 (replace-match " " t t
))
601 (if (and (symbolp nnmail-split-methods
)
602 (fboundp nnmail-split-methods
))
605 (lambda (group) (cons group
(funcall func group
)))
607 (funcall nnmail-split-methods
)
610 Problems with `nnmail-split-methods', using `bogus' mail group")
613 ;; Go throught the split methods to find a match.
614 (while (and methods
(or nnmail-crosspost
(not group-art
)))
615 (goto-char (point-max))
616 (if (or (cdr methods
)
617 (not (equal "" (nth 1 (car methods
)))))
618 (if (and (condition-case ()
619 (if (stringp (nth 1 (car methods
)))
621 (car (cdr (car methods
))) nil t
)
622 ;; Suggested by Brian Edmonds
623 ;; <edmonds@cs.ubc.ca>.
624 (funcall (nth 1 (car methods
))
625 (car (car methods
))))
627 ;; Don't enter the article into the same group twice.
628 (not (assoc (car (car methods
)) group-art
)))
630 (cons (cons (car (car methods
))
631 (funcall func
(car (car methods
))))
635 (list (cons (car (car methods
))
636 (funcall func
(car (car methods
))))))))
637 (setq methods
(cdr methods
))))
638 (kill-buffer (current-buffer))
641 (defun nnmail-insert-lines ()
642 "Insert how many lines and chars there are in the body of the mail."
645 (goto-char (point-min))
646 (if (search-forward "\n\n" nil t
)
648 (setq chars
(- (point-max) (point)))
649 (setq lines
(- (count-lines (point) (point-max)) 1))
652 (if (re-search-backward "^Lines: " nil t
)
653 (delete-region (point) (progn (forward-line 1) (point)))))
654 (insert (format "Lines: %d\n" lines
))
657 (defun nnmail-insert-xref (group-alist)
658 "Insert an Xref line based on the (group . article) alist."
660 (goto-char (point-min))
661 (if (search-forward "\n\n" nil t
)
664 (if (re-search-backward "^Xref: " nil t
)
665 (delete-region (match-beginning 0)
666 (progn (forward-line 1) (point))))
667 (insert (format "Xref: %s" (system-name)))
669 (insert (format " %s:%d" (car (car group-alist
))
670 (cdr (car group-alist
))))
671 (setq group-alist
(cdr group-alist
)))
674 ;; Written by byer@mv.us.adobe.com (Scott Byer).
675 (defun nnmail-make-complex-temp-name (prefix)
676 (let ((newname (make-temp-name prefix
))
678 (while (file-exists-p newname
)
679 (setq newprefix
(concat newprefix
"x"))
680 (setq newname
(make-temp-name newprefix
)))
683 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
685 (defun nnmail-split-fancy ()
686 "Fancy splitting method.
687 See the documentation for the variable `nnmail-split-fancy' for documentation."
688 (nnmail-split-it nnmail-split-fancy
))
690 (defvar nnmail-split-cache nil
)
691 ;; Alist of split expresions their equivalent regexps.
693 (defun nnmail-split-it (split)
694 ;; Return a list of groups matching SPLIT.
695 (cond ((stringp split
)
699 (apply 'nconc
(mapcar 'nnmail-split-it
(cdr split
))))
702 (while (and (not done
) (cdr split
))
703 (setq split
(cdr split
)
704 done
(nnmail-split-it (car split
))))
705 done
)) ((assq split nnmail-split-cache
)
706 ;; A compiled match expression.
707 (goto-char (point-max))
708 (if (re-search-backward (cdr (assq split nnmail-split-cache
)) nil t
)
709 (nnmail-split-it (nth 2 split
))))
711 ;; An uncompiled match.
712 (let* ((field (nth 0 split
))
713 (value (nth 1 split
))
714 (regexp (concat "^\\("
717 nnmail-split-abbrev-alist
))
722 nnmail-split-abbrev-alist
))
725 (setq nnmail-split-cache
726 (cons (cons split regexp
) nnmail-split-cache
))
727 (goto-char (point-max))
728 (if (re-search-backward regexp nil t
)
729 (nnmail-split-it (nth 2 split
)))))))
731 ;; Get a list of spool files to read.
732 (defun nnmail-get-spool-files (&optional group
)
733 (if (null nnmail-spool-file
)
734 ;; No spool file whatsoever.
737 ;; If procmail is used to get incoming mail, the files
738 ;; are stored in this directory.
739 (and (file-exists-p nnmail-procmail-directory
)
741 nnmail-procmail-directory
742 t
(concat (if group group
"")
743 nnmail-procmail-suffix
"$") t
)))
745 ;; Remove any directories that inadvertantly match the procmail
746 ;; suffix, which might happen if the suffix is "".
748 (and (or (file-directory-p (car p
))
749 (file-symlink-p (car p
)))
750 (setq procmails
(delete (car p
) procmails
)))
752 (cond ((listp nnmail-spool-file
)
753 (append nnmail-spool-file procmails
))
754 ((stringp nnmail-spool-file
)
755 (cons nnmail-spool-file procmails
))
759 ;; Activate a backend only if it isn't already activated.
760 ;; If FORCE, re-read the active file even if the backend is
761 ;; already activated.
762 (defun nnmail-activate (backend &optional force
)
763 (let (file timestamp file-time
)
764 (if (or (not (symbol-value (intern (format "%s-group-alist" backend
))))
766 (and (setq file
(condition-case ()
767 (symbol-value (intern (format "%s-active-file"
770 (setq file-time
(nth 5 (file-attributes file
)))
774 (symbol-value (intern
775 (format "%s-active-timestamp"
778 (not (consp timestamp
))
779 (equal timestamp
'(0 0))
780 (> (nth 0 file-time
) (nth 0 timestamp
))
781 (and (= (nth 0 file-time
) (nth 0 timestamp
))
782 (> (nth 1 file-time
) (nth 1 timestamp
))))))
784 (or (eq timestamp
'none
)
785 (set (intern (format "%s-active-timestamp" backend
))
787 (funcall (intern (format "%s-request-list" backend
)))
788 (set (intern (format "%s-group-alist" backend
))
789 (nnmail-get-active))))
792 (defun nnmail-message-id ()
793 (concat "<" (nnmail-unique-id) "@totally-fudged-out-message-id>"))
795 (defvar nnmail-unique-id-char nil
)
797 (defun nnmail-number-base36 (num len
)
798 (if (if (< len
0) (<= num
0) (= len
0))
800 (concat (nnmail-number-base36 (/ num
36) (1- len
))
801 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
804 (defun nnmail-unique-id ()
805 (setq nnmail-unique-id-char
806 (%
(1+ (or nnmail-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
807 ;; (current-time) returns 16-bit ints,
808 ;; and 2^16*25 just fits into 4 digits i base 36.
810 (let ((tm (if (fboundp 'current-time
)
811 (current-time) '(12191 46742 287898))))
813 (nnmail-number-base36 (+ (car tm
)
814 (lsh (% nnmail-unique-id-char
25) 16)) 4)
815 (nnmail-number-base36 (+ (nth 1 tm
)
816 (lsh (/ nnmail-unique-id-char
25) 16)) 4))))
819 ;;; nnmail duplicate handling
822 (defvar nnmail-cache-buffer nil
)
824 (defun nnmail-cache-open ()
825 (if (or (not nnmail-delete-duplicates
)
826 (and nnmail-cache-buffer
827 (buffer-name nnmail-cache-buffer
)))
828 () ; The buffer is open.
831 (setq nnmail-cache-buffer
832 (get-buffer-create " *nnmail message-id cache*")))
833 (buffer-disable-undo (current-buffer))
834 (and (file-exists-p nnmail-message-id-cache-file
)
835 (insert-file-contents nnmail-message-id-cache-file
))
838 (defun nnmail-cache-close ()
839 (if (or (not nnmail-cache-buffer
)
840 (not nnmail-delete-duplicates
)
841 (not (buffer-name nnmail-cache-buffer
))
842 (not (buffer-modified-p nnmail-cache-buffer
)))
843 () ; The buffer is closed.
845 (set-buffer nnmail-cache-buffer
)
846 ;; Weed out the excess number of Message-IDs.
847 (goto-char (point-max))
848 (and (search-backward "\n" nil t nnmail-message-id-cache-length
)
851 (delete-region (point-min) (point))))
853 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file
))
854 (make-directory (file-name-directory nnmail-message-id-cache-file
)
856 (write-region (point-min) (point-max)
857 nnmail-message-id-cache-file nil
'silent
)
858 (set-buffer-modified-p nil
))))
860 (defun nnmail-cache-insert (id)
861 (and nnmail-delete-duplicates
863 (set-buffer nnmail-cache-buffer
)
864 (goto-char (point-max))
867 (defun nnmail-cache-id-exists-p (id)
868 (and nnmail-delete-duplicates
870 (set-buffer nnmail-cache-buffer
)
871 (goto-char (point-max))
872 (search-backward id nil t
))))
877 ;;; nnmail.el ends here