1 ;;; mail-source.el --- functions for fetching mail
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail
9 ;; This file is part of GNU Emacs.
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 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
32 (require 'format-spec)
36 (autoload 'auth-source-user-or-password "auth-source")
37 (autoload 'pop3-movemail "pop3")
38 (autoload 'pop3-get-message-count "pop3")
39 (autoload 'nnheader-cancel-timer "nnheader")
41 (require 'message) ;; for `message-directory'
43 (defvar display-time-mail-function)
45 (defgroup mail-source nil
46 "The mail-fetching library."
50 ;; Define these at compile time to avoid dragging in imap always.
51 (defconst mail-source-imap-authenticators
54 (list 'const (car a)))
55 imap-authenticator-alist)))
56 (defconst mail-source-imap-streams
59 (list 'const (car a)))
62 (defcustom mail-sources '((file))
63 "Where the mail backends will look for incoming mail.
64 This variable is a list of mail source specifiers.
65 See Info node `(gnus)Mail Source Specifiers'."
67 :version "23.1" ;; No Gnus
68 :link '(custom-manual "(gnus)Mail Source Specifiers")
70 (const :tag "None" nil)
72 (choice :format "%[Value Menu%] %v"
74 (cons :tag "Group parameter `mail-source'"
75 (const :format "" group))
76 (cons :tag "Spool file"
77 (const :format "" file)
78 (checklist :tag "Options" :greedy t
80 (const :format "" :value :path)
82 (cons :tag "Several files in a directory"
83 (const :format "" directory)
84 (checklist :tag "Options" :greedy t
86 (const :format "" :value :path)
87 (directory :tag "Path"))
89 (const :format "" :value :suffix)
90 (string :tag "Suffix"))
92 (const :format "" :value :predicate)
93 (function :tag "Predicate"))
95 (const :format "" :value :prescript)
96 (choice :tag "Prescript"
99 (function :format "%v")))
101 (const :format "" :value :postscript)
102 (choice :tag "Postscript"
104 (string :format "%v")
105 (function :format "%v")))
107 (const :format "" :value :plugged)
108 (boolean :tag "Plugged"))))
109 (cons :tag "POP3 server"
110 (const :format "" pop)
111 (checklist :tag "Options" :greedy t
113 (const :format "" :value :server)
114 (string :tag "Server"))
116 (const :format "" :value :port)
119 (integer :format "%v")
120 (string :format "%v")))
122 (const :format "" :value :user)
123 (string :tag "User"))
125 (const :format "" :value :password)
126 (string :tag "Password"))
128 (const :format "" :value :program)
129 (string :tag "Program"))
131 (const :format "" :value :prescript)
132 (choice :tag "Prescript"
134 (string :format "%v")
135 (function :format "%v")
136 (const :tag "None" nil)))
138 (const :format "" :value :postscript)
139 (choice :tag "Postscript"
141 (string :format "%v")
142 (function :format "%v")
143 (const :tag "None" nil)))
145 (const :format "" :value :function)
146 (function :tag "Function"))
149 :value :authentication)
150 (choice :tag "Authentication"
155 (const :format "" :value :plugged)
156 (boolean :tag "Plugged"))
158 (const :format "" :value :stream)
159 (choice :tag "Stream"
161 (const :tag "Clear" nil)
163 (const :tag "SSL/TLS" ssl)))))
164 (cons :tag "Maildir (qmail, postfix...)"
165 (const :format "" maildir)
166 (checklist :tag "Options" :greedy t
168 (const :format "" :value :path)
169 (directory :tag "Path"))
171 (const :format "" :value :plugged)
172 (boolean :tag "Plugged"))))
173 (cons :tag "IMAP server"
174 (const :format "" imap)
175 (checklist :tag "Options" :greedy t
177 (const :format "" :value :server)
178 (string :tag "Server"))
180 (const :format "" :value :port)
185 (const :format "" :value :user)
186 (string :tag "User"))
188 (const :format "" :value :password)
189 (string :tag "Password"))
191 (const :format "" :value :stream)
192 (choice :tag "Stream"
194 ,@mail-source-imap-streams))
196 (const :format "" :value :program)
197 (string :tag "Program"))
200 :value :authenticator)
201 (choice :tag "Authenticator"
203 ,@mail-source-imap-authenticators))
205 (const :format "" :value :mailbox)
206 (string :tag "Mailbox"
209 (const :format "" :value :predicate)
210 (string :tag "Predicate"
211 :value "UNSEEN UNDELETED"))
213 (const :format "" :value :fetchflag)
214 (string :tag "Fetchflag"
219 (boolean :tag "Dontexpunge"))
221 (const :format "" :value :plugged)
222 (boolean :tag "Plugged"))))
223 (cons :tag "Webmail server"
224 (const :format "" webmail)
225 (checklist :tag "Options" :greedy t
227 (const :format "" :value :subtype)
228 ;; Should be generated from
229 ;; `webmail-type-definition', but we
230 ;; can't require webmail without W3.
231 (choice :tag "Subtype"
239 (const :format "" :value :user)
240 (string :tag "User"))
242 (const :format "" :value :password)
243 (string :tag "Password"))
247 (boolean :tag "Dontexpunge"))
249 (const :format "" :value :plugged)
250 (boolean :tag "Plugged"))))))))
252 (defcustom mail-source-ignore-errors nil
253 "*Ignore errors when querying mail sources.
254 If nil, the user will be prompted when an error occurs. If non-nil,
255 the error will be ignored."
260 (defcustom mail-source-primary-source nil
261 "*Primary source for incoming mail.
262 If non-nil, this maildrop will be checked periodically for new mail."
266 (defcustom mail-source-flash t
267 "*If non-nil, flash periodically when mail is available."
271 (defcustom mail-source-crash-box "~/.emacs-mail-crash-box"
272 "File where mail will be stored while processing it."
276 (defcustom mail-source-directory message-directory
277 "Directory where incoming mail source files (if any) will be stored."
281 (defcustom mail-source-default-file-modes 384
282 "Set the mode bits of all new mail files to this integer."
286 (defcustom mail-source-delete-incoming
287 10 ;; development versions
288 ;; 2 ;; released versions
289 "If non-nil, delete incoming files after handling.
290 If t, delete immediately, if nil, never delete. If a positive number, delete
291 files older than number of days.
293 Removing of old files happens in `mail-source-callback', i.e. no
294 old incoming files will be deleted unless you receive new mail.
295 You may also set this variable to nil and call
296 `mail-source-delete-old-incoming' interactively."
298 :version "22.2" ;; No Gnus / Gnus 5.10.10 (default changed)
299 :type '(choice (const :tag "immediately" t)
300 (const :tag "never" nil)
301 (integer :tag "days")))
303 (defcustom mail-source-delete-old-incoming-confirm nil
304 "If non-nil, ask for confirmation before deleting old incoming files.
305 This variable only applies when `mail-source-delete-incoming' is a positive
307 :version "22.2" ;; No Gnus / Gnus 5.10.10 (default changed)
311 (defcustom mail-source-incoming-file-prefix "Incoming"
312 "Prefix for file name for storing incoming mail"
316 (defcustom mail-source-report-new-mail-interval 5
317 "Interval in minutes between checks for new mail."
321 (defcustom mail-source-idle-time-delay 5
322 "Number of idle seconds to wait before checking for new mail."
326 (defcustom mail-source-movemail-program nil
327 "If non-nil, name of program for fetching new mail."
330 :type '(choice (const nil) string))
332 ;;; Internal variables.
334 (defvar mail-source-string ""
335 "A dynamically bound string that says what the current mail source is.")
337 (defvar mail-source-new-mail-available nil
338 "Flag indicating when new mail is available.")
341 (defvar mail-source-common-keyword-map
343 "Mapping from keywords to default values.
344 Common keywords should be listed here.")
346 (defvar mail-source-keyword-map