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