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