gnus-group.el (gnus-group-make-group): Report errors.
[gnus] / lisp / nnimap.el
1 ;;; nnimap.el --- imap backend for Gnus
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 ;; Author: Simon Josefsson <jas@pdc.kth.se>
5 ;;         Jim Radford <radford@robby.caltech.edu>
6 ;; Keywords: mail
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; Todo, major things:
28 ;;
29 ;;   o Fix Gnus to view correct number of unread/total articles in group buffer
30 ;;   o Fix Gnus to handle leading '.' in group names (fixed?)
31 ;;   o Finish disconnected mode (moving articles between mailboxes unplugged)
32 ;;   o Sieve
33 ;;   o MIME (partial article fetches)
34 ;;   o Split to other backends, different split rules for different
35 ;;     servers/inboxes
36 ;;
37 ;; Todo, minor things:
38 ;;
39 ;;   o Don't require half of Gnus -- backends should be standalone
40 ;;   o Verify that we don't use IMAP4rev1 specific things (RFC2060 App B)
41 ;;   o Dont uid fetch 1,* in nnimap-retrive-groups (slow)
42 ;;   o Split up big fetches (1,* header especially) in smaller chunks
43 ;;   o What do I do with gnus-newsgroup-*?
44 ;;   o Tell Gnus about new groups (how can we tell?)
45 ;;   o Respooling (fix Gnus?) (unnecessary?)
46 ;;   o Add support for the following: (if applicable)
47 ;;       request-list-newsgroups, request-regenerate
48 ;;       list-active-group,
49 ;;       request-associate-buffer, request-restore-buffer,
50 ;;   o Do The Right Thing when UIDVALIDITY changes (what's the right thing?)
51 ;;   o Support RFC2221 (Login referrals)
52 ;;   o IMAP2BIS compatibility? (RFC2061)
53 ;;   o ACAP stuff (perhaps a different project, would be nice to ACAPify
54 ;;     .newsrc.eld)
55 ;;   o What about Gnus's article editing, can we support it?  NO!
56 ;;   o Use \Draft to support the draft group??
57 ;;   o Duplicate suppression
58 ;;   o Rewrite UID SEARCH UID X as UID FETCH X (UID) for those with slow servers
59
60 ;;; Code:
61
62 (require 'imap)
63 (require 'nnoo)
64 (require 'nnmail)
65 (require 'nnheader)
66 (require 'mm-util)
67 (require 'gnus)
68 (require 'gnus-range)
69 (require 'gnus-start)
70 (require 'gnus-int)
71
72 (nnoo-declare nnimap)
73
74 (defconst nnimap-version "nnimap 1.0")
75
76 (defgroup nnimap nil
77   "Reading IMAP mail with Gnus."
78   :group 'gnus)
79
80 (defvoo nnimap-address nil
81   "Address of physical IMAP server.  If nil, use the virtual server's name.")
82
83 (defvoo nnimap-server-port nil
84   "Port number on physical IMAP server.
85 If nil, defaults to 993 for SSL connections and 143 otherwise.")
86
87 ;; Splitting variables
88
89 (defcustom nnimap-split-crosspost t
90   "If non-nil, do crossposting if several split methods match the mail.
91 If nil, the first match found will be used."
92   :group 'nnimap
93   :type 'boolean)
94
95 (defcustom nnimap-split-inbox nil
96   "Name of mailbox to split mail from.
97
98 Mail is read from this mailbox and split according to rules in
99 `nnimap-split-rule'.
100
101 This can be a string or a list of strings."
102   :group 'nnimap
103   :type '(choice (string)
104                  (repeat string)))
105
106 (define-widget 'nnimap-strict-function 'function
107   "This widget only matches values that are functionp.
108
109 Warning: This means that a value that is the symbol of a not yet
110 loaded function will not match.  Use with care."
111   :match 'nnimap-strict-function-match)
112
113 (defun nnimap-strict-function-match (widget value)
114   "Ignoring WIDGET, match if VALUE is a function."
115   (functionp value))
116
117 (defcustom nnimap-split-rule nil
118   "Mail will be split according to these rules.
119
120 Mail is read from mailbox(es) specified in `nnimap-split-inbox'.
121
122 If you'd like, for instance, one mail group for mail from the
123 \"gnus-imap\" mailing list, one group for junk mail and leave
124 everything else in the incoming mailbox, you could do something like
125 this:
126
127 \(setq nnimap-split-rule '((\"INBOX.gnus-imap\"   \"From:.*gnus-imap\")
128                           (\"INBOX.junk\"        \"Subject:.*buy\")))
129
130 As you can see, `nnimap-split-rule' is a list of lists, where the
131 first element in each \"rule\" is the name of the IMAP mailbox (or the
132 symbol `junk' if you want to remove the mail), and the second is a
133 regexp that nnimap will try to match on the header to find a fit.
134
135 The second element can also be a function.  In that case, it will be
136 called narrowed to the headers with the first element of the rule as
137 the argument.  It should return a non-nil value if it thinks that the
138 mail belongs in that group.
139
140 This variable can also have a function as its value, the function will
141 be called with the headers narrowed and should return a group where it
142 thinks the article should be splitted to.  See `nnimap-split-fancy'.
143
144 To allow for different split rules on different virtual servers, and
145 even different split rules in different inboxes on the same server,
146 the syntax of this variable have been extended along the lines of:
147
148 \(setq nnimap-split-rule
149       '((\"my1server\"    (\".*\"    ((\"ding\"    \"ding@gnus.org\")
150                                   (\"junk\"    \"From:.*Simon\")))
151         (\"my2server\"    (\"INBOX\" nnimap-split-fancy))
152         (\"my[34]server\" (\".*\"    ((\"private\" \"To:.*Simon\")
153                                   (\"junk\"    my-junk-func)))))
154
155 The virtual server name is in fact a regexp, so that the same rules
156 may apply to several servers.  In the example, the servers
157 \"my3server\" and \"my4server\" both use the same rules.  Similarly,
158 the inbox string is also a regexp.  The actual splitting rules are as
159 before, either a function, or a list with group/regexp or
160 group/function elements."
161   :group 'nnimap
162   :type '(choice :tag "Rule type"
163                  (repeat :menu-tag "Single-server"
164                          :tag "Single-server list"
165                          (list (string :tag "Mailbox")
166                                (choice :tag "Predicate"
167                                        (regexp :tag "A regexp")
168                                        (nnimap-strict-function :tag "A function"))))
169                  (choice :menu-tag "A function"
170                          :tag "A function"
171                          (function-item nnimap-split-fancy)
172                          (function-item nnmail-split-fancy)
173                          (nnimap-strict-function :tag "User-defined function"))
174                  (repeat :menu-tag "Multi-server (extended)"
175                          :tag "Multi-server list"
176                          (list (regexp :tag "Server regexp")
177                                (list (regexp :tag "Incoming Mailbox regexp")
178                                      (repeat :tag "Rules for matching server(s) and mailbox(es)"
179                                              (list (string :tag "Destination mailbox")
180                                                    (choice :tag "Predicate"
181                                                            (regexp :tag "A Regexp")
182                                                            (nnimap-strict-function :tag "A Function")))))))))
183
184 (defcustom nnimap-split-predicate "UNSEEN UNDELETED"
185   "The predicate used to find articles to split.
186 If you use another IMAP client to peek on articles but always would
187 like nnimap to split them once it's started, you could change this to
188 \"UNDELETED\". Other available predicates are available in
189 RFC2060 section 6.4.4."
190   :group 'nnimap
191   :type 'string)
192
193 (defcustom nnimap-split-fancy nil
194   "Like the variable `nnmail-split-fancy', which see."
195   :group 'nnimap
196   :type 'sexp)
197
198 (defcustom nnimap-split-download-body nil
199   "Whether to download entire articles during splitting.
200 This is generally not required, and will slow things down considerably.
201 You may need it if you want to use an advanced splitting function that
202 analyses the body before splitting the article."
203   :group 'nnimap
204   :type 'boolean)
205
206 ;; Performance / bug workaround variables
207
208 (defcustom nnimap-close-asynchronous t
209   "Close mailboxes asynchronously in `nnimap-close-group'.
210 This means that errors cought by nnimap when closing the mailbox will
211 not prevent Gnus from updating the group status, which may be harmful.
212 However, it increases speed."
213   :type 'boolean
214   :group 'nnimap)
215
216 (defcustom nnimap-dont-close t
217   "Never close mailboxes.
218 This increases the speed of closing mailboxes (quiting group) but may
219 decrease the speed of selecting another mailbox later.  Re-selecting
220 the same mailbox will be faster though."
221   :type 'boolean
222   :group 'nnimap)
223
224 (defcustom nnimap-retrieve-groups-asynchronous t
225   "Send asynchronous STATUS commands for each mailbox before checking mail.
226 If you have mailboxes that rarely receives mail, this speeds up new
227 mail checking.  It works by first sending STATUS commands for each
228 mailbox, and then only checking groups which has a modified UIDNEXT
229 more carefully for new mail.
230
231 In summary, the default is O((1-p)*k+p*n) and changing it to nil makes
232 it O(n).  If p is small, then the default is probably faster."
233   :type 'boolean
234   :group 'nnimap)
235
236 (defvoo nnimap-need-unselect-to-notice-new-mail nil
237   "Unselect mailboxes before looking for new mail in them.
238 Some servers seem to need this under some circumstances.")
239
240 ;; Authorization / Privacy variables
241
242 (defvoo nnimap-auth-method nil
243   "Obsolete.")
244
245 (defvoo nnimap-stream nil
246   "How nnimap will connect to the server.
247
248 The default, nil, will try to use the \"best\" method the server can
249 handle.
250
251 Change this if
252
253 1) you want to connect with SSL.  The SSL integration with IMAP is
254    brain-dead so you'll have to tell it specifically.
255
256 2) your server is more capable than your environment -- i.e. your
257    server accept Kerberos login's but you haven't installed the
258    `imtest' program or your machine isn't configured for Kerberos.
259
260 Possible choices: kerberos4, ssl, network")
261
262 (defvoo nnimap-authenticator nil
263   "How nnimap authenticate itself to the server.
264
265 The default, nil, will try to use the \"best\" method the server can
266 handle.
267
268 There is only one reason for fiddling with this variable, and that is
269 if your server is more capable than your environment -- i.e. you
270 connect to a server that accept Kerberos login's but you haven't
271 installed the `imtest' program or your machine isn't configured for
272 Kerberos.
273
274 Possible choices: kerberos4, cram-md5, login, anonymous.")
275
276 (defvoo nnimap-directory (nnheader-concat gnus-directory "overview/")
277   "Directory to keep NOV cache files for nnimap groups.
278 See also `nnimap-nov-file-name'.")
279
280 (defvoo nnimap-nov-file-name "nnimap."
281   "NOV cache base filename.
282 The group name and `nnimap-nov-file-name-suffix' will be appended.  A
283 typical complete file name would be
284 ~/News/overview/nnimap.pdc.INBOX.ding.nov, or
285 ~/News/overview/nnimap/pdc/INBOX/ding/nov if
286 `nnmail-use-long-file-names' is nil")
287
288 (defvoo nnimap-nov-file-name-suffix ".novcache"
289   "Suffix for NOV cache base filename.")
290
291 (defvoo nnimap-nov-is-evil gnus-agent
292   "If non-nil, never generate or use a local nov database for this backend.
293 Using nov databases should speed up header fetching considerably.
294 However, it will invoke a UID SEARCH UID command on the server, and
295 some servers implement this command inefficiently by opening each and
296 every message in the group, thus making it quite slow.
297 Unlike other backends, you do not need to take special care if you
298 flip this variable.")
299
300 (defvoo nnimap-expunge-on-close 'always ; 'ask, 'never
301   "Whether to expunge a group when it is closed.
302 When a IMAP group with articles marked for deletion is closed, this
303 variable determine if nnimap should actually remove the articles or
304 not.
305
306 If always, nnimap always perform a expunge when closing the group.
307 If never, nnimap never expunges articles marked for deletion.
308 If ask, nnimap will ask you if you wish to expunge marked articles.
309
310 When setting this variable to `never', you can only expunge articles
311 by using `G x' (gnus-group-nnimap-expunge) from the Group buffer.")
312
313 (defvoo nnimap-list-pattern "*"
314   "A string LIMIT or list of strings with mailbox wildcards used to limit available groups.
315 See below for available wildcards.