0
|
1 ;;; nnmail.el --- mail support functions for the Gnus mail backends
|
16
|
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
|
0
|
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))
|
16
|
32 (require 'custom)
|
0
|
33
|
16
|
34 (defgroup gnus-mail nil
|
|
35 "Mailreading.."
|
|
36 :group 'gnus)
|
|
37
|
|
38 (defcustom nnmail-split-methods
|
0
|
39 '(("mail.misc" ""))
|
16
|
40 "Incoming mail will be split according to this variable.
|
0
|
41
|
|
42 If you'd like, for instance, one mail group for mail from the
|
|
43 \"4ad-l\" mailing list, one group for junk mail and one for everything
|
|
44 else, you could do something like this:
|
|
45
|
|
46 (setq nnmail-split-methods
|
|
47 '((\"mail.4ad\" \"From:.*4ad\")
|
|
48 (\"mail.junk\" \"From:.*Lars\\\\|Subject:.*buy\")
|
|
49 (\"mail.misc\" \"\")))
|
|
50
|
|
51 As you can see, this variable is a list of lists, where the first
|
|
52 element in each \"rule\" is the name of the group (which, by the way,
|
|
53 does not have to be called anything beginning with \"mail\",
|
|
54 \"yonka.zow\" is a fine, fine name), and the second is a regexp that
|
|
55 nnmail will try to match on the header to find a fit.
|
|
56
|
|
57 The second element can also be a function. In that case, it will be
|
|
58 called narrowed to the headers with the first element of the rule as
|
|
59 the argument. It should return a non-nil value if it thinks that the
|
|
60 mail belongs in that group.
|
|
61
|
|
62 The last element should always have \"\" as the regexp.
|
|
63
|
16
|
64 This variable can also have a function as its value."
|
|
65 :group 'gnus-mail
|
|
66 :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
|
|
67 (function-item nnmail-split-fancy)
|
|
68 (function :tag "Other")))
|
0
|
69
|
|
70 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
|
16
|
71 (defcustom nnmail-crosspost t
|
|
72 "If non-nil, do crossposting if several split methods match the mail.
|
|
73 If nil, the first match found will be used."
|
|
74 :group 'gnus-mail
|
|
75 :type 'boolean)
|
0
|
76
|
|
77 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
|
16
|
78 (defcustom nnmail-keep-last-article nil
|
|
79 "If non-nil, nnmail will never delete the last expired article in a directory.
|
0
|
80 You may need to set this variable if other programs are putting
|
16
|
81 new mail into folder numbers that Gnus has marked as expired."
|
|
82 :group 'gnus-mail
|
|
83 :type 'boolean)
|
0
|
84
|
16
|
85 (defcustom nnmail-use-long-file-names nil
|
|
86 "If non-nil the mail backends will use long file and directory names.
|
0
|
87 If nil, groups like \"mail.misc\" will end up in directories like
|
16
|
88 \"mail/misc/\"."
|
|
89 :group 'gnus-mail
|
|
90 :type 'boolean)
|
0
|
91
|
16
|
92 (defcustom nnmail-default-file-modes 384
|
|
93 "Set the mode bits of all new mail files to this integer."
|
|
94 :group 'gnus-mail
|
|
95 :type 'integer)
|
|
96
|
|
97 (defcustom nnmail-expiry-wait 7
|
0
|
98 "*Expirable articles that are older than this will be expired.
|
|
99 This variable can either be a number (which will be interpreted as a
|
|
100 number of days) -- this doesn't have to be an integer. This variable
|
16
|
101 can also be `immediate' and `never'."
|
|
102 :group 'gnus-mail
|
|
103 :type '(choice (const immediate)
|
|
104 (integer :tag "days")
|
|
105 (const never)))
|
0
|
106
|
16
|
107 (defcustom nnmail-expiry-wait-function nil
|
|
108 "Variable that holds function to specify how old articles should be before they are expired.
|
0
|
109 The function will be called with the name of the group that the
|
|
110 expiry is to be performed in, and it should return an integer that
|
|
111 says how many days an article can be stored before it is considered
|
|
112 \"old\". It can also return the values `never' and `immediate'.
|
|
113
|
|
114 Eg.:
|
|
115
|
16
|
116 \(setq nnmail-expiry-wait-function
|
0
|
117 (lambda (newsgroup)
|
|
118 (cond ((string-match \"private\" newsgroup) 31)
|
|
119 ((string-match \"junk\" newsgroup) 1)
|
|
120 ((string-match \"important\" newsgroup) 'never)
|
16
|
121 (t 7))))"
|
|
122 :group 'gnus-mail
|
|
123 :type '(choice (const :tag "nnmail-expiry-wait" nil)
|
|
124 (function :format "%v" nnmail-)))
|
0
|
125
|
16
|
126 (defcustom nnmail-spool-file
|
0
|
127 (or (getenv "MAIL")
|
|
128 (concat "/usr/spool/mail/" (user-login-name)))
|
|
129 "Where the mail backends will look for incoming mail.
|
|
130 This variable is \"/usr/spool/mail/$user\" by default.
|
|
131 If this variable is nil, no mail backends will read incoming mail.
|
|
132 If this variable is a list, all files mentioned in this list will be
|
16
|
133 used as incoming mailboxes.
|
|
134 If this variable is a directory (i. e., it's name ends with a \"/\"),
|
|
135 treat all files in that directory as incoming spool files."
|
|
136 :group 'gnus-mail
|
|
137 :type 'file)
|
0
|
138
|
16
|
139 (defcustom nnmail-crash-box "~/.gnus-crash-box"
|
|
140 "File where Gnus will store mail while processing it."
|
|
141 :group 'gnus-mail
|
|
142 :type 'file)
|
0
|
143
|
16
|
144 (defcustom nnmail-use-procmail nil
|
0
|
145 "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
|
16
|
146 The file(s) in `nnmail-spool-file' will also be read."
|
|
147 :group 'gnus-mail
|
|
148 :type 'boolean)
|
0
|
149
|
16
|
150 (defcustom nnmail-procmail-directory "~/incoming/"
|
0
|
151 "*When using procmail (and the like), incoming mail is put in this directory.
|
16
|
152 The Gnus mail backends will read the mail from this directory."
|
|
153 :group 'gnus-mail
|
|
154 :type 'directory)
|
0
|
155
|
16
|
156 (defcustom nnmail-procmail-suffix "\\.spool"
|
0
|
157 "*Suffix of files created by procmail (and the like).
|
|
158 This variable might be a suffix-regexp to match the suffixes of
|
16
|
159 several files - eg. \".spool[0-9]*\"."
|
|
160 :group 'gnus-mail
|
|
161 :type 'regexp)
|
0
|
162
|
16
|
163 (defcustom nnmail-resplit-incoming nil
|
|
164 "*If non-nil, re-split incoming procmail sorted mail."
|
|
165 :group 'gnus-mail
|
|
166 :type 'boolean)
|
0
|
167
|
16
|
168 (defcustom nnmail-delete-file-function 'delete-file
|
|
169 "Function called to delete files in some mail backends."
|
|
170 :group 'gnus-mail
|
|
171 :type 'function)
|
|
172
|
|
173 (defcustom nnmail-crosspost-link-function 'add-name-to-file
|
0
|
174 "Function called to create a copy of a file.
|
|
175 This is `add-name-to-file' by default, which means that crossposts
|
|
176 will use hard links. If your file system doesn't allow hard
|
16
|
177 links, you could set this variable to `copy-file' instead."
|
|
178 :group 'gnus-mail
|
|
179 :type '(radio (function-item add-name-to-file)
|
|
180 (function-item copy-file)
|
|
181 (function :tag "Other")))
|
0
|
182
|
16
|
183 (defcustom nnmail-movemail-program "movemail"
|
0
|
184 "*A command to be executed to move mail from the inbox.
|
16
|
185 The default is \"movemail\".
|
0
|
186
|
16
|
187 This can also be a function. In that case, the function will be
|
|
188 called with two parameters -- the name of the INBOX file, and the file
|
|
189 to be moved to."
|
|
190 :group 'gnus-mail
|
|
191 :type 'string)
|
0
|
192
|
16
|
193 (defcustom nnmail-pop-password-required nil
|
|
194 "*Non-nil if a password is required when reading mail using POP."
|
|
195 :group 'gnus-mail
|
|
196 :type 'boolean)
|
|
197
|
|
198 (defcustom nnmail-read-incoming-hook
|
|
199 (if (eq system-type 'windows-nt)
|
|
200 '(nnheader-ms-strip-cr)
|
|
201 nil)
|
|
202 "Hook that will be run after the incoming mail has been transferred.
|
0
|
203 The incoming mail is moved from `nnmail-spool-file' (which normally is
|
|
204 something like \"/usr/spool/mail/$user\") to the user's home
|
16
|
205 directory. This hook is called after the incoming mail box has been
|
0
|
206 emptied, and can be used to call any mail box programs you have
|
|
207 running (\"xwatch\", etc.)
|
|
208
|
|
209 Eg.
|
|
210
|
|
211 \(add-hook 'nnmail-read-incoming-hook
|
16
|
212 (lambda ()
|
0
|
213 (start-process \"mailsend\" nil
|
|
214 \"/local/bin/mailsend\" \"read\" \"mbox\")))
|
|
215
|
|
216 If you have xwatch running, this will alert it that mail has been
|
|
217 read.
|
|
218
|
|
219 If you use `display-time', you could use something like this:
|
|
220
|
|
221 \(add-hook 'nnmail-read-incoming-hook
|
|
222 (lambda ()
|
|
223 ;; Update the displayed time, since that will clear out
|
|
224 ;; the flag that says you have mail.
|
16
|
225 (when (eq (process-status \"display-time\") 'run)
|
|
226 (display-time-filter display-time-process \"\"))))"
|
|
227 :group 'gnus-mail
|
|
228 :type 'hook)
|
0
|
229
|
|
230 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
|
16
|
231 (defcustom nnmail-prepare-incoming-hook nil
|
|
232 "Hook called before treating incoming mail.
|
|
233 The hook is run in a buffer with all the new, incoming mail."
|
|
234 :group 'gnus-mail
|
|
235 :type 'hook)
|
|
236
|
|
237 (defcustom nnmail-prepare-incoming-header-hook nil
|
|
238 "Hook called narrowed to the headers of each message.
|
|
239 This can be used to remove excessive spaces (and stuff like
|
|
240 that) from the headers before splitting and saving the messages."
|
|
241 :group 'gnus-mail
|
|
242 :type 'hook)
|
|
243
|
|
244 (defcustom nnmail-prepare-incoming-message-hook nil
|
|
245 "Hook called narrowed to each message."
|
|
246 :group 'gnus-mail
|
|
247 :type 'hook)
|
0
|
248
|
16
|
249 (defcustom nnmail-list-identifiers nil
|
|
250 "Regexp that matches list identifiers to be removed.
|
|
251 This can also be a list of regexps."
|
|
252 :group 'gnus-mail
|
|
253 :type '(choice regexp
|
|
254 (repeat regexp)))
|
|
255
|
|
256 (defcustom nnmail-pre-get-new-mail-hook nil
|
|
257 "Hook called just before starting to handle new incoming mail."
|
|
258 :group 'gnus-mail
|
|
259 :type 'hook)
|
0
|
260
|
16
|
261 (defcustom nnmail-post-get-new-mail-hook nil
|
|
262 "Hook called just after finishing handling new incoming mail."
|
|
263 :group 'gnus-mail
|
|
264 :type 'hook)
|
|
265
|
|
266 (defcustom nnmail-split-hook nil
|
|
267 "Hook called before deciding where to split an article.
|
|
268 The functions in this hook are free to modify the buffer
|
|
269 contents in any way they choose -- the buffer contents are
|
|
270 discarded after running the split process."
|
|
271 :group 'gnus-mail
|
|
272 :type 'hook)
|
0
|
273
|
|
274 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
|
16
|
275 (defcustom nnmail-tmp-directory nil
|
|
276 "*If non-nil, use this directory for temporary storage when reading incoming mail."
|
|
277 :group 'gnus-mail
|
|
278 :type '(choice (const :tag "default" nil)
|
|
279 (directory :format "%v")))
|
0
|
280
|
16
|
281 (defcustom nnmail-large-newsgroup 50
|
0
|
282 "*The number of the articles which indicates a large newsgroup.
|
|
283 If the number of the articles is greater than the value, verbose
|
16
|
284 messages will be shown to indicate the current status."
|
|
285 :group 'gnus-mail
|
|
286 :type 'integer)
|
0
|
287
|
16
|
288 (defcustom nnmail-split-fancy "mail.misc"
|
|
289 "Incoming mail can be split according to this fancy variable.
|
0
|
290 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
|
|
291
|
|
292 The format is this variable is SPLIT, where SPLIT can be one of
|
|
293 the following:
|
|
294
|
16
|
295 GROUP: Mail will be stored in GROUP (a string).
|
0
|
296
|
|
297 \(FIELD VALUE SPLIT): If the message field FIELD (a regexp) contains
|
|
298 VALUE (a regexp), store the messages as specified by SPLIT.
|
|
299
|
|
300 \(| SPLIT...): Process each SPLIT expression until one of them matches.
|
|
301 A SPLIT expression is said to match if it will cause the mail
|
|
302 message to be stored in one or more groups.
|
|
303
|
|
304 \(& SPLIT...): Process each SPLIT expression.
|
|
305
|
16
|
306 \(: FUNCTION optional args): Call FUNCTION with the optional args, in
|
|
307 the buffer containing the message headers. The return value FUNCTION
|
|
308 should be a split, which is then recursively processed.
|
|
309
|
0
|
310 FIELD must match a complete field name. VALUE must match a complete
|
|
311 word according to the `nnmail-split-fancy-syntax-table' syntax table.
|
|
312 You can use .* in the regexps to match partial field names or words.
|
|
313
|
|
314 FIELD and VALUE can also be lisp symbols, in that case they are expanded
|
|
315 as specified in `nnmail-split-abbrev-alist'.
|
|
316
|
16
|
317 GROUP can contain \\& and \\N which will substitute from matching
|
|
318 \\(\\) patterns in the previous VALUE.
|
|
319
|
0
|
320 Example:
|
|
321
|
|
322 \(setq nnmail-split-methods 'nnmail-split-fancy
|
|
323 nnmail-split-fancy
|
16
|
324 ;; Messages from the mailer daemon are not crossposted to any of
|
0
|
325 ;; the ordinary groups. Warnings are put in a separate group
|
|
326 ;; from real errors.
|
|
327 '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
|
|
328 \"mail.misc\"))
|
|
329 ;; Non-error messages are crossposted to all relevant
|
|
330 ;; groups, but we don't crosspost between the group for the
|
|
331 ;; (ding) list and the group for other (ding) related mail.
|
|
332 (& (| (any \"ding@ifi\\\\.uio\\\\.no\" \"ding.list\")
|
|
333 (\"subject\" \"ding\" \"ding.misc\"))
|
|
334 ;; Other mailing lists...
|
|
335 (any \"procmail@informatik\\\\.rwth-aachen\\\\.de\" \"procmail.list\")
|
|
336 (any \"SmartList@informatik\\\\.rwth-aachen\\\\.de\" \"SmartList.list\")
|
|
337 ;; People...
|
|
338 (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
|
|
339 ;; Unmatched mail goes to the catch all group.
|
16
|
340 \"misc.misc\"))"
|
|
341 :group 'gnus-mail
|
|
342 ;; Sigh!
|
|
343 :type 'sexp)
|
0
|
344
|
16
|
345 (defcustom nnmail-split-abbrev-alist
|
2
|
346 '((any . "from\\|to\\|cc\\|sender\\|apparently-to\\|resent-from\\|resent-to\\|resent-cc")
|
16
|
347 (mail . "mailer-daemon\\|postmaster\\|uucp"))
|
|
348 "Alist of abbreviations allowed in `nnmail-split-fancy'."
|
|
349 :group 'gnus-mail
|
|
350 :type '(repeat (cons :format "%v" symbol regexp)))
|
0
|
351
|
16
|
352 (defcustom nnmail-delete-incoming t
|
|
353 "*If non-nil, the mail backends will delete incoming files after
|
|
354 splitting."
|
|
355 :group 'gnus-mail
|
|
356 :type 'boolean)
|
0
|
357
|
16
|
358 (defcustom nnmail-message-id-cache-length 1000
|
0
|
359 "*The approximate number of Message-IDs nnmail will keep in its cache.
|
|
360 If this variable is nil, no checking on duplicate messages will be
|
16
|
361 performed."
|
|
362 :group 'gnus-mail
|
|
363 :type '(choice (const :tag "disable" nil)
|
|
364 (integer :format "%v")))
|
0
|
365
|
16
|
366 (defcustom nnmail-message-id-cache-file "~/.nnmail-cache"
|
|
367 "*The file name of the nnmail Message-ID cache."
|
|
368 :group 'gnus-mail
|
|
369 :type 'file)
|
0
|
370
|
16
|
371 (defcustom nnmail-treat-duplicates 'warn
|
0
|
372 "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates.
|
|
373 Three values are legal: nil, which means that nnmail is not to keep a
|
|
374 Message-ID cache; `warn', which means that nnmail should insert extra
|
|
375 headers to warn the user about the duplication (this is the default);
|
|
376 and `delete', which means that nnmail will delete duplicated mails.
|
|
377
|
|
378 This variable can also be a function. It will be called from a buffer
|
|
379 narrowed to the article in question with the Message-ID as a
|
16
|
380 parameter. It should return nil, `warn' or `delete'."
|
|
381 :group 'gnus-mail
|
|
382 :type '(choice (const :tag "off" nil)
|
|
383 (const warn)
|
|
384 (const delete)))
|
0
|
385
|
|
386 ;;; Internal variables.
|
|
387
|
16
|
388 (defvar nnmail-split-history nil
|
|
389 "List of group/article elements that say where the previous split put messages.")
|
|
390
|
0
|
391 (defvar nnmail-pop-password nil
|
|
392 "*Password to use when reading mail from a POP server, if required.")
|
|
393
|
2
|
394 (defvar nnmail-split-fancy-syntax-table nil
|
0
|
395 "Syntax table used by `nnmail-split-fancy'.")
|
2
|
396 (unless (syntax-table-p nnmail-split-fancy-syntax-table)
|
|
397 (setq nnmail-split-fancy-syntax-table
|
|
398 (copy-syntax-table (standard-syntax-table)))
|
|
399 ;; support the %-hack
|
|
400 (modify-syntax-entry ?\% "." nnmail-split-fancy-syntax-table))
|
|
401
|
0
|
402 (defvar nnmail-prepare-save-mail-hook nil
|
|
403 "Hook called before saving mail.")
|
|
404
|
|
405 (defvar nnmail-moved-inboxes nil
|
|
406 "List of inboxes that have been moved.")
|
|
407
|
|
408 (defvar nnmail-internal-password nil)
|
|
409
|
|
410
|
|
411
|
|
412 (defconst nnmail-version "nnmail 1.0"
|
|
413 "nnmail version.")
|
|
414
|
|
415
|
|
416
|
|
417 (defun nnmail-request-post (&optional server)
|
|
418 (mail-send-and-exit nil))
|
|
419
|
|
420 (defun nnmail-find-file (file)
|
|
421 "Insert FILE in server buffer safely."
|
|
422 (set-buffer nntp-server-buffer)
|
|
423 (erase-buffer)
|
|
424 (let ((format-alist nil)
|
|
425 (after-insert-file-functions nil))
|
|
426 (condition-case ()
|
|
427 (progn (insert-file-contents file) t)
|
|
428 (file-error nil))))
|
|
429
|
|
430 (defun nnmail-group-pathname (group dir &optional file)
|
|
431 "Make pathname for GROUP."
|
|
432 (concat
|
|
433 (let ((dir (file-name-as-directory (expand-file-name dir))))
|
|
434 ;; If this directory exists, we use it directly.
|
|
435 (if (or nnmail-use-long-file-names
|
|
436 (file-directory-p (concat dir group)))
|
|
437 (concat dir group "/")
|
|
438 ;; If not, we translate dots into slashes.
|
|
439 (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/")))
|
|
440 (or file "")))
|
16
|
441
|
0
|
442 (defun nnmail-date-to-time (date)
|
|
443 "Convert DATE into time."
|
16
|
444 (condition-case ()
|
|
445 (let* ((d1 (timezone-parse-date date))
|
|
446 (t1 (timezone-parse-time (aref d1 3))))
|
|
447 (apply 'encode-time
|
|
448 (mapcar (lambda (el)
|
|
449 (and el (string-to-number el)))
|
|
450 (list
|
|
451 (aref t1 2) (aref t1 1) (aref t1 0)
|
|
452 (aref d1 2) (aref d1 1) (aref d1 0)
|
|
453 (number-to-string
|
|
454 (* 60 (timezone-zone-to-minute (aref d1 4))))))))
|
|
455 ;; If we get an error, then we just return a 0 time.
|
|
456 (error (list 0 0))))
|
0
|
457
|
|
458 (defun nnmail-time-less (t1 t2)
|
|
459 "Say whether time T1 is less than time T2."
|
|
460 (or (< (car t1) (car t2))
|
|
461 (and (= (car t1) (car t2))
|
|
462 (< (nth 1 t1) (nth 1 t2)))))
|
|
463
|
|
464 (defun nnmail-days-to-time (days)
|
|
465 "Convert DAYS into time."
|
|
466 (let* ((seconds (* 1.0 days 60 60 24))
|
|
467 (rest (expt 2 16))
|
16
|
468 (ms (condition-case nil (round (/ seconds rest))
|
0
|
469 (range-error (expt 2 16)))))
|
|
470 (list ms (condition-case nil (round (- seconds (* ms rest)))
|
|
471 (range-error (expt 2 16))))))
|
|
472
|
|
473 (defun nnmail-time-since (time)
|
|
474 "Return the time since TIME, which is either an internal time or a date."
|
|
475 (when (stringp time)
|
|
476 ;; Convert date strings to internal time.
|
|
477 (setq time (nnmail-date-to-time time)))
|
|
478 (let* ((current (current-time))
|
16
|
479 (rest (when (< (nth 1 current) (nth 1 time))
|
|
480 (expt 2 16))))
|
0
|
481 (list (- (+ (car current) (if rest -1 0)) (car time))
|
|
482 (- (+ (or rest 0) (nth 1 current)) (nth 1 time)))))
|
|
483
|
|
484 ;; Function rewritten from rmail.el.
|
|
485 (defun nnmail-move-inbox (inbox)
|
|
486 "Move INBOX to `nnmail-crash-box'."
|
16
|
487 (if (not (file-writable-p nnmail-crash-box))
|
|
488 (gnus-error 1 "Can't write to crash box %s. Not moving mail."
|
|
489 nnmail-crash-box)
|
|
490 ;; If the crash box exists and is empty, we delete it.
|
|
491 (when (and (file-exists-p nnmail-crash-box)
|
|
492 (zerop (nnheader-file-size (file-truename nnmail-crash-box))))
|
|
493 (delete-file nnmail-crash-box))
|
|
494 (let ((inbox (file-truename (expand-file-name inbox)))
|
|
495 (tofile (file-truename (expand-file-name nnmail-crash-box)))
|
|
496 movemail popmail errors)
|
|
497 (if (setq popmail (string-match
|
|
498 "^po:" (file-name-nondirectory inbox)))
|
|
499 (setq inbox (file-name-nondirectory inbox))
|
|
500 (setq movemail t)
|
|
501 ;; On some systems, /usr/spool/mail/foo is a directory
|
|
502 ;; and the actual inbox is /usr/spool/mail/foo/foo.
|
|
503 (when (file-directory-p inbox)
|
|
504 (setq inbox (expand-file-name (user-login-name) inbox))))
|
|
505 (if (member inbox nnmail-moved-inboxes)
|
|
506 ;; We don't try to move an already moved inbox.
|
|
507 nil
|
|
508 (if popmail
|
|
509 (progn
|
|
510 (when (and nnmail-pop-password
|
|
511 (not nnmail-internal-password))
|
|
512 (setq nnmail-internal-password nnmail-pop-password))
|
|
513 (when (and nnmail-pop-password-required
|
|
514 (not nnmail-internal-password))
|
|
515 (setq nnmail-internal-password
|
|
516 (nnmail-read-passwd
|
|
517 (format "Password for %s: "
|
|
518 (substring inbox (+ popmail 3))))))
|
|
519 (message "Getting mail from post office ..."))
|
|
520 (when (or (and (file-exists-p tofile)
|
|
521 (/= 0 (nnheader-file-size tofile)))
|
|
522 (and (file-exists-p inbox)
|
|
523 (/= 0 (nnheader-file-size inbox))))
|
|
524 (message "Getting mail from %s..." inbox)))
|
|
525 ;; Set TOFILE if have not already done so, and
|
|
526 ;; rename or copy the file INBOX to TOFILE if and as appropriate.
|
|
527 (cond
|
|
528 ((file-exists-p tofile)
|
|
529 ;; The crash box exists already.
|
|
530 t)
|
|
531 ((and (not popmail)
|
|
532 (not (file-exists-p inbox)))
|
|
533 ;; There is no inbox.
|
|
534 (setq tofile nil))
|
|
535 (t
|
|
536 ;; If getting from mail spool directory, use movemail to move
|
|
537 ;; rather than just renaming, so as to interlock with the
|
|
538 ;; mailer.
|
|
539 (unwind-protect
|
|
540 (save-excursion
|
|
541 (setq errors (generate-new-buffer " *nnmail loss*"))
|
|
542 (buffer-disable-undo errors)
|
|
543 (let ((default-directory "/"))
|
|
544 (if (nnheader-functionp nnmail-movemail-program)
|
|
545 (funcall nnmail-movemail-program inbox tofile)
|
|
546 (apply
|
|
547 'call-process
|
|
548 (append
|
|
549 (list
|
|
550 (expand-file-name
|
|
551 nnmail-movemail-program exec-directory)
|
|
552 nil errors nil inbox tofile)
|
|
553 (when nnmail-internal-password
|
|
554 (list nnmail-internal-password))))))
|
|
555 (if (not (buffer-modified-p errors))
|
|
556 ;; No output => movemail won
|
|
557 (progn
|
|
558 (unless popmail
|
|
559 (set-file-modes tofile nnmail-default-file-modes))
|
|
560 (push inbox nnmail-moved-inboxes))
|
|
561 (set-buffer errors)
|
|
562 ;; There may be a warning about older revisions. We
|
|
563 ;; ignore those.
|
|
564 (goto-char (point-min))
|
|
565 (if (search-forward "older revision" nil t)
|
|
566 (progn
|
|
567 (unless popmail
|
|
568 (set-file-modes tofile nnmail-default-file-modes))
|
|
569 (push inbox nnmail-moved-inboxes))
|
|
570 ;; Probably a real error.
|
|
571 (subst-char-in-region (point-min) (point-max) ?\n ?\ )
|
|
572 (goto-char (point-max))
|
|
573 (skip-chars-backward " \t")
|
|
574 (delete-region (point) (point-max))
|
|
575 (goto-char (point-min))
|
|
576 (when (looking-at "movemail: ")
|
|
577 (delete-region (point-min) (match-end 0)))
|
|
578 (unless (yes-or-no-p
|
|
579 (format "movemail: %s. Continue? "
|
|
580 (buffer-string)))
|
|
581 (error "%s" (buffer-string)))
|
|
582 (setq tofile nil)))))))
|
|
583 (message "Getting mail from %s...done" inbox)
|
|
584 (and errors
|
|
585 (buffer-name errors)
|
|
586 (kill-buffer errors))
|
|
587 tofile))))
|
0
|
588
|
|
589 (defun nnmail-get-active ()
|
|
590 "Returns an assoc of group names and active ranges.
|
|
591 nn*-request-list should have been called before calling this function."
|
|
592 (let (group-assoc)
|
|
593 ;; Go through all groups from the active list.
|
|
594 (save-excursion
|
|
595 (set-buffer nntp-server-buffer)
|
|
596 (goto-char (point-min))
|
|
597 (while (re-search-forward
|
|
598 "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t)
|
|
599 ;; We create an alist with `(GROUP (LOW . HIGH))' elements.
|
|
600 (push (list (match-string 1)
|
|
601 (cons (string-to-int (match-string 3))
|
|
602 (string-to-int (match-string 2))))
|
|
603 group-assoc)))
|
|
604 group-assoc))
|
|
605
|
|
606 (defun nnmail-save-active (group-assoc file-name)
|
|
607 "Save GROUP-ASSOC in ACTIVE-FILE."
|
|
608 (when file-name
|
16
|
609 (nnheader-temp-write file-name
|
|
610 (nnmail-generate-active group-assoc))))
|
|
611
|
|
612 (defun nnmail-generate-active (alist)
|
|
613 "Generate an active file from group-alist ALIST."
|
|
614 (erase-buffer)
|
|
615 (let (group)
|
|
616 (while (setq group (pop alist))
|
|
617 (insert (format "%s %d %d y\n" (car group) (cdadr group)
|
|
618 (caadr group))))))
|
0
|
619
|
|
620 (defun nnmail-get-split-group (file group)
|
16
|
621 "Find out whether this FILE is to be split into GROUP only.
|
|
622 If GROUP is non-nil and we are using procmail, return the group name
|
|
623 only when the file is the correct procmail file. When GROUP is nil,
|
|
624 return nil if FILE is a spool file or the procmail group for which it
|
|
625 is a spool. If not using procmail, return GROUP."
|
0
|
626 (if (or (eq nnmail-spool-file 'procmail)
|
|
627 nnmail-use-procmail)
|
16
|
628 (if (string-match (concat "^" (expand-file-name
|
|
629 (file-name-as-directory
|
|
630 nnmail-procmail-directory))
|
|
631 "\\([^/]*\\)" nnmail-procmail-suffix "$")
|
|
632 (expand-file-name file))
|
|
633 (let ((procmail-group (substring (expand-file-name file)
|
|
634 (match-beginning 1)
|
|
635 (match-end 1))))
|
|
636 (if group
|
|
637 (if (string-equal group procmail-group)
|
|
638 group
|
|
639 nil)
|
|
640 procmail-group))
|
|
641 nil)
|
0
|
642 group))
|
|
643
|
16
|
644 (defun nnmail-process-babyl-mail-format (func artnum-func)
|
0
|
645 (let ((case-fold-search t)
|
|
646 start message-id content-length do-search end)
|
16
|
647 (goto-char (point-min))
|
0
|
648 (while (not (eobp))
|
|
649 (re-search-forward
|
|
650 "\n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t)
|
|
651 (goto-char (match-end 0))
|
|
652 (delete-region (match-beginning 0) (match-end 0))
|
16
|
653 (narrow-to-region
|
|
654 (setq start (point))
|
|
655 (progn
|
|
656 ;; Skip all the headers in case there are more "From "s...
|
|
657 (or (search-forward "\n\n" nil t)
|
|
658 (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t)
|
|
659 (search-forward ""))
|
|
660 (point)))
|
|
661 ;; Unquote the ">From " line, if any.
|
|
662 (goto-char (point-min))
|
|
663 (when (looking-at ">From ")
|
|
664 (replace-match "X-From-Line: ") )
|
|
665 (run-hooks 'nnmail-prepare-incoming-header-hook)
|
|
666 (goto-char (point-max))
|
0
|
667 ;; Find the Message-ID header.
|
|
668 (save-excursion
|
|
669 (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t)
|
|
670 (setq message-id (buffer-substring (match-beginning 1)
|
|
671 (match-end 1)))
|
|
672 ;; There is no Message-ID here, so we create one.
|
|
673 (save-excursion
|
|
674 (when (re-search-backward "^Message-ID:" nil t)
|
|
675 (beginning-of-line)
|
|
676 (insert "Original-")))
|
|
677 (forward-line -1)
|
|
678 (insert "Message-ID: " (setq message-id (nnmail-message-id))
|
|
679 "\n")))
|
|
680 ;; Look for a Content-Length header.
|
|
681 (if (not (save-excursion
|
|
682 (and (re-search-backward
|
|
683 "^Content-Length:[ \t]*\\([0-9]+\\)" start t)
|
|
684 (setq content-length (string-to-int
|
|
685 (buffer-substring
|
|
686 (match-beginning 1)
|
|
687 (match-end 1))))
|
|
688 ;; We destroy the header, since none of
|
|
689 ;; the backends ever use it, and we do not
|
|
690 ;; want to confuse other mailers by having
|
|
691 ;; a (possibly) faulty header.
|
|
692 (progn (insert "X-") t))))
|
|
693 (setq do-search t)
|
16
|
694 (widen)
|
0
|
695 (if (or (= (+ (point) content-length) (point-max))
|
|
696 (save-excursion
|
|
697 (goto-char (+ (point) content-length))
|
|
698 (looking-at "")))
|
|
699 (progn
|
|
700 (goto-char (+ (point) content-length))
|
|
701 (setq do-search nil))
|
|
702 (setq do-search t)))
|
16
|
703 (widen)
|
0
|
704 ;; Go to the beginning of the next article - or to the end
|
|
705 ;; of the buffer.
|
16
|
706 (when do-search
|
|
707 (if (re-search-forward "^" nil t)
|
|
708 (goto-char (match-beginning 0))
|
|
709 (goto-char (1- (point-max)))))
|
0
|
710 (delete-char 1) ; delete ^_
|
|
711 (save-excursion
|
|
712 (save-restriction
|
|
713 (narrow-to-region start (point))
|
|
714 (goto-char (point-min))
|
16
|
715 (nnmail-check-duplication message-id func artnum-func)
|
0
|
716 (setq end (point-max))))
|
|
717 (goto-char end))))
|
|
718
|
|
719 (defun nnmail-search-unix-mail-delim ()
|
16
|
720 "Put point at the beginning of the next Unix mbox message."
|
|
721 ;; Algorithm used to find the the next article in the
|
|
722 ;; brain-dead Unix mbox format:
|
|
723 ;;
|
|
724 ;; 1) Search for "^From ".
|
|
725 ;; 2) If we find it, then see whether the previous
|
|
726 ;; line is blank and the next line looks like a header.
|
|
727 ;; Then it's possible that this is a mail delim, and we use it.
|
|
728 (let ((case-fold-search nil)
|
0
|
729 found)
|
|
730 (while (not found)
|
16
|
731 (if (not (re-search-forward "^From " nil t))
|
|
732 (setq found 'no)
|
|
733 (save-excursion
|
|
734 (beginning-of-line)
|
|
735 (when (and (or (bobp)
|
|
736 (save-excursion
|
|
737 (forward-line -1)
|
|
738 (= (following-char) ?\n)))
|
|
739 (save-excursion
|
|
740 (forward-line 1)
|
|
741 (while (looking-at ">From ")
|
|
742 (forward-line 1))
|
|
743 (looking-at "[^ \t:]+[ \t]*:")))
|
|
744 (setq found 'yes)))))
|
|
745 (beginning-of-line)
|
0
|
746 (eq found 'yes)))
|
|
747
|
16
|
748 (defun nnmail-search-unix-mail-delim-backward ()
|
|
749 "Put point at the beginning of the current Unix mbox message."
|
|
750 ;; Algorithm used to find the the next article in the
|
|
751 ;; brain-dead Unix mbox format:
|
|
752 ;;
|
|
753 ;; 1) Search for "^From ".
|
|
754 ;; 2) If we find it, then see whether the previous
|
|
755 ;; line is blank and the next line looks like a header.
|
|
756 ;; Then it's possible that this is a mail delim, and we use it.
|
|
757 (let ((case-fold-search nil)
|
|
758 found)
|
|
759 (while (not found)
|
|
760 (if (not (re-search-backward "^From " nil t))
|
|
761 (setq found 'no)
|
|
762 (save-excursion
|
|
763 (beginning-of-line)
|
|
764 (when (and (or (bobp)
|
|
765 (save-excursion
|
|
766 (forward-line -1)
|
|
767 (= (following-char) ?\n)))
|
|
768 (save-excursion
|
|
769 (forward-line 1)
|
|
770 (while (looking-at ">From ")
|
|
771 (forward-line 1))
|
|
772 (looking-at "[^ \t:]+[ \t]*:")))
|
|
773 (setq found 'yes)))))
|
|
774 (beginning-of-line)
|
|
775 (eq found 'yes)))
|
|
776
|
|
777 (defun nnmail-process-unix-mail-format (func artnum-func)
|
0
|
778 (let ((case-fold-search t)
|
|
779 start message-id content-length end skip head-end)
|
|
780 (goto-char (point-min))
|
16
|
781 (if (not (and (re-search-forward "^From " nil t)
|
0
|
782 (goto-char (match-beginning 0))))
|
|
783 ;; Possibly wrong format?
|
|
784 (error "Error, unknown mail format! (Possibly corrupted.)")
|
|
785 ;; Carry on until the bitter end.
|
|
786 (while (not (eobp))
|
|
787 (setq start (point)
|
|
788 end nil)
|
|
789 ;; Find the end of the head.
|
|
790 (narrow-to-region
|
|
791 start
|
|
792 (if (search-forward "\n\n" nil t)
|
|
793 (1- (point))
|
|
794 ;; This will never happen, but just to be on the safe side --
|
|
795 ;; if there is no head-body delimiter, we search a bit manually.
|
|
796 (while (and (looking-at "From \\|[^ \t]+:")
|
|
797 (not (eobp)))
|
|
798 (forward-line 1)
|
|
799 (point))))
|
|
800 ;; Find the Message-ID header.
|
|
801 (goto-char (point-min))
|
|
802 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
|
|
803 (setq message-id (match-string 1))
|
|
804 (save-excursion
|
|
805 (when (re-search-forward "^Message-ID:" nil t)
|
|
806 (beginning-of-line)
|
|
807 (insert "Original-")))
|
|
808 ;; There is no Message-ID here, so we create one.
|
|
809 (forward-line 1)
|
|
810 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
|
|
811 ;; Look for a Content-Length header.
|
|
812 (goto-char (point-min))
|
|
813 (if (not (re-search-forward
|
|
814 "^Content-Length:[ \t]*\\([0-9]+\\)" nil t))
|
|
815 (setq content-length nil)
|
|
816 (setq content-length (string-to-int (match-string 1)))
|
|
817 ;; We destroy the header, since none of the backends ever
|
|
818 ;; use it, and we do not want to confuse other mailers by
|
|
819 ;; having a (possibly) faulty header.
|
|
820 (beginning-of-line)
|
|
821 (insert "X-"))
|
16
|
822 (run-hooks 'nnmail-prepare-incoming-header-hook)
|
0
|
823 ;; Find the end of this article.
|
|
824 (goto-char (point-max))
|
|
825 (widen)
|
|
826 (setq head-end (point))
|
|
827 ;; We try the Content-Length value. The idea: skip over the header
|
|
828 ;; separator, then check what happens content-length bytes into the
|
|
829 ;; message body. This should be either the end ot the buffer, the
|
|
830 ;; message separator or a blank line followed by the separator.
|
|
831 ;; The blank line should probably be deleted. If neither of the
|
|
832 ;; three is met, the content-length header is probably invalid.
|
|
833 (when content-length
|
|
834 (forward-line 1)
|
|
835 (setq skip (+ (point) content-length))
|
|
836 (goto-char skip)
|
|
837 (cond ((or (= skip (point-max))
|
|
838 (= (1+ skip) (point-max)))
|
|
839 (setq end (point-max)))
|
16
|
840 ((looking-at "From ")
|
0
|
841 (setq end skip))
|
16
|
842 ((looking-at "[ \t]*\n\\(From \\)")
|
0
|
843 (setq end (match-beginning 1)))
|
|
844 (t (setq end nil))))
|
|
845 (if end
|
|
846 (goto-char end)
|
|
847 ;; No Content-Length, so we find the beginning of the next
|
|
848 ;; article or the end of the buffer.
|
|
849 (goto-char head-end)
|
|
850 (or (nnmail-search-unix-mail-delim)
|
|
851 (goto-char (point-max))))
|
|
852 ;; Allow the backend to save the article.
|
|
853 (save-excursion
|
|
854 (save-restriction
|
|
855 (narrow-to-region start (point))
|
|
856 (goto-char (point-min))
|
16
|
857 (nnmail-check-duplication message-id func artnum-func)
|
0
|
858 (setq end (point-max))))
|
|
859 (goto-char end)))))
|
|
860
|
16
|
861 (defun nnmail-process-mmdf-mail-format (func artnum-func)
|
0
|
862 (let ((delim "^\^A\^A\^A\^A$")
|
|
863 (case-fold-search t)
|
|
864 start message-id end)
|
|
865 (goto-char (point-min))
|
|
866 (if (not (and (re-search-forward delim nil t)
|
|
867 (forward-line 1)))
|
|
868 ;; Possibly wrong format?
|
|
869 (error "Error, unknown mail format! (Possibly corrupted.)")
|
|
870 ;; Carry on until the bitter end.
|
|
871 (while (not (eobp))
|
|
872 (setq start (point))
|
|
873 ;; Find the end of the head.
|
|
874 (narrow-to-region
|
|
875 start
|
|
876 (if (search-forward "\n\n" nil t)
|
|
877 (1- (point))
|
|
878 ;; This will never happen, but just to be on the safe side --
|
|
879 ;; if there is no head-body delimiter, we search a bit manually.
|
|
880 (while (and (looking-at "From \\|[^ \t]+:")
|
|
881 (not (eobp)))
|
|
882 (forward-line 1)
|
|
883 (point))))
|
|
884 ;; Find the Message-ID header.
|
|
885 (goto-char (point-min))
|
|
886 (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t)
|
|
887 (setq message-id (match-string 1))
|
|
888 ;; There is no Message-ID here, so we create one.
|
|
889 (save-excursion
|
|
890 (when (re-search-backward "^Message-ID:" nil t)
|
|
891 (beginning-of-line)
|
|
892 (insert "Original-")))
|
|
893 (forward-line 1)
|
|
894 (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n"))
|
16
|
895 (run-hooks 'nnmail-prepare-incoming-header-hook)
|
0
|
896 ;; Find the end of this article.
|
|
897 (goto-char (point-max))
|
|
898 (widen)
|
|
899 (if (re-search-forward delim nil t)
|
|
900 (beginning-of-line)
|
|
901 (goto-char (point-max)))
|
|
902 ;; Allow the backend to save the article.
|
|
903 (save-excursion
|
|
904 (save-restriction
|
|
905 (narrow-to-region start (point))
|
|
906 (goto-char (point-min))
|
16
|
907 (nnmail-check-duplication message-id func artnum-func)
|
0
|
908 (setq end (point-max))))
|
|
909 (goto-char end)
|
|
910 (forward-line 2)))))
|
|
911
|
16
|
912 (defun nnmail-split-incoming (incoming func &optional exit-func
|
|
913 group artnum-func)
|
0
|
914 "Go through the entire INCOMING file and pick out each individual mail.
|
|
915 FUNC will be called with the buffer narrowed to each mail."
|
|
916 (let (;; If this is a group-specific split, we bind the split
|
|
917 ;; methods to just this group.
|
|
918 (nnmail-split-methods (if (and group
|
|
919 (or (eq nnmail-spool-file 'procmail)
|
|
920 nnmail-use-procmail)
|
|
921 (not nnmail-resplit-incoming))
|
|
922 (list (list group ""))
|
|
923 nnmail-split-methods)))
|
|
924 (save-excursion
|
|
925 ;; Insert the incoming file.
|
|
926 (set-buffer (get-buffer-create " *nnmail incoming*"))
|
|
927 (buffer-disable-undo (current-buffer))
|
|
928 (erase-buffer)
|
16
|
929 (nnheader-insert-file-contents incoming)
|
0
|
930 (unless (zerop (buffer-size))
|
|
931 (goto-char (point-min))
|
|
932 (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
|
|
933 ;; Handle both babyl, MMDF and unix mail formats, since movemail will
|
|
934 ;; use the former when fetching from a mailbox, the latter when
|
|
935 ;; fetches from a file.
|
|
936 (cond ((or (looking-at "\^L")
|
|
937 (looking-at "BABYL OPTIONS:"))
|
16
|
938 (nnmail-process-babyl-mail-format func artnum-func))
|
0
|
939 ((looking-at "\^A\^A\^A\^A")
|
16
|
940 (nnmail-process-mmdf-mail-format func artnum-func))
|
0
|
941 (t
|
16
|
942 (nnmail-process-unix-mail-format func artnum-func))))
|
|
943 (when exit-func
|
|
944 (funcall exit-func))
|
0
|
945 (kill-buffer (current-buffer)))))
|
|
946
|
|
947 ;; Mail crossposts suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
|
|
948 (defun nnmail-article-group (func)
|
|
949 "Look at the headers and return an alist of groups that match.
|
|
950 FUNC will be called with the group name to determine the article number."
|
|
951 (let ((methods nnmail-split-methods)
|
|
952 (obuf (current-buffer))
|
|
953 (beg (point-min))
|
|
954 end group-art method)
|
|
955 (if (and (sequencep methods) (= (length methods) 1))
|
|
956 ;; If there is only just one group to put everything in, we
|
|
957 ;; just return a list with just this one method in.
|
|
958 (setq group-art
|
|
959 (list (cons (caar methods) (funcall func (caar methods)))))
|
|
960 ;; We do actual comparison.
|
|
961 (save-excursion
|
|
962 ;; Find headers.
|
|
963 (goto-char beg)
|
|
964 (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
|
|
965 (set-buffer nntp-server-buffer)
|
|
966 (erase-buffer)
|
|
967 ;; Copy the headers into the work buffer.
|
|
968 (insert-buffer-substring obuf beg end)
|
|
969 ;; Fold continuation lines.
|
|
970 (goto-char (point-min))
|
|
971 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
|
|
972 (replace-match " " t t))
|
16
|
973 ;; Allow washing.
|
|
974 (run-hooks 'nnmail-split-hook)
|
0
|
975 (if (and (symbolp nnmail-split-methods)
|
|
976 (fboundp nnmail-split-methods))
|
16
|
977 (let ((split
|
0
|
978 (condition-case nil
|
|
979 (or (funcall nnmail-split-methods)
|
|
980 '("bogus"))
|
|
981 (error
|
|
982 (message
|
|
983 "Error in `nnmail-split-methods'; using `bogus' mail group")
|
|
984 (sit-for 1)
|
|
985 '("bogus")))))
|
16
|
986 (unless (equal split '(junk))
|
|
987 ;; `nnmail-split-methods' is a function, so we just call
|
|
988 ;; this function here and use the result.
|
|
989 (setq group-art
|
|
990 (mapcar
|
|
991 (lambda (group) (cons group (funcall func group)))
|
|
992 split))))
|
0
|
993 ;; Go through the split methods to find a match.
|
|
994 (while (and methods (or nnmail-crosspost (not group-art)))
|
|
995 (goto-char (point-max))
|
|
996 (setq method (pop methods))
|
|
997 (if (or methods
|
|
998 (not (equal "" (nth 1 method))))
|
|
999 (when (and
|
16
|
1000 (ignore-errors
|
|
1001 (if (stringp (nth 1 method))
|
|
1002 (re-search-backward (cadr method) nil t)
|
|
1003 ;; Function to say whether this is a match.
|
|
1004 (funcall (nth 1 method) (car method))))
|
0
|
1005 ;; Don't enter the article into the same
|
|
1006 ;; group twice.
|
|
1007 (not (assoc (car method) group-art)))
|
16
|
1008 (push (cons (car method) (funcall func (car method)))
|
0
|
1009 group-art))
|
|
1010 ;; This is the final group, which is used as a
|
|
1011 ;; catch-all.
|
|
1012 (unless group-art
|
|
1013 (setq group-art
|
16
|
1014 (list (cons (car method)
|
0
|
1015 (funcall func (car method)))))))))
|
16
|
1016 ;; See whether the split methods returned `junk'.
|
|
1017 (if (equal group-art '(junk))
|
|
1018 nil
|
|
1019 (nreverse (delq 'junk group-art)))))))
|
0
|
1020
|
|
1021 (defun nnmail-insert-lines ()
|
|
1022 "Insert how many lines there are in the body of the mail.
|
|
1023 Return the number of characters in the body."
|
|
1024 (let (lines chars)
|
|
1025 (save-excursion
|
|
1026 (goto-char (point-min))
|
16
|
1027 (when (search-forward "\n\n" nil t)
|
0
|
1028 (setq chars (- (point-max) (point)))
|
|
1029 (setq lines (count-lines (point) (point-max)))
|
|
1030 (forward-char -1)
|
|
1031 (save-excursion
|
|
1032 (when (re-search-backward "^Lines: " nil t)
|
|
1033 (delete-region (point) (progn (forward-line 1) (point)))))
|
|
1034 (beginning-of-line)
|
|
1035 (insert (format "Lines: %d\n" (max lines 0)))
|
|
1036 chars))))
|
|
1037
|
|
1038 (defun nnmail-insert-xref (group-alist)
|
|
1039 "Insert an Xref line based on the (group . article) alist."
|
|
1040 (save-excursion
|
|
1041 (goto-char (point-min))
|
16
|
1042 (when (search-forward "\n\n" nil t)
|
0
|
1043 (forward-char -1)
|
|
1044 (when (re-search-backward "^Xref: " nil t)
|
16
|
1045 (delete-region (match-beginning 0)
|
0
|
1046 (progn (forward-line 1) (point))))
|
|
1047 (insert (format "Xref: %s" (system-name)))
|
|
1048 (while group-alist
|
|
1049 (insert (format " %s:%d" (caar group-alist) (cdar group-alist)))
|
|
1050 (setq group-alist (cdr group-alist)))
|
|
1051 (insert "\n"))))
|
|
1052
|
16
|
1053 ;;; Message washing functions
|
|
1054
|
|
1055 (defun nnmail-remove-leading-whitespace ()
|
|
1056 "Remove excessive whitespace from all headers."
|
|
1057 (goto-char (point-min))
|
|
1058 (while (re-search-forward "^\\([^ :]+: \\) +" nil t)
|
|
1059 (replace-match "\\1" t)))
|
|
1060
|
|
1061 (defun nnmail-remove-list-identifiers ()
|
|
1062 "Remove list identifiers from Subject headers."
|
|
1063 (let ((regexp (if (stringp nnmail-list-identifiers) nnmail-list-identifiers
|
|
1064 (mapconcat 'identity nnmail-list-identifiers "\\|"))))
|
|
1065 (when regexp
|
|
1066 (goto-char (point-min))
|
|
1067 (when (re-search-forward
|
|
1068 (concat "^Subject: +\\(Re: +\\)?\\(" regexp "\\) *")
|
|
1069 nil t)
|
|
1070 (delete-region (match-beginning 2) (match-end 0))))))
|
|
1071
|
|
1072 (defun nnmail-remove-tabs ()
|
|
1073 "Translate TAB characters into SPACE characters."
|
|
1074 (subst-char-in-region (point-min) (point-max) ?\t ? t))
|
|
1075
|
|
1076 ;;; Utility functions
|
|
1077
|
0
|
1078 ;; Written by byer@mv.us.adobe.com (Scott Byer).
|
|
1079 (defun nnmail-make-complex-temp-name (prefix)
|
|
1080 (let ((newname (make-temp-name prefix))
|
|
1081 (newprefix prefix))
|
|
1082 (while (file-exists-p newname)
|
|
1083 (setq newprefix (concat newprefix "x"))
|
|
1084 (setq newname (make-temp-name newprefix)))
|
|
1085 newname))
|
|
1086
|
|
1087 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
|
|
1088
|
|
1089 (defun nnmail-split-fancy ()
|
|
1090 "Fancy splitting method.
|
|
1091 See the documentation for the variable `nnmail-split-fancy' for documentation."
|
|
1092 (let ((syntab (syntax-table)))
|
|
1093 (unwind-protect
|
|
1094 (progn
|
|
1095 (set-syntax-table nnmail-split-fancy-syntax-table)
|
|
1096 (nnmail-split-it nnmail-split-fancy))
|
|
1097 (set-syntax-table syntab))))
|
|
1098
|
|
1099 (defvar nnmail-split-cache nil)
|
|
1100 ;; Alist of split expressions their equivalent regexps.
|
|
1101
|
|
1102 (defun nnmail-split-it (split)
|
|
1103 ;; Return a list of groups matching SPLIT.
|
16
|
1104 (cond
|
|
1105 ;; nil split
|
|
1106 ((null split)
|
|
1107 nil)
|
|
1108
|
|
1109 ;; A group name. Do the \& and \N subs into the string.
|
|
1110 ((stringp split)
|
|
1111 (list (nnmail-expand-newtext split)))
|
|
1112
|
|
1113 ;; Junk the message.
|
|
1114 ((eq split 'junk)
|
|
1115 (list 'junk))
|
|
1116
|
|
1117 ;; Builtin & operation.
|
|
1118 ((eq (car split) '&)
|
|
1119 (apply 'nconc (mapcar 'nnmail-split-it (cdr split))))
|
|
1120
|
|
1121 ;; Builtin | operation.
|
|
1122 ((eq (car split) '|)
|
|
1123 (let (done)
|
|
1124 (while (and (not done) (cdr split))
|
|
1125 (setq split (cdr split)
|
|
1126 done (nnmail-split-it (car split))))
|
|
1127 done))
|
|
1128
|
|
1129 ;; Builtin : operation.
|
|
1130 ((eq (car split) ':)
|
|
1131 (nnmail-split-it (eval (cdr split))))
|
|
1132
|
|
1133 ;; Check the cache for the regexp for this split.
|
|
1134 ;; FIX FIX FIX could avoid calling assq twice here
|
|
1135 ((assq split nnmail-split-cache)
|
|
1136 (goto-char (point-max))
|
|
1137 ;; FIX FIX FIX problem with re-search-backward is that if you have
|
|
1138 ;; a split: (from "foo-\\(bar\\|baz\\)@gnus.org "mail.foo.\\1")
|
|
1139 ;; and someone mails a message with 'To: foo-bar@gnus.org' and
|
|
1140 ;; 'CC: foo-baz@gnus.org', we'll pick 'mail.foo.baz' as the group
|
|
1141 ;; if the cc line is a later header, even though the other choice
|
|
1142 ;; is probably better. Also, this routine won't do a crosspost
|
|
1143 ;; when there are two different matches.
|
|
1144 ;; I guess you could just make this more determined, and it could
|
|
1145 ;; look for still more matches prior to this one, and recurse
|
|
1146 ;; on each of the multiple matches hit. Of course, then you'd
|
|
1147 ;; want to make sure that nnmail-article-group or nnmail-split-fancy
|
|
1148 ;; removed duplicates, since there might be more of those.
|
|
1149 ;; I guess we could also remove duplicates in the & split case, since
|
|
1150 ;; that's the only thing that can introduce them.
|
|
1151 (when (re-search-backward (cdr (assq split nnmail-split-cache)) nil t)
|
|
1152 ;; Someone might want to do a \N sub on this match, so get the
|
|
1153 ;; correct match positions.
|
|
1154 (goto-char (match-end 0))
|
|
1155 (let ((value (nth 1 split)))
|
|
1156 (re-search-backward (if (symbolp value)
|
|
1157 (cdr (assq value nnmail-split-abbrev-alist))
|
|
1158 value)
|
|
1159 (match-end 1)))
|
|
1160 (nnmail-split-it (nth 2 split))))
|
|
1161
|
|
1162 ;; Not in cache, compute a regexp for the field/value pair.
|
|
1163 (t
|
|
1164 (let* ((field (nth 0 split))
|
|
1165 (value (nth 1 split))
|
|
1166 (regexp (concat "^\\(\\("
|
|
1167 (if (symbolp field)
|
|
1168 (cdr (assq field nnmail-split-abbrev-alist))
|
|
1169 field)
|
|
1170 "\\):.*\\)\\<\\("
|
|
1171 (if (symbolp value)
|
|
1172 (cdr (assq value nnmail-split-abbrev-alist))
|
|
1173 value)
|
|
1174 "\\)\\>")))
|
|
1175 (push (cons split regexp) nnmail-split-cache)
|
|
1176 ;; Now that it's in the cache, just call nnmail-split-it again
|
|
1177 ;; on the same split, which will find it immediately in the cache.
|
|
1178 (nnmail-split-it split)))))
|
|
1179
|
|
1180 (defun nnmail-expand-newtext (newtext)
|
|
1181 (let ((len (length newtext))
|
|
1182 (pos 0)
|
|
1183 c expanded beg N did-expand)
|
|
1184 (while (< pos len)
|
|
1185 (setq beg pos)
|
|
1186 (while (and (< pos len)
|
|
1187 (not (= (aref newtext pos) ?\\)))
|
|
1188 (setq pos (1+ pos)))
|
|
1189 (unless (= beg pos)
|
|
1190 (push (substring newtext beg pos) expanded))
|
|
1191 (when (< pos len)
|
|
1192 ;; we hit a \, expand it.
|
|
1193 (setq did-expand t)
|
|
1194 (setq pos (1+ pos))
|
|
1195 (setq c (aref newtext pos))
|
|
1196 (if (not (or (= c ?\&)
|
|
1197 (and (>= c ?1)
|
|
1198 (<= c ?9))))
|
|
1199 ;; \ followed by some character we don't expand
|
|
1200 (push (char-to-string c) expanded)
|
|
1201 ;; \& or \N
|
|
1202 (if (= c ?\&)
|
|
1203 (setq N 0)
|
|
1204 (setq N (- c ?0)))
|
|
1205 (when (match-beginning N)
|
|
1206 (push (buffer-substring (match-beginning N) (match-end N))
|
|
1207 expanded))))
|
|
1208 (setq pos (1+ pos)))
|
|
1209 (if did-expand
|
|
1210 (apply 'concat (nreverse expanded))
|
|
1211 newtext)))
|
0
|
1212
|
|
1213 ;; Get a list of spool files to read.
|
|
1214 (defun nnmail-get-spool-files (&optional group)
|
|
1215 (if (null nnmail-spool-file)
|
|
1216 ;; No spool file whatsoever.
|
|
1217 nil
|
|
1218 (let* ((procmails
|
|
1219 ;; If procmail is used to get incoming mail, the files
|
|
1220 ;; are stored in this directory.
|
|
1221 (and (file-exists-p nnmail-procmail-directory)
|
|
1222 (or (eq nnmail-spool-file 'procmail)
|
|
1223 nnmail-use-procmail)
|
|
1224 (directory-files
|
|
1225 nnmail-procmail-directory
|
|
1226 t (concat (if group (concat "^" group) "")
|
16
|
1227 nnmail-procmail-suffix "$"))))
|
0
|
1228 (p procmails)
|
|
1229 (crash (when (and (file-exists-p nnmail-crash-box)
|
2
|
1230 (> (nnheader-file-size
|
16
|
1231 (file-truename nnmail-crash-box))
|
|
1232 0))
|
0
|
1233 (list nnmail-crash-box))))
|
16
|
1234 ;; Remove any directories that inadvertently match the procmail
|
0
|
1235 ;; suffix, which might happen if the suffix is "".
|
|
1236 (while p
|
|
1237 (when (file-directory-p (car p))
|
|
1238 (setq procmails (delete (car p) procmails)))
|
|
1239 (setq p (cdr p)))
|
|
1240 ;; Return the list of spools.
|
|
1241 (append
|
|
1242 crash
|
|
1243 (cond ((and group
|
|
1244 (or (eq nnmail-spool-file 'procmail)
|
2
|
1245 nnmail-use-procmail)
|
|
1246 procmails)
|
0
|
1247 procmails)
|
2
|
1248 ((and group
|
|
1249 (eq nnmail-spool-file 'procmail))
|
|
1250 nil)
|
0
|
1251 ((listp nnmail-spool-file)
|
16
|
1252 (nconc
|
|
1253 (apply
|
|
1254 'nconc
|
|
1255 (mapcar
|
|
1256 (lambda (file)
|
|
1257 (if (file-directory-p file)
|
|
1258 (nnheader-directory-regular-files file)
|
|
1259 (list file)))
|
|
1260 nnmail-spool-file))
|
|
1261 procmails))
|
|
1262 ((and (stringp nnmail-spool-file)
|
|
1263 (not (file-directory-p nnmail-spool-file)))
|
0
|
1264 (cons nnmail-spool-file procmails))
|
16
|
1265 ((and (stringp nnmail-spool-file)
|
|
1266 (file-directory-p nnmail-spool-file))
|
|
1267 (nconc
|
|
1268 (nnheader-directory-regular-files nnmail-spool-file)
|
|
1269 procmails))
|
0
|
1270 ((eq nnmail-spool-file 'pop)
|
|
1271 (cons (format "po:%s" (user-login-name)) procmails))
|
|
1272 (t
|
|
1273 procmails))))))
|
|
1274
|
|
1275 ;; Activate a backend only if it isn't already activated.
|
|
1276 ;; If FORCE, re-read the active file even if the backend is
|
|
1277 ;; already activated.
|
|
1278 (defun nnmail-activate (backend &optional force)
|
|
1279 (let (file timestamp file-time)
|
|
1280 (if (or (not (symbol-value (intern (format "%s-group-alist" backend))))
|
|
1281 force
|
16
|
1282 (and (setq file (ignore-errors
|
|
1283 (symbol-value (intern (format "%s-active-file"
|
|
1284 backend)))))
|
0
|
1285 (setq file-time (nth 5 (file-attributes file)))
|
|
1286 (or (not
|
|
1287 (setq timestamp
|
|
1288 (condition-case ()
|
|
1289 (symbol-value (intern
|
|
1290 (format "%s-active-timestamp"
|
|
1291 backend)))
|
|
1292 (error 'none))))
|
|
1293 (not (consp timestamp))
|
|
1294 (equal timestamp '(0 0))
|
|
1295 (> (nth 0 file-time) (nth 0 timestamp))
|
|
1296 (and (= (nth 0 file-time) (nth 0 timestamp))
|
|
1297 (> (nth 1 file-time) (nth 1 timestamp))))))
|
|
1298 (save-excursion
|
|
1299 (or (eq timestamp 'none)
|
|
1300 (set (intern (format "%s-active-timestamp" backend))
|
16
|
1301 ;;; dmoore@ucsd.edu 25.10.96
|
|
1302 ;;; it's not always the case that current-time
|
|
1303 ;;; does correspond to changes in the file's time. So just compare
|
|
1304 ;;; the file's new time against its own previous time.
|
|
1305 ;;; (current-time)
|
|
1306 file-time
|
|
1307 ))
|
0
|
1308 (funcall (intern (format "%s-request-list" backend)))
|
16
|
1309 ;;; dmoore@ucsd.edu 25.10.96
|
|
1310 ;;; BACKEND-request-list already does this itself!
|
|
1311 ;;; (set (intern (format "%s-group-alist" backend))
|
|
1312 ;;; (nnmail-get-active))
|
|
1313 ))
|
0
|
1314 t))
|
|
1315
|
|
1316 (defun nnmail-message-id ()
|
|
1317 (concat "<" (message-unique-id) "@totally-fudged-out-message-id>"))
|
|
1318
|
|
1319 ;;;
|
|
1320 ;;; nnmail duplicate handling
|
|
1321 ;;;
|
|
1322
|
|
1323 (defvar nnmail-cache-buffer nil)
|
|
1324
|
|
1325 (defun nnmail-cache-open ()
|
|
1326 (if (or (not nnmail-treat-duplicates)
|
|
1327 (and nnmail-cache-buffer
|
|
1328 (buffer-name nnmail-cache-buffer)))
|
|
1329 () ; The buffer is open.
|
|
1330 (save-excursion
|
|
1331 (set-buffer
|
|
1332 (setq nnmail-cache-buffer
|
|
1333 (get-buffer-create " *nnmail message-id cache*")))
|
|
1334 (buffer-disable-undo (current-buffer))
|
16
|
1335 (when (file-exists-p nnmail-message-id-cache-file)
|
|
1336 (nnheader-insert-file-contents nnmail-message-id-cache-file))
|
0
|
1337 (set-buffer-modified-p nil)
|
|
1338 (current-buffer))))
|
|
1339
|
|
1340 (defun nnmail-cache-close ()
|
|
1341 (when (and nnmail-cache-buffer
|
|
1342 nnmail-treat-duplicates
|
|
1343 (buffer-name nnmail-cache-buffer)
|
|
1344 (buffer-modified-p nnmail-cache-buffer))
|
|
1345 (save-excursion
|
|
1346 (set-buffer nnmail-cache-buffer)
|
|
1347 ;; Weed out the excess number of Message-IDs.
|
|
1348 (goto-char (point-max))
|
16
|
1349 (when (search-backward "\n" nil t nnmail-message-id-cache-length)
|
|
1350 (progn
|
|
1351 (beginning-of-line)
|
|
1352 (delete-region (point-min) (point))))
|
0
|
1353 ;; Save the buffer.
|
|
1354 (or (file-exists-p (file-name-directory nnmail-message-id-cache-file))
|
|
1355 (make-directory (file-name-directory nnmail-message-id-cache-file)
|
|
1356 t))
|
16
|
1357 (nnmail-write-region (point-min) (point-max)
|
|
1358 nnmail-message-id-cache-file nil 'silent)
|
0
|
1359 (set-buffer-modified-p nil)
|
|
1360 (setq nnmail-cache-buffer nil)
|
|
1361 ;;(kill-buffer (current-buffer))
|
|
1362 )))
|
|
1363
|
|
1364 (defun nnmail-cache-insert (id)
|
|
1365 (when nnmail-treat-duplicates
|
|
1366 (save-excursion
|
|
1367 (set-buffer nnmail-cache-buffer)
|
|
1368 (goto-char (point-max))
|
|
1369 (insert id "\n"))))
|
|
1370
|
|
1371 (defun nnmail-cache-id-exists-p (id)
|
|
1372 (when nnmail-treat-duplicates
|
|
1373 (save-excursion
|
|
1374 (set-buffer nnmail-cache-buffer)
|
|
1375 (goto-char (point-max))
|
|
1376 (search-backward id nil t))))
|
|
1377
|
16
|
1378 (defun nnmail-check-duplication (message-id func artnum-func)
|
|
1379 (run-hooks 'nnmail-prepare-incoming-message-hook)
|
0
|
1380 ;; If this is a duplicate message, then we do not save it.
|
|
1381 (let* ((duplication (nnmail-cache-id-exists-p message-id))
|
16
|
1382 (case-fold-search t)
|
0
|
1383 (action (when duplication
|
|
1384 (cond
|
|
1385 ((memq nnmail-treat-duplicates '(warn delete))
|
|
1386 nnmail-treat-duplicates)
|
|
1387 ((nnheader-functionp nnmail-treat-duplicates)
|
|
1388 (funcall nnmail-treat-duplicates message-id))
|
|
1389 (t
|
16
|
1390 nnmail-treat-duplicates))))
|
|
1391 group-art)
|
|
1392 ;; Let the backend save the article (or not).
|
0
|
1393 (cond
|
|
1394 ((not duplication)
|
|
1395 (nnmail-cache-insert message-id)
|
16
|
1396 (funcall func (setq group-art
|
|
1397 (nreverse (nnmail-article-group artnum-func)))))
|
0
|
1398 ((eq action 'delete)
|
16
|
1399 (setq group-art nil))
|
0
|
1400 ((eq action 'warn)
|
|
1401 ;; We insert a warning.
|
|
1402 (let ((case-fold-search t)
|
|
1403 (newid (nnmail-message-id)))
|
|
1404 (goto-char (point-min))
|
|
1405 (when (re-search-forward "^message-id:" nil t)
|
|
1406 (beginning-of-line)
|
|
1407 (insert "Original-"))
|
|
1408 (beginning-of-line)
|
|
1409 (insert
|
|
1410 "Message-ID: " newid "\n"
|
|
1411 "Gnus-Warning: This is a duplicate of message " message-id "\n")
|
|
1412 (nnmail-cache-insert newid)
|
16
|
1413 (funcall func (setq group-art
|
|
1414 (nreverse (nnmail-article-group artnum-func))))))
|
0
|
1415 (t
|
16
|
1416 (funcall func (setq group-art
|
|
1417 (nreverse (nnmail-article-group artnum-func))))))
|
|
1418 ;; Add the group-art list to the history list.
|
|
1419 (if group-art
|
|
1420 (push group-art nnmail-split-history)
|
|
1421 (delete-region (point-min) (point-max)))))
|
0
|
1422
|
|
1423 ;;; Get new mail.
|
|
1424
|
|
1425 (defun nnmail-get-value (&rest args)
|
|
1426 (let ((sym (intern (apply 'format args))))
|
|
1427 (when (boundp sym)
|
|
1428 (symbol-value sym))))
|
|
1429
|
|
1430 (defun nnmail-get-new-mail (method exit-func temp
|
|
1431 &optional group spool-func)
|
|
1432 "Read new incoming mail."
|
16
|
1433 ;; Nix out the previous split history.
|
|
1434 (unless group
|
|
1435 (setq nnmail-split-history nil))
|
0
|
1436 (let* ((spools (nnmail-get-spool-files group))
|
|
1437 (group-in group)
|
|
1438 incoming incomings spool)
|
|
1439 (when (and (nnmail-get-value "%s-get-new-mail" method)
|
|
1440 nnmail-spool-file)
|
|
1441 ;; We first activate all the groups.
|
|
1442 (nnmail-activate method)
|
|
1443 ;; Allow the user to hook.
|
|
1444 (run-hooks 'nnmail-pre-get-new-mail-hook)
|
|
1445 ;; Open the message-id cache.
|
|
1446 (nnmail-cache-open)
|
|
1447 ;; The we go through all the existing spool files and split the
|
|
1448 ;; mail from each.
|
|
1449 (while spools
|
|
1450 (setq spool (pop spools))
|
|
1451 ;; We read each spool file if either the spool is a POP-mail
|
|
1452 ;; spool, or the file exists. We can't check for the
|
16
|
1453 ;; existence of POPped mail.
|
0
|
1454 (when (or (string-match "^po:" spool)
|
16
|
1455 (and (file-exists-p (file-truename spool))
|
2
|
1456 (> (nnheader-file-size (file-truename spool)) 0)))
|
0
|
1457 (nnheader-message 3 "%s: Reading incoming mail..." method)
|
|
1458 (when (and (nnmail-move-inbox spool)
|
|
1459 (file-exists-p nnmail-crash-box))
|
|
1460 ;; There is new mail. We first find out if all this mail
|
|
1461 ;; is supposed to go to some specific group.
|
|
1462 (setq group (nnmail-get-split-group spool group-in))
|
|
1463 ;; We split the mail
|
|
1464 (nnmail-split-incoming
|
16
|
1465 nnmail-crash-box (intern (format "%s-save-mail" method))
|
|
1466 spool-func group (intern (format "%s-active-number" method)))
|
0
|
1467 ;; Check whether the inbox is to be moved to the special tmp dir.
|
|
1468 (setq incoming
|
|
1469 (nnmail-make-complex-temp-name
|
|
1470 (expand-file-name
|
|
1471 (if nnmail-tmp-directory
|
|
1472 (concat
|
|
1473 (file-name-as-directory nnmail-tmp-directory)
|
|
1474 (file-name-nondirectory (concat temp "Incoming")))
|
|
1475 (concat temp "Incoming")))))
|
|
1476 (rename-file nnmail-crash-box incoming t)
|
|
1477 (push incoming incomings))))
|
|
1478 ;; If we did indeed read any incoming spools, we save all info.
|
|
1479 (when incomings
|
|
1480 (nnmail-save-active
|
|
1481 (nnmail-get-value "%s-group-alist" method)
|
|
1482 (nnmail-get-value "%s-active-file" method))
|
|
1483 (when exit-func
|
|
1484 (funcall exit-func))
|
|
1485 (run-hooks 'nnmail-read-incoming-hook)
|
|
1486 (nnheader-message 3 "%s: Reading incoming mail...done" method))
|
|
1487 ;; Close the message-id cache.
|
|
1488 (nnmail-cache-close)
|
|
1489 ;; Allow the user to hook.
|
|
1490 (run-hooks 'nnmail-post-get-new-mail-hook)
|
|
1491 ;; Delete all the temporary files.
|
|
1492 (while incomings
|
|
1493 (setq incoming (pop incomings))
|
|
1494 (and nnmail-delete-incoming
|
|
1495 (file-exists-p incoming)
|
|
1496 (file-writable-p incoming)
|
|
1497 (delete-file incoming))))))
|
|
1498
|
|
1499 (defun nnmail-expired-article-p (group time force &optional inhibit)
|
|
1500 "Say whether an article that is TIME old in GROUP should be expired."
|
|
1501 (if force
|
|
1502 t
|
|
1503 (let ((days (or (and nnmail-expiry-wait-function
|
|
1504 (funcall nnmail-expiry-wait-function group))
|
|
1505 nnmail-expiry-wait)))
|
|
1506 (cond ((or (eq days 'never)
|
|
1507 (and (not force)
|
|
1508 inhibit))
|
|
1509 ;; This isn't an expirable group.
|
|
1510 nil)
|
|
1511 ((eq days 'immediate)
|
|
1512 ;; We expire all articles on sight.
|
|
1513 t)
|
|
1514 ((equal time '(0 0))
|
|
1515 ;; This is an ange-ftp group, and we don't have any dates.
|
|
1516 nil)
|
|
1517 ((numberp days)
|
|
1518 (setq days (nnmail-days-to-time days))
|
|
1519 ;; Compare the time with the current time.
|
|
1520 (nnmail-time-less days (nnmail-time-since time)))))))
|
|
1521
|
|
1522 (defvar nnmail-read-passwd nil)
|
16
|
1523 (defun nnmail-read-passwd (prompt &rest args)
|
|
1524 "Read a password using PROMPT.
|
|
1525 If ARGS, PROMPT is used as an argument to `format'."
|
|
1526 (let ((prompt
|
|
1527 (if args
|
|
1528 (apply 'format prompt args)
|
|
1529 prompt)))
|
|
1530 (unless nnmail-read-passwd
|
|
1531 (if (load "passwd" t)
|
|
1532 (setq nnmail-read-passwd 'read-passwd)
|
|
1533 (autoload 'ange-ftp-read-passwd "ange-ftp")
|
|
1534 (setq nnmail-read-passwd 'ange-ftp-read-passwd)))
|
|
1535 (funcall nnmail-read-passwd prompt)))
|
0
|
1536
|
|
1537 (defun nnmail-check-syntax ()
|
|
1538 "Check (and modify) the syntax of the message in the current buffer."
|
|
1539 (save-restriction
|
|
1540 (message-narrow-to-head)
|
|
1541 (let ((case-fold-search t))
|
16
|
1542 (unless (re-search-forward "^Message-ID:" nil t)
|
0
|
1543 (insert "Message-ID: " (nnmail-message-id) "\n")))))
|
|
1544
|
16
|
1545 (defun nnmail-write-region (start end filename &optional append visit lockname)
|
|
1546 "Do a `write-region', and then set the file modes."
|
|
1547 (write-region start end filename append visit lockname)
|
|
1548 (set-file-modes filename nnmail-default-file-modes))
|
|
1549
|
|
1550 ;;;
|
|
1551 ;;; Status functions
|
|
1552 ;;;
|
|
1553
|
|
1554 (defun nnmail-replace-status (name value)
|
|
1555 "Make status NAME and VALUE part of the current status line."
|
|
1556 (save-restriction
|
|
1557 (message-narrow-to-head)
|
|
1558 (let ((status (nnmail-decode-status)))
|
|
1559 (setq status (delq (member name status) status))
|
|
1560 (when value
|
|
1561 (push (cons name value) status))
|
|
1562 (message-remove-header "status")
|
|
1563 (goto-char (point-max))
|
|
1564 (insert "Status: " (nnmail-encode-status status) "\n"))))
|
|
1565
|
|
1566 (defun nnmail-decode-status ()
|
|
1567 "Return a status-value alist from STATUS."
|
|
1568 (goto-char (point-min))
|
|
1569 (when (re-search-forward "^Status: " nil t)
|
|
1570 (let (name value status)
|
|
1571 (save-restriction
|
|
1572 ;; Narrow to the status.
|
|
1573 (narrow-to-region
|
|
1574 (point)
|
|
1575 (if (re-search-forward "^[^ \t]" nil t)
|
|
1576 (1- (point))
|
|
1577 (point-max)))
|
|
1578 ;; Go through all elements and add them to the list.
|
|
1579 (goto-char (point-min))
|
|
1580 (while (re-search-forward "[^ \t=]+" nil t)
|
|
1581 (setq name (match-string 0))
|
|
1582 (if (not (= (following-char) ?=))
|
|
1583 ;; Implied "yes".
|
|
1584 (setq value "yes")
|
|
1585 (forward-char 1)
|
|
1586 (if (not (= (following-char) ?\"))
|
|
1587 (if (not (looking-at "[^ \t]"))
|
|
1588 ;; Implied "no".
|
|
1589 (setq value "no")
|
|
1590 ;; Unquoted value.
|
|
1591 (setq value (match-string 0))
|
|
1592 (goto-char (match-end 0)))
|
|
1593 ;; Quoted value.
|
|
1594 (setq value (read (current-buffer)))))
|
|
1595 (push (cons name value) status)))
|
|
1596 status)))
|
|
1597
|
|
1598 (defun nnmail-encode-status (status)
|
|
1599 "Return a status string from STATUS."
|
|
1600 (mapconcat
|
|
1601 (lambda (elem)
|
|
1602 (concat
|
|
1603 (car elem) "="
|
|
1604 (if (string-match "[ \t]" (cdr elem))
|
|
1605 (prin1-to-string (cdr elem))
|
|
1606 (cdr elem))))
|
|
1607 status " "))
|
|
1608
|
|
1609 (defun nnmail-split-history ()
|
|
1610 "Generate an overview of where the last mail split put articles."
|
|
1611 (interactive)
|
|
1612 (unless nnmail-split-history
|
|
1613 (error "No current split history"))
|
|
1614 (with-output-to-temp-buffer "*nnmail split history*"
|
|
1615 (let ((history nnmail-split-history)
|
|
1616 elem)
|
|
1617 (while (setq elem (pop history))
|
|
1618 (princ (mapconcat (lambda (ga)
|
|
1619 (concat (car ga) ":" (int-to-string (cdr ga))))
|
|
1620 elem
|
|
1621 ", "))
|
|
1622 (princ "\n")))))
|
|
1623
|
|
1624 (defun nnmail-new-mail-p (group)
|
|
1625 "Say whether GROUP has new mail."
|
|
1626 (let ((his nnmail-split-history)
|
|
1627 found)
|
|
1628 (while his
|
|
1629 (when (assoc group (pop his))
|
|
1630 (setq found t
|
|
1631 his nil)))
|
|
1632 found))
|
|
1633
|
0
|
1634 (run-hooks 'nnmail-load-hook)
|
|
1635
|
|
1636 (provide 'nnmail)
|
|
1637
|
|
1638 ;;; nnmail.el ends here
|