Mercurial > emacs
annotate lisp/gnus/nnimap.el @ 55857:a713acca9ca9
(find-file): Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 30 May 2004 13:34:19 +0000 |
parents | dd7a1cf22d3d |
children | 5716fec2dbc0 4c90ffeb71c5 |
rev | line source |
---|---|
31717 | 1 ;;; nnimap.el --- imap backend for Gnus |
55398
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
2 |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
3 ;; Copyright (C) 1998,1999,2000,01,02,2004 Free Software Foundation, Inc. |
31717 | 4 |
5 ;; Author: Simon Josefsson <jas@pdc.kth.se> | |
6 ;; Jim Radford <radford@robby.caltech.edu> | |
7 ;; Keywords: 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 | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; Todo, major things: | |
29 ;; | |
30 ;; o Fix Gnus to view correct number of unread/total articles in group buffer | |
31 ;; o Fix Gnus to handle leading '.' in group names (fixed?) | |
32 ;; o Finish disconnected mode (moving articles between mailboxes unplugged) | |
33 ;; o Sieve | |
34 ;; o MIME (partial article fetches) | |
35 ;; o Split to other backends, different split rules for different | |
36 ;; servers/inboxes | |
37 ;; | |
38 ;; Todo, minor things: | |
39 ;; | |
40 ;; o Don't require half of Gnus -- backends should be standalone | |
41 ;; o Verify that we don't use IMAP4rev1 specific things (RFC2060 App B) | |
42 ;; o Dont uid fetch 1,* in nnimap-retrive-groups (slow) | |
43 ;; o Split up big fetches (1,* header especially) in smaller chunks | |
44 ;; o What do I do with gnus-newsgroup-*? | |
45 ;; o Tell Gnus about new groups (how can we tell?) | |
48588 | 46 ;; o Respooling (fix Gnus?) (unnecessary?) |
31717 | 47 ;; o Add support for the following: (if applicable) |
48 ;; request-list-newsgroups, request-regenerate | |
49 ;; list-active-group, | |
50 ;; request-associate-buffer, request-restore-buffer, | |
51 ;; o Do The Right Thing when UIDVALIDITY changes (what's the right thing?) | |
52 ;; o Support RFC2221 (Login referrals) | |
53 ;; o IMAP2BIS compatibility? (RFC2061) | |
54 ;; o ACAP stuff (perhaps a different project, would be nice to ACAPify | |
55 ;; .newsrc.eld) | |
56 ;; o What about Gnus's article editing, can we support it? NO! | |
57 ;; o Use \Draft to support the draft group?? | |
58 ;; o Duplicate suppression | |
59 | |
60 ;;; Code: | |
61 | |
62 (eval-and-compile | |
32153
fc62cbb87aa5
require 'cl when compiling.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31717
diff
changeset
|
63 (require 'cl) |
31717 | 64 (require 'imap)) |
65 | |
66 (require 'nnoo) | |
67 (require 'nnmail) | |
68 (require 'nnheader) | |
69 (require 'mm-util) | |
70 (require 'gnus) | |
71 (require 'gnus-range) | |
72 (require 'gnus-start) | |
73 (require 'gnus-int) | |
74 | |
75 (nnoo-declare nnimap) | |
76 | |
77 (defconst nnimap-version "nnimap 0.131") | |
78 | |
79 (defvoo nnimap-address nil | |
80 "Address of physical IMAP server. If nil, use the virtual server's name.") | |
81 | |
82 (defvoo nnimap-server-port nil | |
83 "Port number on physical IMAP server. | |
84 If nil, defaults to 993 for SSL connections and 143 otherwise.") | |
85 | |
86 ;; Splitting variables | |
87 | |
88 (defvar nnimap-split-crosspost t | |
89 "If non-nil, do crossposting if several split methods match the mail. | |
90 If nil, the first match found will be used.") | |
91 | |
92 (defvar nnimap-split-inbox nil | |
93 "*Name of mailbox to split mail from. | |
94 | |
95 Mail is read from this mailbox and split according to rules in | |
96 `nnimap-split-rules'. | |
97 | |
98 This can be a string or a list of strings.") | |
99 | |
100 (defvar nnimap-split-rule nil | |
48588 | 101 "*Mail will be split according to these rules. |
31717 | 102 |
103 Mail is read from mailbox(es) specified in `nnimap-split-inbox'. | |
104 | |
105 If you'd like, for instance, one mail group for mail from the | |
106 \"gnus-imap\" mailing list, one group for junk mail and leave | |
107 everything else in the incoming mailbox, you could do something like | |
108 this: | |
109 | |
48216
e5026995ea82
(nnimap-split-rule): Doc fix - escape open parens in column 0.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44512
diff
changeset
|
110 \(setq nnimap-split-rule '((\"INBOX.gnus-imap\" \"From:.*gnus-imap\") |
31717 | 111 (\"INBOX.junk\" \"Subject:.*buy\"))) |
112 | |
113 As you can see, `nnimap-split-rule' is a list of lists, where the first | |
114 element in each \"rule\" is the name of the IMAP mailbox, and the | |
115 second is a regexp that nnimap will try to match on the header to find | |
116 a fit. | |
117 | |
118 The second element can also be a function. In that case, it will be | |
119 called narrowed to the headers with the first element of the rule as | |
120 the argument. It should return a non-nil value if it thinks that the | |
121 mail belongs in that group. | |
122 | |
123 This variable can also have a function as its value, the function will | |
124 be called with the headers narrowed and should return a group where it | |
125 thinks the article should be splitted to. See `nnimap-split-fancy'. | |
126 | |
127 To allow for different split rules on different virtual servers, and | |
128 even different split rules in different inboxes on the same server, | |
129 the syntax of this variable have been extended along the lines of: | |
130 | |
48216
e5026995ea82
(nnimap-split-rule): Doc fix - escape open parens in column 0.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44512
diff
changeset
|
131 \(setq nnimap-split-rule |
31717 | 132 '((\"my1server\" (\".*\" ((\"ding\" \"ding@gnus.org\") |
133 (\"junk\" \"From:.*Simon\"))) | |
134 (\"my2server\" (\"INBOX\" nnimap-split-fancy)) | |
135 (\"my[34]server\" (\".*\" ((\"private\" \"To:.*Simon\") | |
136 (\"junk\" my-junk-func))))) | |
137 | |
138 The virtual server name is in fact a regexp, so that the same rules | |
139 may apply to several servers. In the example, the servers | |
140 \"my3server\" and \"my4server\" both use the same rules. Similarly, | |
141 the inbox string is also a regexp. The actual splitting rules are as | |
142 before, either a function, or a list with group/regexp or | |
143 group/function elements.") | |
144 | |
145 (defvar nnimap-split-predicate "UNSEEN UNDELETED" | |
146 "The predicate used to find articles to split. | |
147 If you use another IMAP client to peek on articles but always would | |
148 like nnimap to split them once it's started, you could change this to | |
149 \"UNDELETED\". Other available predicates are available in | |
150 RFC2060 section 6.4.4.") | |
151 | |
152 (defvar nnimap-split-fancy nil | |
153 "Like `nnmail-split-fancy', which see.") | |
154 | |
155 ;; Authorization / Privacy variables | |
156 | |
157 (defvoo nnimap-auth-method nil | |
158 "Obsolete.") | |
159 | |
160 (defvoo nnimap-stream nil | |
161 "How nnimap will connect to the server. | |
162 | |
163 The default, nil, will try to use the \"best\" method the server can | |
164 handle. | |
165 | |
166 Change this if | |
167 | |
168 1) you want to connect with SSL. The SSL integration with IMAP is | |
169 brain-dead so you'll have to tell it specifically. | |
170 | |
171 2) your server is more capable than your environment -- i.e. your | |
172 server accept Kerberos login's but you haven't installed the | |
173 `imtest' program or your machine isn't configured for Kerberos. | |
174 | |
175 Possible choices: kerberos4, ssl, network") | |
176 | |
177 (defvoo nnimap-authenticator nil | |
178 "How nnimap authenticate itself to the server. | |
179 | |
180 The default, nil, will try to use the \"best\" method the server can | |
181 handle. | |
182 | |
183 There is only one reason for fiddling with this variable, and that is | |
184 if your server is more capable than your environment -- i.e. you | |
185 connect to a server that accept Kerberos login's but you haven't | |
186 installed the `imtest' program or your machine isn't configured for | |
187 Kerberos. | |
188 | |
189 Possible choices: kerberos4, cram-md5, login, anonymous.") | |
190 | |
191 (defvoo nnimap-directory (nnheader-concat gnus-directory "overview/") | |
192 "Directory to keep NOV cache files for nnimap groups. | |
193 See also `nnimap-nov-file-name'.") | |
194 | |
195 (defvoo nnimap-nov-file-name "nnimap." | |
196 "NOV cache base filename. | |
197 The group name and `nnimap-nov-file-name-suffix' will be appended. A | |
198 typical complete file name would be | |
199 ~/News/overview/nnimap.pdc.INBOX.ding.nov, or | |
200 ~/News/overview/nnimap/pdc/INBOX/ding/nov if | |
201 `nnmail-use-long-file-names' is nil") | |
202 | |
203 (defvoo nnimap-nov-file-name-suffix ".novcache" | |
204 "Suffix for NOV cache base filename.") | |
205 | |
206 (defvoo nnimap-nov-is-evil nil | |
207 "If non-nil, nnimap will never generate or use a local nov database for this backend. | |
208 Using nov databases will speed up header fetching considerably. | |
209 Unlike other backends, you do not need to take special care if you | |
210 flip this variable.") | |
211 | |
212 (defvoo nnimap-expunge-on-close 'always ; 'ask, 'never | |
213 "Whether to expunge a group when it is closed. | |
214 When a IMAP group with articles marked for deletion is closed, this | |
215 variable determine if nnimap should actually remove the articles or | |
216 not. | |
217 | |
218 If always, nnimap always perform a expunge when closing the group. | |
219 If never, nnimap never expunges articles marked for deletion. | |
220 If ask, nnimap will ask you if you wish to expunge marked articles. | |
221 | |
222 When setting this variable to `never', you can only expunge articles | |
223 by using `G x' (gnus-group-nnimap-expunge) from the Group buffer.") | |
224 | |
225 (defvoo nnimap-list-pattern "*" | |
226 "A string LIMIT or list of strings with mailbox wildcards used to limit available groups. | |
227 See below for available wildcards. | |
228 | |
229 The LIMIT string can be a cons cell (REFERENCE . LIMIT), where | |
230 REFERENCE will be passed as the first parameter to LIST/LSUB. The | |
231 semantics of this are server specific, on the University of Washington | |
232 server you can specify a directory. | |
233 | |
234 Example: | |
235 '(\"INBOX\" \"mail/*\" (\"~friend/mail/\" . \"list/*\")) | |
236 | |
237 There are two wildcards * and %. * matches everything, % matches | |
238 everything in the current hierarchy.") | |
239 | |
240 (defvoo nnimap-news-groups nil | |
241 "IMAP support a news-like mode, also known as bulletin board mode, where replies is sent via IMAP instead of SMTP. | |
242 | |
243 This variable should contain a regexp matching groups where you wish | |
244 replies to be stored to the mailbox directly. | |
245 | |
246 Example: | |
247 '(\"^[^I][^N][^B][^O][^X].*$\") | |
248 | |
249 This will match all groups not beginning with \"INBOX\". | |
250 | |
251 Note that there is nothing technically different between mail-like and | |
252 news-like mailboxes. If you wish to have a group with todo items or | |
253 similar which you wouldn't want to set up a mailing list for, you can | |
254 use this to make replies go directly to the group.") | |
255 | |
256 (defvoo nnimap-server-address nil | |
257 "Obsolete. Use `nnimap-address'.") | |
258 | |
259 (defcustom nnimap-authinfo-file "~/.authinfo" | |
260 "Authorization information for IMAP servers. In .netrc format." | |
261 :type | |
262 '(choice file | |
263 (repeat :tag "Entries" | |
264 :menu-tag "Inline" | |
265 (list :format "%v" | |
266 :value ("" ("login" . "") ("password" . "")) | |
267 (string :tag "Host") | |
268 (checklist :inline t | |
269 (cons :format "%v" | |
270 (const :format "" "login") | |
271 (string :format "Login: %v")) | |
272 (cons :format "%v" | |
273 (const :format "" "password") | |
274 (string :format "Password: %v"))))))) | |
275 | |
276 (defcustom nnimap-prune-cache t | |
277 "If non-nil, nnimap check whether articles still exist on server before using data stored in NOV cache." | |
278 :type 'boolean) | |
279 | |
280 (defvar nnimap-request-list-method 'imap-mailbox-list | |
281 "Method to use to request a list of all folders from the server. | |
282 If this is 'imap-mailbox-lsub, then use a server-side subscription list to | |
283 restrict visible folders.") | |
284 | |
285 ;; Internal variables: | |
286 | |
287 (defvar nnimap-debug nil | |
288 "Name of buffer to record debugging info. | |
289 For example: (setq nnimap-debug \"*nnimap-debug*\")") | |
290 (defvar nnimap-current-move-server nil) | |
291 (defvar nnimap-current-move-group nil) | |
292 (defvar nnimap-current-move-article nil) | |
293 (defvar nnimap-length) | |
294 (defvar nnimap-progress-chars '(?| ?/ ?- ?\\)) | |
295 (defvar nnimap-progress-how-often 20) | |
296 (defvar nnimap-counter) | |
297 (defvar nnimap-callback-callback-function nil | |
298 "Gnus callback the nnimap asynchronous callback should call.") | |
299 (defvar nnimap-callback-buffer nil | |
300 "Which buffer the asynchronous article prefetch callback should work in.") | |
301 (defvar nnimap-server-buffer-alist nil) ;; Map server name to buffers. | |
302 (defvar nnimap-current-server nil) ;; Current server | |
303 (defvar nnimap-server-buffer nil) ;; Current servers' buffer | |
304 | |
305 | |
306 | |
307 (nnoo-define-basics nnimap) | |
308 | |
309 ;; Utility functions: | |
310 | |
311 (defsubst nnimap-get-server-buffer (server) | |
312 "Return buffer for SERVER, if nil use current server." | |
313 (cadr (assoc (or server nnimap-current-server) nnimap-server-buffer-alist))) | |
314 | |
315 (defun nnimap-possibly-change-server (server) | |
316 "Return buffer for SERVER, changing the current server as a side-effect. | |
317 If SERVER is nil, uses the current server." | |
318 (setq nnimap-current-server (or server nnimap-current-server) | |
319 nnimap-server-buffer (nnimap-get-server-buffer nnimap-current-server))) | |
320 | |
321 (defun nnimap-verify-uidvalidity (group server) | |
322 "Verify stored uidvalidity match current one in GROUP on SERVER." | |
323 (let* ((gnusgroup (gnus-group-prefixed-name | |
324 group (gnus-server-to-method | |
325 (format "nnimap:%s" server)))) | |
326 (new-uidvalidity (imap-mailbox-get 'uidvalidity)) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
327 (old-uidvalidity (gnus-group-get-parameter gnusgroup 'uidvalidity)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
328 (dir (file-name-as-directory (expand-file-name nnimap-directory))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
329 (nameuid (nnheader-translate-file-chars |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
330 (concat nnimap-nov-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
331 (if (equal server "") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
332 "unnamed" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
333 server) "." group "." old-uidvalidity |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
334 nnimap-nov-file-name-suffix) t)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
335 (file (if (or nnmail-use-long-file-names |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
336 (file-exists-p (expand-file-name nameuid dir))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
337 (expand-file-name nameuid dir) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
338 (expand-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
339 (mm-encode-coding-string |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
340 (nnheader-replace-chars-in-string nameuid ?. ?/) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
341 nnmail-pathname-coding-system) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
342 dir)))) |
31717 | 343 (if old-uidvalidity |
344 (if (not (equal old-uidvalidity new-uidvalidity)) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
345 ;; uidvalidity clash |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
346 (gnus-delete-file file) |
31717 | 347 (gnus-group-set-parameter gnusgroup 'uidvalidity new-uidvalidity) |
348 t) | |
349 (gnus-group-add-parameter gnusgroup (cons 'uidvalidity new-uidvalidity)) | |
350 t))) | |
351 | |
352 (defun nnimap-before-find-minmax-bugworkaround () | |
353 "Function called before iterating through mailboxes with | |
354 `nnimap-find-minmax-uid'." | |
355 ;; XXX this is for UoW imapd problem, it doesn't notice new mail in | |
356 ;; currently selected mailbox without a re-select/examine. | |
357 (or (null (imap-current-mailbox nnimap-server-buffer)) | |
358 (imap-mailbox-unselect nnimap-server-buffer))) | |
359 | |
360 (defun nnimap-find-minmax-uid (group &optional examine) | |
48588 | 361 "Find lowest and highest active article number in GROUP. |
31717 | 362 If EXAMINE is non-nil the group is selected read-only." |
363 (with-current-buffer nnimap-server-buffer | |
364 (when (imap-mailbox-select group examine) | |
365 (let (minuid maxuid) | |
366 (when (> (imap-mailbox-get 'exists) 0) | |
367 (imap-fetch "1,*" "UID" nil 'nouidfetch) | |
368 (imap-message-map (lambda (uid Uid) | |
369 (setq minuid (if minuid (min minuid uid) uid) | |
370 maxuid (if maxuid (max maxuid uid) uid))) | |
371 'UID)) | |
372 (list (imap-mailbox-get 'exists) minuid maxuid))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
373 |
31717 | 374 (defun nnimap-possibly-change-group (group &optional server) |
375 "Make GROUP the current group, and SERVER the current server." | |
376 (when (nnimap-possibly-change-server server) | |
377 (with-current-buffer nnimap-server-buffer | |
378 (if (or (null group) (imap-current-mailbox-p group)) | |
379 imap-current-mailbox | |
380 (if (imap-mailbox-select group) | |
381 (if (or (nnimap-verify-uidvalidity | |
382 group (or server nnimap-current-server)) | |
383 (zerop (imap-mailbox-get 'exists group)) | |
384 (yes-or-no-p | |
385 (format | |
386 "nnimap: Group %s is not uidvalid. Continue? " group))) | |
387 imap-current-mailbox | |
388 (imap-mailbox-unselect) | |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
32995
diff
changeset
|
389 (error "nnimap: Group %s is not uid-valid" group)) |
31717 | 390 (nnheader-report 'nnimap (imap-error-text))))))) |
391 | |
392 (defun nnimap-replace-whitespace (string) | |
393 "Return STRING with all whitespace replaced with space." | |
394 (when string | |
395 (while (string-match "[\r\n\t]+" string) | |
396 (setq string (replace-match " " t t string))) | |
397 string)) | |
398 | |
399 ;; Required backend functions | |
400 | |
401 (defun nnimap-retrieve-headers-progress () | |
402 "Hook to insert NOV line for current article into `nntp-server-buffer'." | |
403 (and (numberp nnmail-large-newsgroup) | |
404 (zerop (% (incf nnimap-counter) nnimap-progress-how-often)) | |
405 (> nnimap-length nnmail-large-newsgroup) | |
406 (nnheader-message 6 "nnimap: Retrieving headers... %c" | |
407 (nth (/ (% nnimap-counter | |
408 (* (length nnimap-progress-chars) | |
409 nnimap-progress-how-often)) | |
410 nnimap-progress-how-often) | |
411 nnimap-progress-chars))) | |
412 (with-current-buffer nntp-server-buffer | |
413 (let (headers lines chars uid mbx) | |
414 (with-current-buffer nnimap-server-buffer | |
415 (setq uid imap-current-message | |
416 mbx imap-current-mailbox | |
417 headers (nnimap-demule | |
418 (if (imap-capability 'IMAP4rev1) | |
419 ;; xxx don't just use car? alist doesn't contain | |
420 ;; anything else now, but it might... | |
421 (nth 2 (car (imap-message-get uid 'BODYDETAIL))) | |
422 (imap-message-get uid 'RFC822.HEADER))) | |
423 lines (imap-body-lines (imap-message-body imap-current-message)) | |
424 chars (imap-message-get imap-current-message 'RFC822.SIZE))) | |
425 (nnheader-insert-nov | |
426 (with-temp-buffer | |
427 (buffer-disable-undo) | |
428 (insert headers) | |
429 (nnheader-ms-strip-cr) | |
430 (nnheader-fold-continuation-lines) | |
431 (subst-char-in-region (point-min) (point-max) ?\t ? ) | |
432 (let ((head (nnheader-parse-head 'naked))) | |
433 (mail-header-set-number head uid) | |
434 (mail-header-set-chars head chars) | |
435 (mail-header-set-lines head lines) | |
436 (mail-header-set-xref | |
437 head (format "%s %s:%d" (system-name) mbx uid)) | |
438 head)))))) | |
439 | |
440 (defun nnimap-retrieve-which-headers (articles fetch-old) | |
441 "Get a range of articles to fetch based on ARTICLES and FETCH-OLD." | |
442 (with-current-buffer nnimap-server-buffer | |
443 (if (numberp (car-safe articles)) | |
444 (imap-search | |
445 (concat "UID " | |
446 (imap-range-to-message-set | |
447 (gnus-compress-sequence | |
448 (append (gnus-uncompress-sequence | |
449 (and fetch-old | |
450 (cons (if (numberp fetch-old) | |
451 (max 1 (- (car articles) fetch-old)) | |
452 1) | |
453 (1- (car articles))))) | |
454 articles))))) | |
455 (mapcar (lambda (msgid) | |
456 (imap-search | |
457 (format "HEADER Message-Id %s" msgid))) | |
458 articles)))) | |
459 | |
460 (defun nnimap-group-overview-filename (group server) | |
49274
eb2699620e9c
* gnus-agent.el: Don't use `path'.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
48588
diff
changeset
|
461 "Make file name for GROUP on SERVER." |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
462 (let* ((dir (file-name-as-directory (expand-file-name nnimap-directory))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
463 (uidvalidity (gnus-group-get-parameter |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
464 (gnus-group-prefixed-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
465 group (gnus-server-to-method |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
466 (format "nnimap:%s" server))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
467 'uidvalidity)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
468 (name (nnheader-translate-file-chars |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
469 (concat nnimap-nov-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
470 (if (equal server "") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
471 "unnamed" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
472 server) "." group nnimap-nov-file-name-suffix) t)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
473 (nameuid (nnheader-translate-file-chars |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
474 (concat nnimap-nov-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
475 (if (equal server "") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
476 "unnamed" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
477 server) "." group "." uidvalidity |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
478 nnimap-nov-file-name-suffix) t)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
479 (oldfile (if (or nnmail-use-long-file-names |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
480 (file-exists-p (expand-file-name name dir))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
481 (expand-file-name name dir) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
482 (expand-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
483 (mm-encode-coding-string |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
484 (nnheader-replace-chars-in-string name ?. ?/) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
485 nnmail-pathname-coding-system) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
486 dir))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
487 (newfile (if (or nnmail-use-long-file-names |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
488 (file-exists-p (expand-file-name nameuid dir))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
489 (expand-file-name nameuid dir) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
490 (expand-file-name |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
491 (mm-encode-coding-string |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
492 (nnheader-replace-chars-in-string nameuid ?. ?/) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
493 nnmail-pathname-coding-system) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
494 dir)))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
495 (when (and (file-exists-p oldfile) (not (file-exists-p newfile))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
496 (message "nnimap: Upgrading novcache filename...") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
497 (sit-for 1) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
498 (gnus-make-directory (file-name-directory newfile)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
499 (unless (ignore-errors (rename-file oldfile newfile) t) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
500 (if (ignore-errors (copy-file oldfile newfile) t) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
501 (delete-file oldfile) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
502 (error "Can't rename `%s' to `%s'" oldfile newfile)))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
503 newfile)) |
31717 | 504 |
505 (defun nnimap-retrieve-headers-from-file (group server) | |
506 (with-current-buffer nntp-server-buffer | |
507 (let ((nov (nnimap-group-overview-filename group server))) | |
508 (when (file-exists-p nov) | |
509 (mm-insert-file-contents nov) | |
510 (set-buffer-modified-p nil) | |
511 (let ((min (ignore-errors (goto-char (point-min)) | |
512 (read (current-buffer)))) | |
513 (max (ignore-errors (goto-char (point-max)) | |
514 (forward-line -1) | |
515 (read (current-buffer))))) | |
516 (if (and (numberp min) (numberp max)) | |
517 (cons min max) | |
518 ;; junk, remove it, it's saved later | |
519 (erase-buffer) | |
520 nil)))))) | |
521 | |
522 (defun nnimap-retrieve-headers-from-server (articles group server) | |
523 (with-current-buffer nnimap-server-buffer | |
524 (let ((imap-fetch-data-hook '(nnimap-retrieve-headers-progress)) | |
525 (nnimap-length (gnus-range-length articles)) | |
526 (nnimap-counter 0)) | |
527 (imap-fetch (imap-range-to-message-set articles) | |
528 (concat "(UID RFC822.SIZE BODY " | |
529 (let ((headers | |
530 (append '(Subject From Date Message-Id | |
531 References In-Reply-To Xref) | |
532 (copy-sequence | |
533 nnmail-extra-headers)))) | |
534 (if (imap-capability 'IMAP4rev1) | |
535 (format "BODY.PEEK[HEADER.FIELDS %s])" headers) | |
536 (format "RFC822.HEADER.LINES %s)" headers))))) | |
537 (and (numberp nnmail-large-newsgroup) | |
538 (> nnimap-length nnmail-large-newsgroup) | |
539 (nnheader-message 6 "nnimap: Retrieving headers...done"))))) | |
540 | |
541 (defun nnimap-use-nov-p (group server) | |
542 (or gnus-nov-is-evil nnimap-nov-is-evil | |
543 (unless (and (gnus-make-directory | |
544 (file-name-directory | |
545 (nnimap-group-overview-filename group server))) | |
546 (file-writable-p | |
547 (nnimap-group-overview-filename group server))) | |
548 (message "nnimap: Nov cache not writable, %s" | |
549 (nnimap-group-overview-filename group server))))) | |
550 | |
551 (deffoo nnimap-retrieve-headers (articles &optional group server fetch-old) | |
552 (when (nnimap-possibly-change-group group server) | |
553 (with-current-buffer nntp-server-buffer | |
554 (erase-buffer) | |
555 (if (nnimap-use-nov-p group server) | |
556 (nnimap-retrieve-headers-from-server | |
557 (gnus-compress-sequence articles) group server) | |
558 (let (uids cached low high) | |
559 (when (setq uids (nnimap-retrieve-which-headers articles fetch-old) | |
560 low (car uids) | |
561 high (car (last uids))) | |
562 (if (setq cached (nnimap-retrieve-headers-from-file group server)) | |
563 (progn | |
564 ;; fetch articles with uids before cache block | |
565 (when (< low (car cached)) | |
566 (goto-char (point-min)) | |
567 (nnimap-retrieve-headers-from-server | |
568 (cons low (1- (car cached))) group server)) | |
569 ;; fetch articles with uids after cache block | |
570 (when (> high (cdr cached)) | |
571 (goto-char (point-max)) | |
572 (nnimap-retrieve-headers-from-server | |
573 (cons (1+ (cdr cached)) high) group server)) | |
574 (when nnimap-prune-cache | |
575 ;; remove nov's for articles which has expired on server | |
576 (goto-char (point-min)) | |
577 (dolist (uid (gnus-set-difference articles uids)) | |
578 (when (re-search-forward (format "^%d\t" uid) nil t) | |
579 (gnus-delete-line))))) | |
580 ;; nothing cached, fetch whole range from server | |
581 (nnimap-retrieve-headers-from-server | |
582 (cons low high) group server)) | |
583 (when (buffer-modified-p) | |
584 (nnmail-write-region | |
44512
d9d12d6d22cc
(nnimap-retrieve-headers): Don't assume point-min == 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40494
diff
changeset
|
585 (point-min) (point-max) |
d9d12d6d22cc
(nnimap-retrieve-headers): Don't assume point-min == 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40494
diff
changeset
|
586 (nnimap-group-overview-filename group server) nil 'nomesg)) |
31717 | 587 (nnheader-nov-delete-outside-range low high)))) |
588 'nov))) | |
589 | |
590 (defun nnimap-open-connection (server) | |
591 (if (not (imap-open nnimap-address nnimap-server-port nnimap-stream | |
592 nnimap-authenticator nnimap-server-buffer)) | |
593 (nnheader-report 'nnimap "Can't open connection to server %s" server) | |
594 (unless (or (imap-capability 'IMAP4 nnimap-server-buffer) | |
595 (imap-capability 'IMAP4rev1 nnimap-server-buffer)) | |
596 (imap-close nnimap-server-buffer) | |
597 (nnheader-report 'nnimap "Server %s is not IMAP4 compliant" server)) | |
598 (let* ((list (gnus-parse-netrc nnimap-authinfo-file)) | |
599 (port (if nnimap-server-port | |
600 (int-to-string nnimap-server-port) | |
601 "imap")) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
602 (alist (gnus-netrc-machine list (or nnimap-server-address |
31717 | 603 nnimap-address server) |
604 port "imap")) | |
605 (user (gnus-netrc-get alist "login")) | |
606 (passwd (gnus-netrc-get alist "password"))) | |
607 (if (imap-authenticate user passwd nnimap-server-buffer) | |
608 (prog1 | |
609 (push (list server nnimap-server-buffer) | |
610 nnimap-server-buffer-alist) | |
611 (nnimap-possibly-change-server server)) | |
612 (imap-close nnimap-server-buffer) | |
613 (kill-buffer nnimap-server-buffer) | |
614 (nnheader-report 'nnimap "Could not authenticate to %s" server))))) | |
615 | |
616 (deffoo nnimap-open-server (server &optional defs) | |
617 (nnheader-init-server-buffer) | |
618 (if (nnimap-server-opened server) | |
619 t | |
620 (unless (assq 'nnimap-server-buffer defs) | |
621 (push (list 'nnimap-server-buffer (concat " *nnimap* " server)) defs)) | |
622 ;; translate `nnimap-server-address' to `nnimap-address' in defs | |
623 ;; for people that configured nnimap with a very old version | |
624 (unless (assq 'nnimap-address defs) | |
625 (if (assq 'nnimap-server-address defs) | |
626 (push (list 'nnimap-address | |
627 (cadr (assq 'nnimap-server-address defs))) defs) | |
628 (push (list 'nnimap-address server) defs))) | |
629 (nnoo-change-server 'nnimap server defs) | |
630 (with-current-buffer (get-buffer-create nnimap-server-buffer) | |
631 (nnoo-change-server 'nnimap server defs)) | |
632 (or (and nnimap-server-buffer | |
633 (imap-opened nnimap-server-buffer)) | |
634 (nnimap-open-connection server)))) | |
635 | |
636 (deffoo nnimap-server-opened (&optional server) | |
637 "Whether SERVER is opened. | |
638 If SERVER is the current virtual server, and the connection to the | |
639 physical server is alive, this function return a non-nil value. If | |
640 SERVER is nil, it is treated as the current server." | |
641 ;; clean up autologouts?? | |
642 (and (or server nnimap-current-server) | |
643 (nnoo-server-opened 'nnimap (or server nnimap-current-server)) | |
644 (imap-opened (nnimap-get-server-buffer server)))) | |
645 | |
646 (deffoo nnimap-close-server (&optional server) | |
647 "Close connection to server and free all resources connected to it. | |
648 Return nil if the server couldn't be closed for some reason." | |
649 (let ((server (or server nnimap-current-server))) | |
650 (when (or (nnimap-server-opened server) | |
651 (imap-opened (nnimap-get-server-buffer server))) | |
652 (imap-close (nnimap-get-server-buffer server)) | |
653 (kill-buffer (nnimap-get-server-buffer server)) | |
654 (setq nnimap-server-buffer nil | |
655 nnimap-current-server nil | |
656 nnimap-server-buffer-alist | |
657 (delq server nnimap-server-buffer-alist))) | |
658 (nnoo-close-server 'nnimap server))) | |
659 | |
660 (deffoo nnimap-request-close () | |
661 "Close connection to all servers and free all resources that the backend have reserved. | |
662 All buffers that have been created by that | |
663 backend should be killed. (Not the nntp-server-buffer, though.) This | |
664 function is generally only called when Gnus is shutting down." | |
665 (mapcar (lambda (server) (nnimap-close-server (car server))) | |
666 nnimap-server-buffer-alist) | |
667 (setq nnimap-server-buffer-alist nil)) | |
668 | |
669 (deffoo nnimap-status-message (&optional server) | |
670 "This function returns the last error message from server." | |
671 (when (nnimap-possibly-change-server server) | |
672 (nnoo-status-message 'nnimap server))) | |
673 | |
674 (defun nnimap-demule (string) | |
55398
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
675 ;; BEWARE: we used to use string-as-multibyte here which is braindead |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
676 ;; because it will turn accidental emacs-mule-valid byte sequences |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
677 ;; into multibyte chars. --Stef |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
678 (funcall (if (and (fboundp 'string-to-multibyte) |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
679 (subrp (symbol-function 'string-to-multibyte))) |
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
680 'string-to-multibyte |
31717 | 681 'identity) |
682 (or string ""))) | |
683 | |
684 (defun nnimap-callback () | |
685 (remove-hook 'imap-fetch-data-hook 'nnimap-callback) | |
686 (with-current-buffer nnimap-callback-buffer | |
687 (insert | |
688 (with-current-buffer nnimap-server-buffer | |
689 (nnimap-demule | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
690 (if (imap-capability 'IMAP4rev1) |
31717 | 691 ;; xxx don't just use car? alist doesn't contain |
692 ;; anything else now, but it might... | |
693 (nth 2 (car (imap-message-get (imap-current-message) 'BODYDETAIL))) | |
694 (imap-message-get (imap-current-message) 'RFC822))))) | |
695 (nnheader-ms-strip-cr) | |
696 (funcall nnimap-callback-callback-function t))) | |
697 | |
698 (defun nnimap-request-article-part (article part prop &optional | |
699 group server to-buffer detail) | |
700 (when (nnimap-possibly-change-group group server) | |
701 (let ((article (if (stringp article) | |
702 (car-safe (imap-search | |
703 (format "HEADER Message-Id %s" article) | |
704 nnimap-server-buffer)) | |
705 article))) | |
706 (when article | |
707 (gnus-message 10 "nnimap: Fetching (part of) article %d..." article) | |
708 (if (not nnheader-callback-function) | |
709 (with-current-buffer (or to-buffer nntp-server-buffer) | |
710 (erase-buffer) | |
711 (let ((data (imap-fetch article part prop nil | |
712 nnimap-server-buffer))) | |
713 (insert (nnimap-demule (if detail | |
714 (nth 2 (car data)) | |
715 data)))) | |
716 (nnheader-ms-strip-cr) | |
717 (gnus-message 10 "nnimap: Fetching (part of) article %d...done" | |
718 article) | |
719 (if (bobp) | |
720 (nnheader-report 'nnimap "No such article: %s" | |
721 (imap-error-text nnimap-server-buffer)) | |
722 (cons group article))) | |
723 (add-hook 'imap-fetch-data-hook 'nnimap-callback) | |
724 (setq nnimap-callback-callback-function nnheader-callback-function | |
725 nnimap-callback-buffer nntp-server-buffer) | |
726 (imap-fetch-asynch article part nil nnimap-server-buffer) | |
727 (cons group article)))))) | |
728 | |
729 (deffoo nnimap-asynchronous-p () | |
730 t) | |
731 | |
732 (deffoo nnimap-request-article (article &optional group server to-buffer) | |
733 (if (imap-capability 'IMAP4rev1 nnimap-server-buffer) | |
734 (nnimap-request-article-part | |
735 article "BODY.PEEK[]" 'BODYDETAIL group server to-buffer 'detail) | |
736 (nnimap-request-article-part | |
737 article "RFC822.PEEK" 'RFC822 group server to-buffer))) | |
738 | |
739 (deffoo nnimap-request-head (article &optional group server to-buffer) | |
740 (if (imap-capability 'IMAP4rev1 nnimap-server-buffer) | |
741 (nnimap-request-article-part | |
742 article "BODY.PEEK[HEADER]" 'BODYDETAIL group server to-buffer 'detail) | |
743 (nnimap-request-article-part | |
744 article "RFC822.HEADER" 'RFC822.HEADER group server to-buffer))) | |
745 | |
746 (deffoo nnimap-request-body (article &optional group server to-buffer) | |
747 (if (imap-capability 'IMAP4rev1 nnimap-server-buffer) | |
748 (nnimap-request-article-part | |
749 article "BODY.PEEK[TEXT]" 'BODYDETAIL group server to-buffer 'detail) | |
750 (nnimap-request-article-part | |
751 article "RFC822.TEXT.PEEK" 'RFC822.TEXT group server to-buffer))) | |
752 | |
753 (deffoo nnimap-request-group (group &optional server fast) | |
754 (nnimap-request-update-info-internal | |
755 group | |
756 (gnus-get-info (gnus-group-prefixed-name | |
757 group (gnus-server-to-method (format "nnimap:%s" server)))) | |
758 server) | |
759 (when (nnimap-possibly-change-group group server) | |
760 (nnimap-before-find-minmax-bugworkaround) | |
761 (let (info) | |
762 (cond (fast group) | |
763 ((null (setq info (nnimap-find-minmax-uid group t))) | |
764 (nnheader-report 'nnimap "Could not get active info for %s" | |
765 group)) | |
766 (t | |
767 (nnheader-insert "211 %d %d %d %s\n" (or (nth 0 info) 0) | |
768 (max 1 (or (nth 1 info) 1)) | |
769 (or (nth 2 info) 0) group) | |
770 (nnheader-report 'nnimap "Group %s selected" group) | |
771 t))))) | |
772 | |
773 (defun nnimap-close-group (group &optional server) | |
774 (with-current-buffer nnimap-server-buffer | |
775 (when (and (imap-opened) | |
776 (nnimap-possibly-change-group group server)) | |
777 (case nnimap-expunge-on-close | |
778 ('always (imap-mailbox-expunge) | |
779 (imap-mailbox-close)) | |
780 ('ask (if (and (imap-search "DELETED") | |
781 (gnus-y-or-n-p (format | |
782 "Expunge articles in group `%s'? " | |
783 imap-current-mailbox))) | |
784 (progn (imap-mailbox-expunge) | |
785 (imap-mailbox-close)) | |
786 (imap-mailbox-unselect))) | |
787 (t (imap-mailbox-unselect))) | |
788 (not imap-current-mailbox)))) | |
789 | |
790 (defun nnimap-pattern-to-list-arguments (pattern) | |
791 (mapcar (lambda (p) | |
792 (cons (car-safe p) (or (cdr-safe p) p))) | |
793 (if (and (listp pattern) | |
794 (listp (cdr pattern))) | |
795 pattern | |
796 (list pattern)))) | |
797 | |
798 (deffoo nnimap-request-list (&optional server) | |
799 (when (nnimap-possibly-change-server server) | |
800 (with-current-buffer nntp-server-buffer | |
801 (erase-buffer)) | |
802 (gnus-message 5 "nnimap: Generating active list%s..." | |
803 (if (> (length server) 0) (concat " for " server) "")) | |
804 (nnimap-before-find-minmax-bugworkaround) | |
805 (with-current-buffer nnimap-server-buffer | |
806 (dolist (pattern (nnimap-pattern-to-list-arguments nnimap-list-pattern)) | |
807 (dolist (mbx (funcall nnimap-request-list-method | |
808 (cdr pattern) (car pattern))) | |
809 (or (member "\\NoSelect" (imap-mailbox-get 'list-flags mbx)) | |
810 (let ((info (nnimap-find-minmax-uid mbx 'examine))) | |
811 (when info | |
812 (with-current-buffer nntp-server-buffer | |
813 (insert (format "\"%s\" %d %d y\n" | |
814 mbx (or (nth 2 info) 0) | |
815 (max 1 (or (nth 1 info) 1))))))))))) | |
816 (gnus-message 5 "nnimap: Generating active list%s...done" | |
817 (if (> (length server) 0) (concat " for " server) "")) | |
818 t)) | |
819 | |
820 (deffoo nnimap-request-post (&optional server) | |
821 (let ((success t)) | |
822 (dolist (mbx (message-unquote-tokens | |
823 (message-tokenize-header | |
824 (message-fetch-field "Newsgroups") ", ")) success) | |
825 (let ((to-newsgroup (gnus-group-prefixed-name mbx gnus-command-method))) | |
826 (or (gnus-active to-newsgroup) | |
827 (gnus-activate-group to-newsgroup) | |
828 (if (gnus-y-or-n-p (format "No such group: %s. Create it? " | |
829 to-newsgroup)) | |
830 (or (and (gnus-request-create-group | |
831 to-newsgroup gnus-command-method) | |
832 (gnus-activate-group to-newsgroup nil nil | |
833 gnus-command-method)) | |
834 (error "Couldn't create group %s" to-newsgroup))) | |
835 (error "No such group: %s" to-newsgroup)) | |
836 (unless (nnimap-request-accept-article mbx (nth 1 gnus-command-method)) | |
837 (setq success nil)))))) | |
838 | |
839 ;; Optional backend functions | |
840 | |
841 (deffoo nnimap-retrieve-groups (groups &optional server) | |
842 (when (nnimap-possibly-change-server server) | |
843 (gnus-message 5 "nnimap: Checking mailboxes...") | |
844 (with-current-buffer nntp-server-buffer | |
845 (erase-buffer) | |
846 (nnimap-before-find-minmax-bugworkaround) | |
847 (dolist (group groups) | |
848 (gnus-message 7 "nnimap: Checking mailbox %s" group) | |
849 (or (member "\\NoSelect" | |
850 (imap-mailbox-get 'list-flags group nnimap-server-buffer)) | |
851 (let ((info (nnimap-find-minmax-uid group 'examine))) | |
852 (insert (format "\"%s\" %d %d y\n" group | |
853 (or (nth 2 info) 0) | |
854 (max 1 (or (nth 1 info) 1)))))))) | |
855 (gnus-message 5 "nnimap: Checking mailboxes...done") | |
856 'active)) | |
857 | |
858 (deffoo nnimap-request-update-info-internal (group info &optional server) | |
859 (when (nnimap-possibly-change-group group server) | |
860 (when info;; xxx what does this mean? should we create a info? | |
861 (with-current-buffer nnimap-server-buffer | |
862 (gnus-message 5 "nnimap: Updating info for %s..." | |
863 (gnus-info-group info)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
864 |
31717 | 865 (when (nnimap-mark-permanent-p 'read) |
866 (let (seen unseen) | |
867 ;; read info could contain articles marked unread by other | |
868 ;; imap clients! we correct this | |
869 (setq seen (gnus-uncompress-range (gnus-info-read info)) | |
870 unseen (imap-search "UNSEEN UNDELETED") | |
871 seen (gnus-set-difference seen unseen) | |
872 ;; seen might lack articles marked as read by other | |
873 ;; imap clients! we correct this | |
874 seen (append seen (imap-search "SEEN")) | |
875 ;; remove dupes | |
876 seen (sort seen '<) | |
877 seen (gnus-compress-sequence seen t) | |
878 ;; we can't return '(1) since this isn't a "list of ranges", | |
879 ;; and we can't return '((1)) since g-list-of-unread-articles | |
880 ;; is buggy so we return '((1 . 1)). | |
881 seen (if (and (integerp (car seen)) | |
882 (null (cdr seen))) | |
883 (list (cons (car seen) (car seen))) | |
884 seen)) | |
885 (gnus-info-set-read info seen))) | |
886 | |
887 (mapcar (lambda (pred) | |
888 (when (and (nnimap-mark-permanent-p (cdr pred)) | |
889 (member (nnimap-mark-to-flag (cdr pred)) | |
890 (imap-mailbox-get 'flags))) | |
891 (gnus-info-set-marks | |
892 info | |
893 (nnimap-update-alist-soft | |
894 (cdr pred) | |
895 (gnus-compress-sequence | |
896 (imap-search (nnimap-mark-to-predicate (cdr pred)))) | |
897 (gnus-info-marks info)) | |
898 t))) | |
899 gnus-article-mark-lists) | |
900 | |
901 ;; nnimap mark dormant article as ticked too (for other clients) | |
902 ;; so we remove that mark for gnus since we support dormant | |
903 (gnus-info-set-marks | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
904 info |
31717 | 905 (nnimap-update-alist-soft |
906 'tick | |
907 (gnus-remove-from-range | |
908 (cdr-safe (assoc 'tick (gnus-info-marks info))) | |
909 (cdr-safe (assoc 'dormant (gnus-info-marks info)))) | |
910 (gnus-info-marks info)) | |
911 t) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
912 |
31717 | 913 (gnus-message 5 "nnimap: Updating info for %s...done" |
914 (gnus-info-group info)) | |
915 | |
916 info)))) | |
917 | |
918 (deffoo nnimap-request-type (group &optional article) | |
919 (if (and nnimap-news-groups (string-match nnimap-news-groups group)) | |
920 'news | |
921 'mail)) | |
922 | |
923 (deffoo nnimap-request-set-mark (group actions &optional server) | |
924 (when (nnimap-possibly-change-group group server) | |
925 (with-current-buffer nnimap-server-buffer | |
926 (let (action) | |
927 (gnus-message 7 "nnimap: Setting marks in %s..." group) | |
928 (while (setq action (pop actions)) | |
929 (let ((range (nth 0 action)) | |
930 (what (nth 1 action)) | |
931 (cmdmarks (nth 2 action)) | |
932 marks) | |
933 ;; cache flags are pointless on the server | |
934 (setq cmdmarks (delq 'cache cmdmarks)) | |
935 ;; flag dormant articles as ticked | |
936 (if (memq 'dormant cmdmarks) | |
937 (setq cmdmarks (cons 'tick cmdmarks))) | |
938 ;; remove stuff we are forbidden to store | |
939 (mapcar (lambda (mark) | |
940 (if (imap-message-flag-permanent-p | |
941 (nnimap-mark-to-flag mark)) | |
942 (setq marks (cons mark marks)))) | |
943 cmdmarks) | |
944 (when (and range marks) | |
945 (cond ((eq what 'del) | |
946 (imap-message-flags-del | |
947 (imap-range-to-message-set range) | |
948 (nnimap-mark-to-flag marks nil t))) | |
949 ((eq what 'add) | |
950 (imap-message-flags-add | |
951 (imap-range-to-message-set range) | |
952 (nnimap-mark-to-flag marks nil t))) | |
953 ((eq what 'set) | |
954 (imap-message-flags-set | |
955 (imap-range-to-message-set range) | |
956 (nnimap-mark-to-flag marks nil t))))))) | |
957 (gnus-message 7 "nnimap: Setting marks in %s...done" group)))) | |
958 nil) | |
959 | |
960 (defun nnimap-split-fancy () | |
961 "Like nnmail-split-fancy, but uses nnimap-split-fancy." | |
962 (let ((nnmail-split-fancy nnimap-split-fancy)) | |
963 (nnmail-split-fancy))) | |
964 | |
965 (defun nnimap-split-to-groups (rules) | |
966 ;; tries to match all rules in nnimap-split-rule against content of | |
967 ;; nntp-server-buffer, returns a list of groups that matched. | |
968 (with-current-buffer nntp-server-buffer | |
969 ;; Fold continuation lines. | |
970 (goto-char (point-min)) | |
971 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) | |
972 (replace-match " " t t)) | |
973 (if (functionp rules) | |
974 (funcall rules) | |
975 (let (to-groups regrepp) | |
976 (catch 'split-done | |
977 (dolist (rule rules to-groups) | |
978 (let ((group (car rule)) | |
979 (regexp (cadr rule))) | |
980 (goto-char (point-min)) | |
981 (when (and (if (stringp regexp) | |
982 (progn | |
983 (setq regrepp (string-match "\\\\[0-9&]" group)) | |
984 (re-search-forward regexp nil t)) | |
985 (funcall regexp group)) | |
986 ;; Don't enter the article into the same group twice. | |
987 (not (assoc group to-groups))) | |
988 (push (if regrepp | |
989 (nnmail-expand-newtext group) | |
990 group) | |
991 to-groups) | |
992 (or nnimap-split-crosspost | |
993 (throw 'split-done to-groups)))))))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
994 |
31717 | 995 (defun nnimap-assoc-match (key alist) |
996 (let (element) | |
997 (while (and alist (not element)) | |
998 (if (string-match (car (car alist)) key) | |
999 (setq element (car alist))) | |
1000 (setq alist (cdr alist))) | |
1001 element)) | |
1002 | |
1003 (defun nnimap-split-find-rule (server inbox) | |
1004 (if (and (listp nnimap-split-rule) (listp (car nnimap-split-rule)) | |
1005 (list (cdar nnimap-split-rule)) (listp (cadar nnimap-split-rule))) | |
1006 ;; extended format | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
1007 (cadr (nnimap-assoc-match inbox (cdr (nnimap-assoc-match |
31717 | 1008 server nnimap-split-rule)))) |
1009 nnimap-split-rule)) | |
1010 | |
1011 (defun nnimap-split-find-inbox (server) | |
1012 (if (listp nnimap-split-inbox) | |
1013 nnimap-split-inbox | |
1014 (list nnimap-split-inbox))) | |
1015 | |
1016 (defun nnimap-split-articles (&optional group server) | |
1017 (when (nnimap-possibly-change-server server) | |
1018 (with-current-buffer nnimap-server-buffer | |
1019 (let (rule inbox removeorig (inboxes (nnimap-split-find-inbox server))) | |
1020 ;; iterate over inboxes | |
1021 (while (and (setq inbox (pop inboxes)) | |
1022 (nnimap-possibly-change-group inbox));; SELECT | |
1023 ;; find split rule for this server / inbox | |
1024 (when (setq rule (nnimap-split-find-rule server inbox)) | |
1025 ;; iterate over articles | |
1026 (dolist (article (imap-search nnimap-split-predicate)) | |
1027 (when (nnimap-request-head article) | |
1028 ;; copy article to right group(s) | |
1029 (setq removeorig nil) | |
1030 (dolist (to-group (nnimap-split-to-groups rule)) | |
1031 (if (imap-message-copy (number-to-string article) | |
1032 to-group nil 'nocopyuid) | |
1033 (progn | |
1034 (message "IMAP split moved %s:%s:%d to %s" server inbox | |
1035 article to-group) | |
1036 (setq removeorig t) | |
1037 ;; Add the group-art list to the history list. | |
1038 (push (list (cons to-group 0)) nnmail-split-history)) | |
1039 (message "IMAP split failed to move %s:%s:%d to %s" server | |
1040 inbox article to-group))) | |
1041 ;; remove article if it was successfully copied somewhere | |
1042 (and removeorig | |
1043 (imap-message-flags-add (format "%d" article) | |
1044 "\\Seen \\Deleted"))))) | |
1045 (when (imap-mailbox-select inbox);; just in case | |
1046 ;; todo: UID EXPUNGE (if available) to remove splitted articles | |
1047 (imap-mailbox-expunge) | |
1048 (imap-mailbox-close))) | |
1049 t)))) | |
1050 | |
1051 (deffoo nnimap-request-scan (&optional group server) | |
1052 (nnimap-split-articles group server)) | |
1053 | |
1054 (deffoo nnimap-request-newgroups (date &optional server) | |
1055 (when (nnimap-possibly-change-server server) | |
1056 (with-current-buffer nntp-server-buffer | |
1057 (gnus-message 5 "nnimap: Listing subscribed mailboxes%s%s..." | |
1058 (if (> (length server) 0) " on " "") server) | |
1059 (erase-buffer) | |
1060 (nnimap-before-find-minmax-bugworkaround) | |
1061 (dolist (pattern (nnimap-pattern-to-list-arguments | |
1062 nnimap-list-pattern)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
1063 (dolist (mbx (imap-mailbox-lsub "*" (car pattern) nil |
31717 | 1064 nnimap-server-buffer)) |
1065 (or (catch 'found | |
1066 (dolist (mailbox (imap-mailbox-get 'list-flags mbx | |
1067 nnimap-server-buffer)) | |
1068 (if (string= (downcase mailbox) "\\noselect") | |
1069 (throw 'found t))) | |
1070 nil) | |
1071 (let ((info (nnimap-find-minmax-uid mbx 'examine))) | |
1072 (when info | |
1073 (insert (format "\"%s\" %d %d y\n" | |
1074 mbx (or (nth 2 info) 0) | |
1075 (max 1 (or (nth 1 info) 1))))))))) | |
1076 (gnus-message 5 "nnimap: Listing subscribed mailboxes%s%s...done" | |
1077 (if (> (length server) 0) " on " "") server)) | |
1078 t)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
1079 |
31717 | 1080 (deffoo nnimap-request-create-group (group &optional server args) |
1081 (when (nnimap-possibly-change-server server) | |
1082 (or (imap-mailbox-status group 'uidvalidity nnimap-server-buffer) | |
1083 (imap-mailbox-create group nnimap-server-buffer)))) | |
1084 | |
1085 (defun nnimap-time-substract (time1 time2) | |
1086 "Return TIME for TIME1 - TIME2." | |
1087 (let* ((ms (- (car time1) (car time2))) | |
1088 (ls (- (nth 1 time1) (nth 1 time2)))) | |
1089 (if (< ls 0) | |
1090 (list (- ms 1) (+ (expt 2 16) ls)) | |
1091 (list ms ls)))) | |
1092 | |
1093 (defun nnimap-date-days-ago (daysago) | |
1094 "Return date, in format \"3-Aug-1998\", for DAYSAGO days ago." | |
40494
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1095 (let* ((time (nnimap-time-substract (current-time) (days-to-time daysago))) |
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1096 (date (format-time-string |
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1097 (format "%%d-%s-%%Y" |
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1098 (capitalize (car (rassoc (nth 4 (decode-time time)) |
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1099 parse-time-months)))) |
4c7be17ecf55
(nnimap-date-days-ago): Defeat locale.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
1100 time))) |
31717 | 1101 (if (eq ?0 (string-to-char date)) |
1102 (substring date 1) | |
1103 date))) | |
1104 | |
1105 (defun nnimap-request-expire-articles-progress () | |
1106 (gnus-message 5 "nnimap: Marking article %d for deletion..." | |
1107 imap-current-message)) | |
1108 | |
1109 ;; Notice that we don't actually delete anything, we just mark them deleted. | |
1110 (deffoo nnimap-request-expire-articles (articles group &optional server force) | |
1111 (let ((artseq (gnus-compress-sequence articles))) | |
1112 (when (and artseq (nnimap-possibly-change-group group server)) | |
1113 (with-current-buffer nnimap-server-buffer | |
1114 (if force | |
1115 (and (imap-message-flags-add | |
1116 (imap-range-to-message-set artseq) "\\Deleted") | |
1117 (setq articles nil)) | |
1118 (let ((days (or (and nnmail-expiry-wait-function | |
1119 (funcall nnmail-expiry-wait-function group)) | |
1120 nnmail-expiry-wait))) | |
1121 (cond ((eq days 'immediate) | |
1122 (and (imap-message-flags-add | |
1123 (imap-range-to-message-set artseq) "\\Deleted") | |
1124 (setq articles nil))) | |
1125 ((numberp days) | |
1126 (let ((oldarts (imap-search | |
1127 (format "UID %s NOT SINCE %s" | |
1128 (imap-range-to-message-set artseq) | |
1129 (nnimap-date-days-ago days)))) | |
1130 (imap-fetch-data-hook | |
1131 '(nnimap-request-expire-articles-progress))) | |
1132 (and oldarts | |
1133 (imap-message-flags-add | |
1134 (imap-range-to-message-set | |
1135 (gnus-compress-sequence oldarts)) | |
1136 "\\Deleted") | |
1137 (setq articles (gnus-set-difference | |
1138 articles oldarts))))))))))) | |
1139 ;; return articles not deleted | |
1140 articles) | |
1141 | |
1142 (deffoo nnimap-request-move-article (article group server | |
1143 accept-form &optional last) | |
1144 (when (nnimap-possibly-change-server server) | |
1145 (save-excursion | |
1146 (let ((buf (get-buffer-create " *nnimap move*")) | |
1147 (nnimap-current-move-article article) | |
1148 (nnimap-current-move-group group) | |
1149 (nnimap-current-move-server nnimap-current-server) | |
1150 result) | |
1151 (and (nnimap-request-article article group server) | |
1152 (save-excursion | |
1153 (set-buffer buf) | |
1154 (buffer-disable-undo (current-buffer)) | |
1155 (insert-buffer-substring nntp-server-buffer) | |
1156 (setq result (eval accept-form)) | |
1157 (kill-buffer buf) | |
1158 result) | |
1159 (nnimap-request-expire-articles (list article) group server t)) | |
1160 result)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
1161 |
31717 | 1162 (deffoo nnimap-request-accept-article (group &optional server last) |
1163 (when (nnimap-possibly-change-server server) | |
1164 (let (uid) | |
1165 (if (setq uid | |
1166 (if (string= nnimap-current-server nnimap-current-move-server) | |
1167 ;; moving article within same server, speed it up... | |
1168 (and (nnimap-possibly-change-group | |
1169 nnimap-current-move-group) | |
1170 (imap-message-copy (number-to-string | |
1171 nnimap-current-move-article) | |
1172 group 'dontcreate nil | |
1173 nnimap-server-buffer)) | |
1174 (with-current-buffer (current-buffer) | |
1175 (goto-char (point-min)) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1176 ;; remove any 'From blabla' lines, some IMAP servers |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1177 ;; reject the entire message otherwise. |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1178 (when (looking-at "^From[^:]") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1179 (kill-region (point) (progn (forward-line) (point)))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1180 ;; turn into rfc822 format (\r\n eol's) |
31717 | 1181 (while (search-forward "\n" nil t) |
1182 (replace-match "\r\n"))) | |
1183 ;; this 'or' is for Cyrus server bug | |
1184 (or (null (imap-current-mailbox nnimap-server-buffer)) | |
1185 (imap-mailbox-unselect nnimap-server-buffer)) | |
1186 (imap-message-append group (current-buffer) nil nil | |
1187 nnimap-server-buffer))) | |
1188 (cons group (nth 1 uid)) | |
1189 (nnheader-report 'nnimap (imap-error-text nnimap-server-buffer)))))) | |
1190 | |
1191 (deffoo nnimap-request-delete-group (group force &optional server) | |
1192 (when (nnimap-possibly-change-server server) | |
1193 (with-current-buffer nnimap-server-buffer | |
1194 (if force | |
1195 (or (null (imap-mailbox-status group 'uidvalidity)) | |
1196 (imap-mailbox-delete group)) | |
1197 ;; UNSUBSCRIBE? | |
1198 t)))) | |
1199 | |
1200 (deffoo nnimap-request-rename-group (group new-name &optional server) | |
1201 (when (nnimap-possibly-change-server server) | |
1202 (imap-mailbox-rename group new-name nnimap-server-buffer))) | |
1203 | |
1204 (defun nnimap-expunge (mailbox server) | |
1205 (when (nnimap-possibly-change-group mailbox server) | |
1206 (imap-mailbox-expunge nnimap-server-buffer))) | |
1207 | |
1208 (defun nnimap-acl-get (mailbox server) | |
1209 (when (nnimap-possibly-change-server server) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1210 (and (imap-capability 'ACL nnimap-server-buffer) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
32153
diff
changeset
|
1211 (imap-mailbox-acl-get mailbox nnimap-server-buffer)))) |
31717 | 1212 |
1213 (defun nnimap-acl-edit (mailbox method old-acls new-acls) | |
1214 (when (nnimap-possibly-change-server (cadr method)) | |
1215 (unless (imap-capability 'ACL nnimap-server-buffer) | |
1216 (error "Your server does not support ACL editing")) | |
1217 (with-current-buffer nnimap-server-buffer | |
1218 ;; delete all removed identifiers | |
1219 (mapcar (lambda (old-acl) | |
1220 (unless (assoc (car old-acl) new-acls) | |
1221 (or (imap-mailbox-acl-delete (car old-acl) mailbox) | |
1222 (error "Can't delete ACL for %s" (car old-acl))))) | |
1223 old-acls) | |
1224 ;; set all changed acl's | |
1225 (mapcar (lambda (new-acl) | |
1226 (let ((new-rights (cdr new-acl)) | |
1227 (old-rights (cdr (assoc (car new-acl) old-acls)))) | |
1228 (unless (and old-rights new-rights | |
1229 (string= old-rights new-rights)) | |
1230 (or (imap-mailbox-acl-set (car new-acl) new-rights mailbox) | |
1231 (error "Can't set ACL for %s to %s" (car new-acl) | |
1232 new-rights))))) | |
1233 new-acls) | |
1234 t))) | |
1235 | |
1236 | |
1237 ;;; Internal functions | |
1238 | |
1239 ;; | |
1240 ;; This is confusing. | |
1241 ;; | |
1242 ;; mark => read, tick, draft, reply etc | |
1243 ;; flag => "\\Seen", "\\Flagged", "\\Draft", "gnus-expire" etc | |
1244 ;; predicate => "SEEN", "FLAGGED", "DRAFT", "KEYWORD gnus-expire" etc | |
1245 ;; | |
1246 ;; Mark should not really contain 'read since it's not a "mark" in the Gnus | |
1247 ;; world, but we cheat. Mark == gnus-article-mark-lists + '(read . read). | |
1248 ;; | |
1249 | |
1250 (defconst nnimap-mark-to-predicate-alist | |
1251 (mapcar | |
1252 (lambda (pair) ; cdr is the mark | |
1253 (or (assoc (cdr pair) | |
1254 '((read . "SEEN") | |
1255 (tick . "FLAGGED") | |
1256 (draft . "DRAFT") | |
1257 (reply . "ANSWERED"))) | |
1258 (cons (cdr pair) | |
1259 (format "KEYWORD gnus-%s" (symbol-name (cdr pair)))))) | |
1260 (cons '(read . read) gnus-article-mark-lists))) | |
1261 | |
1262 (defun nnimap-mark-to-predicate (pred) | |
1263 "Convert a Gnus mark (a symbol such as read, tick, expire) to a IMAP predicate. | |
1264 This is a string such as \"SEEN\", \"FLAGGED\", \"KEYWORD gnus-expire\", | |
1265 to be used within a IMAP SEARCH query." | |
1266 (cdr (assq pred nnimap-mark-to-predicate-alist))) | |
1267 | |
1268 (defconst nnimap-mark-to-flag-alist | |
1269 (mapcar | |
1270 (lambda (pair) | |
1271 (or (assoc (cdr pair) | |
1272 '((read . "\\Seen") | |
1273 (tick . "\\Flagged") | |
1274 (draft . "\\Draft") | |
1275 (reply . "\\Answered"))) | |
1276 (cons (cdr pair) | |
1277 (format "gnus-%s" (symbol-name (cdr pair)))))) | |
1278 (cons '(read . read) gnus-article-mark-lists))) | |
1279 | |
1280 (defun nnimap-mark-to-flag-1 (preds) | |
1281 (if (and (not (null preds)) (listp preds)) | |
1282 (cons (nnimap-mark-to-flag (car preds)) | |
1283 (nnimap-mark-to-flag (cdr preds))) | |
1284 (cdr (assoc preds nnimap-mark-to-flag-alist)))) | |
1285 | |
1286 (defun nnimap-mark-to-flag (preds &optional always-list make-string) | |
1287 "Convert a Gnus mark (a symbol such as read, tick, expire) to a IMAP flag. | |
1288 This is a string such as \"\\Seen\", \"\\Flagged\", \"gnus-expire\", to | |
1289 be used in a STORE FLAGS command." | |
1290 (let ((result (nnimap-mark-to-flag-1 preds))) | |
1291 (setq result (if (and (or make-string always-list) | |
1292 (not (listp result))) | |
1293 (list result) | |
1294 result)) | |
1295 (if make-string | |
1296 (mapconcat (lambda (flag) | |
1297 (if (listp flag) | |
1298 (mapconcat 'identity flag " ") | |
1299 flag)) | |
1300 result " ") | |
1301 result))) | |
1302 | |
1303 (defun nnimap-mark-permanent-p (mark &optional group) | |
1304 "Return t iff MARK can be permanently (between IMAP sessions) saved on articles, in GROUP." | |
1305 (imap-message-flag-permanent-p (nnimap-mark-to-flag mark))) | |
1306 | |
1307 (defun nnimap-remassoc (key alist) | |
1308 "Delete by side effect any elements of LIST whose car is `equal' to KEY. | |
1309 The modified LIST is returned. If the first member | |
1310 of LIST has a car that is `equal' to KEY, there is no way to remove it | |
1311 by side effect; therefore, write `(setq foo (remassoc key foo))' to be | |
1312 sure of changing the value of `foo'." | |
1313 (when alist | |
1314 (if (equal key (caar alist)) | |
1315 (cdr alist) | |
1316 (setcdr alist (nnimap-remassoc key (cdr alist))) | |
1317 alist))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49274
diff
changeset
|
1318 |
31717 | 1319 (defun nnimap-update-alist-soft (key value alist) |
1320 (if value | |
1321 (cons (cons key value) (nnimap-remassoc key alist)) | |
1322 (nnimap-remassoc key alist))) | |
1323 | |
1324 (when nnimap-debug | |
1325 (require 'trace) | |
1326 (buffer-disable-undo (get-buffer-create nnimap-debug)) | |
1327 (mapcar (lambda (f) (trace-function-background f nnimap-debug)) | |
1328 '( | |
1329 nnimap-possibly-change-server | |
1330 nnimap-verify-uidvalidity | |
1331 nnimap-find-minmax-uid | |
1332 nnimap-before-find-minmax-bugworkaround | |
1333 nnimap-possibly-change-group | |
1334 ;;nnimap-replace-whitespace | |
1335 nnimap-retrieve-headers-progress | |
1336 nnimap-retrieve-which-headers | |
1337 nnimap-group-overview-filename | |
1338 nnimap-retrieve-headers-from-file | |
1339 nnimap-retrieve-headers-from-server | |
1340 nnimap-retrieve-headers | |
1341 nnimap-open-connection | |
1342 nnimap-open-server | |
1343 nnimap-server-opened | |
1344 nnimap-close-server | |
1345 nnimap-request-close | |
1346 nnimap-status-message | |
1347 ;;nnimap-demule | |
1348 nnimap-request-article-part | |
1349 nnimap-request-article | |
1350 nnimap-request-head | |
1351 nnimap-request-body | |
1352 nnimap-request-group | |
1353 nnimap-close-group | |
1354 nnimap-pattern-to-list-arguments | |
1355 nnimap-request-list | |
1356 nnimap-request-post | |
1357 nnimap-retrieve-groups | |
1358 nnimap-request-update-info-internal | |
1359 nnimap-request-type | |
1360 nnimap-request-set-mark | |
1361 nnimap-split-to-groups | |
1362 nnimap-split-find-rule | |
1363 nnimap-split-find-inbox | |
1364 nnimap-split-articles | |
1365 nnimap-request-scan | |
1366 nnimap-request-newgroups | |
1367 nnimap-request-create-group | |
1368 nnimap-time-substract | |
1369 nnimap-date-days-ago | |
1370 nnimap-request-expire-articles-progress | |
1371 nnimap-request-expire-articles | |
1372 nnimap-request-move-article | |
1373 nnimap-request-accept-article | |
1374 nnimap-request-delete-group | |
1375 nnimap-request-rename-group | |
1376 gnus-group-nnimap-expunge | |
1377 gnus-group-nnimap-edit-acl | |
1378 gnus-group-nnimap-edit-acl-done | |
1379 nnimap-group-mode-hook | |
1380 nnimap-mark-to-predicate | |
1381 nnimap-mark-to-flag-1 | |
1382 nnimap-mark-to-flag | |
1383 nnimap-mark-permanent-p | |
1384 nnimap-remassoc | |
1385 nnimap-update-alist-soft | |
1386 ))) | |
1387 | |
1388 (provide 'nnimap) | |
1389 | |
55398
dd7a1cf22d3d
(nnimap-demule): Avoid string-as-multibyte.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1390 ;; arch-tag: 2b001f20-3ff9-4094-a0ad-46807c1ba70b |
31717 | 1391 ;;; nnimap.el ends here |