Mercurial > emacs
annotate lisp/gnus/mail-source.el @ 80301:6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
default to nil.
(mail-source-delete-old-incoming): Make confirmation prompt more clear.
author | Reiner Steib <Reiner.Steib@gmx.de> |
---|---|
date | Sat, 08 Mar 2008 12:06:58 +0000 |
parents | 639e83cd103d |
children | 07ebd0fc42b8 |
rev | line source |
---|---|
31717 | 1 ;;; mail-source.el --- functions for fetching mail |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
79708 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
7 ;; Keywords: news, mail | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77959
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
31717 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
31717 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
32918 | 30 (eval-when-compile |
31 (require 'cl) | |
32 (require 'imap) | |
33 (eval-when-compile (defvar display-time-mail-function))) | |
31717 | 34 (eval-and-compile |
35 (autoload 'pop3-movemail "pop3") | |
32918 | 36 (autoload 'pop3-get-message-count "pop3") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
37 (autoload 'nnheader-cancel-timer "nnheader") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
38 (autoload 'nnheader-run-at-time "nnheader")) |
31717 | 39 (require 'format-spec) |
32918 | 40 (require 'mm-util) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
41 (require 'message) ;; for `message-directory' |
31717 | 42 |
43 (defgroup mail-source nil | |
44 "The mail-fetching library." | |
31764 | 45 :version "21.1" |
31717 | 46 :group 'gnus) |
47 | |
32918 | 48 ;; Define these at compile time to avoid dragging in imap always. |
49 (defconst mail-source-imap-authenticators | |
50 (eval-when-compile | |
51 (mapcar (lambda (a) | |
52 (list 'const (car a))) | |
53 imap-authenticator-alist))) | |
54 (defconst mail-source-imap-streams | |
55 (eval-when-compile | |
56 (mapcar (lambda (a) | |
57 (list 'const (car a))) | |
58 imap-stream-alist))) | |
59 | |
32102 | 60 (defcustom mail-sources nil |
31717 | 61 "*Where the mail backends will look for incoming mail. |
31764 | 62 This variable is a list of mail source specifiers. |
63 See Info node `(gnus)Mail Source Specifiers'." | |
31717 | 64 :group 'mail-source |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
65 :link '(custom-manual "(gnus)Mail Source Specifiers") |
71262 | 66 :type `(choice |
67 (const nil) | |
68 (repeat | |
69 (choice :format "%[Value Menu%] %v" | |
70 :value (file) | |
71 (cons :tag "Spool file" | |
72 (const :format "" file) | |
73 (checklist :tag "Options" :greedy t | |
74 (group :inline t | |
75 (const :format "" :value :path) | |
76 file))) | |
77 (cons :tag "Several files in a directory" | |
78 (const :format "" directory) | |
79 (checklist :tag "Options" :greedy t | |
80 (group :inline t | |
81 (const :format "" :value :path) | |
82 (directory :tag "Path")) | |
83 (group :inline t | |
84 (const :format "" :value :suffix) | |
85 (string :tag "Suffix")) | |
86 (group :inline t | |
87 (const :format "" :value :predicate) | |
88 (function :tag "Predicate")) | |
89 (group :inline t | |
90 (const :format "" :value :prescript) | |
91 (choice :tag "Prescript" | |
92 :value nil | |
93 (string :format "%v") | |
94 (function :format "%v"))) | |
95 (group :inline t | |
96 (const :format "" :value :postscript) | |
97 (choice :tag "Postscript" | |
98 :value nil | |
99 (string :format "%v") | |
100 (function :format "%v"))) | |
101 (group :inline t | |
102 (const :format "" :value :plugged) | |
103 (boolean :tag "Plugged")))) | |
104 (cons :tag "POP3 server" | |
105 (const :format "" pop) | |
106 (checklist :tag "Options" :greedy t | |
107 (group :inline t | |
108 (const :format "" :value :server) | |
109 (string :tag "Server")) | |
110 (group :inline t | |
111 (const :format "" :value :port) | |
112 (choice :tag "Port" | |
113 :value "pop3" | |
114 (number :format "%v") | |
115 (string :format "%v"))) | |
116 (group :inline t | |
117 (const :format "" :value :user) | |
118 (string :tag "User")) | |
119 (group :inline t | |
120 (const :format "" :value :password) | |
121 (string :tag "Password")) | |
122 (group :inline t | |
123 (const :format "" :value :program) | |
124 (string :tag "Program")) | |
125 (group :inline t | |
126 (const :format "" :value :prescript) | |
127 (choice :tag "Prescript" | |
128 :value nil | |
129 (string :format "%v") | |
130 (function :format "%v"))) | |
131 (group :inline t | |
132 (const :format "" :value :postscript) | |
133 (choice :tag "Postscript" | |
134 :value nil | |
135 (string :format "%v") | |
136 (function :format "%v"))) | |
137 (group :inline t | |
138 (const :format "" :value :function) | |
139 (function :tag "Function")) | |
140 (group :inline t | |
141 (const :format "" | |
142 :value :authentication) | |
143 (choice :tag "Authentication" | |
144 :value apop | |
145 (const password) | |
146 (const apop))) | |
147 (group :inline t | |
148 (const :format "" :value :plugged) | |
149 (boolean :tag "Plugged")))) | |
150 (cons :tag "Maildir (qmail, postfix...)" | |
151 (const :format "" maildir) | |
152 (checklist :tag "Options" :greedy t | |
153 (group :inline t | |
154 (const :format "" :value :path) | |
155 (directory :tag "Path")) | |
156 (group :inline t | |
157 (const :format "" :value :plugged) | |
158 (boolean :tag "Plugged")))) | |
159 (cons :tag "IMAP server" | |
160 (const :format "" imap) | |
161 (checklist :tag "Options" :greedy t | |
162 (group :inline t | |
163 (const :format "" :value :server) | |
164 (string :tag "Server")) | |
165 (group :inline t | |
166 (const :format "" :value :port) | |
167 (choice :tag "Port" | |
168 :value 143 | |
169 number string)) | |
170 (group :inline t | |
171 (const :format "" :value :user) | |
172 (string :tag "User")) | |
173 (group :inline t | |
174 (const :format "" :value :password) | |
175 (string :tag "Password")) | |
176 (group :inline t | |
177 (const :format "" :value :stream) | |
178 (choice :tag "Stream" | |
179 :value network | |
180 ,@mail-source-imap-streams)) | |
181 (group :inline t | |
182 (const :format "" :value :program) | |
183 (string :tag "Program")) | |
184 (group :inline t | |
185 (const :format "" | |
186 :value :authenticator) | |
187 (choice :tag "Authenticator" | |
188 :value login | |
189 ,@mail-source-imap-authenticators)) | |
190 (group :inline t | |
191 (const :format "" :value :mailbox) | |
192 (string :tag "Mailbox" | |
193 :value "INBOX")) | |
194 (group :inline t | |
195 (const :format "" :value :predicate) | |
196 (string :tag "Predicate" | |
197 :value "UNSEEN UNDELETED")) | |
198 (group :inline t | |
199 (const :format "" :value :fetchflag) | |
200 (string :tag "Fetchflag" | |
201 :value "\\Deleted")) | |
202 (group :inline t | |
203 (const :format "" | |
204 :value :dontexpunge) | |
205 (boolean :tag "Dontexpunge")) | |
206 (group :inline t | |
207 (const :format "" :value :plugged) | |
208 (boolean :tag "Plugged")))) | |
209 (cons :tag "Webmail server" | |
210 (const :format "" webmail) | |
211 (checklist :tag "Options" :greedy t | |
212 (group :inline t | |
213 (const :format "" :value :subtype) | |
214 ;; Should be generated from | |
215 ;; `webmail-type-definition', but we | |
216 ;; can't require webmail without W3. | |
217 (choice :tag "Subtype" | |
218 :value hotmail | |
219 (const hotmail) | |
220 (const yahoo) | |
221 (const netaddress) | |
222 (const netscape) | |
223 (const my-deja))) | |
224 (group :inline t | |
225 (const :format "" :value :user) | |
226 (string :tag "User")) | |
227 (group :inline t | |
228 (const :format "" :value :password) | |
229 (string :tag "Password")) | |
230 (group :inline t | |
231 (const :format "" | |
232 :value :dontexpunge) | |
233 (boolean :tag "Dontexpunge")) | |
234 (group :inline t | |
235 (const :format "" :value :plugged) | |
236 (boolean :tag "Plugged")))))))) | |
31717 | 237 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
238 (defcustom mail-source-ignore-errors nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
239 "*Ignore errors when querying mail sources. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
240 If nil, the user will be prompted when an error occurs. If non-nil, |
57153
497f0d2ca551
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-558
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
241 the error will be ignored." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57581
diff
changeset
|
242 :version "22.1" |
57153
497f0d2ca551
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-558
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
243 :group 'mail-source |
497f0d2ca551
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-558
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
244 :type 'boolean) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
245 |
31717 | 246 (defcustom mail-source-primary-source nil |
247 "*Primary source for incoming mail. | |
248 If non-nil, this maildrop will be checked periodically for new mail." | |
249 :group 'mail-source | |
250 :type 'sexp) | |
251 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
252 (defcustom mail-source-flash t |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
253 "*If non-nil, flash periodically when mail is available." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
254 :group 'mail-source |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
255 :type 'boolean) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
256 |
31717 | 257 (defcustom mail-source-crash-box "~/.emacs-mail-crash-box" |
258 "File where mail will be stored while processing it." | |
259 :group 'mail-source | |
260 :type 'file) | |
261 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
262 (defcustom mail-source-directory message-directory |
57581
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
263 "Directory where incoming mail source files (if any) will be stored." |
31717 | 264 :group 'mail-source |
265 :type 'directory) | |
266 | |
267 (defcustom mail-source-default-file-modes 384 | |
268 "Set the mode bits of all new mail files to this integer." | |
269 :group 'mail-source | |
270 :type 'integer) | |
271 | |
80192 | 272 (defcustom mail-source-delete-incoming |
273 ;; 10 ;; development versions | |
274 2 ;; released versions | |
275 "If non-nil, delete incoming files after handling. | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
276 If t, delete immediately, if nil, never delete. If a positive number, delete |
80192 | 277 files older than number of days. |
278 | |
279 Removing of old files happens in `mail-source-callback', i.e. no | |
280 old incoming files will be deleted unless you receive new mail. | |
281 You may also set this variable to nil and call | |
282 `mail-source-delete-old-incoming' interactively." | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
283 :group 'mail-source |
80192 | 284 :version "22.2" ;; No Gnus / Gnus 5.10.10 (default changed) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
285 :type '(choice (const :tag "immediately" t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
286 (const :tag "never" nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
287 (integer :tag "days"))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
288 |
80301
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
289 (defcustom mail-source-delete-old-incoming-confirm nil |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
290 "If non-nil, ask for confirmation before deleting old incoming files. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
291 This variable only applies when `mail-source-delete-incoming' is a positive |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
292 number." |
80301
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
293 :version "22.2" ;; No Gnus / Gnus 5.10.10 (default changed) |
31717 | 294 :group 'mail-source |
295 :type 'boolean) | |
296 | |
297 (defcustom mail-source-incoming-file-prefix "Incoming" | |
298 "Prefix for file name for storing incoming mail" | |
299 :group 'mail-source | |
300 :type 'string) | |
301 | |
302 (defcustom mail-source-report-new-mail-interval 5 | |
303 "Interval in minutes between checks for new mail." | |
304 :group 'mail-source | |
305 :type 'number) | |
306 | |
307 (defcustom mail-source-idle-time-delay 5 | |
308 "Number of idle seconds to wait before checking for new mail." | |
309 :group 'mail-source | |
310 :type 'number) | |
311 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
312 (defcustom mail-source-movemail-program nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
313 "If non-nil, name of program for fetching new mail." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57581
diff
changeset
|
314 :version "22.1" |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
315 :group 'mail-source |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
316 :type '(choice (const nil) string)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
317 |
31717 | 318 ;;; Internal variables. |
319 | |
320 (defvar mail-source-string "" | |
321 "A dynamically bound string that says what the current mail source is.") | |
322 | |
323 (defvar mail-source-new-mail-available nil | |
324 "Flag indicating when new mail is available.") | |
325 | |
326 (eval-and-compile | |
327 (defvar mail-source-common-keyword-map | |
328 '((:plugged)) | |
329 "Mapping from keywords to default values. | |
330 Common keywords should be listed here.") | |
331 | |
332 (defvar mail-source-keyword-map | |
333 '((file | |
334 (:prescript) | |
335 (:prescript-delay) | |
336 (:postscript) | |
337 (:path (or (getenv "MAIL") | |
32918 | 338 (expand-file-name (user-login-name) rmail-spool-directory)))) |
31717 | 339 (directory |
43422
fa370bd262ee
Patched a wrong location.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
43421
diff
changeset
|
340 (:prescript) |
fa370bd262ee
Patched a wrong location.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
43421
diff
changeset
|
341 (:prescript-delay) |
fa370bd262ee
Patched a wrong location.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
43421
diff
changeset
|
342 (:postscript) |
31717 | 343 (:path) |
344 (:suffix ".spool") | |
345 (:predicate identity)) | |
346 (pop | |
347 (:prescript) | |
348 (:prescript-delay) | |
349 (:postscript) | |
350 (:server (getenv "MAILHOST")) | |
351 (:port 110) | |
352 (:user (or (user-login-name) (getenv "LOGNAME") (getenv "USER"))) | |
353 (:program) | |
354 (:function) | |
355 (:password) | |
356 (:authentication password)) | |
357 (maildir | |
358 (:path (or (getenv "MAILDIR") "~/Maildir/")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
359 (:subdirs ("cur" "new")) |
31717 | 360 (:function)) |
361 (imap | |
362 (:server (getenv "MAILHOST")) | |
363 (:port) | |
364 (:stream) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
365 (:program) |
31717 | 366 (:authentication) |
367 (:user (or (user-login-name) (getenv "LOGNAME") (getenv "USER"))) | |
368 (:password) | |
369 (:mailbox "INBOX") | |
370 (:predicate "UNSEEN UNDELETED") | |
371 (:fetchflag "\\Deleted") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
372 (:prescript) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
373 (:prescript-delay) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
374 (:postscript) |
31717 | 375 (:dontexpunge)) |
376 (webmail | |
377 (:subtype hotmail) | |
378 (:user (or (user-login-name) (getenv "LOGNAME") (getenv "USER"))) | |
379 (:password) | |
380 (:dontexpunge) | |
381 (:authentication password))) | |
382 "Mapping from keywords to default values. | |
383 All keywords that can be used must be listed here.")) | |
384 | |
385 (defvar mail-source-fetcher-alist | |
386 '((file mail-source-fetch-file) | |
387 (directory mail-source-fetch-directory) | |
388 (pop mail-source-fetch-pop) | |
389 (maildir mail-source-fetch-maildir) | |
390 (imap mail-source-fetch-imap) | |
391 (webmail mail-source-fetch-webmail)) | |
392 "A mapping from source type to fetcher function.") | |
393 | |
394 (defvar mail-source-password-cache nil) | |
395 | |
396 (defvar mail-source-plugged t) | |
397 | |
398 ;;; Functions | |
399 | |
400 (eval-and-compile | |
401 (defun mail-source-strip-keyword (keyword) | |
402 "Strip the leading colon off the KEYWORD." | |
403 (intern (substring (symbol-name keyword) 1)))) | |
404 | |
405 (eval-and-compile | |
406 (defun mail-source-bind-1 (type) | |
407 (let* ((defaults (cdr (assq type mail-source-keyword-map))) | |
408 default bind) | |
409 (while (setq default (pop defaults)) | |
410 (push (list (mail-source-strip-keyword (car default)) | |
411 nil) | |
412 bind)) | |
413 bind))) | |
414 | |
415 (defmacro mail-source-bind (type-source &rest body) | |
416 "Return a `let' form that binds all variables in source TYPE. | |
417 TYPE-SOURCE is a list where the first element is the TYPE, and | |
418 the second variable is the SOURCE. | |
419 At run time, the mail source specifier SOURCE will be inspected, | |
420 and the variables will be set according to it. Variables not | |
421 specified will be given default values. | |
422 | |
423 After this is done, BODY will be executed in the scope | |
424 of the `let' form. | |
425 | |
426 The variables bound and their default values are described by | |
427 the `mail-source-keyword-map' variable." | |
428 `(let ,(mail-source-bind-1 (car type-source)) | |
429 (mail-source-set-1 ,(cadr type-source)) | |
430 ,@body)) | |
431 | |
432 (put 'mail-source-bind 'lisp-indent-function 1) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
433 (put 'mail-source-bind 'edebug-form-spec '(sexp body)) |
31717 | 434 |
435 (defun mail-source-set-1 (source) | |
436 (let* ((type (pop source)) | |
437 (defaults (cdr (assq type mail-source-keyword-map))) | |
438 default value keyword) | |
439 (while (setq default (pop defaults)) | |
440 (set (mail-source-strip-keyword (setq keyword (car default))) | |
441 (if (setq value (plist-get source keyword)) | |
442 (mail-source-value value) | |
443 (mail-source-value (cadr default))))))) | |
444 | |
445 (eval-and-compile | |
446 (defun mail-source-bind-common-1 () | |
447 (let* ((defaults mail-source-common-keyword-map) | |
448 default bind) | |
449 (while (setq default (pop defaults)) | |
450 (push (list (mail-source-strip-keyword (car default)) | |
451 nil) | |
452 bind)) | |
453 bind))) | |
454 | |
455 (defun mail-source-set-common-1 (source) | |
456 (let* ((type (pop source)) | |
457 (defaults mail-source-common-keyword-map) | |
458 (defaults-1 (cdr (assq type mail-source-keyword-map))) | |
459 default value keyword) | |
460 (while (setq default (pop defaults)) | |
461 (set (mail-source-strip-keyword (setq keyword (car default))) | |
462 (if (setq value (plist-get source keyword)) | |
463 (mail-source-value value) | |
464 (if (setq value (assq keyword defaults-1)) | |
465 (mail-source-value (cadr value)) | |
466 (mail-source-value (cadr default)))))))) | |
467 | |
468 (defmacro mail-source-bind-common (source &rest body) | |
469 "Return a `let' form that binds all common variables. | |
470 See `mail-source-bind'." | |
471 `(let ,(mail-source-bind-common-1) | |
472 (mail-source-set-common-1 source) | |
473 ,@body)) | |
474 | |
475 (put 'mail-source-bind-common 'lisp-indent-function 1) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
476 (put 'mail-source-bind-common 'edebug-form-spec '(sexp body)) |
31717 | 477 |
478 (defun mail-source-value (value) | |
479 "Return the value of VALUE." | |
480 (cond | |
481 ;; String | |
482 ((stringp value) | |
483 value) | |
484 ;; Function | |
485 ((and (listp value) | |
486 (functionp (car value))) | |
487 (eval value)) | |
488 ;; Just return the value. | |
489 (t | |
490 value))) | |
491 | |
492 (defun mail-source-fetch (source callback) | |
493 "Fetch mail from SOURCE and call CALLBACK zero or more times. | |
494 CALLBACK will be called with the name of the file where (some of) | |
495 the mail from SOURCE is put. | |
496 Return the number of files that were found." | |
497 (mail-source-bind-common source | |
498 (if (or mail-source-plugged plugged) | |
499 (save-excursion | |
500 (let ((function (cadr (assq (car source) mail-source-fetcher-alist))) | |
501 (found 0)) | |
502 (unless function | |
503 (error "%S is an invalid mail source specification" source)) | |
504 ;; If there's anything in the crash box, we do it first. | |
505 (when (file-exists-p mail-source-crash-box) | |
506 (message "Processing mail from %s..." mail-source-crash-box) | |
507 (setq found (mail-source-callback | |
508 callback mail-source-crash-box))) | |
509 (+ found | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
510 (if (or debug-on-quit debug-on-error) |
31717 | 511 (funcall function source callback) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
512 (condition-case err |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
513 (funcall function source callback) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
514 (error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
515 (if (and (not mail-source-ignore-errors) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
516 (not |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
517 (yes-or-no-p |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
518 (format "Mail source %s error (%s). Continue? " |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
519 (if (memq ':password source) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
520 (let ((s (copy-sequence source))) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57581
diff
changeset
|
521 (setcar (cdr (memq ':password s)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
522 "********") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
523 s) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
524 source) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
525 (cadr err))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
526 (error "Cannot get new mail")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
527 0))))))))) |
31717 | 528 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
529 (defun mail-source-delete-old-incoming (&optional age confirm) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
530 "Remove incoming files older than AGE days. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
531 If CONFIRM is non-nil, ask for confirmation before removing a file." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
532 (interactive "P") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
533 (let* ((high2days (/ 65536.0 60 60 24));; convert high bits to days |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
534 (low2days (/ 1.0 65536.0)) ;; convert low bits to days |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
535 (diff (if (natnump age) age 30));; fallback, if no valid AGE given |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
536 currday files) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
537 (setq files (directory-files |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
538 mail-source-directory t |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
539 (concat mail-source-incoming-file-prefix "*")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
540 currday (* (car (current-time)) high2days) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
541 currday (+ currday (* low2days (nth 1 (current-time))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
542 (while files |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
543 (let* ((ffile (car files)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
544 (bfile (gnus-replace-in-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
545 ffile "\\`.*/\\([^/]+\\)\\'" "\\1")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
546 (filetime (nth 5 (file-attributes ffile))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
547 (fileday (* (car filetime) high2days)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
548 (fileday (+ fileday (* low2days (nth 1 filetime))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
549 (setq files (cdr files)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
550 (when (and (> (- currday fileday) diff) |
80301
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
551 (if confirm |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
552 (y-or-n-p |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
553 (format "\ |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
554 Delete old (> %s day(s)) incoming mail file `%s'? " diff bfile)) |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
555 (gnus-message 8 "\ |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
556 Deleting old (> %s day(s)) incoming mail file `%s'." diff bfile) |
6bd4639256ce
(mail-source-delete-old-incoming-confirm): Change
Reiner Steib <Reiner.Steib@gmx.de>
parents:
80192
diff
changeset
|
557 t)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
558 (delete-file ffile)))))) |
31717 | 559 |
560 (defun mail-source-callback (callback info) | |
561 "Call CALLBACK on the mail file, and then remove the mail file. | |
562 Pass INFO on to CALLBACK." | |
563 (if (or (not (file-exists-p mail-source-crash-box)) | |
564 (zerop (nth 7 (file-attributes mail-source-crash-box)))) | |
565 (progn | |
566 (when (file-exists-p mail-source-crash-box) | |
567 (delete-file mail-source-crash-box)) | |
568 0) | |
569 (prog1 | |
570 (funcall callback mail-source-crash-box info) | |
571 (when (file-exists-p mail-source-crash-box) | |
572 ;; Delete or move the incoming mail out of the way. | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
573 (if (eq mail-source-delete-incoming t) |
31717 | 574 (delete-file mail-source-crash-box) |
575 (let ((incoming | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
576 (mm-make-temp-file |
31717 | 577 (expand-file-name |
578 mail-source-incoming-file-prefix | |
579 mail-source-directory)))) | |
580 (unless (file-exists-p (file-name-directory incoming)) | |
581 (make-directory (file-name-directory incoming) t)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
582 (rename-file mail-source-crash-box incoming t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
583 ;; remove old incoming files? |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
584 (when (natnump mail-source-delete-incoming) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
585 (mail-source-delete-old-incoming |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
586 mail-source-delete-incoming |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
587 mail-source-delete-old-incoming-confirm)))))))) |
31717 | 588 |
589 (defun mail-source-movemail (from to) | |
590 "Move FROM to TO using movemail." | |
591 (if (not (file-writable-p to)) | |
592 (error "Can't write to crash box %s. Not moving mail" to) | |
593 (let ((to (file-truename (expand-file-name to))) | |
594 errors result) | |
595 (setq to (file-truename to) | |
596 from (file-truename from)) | |
597 ;; Set TO if have not already done so, and rename or copy | |
598 ;; the file FROM to TO if and as appropriate. | |
599 (cond | |
600 ((file-exists-p to) | |
601 ;; The crash box exists already. | |
602 t) | |
603 ((not (file-exists-p from)) | |
604 ;; There is no inbox. | |
605 (setq to nil)) | |
606 ((zerop (nth 7 (file-attributes from))) | |
607 ;; Empty file. | |
608 (setq to 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 " *mail source loss*")) | |
616 (let ((default-directory "/")) | |
617 (setq result | |
618 (apply | |
619 'call-process | |
620 (append | |
621 (list | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
622 (or mail-source-movemail-program |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
623 (expand-file-name "movemail" exec-directory)) |
31717 | 624 nil errors nil from to))))) |
625 (when (file-exists-p to) | |
626 (set-file-modes to mail-source-default-file-modes)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
627 (if (and (or (not (buffer-modified-p errors)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
628 (zerop (buffer-size errors))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
629 (and (numberp result) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
630 (zerop result))) |
31717 | 631 ;; No output => movemail won. |
632 t | |
633 (set-buffer errors) | |
634 ;; There may be a warning about older revisions. We | |
635 ;; ignore that. | |
636 (goto-char (point-min)) | |
637 (if (search-forward "older revision" nil t) | |
638 t | |
639 ;; Probably a real error. | |
640 (subst-char-in-region (point-min) (point-max) ?\n ?\ ) | |
641 (goto-char (point-max)) | |
642 (skip-chars-backward " \t") | |
643 (delete-region (point) (point-max)) | |
644 (goto-char (point-min)) | |
645 (when (looking-at "movemail: ") | |
646 (delete-region (point-min) (match-end 0))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
647 ;; Result may be a signal description string. |
31717 | 648 (unless (yes-or-no-p |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
649 (format "movemail: %s (%s return). Continue? " |
31717 | 650 (buffer-string) result)) |
651 (error "%s" (buffer-string))) | |
652 (setq to nil))))))) | |
653 (when (and errors | |
654 (buffer-name errors)) | |
655 (kill-buffer errors)) | |
656 ;; Return whether we moved successfully or not. | |
657 to))) | |
658 | |
659 (defun mail-source-movemail-and-remove (from to) | |
660 "Move FROM to TO using movemail, then remove FROM if empty." | |
661 (or (not (mail-source-movemail from to)) | |
662 (not (zerop (nth 7 (file-attributes from)))) | |
663 (delete-file from))) | |
664 | |
665 (defun mail-source-fetch-with-program (program) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
666 (eq 0 (call-process shell-file-name nil nil nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
667 shell-command-switch program))) |
31717 | 668 |
669 (defun mail-source-run-script (script spec &optional delay) | |
670 (when script | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
671 (if (functionp script) |
31717 | 672 (funcall script) |
673 (mail-source-call-script | |
674 (format-spec script spec)))) | |
675 (when delay | |
676 (sleep-for delay))) | |
677 | |
678 (defun mail-source-call-script (script) | |
679 (let ((background nil)) | |
680 (when (string-match "& *$" script) | |
681 (setq script (substring script 0 (match-beginning 0)) | |
682 background 0)) | |
683 (call-process shell-file-name nil background nil | |
684 shell-command-switch script))) | |
685 | |
686 ;;; | |
687 ;;; Different fetchers | |
688 ;;; | |
689 | |
690 (defun mail-source-fetch-file (source callback) | |
691 "Fetcher for single-file sources." | |
692 (mail-source-bind (file source) | |
693 (mail-source-run-script | |
694 prescript (format-spec-make ?t mail-source-crash-box) | |
695 prescript-delay) | |
696 (let ((mail-source-string (format "file:%s" path))) | |
697 (if (mail-source-movemail path mail-source-crash-box) | |
698 (prog1 | |
699 (mail-source-callback callback path) | |
700 (mail-source-run-script | |
701 postscript (format-spec-make ?t mail-source-crash-box))) | |
702 0)))) | |
703 | |
704 (defun mail-source-fetch-directory (source callback) | |
705 "Fetcher for directory sources." | |
706 (mail-source-bind (directory source) | |
43421
a949c187ce13
* mail-source.el (mail-source-fetch-directory): Run scripts.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
38413
diff
changeset
|
707 (mail-source-run-script |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
708 prescript (format-spec-make ?t path) prescript-delay) |
31717 | 709 (let ((found 0) |
710 (mail-source-string (format "directory:%s" path))) | |
711 (dolist (file (directory-files | |
712 path t (concat (regexp-quote suffix) "$"))) | |
713 (when (and (file-regular-p file) | |
714 (funcall predicate file) | |
715 (mail-source-movemail file mail-source-crash-box)) | |
716 (incf found (mail-source-callback callback file)))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
717 (mail-source-run-script postscript (format-spec-make ?t path)) |
31717 | 718 found))) |
719 | |
720 (defun mail-source-fetch-pop (source callback) | |
721 "Fetcher for single-file sources." | |
722 (mail-source-bind (pop source) | |
723 (mail-source-run-script | |
724 prescript | |
725 (format-spec-make ?p password ?t mail-source-crash-box | |
726 ?s server ?P port ?u user) | |
727 prescript-delay) | |
728 (let ((from (format "%s:%s:%s" server user port)) | |
729 (mail-source-string (format "pop:%s@%s" user server)) | |
730 result) | |
731 (when (eq authentication 'password) | |
732 (setq password | |
733 (or password | |
734 (cdr (assoc from mail-source-password-cache)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
735 (read-passwd |
31717 | 736 (format "Password for %s at %s: " user server))))) |
737 (when server | |
738 (setenv "MAILHOST" server)) | |
739 (setq result | |
740 (cond | |
741 (program | |
742 (mail-source-fetch-with-program | |
743 (format-spec | |
744 program | |
745 (format-spec-make ?p password ?t mail-source-crash-box | |
746 ?s server ?P port ?u user)))) | |
747 (function | |
748 (funcall function mail-source-crash-box)) | |
749 ;; The default is to use pop3.el. | |
750 (t | |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
751 (require 'pop3) |
31717 | 752 (let ((pop3-password password) |
753 (pop3-maildrop user) | |
754 (pop3-mailhost server) | |
755 (pop3-port port) | |
756 (pop3-authentication-scheme | |
757 (if (eq authentication 'apop) 'apop 'pass))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
758 (if (or debug-on-quit debug-on-error) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
759 (save-excursion (pop3-movemail mail-source-crash-box)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
760 (condition-case err |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
761 (save-excursion (pop3-movemail mail-source-crash-box)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
762 (error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
763 ;; We nix out the password in case the error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
764 ;; was because of a wrong password being given. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
765 (setq mail-source-password-cache |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
766 (delq (assoc from mail-source-password-cache) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
767 mail-source-password-cache)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
768 (signal (car err) (cdr err))))))))) |
31717 | 769 (if result |
770 (progn | |
771 (when (eq authentication 'password) | |
772 (unless (assoc from mail-source-password-cache) | |
773 (push (cons from password) mail-source-password-cache))) | |
774 (prog1 | |
775 (mail-source-callback callback server) | |
776 ;; Update display-time's mail flag, if relevant. | |
777 (if (equal source mail-source-primary-source) | |
778 (setq mail-source-new-mail-available nil)) | |
779 (mail-source-run-script | |
780 postscript | |
781 (format-spec-make ?p password ?t mail-source-crash-box | |
782 ?s server ?P port ?u user)))) | |
783 ;; We nix out the password in case the error | |
784 ;; was because of a wrong password being given. | |
785 (setq mail-source-password-cache | |
786 (delq (assoc from mail-source-password-cache) | |
787 mail-source-password-cache)) | |
788 0)))) | |
789 | |
790 (defun mail-source-check-pop (source) | |
791 "Check whether there is new mail." | |
792 (mail-source-bind (pop source) | |
793 (let ((from (format "%s:%s:%s" server user port)) | |
794 (mail-source-string (format "pop:%s@%s" user server)) | |
795 result) | |
796 (when (eq authentication 'password) | |
797 (setq password | |
798 (or password | |
799 (cdr (assoc from mail-source-password-cache)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
800 (read-passwd |
31717 | 801 (format "Password for %s at %s: " user server)))) |
802 (unless (assoc from mail-source-password-cache) | |
803 (push (cons from password) mail-source-password-cache))) | |
804 (when server | |
805 (setenv "MAILHOST" server)) | |
806 (setq result | |
807 (cond | |
808 ;; No easy way to check whether mail is waiting for these. | |
809 (program) | |
810 (function) | |
811 ;; The default is to use pop3.el. | |
812 (t | |
66299
01b85ec4a61d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
813 (require 'pop3) |
31717 | 814 (let ((pop3-password password) |
815 (pop3-maildrop user) | |
816 (pop3-mailhost server) | |
817 (pop3-port port) | |
818 (pop3-authentication-scheme | |
819 (if (eq authentication 'apop) 'apop 'pass))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
820 (if (or debug-on-quit debug-on-error) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
821 (save-excursion (pop3-get-message-count)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
822 (condition-case err |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
823 (save-excursion (pop3-get-message-count)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
824 (error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
825 ;; We nix out the password in case the error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
826 ;; was because of a wrong password being given. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
827 (setq mail-source-password-cache |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
828 (delq (assoc from mail-source-password-cache) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
829 mail-source-password-cache)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
830 (signal (car err) (cdr err))))))))) |
31717 | 831 (if result |
832 ;; Inform display-time that we have new mail. | |
833 (setq mail-source-new-mail-available (> result 0)) | |
834 ;; We nix out the password in case the error | |
835 ;; was because of a wrong password being given. | |
836 (setq mail-source-password-cache | |
837 (delq (assoc from mail-source-password-cache) | |
838 mail-source-password-cache))) | |
839 result))) | |
840 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
841 (defun mail-source-touch-pop () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
842 "Open and close a POP connection shortly. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
843 POP server should be defined in `mail-source-primary-source' (which is |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
844 preferred) or `mail-sources'. You may use it for the POP-before-SMTP |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
845 authentication. To do that, you need to set the |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
846 `message-send-mail-function' variable as `message-smtpmail-send-it' |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
847 and put the following line in your ~/.gnus.el file: |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
848 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
849 \(add-hook 'message-send-mail-hook 'mail-source-touch-pop) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
850 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
851 See the Gnus manual for details." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
852 (let ((sources (if mail-source-primary-source |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
853 (list mail-source-primary-source) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
854 mail-sources))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
855 (while sources |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
856 (if (eq 'pop (car (car sources))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
857 (mail-source-check-pop (car sources))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
858 (setq sources (cdr sources))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
859 |
31717 | 860 (defun mail-source-new-mail-p () |
861 "Handler for `display-time' to indicate when new mail is available." | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
862 ;; Flash (ie. ring the visible bell) if mail is available. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
863 (if (and mail-source-flash mail-source-new-mail-available) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
864 (let ((visible-bell t)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
865 (ding))) |
31717 | 866 ;; Only report flag setting; flag is updated on a different schedule. |
867 mail-source-new-mail-available) | |
868 | |
869 | |
870 (defvar mail-source-report-new-mail nil) | |
871 (defvar mail-source-report-new-mail-timer nil) | |
872 (defvar mail-source-report-new-mail-idle-timer nil) | |
873 | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
874 (eval-when-compile |
32333 | 875 (if (featurep 'xemacs) |
60696
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
876 (require 'timer-funcs) |
32333 | 877 (require 'timer))) |
31717 | 878 |
879 (defun mail-source-start-idle-timer () | |
880 ;; Start our idle timer if necessary, so we delay the check until the | |
881 ;; user isn't typing. | |
882 (unless mail-source-report-new-mail-idle-timer | |
883 (setq mail-source-report-new-mail-idle-timer | |
884 (run-with-idle-timer | |
885 mail-source-idle-time-delay | |
886 nil | |
887 (lambda () | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
888 (unwind-protect |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
889 (mail-source-check-pop mail-source-primary-source) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
890 (setq mail-source-report-new-mail-idle-timer nil))))) |
31717 | 891 ;; Since idle timers created when Emacs is already in the idle |
892 ;; state don't get activated until Emacs _next_ becomes idle, we | |
893 ;; need to force our timer to be considered active now. We do | |
894 ;; this by being naughty and poking the timer internals directly | |
895 ;; (element 0 of the vector is nil if the timer is active). | |
896 (aset mail-source-report-new-mail-idle-timer 0 nil))) | |
897 | |
898 (defun mail-source-report-new-mail (arg) | |
899 "Toggle whether to report when new mail is available. | |
900 This only works when `display-time' is enabled." | |
901 (interactive "P") | |
902 (if (not mail-source-primary-source) | |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33342
diff
changeset
|
903 (error "Need to set `mail-source-primary-source' to check for new mail")) |
31717 | 904 (let ((on (if (null arg) |
905 (not mail-source-report-new-mail) | |
906 (> (prefix-numeric-value arg) 0)))) | |
907 (setq mail-source-report-new-mail on) | |
908 (and mail-source-report-new-mail-timer | |
32102 | 909 (nnheader-cancel-timer mail-source-report-new-mail-timer)) |
31717 | 910 (and mail-source-report-new-mail-idle-timer |
32102 | 911 (nnheader-cancel-timer mail-source-report-new-mail-idle-timer)) |
31717 | 912 (setq mail-source-report-new-mail-timer nil) |
913 (setq mail-source-report-new-mail-idle-timer nil) | |
914 (if on | |
915 (progn | |
916 (require 'time) | |
31764 | 917 ;; display-time-mail-function is an Emacs 21 feature. |
31717 | 918 (setq display-time-mail-function #'mail-source-new-mail-p) |
919 ;; Set up the main timer. | |
920 (setq mail-source-report-new-mail-timer | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
921 (nnheader-run-at-time |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
922 (* 60 mail-source-report-new-mail-interval) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
923 (* 60 mail-source-report-new-mail-interval) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
924 #'mail-source-start-idle-timer)) |
31717 | 925 ;; When you get new mail, clear "Mail" from the mode line. |
926 (add-hook 'nnmail-post-get-new-mail-hook | |
927 'display-time-event-handler) | |
928 (message "Mail check enabled")) | |
929 (setq display-time-mail-function nil) | |
930 (remove-hook 'nnmail-post-get-new-mail-hook | |
931 'display-time-event-handler) | |
932 (message "Mail check disabled")))) | |
933 | |
934 (defun mail-source-fetch-maildir (source callback) | |
935 "Fetcher for maildir sources." | |
936 (mail-source-bind (maildir source) | |
937 (let ((found 0) | |
938 mail-source-string) | |
939 (unless (string-match "/$" path) | |
940 (setq path (concat path "/"))) | |
941 (dolist (subdir subdirs) | |
942 (when (file-directory-p (concat path subdir)) | |
943 (setq mail-source-string (format "maildir:%s%s" path subdir)) | |
944 (dolist (file (directory-files (concat path subdir) t)) | |
945 (when (and (not (file-directory-p file)) | |
946 (not (if function | |
947 (funcall function file mail-source-crash-box) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
948 (let ((coding-system-for-write |
31717 | 949 mm-text-coding-system) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
950 (coding-system-for-read |
31717 | 951 mm-text-coding-system)) |
952 (with-temp-file mail-source-crash-box | |
953 (insert-file-contents file) | |
954 (goto-char (point-min)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
955 ;;; ;; Unix mail format |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
956 ;;; (unless (looking-at "\n*From ") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
957 ;;; (insert "From maildir " |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
958 ;;; (current-time-string) "\n")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
959 ;;; (while (re-search-forward "^From " nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
960 ;;; (replace-match ">From ")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
961 ;;; (goto-char (point-max)) |
32333 | 962 ;;; (insert "\n\n") |
31717 | 963 ;; MMDF mail format |
32333 | 964 (insert "\001\001\001\001\n")) |
31717 | 965 (delete-file file))))) |
966 (incf found (mail-source-callback callback file)))))) | |
967 found))) | |
968 | |
969 (eval-and-compile | |
970 (autoload 'imap-open "imap") | |
971 (autoload 'imap-authenticate "imap") | |
972 (autoload 'imap-mailbox-select "imap") | |
973 (autoload 'imap-mailbox-unselect "imap") | |
974 (autoload 'imap-mailbox-close "imap") | |
975 (autoload 'imap-search "imap") | |
976 (autoload 'imap-fetch "imap") | |
977 (autoload 'imap-close "imap") | |
978 (autoload 'imap-error-text "imap") | |
979 (autoload 'imap-message-flags-add "imap") | |
980 (autoload 'imap-list-to-message-set "imap") | |
32102 | 981 (autoload 'imap-range-to-message-set "imap") |
31717 | 982 (autoload 'nnheader-ms-strip-cr "nnheader")) |
983 | |
32102 | 984 (defvar mail-source-imap-file-coding-system 'binary |
985 "Coding system for the crashbox made by `mail-source-fetch-imap'.") | |
986 | |
31717 | 987 (defun mail-source-fetch-imap (source callback) |
988 "Fetcher for imap sources." | |
989 (mail-source-bind (imap source) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
990 (mail-source-run-script |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
991 prescript (format-spec-make ?p password ?t mail-source-crash-box |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
992 ?s server ?P port ?u user) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
993 prescript-delay) |
31717 | 994 (let ((from (format "%s:%s:%s" server user port)) |
995 (found 0) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
996 (buf (generate-new-buffer " *imap source*")) |
31717 | 997 (mail-source-string (format "imap:%s:%s" server mailbox)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
998 (imap-shell-program (or (list program) imap-shell-program)) |
31717 | 999 remove) |
1000 (if (and (imap-open server port stream authentication buf) | |
1001 (imap-authenticate | |
1002 user (or (cdr (assoc from mail-source-password-cache)) | |
1003 password) buf) | |
1004 (imap-mailbox-select mailbox nil buf)) | |
32918 | 1005 (let ((coding-system-for-write mail-source-imap-file-coding-system) |
32333 | 1006 str) |
31717 | 1007 (with-temp-file mail-source-crash-box |
32918 | 1008 ;; Avoid converting 8-bit chars from inserted strings to |
1009 ;; multibyte. | |
1010 (mm-disable-multibyte) | |
31717 | 1011 ;; remember password |
1012 (with-current-buffer buf | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1013 (when (and imap-password |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1014 (not (assoc from mail-source-password-cache))) |
31717 | 1015 (push (cons from imap-password) mail-source-password-cache))) |
1016 ;; if predicate is nil, use all uids | |
1017 (dolist (uid (imap-search (or predicate "1:*") buf)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1018 (when (setq str |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1019 (if (imap-capability 'IMAP4rev1 buf) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1020 (caddar (imap-fetch uid "BODY.PEEK[]" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1021 'BODYDETAIL nil buf)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1022 (imap-fetch uid "RFC822.PEEK" 'RFC822 nil buf))) |
31717 | 1023 (push uid remove) |
1024 (insert "From imap " (current-time-string) "\n") | |
1025 (save-excursion | |
1026 (insert str "\n\n")) | |
1027 (while (re-search-forward "^From " nil t) | |
1028 (replace-match ">From ")) | |
1029 (goto-char (point-max)))) | |
1030 (nnheader-ms-strip-cr)) | |
1031 (incf found (mail-source-callback callback server)) | |
1032 (when (and remove fetchflag) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1033 (setq remove (nreverse remove)) |
31717 | 1034 (imap-message-flags-add |
32102 | 1035 (imap-range-to-message-set (gnus-compress-sequence remove)) |
1036 fetchflag nil buf)) | |
31717 | 1037 (if dontexpunge |
1038 (imap-mailbox-unselect buf) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1039 (imap-mailbox-close nil buf)) |
31717 | 1040 (imap-close buf)) |
1041 (imap-close buf) | |
1042 ;; We nix out the password in case the error | |
1043 ;; was because of a wrong password being given. | |
1044 (setq mail-source-password-cache | |
1045 (delq (assoc from mail-source-password-cache) | |
1046 mail-source-password-cache)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1047 (error "IMAP error: %s" (imap-error-text buf))) |
31717 | 1048 (kill-buffer buf) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1049 (mail-source-run-script |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1050 postscript |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1051 (format-spec-make ?p password ?t mail-source-crash-box |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1052 ?s server ?P port ?u user)) |
31717 | 1053 found))) |
1054 | |
1055 (eval-and-compile | |
1056 (autoload 'webmail-fetch "webmail")) | |
1057 | |
1058 (defun mail-source-fetch-webmail (source callback) | |
1059 "Fetch for webmail source." | |
1060 (mail-source-bind (webmail source) | |
1061 (let ((mail-source-string (format "webmail:%s:%s" subtype user)) | |
1062 (webmail-newmail-only dontexpunge) | |
1063 (webmail-move-to-trash-can (not dontexpunge))) | |
1064 (when (eq authentication 'password) | |
1065 (setq password | |
1066 (or password | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
1067 (cdr (assoc (format "webmail:%s:%s" subtype user) |
31717 | 1068 mail-source-password-cache)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
1069 (read-passwd |
31717 | 1070 (format "Password for %s at %s: " user subtype)))) |
1071 (when (and password | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
1072 (not (assoc (format "webmail:%s:%s" subtype user) |
31717 | 1073 mail-source-password-cache))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44075
diff
changeset
|
1074 (push (cons (format "webmail:%s:%s" subtype user) password) |
31717 | 1075 mail-source-password-cache))) |
1076 (webmail-fetch mail-source-crash-box subtype user password) | |
1077 (mail-source-callback callback (symbol-name subtype))))) | |
1078 | |
1079 (provide 'mail-source) | |
1080 | |
52401 | 1081 ;;; arch-tag: 72948025-1d17-4d6c-bb12-ef1aa2c490fd |
31717 | 1082 ;;; mail-source.el ends here |