0
|
1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
|
|
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
|
|
5 ;; Keywords: news, mail
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
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)
|
|
12 ;; any later version.
|
|
13
|
|
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.
|
|
18
|
|
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.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (require 'nnheader)
|
|
29 (require 'timezone)
|
|
30 (require 'message)
|
|
31 (eval-when-compile (require 'cl))
|
|
32
|
|
33 (defvar nnmail-split-methods
|
|
34 '(("mail.misc" ""))
|
|
35 "*Incoming mail will be split according to this variable.
|
|
36
|
|
37 If you'd like, for instance, one mail group for mail from the
|
|
38 \"4ad-l\" mailing list, one group for junk mail and one for everything
|
|
39 else, you could do something like this:
|
|
40
|
|
41 (setq nnmail-split-methods
|
|
42 '((\"mail.4ad\" \"From:.*4ad\")
|
|
43 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
|
|
44 (\"mail.misc\" \"\")))
|
|
45
|
|
46 As you can see, this variable is a list of lists, where the first
|
|
47 element in each \"rule\" is the name of the group (which, by the way,
|
|
48 does not have to be called anything beginning with \"mail\",
|
|
49 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
|
|
50 nnmail will try to match on the header to find a fit.
|
|
51
|
|
52 The second element can also be a function. In that case, it will be
|
|
53 called narrowed to the headers with the first element of the rule as
|
|
54 the argument. It should return a non-nil value if it thinks that the
|
|
55 mail belongs in that group.
|
|
56
|
|
57 The last element should always have \"\" as the regexp.
|
|
58
|
|
59 This variable can also have a function as its value.")
|
|
60
|
|
61 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
|
|
62 (defvar nnmail-crosspost t
|
|
63 "*If non-nil, do crossposting if several split methods match the mail.
|
|
64 If nil, the first match found will be used.")
|
|
65
|
|
66 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
|
|
67 (defvar nnmail-keep-last-article nil
|
|
68 "*If non-nil, nnmail will never delete the last expired article in a directory.
|
|
69 You may need to set this variable if other programs are putting
|
|
70 new mail into folder numbers that Gnus has marked as expired.")
|
|
71
|
|
72 (defvar nnmail-use-long-file-names nil
|
|
73 "*If non-nil the mail backends will use long file and directory names.
|
|
74 If nil, groups like \"mail.misc\" will end up in directories like
|
|
75 \"mail/misc/\".")
|
|
76
|
|
77 (defvar nnmail-expiry-wait 7
|
|
78 "*Expirable articles that are older than this will be expired.
|
|
79 This variable can either be a number (which will be interpreted as a
|
|
80 number of days) -- this doesn't have to be an integer. This variable
|
|
81 can also be `immediate' and `never'.")
|
|
82
|
|
83 (defvar nnmail-expiry-wait-function nil
|
|
84 "*Variable that holds function to specify how old articles should be before they are expired.
|
|
85 The function will be called with the name of the group that the
|
|
86 expiry is to be performed in, and it should return an integer that
|
|
87 says how many days an article can be stored before it is considered
|
|
88 \"old\". It can also return the values `never' and `immediate'.
|
|
89
|
|
90 Eg.:
|
|
91
|
|
92 (setq nnmail-expiry-wait-function
|
|
93 (lambda (newsgroup)
|
|
94 (cond ((string-match \"private\" newsgroup) 31)
|
|
95 ((string-match \"junk\" newsgroup) 1)
|
|
96 ((string-match \"important\" newsgroup) 'never)
|
|
97 (t 7))))")
|
|
98
|
|
99 (defvar nnmail-spool-file
|
|
100 (or (getenv "MAIL")
|
|
101 (concat "/usr/spool/mail/" (user-login-name)))
|
|
102 "Where the mail backends will look for incoming mail.
|
|
103 This variable is \"/usr/spool/mail/$user\" by default.
|
|
104 If this variable is nil, no mail backends will read incoming mail.
|
|
105 If this variable is a list, all files mentioned in this list will be
|
|
106 used as incoming mailboxes.")
|
|
107
|
|
108 (defvar nnmail-crash-box "~/.gnus-crash-box"
|
|
109 "*File where Gnus will store mail while processing it.")
|
|
110
|
|
111 (defvar nnmail-use-procmail nil
|
|
112 "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
|
|
113 The file(s) in `nnmail-spool-file' will also be read.")
|
|
114
|
|
115 (defvar nnmail-procmail-directory "~/incoming/"
|
|
116 "*When using procmail (and the like), incoming mail is put in this directory.
|
|
117 The Gnus mail backends will read the mail from this directory.")
|
|
118
|
|
119 (defvar nnmail-procmail-suffix "\\.spool"
|
|
120 "*Suffix of files created by procmail (and the like).
|
|
121 This variable might be a suffix-regexp to match the suffixes of
|
|
122 several files - eg. \".spool[0-9]*\".")
|
|
123
|
|
124 (defvar nnmail-resplit-incoming nil
|
|
125 "*If non-nil, re-split incoming procmail sorted mail.")
|
|
126
|
|
127 (defvar nnmail-delete-file-function 'delete-file
|
|
128 "Function called to delete files in some mail backends.")
|
|
129
|
|
130 (defvar nnmail-crosspost-link-function 'add-name-to-file
|
|
131 "Function called to create a copy of a file.
|
|
132 This is `add-name-to-file' by default, which means that crossposts
|
|
133 will use hard links. If your file system doesn't allow hard
|
|
134 links, you could set this variable to `copy-file' instead.")
|
|
135
|
|
136 (defvar nnmail-movemail-program "movemail"
|
|
137 "*A command to be executed to move mail from the inbox.
|
|
138 The default is \"movemail\".")
|
|
139
|
|
140 (defvar nnmail-pop-password-required nil
|
|
141 "*Non-nil if a password is required when reading mail using POP.")
|
|
142
|
|
143 (defvar nnmail-read-incoming-hook nil
|
|
144 "*Hook that will be run after the incoming mail has been transferred.
|
|
145 The incoming mail is moved from `nnmail-spool-file' (which normally is
|
|
146 something like \"/usr/spool/mail/$user\") to the user's home
|
|
147 directory. This hook is called after the incoming mail box has been
|
|
148 emptied, and can be used to call any mail box programs you have
|
|
149 running (\"xwatch\", etc.)
|
|
150
|
|
151 Eg.
|
|
152
|
|
153 \(add-hook 'nnmail-read-incoming-hook
|
|
154 (lambda ()
|
|
155 (start-process \"mailsend\" nil
|
|
156 \"/local/bin/mailsend\" \"read\" \"mbox\")))
|
|
157
|
|
158 If you have xwatch running, this will alert it that mail has been
|
|
159 read.
|
|
160
|
|
161 If you use `display-time', you could use something like this:
|
|
162
|
|
163 \(add-hook 'nnmail-read-incoming-hook
|
|
164 (lambda ()
|
|
165 ;; Update the displayed time, since that will clear out
|
|
166 ;; the flag that says you have mail.
|
|
167 (if (eq (process-status \"display-time\") 'run)
|
|
168 (display-time-filter display-time-process \"\"))))")
|
|
169
|
|
170 (when (eq system-type 'windows-nt)
|
|
171 (add-hook 'nnmail-prepare-incoming-hook 'nnheader-ms-strip-cr))
|
|
172
|
|
173 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
|
|
174 (defvar nnmail-prepare-incoming-hook nil
|
|
175 "*Hook called before treating incoming mail.
|
|
176 The hook is run in a buffer with all the new, incoming mail.")
|
|
177
|
|
178 (defvar nnmail-pre-get-new-mail-hook nil
|
|
179 "Hook called just before starting to handle new incoming mail.")
|
|
180
|
|
181 (defvar nnmail-post-get-new-mail-hook nil
|
|
182 "Hook called just after finishing handling new incoming mail.")
|
|
183
|
|
184 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
|
|
185 (defvar nnmail-tmp-directory nil
|
|
186 "*If non-nil, use this directory for temporary storage when reading incoming mail.")
|
|
187
|
|
188 (defvar nnmail-large-newsgroup 50
|
|
189 "*The number of the articles which indicates a large newsgroup.
|
|
190 If the number of the articles is greater than the value, verbose
|
|
191 messages will be shown to indicate the current status.")
|
|
192
|
|
193 (defvar nnmail-split-fancy "mail.misc"
|
|
194 "*Incoming mail can be split according to this fancy variable.
|
|
195 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
|
|
196
|
|
197 The format is this variable is SPLIT, where SPLIT can be one of
|
|
198 the following:
|
|
199
|
|
200 GROUP: Mail will be stored in GROUP (a string).
|
|
201
|
|
202 \(FIELD VALUE SPLIT): If the message field FIELD (a regexp) contains
|
|
203 VALUE (a regexp), store the messages as specified by SPLIT.
|
|
204
|
|
205 \(| SPLIT...): Process each SPLIT expression until one of them matches.
|
|
206 A SPLIT expression is said to match if it will cause the mail
|
|
207 message to be stored in one or more groups.
|
|
208
|
|
209 \(& SPLIT...): Process each SPLIT expression.
|
|
210
|
|
211 FIELD must match a complete field name. VALUE must match a complete
|
|
212 word according to the `nnmail-split-fancy-syntax-table' syntax table.
|
|
213 You can use .* in the regexps to match partial field names or words.
|
|
214
|
|
215 FIELD and VALUE can also be lisp symbols, in that case they are expanded
|
|
216 as specified in `nnmail-split-abbrev-alist'.
|
|
217
|
|
218 Example:
|
|
219
|
|
220 \(setq nnmail-split-methods 'nnmail-split-fancy
|
|
221 nnmail-split-fancy
|
|
222 ;; Messages from the mailer deamon are not crossposted to any of
|
|
223 ;; the ordinary groups. Warnings are put in a separate group
|
|
224 ;; from real errors.
|
|
225 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
|
|
226 \"mail.misc\"))
|
|
227 ;; Non-error messages are crossposted to all relevant
|
|
228 ;; groups, but we don't crosspost between the group for the
|
|
229 ;; (ding) list and the group for other (ding) related mail.
|
|
230 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
|
|
231 (\"subject\" \"ding\" \"ding.misc\"))
|
|
232 ;; Other mailing lists...
|
|
233 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
|
|
234 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
|
|
235 ;; People...
|
|
236 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
|
|
237 ;; Unmatched mail goes to the catch all group.
|
|
238 \"misc.misc\"))")
|
|
239
|
|
240 (defvar nnmail-split-abbrev-alist
|
2
|
241 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
|
0
|
242 (mail . "mailer-daemon\\|postmaster"))
|
|
243 "*Alist of abbreviations allowed in `nnmail-split-fancy'.")
|
|
244
|
|
245 (defvar nnmail-delete-incoming t
|
|
246 "*If non-nil, the mail backends will delete incoming files after splitting.")
|
|
247
|
|
248 (defvar nnmail-message-id-cache-length 1000
|
|
249 "*The approximate number of Message-IDs nnmail will keep in its cache.
|
|
250 If this variable is nil, no checking on duplicate messages will be
|
|
251 performed.")
|
|
252
|
|
253 (defvar nnmail-message-id-cache-file "~/.nnmail-cache"
|
|
254 "*The file name of the nnmail Message-ID cache.")
|
|
255
|
|
256 (defvar nnmail-treat-duplicates 'warn
|
|
257 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
|
|
258 Three values are legal: nil, which means that nnmail is not to keep a
|
|
259 Message-ID cache; `warn', which means that nnmail should insert extra
|
|
260 headers to warn the user about the duplication (this is the default);
|
|
261 and `delete', which means that nnmail will delete duplicated mails.
|
|
262
|
|
263 This variable can also be a function. It will be called from a buffer
|
|
264 narrowed to the article in question with the Message-ID as a
|
|
265 parameter. It should return nil, `warn' or `delete'.")
|
|
266
|
|
267 ;;; Internal variables.
|
|
268
|
|
269 (defvar nnmail-pop-password nil
|
|
270 "*Password to use when reading mail from a POP server, if required.")
|
|
271
|
2
|
272 (defvar nnmail-split-fancy-syntax-table nil
|
0
|
273 "Syntax table used by `nnmail-split-fancy'.")
|
2
|
274 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
|
|
275 (setq nnmail-split-fancy-syntax-table
|
|
276 (copy-syntax-table (standard-syntax-table)))
|
|
277 ;; support the %-hack
|
|
278 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
|
|
279
|
0
|
280
|
|
281 (defvar nnmail-prepare-save-mail-hook nil
|
|
282 "Hook called before saving mail.")
|
|
283
|
|
284 (defvar nnmail-moved-inboxes nil
|
|
285 "List of inboxes that have been moved.")
|
|
286
|
|
287 (defvar nnmail-internal-password nil)
|
|
288
|
|
289
|
|
290
|
|
291 (defconst nnmail-version "nnmail 1.0"
|
|
292 "nnmail version.")
|
|
293
|
|
294
|
|
295
|
|
296 (defun nnmail-request-post (&optional server)
|
|
297 (mail-send-and-exit nil))
|
|
298
|
|
299 (defun nnmail-find-file (file)
|
|
300 "Insert FILE in server buffer safely."
|
|
301 (set-buffer nntp-server-buffer)
|
|
302 (erase-buffer)
|
|
303 (let ((format-alist nil)
|
|
304 (after-insert-file-functions nil))
|
|
305 (condition-case ()
|
|
306 (progn (insert-file-contents file) t)
|
|
307 (file-error nil))))
|
|
308
|
|
309 (defun nnmail-group-pathname (group dir &optional file)
|
|
310 "Make pathname for GROUP."
|
|
311 (concat
|
|
312 (let ((dir (file-name-as-directory (expand-file-name dir))))
|
|
313 ;; If this directory exists, we use it directly.
|
|
314 (if (or nnmail-use-long-file-names
|
|
315 (file-directory-p (concat dir group)))
|
|
316 (concat dir group "/")
|
|
317 ;; If not, we translate dots into slashes.
|
|
318 (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/")))
|
|
319 (or file "")))
|
|
320
|
|
321 (defun nnmail-date-to-time (date)
|
|
322 "Convert DATE into time."
|
|
323 (let* ((d1 (timezone-parse-date date))
|
|
324 (t1 (timezone-parse-time (aref d1 3))))
|
|
325 (apply 'encode-time
|
|
326 (mapcar (lambda (el)
|
|
327 (and el (string-to-number el)))
|
|
328 (list
|
|
329 (aref t1 2) (aref t1 1) (aref t1 0)
|
|
330 (aref d1 2) (aref d1 1) (aref d1 0)
|
|
331 (aref d1 4))))))
|
|
332
|
|
333 (defun nnmail-time-less (t1 t2)
|
|
334 "Say whether time T1 is less than time T2."
|
|
335 (or (< (car t1) (car t2))
|
|
336 (and (= (car t1) (car t2))
|
|
337 (< (nth 1 t1) (nth 1 t2)))))
|
|
338
|
|
339 (defun nnmail-days-to-time (days)
|
|
340 "Convert DAYS into time."
|
|
341 (let* ((seconds (* 1.0 days 60 60 24))
|
|
342 (rest (expt 2 16))
|
|
343 (ms (condition-case nil (round (/ seconds rest))
|
|
344 (range-error (expt 2 16)))))
|
|
345 (list ms (condition-case nil (round (- seconds (* ms rest)))
|
|
346 (range-error (expt 2 16))))))
|
|
347
|
|
348 (defun nnmail-time-since (time)
|
|
349 "Return the time since TIME, which is either an internal time or a date."
|
|
350 (when (stringp time)
|
|
351 ;; Convert date strings to internal time.
|
|
352 (setq time (nnmail-date-to-time time)))
|
|
353 (let* ((current (current-time))
|
|
354 (rest (if (< (nth 1 current) (nth 1 time)) (expt 2 16))))
|
|
355 (list (- (+ (car current) (if rest -1 0)) (car time))
|
|
356 (- (+ (or rest 0) (nth 1 current)) (nth 1 time)))))
|
|
357
|
|
358 ;; Function rewritten from rmail.el.
|
|
359 (defun nnmail-move-inbox (inbox)
|
|
360 "Move INBOX to `nnmail-crash-box'."
|
2
|
361 (let ((inbox (file-truename (expand-file-name inbox)))
|
|
362 (tofile (file-truename (expand-file-name nnmail-crash-box)))
|
0
|
363 movemail popmail errors password)
|
|
364 ;; If getting from mail spool directory,
|
|
365 ;; use movemail to move rather than just renaming,
|
|
366 ;; so as to interlock with the mailer.
|
|
367 (unless (setq popmail (string-match "^po:" (file-name-nondirectory inbox)))
|
|
368 (setq movemail t))
|
|
369 (when popmail
|
|
370 (setq inbox (file-name-nondirectory inbox)))
|
|
371 (when (and movemail
|
|
372 ;; On some systems, /usr/spool/mail/foo is a directory
|
|
373 ;; and the actual inbox is /usr/spool/mail/foo/foo.
|
|
374 (file-directory-p inbox))
|
|
375 (setq inbox (expand-file-name (user-login-name) inbox)))
|
|
376 (if (member inbox nnmail-moved-inboxes)
|
|
377 nil
|
|
378 (if popmail
|
|
379 (progn
|
|
380 (setq nnmail-internal-password nnmail-pop-password)
|
|
381 (when (and nnmail-pop-password-required (not nnmail-pop-password))
|
|
382 (setq nnmail-internal-password
|
|
383 (nnmail-read-passwd
|
|
384 (format "Password for %s: "
|
|
385 (substring inbox (+ popmail 3))))))
|
|
386 (message "Getting mail from post office ..."))
|
|
387 (when (or (and (file-exists-p tofile)
|
2
|
388 (/= 0 (nnheader-file-size tofile)))
|
0
|
389 (and (file-exists-p inbox)
|
2
|
390 (/= 0 (nnheader-file-size inbox))))
|
0
|
391 (message "Getting mail from %s..." inbox)))
|
|
392 ;; Set TOFILE if have not already done so, and
|
|
393 ;; rename or copy the file INBOX to TOFILE if and as appropriate.
|
|
394 (cond
|
|
395 ((file-exists-p tofile)
|
|
396 ;; The crash box exists already.
|
|
397 t)
|
|
398 ((and (not popmail)
|
|
399 (not (file-exists-p inbox)))
|
|
400 ;; There is no inbox.
|
|
401 (setq tofile nil))
|
|
402 ((and (not movemail) (not popmail))
|
|
403 ;; Try copying. If that fails (perhaps no space),
|
|
404 ;; rename instead.
|
|
405 (condition-case nil
|
|
406 (copy-file inbox tofile nil)
|
|
407 (error
|
|
408 ;; Third arg is t so we can replace existing file TOFILE.
|
|
409 (rename-file inbox tofile t)))
|
|
410 (push inbox nnmail-moved-inboxes)
|
|
411 ;; Make the real inbox file empty.
|
|
412 ;; Leaving it deleted could cause lossage
|
|
413 ;; because mailers often won't create the file.
|
|
414 (condition-case ()
|
|
415 (write-region (point) (point) inbox)
|
|
416 (file-error nil)))
|
|
417 (t
|
|
418 ;; Use movemail.
|
|
419 (unwind-protect
|
|
420 (save-excursion
|
|
421 (setq errors (generate-new-buffer " *nnmail loss*"))
|
|
422 (buffer-disable-undo errors)
|
|
423 (let ((default-directory "/"))
|
|
424 (apply
|
|
425 'call-process
|
|
426 (append
|
|
427 (list
|
|
428 (expand-file-name nnmail-movemail-program exec-directory)
|
|
429 nil errors nil inbox tofile)
|
|
430 (when nnmail-internal-password
|
|
431 (list nnmail-internal-password)))))
|
|
432 (if (not (buffer-modified-p errors))
|
|
433 ;; No output => movemail won
|
|
434 (push inbox nnmail-moved-inboxes)
|
|
435 (set-buffer errors)
|
|
436 (subst-char-in-region (point-min) (point-max) ?\n ?\ )
|
|
437 (goto-char (point-max))
|
|
438 (skip-chars-backward " \t")
|
|
439 (delete-region (point) (point-max))
|
|
440 (goto-char (point-min))
|
|
441 (if (looking-at "movemail: ")
|
|
442 (delete-region (point-min) (match-end 0)))
|
2
|
443 (error (concat "movemail: " (buffer-string)))
|
0
|
444 (setq tofile nil))))))
|
|
445 (and errors
|
|
446 (buffer-name errors)
|
|
447 (kill-buffer errors))
|
|
448 tofile)))
|
|
449
|
|
450 (defun nnmail-get-active ()
|
|
451 "Returns an assoc of group names and active ranges.
|
|
452 nn*-request-list should have been called before calling this function."
|
|
453 (let (group-assoc)
|
|
454 ;; Go through all groups from the active list.
|
|
455 (save-excursion
|
|
456 (set-buffer nntp-server-buffer)
|
|
457 (goto-char (point-min))
|
|
458 (while (re-search-forward
|
|
459 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t)
|
|
460 ;; We create an alist with `(GROUP (LOW . HIGH))' elements.
|
|
461 (push (list (match-string 1)
|
|
462 (cons (string-to-int (match-string 3))
|
|
463 (string-to-int (match-string 2))))
|
|
464 group-assoc)))
|
|
465 group-assoc))
|
|
466
|
|
467 (defun nnmail-save-active (group-assoc file-name)
|
|
468 "Save GROUP-ASSOC in ACTIVE-FILE."
|
|
469 (when file-name
|
|
470 (let (group)
|
|
471 (save-excursion
|
|
472 (set-buffer (get-buffer-create " *nnmail active*"))
|
|
473 (buffer-disable-undo (current-buffer))
|
|
474 (erase-buffer)
|
|
475 (while group-assoc
|
|
476 (setq group (pop group-assoc))
|
|
477 (insert (format "%s %d %d y\n" (car group) (cdadr group)
|
|
478 (caadr group))))
|
|
479 (unless (file-exists-p (file-name-directory file-name))
|
|
480 (make-directory (file-name-directory file-name) t))
|
|
481 (write-region 1 (point-max) (expand-file-name file-name) nil 'nomesg)
|
|
482 (kill-buffer (current-buffer))))))
|
|
483
|
|
484 (defun nnmail-get-split-group (file group)
|
|
485 (if (or (eq nnmail-spool-file 'procmail)
|
|
486 nnmail-use-procmail)
|
|
487 (cond (group group)
|
|
488 ((string-match (concat "^" (expand-file-name
|
|
489 (file-name-as-directory
|
|
490 nnmail-procmail-directory))
|
|
491 "\\([^/]*\\)" nnmail-procmail-suffix "$")
|
|
492 (expand-file-name file))
|
|
493 (substring (expand-file-name file)
|
|
494 (match-beginning 1) (match-end 1)))
|
|
495 (t
|
|
496 group))
|
|
497 group))
|
|
498
|
|
499 (defun nnmail-process-babyl-mail-format (func)
|
|
500 (let ((case-fold-search t)
|
|
501 start message-id content-length do-search end)
|
|
502 (while (not (eobp))
|
|
503 (goto-char (point-min))
|
|
504 (re-search-forward
|
|
505 "\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
|
|
506 (goto-char (match-end 0))
|
|
507 (delete-region (match-beginning 0) (match-end 0))
|
|
508 (setq start (point))
|
|
509 ;; Skip all the headers in case there are more "From "s...
|
|
510 (or (search-forward "\n\n" nil t)
|
|
511 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
|
|
512 (search-forward ""))
|
|
513 ;; Find the Message-ID header.
|
|
514 (save-excursion
|
|
515 (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t)
|
|
516 (setq message-id (buffer-substring (match-beginning 1)
|
|
517 (match-end 1)))
|
|
518 ;; There is no Message-ID here, so we create one.
|
|
519 (save-excursion
|
|
520 (when (re-search-backward "^Message-ID:" nil t)
|
|
521 (beginning-of-line)
|
|
522 (insert "Original-")))
|
|
523 (forward-line -1)
|
|
524 (insert "Message-ID: " (setq message-id (nnmail-message-id))
|
|
525 "\n")))
|
|
526 ;; Look for a Content-Length header.
|
|
527 (if (not (save-excursion
|
|
528 (and (re-search-backward
|
|
529 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
|
|
530 (setq content-length (string-to-int
|
|
531 (buffer-substring
|
|
532 (match-beginning 1)
|
|
533 (match-end 1))))
|
|
534 ;; We destroy the header, since none of
|
|
535 ;; the backends ever use it, and we do not
|
|
536 ;; want to confuse other mailers by having
|
|
537 ;; a (possibly) faulty header.
|
|
538 (progn (insert "X-") t))))
|
|
539 (setq do-search t)
|
|
540 (if (or (= (+ (point) content-length) (point-max))
|
|
541 (save-excursion
|
|
542 (goto-char (+ (point) content-length))
|
|
543 (looking-at "")))
|
|
544 (progn
|
|
545 (goto-char (+ (point) content-length))
|
|
546 (setq do-search nil))
|
|
547 (setq do-search t)))
|
|
548 ;; Go to the beginning of the next article - or to the end
|
|
549 ;; of the buffer.
|
|
550 (if do-search
|
|
551 (if (re-search-forward "^" nil t)
|
|
552 (goto-char (match-beginning 0))
|
|
553 (goto-char (1- (point-max)))))
|
|
554 (delete-char 1) ; delete ^_
|
|
555 (save-excursion
|
|
556 (save-restriction
|
|
557 (narrow-to-region start (point))
|
|
558 (goto-char (point-min))
|
|
559 (nnmail-check-duplication message-id func)
|
|
560 (setq end (point-max))))
|
|
561 (goto-char end))))
|
|
562
|
|
563 (defun nnmail-search-unix-mail-delim ()
|
|
564 "Put point at the beginning of the next message."
|
|
565 (let ((case-fold-search t)
|
|
566 (delim (concat "^" message-unix-mail-delimiter))
|
|
567 found)
|
|
568 (while (not found)
|
|
569 (if (re-search-forward delim nil t)
|
|
570 (when (or (looking-at "[^\n :]+ *:")
|
|
571 (looking-at delim)
|
|
572 (looking-at (concat ">" message-unix-mail-delimiter)))
|
|
573 (forward-line -1)
|
|
574 (setq found 'yes))
|
|
575 (setq found 'no)))
|
|
576 (eq found 'yes)))
|
|
577
|
|
578 (defun nnmail-process-unix-mail-format (func)
|
|
579 (let ((case-fold-search t)
|
|
580 (delim (concat "^" message-unix-mail-delimiter))
|
|
581 start message-id content-length end skip head-end)
|
|
582 (goto-char (point-min))
|
|
583 (if (not (and (re-search-forward delim nil t)
|
|
584 (goto-char (match-beginning 0))))
|
|
585 ;; Possibly wrong format?
|
|
586 (error "Error, unknown mail format! (Possibly corrupted.)")
|
|
587 ;; Carry on until the bitter end.
|
|
588 (while (not (eobp))
|
|
589 (setq start (point)
|
|
590 end nil)
|
|
591 ;; Find the end of the head.
|
|
592 (narrow-to-region
|
|
593 start
|
|
594 (if (search-forward "\n\n" nil t)
|
|
595 (1- (point))
|
|
596 ;; This will never happen, but just to be on the safe side --
|
|
597 ;; if there is no head-body delimiter, we search a bit manually.
|
|
598 (while (and (looking-at "From \\|[^ \t]+:")
|
|
599 (not (eobp)))
|
|
600 (forward-line 1)
|
|
601 (point))))
|
|
602 ;; Find the Message-ID header.
|
|
603 (goto-char (point-min))
|
|
604 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
|
|
605 (setq message-id (match-string 1))
|
|
606 (save-excursion
|
|
607 (when (re-search-forward "^Message-ID:" nil t)
|
|
608 (beginning-of-line)
|
|
609 (insert "Original-")))
|
|
610 ;; There is no Message-ID here, so we create one.
|
|
611 (forward-line 1)
|
|
612 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
|
|
613 ;; Look for a Content-Length header.
|
|
614 (goto-char (point-min))
|
|
615 (if (not (re-search-forward
|
|
616 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
|
|
617 (setq content-length nil)
|
|
618 (setq content-length (string-to-int (match-string 1)))
|
|
619 ;; We destroy the header, since none of the backends ever
|
|
620 ;; use it, and we do not want to confuse other mailers by
|
|
621 ;; having a (possibly) faulty header.
|
|
622 (beginning-of-line)
|
|
623 (insert "X-"))
|
|
624 ;; Find the end of this article.
|
|
625 (goto-char (point-max))
|
|
626 (widen)
|
|
627 (setq head-end (point))
|
|
628 ;; We try the Content-Length value. The idea: skip over the header
|
|
629 ;; separator, then check what happens content-length bytes into the
|
|
630 ;; message body. This should be either the end ot the buffer, the
|
|
631 ;; message separator or a blank line followed by the separator.
|
|
632 ;; The blank line should probably be deleted. If neither of the
|
|
633 ;; three is met, the content-length header is probably invalid.
|
|
634 (when content-length
|
|
635 (forward-line 1)
|
|
636 (setq skip (+ (point) content-length))
|
|
637 (goto-char skip)
|
|
638 (cond ((or (= skip (point-max))
|
|
639 (= (1+ skip) (point-max)))
|
|
640 (setq end (point-max)))
|
|
641 ((looking-at delim)
|
|
642 (setq end skip))
|
|
643 ((looking-at
|
|
644 (concat "[ \t]*\n\\(" delim "\\)"))
|
|
645 (setq end (match-beginning 1)))
|
|
646 (t (setq end nil))))
|
|
647 (if end
|
|
648 (goto-char end)
|
|
649 ;; No Content-Length, so we find the beginning of the next
|
|
650 ;; article or the end of the buffer.
|
|
651 (goto-char head-end)
|
|
652 (or (nnmail-search-unix-mail-delim)
|
|
653 (goto-char (point-max))))
|
|
654 ;; Allow the backend to save the article.
|
|
655 (save-excursion
|
|
656 (save-restriction
|
|
657 (narrow-to-region start (point))
|
|
658 (goto-char (point-min))
|
|
659 (nnmail-check-duplication message-id func)
|
|
660 (setq end (point-max))))
|
|
661 (goto-char end)))))
|
|
662
|
|
663 (defun nnmail-process-mmdf-mail-format (func)
|
|
664 (let ((delim "^\^A\^A\^A\^A$")
|
|
665 (case-fold-search t)
|
|
666 start message-id end)
|
|
667 (goto-char (point-min))
|
|
668 (if (not (and (re-search-forward delim nil t)
|
|
669 (forward-line 1)))
|
|
670 ;; Possibly wrong format?
|
|
671 (error "Error, unknown mail format! (Possibly corrupted.)")
|
|
672 ;; Carry on until the bitter end.
|
|
673 (while (not (eobp))
|
|
674 (setq start (point))
|
|
675 ;; Find the end of the head.
|
|
676 (narrow-to-region
|
|
677 start
|
|
678 (if (search-forward "\n\n" nil t)
|
|
679 (1- (point))
|
|
680 ;; This will never happen, but just to be on the safe side --
|
|
681 ;; if there is no head-body delimiter, we search a bit manually.
|
|
682 (while (and (looking-at "From \\|[^ \t]+:")
|
|
683 (not (eobp)))
|
|
684 (forward-line 1)
|
|
685 (point))))
|
|
686 ;; Find the Message-ID header.
|
|
687 (goto-char (point-min))
|
|
688 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
|
|
689 (setq message-id (match-string 1))
|
|
690 ;; There is no Message-ID here, so we create one.
|
|
691 (save-excursion
|
|
692 (when (re-search-backward "^Message-ID:" nil t)
|
|
693 (beginning-of-line)
|
|
694 (insert "Original-")))
|
|
695 (forward-line 1)
|
|
696 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
|
|
697 ;; Find the end of this article.
|
|
698 (goto-char (point-max))
|
|
699 (widen)
|
|
700 (if (re-search-forward delim nil t)
|
|
701 (beginning-of-line)
|
|
702 (goto-char (point-max)))
|
|
703 ;; Allow the backend to save the article.
|
|
704 (save-excursion
|
|
705 (save-restriction
|
|
706 (narrow-to-region start (point))
|
|
707 (goto-char (point-min))
|
|
708 (nnmail-check-duplication message-id func)
|
|
709 (setq end (point-max))))
|
|
710 (goto-char end)
|
|
711 (forward-line 2)))))
|
|
712
|
|
713 (defun nnmail-split-incoming (incoming func &optional exit-func group)
|
|
714 "Go through the entire INCOMING file and pick out each individual mail.
|
|
715 FUNC will be called with the buffer narrowed to each mail."
|
|
716 (let (;; If this is a group-specific split, we bind the split
|
|
717 ;; methods to just this group.
|
|
718 (nnmail-split-methods (if (and group
|
|
719 (or (eq nnmail-spool-file 'procmail)
|
|
720 nnmail-use-procmail)
|
|
721 (not nnmail-resplit-incoming))
|
|
722 (list (list group ""))
|
|
723 nnmail-split-methods)))
|
|
724 (save-excursion
|
|
725 ;; Insert the incoming file.
|
|
726 (set-buffer (get-buffer-create " *nnmail incoming*"))
|
|
727 (buffer-disable-undo (current-buffer))
|
|
728 (erase-buffer)
|
|
729 (nnheader-insert-file-contents-literally incoming)
|
|
730 (unless (zerop (buffer-size))
|
|
731 (goto-char (point-min))
|
|
732 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
|
|
733 ;; Handle both babyl, MMDF and unix mail formats, since movemail will
|
|
734 ;; use the former when fetching from a mailbox, the latter when
|
|
735 ;; fetches from a file.
|
|
736 (cond ((or (looking-at "\^L")
|
|
737 (looking-at "BABYL OPTIONS:"))
|
|
738 (nnmail-process-babyl-mail-format func))
|
|
739 ((looking-at "\^A\^A\^A\^A")
|
|
740 (nnmail-process-mmdf-mail-format func))
|
|
741 (t
|
|
742 (nnmail-process-unix-mail-format func))))
|
|
743 (if exit-func (funcall exit-func))
|
|
744 (kill-buffer (current-buffer)))))
|
|
745
|
|
746 ;; Mail crossposts suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
|
|
747 (defun nnmail-article-group (func)
|
|
748 "Look at the headers and return an alist of groups that match.
|
|
749 FUNC will be called with the group name to determine the article number."
|
|
750 (let ((methods nnmail-split-methods)
|
|
751 (obuf (current-buffer))
|
|
752 (beg (point-min))
|
|
753 end group-art method)
|
|
754 (if (and (sequencep methods) (= (length methods) 1))
|
|
755 ;; If there is only just one group to put everything in, we
|
|
756 ;; just return a list with just this one method in.
|
|
757 (setq group-art
|
|
758 (list (cons (caar methods) (funcall func (caar methods)))))
|
|
759 ;; We do actual comparison.
|
|
760 (save-excursion
|
|
761 ;; Find headers.
|
|
762 (goto-char beg)
|
|
763 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
|
|
764 (set-buffer nntp-server-buffer)
|
|
765 (erase-buffer)
|
|
766 ;; Copy the headers into the work buffer.
|
|
767 (insert-buffer-substring obuf beg end)
|
|
768 ;; Fold continuation lines.
|
|
769 (goto-char (point-min))
|
|
770 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
|
|
771 (replace-match " " t t))
|
|
772 (if (and (symbolp nnmail-split-methods)
|
|
773 (fboundp nnmail-split-methods))
|
|
774 ;; `nnmail-split-methods' is a function, so we just call
|
|
775 ;; this function here and use the result.
|
|
776 (setq group-art
|
|
777 (mapcar
|
|
778 (lambda (group) (cons group (funcall func group)))
|
|
779 (condition-case nil
|
|
780 (or (funcall nnmail-split-methods)
|
|
781 '("bogus"))
|
|
782 (error
|
|
783 (message
|
|
784 "Error in `nnmail-split-methods'; using `bogus' mail group")
|
|
785 (sit-for 1)
|
|
786 '("bogus")))))
|
|
787 ;; Go through the split methods to find a match.
|
|
788 (while (and methods (or nnmail-crosspost (not group-art)))
|
|
789 (goto-char (point-max))
|
|
790 (setq method (pop methods))
|
|
791 (if (or methods
|
|
792 (not (equal "" (nth 1 method))))
|
|
793 (when (and
|
|
794 (condition-case ()
|
|
795 (if (stringp (nth 1 method))
|
|
796 (re-search-backward (cadr method) nil t)
|
|
797 ;; Function to say whether this is a match.
|
|
798 (funcall (nth 1 method) (car method)))
|
|
799 (error nil))
|
|
800 ;; Don't enter the article into the same
|
|
801 ;; group twice.
|
|
802 (not (assoc (car method) group-art)))
|
|
803 (push (cons (car method) (funcall func (car method)))
|
|
804 group-art))
|
|
805 ;; This is the final group, which is used as a
|
|
806 ;; catch-all.
|
|
807 (unless group-art
|
|
808 (setq group-art
|
|
809 (list (cons (car method)
|
|
810 (funcall func (car method)))))))))
|
|
811 group-art))))
|
|
812
|
|
813 (defun nnmail-insert-lines ()
|
|
814 "Insert how many lines there are in the body of the mail.
|
|
815 Return the number of characters in the body."
|
|
816 (let (lines chars)
|
|
817 (save-excursion
|
|
818 (goto-char (point-min))
|
|
819 (when (search-forward "\n\n" nil t)
|
|
820 (setq chars (- (point-max) (point)))
|
|
821 (setq lines (count-lines (point) (point-max)))
|
|
822 (forward-char -1)
|
|
823 (save-excursion
|
|
824 (when (re-search-backward "^Lines: " nil t)
|
|
825 (delete-region (point) (progn (forward-line 1) (point)))))
|
|
826 (beginning-of-line)
|
|
827 (insert (format "Lines: %d\n" (max lines 0)))
|
|
828 chars))))
|
|
829
|
|
830 (defun nnmail-insert-xref (group-alist)
|
|
831 "Insert an Xref line based on the (group . article) alist."
|
|
832 (save-excursion
|
|
833 (goto-char (point-min))
|
|
834 (when (search-forward "\n\n" nil t)
|
|
835 (forward-char -1)
|
|
836 (when (re-search-backward "^Xref: " nil t)
|
|
837 (delete-region (match-beginning 0)
|
|
838 (progn (forward-line 1) (point))))
|
|
839 (insert (format "Xref: %s" (system-name)))
|
|
840 (while group-alist
|
|
841 (insert (format " %s:%d" (caar group-alist) (cdar group-alist)))
|
|
842 (setq group-alist (cdr group-alist)))
|
|
843 (insert "\n"))))
|
|
844
|
|
845 ;; Written by byer@mv.us.adobe.com (Scott Byer).
|
|
846 (defun nnmail-make-complex-temp-name (prefix)
|
|
847 (let ((newname (make-temp-name prefix))
|
|
848 (newprefix prefix))
|
|
849 (while (file-exists-p newname)
|
|
850 (setq newprefix (concat newprefix "x"))
|
|
851 (setq newname (make-temp-name newprefix)))
|
|
852 newname))
|
|
853
|
|
854 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
|
|
855
|
|
856 (defun nnmail-split-fancy ()
|
|
857 "Fancy splitting method.
|
|
858 See the documentation for the variable `nnmail-split-fancy' for documentation."
|
|
859 (let ((syntab (syntax-table)))
|
|
860 (unwind-protect
|
|
861 (progn
|
|
862 (set-syntax-table nnmail-split-fancy-syntax-table)
|
|
863 (nnmail-split-it nnmail-split-fancy))
|
|
864 (set-syntax-table syntab))))
|
|
865
|
|
866 (defvar nnmail-split-cache nil)
|
|
867 ;; Alist of split expressions their equivalent regexps.
|
|
868
|
|
869 (defun nnmail-split-it (split)
|
|
870 ;; Return a list of groups matching SPLIT.
|
|
871 (cond ((stringp split)
|
|
872 ;; A group.
|
|
873 (list split))
|
|
874 ((eq (car split) '&)
|
|
875 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
|
|
876 ((eq (car split) '|)
|
|
877 (let (done)
|
|
878 (while (and (not done) (cdr split))
|
|
879 (setq split (cdr split)
|
|
880 done (nnmail-split-it (car split))))
|
|
881 done))
|
|
882 ((assq split nnmail-split-cache)
|
|
883 ;; A compiled match expression.
|
|
884 (goto-char (point-max))
|
|
885 (if (re-search-backward (cdr (assq split nnmail-split-cache)) nil t)
|
|
886 (nnmail-split-it (nth 2 split))))
|
|
887 (t
|
|
888 ;; An uncompiled match.
|
|
889 (let* ((field (nth 0 split))
|
|
890 (value (nth 1 split))
|
|
891 (regexp (concat "^\\("
|
|
892 (if (symbolp field)
|
|
893 (cdr (assq field
|
|
894 nnmail-split-abbrev-alist))
|
|
895 field)
|
|
896 "\\):.*\\<\\("
|
|
897 (if (symbolp value)
|
|
898 (cdr (assq value
|
|
899 nnmail-split-abbrev-alist))
|
|
900 value)
|
|
901 "\\)\\>")))
|
|
902 (setq nnmail-split-cache
|
|
903 (cons (cons split regexp) nnmail-split-cache))
|
|
904 (goto-char (point-max))
|
|
905 (if (re-search-backward regexp nil t)
|
|
906 (nnmail-split-it (nth 2 split)))))))
|
|
907
|
|
908 ;; Get a list of spool files to read.
|
|
909 (defun nnmail-get-spool-files (&optional group)
|
|
910 (if (null nnmail-spool-file)
|
|
911 ;; No spool file whatsoever.
|
|
912 nil
|
|
913 (let* ((procmails
|
|
914 ;; If procmail is used to get incoming mail, the files
|
|
915 ;; are stored in this directory.
|
|
916 (and (file-exists-p nnmail-procmail-directory)
|
|
917 (or (eq nnmail-spool-file 'procmail)
|
|
918 nnmail-use-procmail)
|
|
919 (directory-files
|
|
920 nnmail-procmail-directory
|
|
921 t (concat (if group (concat "^" group) "")
|
|
922 nnmail-procmail-suffix "$") t)))
|
|
923 (p procmails)
|
|
924 (crash (when (and (file-exists-p nnmail-crash-box)
|
2
|
925 (> (nnheader-file-size
|
|
926 (file-truename nnmail-crash-box)) 0))
|
0
|
927 (list nnmail-crash-box))))
|
|
928 ;; Remove any directories that inadvertantly match the procmail
|
|
929 ;; suffix, which might happen if the suffix is "".
|
|
930 (while p
|
|
931 (when (file-directory-p (car p))
|
|
932 (setq procmails (delete (car p) procmails)))
|
|
933 (setq p (cdr p)))
|
|
934 ;; Return the list of spools.
|
|
935 (append
|
|
936 crash
|
|
937 (cond ((and group
|
|
938 (or (eq nnmail-spool-file 'procmail)
|
2
|
939 nnmail-use-procmail)
|
|
940 procmails)
|
0
|
941 procmails)
|
2
|
942 ((and group
|
|
943 (eq nnmail-spool-file 'procmail))
|
|
944 nil)
|
0
|
945 ((listp nnmail-spool-file)
|
|
946 (append nnmail-spool-file procmails))
|
|
947 ((stringp nnmail-spool-file)
|
|
948 (cons nnmail-spool-file procmails))
|
|
949 ((eq nnmail-spool-file 'pop)
|
|
950 (cons (format "po:%s" (user-login-name)) procmails))
|
|
951 (t
|
|
952 procmails))))))
|
|
953
|
|
954 ;; Activate a backend only if it isn't already activated.
|
|
955 ;; If FORCE, re-read the active file even if the backend is
|
|
956 ;; already activated.
|
|
957 (defun nnmail-activate (backend &optional force)
|
|
958 (let (file timestamp file-time)
|
|
959 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
|
|
960 force
|
|
961 (and (setq file (condition-case ()
|
|
962 (symbol-value (intern (format "%s-active-file"
|
|
963 backend)))
|
|
964 (error nil)))
|
|
965 (setq file-time (nth 5 (file-attributes file)))
|
|
966 (or (not
|
|
967 (setq timestamp
|
|
968 (condition-case ()
|
|
969 (symbol-value (intern
|
|
970 (format "%s-active-timestamp"
|
|
971 backend)))
|
|
972 (error 'none))))
|
|
973 (not (consp timestamp))
|
|
974 (equal timestamp '(0 0))
|
|
975 (> (nth 0 file-time) (nth 0 timestamp))
|
|
976 (and (= (nth 0 file-time) (nth 0 timestamp))
|
|
977 (> (nth 1 file-time) (nth 1 timestamp))))))
|
|
978 (save-excursion
|
|
979 (or (eq timestamp 'none)
|
|
980 (set (intern (format "%s-active-timestamp" backend))
|
|
981 (current-time)))
|
|
982 (funcall (intern (format "%s-request-list" backend)))
|
|
983 (set (intern (format "%s-group-alist" backend))
|
|
984 (nnmail-get-active))))
|
|
985 t))
|
|
986
|
|
987 (defun nnmail-message-id ()
|
|
988 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
|
|
989
|
|
990 ;;;
|
|
991 ;;; nnmail duplicate handling
|
|
992 ;;;
|
|
993
|
|
994 (defvar nnmail-cache-buffer nil)
|
|
995
|
|
996 (defun nnmail-cache-open ()
|
|
997 (if (or (not nnmail-treat-duplicates)
|
|
998 (and nnmail-cache-buffer
|
|
999 (buffer-name nnmail-cache-buffer)))
|
|
1000 () ; The buffer is open.
|
|
1001 (save-excursion
|
|
1002 (set-buffer
|
|
1003 (setq nnmail-cache-buffer
|
|
1004 (get-buffer-create " *nnmail message-id cache*")))
|
|
1005 (buffer-disable-undo (current-buffer))
|
|
1006 (and (file-exists-p nnmail-message-id-cache-file)
|
|
1007 (insert-file-contents nnmail-message-id-cache-file))
|
|
1008 (set-buffer-modified-p nil)
|
|
1009 (current-buffer))))
|
|
1010
|
|
1011 (defun nnmail-cache-close ()
|
|
1012 (when (and nnmail-cache-buffer
|
|
1013 nnmail-treat-duplicates
|
|
1014 (buffer-name nnmail-cache-buffer)
|
|
1015 (buffer-modified-p nnmail-cache-buffer))
|
|
1016 (save-excursion
|
|
1017 (set-buffer nnmail-cache-buffer)
|
|
1018 ;; Weed out the excess number of Message-IDs.
|
|
1019 (goto-char (point-max))
|
|
1020 (and (search-backward "\n" nil t nnmail-message-id-cache-length)
|
|
1021 (progn
|
|
1022 (beginning-of-line)
|
|
1023 (delete-region (point-min) (point))))
|
|
1024 ;; Save the buffer.
|
|
1025 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
|
|
1026 (make-directory (file-name-directory nnmail-message-id-cache-file)
|
|
1027 t))
|
|
1028 (write-region (point-min) (point-max)
|
|
1029 nnmail-message-id-cache-file nil 'silent)
|
|
1030 (set-buffer-modified-p nil)
|
|
1031 (setq nnmail-cache-buffer nil)
|
|
1032 ;;(kill-buffer (current-buffer))
|
|
1033 )))
|
|
1034
|
|
1035 (defun nnmail-cache-insert (id)
|
|
1036 (when nnmail-treat-duplicates
|
|
1037 (save-excursion
|
|
1038 (set-buffer nnmail-cache-buffer)
|
|
1039 (goto-char (point-max))
|
|
1040 (insert id "\n"))))
|
|
1041
|
|
1042 (defun nnmail-cache-id-exists-p (id)
|
|
1043 (when nnmail-treat-duplicates
|
|
1044 (save-excursion
|
|
1045 (set-buffer nnmail-cache-buffer)
|
|
1046 (goto-char (point-max))
|
|
1047 (search-backward id nil t))))
|
|
1048
|
|
1049 (defun nnmail-check-duplication (message-id func)
|
|
1050 ;; If this is a duplicate message, then we do not save it.
|
|
1051 (let* ((duplication (nnmail-cache-id-exists-p message-id))
|
|
1052 (action (when duplication
|
|
1053 (cond
|
|
1054 ((memq nnmail-treat-duplicates '(warn delete))
|
|
1055 nnmail-treat-duplicates)
|
|
1056 ((nnheader-functionp nnmail-treat-duplicates)
|
|
1057 (funcall nnmail-treat-duplicates message-id))
|
|
1058 (t
|
|
1059 nnmail-treat-duplicates)))))
|
|
1060 (cond
|
|
1061 ((not duplication)
|
|
1062 (nnmail-cache-insert message-id)
|
|
1063 (funcall func))
|
|
1064 ((eq action 'delete)
|
|
1065 (delete-region (point-min) (point-max)))
|
|
1066 ((eq action 'warn)
|
|
1067 ;; We insert a warning.
|
|
1068 (let ((case-fold-search t)
|
|
1069 (newid (nnmail-message-id)))
|
|
1070 (goto-char (point-min))
|
|
1071 (when (re-search-forward "^message-id:" nil t)
|
|
1072 (beginning-of-line)
|
|
1073 (insert "Original-"))
|
|
1074 (beginning-of-line)
|
|
1075 (insert
|
|
1076 "Message-ID: " newid "\n"
|
|
1077 "Gnus-Warning: This is a duplicate of message " message-id "\n")
|
|
1078 (nnmail-cache-insert newid)
|
|
1079 (funcall func)))
|
|
1080 (t
|
|
1081 (funcall func)))))
|
|
1082
|
|
1083 ;;; Get new mail.
|
|
1084
|
|
1085 (defun nnmail-get-value (&rest args)
|
|
1086 (let ((sym (intern (apply 'format args))))
|
|
1087 (when (boundp sym)
|
|
1088 (symbol-value sym))))
|
|
1089
|
|
1090 (defun nnmail-get-new-mail (method exit-func temp
|
|
1091 &optional group spool-func)
|
|
1092 "Read new incoming mail."
|
|
1093 (let* ((spools (nnmail-get-spool-files group))
|
|
1094 (group-in group)
|
|
1095 incoming incomings spool)
|
|
1096 (when (and (nnmail-get-value "%s-get-new-mail" method)
|
|
1097 nnmail-spool-file)
|
|
1098 ;; We first activate all the groups.
|
|
1099 (nnmail-activate method)
|
|
1100 ;; Allow the user to hook.
|
|
1101 (run-hooks 'nnmail-pre-get-new-mail-hook)
|
|
1102 ;; Open the message-id cache.
|
|
1103 (nnmail-cache-open)
|
|
1104 ;; The we go through all the existing spool files and split the
|
|
1105 ;; mail from each.
|
|
1106 (while spools
|
|
1107 (setq spool (pop spools))
|
|
1108 ;; We read each spool file if either the spool is a POP-mail
|
|
1109 ;; spool, or the file exists. We can't check for the
|
|
1110 ;; existance of POPped mail.
|
|
1111 (when (or (string-match "^po:" spool)
|
|
1112 (and (file-exists-p spool)
|
2
|
1113 (> (nnheader-file-size (file-truename spool)) 0)))
|
0
|
1114 (nnheader-message 3 "%s: Reading incoming mail..." method)
|
|
1115 (when (and (nnmail-move-inbox spool)
|
|
1116 (file-exists-p nnmail-crash-box))
|
|
1117 ;; There is new mail. We first find out if all this mail
|
|
1118 ;; is supposed to go to some specific group.
|
|
1119 (setq group (nnmail-get-split-group spool group-in))
|
|
1120 ;; We split the mail
|
|
1121 (nnmail-split-incoming
|
|
1122 nnmail-crash-box (intern (format "%s-save-mail" method))
|
|
1123 spool-func group)
|
|
1124 ;; Check whether the inbox is to be moved to the special tmp dir.
|
|
1125 (setq incoming
|
|
1126 (nnmail-make-complex-temp-name
|
|
1127 (expand-file-name
|
|
1128 (if nnmail-tmp-directory
|
|
1129 (concat
|
|
1130 (file-name-as-directory nnmail-tmp-directory)
|
|
1131 (file-name-nondirectory (concat temp "Incoming")))
|
|
1132 (concat temp "Incoming")))))
|
|
1133 (rename-file nnmail-crash-box incoming t)
|
|
1134 (push incoming incomings))))
|
|
1135 ;; If we did indeed read any incoming spools, we save all info.
|
|
1136 (when incomings
|
|
1137 (nnmail-save-active
|
|
1138 (nnmail-get-value "%s-group-alist" method)
|
|
1139 (nnmail-get-value "%s-active-file" method))
|
|
1140 (when exit-func
|
|
1141 (funcall exit-func))
|
|
1142 (run-hooks 'nnmail-read-incoming-hook)
|
|
1143 (nnheader-message 3 "%s: Reading incoming mail...done" method))
|
|
1144 ;; Close the message-id cache.
|
|
1145 (nnmail-cache-close)
|
|
1146 ;; Allow the user to hook.
|
|
1147 (run-hooks 'nnmail-post-get-new-mail-hook)
|
|
1148 ;; Delete all the temporary files.
|
|
1149 (while incomings
|
|
1150 (setq incoming (pop incomings))
|
|
1151 (and nnmail-delete-incoming
|
|
1152 (file-exists-p incoming)
|
|
1153 (file-writable-p incoming)
|
|
1154 (delete-file incoming))))))
|
|
1155
|
|
1156 (defun nnmail-expired-article-p (group time force &optional inhibit)
|
|
1157 "Say whether an article that is TIME old in GROUP should be expired."
|
|
1158 (if force
|
|
1159 t
|
|
1160 (let ((days (or (and nnmail-expiry-wait-function
|
|
1161 (funcall nnmail-expiry-wait-function group))
|
|
1162 nnmail-expiry-wait)))
|
|
1163 (cond ((or (eq days 'never)
|
|
1164 (and (not force)
|
|
1165 inhibit))
|
|
1166 ;; This isn't an expirable group.
|
|
1167 nil)
|
|
1168 ((eq days 'immediate)
|
|
1169 ;; We expire all articles on sight.
|
|
1170 t)
|
|
1171 ((equal time '(0 0))
|
|
1172 ;; This is an ange-ftp group, and we don't have any dates.
|
|
1173 nil)
|
|
1174 ((numberp days)
|
|
1175 (setq days (nnmail-days-to-time days))
|
|
1176 ;; Compare the time with the current time.
|
|
1177 (nnmail-time-less days (nnmail-time-since time)))))))
|
|
1178
|
|
1179 (defvar nnmail-read-passwd nil)
|
|
1180 (defun nnmail-read-passwd (prompt)
|
|
1181 (unless nnmail-read-passwd
|
|
1182 (if (load "passwd" t)
|
|
1183 (setq nnmail-read-passwd 'read-passwd)
|
|
1184 (autoload 'ange-ftp-read-passwd "ange-ftp")
|
|
1185 (setq nnmail-read-passwd 'ange-ftp-read-passwd)))
|
|
1186 (funcall nnmail-read-passwd prompt))
|
|
1187
|
|
1188 (defun nnmail-check-syntax ()
|
|
1189 "Check (and modify) the syntax of the message in the current buffer."
|
|
1190 (save-restriction
|
|
1191 (message-narrow-to-head)
|
|
1192 (let ((case-fold-search t))
|
|
1193 (unless (re-search-forward "^Message-Id:" nil t)
|
|
1194 (insert "Message-ID: " (nnmail-message-id) "\n")))))
|
|
1195
|
|
1196 (run-hooks 'nnmail-load-hook)
|
|
1197
|
|
1198 (provide 'nnmail)
|
|
1199
|
|
1200 ;;; nnmail.el ends here
|