Mercurial > emacs
annotate lisp/gnus/imap.el @ 66573:e65b759c6906
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-630
Merge from gnus--rel--5.10
Patches applied:
* gnus--rel--5.10 (patch 149-151)
- Merge from emacs--cvs-trunk--0
- Update from CVS
2005-10-27 Reiner Steib <Reiner.Steib@gmx.de>
* lisp/gnus/flow-fill.el (fill-flowed-encode-tests): Restore trailing
whitespace removed in revision 7.8. Use concatenated string to
protect trailing whitespace.
2005-10-27 Jouni K Seppanen <jks@iki.fi> (tiny change)
* lisp/gnus/nnimap.el (nnimap-search-uids-not-since-is-evil): Add variable.
(nnimap-request-expire-articles): Use it to avoid sending 'UID
SEARCH UID ... NOT SINCE' queries, for inefficient servers like
Courier IMAP ("some version from 2004"). Mostly based on similar
code in the same function.
2005-10-26 Katsumi Yamaoka <yamaoka@jpl.org>
* lisp/gnus/message.el (message-display-completion-list): New function.
(message-expand-group): Use it; make sure the Completions buffer
is modifiable.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 31 Oct 2005 07:07:28 +0000 |
parents | 68bb9e8a5390 |
children | 28264c86d408 |
rev | line source |
---|---|
31717 | 1 ;;; imap.el --- imap library |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Simon Josefsson <jas@pdc.kth.se> | |
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 | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
31717 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; imap.el is a elisp library providing an interface for talking to | |
29 ;; IMAP servers. | |
30 ;; | |
31 ;; imap.el is roughly divided in two parts, one that parses IMAP | |
32 ;; responses from the server and storing data into buffer-local | |
33 ;; variables, and one for utility functions which send commands to | |
34 ;; server, waits for an answer, and return information. The latter | |
35 ;; part is layered on top of the previous. | |
36 ;; | |
37 ;; The imap.el API consist of the following functions, other functions | |
38 ;; in this file should not be called directly and the result of doing | |
39 ;; so are at best undefined. | |
40 ;; | |
41 ;; Global commands: | |
42 ;; | |
43 ;; imap-open, imap-opened, imap-authenticate, imap-close, | |
44 ;; imap-capability, imap-namespace, imap-error-text | |
45 ;; | |
46 ;; Mailbox commands: | |
47 ;; | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
48 ;; imap-mailbox-get, imap-mailbox-map, imap-current-mailbox, |
31717 | 49 ;; imap-current-mailbox-p, imap-search, imap-mailbox-select, |
50 ;; imap-mailbox-examine, imap-mailbox-unselect, imap-mailbox-expunge | |
51 ;; imap-mailbox-close, imap-mailbox-create, imap-mailbox-delete | |
52 ;; imap-mailbox-rename, imap-mailbox-lsub, imap-mailbox-list | |
53 ;; imap-mailbox-subscribe, imap-mailbox-unsubscribe, imap-mailbox-status | |
54 ;; imap-mailbox-acl-get, imap-mailbox-acl-set, imap-mailbox-acl-delete | |
55 ;; | |
56 ;; Message commands: | |
57 ;; | |
58 ;; imap-fetch-asynch, imap-fetch, | |
59 ;; imap-current-message, imap-list-to-message-set, | |
60 ;; imap-message-get, imap-message-map | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
61 ;; imap-message-envelope-date, imap-message-envelope-subject, |
31717 | 62 ;; imap-message-envelope-from, imap-message-envelope-sender, |
63 ;; imap-message-envelope-reply-to, imap-message-envelope-to, | |
64 ;; imap-message-envelope-cc, imap-message-envelope-bcc | |
65 ;; imap-message-envelope-in-reply-to, imap-message-envelope-message-id | |
66 ;; imap-message-body, imap-message-flag-permanent-p | |
67 ;; imap-message-flags-set, imap-message-flags-del | |
68 ;; imap-message-flags-add, imap-message-copyuid | |
69 ;; imap-message-copy, imap-message-appenduid | |
70 ;; imap-message-append, imap-envelope-from | |
71 ;; imap-body-lines | |
72 ;; | |
59289 | 73 ;; It is my hope that these commands should be pretty self |
31717 | 74 ;; explanatory for someone that know IMAP. All functions have |
75 ;; additional documentation on how to invoke them. | |
76 ;; | |
77 ;; imap.el support RFC1730/2060 (IMAP4/IMAP4rev1), implemented IMAP | |
78 ;; extensions are RFC2195 (CRAM-MD5), RFC2086 (ACL), RFC2342 | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
79 ;; (NAMESPACE), RFC2359 (UIDPLUS), the IMAP-part of RFC2595 (STARTTLS, |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
80 ;; LOGINDISABLED) (with use of external library starttls.el and |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
81 ;; program starttls) and the GSSAPI / kerberos V4 sections of RFC1731 |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
82 ;; (with use of external program `imtest'). It also take advantage |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
83 ;; the UNSELECT extension in Cyrus IMAPD. |
31717 | 84 ;; |
85 ;; Without the work of John McClary Prevost and Jim Radford this library | |
86 ;; would not have seen the light of day. Many thanks. | |
87 ;; | |
88 ;; This is a transcript of short interactive session for demonstration | |
89 ;; purposes. | |
90 ;; | |
91 ;; (imap-open "my.mail.server") | |
92 ;; => " *imap* my.mail.server:0" | |
93 ;; | |
94 ;; The rest are invoked with current buffer as the buffer returned by | |
95 ;; `imap-open'. It is possible to do all without this, but it would | |
96 ;; look ugly here since `buffer' is always the last argument for all | |
97 ;; imap.el API functions. | |
98 ;; | |
99 ;; (imap-authenticate "myusername" "mypassword") | |
100 ;; => auth | |
101 ;; | |
102 ;; (imap-mailbox-lsub "*") | |
103 ;; => ("INBOX.sentmail" "INBOX.private" "INBOX.draft" "INBOX.spam") | |
104 ;; | |
105 ;; (imap-mailbox-list "INBOX.n%") | |
106 ;; => ("INBOX.namedroppers" "INBOX.nnimap" "INBOX.ntbugtraq") | |
107 ;; | |
108 ;; (imap-mailbox-select "INBOX.nnimap") | |
109 ;; => "INBOX.nnimap" | |
110 ;; | |
111 ;; (imap-mailbox-get 'exists) | |
112 ;; => 166 | |
113 ;; | |
114 ;; (imap-mailbox-get 'uidvalidity) | |
115 ;; => "908992622" | |
116 ;; | |
117 ;; (imap-search "FLAGGED SINCE 18-DEC-98") | |
118 ;; => (235 236) | |
119 ;; | |
120 ;; (imap-fetch 235 "RFC822.PEEK" 'RFC822) | |
121 ;; => "X-Sieve: cmu-sieve 1.3^M\nX-Username: <jas@pdc.kth.se>^M\r...." | |
122 ;; | |
123 ;; Todo: | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
124 ;; |
31717 | 125 ;; o Parse UIDs as strings? We need to overcome the 28 bit limit somehow. |
126 ;; o Don't use `read' at all (important places already fixed) | |
127 ;; o Accept list of articles instead of message set string in most | |
128 ;; imap-message-* functions. | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
129 ;; o Send strings as literal if they contain, e.g., ". |
31717 | 130 ;; |
131 ;; Revision history: | |
132 ;; | |
133 ;; - 19991218 added starttls/digest-md5 patch, | |
134 ;; by Daiki Ueno <ueno@ueda.info.waseda.ac.jp> | |
135 ;; NB! you need SLIM for starttls.el and digest-md5.el | |
136 ;; - 19991023 commited to pgnus | |
137 ;; | |
138 | |
139 ;;; Code: | |
140 | |
141 (eval-when-compile (require 'cl)) | |
142 (eval-and-compile | |
143 (autoload 'base64-decode-string "base64") | |
144 (autoload 'base64-encode-string "base64") | |
145 (autoload 'starttls-open-stream "starttls") | |
146 (autoload 'starttls-negotiate "starttls") | |
147 (autoload 'digest-md5-parse-digest-challenge "digest-md5") | |
148 (autoload 'digest-md5-digest-response "digest-md5") | |
149 (autoload 'digest-md5-digest-uri "digest-md5") | |
150 (autoload 'digest-md5-challenge "digest-md5") | |
151 (autoload 'rfc2104-hash "rfc2104") | |
152 (autoload 'md5 "md5") | |
153 (autoload 'utf7-encode "utf7") | |
154 (autoload 'utf7-decode "utf7") | |
155 (autoload 'format-spec "format-spec") | |
33299
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
156 (autoload 'format-spec-make "format-spec") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
157 (autoload 'open-tls-stream "tls") |
33299
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
158 ;; Avoid use gnus-point-at-eol so we're independent of Gnus. These |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
159 ;; days we have point-at-eol anyhow. |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
160 (if (fboundp 'point-at-eol) |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
161 (defalias 'imap-point-at-eol 'point-at-eol) |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
162 (defun imap-point-at-eol () |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
163 (save-excursion |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
164 (end-of-line) |
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
165 (point))))) |
31717 | 166 |
167 ;; User variables. | |
168 | |
169 (defgroup imap nil | |
170 "Low-level IMAP issues." | |
171 :version "21.1" | |
172 :group 'mail) | |
173 | |
174 (defcustom imap-kerberos4-program '("imtest -m kerberos_v4 -u %l -p %p %s" | |
175 "imtest -kp %s %p") | |
176 "List of strings containing commands for Kerberos 4 authentication. | |
177 %s is replaced with server hostname, %p with port to connect to, and | |
178 %l with the value of `imap-default-user'. The program should accept | |
179 IMAP commands on stdin and return responses to stdout. Each entry in | |
180 the list is tried until a successful connection is made." | |
181 :group 'imap | |
182 :type '(repeat string)) | |
183 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
184 (defcustom imap-gssapi-program (list |
66454
9082bf778ad8
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
185 (concat "gsasl %s %p " |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
186 "--mechanism GSSAPI " |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
187 "--authentication-id %l") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
188 "imtest -m gssapi -u %l -p %p %s") |
31717 | 189 "List of strings containing commands for GSSAPI (krb5) authentication. |
190 %s is replaced with server hostname, %p with port to connect to, and | |
191 %l with the value of `imap-default-user'. The program should accept | |
192 IMAP commands on stdin and return responses to stdout. Each entry in | |
193 the list is tried until a successful connection is made." | |
194 :group 'imap | |
195 :type '(repeat string)) | |
196 | |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
197 (defcustom imap-ssl-program '("openssl s_client -quiet -ssl3 -connect %s:%p" |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
198 "openssl s_client -quiet -ssl2 -connect %s:%p" |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
199 "s_client -quiet -ssl3 -connect %s:%p" |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
200 "s_client -quiet -ssl2 -connect %s:%p") |
31717 | 201 "A string, or list of strings, containing commands for SSL connections. |
202 Within a string, %s is replaced with the server address and %p with | |
203 port number on server. The program should accept IMAP commands on | |
204 stdin and return responses to stdout. Each entry in the list is tried | |
205 until a successful connection is made." | |
206 :group 'imap | |
207 :type '(choice string | |
208 (repeat string))) | |
209 | |
210 (defcustom imap-shell-program '("ssh %s imapd" | |
211 "rsh %s imapd" | |
212 "ssh %g ssh %s imapd" | |
213 "rsh %g rsh %s imapd") | |
214 "A list of strings, containing commands for IMAP connection. | |
215 Within a string, %s is replaced with the server address, %p with port | |
216 number on server, %g with `imap-shell-host', and %l with | |
217 `imap-default-user'. The program should read IMAP commands from stdin | |
218 and write IMAP response to stdout. Each entry in the list is tried | |
219 until a successful connection is made." | |
220 :group 'imap | |
221 :type '(repeat string)) | |
222 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
223 (defcustom imap-process-connection-type nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
224 "*Value for `process-connection-type' to use for Kerberos4, GSSAPI and SSL. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
225 The `process-connection-type' variable control type of device |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
226 used to communicate with subprocesses. Values are nil to use a |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
227 pipe, or t or `pty' to use a pty. The value has no effect if the |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
228 system has no ptys or if all ptys are busy: then a pipe is used |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
229 in any case. The value takes effect when a IMAP server is |
57153
497f0d2ca551
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-558
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
230 opened, changing it after that has no effect." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59289
diff
changeset
|
231 :version "22.1" |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
232 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
233 :type 'boolean) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
234 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
235 (defcustom imap-use-utf7 t |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
236 "If non-nil, do utf7 encoding/decoding of mailbox names. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
237 Since the UTF7 decoding currently only decodes into ISO-8859-1 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
238 characters, you may disable this decoding if you need to access UTF7 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
239 encoded mailboxes which doesn't translate into ISO-8859-1." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
240 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
241 :type 'boolean) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
242 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
243 (defcustom imap-log nil |
60028
681d4e4ca613
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
244 "If non-nil, a imap session trace is placed in *imap-log* buffer. |
681d4e4ca613
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
245 Note that username, passwords and other privacy sensitive |
681d4e4ca613
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
246 information (such as e-mail) may be stored in the *imap-log* |
681d4e4ca613
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
247 buffer. It is not written to disk, however. Do not enable this |
681d4e4ca613
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
248 variable unless you are comfortable with that." |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
249 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
250 :type 'boolean) |
31717 | 251 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
252 (defcustom imap-debug nil |
60161
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
60028
diff
changeset
|
253 "If non-nil, random debug spews are placed in *imap-debug* buffer. |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
60028
diff
changeset
|
254 Note that username, passwords and other privacy sensitive |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
60028
diff
changeset
|
255 information (such as e-mail) may be stored in the *imap-debug* |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
60028
diff
changeset
|
256 buffer. It is not written to disk, however. Do not enable this |
b070535d2416
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-111
Miles Bader <miles@gnu.org>
parents:
60028
diff
changeset
|
257 variable unless you are comfortable with that." |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
258 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
259 :type 'boolean) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
260 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
261 (defcustom imap-shell-host "gateway" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
262 "Hostname of rlogin proxy." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
263 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
264 :type 'string) |
31717 | 265 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
266 (defcustom imap-default-user (user-login-name) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
267 "Default username to use." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
268 :group 'imap |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
269 :type 'string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
270 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
271 (defcustom imap-read-timeout (if (string-match |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
272 "windows-nt\\|os/2\\|emx\\|cygwin" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
273 (symbol-name system-type)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
274 1.0 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
275 0.1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
276 "*How long to wait between checking for the end of output. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
277 Shorter values mean quicker response, but is more CPU intensive." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
278 :type 'number |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
279 :group 'imap) |
31717 | 280 |
57581
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
281 (defcustom imap-store-password nil |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
282 "If non-nil, store session password without promting." |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
283 :group 'imap |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
284 :type 'boolean) |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
285 |
31717 | 286 ;; Various variables. |
287 | |
288 (defvar imap-fetch-data-hook nil | |
289 "Hooks called after receiving each FETCH response.") | |
290 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
291 (defvar imap-streams '(gssapi kerberos4 starttls tls ssl network shell) |
31717 | 292 "Priority of streams to consider when opening connection to server.") |
293 | |
294 (defvar imap-stream-alist | |
295 '((gssapi imap-gssapi-stream-p imap-gssapi-open) | |
296 (kerberos4 imap-kerberos4-stream-p imap-kerberos4-open) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
297 (tls imap-tls-p imap-tls-open) |
31717 | 298 (ssl imap-ssl-p imap-ssl-open) |
299 (network imap-network-p imap-network-open) | |
300 (shell imap-shell-p imap-shell-open) | |
301 (starttls imap-starttls-p imap-starttls-open)) | |
302 "Definition of network streams. | |
303 | |
47129
dd529e3b965b
(imap-authenticator-alist, imap-stream-alist, imap-continuation): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
304 \(NAME CHECK OPEN) |
31717 | 305 |
306 NAME names the stream, CHECK is a function returning non-nil if the | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
307 server support the stream and OPEN is a function for opening the |
31717 | 308 stream.") |
309 | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
310 (defvar imap-authenticators '(gssapi |
31717 | 311 kerberos4 |
312 digest-md5 | |
313 cram-md5 | |
314 login | |
315 anonymous) | |
316 "Priority of authenticators to consider when authenticating to server.") | |
317 | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
318 (defvar imap-authenticator-alist |
31717 | 319 '((gssapi imap-gssapi-auth-p imap-gssapi-auth) |
320 (kerberos4 imap-kerberos4-auth-p imap-kerberos4-auth) | |
321 (cram-md5 imap-cram-md5-p imap-cram-md5-auth) | |
322 (login imap-login-p imap-login-auth) | |
323 (anonymous imap-anonymous-p imap-anonymous-auth) | |
324 (digest-md5 imap-digest-md5-p imap-digest-md5-auth)) | |
325 "Definition of authenticators. | |
326 | |
47129
dd529e3b965b
(imap-authenticator-alist, imap-stream-alist, imap-continuation): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
327 \(NAME CHECK AUTHENTICATE) |
31717 | 328 |
329 NAME names the authenticator. CHECK is a function returning non-nil if | |
330 the server support the authenticator and AUTHENTICATE is a function | |
47129
dd529e3b965b
(imap-authenticator-alist, imap-stream-alist, imap-continuation): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
331 for doing the actual authentication.") |
31717 | 332 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
333 (defvar imap-error nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
334 "Error codes from the last command.") |
31717 | 335 |
59289 | 336 ;; Internal constants. Change these and die. |
31717 | 337 |
338 (defconst imap-default-port 143) | |
339 (defconst imap-default-ssl-port 993) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
340 (defconst imap-default-tls-port 993) |
31717 | 341 (defconst imap-default-stream 'network) |
342 (defconst imap-coding-system-for-read 'binary) | |
343 (defconst imap-coding-system-for-write 'binary) | |
344 (defconst imap-local-variables '(imap-server | |
345 imap-port | |
346 imap-client-eol | |
347 imap-server-eol | |
348 imap-auth | |
349 imap-stream | |
350 imap-username | |
351 imap-password | |
352 imap-current-mailbox | |
353 imap-current-target-mailbox | |
354 imap-message-data | |
355 imap-capability | |
356 imap-namespace | |
357 imap-state | |
358 imap-reached-tag | |
359 imap-failed-tags | |
360 imap-tag | |
361 imap-process | |
362 imap-calculate-literal-size-first | |
363 imap-mailbox-data)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
364 (defconst imap-log-buffer "*imap-log*") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
365 (defconst imap-debug-buffer "*imap-debug*") |
31717 | 366 |
367 ;; Internal variables. | |
368 | |
369 (defvar imap-stream nil) | |
370 (defvar imap-auth nil) | |
371 (defvar imap-server nil) | |
372 (defvar imap-port nil) | |
373 (defvar imap-username nil) | |
374 (defvar imap-password nil) | |
375 (defvar imap-calculate-literal-size-first nil) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
376 (defvar imap-state 'closed |
31717 | 377 "IMAP state. |
378 Valid states are `closed', `initial', `nonauth', `auth', `selected' | |
379 and `examine'.") | |
380 | |
381 (defvar imap-server-eol "\r\n" | |
382 "The EOL string sent from the server.") | |
383 | |
384 (defvar imap-client-eol "\r\n" | |
385 "The EOL string we send to the server.") | |
386 | |
387 (defvar imap-current-mailbox nil | |
388 "Current mailbox name.") | |
389 | |
390 (defvar imap-current-target-mailbox nil | |
391 "Current target mailbox for COPY and APPEND commands.") | |
392 | |
393 (defvar imap-mailbox-data nil | |
394 "Obarray with mailbox data.") | |
395 | |
396 (defvar imap-mailbox-prime 997 | |
397 "Length of imap-mailbox-data.") | |
398 | |
399 (defvar imap-current-message nil | |
400 "Current message number.") | |
401 | |
402 (defvar imap-message-data nil | |
403 "Obarray with message data.") | |
404 | |
405 (defvar imap-message-prime 997 | |
406 "Length of imap-message-data.") | |
407 | |
408 (defvar imap-capability nil | |
409 "Capability for server.") | |
410 | |
411 (defvar imap-namespace nil | |
412 "Namespace for current server.") | |
413 | |
414 (defvar imap-reached-tag 0 | |
415 "Lower limit on command tags that have been parsed.") | |
416 | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
417 (defvar imap-failed-tags nil |
31717 | 418 "Alist of tags that failed. |
419 Each element is a list with four elements; tag (a integer), response | |
420 state (a symbol, `OK', `NO' or `BAD'), response code (a string), and | |
421 human readable response text (a string).") | |
422 | |
423 (defvar imap-tag 0 | |
424 "Command tag number.") | |
425 | |
426 (defvar imap-process nil | |
427 "Process.") | |
428 | |
429 (defvar imap-continuation nil | |
430 "Non-nil indicates that the server emitted a continuation request. | |
47129
dd529e3b965b
(imap-authenticator-alist, imap-stream-alist, imap-continuation): Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
42205
diff
changeset
|
431 The actual value is really the text on the continuation line.") |
31717 | 432 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
433 (defvar imap-callbacks nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
434 "List of response tags and callbacks, on the form `(number . function)'. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
435 The function should take two arguments, the first the IMAP tag and the |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
436 second the status (OK, NO, BAD etc) of the command.") |
31717 | 437 |
438 | |
439 ;; Utility functions: | |
440 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
441 (defun imap-remassoc (key alist) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
442 "Delete by side effect any elements of LIST whose car is `equal' to KEY. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
443 The modified LIST is returned. If the first member |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
444 of LIST has a car that is `equal' to KEY, there is no way to remove it |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
445 by side effect; therefore, write `(setq foo (remassoc key foo))' to be |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
446 sure of changing the value of `foo'." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
447 (when alist |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
448 (if (equal key (caar alist)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
449 (cdr alist) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
450 (setcdr alist (imap-remassoc key (cdr alist))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
451 alist))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
452 |
31717 | 453 (defsubst imap-disable-multibyte () |
454 "Enable multibyte in the current buffer." | |
455 (when (fboundp 'set-buffer-multibyte) | |
456 (set-buffer-multibyte nil))) | |
457 | |
458 (defsubst imap-utf7-encode (string) | |
459 (if imap-use-utf7 | |
460 (and string | |
461 (condition-case () | |
462 (utf7-encode string t) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
463 (error (message |
31717 | 464 "imap: Could not UTF7 encode `%s', using it unencoded..." |
465 string) | |
466 string))) | |
467 string)) | |
468 | |
469 (defsubst imap-utf7-decode (string) | |
470 (if imap-use-utf7 | |
471 (and string | |
472 (condition-case () | |
473 (utf7-decode string t) | |
474 (error (message | |
475 "imap: Could not UTF7 decode `%s', using it undecoded..." | |
476 string) | |
477 string))) | |
478 string)) | |
479 | |
480 (defsubst imap-ok-p (status) | |
481 (if (eq status 'OK) | |
482 t | |
483 (setq imap-error status) | |
484 nil)) | |
485 | |
486 (defun imap-error-text (&optional buffer) | |
487 (with-current-buffer (or buffer (current-buffer)) | |
488 (nth 3 (car imap-failed-tags)))) | |
489 | |
490 | |
491 ;; Server functions; stream stuff: | |
492 | |
493 (defun imap-kerberos4-stream-p (buffer) | |
494 (imap-capability 'AUTH=KERBEROS_V4 buffer)) | |
495 | |
496 (defun imap-kerberos4-open (name buffer server port) | |
497 (let ((cmds imap-kerberos4-program) | |
498 cmd done) | |
499 (while (and (not done) (setq cmd (pop cmds))) | |
500 (message "Opening Kerberos 4 IMAP connection with `%s'..." cmd) | |
501 (erase-buffer) | |
502 (let* ((port (or port imap-default-port)) | |
503 (coding-system-for-read imap-coding-system-for-read) | |
504 (coding-system-for-write imap-coding-system-for-write) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
505 (process-connection-type imap-process-connection-type) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
506 (process (start-process |
31717 | 507 name buffer shell-file-name shell-command-switch |
508 (format-spec | |
509 cmd | |
510 (format-spec-make | |
511 ?s server | |
512 ?p (number-to-string port) | |
513 ?l imap-default-user)))) | |
514 response) | |
515 (when process | |
516 (with-current-buffer buffer | |
517 (setq imap-client-eol "\n" | |
518 imap-calculate-literal-size-first t) | |
519 (while (and (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
520 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
31717 | 521 (goto-char (point-min)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
522 ;; Athena IMTEST can output SSL verify errors |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
523 (or (while (looking-at "^verify error:num=") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
524 (forward-line)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
525 t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
526 (or (while (looking-at "^TLS connection established") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
527 (forward-line)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
528 t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
529 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
530 (or (while (looking-at "^C:") |
31717 | 531 (forward-line)) |
532 t) | |
533 ;; cyrus 1.6 imtest print "S: " before server greeting | |
534 (or (not (looking-at "S: ")) | |
535 (forward-char 3) | |
536 t) | |
537 (not (and (imap-parse-greeting) | |
538 ;; success in imtest < 1.6: | |
539 (or (re-search-forward | |
540 "^__\\(.*\\)__\n" nil t) | |
541 ;; success in imtest 1.6: | |
542 (re-search-forward | |
543 "^\\(Authenticat.*\\)" nil t)) | |
544 (setq response (match-string 1))))) | |
545 (accept-process-output process 1) | |
546 (sit-for 1)) | |
547 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
548 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 549 (imap-disable-multibyte) |
550 (buffer-disable-undo) | |
551 (goto-char (point-max)) | |
552 (insert-buffer-substring buffer))) | |
553 (erase-buffer) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
554 (message "Opening Kerberos 4 IMAP connection with `%s'...%s" cmd |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
555 (if response (concat "done, " response) "failed")) |
31717 | 556 (if (and response (let ((case-fold-search nil)) |
557 (not (string-match "failed" response)))) | |
558 (setq done process) | |
559 (if (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
560 (imap-send-command "LOGOUT")) |
31717 | 561 (delete-process process) |
562 nil))))) | |
563 done)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
564 |
31717 | 565 (defun imap-gssapi-stream-p (buffer) |
566 (imap-capability 'AUTH=GSSAPI buffer)) | |
567 | |
568 (defun imap-gssapi-open (name buffer server port) | |
569 (let ((cmds imap-gssapi-program) | |
570 cmd done) | |
571 (while (and (not done) (setq cmd (pop cmds))) | |
572 (message "Opening GSSAPI IMAP connection with `%s'..." cmd) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
573 (erase-buffer) |
31717 | 574 (let* ((port (or port imap-default-port)) |
575 (coding-system-for-read imap-coding-system-for-read) | |
576 (coding-system-for-write imap-coding-system-for-write) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
577 (process-connection-type imap-process-connection-type) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
578 (process (start-process |
31717 | 579 name buffer shell-file-name shell-command-switch |
580 (format-spec | |
581 cmd | |
582 (format-spec-make | |
583 ?s server | |
584 ?p (number-to-string port) | |
585 ?l imap-default-user)))) | |
586 response) | |
587 (when process | |
588 (with-current-buffer buffer | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
589 (setq imap-client-eol "\n" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
590 imap-calculate-literal-size-first t) |
31717 | 591 (while (and (memq (process-status process) '(open run)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
592 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
31717 | 593 (goto-char (point-min)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
594 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
595 (or (while (looking-at "^C:") |
31717 | 596 (forward-line)) |
597 t) | |
598 ;; cyrus 1.6 imtest print "S: " before server greeting | |
599 (or (not (looking-at "S: ")) | |
600 (forward-char 3) | |
601 t) | |
66454
9082bf778ad8
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
602 ;; GNU SASL may print 'Trying ...' first. |
9082bf778ad8
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
603 (or (not (looking-at "Trying ")) |
9082bf778ad8
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
604 (forward-line) |
9082bf778ad8
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
64754
diff
changeset
|
605 t) |
31717 | 606 (not (and (imap-parse-greeting) |
607 ;; success in imtest 1.6: | |
608 (re-search-forward | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
609 (concat "^\\(\\(Authenticat.*\\)\\|\\(" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
610 "Client authentication " |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
611 "finished.*\\)\\)") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
612 nil t) |
31717 | 613 (setq response (match-string 1))))) |
614 (accept-process-output process 1) | |
615 (sit-for 1)) | |
616 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
617 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 618 (imap-disable-multibyte) |
619 (buffer-disable-undo) | |
620 (goto-char (point-max)) | |
621 (insert-buffer-substring buffer))) | |
622 (erase-buffer) | |
623 (message "GSSAPI IMAP connection: %s" (or response "failed")) | |
624 (if (and response (let ((case-fold-search nil)) | |
625 (not (string-match "failed" response)))) | |
626 (setq done process) | |
627 (if (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
628 (imap-send-command "LOGOUT")) |
31717 | 629 (delete-process process) |
630 nil))))) | |
631 done)) | |
632 | |
633 (defun imap-ssl-p (buffer) | |
634 nil) | |
635 | |
636 (defun imap-ssl-open (name buffer server port) | |
637 "Open a SSL connection to server." | |
638 (let ((cmds (if (listp imap-ssl-program) imap-ssl-program | |
639 (list imap-ssl-program))) | |
640 cmd done) | |
641 (while (and (not done) (setq cmd (pop cmds))) | |
642 (message "imap: Opening SSL connection with `%s'..." cmd) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
643 (erase-buffer) |
31717 | 644 (let* ((port (or port imap-default-ssl-port)) |
645 (coding-system-for-read imap-coding-system-for-read) | |
646 (coding-system-for-write imap-coding-system-for-write) | |
62943
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
647 (process-connection-type imap-process-connection-type) |
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
648 (set-process-query-on-exit-flag |
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
649 (if (fboundp 'set-process-query-on-exit-flag) |
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
650 'set-process-query-on-exit-flag |
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
651 'process-kill-without-query)) |
31717 | 652 process) |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
653 (when (progn |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
654 (setq process (start-process |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
655 name buffer shell-file-name |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
656 shell-command-switch |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
657 (format-spec cmd |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
658 (format-spec-make |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
659 ?s server |
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
660 ?p (number-to-string port))))) |
62943
11d53dd5abd9
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents:
60161
diff
changeset
|
661 (funcall set-process-query-on-exit-flag process nil) |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
662 process) |
31717 | 663 (with-current-buffer buffer |
664 (goto-char (point-min)) | |
665 (while (and (memq (process-status process) '(open run)) | |
49993
a40d0a292281
* nnfolder.el (nnfolder-request-accept-article): Don't use
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
49474
diff
changeset
|
666 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
31717 | 667 (goto-char (point-max)) |
668 (forward-line -1) | |
669 (not (imap-parse-greeting))) | |
670 (accept-process-output process 1) | |
671 (sit-for 1)) | |
672 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
673 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 674 (imap-disable-multibyte) |
675 (buffer-disable-undo) | |
676 (goto-char (point-max)) | |
677 (insert-buffer-substring buffer))) | |
678 (erase-buffer) | |
679 (when (memq (process-status process) '(open run)) | |
680 (setq done process)))))) | |
681 (if done | |
682 (progn | |
683 (message "imap: Opening SSL connection with `%s'...done" cmd) | |
684 done) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
685 (message "imap: Opening SSL connection with `%s'...failed" cmd) |
31717 | 686 nil))) |
687 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
688 (defun imap-tls-p (buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
689 nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
690 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
691 (defun imap-tls-open (name buffer server port) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
692 (let* ((port (or port imap-default-tls-port)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
693 (coding-system-for-read imap-coding-system-for-read) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
694 (coding-system-for-write imap-coding-system-for-write) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
695 (process (open-tls-stream name buffer server port))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
696 (when process |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
697 (while (and (memq (process-status process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
698 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
699 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
700 (forward-line -1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
701 (not (imap-parse-greeting))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
702 (accept-process-output process 1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
703 (sit-for 1)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
704 (and imap-log |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
705 (with-current-buffer (get-buffer-create imap-log-buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
706 (imap-disable-multibyte) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
707 (buffer-disable-undo) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
708 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
709 (insert-buffer-substring buffer))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
710 (when (memq (process-status process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
711 process)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
712 |
31717 | 713 (defun imap-network-p (buffer) |
714 t) | |
715 | |
716 (defun imap-network-open (name buffer server port) | |
717 (let* ((port (or port imap-default-port)) | |
718 (coding-system-for-read imap-coding-system-for-read) | |
719 (coding-system-for-write imap-coding-system-for-write) | |
720 (process (open-network-stream name buffer server port))) | |
721 (when process | |
722 (while (and (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
723 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
31717 | 724 (goto-char (point-min)) |
725 (not (imap-parse-greeting))) | |
726 (accept-process-output process 1) | |
727 (sit-for 1)) | |
728 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
729 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 730 (imap-disable-multibyte) |
731 (buffer-disable-undo) | |
732 (goto-char (point-max)) | |
733 (insert-buffer-substring buffer))) | |
734 (when (memq (process-status process) '(open run)) | |
735 process)))) | |
736 | |
737 (defun imap-shell-p (buffer) | |
738 nil) | |
739 | |
740 (defun imap-shell-open (name buffer server port) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
741 (let ((cmds (if (listp imap-shell-program) imap-shell-program |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
742 (list imap-shell-program))) |
31717 | 743 cmd done) |
744 (while (and (not done) (setq cmd (pop cmds))) | |
745 (message "imap: Opening IMAP connection with `%s'..." cmd) | |
746 (setq imap-client-eol "\n") | |
747 (let* ((port (or port imap-default-port)) | |
748 (coding-system-for-read imap-coding-system-for-read) | |
749 (coding-system-for-write imap-coding-system-for-write) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
750 (process (start-process |
31717 | 751 name buffer shell-file-name shell-command-switch |
752 (format-spec | |
753 cmd | |
754 (format-spec-make | |
755 ?s server | |
756 ?g imap-shell-host | |
757 ?p (number-to-string port) | |
758 ?l imap-default-user))))) | |
759 (when process | |
760 (while (and (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
761 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
762 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
763 (forward-line -1) |
31717 | 764 (not (imap-parse-greeting))) |
765 (accept-process-output process 1) | |
766 (sit-for 1)) | |
767 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
768 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 769 (imap-disable-multibyte) |
770 (buffer-disable-undo) | |
771 (goto-char (point-max)) | |
772 (insert-buffer-substring buffer))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
773 (erase-buffer) |
31717 | 774 (when (memq (process-status process) '(open run)) |
775 (setq done process))))) | |
776 (if done | |
777 (progn | |
778 (message "imap: Opening IMAP connection with `%s'...done" cmd) | |
779 done) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
780 (message "imap: Opening IMAP connection with `%s'...failed" cmd) |
31717 | 781 nil))) |
782 | |
783 (defun imap-starttls-p (buffer) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
784 (imap-capability 'STARTTLS buffer)) |
31717 | 785 |
786 (defun imap-starttls-open (name buffer server port) | |
787 (let* ((port (or port imap-default-port)) | |
788 (coding-system-for-read imap-coding-system-for-read) | |
789 (coding-system-for-write imap-coding-system-for-write) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
790 (process (starttls-open-stream name buffer server port)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
791 done tls-info) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
792 (message "imap: Connecting with STARTTLS...") |
31717 | 793 (when process |
794 (while (and (memq (process-status process) '(open run)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
795 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
796 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
797 (forward-line -1) |
31717 | 798 (not (imap-parse-greeting))) |
799 (accept-process-output process 1) | |
800 (sit-for 1)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
801 (imap-send-command "STARTTLS") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
802 (while (and (memq (process-status process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
803 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
804 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
805 (forward-line -1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
806 (not (re-search-forward "[0-9]+ OK.*\r?\n" nil t))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
807 (accept-process-output process 1) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
808 (sit-for 1)) |
31717 | 809 (and imap-log |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
810 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 811 (buffer-disable-undo) |
812 (goto-char (point-max)) | |
813 (insert-buffer-substring buffer))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
814 (when (and (setq tls-info (starttls-negotiate process)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
815 (memq (process-status process) '(open run))) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
816 (setq done process))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
817 (if (stringp tls-info) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
818 (message "imap: STARTTLS info: %s" tls-info)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
819 (message "imap: Connecting with STARTTLS...%s" (if done "done" "failed")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
820 done)) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
821 |
31717 | 822 ;; Server functions; authenticator stuff: |
823 | |
824 (defun imap-interactive-login (buffer loginfunc) | |
825 "Login to server in BUFFER. | |
826 LOGINFUNC is passed a username and a password, it should return t if | |
48588 | 827 it where successful authenticating itself to the server, nil otherwise. |
31717 | 828 Returns t if login was successful, nil otherwise." |
829 (with-current-buffer buffer | |
41516
52c9115c94be
(imap-interactive-login, imap-open, imap-authenticate):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39064
diff
changeset
|
830 (make-local-variable 'imap-username) |
52c9115c94be
(imap-interactive-login, imap-open, imap-authenticate):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39064
diff
changeset
|
831 (make-local-variable 'imap-password) |
31717 | 832 (let (user passwd ret) |
833 ;; (condition-case () | |
834 (while (or (not user) (not passwd)) | |
835 (setq user (or imap-username | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
836 (read-from-minibuffer |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
837 (concat "IMAP username for " imap-server |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
838 " (using stream `" (symbol-name imap-stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
839 "'): ") |
31717 | 840 (or user imap-default-user)))) |
841 (setq passwd (or imap-password | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
842 (read-passwd |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
843 (concat "IMAP password for " user "@" |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
844 imap-server " (using authenticator `" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
845 (symbol-name imap-auth) "'): ")))) |
31717 | 846 (when (and user passwd) |
847 (if (funcall loginfunc user passwd) | |
848 (progn | |
849 (setq ret t | |
850 imap-username user) | |
57581
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
851 (when (and (not imap-password) |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
852 (or imap-store-password |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
853 (y-or-n-p "Store password for this session? "))) |
645f020dcc8a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-626
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
854 (setq imap-password passwd))) |
31717 | 855 (message "Login failed...") |
856 (setq passwd nil) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
857 (setq imap-password nil) |
31717 | 858 (sit-for 1)))) |
859 ;; (quit (with-current-buffer buffer | |
860 ;; (setq user nil | |
861 ;; passwd nil))) | |
862 ;; (error (with-current-buffer buffer | |
863 ;; (setq user nil | |
864 ;; passwd nil)))) | |
865 ret))) | |
866 | |
867 (defun imap-gssapi-auth-p (buffer) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
868 (eq imap-stream 'gssapi)) |
31717 | 869 |
870 (defun imap-gssapi-auth (buffer) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
871 (message "imap: Authenticating using GSSAPI...%s" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
872 (if (eq imap-stream 'gssapi) "done" "failed")) |
31717 | 873 (eq imap-stream 'gssapi)) |
874 | |
875 (defun imap-kerberos4-auth-p (buffer) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
876 (and (imap-capability 'AUTH=KERBEROS_V4 buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
877 (eq imap-stream 'kerberos4))) |
31717 | 878 |
879 (defun imap-kerberos4-auth (buffer) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
880 (message "imap: Authenticating using Kerberos 4...%s" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
881 (if (eq imap-stream 'kerberos4) "done" "failed")) |
31717 | 882 (eq imap-stream 'kerberos4)) |
883 | |
884 (defun imap-cram-md5-p (buffer) | |
885 (imap-capability 'AUTH=CRAM-MD5 buffer)) | |
886 | |
887 (defun imap-cram-md5-auth (buffer) | |
888 "Login to server using the AUTH CRAM-MD5 method." | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
889 (message "imap: Authenticating using CRAM-MD5...") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
890 (let ((done (imap-interactive-login |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
891 buffer |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
892 (lambda (user passwd) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
893 (imap-ok-p |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
894 (imap-send-command-wait |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
895 (list |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
896 "AUTHENTICATE CRAM-MD5" |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
897 (lambda (challenge) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
898 (let* ((decoded (base64-decode-string challenge)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
899 (hash (rfc2104-hash 'md5 64 16 passwd decoded)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
900 (response (concat user " " hash)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
901 (encoded (base64-encode-string response))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
902 encoded))))))))) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
903 (if done |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
904 (message "imap: Authenticating using CRAM-MD5...done") |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
905 (message "imap: Authenticating using CRAM-MD5...failed")))) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
906 |
31717 | 907 (defun imap-login-p (buffer) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
908 (and (not (imap-capability 'LOGINDISABLED buffer)) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
909 (not (imap-capability 'X-LOGIN-CMD-DISABLED buffer)))) |
31717 | 910 |
911 (defun imap-login-auth (buffer) | |
912 "Login to server using the LOGIN command." | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
913 (message "imap: Plaintext authentication...") |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
914 (imap-interactive-login buffer |
31717 | 915 (lambda (user passwd) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
916 (imap-ok-p (imap-send-command-wait |
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
917 (concat "LOGIN \"" user "\" \"" |
31717 | 918 passwd "\"")))))) |
919 | |
920 (defun imap-anonymous-p (buffer) | |
921 t) | |
922 | |
923 (defun imap-anonymous-auth (buffer) | |
48588 | 924 (message "imap: Logging in anonymously...") |
31717 | 925 (with-current-buffer buffer |
926 (imap-ok-p (imap-send-command-wait | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
927 (concat "LOGIN anonymous \"" (concat (user-login-name) "@" |
31717 | 928 (system-name)) "\""))))) |
929 | |
930 (defun imap-digest-md5-p (buffer) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
931 (and (imap-capability 'AUTH=DIGEST-MD5 buffer) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
932 (condition-case () |
31717 | 933 (require 'digest-md5) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
934 (error nil)))) |
31717 | 935 |
936 (defun imap-digest-md5-auth (buffer) | |
937 "Login to server using the AUTH DIGEST-MD5 method." | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
938 (message "imap: Authenticating using DIGEST-MD5...") |
31717 | 939 (imap-interactive-login |
940 buffer | |
941 (lambda (user passwd) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
942 (let ((tag |
31717 | 943 (imap-send-command |
944 (list | |
945 "AUTHENTICATE DIGEST-MD5" | |
946 (lambda (challenge) | |
947 (digest-md5-parse-digest-challenge | |
948 (base64-decode-string challenge)) | |
949 (let* ((digest-uri | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
950 (digest-md5-digest-uri |
31717 | 951 "imap" (digest-md5-challenge 'realm))) |
952 (response | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
953 (digest-md5-digest-response |
31717 | 954 user passwd digest-uri))) |
955 (base64-encode-string response 'no-line-break)))) | |
956 ))) | |
957 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE)) | |
958 nil | |
959 (setq imap-continuation nil) | |
960 (imap-send-command-1 "") | |
961 (imap-ok-p (imap-wait-for-tag tag))))))) | |
962 | |
963 ;; Server functions: | |
964 | |
965 (defun imap-open-1 (buffer) | |
966 (with-current-buffer buffer | |
967 (erase-buffer) | |
968 (setq imap-current-mailbox nil | |
969 imap-current-message nil | |
970 imap-state 'initial | |
971 imap-process (condition-case () | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
972 (funcall (nth 2 (assq imap-stream |
31717 | 973 imap-stream-alist)) |
974 "imap" buffer imap-server imap-port) | |
975 ((error quit) nil))) | |
976 (when imap-process | |
977 (set-process-filter imap-process 'imap-arrival-filter) | |
978 (set-process-sentinel imap-process 'imap-sentinel) | |
979 (while (and (eq imap-state 'initial) | |
980 (memq (process-status imap-process) '(open run))) | |
981 (message "Waiting for response from %s..." imap-server) | |
982 (accept-process-output imap-process 1)) | |
983 (message "Waiting for response from %s...done" imap-server) | |
984 (and (memq (process-status imap-process) '(open run)) | |
985 imap-process)))) | |
986 | |
987 (defun imap-open (server &optional port stream auth buffer) | |
988 "Open a IMAP connection to host SERVER at PORT returning a buffer. | |
989 If PORT is unspecified, a default value is used (143 except | |
990 for SSL which use 993). | |
991 STREAM indicates the stream to use, see `imap-streams' for available | |
992 streams. If nil, it choices the best stream the server is capable of. | |
993 AUTH indicates authenticator to use, see `imap-authenticators' for | |
994 available authenticators. If nil, it choices the best stream the | |
995 server is capable of. | |
996 BUFFER can be a buffer or a name of a buffer, which is created if | |
48588 | 997 necessary. If nil, the buffer name is generated." |
31717 | 998 (setq buffer (or buffer (format " *imap* %s:%d" server (or port 0)))) |
999 (with-current-buffer (get-buffer-create buffer) | |
1000 (if (imap-opened buffer) | |
1001 (imap-close buffer)) | |
41516
52c9115c94be
(imap-interactive-login, imap-open, imap-authenticate):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39064
diff
changeset
|
1002 (mapcar 'make-local-variable imap-local-variables) |
31717 | 1003 (imap-disable-multibyte) |
1004 (buffer-disable-undo) | |
1005 (setq imap-server (or server imap-server)) | |
1006 (setq imap-port (or port imap-port)) | |
1007 (setq imap-auth (or auth imap-auth)) | |
1008 (setq imap-stream (or stream imap-stream)) | |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
1009 (message "imap: Connecting to %s..." imap-server) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1010 (if (null (let ((imap-stream (or imap-stream imap-default-stream))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1011 (imap-open-1 buffer))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1012 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1013 (message "imap: Connecting to %s...failed" imap-server) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1014 nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1015 (when (null imap-stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1016 ;; Need to choose stream. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1017 (let ((streams imap-streams)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1018 (while (setq stream (pop streams)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1019 ;; OK to use this stream? |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1020 (when (funcall (nth 1 (assq stream imap-stream-alist)) buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1021 ;; Stream changed? |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1022 (if (not (eq imap-default-stream stream)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1023 (with-current-buffer (get-buffer-create |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1024 (generate-new-buffer-name " *temp*")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1025 (mapcar 'make-local-variable imap-local-variables) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1026 (imap-disable-multibyte) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1027 (buffer-disable-undo) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1028 (setq imap-server (or server imap-server)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1029 (setq imap-port (or port imap-port)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1030 (setq imap-auth (or auth imap-auth)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1031 (message "imap: Reconnecting with stream `%s'..." stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1032 (if (null (let ((imap-stream stream)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1033 (imap-open-1 (current-buffer)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1034 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1035 (kill-buffer (current-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1036 (message |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1037 "imap: Reconnecting with stream `%s'...failed" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1038 stream)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1039 ;; We're done, kill the first connection |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1040 (imap-close buffer) |
66564
68bb9e8a5390
* imap.el (imap-open): Handle case where buffer is a buffer
Chong Yidong <cyd@stupidchicken.com>
parents:
66454
diff
changeset
|
1041 (let ((name (if (stringp buffer) |
68bb9e8a5390
* imap.el (imap-open): Handle case where buffer is a buffer
Chong Yidong <cyd@stupidchicken.com>
parents:
66454
diff
changeset
|
1042 buffer |
68bb9e8a5390
* imap.el (imap-open): Handle case where buffer is a buffer
Chong Yidong <cyd@stupidchicken.com>
parents:
66454
diff
changeset
|
1043 (buffer-name buffer)))) |
68bb9e8a5390
* imap.el (imap-open): Handle case where buffer is a buffer
Chong Yidong <cyd@stupidchicken.com>
parents:
66454
diff
changeset
|
1044 (kill-buffer buffer) |
68bb9e8a5390
* imap.el (imap-open): Handle case where buffer is a buffer
Chong Yidong <cyd@stupidchicken.com>
parents:
66454
diff
changeset
|
1045 (rename-buffer name)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1046 (message "imap: Reconnecting with stream `%s'...done" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1047 stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1048 (setq imap-stream stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1049 (setq imap-capability nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1050 (setq streams nil))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1051 ;; We're done |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1052 (message "imap: Connecting to %s...done" imap-server) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1053 (setq imap-stream stream) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1054 (setq imap-capability nil) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1055 (setq streams nil)))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1056 (when (imap-opened buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1057 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1058 (when imap-stream |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1059 buffer)))) |
31717 | 1060 |
1061 (defun imap-opened (&optional buffer) | |
1062 "Return non-nil if connection to imap server in BUFFER is open. | |
1063 If BUFFER is nil then the current buffer is used." | |
1064 (and (setq buffer (get-buffer (or buffer (current-buffer)))) | |
1065 (buffer-live-p buffer) | |
1066 (with-current-buffer buffer | |
1067 (and imap-process | |
1068 (memq (process-status imap-process) '(open run)))))) | |
1069 | |
1070 (defun imap-authenticate (&optional user passwd buffer) | |
1071 "Authenticate to server in BUFFER, using current buffer if nil. | |
1072 It uses the authenticator specified when opening the server. If the | |
1073 authenticator requires username/passwords, they are queried from the | |
1074 user and optionally stored in the buffer. If USER and/or PASSWD is | |
1075 specified, the user will not be questioned and the username and/or | |
1076 password is remembered in the buffer." | |
1077 (with-current-buffer (or buffer (current-buffer)) | |
1078 (if (not (eq imap-state 'nonauth)) | |
1079 (or (eq imap-state 'auth) | |
1080 (eq imap-state 'select) | |
1081 (eq imap-state 'examine)) | |
41516
52c9115c94be
(imap-interactive-login, imap-open, imap-authenticate):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39064
diff
changeset
|
1082 (make-local-variable 'imap-username) |
52c9115c94be
(imap-interactive-login, imap-open, imap-authenticate):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39064
diff
changeset
|
1083 (make-local-variable 'imap-password) |
31717 | 1084 (if user (setq imap-username user)) |
1085 (if passwd (setq imap-password passwd)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1086 (if imap-auth |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1087 (and (funcall (nth 2 (assq imap-auth |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1088 imap-authenticator-alist)) buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1089 (setq imap-state 'auth)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1090 ;; Choose authenticator. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1091 (let ((auths imap-authenticators) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1092 auth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1093 (while (setq auth (pop auths)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1094 ;; OK to use authenticator? |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1095 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1096 (message "imap: Authenticating to `%s' using `%s'..." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1097 imap-server auth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1098 (setq imap-auth auth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1099 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1100 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1101 (message "imap: Authenticating to `%s' using `%s'...done" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1102 imap-server auth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1103 (setq auths nil)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1104 (message "imap: Authenticating to `%s' using `%s'...failed" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1105 imap-server auth))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1106 imap-state)))) |
31717 | 1107 |
1108 (defun imap-close (&optional buffer) | |
1109 "Close connection to server in BUFFER. | |
1110 If BUFFER is nil, the current buffer is used." | |
1111 (with-current-buffer (or buffer (current-buffer)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1112 (when (imap-opened) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1113 (condition-case nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1114 (imap-send-command-wait "LOGOUT") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1115 (quit nil))) |
31717 | 1116 (when (and imap-process |
1117 (memq (process-status imap-process) '(open run))) | |
1118 (delete-process imap-process)) | |
1119 (setq imap-current-mailbox nil | |
1120 imap-current-message nil | |
1121 imap-process nil) | |
1122 (erase-buffer) | |
1123 t)) | |
1124 | |
1125 (defun imap-capability (&optional identifier buffer) | |
1126 "Return a list of identifiers which server in BUFFER support. | |
1127 If IDENTIFIER, return non-nil if it's among the servers capabilities. | |
1128 If BUFFER is nil, the current buffer is assumed." | |
1129 (with-current-buffer (or buffer (current-buffer)) | |
1130 (unless imap-capability | |
1131 (unless (imap-ok-p (imap-send-command-wait "CAPABILITY")) | |
1132 (setq imap-capability '(IMAP2)))) | |
1133 (if identifier | |
1134 (memq (intern (upcase (symbol-name identifier))) imap-capability) | |
1135 imap-capability))) | |
1136 | |
1137 (defun imap-namespace (&optional buffer) | |
1138 "Return a namespace hierarchy at server in BUFFER. | |
1139 If BUFFER is nil, the current buffer is assumed." | |
1140 (with-current-buffer (or buffer (current-buffer)) | |
1141 (unless imap-namespace | |
1142 (when (imap-capability 'NAMESPACE) | |
1143 (imap-send-command-wait "NAMESPACE"))) | |
1144 imap-namespace)) | |
1145 | |
1146 (defun imap-send-command-wait (command &optional buffer) | |
1147 (imap-wait-for-tag (imap-send-command command buffer) buffer)) | |
1148 | |
1149 | |
1150 ;; Mailbox functions: | |
1151 | |
1152 (defun imap-mailbox-put (propname value &optional mailbox buffer) | |
1153 (with-current-buffer (or buffer (current-buffer)) | |
1154 (if imap-mailbox-data | |
1155 (put (intern (or mailbox imap-current-mailbox) imap-mailbox-data) | |
1156 propname value) | |
1157 (error "Imap-mailbox-data is nil, prop %s value %s mailbox %s buffer %s" | |
1158 propname value mailbox (current-buffer))) | |
1159 t)) | |
1160 | |
1161 (defsubst imap-mailbox-get-1 (propname &optional mailbox) | |
1162 (get (intern-soft (or mailbox imap-current-mailbox) imap-mailbox-data) | |
1163 propname)) | |
1164 | |
1165 (defun imap-mailbox-get (propname &optional mailbox buffer) | |
1166 (let ((mailbox (imap-utf7-encode mailbox))) | |
1167 (with-current-buffer (or buffer (current-buffer)) | |
1168 (imap-mailbox-get-1 propname (or mailbox imap-current-mailbox))))) | |
1169 | |
1170 (defun imap-mailbox-map-1 (func &optional mailbox-decoder buffer) | |
1171 (with-current-buffer (or buffer (current-buffer)) | |
1172 (let (result) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1173 (mapatoms |
31717 | 1174 (lambda (s) |
1175 (push (funcall func (if mailbox-decoder | |
1176 (funcall mailbox-decoder (symbol-name s)) | |
1177 (symbol-name s))) result)) | |
1178 imap-mailbox-data) | |
1179 result))) | |
1180 | |
1181 (defun imap-mailbox-map (func &optional buffer) | |
1182 "Map a function across each mailbox in `imap-mailbox-data', returning a list. | |
1183 Function should take a mailbox name (a string) as | |
1184 the only argument." | |
1185 (imap-mailbox-map-1 func 'imap-utf7-decode buffer)) | |
1186 | |
1187 (defun imap-current-mailbox (&optional buffer) | |
1188 (with-current-buffer (or buffer (current-buffer)) | |
1189 (imap-utf7-decode imap-current-mailbox))) | |
1190 | |
1191 (defun imap-current-mailbox-p-1 (mailbox &optional examine) | |
1192 (and (string= mailbox imap-current-mailbox) | |
1193 (or (and examine | |
1194 (eq imap-state 'examine)) | |
1195 (and (not examine) | |
1196 (eq imap-state 'selected))))) | |
1197 | |
1198 (defun imap-current-mailbox-p (mailbox &optional examine buffer) | |
1199 (with-current-buffer (or buffer (current-buffer)) | |
1200 (imap-current-mailbox-p-1 (imap-utf7-encode mailbox) examine))) | |
1201 | |
1202 (defun imap-mailbox-select-1 (mailbox &optional examine) | |
1203 "Select MAILBOX on server in BUFFER. | |
1204 If EXAMINE is non-nil, do a read-only select." | |
1205 (if (imap-current-mailbox-p-1 mailbox examine) | |
1206 imap-current-mailbox | |
1207 (setq imap-current-mailbox mailbox) | |
1208 (if (imap-ok-p (imap-send-command-wait | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1209 (concat (if examine "EXAMINE" "SELECT") " \"" |
31717 | 1210 mailbox "\""))) |
1211 (progn | |
1212 (setq imap-message-data (make-vector imap-message-prime 0) | |
1213 imap-state (if examine 'examine 'selected)) | |
1214 imap-current-mailbox) | |
1215 ;; Failed SELECT/EXAMINE unselects current mailbox | |
1216 (setq imap-current-mailbox nil)))) | |
1217 | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1218 (defun imap-mailbox-select (mailbox &optional examine buffer) |
31717 | 1219 (with-current-buffer (or buffer (current-buffer)) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1220 (imap-utf7-decode |
31717 | 1221 (imap-mailbox-select-1 (imap-utf7-encode mailbox) examine)))) |
1222 | |
1223 (defun imap-mailbox-examine-1 (mailbox &optional buffer) | |
1224 (with-current-buffer (or buffer (current-buffer)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1225 (imap-mailbox-select-1 mailbox 'examine))) |
31717 | 1226 |
1227 (defun imap-mailbox-examine (mailbox &optional buffer) | |
1228 "Examine MAILBOX on server in BUFFER." | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1229 (imap-mailbox-select mailbox 'examine buffer)) |
31717 | 1230 |
1231 (defun imap-mailbox-unselect (&optional buffer) | |
1232 "Close current folder in BUFFER, without expunging articles." | |
1233 (with-current-buffer (or buffer (current-buffer)) | |
1234 (when (or (eq imap-state 'auth) | |
1235 (and (imap-capability 'UNSELECT) | |
1236 (imap-ok-p (imap-send-command-wait "UNSELECT"))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1237 (and (imap-ok-p |
31717 | 1238 (imap-send-command-wait (concat "EXAMINE \"" |
1239 imap-current-mailbox | |
1240 "\""))) | |
1241 (imap-ok-p (imap-send-command-wait "CLOSE")))) | |
1242 (setq imap-current-mailbox nil | |
1243 imap-message-data nil | |
1244 imap-state 'auth) | |
1245 t))) | |
1246 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1247 (defun imap-mailbox-expunge (&optional asynch buffer) |
31717 | 1248 "Expunge articles in current folder in BUFFER. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1249 If ASYNCH, do not wait for succesful completion of the command. |
31717 | 1250 If BUFFER is nil the current buffer is assumed." |
1251 (with-current-buffer (or buffer (current-buffer)) | |
1252 (when (and imap-current-mailbox (not (eq imap-state 'examine))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1253 (if asynch |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1254 (imap-send-command "EXPUNGE") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1255 (imap-ok-p (imap-send-command-wait "EXPUNGE")))))) |
31717 | 1256 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1257 (defun imap-mailbox-close (&optional asynch buffer) |
31717 | 1258 "Expunge articles and close current folder in BUFFER. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1259 If ASYNCH, do not wait for succesful completion of the command. |
31717 | 1260 If BUFFER is nil the current buffer is assumed." |
1261 (with-current-buffer (or buffer (current-buffer)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1262 (when imap-current-mailbox |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1263 (if asynch |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1264 (imap-add-callback (imap-send-command "CLOSE") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1265 `(lambda (tag status) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1266 (message "IMAP mailbox `%s' closed... %s" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1267 imap-current-mailbox status) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1268 (when (eq ,imap-current-mailbox |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1269 imap-current-mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1270 ;; Don't wipe out data if another mailbox |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1271 ;; was selected... |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1272 (setq imap-current-mailbox nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1273 imap-message-data nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1274 imap-state 'auth)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1275 (when (imap-ok-p (imap-send-command-wait "CLOSE")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1276 (setq imap-current-mailbox nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1277 imap-message-data nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1278 imap-state 'auth))) |
31717 | 1279 t))) |
1280 | |
1281 (defun imap-mailbox-create-1 (mailbox) | |
1282 (imap-ok-p (imap-send-command-wait (list "CREATE \"" mailbox "\"")))) | |
1283 | |
1284 (defun imap-mailbox-create (mailbox &optional buffer) | |
1285 "Create MAILBOX on server in BUFFER. | |
1286 If BUFFER is nil the current buffer is assumed." | |
1287 (with-current-buffer (or buffer (current-buffer)) | |
1288 (imap-mailbox-create-1 (imap-utf7-encode mailbox)))) | |
1289 | |
1290 (defun imap-mailbox-delete (mailbox &optional buffer) | |
1291 "Delete MAILBOX on server in BUFFER. | |
1292 If BUFFER is nil the current buffer is assumed." | |
1293 (let ((mailbox (imap-utf7-encode mailbox))) | |
1294 (with-current-buffer (or buffer (current-buffer)) | |
1295 (imap-ok-p | |
1296 (imap-send-command-wait (list "DELETE \"" mailbox "\"")))))) | |
1297 | |
1298 (defun imap-mailbox-rename (oldname newname &optional buffer) | |
1299 "Rename mailbox OLDNAME to NEWNAME on server in BUFFER. | |
1300 If BUFFER is nil the current buffer is assumed." | |
1301 (let ((oldname (imap-utf7-encode oldname)) | |
1302 (newname (imap-utf7-encode newname))) | |
1303 (with-current-buffer (or buffer (current-buffer)) | |
1304 (imap-ok-p | |
1305 (imap-send-command-wait (list "RENAME \"" oldname "\" " | |
1306 "\"" newname "\"")))))) | |
1307 | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1308 (defun imap-mailbox-lsub (&optional root reference add-delimiter buffer) |
31717 | 1309 "Return a list of subscribed mailboxes on server in BUFFER. |
1310 If ROOT is non-nil, only list matching mailboxes. If ADD-DELIMITER is | |
1311 non-nil, a hierarchy delimiter is added to root. REFERENCE is a | |
1312 implementation-specific string that has to be passed to lsub command." | |
1313 (with-current-buffer (or buffer (current-buffer)) | |
1314 ;; Make sure we know the hierarchy separator for root's hierarchy | |
1315 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root))) | |
1316 (imap-send-command-wait (concat "LIST \"" reference "\" \"" | |
1317 (imap-utf7-encode root) "\""))) | |
1318 ;; clear list data (NB not delimiter and other stuff) | |
1319 (imap-mailbox-map-1 (lambda (mailbox) | |
1320 (imap-mailbox-put 'lsub nil mailbox))) | |
1321 (when (imap-ok-p | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1322 (imap-send-command-wait |
31717 | 1323 (concat "LSUB \"" reference "\" \"" (imap-utf7-encode root) |
1324 (and add-delimiter (imap-mailbox-get-1 'delimiter root)) | |
1325 "%\""))) | |
1326 (let (out) | |
1327 (imap-mailbox-map-1 (lambda (mailbox) | |
1328 (when (imap-mailbox-get-1 'lsub mailbox) | |
1329 (push (imap-utf7-decode mailbox) out)))) | |
1330 (nreverse out))))) | |
1331 | |
1332 (defun imap-mailbox-list (root &optional reference add-delimiter buffer) | |
1333 "Return a list of mailboxes matching ROOT on server in BUFFER. | |
1334 If ADD-DELIMITER is non-nil, a hierarchy delimiter is added to | |
1335 root. REFERENCE is a implementation-specific string that has to be | |
1336 passed to list command." | |
1337 (with-current-buffer (or buffer (current-buffer)) | |
1338 ;; Make sure we know the hierarchy separator for root's hierarchy | |
1339 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root))) | |
1340 (imap-send-command-wait (concat "LIST \"" reference "\" \"" | |
1341 (imap-utf7-encode root) "\""))) | |
1342 ;; clear list data (NB not delimiter and other stuff) | |
1343 (imap-mailbox-map-1 (lambda (mailbox) | |
1344 (imap-mailbox-put 'list nil mailbox))) | |
1345 (when (imap-ok-p | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1346 (imap-send-command-wait |
31717 | 1347 (concat "LIST \"" reference "\" \"" (imap-utf7-encode root) |
1348 (and add-delimiter (imap-mailbox-get-1 'delimiter root)) | |
1349 "%\""))) | |
1350 (let (out) | |
1351 (imap-mailbox-map-1 (lambda (mailbox) | |
1352 (when (imap-mailbox-get-1 'list mailbox) | |
1353 (push (imap-utf7-decode mailbox) out)))) | |
1354 (nreverse out))))) | |
1355 | |
1356 (defun imap-mailbox-subscribe (mailbox &optional buffer) | |
1357 "Send the SUBSCRIBE command on the mailbox to server in BUFFER. | |
1358 Returns non-nil if successful." | |
1359 (with-current-buffer (or buffer (current-buffer)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1360 (imap-ok-p (imap-send-command-wait (concat "SUBSCRIBE \"" |
31717 | 1361 (imap-utf7-encode mailbox) |
1362 "\""))))) | |
1363 | |
1364 (defun imap-mailbox-unsubscribe (mailbox &optional buffer) | |
1365 "Send the SUBSCRIBE command on the mailbox to server in BUFFER. | |
1366 Returns non-nil if successful." | |
1367 (with-current-buffer (or buffer (current-buffer)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1368 (imap-ok-p (imap-send-command-wait (concat "UNSUBSCRIBE " |
31717 | 1369 (imap-utf7-encode mailbox) |
1370 "\""))))) | |
1371 | |
1372 (defun imap-mailbox-status (mailbox items &optional buffer) | |
1373 "Get status items ITEM in MAILBOX from server in BUFFER. | |
1374 ITEMS can be a symbol or a list of symbols, valid symbols are one of | |
1375 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity | |
1376 or 'unseen. If ITEMS is a list of symbols, a list of values is | |
49474
a53b597e29e0
(imap-mailbox-status): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
48588
diff
changeset
|
1377 returned, if ITEMS is a symbol only its value is returned." |
31717 | 1378 (with-current-buffer (or buffer (current-buffer)) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1379 (when (imap-ok-p |
31717 | 1380 (imap-send-command-wait (list "STATUS \"" |
1381 (imap-utf7-encode mailbox) | |
1382 "\" " | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1383 (upcase |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1384 (format "%s" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1385 (if (listp items) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1386 items |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1387 (list items))))))) |
31717 | 1388 (if (listp items) |
1389 (mapcar (lambda (item) | |
1390 (imap-mailbox-get item mailbox)) | |
1391 items) | |
1392 (imap-mailbox-get items mailbox))))) | |
1393 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1394 (defun imap-mailbox-status-asynch (mailbox items &optional buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1395 "Send status item request ITEM on MAILBOX to server in BUFFER. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1396 ITEMS can be a symbol or a list of symbols, valid symbols are one of |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1397 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1398 or 'unseen. The IMAP command tag is returned." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1399 (with-current-buffer (or buffer (current-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1400 (imap-send-command (list "STATUS \"" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1401 (imap-utf7-encode mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1402 "\" " |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1403 (format "%s" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1404 (if (listp items) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1405 items |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1406 (list items))))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1407 |
31717 | 1408 (defun imap-mailbox-acl-get (&optional mailbox buffer) |
1409 "Get ACL on mailbox from server in BUFFER." | |
1410 (let ((mailbox (imap-utf7-encode mailbox))) | |
1411 (with-current-buffer (or buffer (current-buffer)) | |
1412 (when (imap-ok-p | |
1413 (imap-send-command-wait (list "GETACL \"" | |
1414 (or mailbox imap-current-mailbox) | |
1415 "\""))) | |
1416 (imap-mailbox-get-1 'acl (or mailbox imap-current-mailbox)))))) | |
1417 | |
1418 (defun imap-mailbox-acl-set (identifier rights &optional mailbox buffer) | |
1419 "Change/set ACL for IDENTIFIER to RIGHTS in MAILBOX from server in BUFFER." | |
1420 (let ((mailbox (imap-utf7-encode mailbox))) | |
1421 (with-current-buffer (or buffer (current-buffer)) | |
1422 (imap-ok-p | |
1423 (imap-send-command-wait (list "SETACL \"" | |
1424 (or mailbox imap-current-mailbox) | |
1425 "\" " | |
1426 identifier | |
1427 " " | |
1428 rights)))))) | |
1429 | |
1430 (defun imap-mailbox-acl-delete (identifier &optional mailbox buffer) | |
1431 "Removes any <identifier,rights> pair for IDENTIFIER in MAILBOX from server in BUFFER." | |
1432 (let ((mailbox (imap-utf7-encode mailbox))) | |
1433 (with-current-buffer (or buffer (current-buffer)) | |
1434 (imap-ok-p | |
1435 (imap-send-command-wait (list "DELETEACL \"" | |
1436 (or mailbox imap-current-mailbox) | |
1437 "\" " | |
1438 identifier)))))) | |
1439 | |
1440 | |
1441 ;; Message functions: | |
1442 | |
1443 (defun imap-current-message (&optional buffer) | |
1444 (with-current-buffer (or buffer (current-buffer)) | |
1445 imap-current-message)) | |
1446 | |
1447 (defun imap-list-to-message-set (list) | |
1448 (mapconcat (lambda (item) | |
1449 (number-to-string item)) | |
1450 (if (listp list) | |
1451 list | |
1452 (list list)) | |
1453 ",")) | |
1454 | |
1455 (defun imap-range-to-message-set (range) | |
1456 (mapconcat | |
1457 (lambda (item) | |
1458 (if (consp item) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1459 (format "%d:%d" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1460 (car item) (cdr item)) |
31717 | 1461 (format "%d" item))) |
1462 (if (and (listp range) (not (listp (cdr range)))) | |
1463 (list range) ;; make (1 . 2) into ((1 . 2)) | |
1464 range) | |
1465 ",")) | |
1466 | |
1467 (defun imap-fetch-asynch (uids props &optional nouidfetch buffer) | |
1468 (with-current-buffer (or buffer (current-buffer)) | |
1469 (imap-send-command (format "%sFETCH %s %s" (if nouidfetch "" "UID ") | |
1470 (if (listp uids) | |
1471 (imap-list-to-message-set uids) | |
1472 uids) | |
1473 props)))) | |
1474 | |
1475 (defun imap-fetch (uids props &optional receive nouidfetch buffer) | |
1476 "Fetch properties PROPS from message set UIDS from server in BUFFER. | |
1477 UIDS can be a string, number or a list of numbers. If RECEIVE | |
59289 | 1478 is non-nil return these properties." |
31717 | 1479 (with-current-buffer (or buffer (current-buffer)) |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1480 (when (imap-ok-p (imap-send-command-wait |
31717 | 1481 (format "%sFETCH %s %s" (if nouidfetch "" "UID ") |
1482 (if (listp uids) | |
1483 (imap-list-to-message-set uids) | |
1484 uids) | |
1485 props))) | |
1486 (if (or (null receive) (stringp uids)) | |
1487 t | |
1488 (if (listp uids) | |
1489 (mapcar (lambda (uid) | |
1490 (if (listp receive) | |
1491 (mapcar (lambda (prop) | |
1492 (imap-message-get uid prop)) | |
1493 receive) | |
1494 (imap-message-get uid receive))) | |
1495 uids) | |
1496 (imap-message-get uids receive)))))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1497 |
31717 | 1498 (defun imap-message-put (uid propname value &optional buffer) |
1499 (with-current-buffer (or buffer (current-buffer)) | |
1500 (if imap-message-data | |
1501 (put (intern (number-to-string uid) imap-message-data) | |
1502 propname value) | |
1503 (error "Imap-message-data is nil, uid %s prop %s value %s buffer %s" | |
1504 uid propname value (current-buffer))) | |
1505 t)) | |
1506 | |
1507 (defun imap-message-get (uid propname &optional buffer) | |
1508 (with-current-buffer (or buffer (current-buffer)) | |
1509 (get (intern-soft (number-to-string uid) imap-message-data) | |
1510 propname))) | |
1511 | |
1512 (defun imap-message-map (func propname &optional buffer) | |
1513 "Map a function across each mailbox in `imap-message-data', returning a list." | |
1514 (with-current-buffer (or buffer (current-buffer)) | |
1515 (let (result) | |
1516 (mapatoms | |
1517 (lambda (s) | |
1518 (push (funcall func (get s 'UID) (get s propname)) result)) | |
1519 imap-message-data) | |
1520 result))) | |
1521 | |
1522 (defmacro imap-message-envelope-date (uid &optional buffer) | |
1523 `(with-current-buffer (or ,buffer (current-buffer)) | |
1524 (elt (imap-message-get ,uid 'ENVELOPE) 0))) | |
1525 | |
1526 (defmacro imap-message-envelope-subject (uid &optional buffer) | |
1527 `(with-current-buffer (or ,buffer (current-buffer)) | |
1528 (elt (imap-message-get ,uid 'ENVELOPE) 1))) | |
1529 | |
1530 (defmacro imap-message-envelope-from (uid &optional buffer) | |
1531 `(with-current-buffer (or ,buffer (current-buffer)) | |
1532 (elt (imap-message-get ,uid 'ENVELOPE) 2))) | |
1533 | |
1534 (defmacro imap-message-envelope-sender (uid &optional buffer) | |
1535 `(with-current-buffer (or ,buffer (current-buffer)) | |
1536 (elt (imap-message-get ,uid 'ENVELOPE) 3))) | |
1537 | |
1538 (defmacro imap-message-envelope-reply-to (uid &optional buffer) | |
1539 `(with-current-buffer (or ,buffer (current-buffer)) | |
1540 (elt (imap-message-get ,uid 'ENVELOPE) 4))) | |
1541 | |
1542 (defmacro imap-message-envelope-to (uid &optional buffer) | |
1543 `(with-current-buffer (or ,buffer (current-buffer)) | |
1544 (elt (imap-message-get ,uid 'ENVELOPE) 5))) | |
1545 | |
1546 (defmacro imap-message-envelope-cc (uid &optional buffer) | |
1547 `(with-current-buffer (or ,buffer (current-buffer)) | |
1548 (elt (imap-message-get ,uid 'ENVELOPE) 6))) | |
1549 | |
1550 (defmacro imap-message-envelope-bcc (uid &optional buffer) | |
1551 `(with-current-buffer (or ,buffer (current-buffer)) | |
1552 (elt (imap-message-get ,uid 'ENVELOPE) 7))) | |
1553 | |
1554 (defmacro imap-message-envelope-in-reply-to (uid &optional buffer) | |
1555 `(with-current-buffer (or ,buffer (current-buffer)) | |
1556 (elt (imap-message-get ,uid 'ENVELOPE) 8))) | |
1557 | |
1558 (defmacro imap-message-envelope-message-id (uid &optional buffer) | |
1559 `(with-current-buffer (or ,buffer (current-buffer)) | |
1560 (elt (imap-message-get ,uid 'ENVELOPE) 9))) | |
1561 | |
1562 (defmacro imap-message-body (uid &optional buffer) | |
1563 `(with-current-buffer (or ,buffer (current-buffer)) | |
1564 (imap-message-get ,uid 'BODY))) | |
1565 | |
1566 (defun imap-search (predicate &optional buffer) | |
1567 (with-current-buffer (or buffer (current-buffer)) | |
1568 (imap-mailbox-put 'search 'dummy) | |
1569 (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate))) | |
1570 (if (eq (imap-mailbox-get-1 'search imap-current-mailbox) 'dummy) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1571 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1572 (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1573 nil) |
31717 | 1574 (imap-mailbox-get-1 'search imap-current-mailbox))))) |
1575 | |
1576 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer) | |
1577 "Return t iff FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER." | |
1578 (with-current-buffer (or buffer (current-buffer)) | |
1579 (or (member "\\*" (imap-mailbox-get 'permanentflags mailbox)) | |
1580 (member flag (imap-mailbox-get 'permanentflags mailbox))))) | |
1581 | |
1582 (defun imap-message-flags-set (articles flags &optional silent buffer) | |
1583 (when (and articles flags) | |
1584 (with-current-buffer (or buffer (current-buffer)) | |
1585 (imap-ok-p (imap-send-command-wait | |
1586 (concat "UID STORE " articles | |
1587 " FLAGS" (if silent ".SILENT") " (" flags ")")))))) | |
1588 | |
1589 (defun imap-message-flags-del (articles flags &optional silent buffer) | |
1590 (when (and articles flags) | |
1591 (with-current-buffer (or buffer (current-buffer)) | |
1592 (imap-ok-p (imap-send-command-wait | |
1593 (concat "UID STORE " articles | |
1594 " -FLAGS" (if silent ".SILENT") " (" flags ")")))))) | |
1595 | |
1596 (defun imap-message-flags-add (articles flags &optional silent buffer) | |
1597 (when (and articles flags) | |
1598 (with-current-buffer (or buffer (current-buffer)) | |
1599 (imap-ok-p (imap-send-command-wait | |
1600 (concat "UID STORE " articles | |
1601 " +FLAGS" (if silent ".SILENT") " (" flags ")")))))) | |
1602 | |
1603 (defun imap-message-copyuid-1 (mailbox) | |
1604 (if (imap-capability 'UIDPLUS) | |
1605 (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox)) | |
1606 (string-to-number (nth 2 (imap-mailbox-get-1 'copyuid mailbox)))) | |
1607 (let ((old-mailbox imap-current-mailbox) | |
1608 (state imap-state) | |
1609 (imap-message-data (make-vector 2 0))) | |
1610 (when (imap-mailbox-examine-1 mailbox) | |
1611 (prog1 | |
1612 (and (imap-fetch "*" "UID") | |
1613 (list (imap-mailbox-get-1 'uidvalidity mailbox) | |
1614 (apply 'max (imap-message-map | |
1615 (lambda (uid prop) uid) 'UID)))) | |
1616 (if old-mailbox | |
1617 (imap-mailbox-select old-mailbox (eq state 'examine)) | |
1618 (imap-mailbox-unselect))))))) | |
1619 | |
1620 (defun imap-message-copyuid (mailbox &optional buffer) | |
1621 (with-current-buffer (or buffer (current-buffer)) | |
1622 (imap-message-copyuid-1 (imap-utf7-decode mailbox)))) | |
1623 | |
1624 (defun imap-message-copy (articles mailbox | |
1625 &optional dont-create no-copyuid buffer) | |
1626 "Copy ARTICLES (a string message set) to MAILBOX on server in | |
1627 BUFFER, creating mailbox if it doesn't exist. If dont-create is | |
1628 non-nil, it will not create a mailbox. On success, return a list with | |
1629 the UIDVALIDITY of the mailbox the article(s) was copied to as the | |
1630 first element, rest of list contain the saved articles' UIDs." | |
1631 (when articles | |
1632 (with-current-buffer (or buffer (current-buffer)) | |
1633 (let ((mailbox (imap-utf7-encode mailbox))) | |
1634 (if (let ((cmd (concat "UID COPY " articles " \"" mailbox "\"")) | |
1635 (imap-current-target-mailbox mailbox)) | |
1636 (if (imap-ok-p (imap-send-command-wait cmd)) | |
1637 t | |
1638 (when (and (not dont-create) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1639 ;; removed because of buggy Oracle server |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1640 ;; that doesn't send TRYCREATE tags (which |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1641 ;; is a MUST according to specifications): |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1642 ;;(imap-mailbox-get-1 'trycreate mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1643 (imap-mailbox-create-1 mailbox)) |
31717 | 1644 (imap-ok-p (imap-send-command-wait cmd))))) |
1645 (or no-copyuid | |
1646 (imap-message-copyuid-1 mailbox))))))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1647 |
31717 | 1648 (defun imap-message-appenduid-1 (mailbox) |
1649 (if (imap-capability 'UIDPLUS) | |
1650 (imap-mailbox-get-1 'appenduid mailbox) | |
1651 (let ((old-mailbox imap-current-mailbox) | |
1652 (state imap-state) | |
1653 (imap-message-data (make-vector 2 0))) | |
1654 (when (imap-mailbox-examine-1 mailbox) | |
1655 (prog1 | |
1656 (and (imap-fetch "*" "UID") | |
1657 (list (imap-mailbox-get-1 'uidvalidity mailbox) | |
1658 (apply 'max (imap-message-map | |
1659 (lambda (uid prop) uid) 'UID)))) | |
1660 (if old-mailbox | |
1661 (imap-mailbox-select old-mailbox (eq state 'examine)) | |
1662 (imap-mailbox-unselect))))))) | |
1663 | |
1664 (defun imap-message-appenduid (mailbox &optional buffer) | |
1665 (with-current-buffer (or buffer (current-buffer)) | |
1666 (imap-message-appenduid-1 (imap-utf7-encode mailbox)))) | |
1667 | |
1668 (defun imap-message-append (mailbox article &optional flags date-time buffer) | |
1669 "Append ARTICLE (a buffer) to MAILBOX on server in BUFFER. | |
1670 FLAGS and DATE-TIME is currently not used. Return a cons holding | |
1671 uidvalidity of MAILBOX and UID the newly created article got, or nil | |
1672 on failure." | |
1673 (let ((mailbox (imap-utf7-encode mailbox))) | |
1674 (with-current-buffer (or buffer (current-buffer)) | |
1675 (and (let ((imap-current-target-mailbox mailbox)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1676 (imap-ok-p |
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1677 (imap-send-command-wait |
31717 | 1678 (list "APPEND \"" mailbox "\" " article)))) |
1679 (imap-message-appenduid-1 mailbox))))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1680 |
31717 | 1681 (defun imap-body-lines (body) |
1682 "Return number of lines in article by looking at the mime bodystructure BODY." | |
1683 (if (listp body) | |
1684 (if (stringp (car body)) | |
1685 (cond ((and (string= (upcase (car body)) "TEXT") | |
1686 (numberp (nth 7 body))) | |
1687 (nth 7 body)) | |
1688 ((and (string= (upcase (car body)) "MESSAGE") | |
1689 (numberp (nth 9 body))) | |
1690 (nth 9 body)) | |
1691 (t 0)) | |
1692 (apply '+ (mapcar 'imap-body-lines body))) | |
1693 0)) | |
1694 | |
1695 (defun imap-envelope-from (from) | |
1696 "Return a from string line." | |
1697 (and from | |
1698 (concat (aref from 0) | |
1699 (if (aref from 0) " <") | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1700 (aref from 2) |
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1701 "@" |
31717 | 1702 (aref from 3) |
1703 (if (aref from 0) ">")))) | |
1704 | |
1705 | |
1706 ;; Internal functions. | |
1707 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1708 (defun imap-add-callback (tag func) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1709 (setq imap-callbacks (append (list (cons tag func)) imap-callbacks))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1710 |
31717 | 1711 (defun imap-send-command-1 (cmdstr) |
1712 (setq cmdstr (concat cmdstr imap-client-eol)) | |
1713 (and imap-log | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1714 (with-current-buffer (get-buffer-create imap-log-buffer) |
31717 | 1715 (imap-disable-multibyte) |
1716 (buffer-disable-undo) | |
1717 (goto-char (point-max)) | |
1718 (insert cmdstr))) | |
1719 (process-send-string imap-process cmdstr)) | |
1720 | |
1721 (defun imap-send-command (command &optional buffer) | |
1722 (with-current-buffer (or buffer (current-buffer)) | |
1723 (if (not (listp command)) (setq command (list command))) | |
1724 (let ((tag (setq imap-tag (1+ imap-tag))) | |
1725 cmd cmdstr) | |
1726 (setq cmdstr (concat (number-to-string imap-tag) " ")) | |
1727 (while (setq cmd (pop command)) | |
1728 (cond ((stringp cmd) | |
1729 (setq cmdstr (concat cmdstr cmd))) | |
1730 ((bufferp cmd) | |
1731 (let ((eol imap-client-eol) | |
1732 (calcfirst imap-calculate-literal-size-first) | |
1733 size) | |
1734 (with-current-buffer cmd | |
1735 (if calcfirst | |
1736 (setq size (buffer-size))) | |
1737 (when (not (equal eol "\r\n")) | |
1738 ;; XXX modifies buffer! | |
1739 (goto-char (point-min)) | |
1740 (while (search-forward "\r\n" nil t) | |
1741 (replace-match eol))) | |
1742 (if (not calcfirst) | |
1743 (setq size (buffer-size)))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1744 (setq cmdstr |
31717 | 1745 (concat cmdstr (format "{%d}" size)))) |
1746 (unwind-protect | |
1747 (progn | |
1748 (imap-send-command-1 cmdstr) | |
1749 (setq cmdstr nil) | |
1750 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1751 (setq command nil) ;; abort command if no cont-req |
31717 | 1752 (let ((process imap-process) |
1753 (stream imap-stream) | |
1754 (eol imap-client-eol)) | |
1755 (with-current-buffer cmd | |
1756 (and imap-log | |
1757 (with-current-buffer (get-buffer-create | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1758 imap-log-buffer) |
31717 | 1759 (imap-disable-multibyte) |
1760 (buffer-disable-undo) | |
1761 (goto-char (point-max)) | |
1762 (insert-buffer-substring cmd))) | |
1763 (process-send-region process (point-min) | |
1764 (point-max))) | |
1765 (process-send-string process imap-client-eol)))) | |
1766 (setq imap-continuation nil))) | |
1767 ((functionp cmd) | |
1768 (imap-send-command-1 cmdstr) | |
1769 (setq cmdstr nil) | |
1770 (unwind-protect | |
1771 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1772 (setq command nil) ;; abort command if no cont-req |
31717 | 1773 (setq command (cons (funcall cmd imap-continuation) |
1774 command))) | |
1775 (setq imap-continuation nil))) | |
1776 (t | |
1777 (error "Unknown command type")))) | |
1778 (if cmdstr | |
1779 (imap-send-command-1 cmdstr)) | |
1780 tag))) | |
1781 | |
1782 (defun imap-wait-for-tag (tag &optional buffer) | |
1783 (with-current-buffer (or buffer (current-buffer)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1784 (let (imap-have-messaged) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1785 (while (and (null imap-continuation) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1786 (memq (process-status imap-process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1787 (< imap-reached-tag tag)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1788 (let ((len (/ (point-max) 1024)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1789 message-log-max) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1790 (unless (< len 10) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1791 (setq imap-have-messaged t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1792 (message "imap read: %dk" len)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1793 (accept-process-output imap-process |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1794 (truncate imap-read-timeout) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1795 (truncate (* (- imap-read-timeout |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1796 (truncate imap-read-timeout)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1797 1000))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1798 ;; A process can die _before_ we have processed everything it |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1799 ;; has to say. Moreover, this can happen in between the call to |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1800 ;; accept-process-output and the call to process-status in an |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1801 ;; iteration of the loop above. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1802 (when (and (null imap-continuation) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1803 (< imap-reached-tag tag)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1804 (accept-process-output imap-process 0 0)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1805 (when imap-have-messaged |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1806 (message "")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1807 (and (memq (process-status imap-process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1808 (or (assq tag imap-failed-tags) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1809 (if imap-continuation |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1810 'INCOMPLETE |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1811 'OK)))))) |
31717 | 1812 |
1813 (defun imap-sentinel (process string) | |
1814 (delete-process process)) | |
1815 | |
1816 (defun imap-find-next-line () | |
1817 "Return point at end of current line, taking into account literals. | |
1818 Return nil if no complete line has arrived." | |
1819 (when (re-search-forward (concat imap-server-eol "\\|{\\([0-9]+\\)}" | |
1820 imap-server-eol) | |
1821 nil t) | |
1822 (if (match-string 1) | |
1823 (if (< (point-max) (+ (point) (string-to-number (match-string 1)))) | |
1824 nil | |
1825 (goto-char (+ (point) (string-to-number (match-string 1)))) | |
1826 (imap-find-next-line)) | |
1827 (point)))) | |
1828 | |
1829 (defun imap-arrival-filter (proc string) | |
1830 "IMAP process filter." | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1831 ;; Sometimes, we are called even though the process has died. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1832 ;; Better abstain from doing stuff in that case. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1833 (when (buffer-name (process-buffer proc)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1834 (with-current-buffer (process-buffer proc) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1835 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1836 (insert string) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1837 (and imap-log |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1838 (with-current-buffer (get-buffer-create imap-log-buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1839 (imap-disable-multibyte) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1840 (buffer-disable-undo) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1841 (goto-char (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1842 (insert string))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1843 (let (end) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1844 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1845 (while (setq end (imap-find-next-line)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1846 (save-restriction |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1847 (narrow-to-region (point-min) end) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1848 (delete-backward-char (length imap-server-eol)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1849 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1850 (unwind-protect |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1851 (cond ((eq imap-state 'initial) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1852 (imap-parse-greeting)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1853 ((or (eq imap-state 'auth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1854 (eq imap-state 'nonauth) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1855 (eq imap-state 'selected) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1856 (eq imap-state 'examine)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1857 (imap-parse-response)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1858 (t |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1859 (message "Unknown state %s in arrival filter" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1860 imap-state))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
1861 (delete-region (point-min) (point-max))))))))) |
31717 | 1862 |
1863 | |
1864 ;; Imap parser. | |
1865 | |
1866 (defsubst imap-forward () | |
1867 (or (eobp) (forward-char))) | |
1868 | |
1869 ;; number = 1*DIGIT | |
1870 ;; ; Unsigned 32-bit integer | |
1871 ;; ; (0 <= n < 4,294,967,296) | |
1872 | |
1873 (defsubst imap-parse-number () | |
1874 (when (looking-at "[0-9]+") | |
1875 (prog1 | |
1876 (string-to-number (match-string 0)) | |
1877 (goto-char (match-end 0))))) | |
1878 | |
1879 ;; literal = "{" number "}" CRLF *CHAR8 | |
1880 ;; ; Number represents the number of CHAR8s | |
1881 | |
1882 (defsubst imap-parse-literal () | |
1883 (when (looking-at "{\\([0-9]+\\)}\r\n") | |
1884 (let ((pos (match-end 0)) | |
1885 (len (string-to-number (match-string 1)))) | |
1886 (if (< (point-max) (+ pos len)) | |
1887 nil | |
1888 (goto-char (+ pos len)) | |
1889 (buffer-substring pos (+ pos len)))))) | |
1890 | |
1891 ;; string = quoted / literal | |
1892 ;; | |
1893 ;; quoted = DQUOTE *QUOTED-CHAR DQUOTE | |
1894 ;; | |
1895 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> / | |
1896 ;; "\" quoted-specials | |
1897 ;; | |
1898 ;; quoted-specials = DQUOTE / "\" | |
1899 ;; | |
1900 ;; TEXT-CHAR = <any CHAR except CR and LF> | |
1901 | |
1902 (defsubst imap-parse-string () | |
1903 (cond ((eq (char-after) ?\") | |
1904 (forward-char 1) | |
1905 (let ((p (point)) (name "")) | |
1906 (skip-chars-forward "^\"\\\\") | |
1907 (setq name (buffer-substring p (point))) | |
1908 (while (eq (char-after) ?\\) | |
1909 (setq p (1+ (point))) | |
1910 (forward-char 2) | |
1911 (skip-chars-forward "^\"\\\\") | |
1912 (setq name (concat name (buffer-substring p (point))))) | |
1913 (forward-char 1) | |
1914 name)) | |
1915 ((eq (char-after) ?{) | |
1916 (imap-parse-literal)))) | |
1917 | |
1918 ;; nil = "NIL" | |
1919 | |
1920 (defsubst imap-parse-nil () | |
1921 (if (looking-at "NIL") | |
1922 (goto-char (match-end 0)))) | |
1923 | |
1924 ;; nstring = string / nil | |
1925 | |
1926 (defsubst imap-parse-nstring () | |
1927 (or (imap-parse-string) | |
1928 (and (imap-parse-nil) | |
1929 nil))) | |
1930 | |
1931 ;; astring = atom / string | |
1932 ;; | |
1933 ;; atom = 1*ATOM-CHAR | |
1934 ;; | |
1935 ;; ATOM-CHAR = <any CHAR except atom-specials> | |
1936 ;; | |
1937 ;; atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / | |
1938 ;; quoted-specials | |
1939 ;; | |
1940 ;; list-wildcards = "%" / "*" | |
1941 ;; | |
1942 ;; quoted-specials = DQUOTE / "\" | |
1943 | |
1944 (defsubst imap-parse-astring () | |
1945 (or (imap-parse-string) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
1946 (buffer-substring (point) |
31717 | 1947 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t) |
1948 (goto-char (1- (match-end 0))) | |
1949 (end-of-line) | |
1950 (point))))) | |
1951 | |
1952 ;; address = "(" addr-name SP addr-adl SP addr-mailbox SP | |
1953 ;; addr-host ")" | |
1954 ;; | |
1955 ;; addr-adl = nstring | |
1956 ;; ; Holds route from [RFC-822] route-addr if | |
42205 | 1957 ;; ; non-nil |
31717 | 1958 ;; |
1959 ;; addr-host = nstring | |
42205 | 1960 ;; ; nil indicates [RFC-822] group syntax. |
31717 | 1961 ;; ; Otherwise, holds [RFC-822] domain name |
1962 ;; | |
1963 ;; addr-mailbox = nstring | |
42205 | 1964 ;; ; nil indicates end of [RFC-822] group; if |
1965 ;; ; non-nil and addr-host is nil, holds | |
31717 | 1966 ;; ; [RFC-822] group name. |
1967 ;; ; Otherwise, holds [RFC-822] local-part | |
1968 ;; ; after removing [RFC-822] quoting | |
1969 ;; | |
1970 ;; addr-name = nstring | |
42205 | 1971 ;; ; If non-nil, holds phrase from [RFC-822] |
31717 | 1972 ;; ; mailbox after removing [RFC-822] quoting |
1973 ;; | |
1974 | |
1975 (defsubst imap-parse-address () | |
1976 (let (address) | |
1977 (when (eq (char-after) ?\() | |
1978 (imap-forward) | |
1979 (setq address (vector (prog1 (imap-parse-nstring) | |
1980 (imap-forward)) | |
1981 (prog1 (imap-parse-nstring) | |
1982 (imap-forward)) | |
1983 (prog1 (imap-parse-nstring) | |
1984 (imap-forward)) | |
1985 (imap-parse-nstring))) | |
1986 (when (eq (char-after) ?\)) | |
1987 (imap-forward) | |
1988 address)))) | |
1989 | |
1990 ;; address-list = "(" 1*address ")" / nil | |
1991 ;; | |
1992 ;; nil = "NIL" | |
1993 | |
1994 (defsubst imap-parse-address-list () | |
1995 (if (eq (char-after) ?\() | |
1996 (let (address addresses) | |
1997 (imap-forward) | |
1998 (while (and (not (eq (char-after) ?\))) | |
1999 ;; next line for MS Exchange bug | |
2000 (progn (and (eq (char-after) ? ) (imap-forward)) t) | |
2001 (setq address (imap-parse-address))) | |
2002 (setq addresses (cons address addresses))) | |
2003 (when (eq (char-after) ?\)) | |
2004 (imap-forward) | |
2005 (nreverse addresses))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2006 ;; With assert, the code might not be eval'd. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2007 ;; (assert (imap-parse-nil) t "In imap-parse-address-list") |
54490
0045ce238ded
(imap-parse-address-list, imap-parse-body-ext): Disable wrong use of `assert'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
2008 (imap-parse-nil))) |
31717 | 2009 |
2010 ;; mailbox = "INBOX" / astring | |
2011 ;; ; INBOX is case-insensitive. All case variants of | |
2012 ;; ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX | |
2013 ;; ; not as an astring. An astring which consists of | |
2014 ;; ; the case-insensitive sequence "I" "N" "B" "O" "X" | |
2015 ;; ; is considered to be INBOX and not an astring. | |
2016 ;; ; Refer to section 5.1 for further | |
2017 ;; ; semantic details of mailbox names. | |
2018 | |
2019 (defsubst imap-parse-mailbox () | |
2020 (let ((mailbox (imap-parse-astring))) | |
2021 (if (string-equal "INBOX" (upcase mailbox)) | |
2022 "INBOX" | |
2023 mailbox))) | |
2024 | |
2025 ;; greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF | |
2026 ;; | |
2027 ;; resp-cond-auth = ("OK" / "PREAUTH") SP resp-text | |
2028 ;; ; Authentication condition | |
2029 ;; | |
2030 ;; resp-cond-bye = "BYE" SP resp-text | |
2031 | |
2032 (defun imap-parse-greeting () | |
2033 "Parse a IMAP greeting." | |
2034 (cond ((looking-at "\\* OK ") | |
2035 (setq imap-state 'nonauth)) | |
2036 ((looking-at "\\* PREAUTH ") | |
2037 (setq imap-state 'auth)) | |
2038 ((looking-at "\\* BYE ") | |
2039 (setq imap-state 'closed)))) | |
2040 | |
2041 ;; response = *(continue-req / response-data) response-done | |
2042 ;; | |
2043 ;; continue-req = "+" SP (resp-text / base64) CRLF | |
2044 ;; | |
2045 ;; response-data = "*" SP (resp-cond-state / resp-cond-bye / | |
2046 ;; mailbox-data / message-data / capability-data) CRLF | |
2047 ;; | |
2048 ;; response-done = response-tagged / response-fatal | |
2049 ;; | |
2050 ;; response-fatal = "*" SP resp-cond-bye CRLF | |
2051 ;; ; Server closes connection immediately | |
2052 ;; | |
2053 ;; response-tagged = tag SP resp-cond-state CRLF | |
2054 ;; | |
2055 ;; resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text | |
2056 ;; ; Status condition | |
2057 ;; | |
2058 ;; resp-cond-bye = "BYE" SP resp-text | |
2059 ;; | |
2060 ;; mailbox-data = "FLAGS" SP flag-list / | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2061 ;; "LIST" SP mailbox-list / |
31717 | 2062 ;; "LSUB" SP mailbox-list / |
2063 ;; "SEARCH" *(SP nz-number) / | |
2064 ;; "STATUS" SP mailbox SP "(" | |
2065 ;; [status-att SP number *(SP status-att SP number)] ")" / | |
2066 ;; number SP "EXISTS" / | |
2067 ;; number SP "RECENT" | |
2068 ;; | |
2069 ;; message-data = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att)) | |
2070 ;; | |
2071 ;; capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1" | |
2072 ;; *(SP capability) | |
2073 ;; ; IMAP4rev1 servers which offer RFC 1730 | |
2074 ;; ; compatibility MUST list "IMAP4" as the first | |
2075 ;; ; capability. | |
2076 | |
2077 (defun imap-parse-response () | |
2078 "Parse a IMAP command response." | |
2079 (let (token) | |
2080 (case (setq token (read (current-buffer))) | |
2081 (+ (setq imap-continuation | |
2082 (or (buffer-substring (min (point-max) (1+ (point))) | |
2083 (point-max)) | |
2084 t))) | |
2085 (* (case (prog1 (setq token (read (current-buffer))) | |
2086 (imap-forward)) | |
2087 (OK (imap-parse-resp-text)) | |
2088 (NO (imap-parse-resp-text)) | |
2089 (BAD (imap-parse-resp-text)) | |
2090 (BYE (imap-parse-resp-text)) | |
2091 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list))) | |
2092 (LIST (imap-parse-data-list 'list)) | |
2093 (LSUB (imap-parse-data-list 'lsub)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2094 (SEARCH (imap-mailbox-put |
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2095 'search |
31717 | 2096 (read (concat "(" (buffer-substring (point) (point-max)) ")")))) |
2097 (STATUS (imap-parse-status)) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2098 (CAPABILITY (setq imap-capability |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2099 (read (concat "(" (upcase (buffer-substring |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2100 (point) (point-max))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2101 ")")))) |
31717 | 2102 (ACL (imap-parse-acl)) |
2103 (t (case (prog1 (read (current-buffer)) | |
2104 (imap-forward)) | |
2105 (EXISTS (imap-mailbox-put 'exists token)) | |
2106 (RECENT (imap-mailbox-put 'recent token)) | |
2107 (EXPUNGE t) | |
2108 (FETCH (imap-parse-fetch token)) | |
2109 (t (message "Garbage: %s" (buffer-string))))))) | |
2110 (t (let (status) | |
2111 (if (not (integerp token)) | |
2112 (message "Garbage: %s" (buffer-string)) | |
2113 (case (prog1 (setq status (read (current-buffer))) | |
2114 (imap-forward)) | |
2115 (OK (progn | |
2116 (setq imap-reached-tag (max imap-reached-tag token)) | |
2117 (imap-parse-resp-text))) | |
2118 (NO (progn | |
2119 (setq imap-reached-tag (max imap-reached-tag token)) | |
2120 (save-excursion | |
2121 (imap-parse-resp-text)) | |
2122 (let (code text) | |
2123 (when (eq (char-after) ?\[) | |
2124 (setq code (buffer-substring (point) | |
2125 (search-forward "]"))) | |
2126 (imap-forward)) | |
2127 (setq text (buffer-substring (point) (point-max))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2128 (push (list token status code text) |
31717 | 2129 imap-failed-tags)))) |
2130 (BAD (progn | |
2131 (setq imap-reached-tag (max imap-reached-tag token)) | |
2132 (save-excursion | |
2133 (imap-parse-resp-text)) | |
2134 (let (code text) | |
2135 (when (eq (char-after) ?\[) | |
2136 (setq code (buffer-substring (point) | |
2137 (search-forward "]"))) | |
2138 (imap-forward)) | |
2139 (setq text (buffer-substring (point) (point-max))) | |
2140 (push (list token status code text) imap-failed-tags) | |
2141 (error "Internal error, tag %s status %s code %s text %s" | |
2142 token status code text)))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2143 (t (message "Garbage: %s" (buffer-string)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2144 (when (assq token imap-callbacks) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2145 (funcall (cdr (assq token imap-callbacks)) token status) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2146 (setq imap-callbacks |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2147 (imap-remassoc token imap-callbacks))))))))) |
31717 | 2148 |
2149 ;; resp-text = ["[" resp-text-code "]" SP] text | |
2150 ;; | |
2151 ;; text = 1*TEXT-CHAR | |
2152 ;; | |
2153 ;; TEXT-CHAR = <any CHAR except CR and LF> | |
2154 | |
2155 (defun imap-parse-resp-text () | |
2156 (imap-parse-resp-text-code)) | |
2157 | |
2158 ;; resp-text-code = "ALERT" / | |
2159 ;; "BADCHARSET [SP "(" astring *(SP astring) ")" ] / | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2160 ;; "NEWNAME" SP string SP string / |
31717 | 2161 ;; "PARSE" / |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2162 ;; "PERMANENTFLAGS" SP "(" |
31717 | 2163 ;; [flag-perm *(SP flag-perm)] ")" / |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2164 ;; "READ-ONLY" / |
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2165 ;; "READ-WRITE" / |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2166 ;; "TRYCREATE" / |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2167 ;; "UIDNEXT" SP nz-number / |
31717 | 2168 ;; "UIDVALIDITY" SP nz-number / |
2169 ;; "UNSEEN" SP nz-number / | |
2170 ;; resp-text-atom [SP 1*<any TEXT-CHAR except "]">] | |
2171 ;; | |
2172 ;; resp_code_apnd = "APPENDUID" SPACE nz_number SPACE uniqueid | |
2173 ;; | |
2174 ;; resp_code_copy = "COPYUID" SPACE nz_number SPACE set SPACE set | |
2175 ;; | |
2176 ;; set = sequence-num / (sequence-num ":" sequence-num) / | |
2177 ;; (set "," set) | |
2178 ;; ; Identifies a set of messages. For message | |
2179 ;; ; sequence numbers, these are consecutive | |
2180 ;; ; numbers from 1 to the number of messages in | |
2181 ;; ; the mailbox | |
2182 ;; ; Comma delimits individual numbers, colon | |
2183 ;; ; delimits between two numbers inclusive. | |
2184 ;; ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13, | |
2185 ;; ; 14,15 for a mailbox with 15 messages. | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2186 ;; |
31717 | 2187 ;; sequence-num = nz-number / "*" |
2188 ;; ; * is the largest number in use. For message | |
2189 ;; ; sequence numbers, it is the number of messages | |
2190 ;; ; in the mailbox. For unique identifiers, it is | |
2191 ;; ; the unique identifier of the last message in | |
2192 ;; ; the mailbox. | |
2193 ;; | |
2194 ;; flag-perm = flag / "\*" | |
2195 ;; | |
2196 ;; flag = "\Answered" / "\Flagged" / "\Deleted" / | |
2197 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension | |
2198 ;; ; Does not include "\Recent" | |
2199 ;; | |
2200 ;; flag-extension = "\" atom | |
2201 ;; ; Future expansion. Client implementations | |
2202 ;; ; MUST accept flag-extension flags. Server | |
2203 ;; ; implementations MUST NOT generate | |
2204 ;; ; flag-extension flags except as defined by | |
2205 ;; ; future standard or standards-track | |
2206 ;; ; revisions of this specification. | |
2207 ;; | |
2208 ;; flag-keyword = atom | |
2209 ;; | |
2210 ;; resp-text-atom = 1*<any ATOM-CHAR except "]"> | |
2211 | |
2212 (defun imap-parse-resp-text-code () | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2213 ;; xxx next line for stalker communigate pro 3.3.1 bug |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2214 (when (looking-at " \\[") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2215 (imap-forward)) |
31717 | 2216 (when (eq (char-after) ?\[) |
2217 (imap-forward) | |
2218 (cond ((search-forward "PERMANENTFLAGS " nil t) | |
2219 (imap-mailbox-put 'permanentflags (imap-parse-flag-list))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2220 ((search-forward "UIDNEXT \\([0-9]+\\)" nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2221 (imap-mailbox-put 'uidnext (match-string 1))) |
31717 | 2222 ((search-forward "UNSEEN " nil t) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2223 (imap-mailbox-put 'first-unseen (read (current-buffer)))) |
31717 | 2224 ((looking-at "UIDVALIDITY \\([0-9]+\\)") |
2225 (imap-mailbox-put 'uidvalidity (match-string 1))) | |
2226 ((search-forward "READ-ONLY" nil t) | |
2227 (imap-mailbox-put 'read-only t)) | |
2228 ((search-forward "NEWNAME " nil t) | |
2229 (let (oldname newname) | |
2230 (setq oldname (imap-parse-string)) | |
2231 (imap-forward) | |
2232 (setq newname (imap-parse-string)) | |
2233 (imap-mailbox-put 'newname newname oldname))) | |
2234 ((search-forward "TRYCREATE" nil t) | |
2235 (imap-mailbox-put 'trycreate t imap-current-target-mailbox)) | |
2236 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)") | |
2237 (imap-mailbox-put 'appenduid | |
2238 (list (match-string 1) | |
2239 (string-to-number (match-string 2))) | |
2240 imap-current-target-mailbox)) | |
2241 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)") | |
2242 (imap-mailbox-put 'copyuid (list (match-string 1) | |
2243 (match-string 2) | |
2244 (match-string 3)) | |
2245 imap-current-target-mailbox)) | |
2246 ((search-forward "ALERT] " nil t) | |
2247 (message "Imap server %s information: %s" imap-server | |
2248 (buffer-substring (point) (point-max))))))) | |
2249 | |
2250 ;; mailbox-list = "(" [mbx-list-flags] ")" SP | |
2251 ;; (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox | |
2252 ;; | |
2253 ;; mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag | |
2254 ;; *(SP mbx-list-oflag) / | |
2255 ;; mbx-list-oflag *(SP mbx-list-oflag) | |
2256 ;; | |
2257 ;; mbx-list-oflag = "\Noinferiors" / flag-extension | |
2258 ;; ; Other flags; multiple possible per LIST response | |
2259 ;; | |
2260 ;; mbx-list-sflag = "\Noselect" / "\Marked" / "\Unmarked" | |
2261 ;; ; Selectability flags; only one per LIST response | |
2262 ;; | |
2263 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> / | |
2264 ;; "\" quoted-specials | |
2265 ;; | |
2266 ;; quoted-specials = DQUOTE / "\" | |
2267 | |
2268 (defun imap-parse-data-list (type) | |
2269 (let (flags delimiter mailbox) | |
2270 (setq flags (imap-parse-flag-list)) | |
2271 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"") | |
2272 (setq delimiter (match-string 1)) | |
2273 (goto-char (1+ (match-end 0))) | |
2274 (when (setq mailbox (imap-parse-mailbox)) | |
2275 (imap-mailbox-put type t mailbox) | |
2276 (imap-mailbox-put 'list-flags flags mailbox) | |
2277 (imap-mailbox-put 'delimiter delimiter mailbox))))) | |
2278 | |
2279 ;; msg_att ::= "(" 1#("ENVELOPE" SPACE envelope / | |
2280 ;; "FLAGS" SPACE "(" #(flag / "\Recent") ")" / | |
2281 ;; "INTERNALDATE" SPACE date_time / | |
2282 ;; "RFC822" [".HEADER" / ".TEXT"] SPACE nstring / | |
2283 ;; "RFC822.SIZE" SPACE number / | |
2284 ;; "BODY" ["STRUCTURE"] SPACE body / | |
2285 ;; "BODY" section ["<" number ">"] SPACE nstring / | |
2286 ;; "UID" SPACE uniqueid) ")" | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2287 ;; |
31717 | 2288 ;; date_time ::= <"> date_day_fixed "-" date_month "-" date_year |
2289 ;; SPACE time SPACE zone <"> | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2290 ;; |
31717 | 2291 ;; section ::= "[" [section_text / (nz_number *["." nz_number] |
2292 ;; ["." (section_text / "MIME")])] "]" | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2293 ;; |
31717 | 2294 ;; section_text ::= "HEADER" / "HEADER.FIELDS" [".NOT"] |
2295 ;; SPACE header_list / "TEXT" | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2296 ;; |
31717 | 2297 ;; header_fld_name ::= astring |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2298 ;; |
31717 | 2299 ;; header_list ::= "(" 1#header_fld_name ")" |
2300 | |
2301 (defsubst imap-parse-header-list () | |
2302 (when (eq (char-after) ?\() | |
2303 (let (strlist) | |
2304 (while (not (eq (char-after) ?\))) | |
2305 (imap-forward) | |
2306 (push (imap-parse-astring) strlist)) | |
2307 (imap-forward) | |
2308 (nreverse strlist)))) | |
2309 | |
2310 (defsubst imap-parse-fetch-body-section () | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2311 (let ((section |
31717 | 2312 (buffer-substring (point) (1- (re-search-forward "[] ]" nil t))))) |
2313 (if (eq (char-before) ? ) | |
2314 (prog1 | |
2315 (mapconcat 'identity (cons section (imap-parse-header-list)) " ") | |
2316 (search-forward "]" nil t)) | |
2317 section))) | |
2318 | |
2319 (defun imap-parse-fetch (response) | |
2320 (when (eq (char-after) ?\() | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2321 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2322 rfc822size body bodydetail bodystructure flags-empty) |
31717 | 2323 (while (not (eq (char-after) ?\))) |
2324 (imap-forward) | |
2325 (let ((token (read (current-buffer)))) | |
2326 (imap-forward) | |
2327 (cond ((eq token 'UID) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2328 (setq uid (condition-case () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2329 (read (current-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2330 (error)))) |
31717 | 2331 ((eq token 'FLAGS) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2332 (setq flags (imap-parse-flag-list)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2333 (if (not flags) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2334 (setq flags-empty 't))) |
31717 | 2335 ((eq token 'ENVELOPE) |
2336 (setq envelope (imap-parse-envelope))) | |
2337 ((eq token 'INTERNALDATE) | |
2338 (setq internaldate (imap-parse-string))) | |
2339 ((eq token 'RFC822) | |
2340 (setq rfc822 (imap-parse-nstring))) | |
2341 ((eq token 'RFC822.HEADER) | |
2342 (setq rfc822header (imap-parse-nstring))) | |
2343 ((eq token 'RFC822.TEXT) | |
2344 (setq rfc822text (imap-parse-nstring))) | |
2345 ((eq token 'RFC822.SIZE) | |
2346 (setq rfc822size (read (current-buffer)))) | |
2347 ((eq token 'BODY) | |
2348 (if (eq (char-before) ?\[) | |
2349 (push (list | |
2350 (upcase (imap-parse-fetch-body-section)) | |
2351 (and (eq (char-after) ?<) | |
2352 (buffer-substring (1+ (point)) | |
2353 (search-forward ">" nil t))) | |
2354 (progn (imap-forward) | |
2355 (imap-parse-nstring))) | |
2356 bodydetail) | |
2357 (setq body (imap-parse-body)))) | |
2358 ((eq token 'BODYSTRUCTURE) | |
2359 (setq bodystructure (imap-parse-body)))))) | |
2360 (when uid | |
2361 (setq imap-current-message uid) | |
2362 (imap-message-put uid 'UID uid) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2363 (and (or flags flags-empty) (imap-message-put uid 'FLAGS flags)) |
31717 | 2364 (and envelope (imap-message-put uid 'ENVELOPE envelope)) |
2365 (and internaldate (imap-message-put uid 'INTERNALDATE internaldate)) | |
2366 (and rfc822 (imap-message-put uid 'RFC822 rfc822)) | |
2367 (and rfc822header (imap-message-put uid 'RFC822.HEADER rfc822header)) | |
2368 (and rfc822text (imap-message-put uid 'RFC822.TEXT rfc822text)) | |
2369 (and rfc822size (imap-message-put uid 'RFC822.SIZE rfc822size)) | |
2370 (and body (imap-message-put uid 'BODY body)) | |
2371 (and bodydetail (imap-message-put uid 'BODYDETAIL bodydetail)) | |
2372 (and bodystructure (imap-message-put uid 'BODYSTRUCTURE bodystructure)) | |
2373 (run-hooks 'imap-fetch-data-hook))))) | |
2374 | |
2375 ;; mailbox-data = ... | |
2376 ;; "STATUS" SP mailbox SP "(" | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2377 ;; [status-att SP number |
31717 | 2378 ;; *(SP status-att SP number)] ")" |
2379 ;; ... | |
2380 ;; | |
2381 ;; status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" / | |
2382 ;; "UNSEEN" | |
2383 | |
2384 (defun imap-parse-status () | |
2385 (let ((mailbox (imap-parse-mailbox))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2386 (if (eq (char-after) ? ) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2387 (forward-char)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2388 (when (and mailbox (eq (char-after) ?\()) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2389 (while (and (not (eq (char-after) ?\))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2390 (or (forward-char) t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2391 (looking-at "\\([A-Za-z]+\\) ")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2392 (let ((token (match-string 1))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2393 (goto-char (match-end 0)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2394 (cond ((string= token "MESSAGES") |
31717 | 2395 (imap-mailbox-put 'messages (read (current-buffer)) mailbox)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2396 ((string= token "RECENT") |
31717 | 2397 (imap-mailbox-put 'recent (read (current-buffer)) mailbox)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2398 ((string= token "UIDNEXT") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2399 (and (looking-at "[0-9]+") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2400 (imap-mailbox-put 'uidnext (match-string 0) mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2401 (goto-char (match-end 0)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2402 ((string= token "UIDVALIDITY") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2403 (and (looking-at "[0-9]+") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2404 (imap-mailbox-put 'uidvalidity (match-string 0) mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2405 (goto-char (match-end 0)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2406 ((string= token "UNSEEN") |
31717 | 2407 (imap-mailbox-put 'unseen (read (current-buffer)) mailbox)) |
2408 (t | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2409 (message "Unknown status data %s in mailbox %s ignored" |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2410 token mailbox) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2411 (read (current-buffer))))))))) |
31717 | 2412 |
2413 ;; acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE | |
2414 ;; rights) | |
2415 ;; | |
2416 ;; identifier ::= astring | |
2417 ;; | |
2418 ;; rights ::= astring | |
2419 | |
2420 (defun imap-parse-acl () | |
2421 (let ((mailbox (imap-parse-mailbox)) | |
2422 identifier rights acl) | |
2423 (while (eq (char-after) ?\ ) | |
2424 (imap-forward) | |
2425 (setq identifier (imap-parse-astring)) | |
2426 (imap-forward) | |
2427 (setq rights (imap-parse-astring)) | |
2428 (setq acl (append acl (list (cons identifier rights))))) | |
2429 (imap-mailbox-put 'acl acl mailbox))) | |
2430 | |
2431 ;; flag-list = "(" [flag *(SP flag)] ")" | |
2432 ;; | |
2433 ;; flag = "\Answered" / "\Flagged" / "\Deleted" / | |
2434 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension | |
2435 ;; ; Does not include "\Recent" | |
2436 ;; | |
2437 ;; flag-keyword = atom | |
2438 ;; | |
2439 ;; flag-extension = "\" atom | |
2440 ;; ; Future expansion. Client implementations | |
2441 ;; ; MUST accept flag-extension flags. Server | |
2442 ;; ; implementations MUST NOT generate | |
2443 ;; ; flag-extension flags except as defined by | |
2444 ;; ; future standard or standards-track | |
2445 ;; ; revisions of this specification. | |
2446 | |
2447 (defun imap-parse-flag-list () | |
2448 (let (flag-list start) | |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
2449 (assert (eq (char-after) ?\() nil "In imap-parse-flag-list") |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2450 (while (and (not (eq (char-after) ?\))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2451 (setq start (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2452 (imap-forward) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2453 ;; next line for Courier IMAP bug. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2454 (skip-chars-forward " ") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2455 (point))) |
33299
be95f43e08db
(imap-point-at-eol): New, replacing gnus-point-at-eol.
Dave Love <fx@gnu.org>
parents:
32995
diff
changeset
|
2456 (> (skip-chars-forward "^ )" (imap-point-at-eol)) 0)) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2457 (push (buffer-substring start (point)) flag-list)) |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
2458 (assert (eq (char-after) ?\)) nil "In imap-parse-flag-list") |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2459 (imap-forward) |
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2460 (nreverse flag-list))) |
31717 | 2461 |
2462 ;; envelope = "(" env-date SP env-subject SP env-from SP env-sender SP | |
2463 ;; env-reply-to SP env-to SP env-cc SP env-bcc SP | |
2464 ;; env-in-reply-to SP env-message-id ")" | |
2465 ;; | |
2466 ;; env-bcc = "(" 1*address ")" / nil | |
2467 ;; | |
2468 ;; env-cc = "(" 1*address ")" / nil | |
2469 ;; | |
2470 ;; env-date = nstring | |
2471 ;; | |
2472 ;; env-from = "(" 1*address ")" / nil | |
2473 ;; | |
2474 ;; env-in-reply-to = nstring | |
2475 ;; | |
2476 ;; env-message-id = nstring | |
2477 ;; | |
2478 ;; env-reply-to = "(" 1*address ")" / nil | |
2479 ;; | |
2480 ;; env-sender = "(" 1*address ")" / nil | |
2481 ;; | |
2482 ;; env-subject = nstring | |
2483 ;; | |
2484 ;; env-to = "(" 1*address ")" / nil | |
2485 | |
2486 (defun imap-parse-envelope () | |
2487 (when (eq (char-after) ?\() | |
2488 (imap-forward) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2489 (vector (prog1 (imap-parse-nstring) ;; date |
31717 | 2490 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2491 (prog1 (imap-parse-nstring) ;; subject |
31717 | 2492 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2493 (prog1 (imap-parse-address-list) ;; from |
31717 | 2494 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2495 (prog1 (imap-parse-address-list) ;; sender |
31717 | 2496 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2497 (prog1 (imap-parse-address-list) ;; reply-to |
31717 | 2498 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2499 (prog1 (imap-parse-address-list) ;; to |
31717 | 2500 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2501 (prog1 (imap-parse-address-list) ;; cc |
31717 | 2502 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2503 (prog1 (imap-parse-address-list) ;; bcc |
31717 | 2504 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2505 (prog1 (imap-parse-nstring) ;; in-reply-to |
31717 | 2506 (imap-forward)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2507 (prog1 (imap-parse-nstring) ;; message-id |
31717 | 2508 (imap-forward))))) |
2509 | |
2510 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil | |
2511 | |
2512 (defsubst imap-parse-string-list () | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2513 (cond ((eq (char-after) ?\() ;; body-fld-param |
31717 | 2514 (let (strlist str) |
2515 (imap-forward) | |
2516 (while (setq str (imap-parse-string)) | |
2517 (push str strlist) | |
2518 ;; buggy stalker communigate pro 3.0 doesn't print SPC | |
2519 ;; between body-fld-param's sometimes | |
2520 (or (eq (char-after) ?\") | |
2521 (imap-forward))) | |
2522 (nreverse strlist))) | |
2523 ((imap-parse-nil) | |
2524 nil))) | |
2525 | |
2526 ;; body-extension = nstring / number / | |
2527 ;; "(" body-extension *(SP body-extension) ")" | |
2528 ;; ; Future expansion. Client implementations | |
2529 ;; ; MUST accept body-extension fields. Server | |
2530 ;; ; implementations MUST NOT generate | |
2531 ;; ; body-extension fields except as defined by | |
2532 ;; ; future standard or standards-track | |
2533 ;; ; revisions of this specification. | |
2534 | |
2535 (defun imap-parse-body-extension () | |
2536 (if (eq (char-after) ?\() | |
2537 (let (b-e) | |
2538 (imap-forward) | |
2539 (push (imap-parse-body-extension) b-e) | |
2540 (while (eq (char-after) ?\ ) | |
2541 (imap-forward) | |
2542 (push (imap-parse-body-extension) b-e)) | |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
2543 (assert (eq (char-after) ?\)) nil "In imap-parse-body-extension") |
31717 | 2544 (imap-forward) |
2545 (nreverse b-e)) | |
2546 (or (imap-parse-number) | |
2547 (imap-parse-nstring)))) | |
2548 | |
2549 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang | |
2550 ;; *(SP body-extension)]] | |
2551 ;; ; MUST NOT be returned on non-extensible | |
2552 ;; ; "BODY" fetch | |
2553 ;; | |
2554 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang | |
2555 ;; *(SP body-extension)]] | |
2556 ;; ; MUST NOT be returned on non-extensible | |
2557 ;; ; "BODY" fetch | |
2558 | |
2559 (defsubst imap-parse-body-ext () | |
2560 (let (ext) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2561 (when (eq (char-after) ?\ ) ;; body-fld-dsp |
31717 | 2562 (imap-forward) |
2563 (let (dsp) | |
2564 (if (eq (char-after) ?\() | |
2565 (progn | |
2566 (imap-forward) | |
2567 (push (imap-parse-string) dsp) | |
2568 (imap-forward) | |
2569 (push (imap-parse-string-list) dsp) | |
2570 (imap-forward)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2571 ;; With assert, the code might not be eval'd. |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2572 ;; (assert (imap-parse-nil) t "In imap-parse-body-ext") |
54490
0045ce238ded
(imap-parse-address-list, imap-parse-body-ext): Disable wrong use of `assert'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
2573 (imap-parse-nil)) |
31717 | 2574 (push (nreverse dsp) ext)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2575 (when (eq (char-after) ?\ ) ;; body-fld-lang |
31717 | 2576 (imap-forward) |
2577 (if (eq (char-after) ?\() | |
2578 (push (imap-parse-string-list) ext) | |
2579 (push (imap-parse-nstring) ext)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2580 (while (eq (char-after) ?\ ) ;; body-extension |
31717 | 2581 (imap-forward) |
2582 (setq ext (append (imap-parse-body-extension) ext))))) | |
2583 ext)) | |
2584 | |
2585 ;; body = "(" body-type-1part / body-type-mpart ")" | |
2586 ;; | |
2587 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang | |
2588 ;; *(SP body-extension)]] | |
2589 ;; ; MUST NOT be returned on non-extensible | |
2590 ;; ; "BODY" fetch | |
2591 ;; | |
2592 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang | |
2593 ;; *(SP body-extension)]] | |
2594 ;; ; MUST NOT be returned on non-extensible | |
2595 ;; ; "BODY" fetch | |
2596 ;; | |
2597 ;; body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP | |
2598 ;; body-fld-enc SP body-fld-octets | |
2599 ;; | |
2600 ;; body-fld-desc = nstring | |
2601 ;; | |
2602 ;; body-fld-dsp = "(" string SP body-fld-param ")" / nil | |
2603 ;; | |
2604 ;; body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/ | |
2605 ;; "QUOTED-PRINTABLE") DQUOTE) / string | |
2606 ;; | |
2607 ;; body-fld-id = nstring | |
2608 ;; | |
2609 ;; body-fld-lang = nstring / "(" string *(SP string) ")" | |
2610 ;; | |
2611 ;; body-fld-lines = number | |
2612 ;; | |
2613 ;; body-fld-md5 = nstring | |
2614 ;; | |
2615 ;; body-fld-octets = number | |
2616 ;; | |
2617 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil | |
2618 ;; | |
2619 ;; body-type-1part = (body-type-basic / body-type-msg / body-type-text) | |
2620 ;; [SP body-ext-1part] | |
2621 ;; | |
2622 ;; body-type-basic = media-basic SP body-fields | |
2623 ;; ; MESSAGE subtype MUST NOT be "RFC822" | |
2624 ;; | |
2625 ;; body-type-msg = media-message SP body-fields SP envelope | |
2626 ;; SP body SP body-fld-lines | |
2627 ;; | |
2628 ;; body-type-text = media-text SP body-fields SP body-fld-lines | |
2629 ;; | |
2630 ;; body-type-mpart = 1*body SP media-subtype | |
2631 ;; [SP body-ext-mpart] | |
2632 ;; | |
2633 ;; media-basic = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" / | |
2634 ;; "MESSAGE" / "VIDEO") DQUOTE) / string) SP media-subtype | |
2635 ;; ; Defined in [MIME-IMT] | |
2636 ;; | |
2637 ;; media-message = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE | |
2638 ;; ; Defined in [MIME-IMT] | |
2639 ;; | |
2640 ;; media-subtype = string | |
2641 ;; ; Defined in [MIME-IMT] | |
2642 ;; | |
2643 ;; media-text = DQUOTE "TEXT" DQUOTE SP media-subtype | |
2644 ;; ; Defined in [MIME-IMT] | |
2645 | |
2646 (defun imap-parse-body () | |
2647 (let (body) | |
2648 (when (eq (char-after) ?\() | |
2649 (imap-forward) | |
2650 (if (eq (char-after) ?\() | |
2651 (let (subbody) | |
2652 (while (and (eq (char-after) ?\() | |
2653 (setq subbody (imap-parse-body))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2654 ;; buggy stalker communigate pro 3.0 insert a SPC between |
31717 | 2655 ;; parts in multiparts |
2656 (when (and (eq (char-after) ?\ ) | |
2657 (eq (char-after (1+ (point))) ?\()) | |
2658 (imap-forward)) | |
2659 (push subbody body)) | |
2660 (imap-forward) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2661 (push (imap-parse-string) body) ;; media-subtype |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2662 (when (eq (char-after) ?\ ) ;; body-ext-mpart: |
31717 | 2663 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2664 (if (eq (char-after) ?\() ;; body-fld-param |
31717 | 2665 (push (imap-parse-string-list) body) |
2666 (push (and (imap-parse-nil) nil) body)) | |
2667 (setq body | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2668 (append (imap-parse-body-ext) body))) ;; body-ext-... |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
2669 (assert (eq (char-after) ?\)) nil "In imap-parse-body") |
31717 | 2670 (imap-forward) |
2671 (nreverse body)) | |
2672 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2673 (push (imap-parse-string) body) ;; media-type |
31717 | 2674 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2675 (push (imap-parse-string) body) ;; media-subtype |
31717 | 2676 (imap-forward) |
2677 ;; next line for Sun SIMS bug | |
2678 (and (eq (char-after) ? ) (imap-forward)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2679 (if (eq (char-after) ?\() ;; body-fld-param |
31717 | 2680 (push (imap-parse-string-list) body) |
2681 (push (and (imap-parse-nil) nil) body)) | |
2682 (imap-forward) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2683 (push (imap-parse-nstring) body) ;; body-fld-id |
31717 | 2684 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2685 (push (imap-parse-nstring) body) ;; body-fld-desc |
31717 | 2686 (imap-forward) |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2687 ;; next `or' for Sun SIMS bug, it regard body-fld-enc as a |
42205 | 2688 ;; nstring and return nil instead of defaulting back to 7BIT |
32995
3720ccaca161
2000-10-27 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
2689 ;; as the standard says. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2690 (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc |
31717 | 2691 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2692 (push (imap-parse-number) body) ;; body-fld-octets |
31717 | 2693 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2694 ;; ok, we're done parsing the required parts, what comes now is one |
31717 | 2695 ;; of three things: |
2696 ;; | |
2697 ;; envelope (then we're parsing body-type-msg) | |
2698 ;; body-fld-lines (then we're parsing body-type-text) | |
2699 ;; body-ext-1part (then we're parsing body-type-basic) | |
2700 ;; | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2701 ;; the problem is that the two first are in turn optionally followed |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2702 ;; by the third. So we parse the first two here (if there are any)... |
31717 | 2703 |
2704 (when (eq (char-after) ?\ ) | |
2705 (imap-forward) | |
2706 (let (lines) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2707 (cond ((eq (char-after) ?\() ;; body-type-msg: |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2708 (push (imap-parse-envelope) body) ;; envelope |
31717 | 2709 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2710 (push (imap-parse-body) body) ;; body |
31717 | 2711 ;; buggy stalker communigate pro 3.0 doesn't print |
2712 ;; number of lines in message/rfc822 attachment | |
2713 (if (eq (char-after) ?\)) | |
2714 (push 0 body) | |
2715 (imap-forward) | |
2716 (push (imap-parse-number) body))) ;; body-fld-lines | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2717 ((setq lines (imap-parse-number)) ;; body-type-text: |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2718 (push lines body)) ;; body-fld-lines |
31717 | 2719 (t |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2720 (backward-char))))) ;; no match... |
31717 | 2721 |
2722 ;; ...and then parse the third one here... | |
2723 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2724 (when (eq (char-after) ?\ ) ;; body-ext-1part: |
31717 | 2725 (imap-forward) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2726 (push (imap-parse-nstring) body) ;; body-fld-md5 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2727 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part.. |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2728 |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
57153
diff
changeset
|
2729 (assert (eq (char-after) ?\)) nil "In imap-parse-body 2") |
31717 | 2730 (imap-forward) |
2731 (nreverse body))))) | |
2732 | |
2733 (when imap-debug ; (untrace-all) | |
2734 (require 'trace) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2735 (buffer-disable-undo (get-buffer-create imap-debug-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
54490
diff
changeset
|
2736 (mapcar (lambda (f) (trace-function-background f imap-debug-buffer)) |
31717 | 2737 '( |
2738 imap-utf7-encode | |
2739 imap-utf7-decode | |
2740 imap-error-text | |
2741 imap-kerberos4s-p | |
2742 imap-kerberos4-open | |
2743 imap-ssl-p | |
2744 imap-ssl-open | |
2745 imap-network-p | |
2746 imap-network-open | |
2747 imap-interactive-login | |
2748 imap-kerberos4a-p | |
2749 imap-kerberos4-auth | |
2750 imap-cram-md5-p | |
2751 imap-cram-md5-auth | |
2752 imap-login-p | |
2753 imap-login-auth | |
2754 imap-anonymous-p | |
2755 imap-anonymous-auth | |
2756 imap-open-1 | |
2757 imap-open | |
2758 imap-opened | |
2759 imap-authenticate | |
2760 imap-close | |
2761 imap-capability | |
2762 imap-namespace | |
2763 imap-send-command-wait | |
2764 imap-mailbox-put | |
2765 imap-mailbox-get | |
2766 imap-mailbox-map-1 | |
2767 imap-mailbox-map | |
2768 imap-current-mailbox | |
2769 imap-current-mailbox-p-1 | |
2770 imap-current-mailbox-p | |
2771 imap-mailbox-select-1 | |
2772 imap-mailbox-select | |
2773 imap-mailbox-examine-1 | |
2774 imap-mailbox-examine | |
2775 imap-mailbox-unselect | |
2776 imap-mailbox-expunge | |
2777 imap-mailbox-close | |
2778 imap-mailbox-create-1 | |
2779 imap-mailbox-create | |
2780 imap-mailbox-delete | |
2781 imap-mailbox-rename | |
2782 imap-mailbox-lsub | |
2783 imap-mailbox-list | |
2784 imap-mailbox-subscribe | |
2785 imap-mailbox-unsubscribe | |
2786 imap-mailbox-status | |
2787 imap-mailbox-acl-get | |
2788 imap-mailbox-acl-set | |
2789 imap-mailbox-acl-delete | |
2790 imap-current-message | |
2791 imap-list-to-message-set | |
2792 imap-fetch-asynch | |
2793 imap-fetch | |
2794 imap-message-put | |
2795 imap-message-get | |
2796 imap-message-map | |
2797 imap-search | |
2798 imap-message-flag-permanent-p | |
2799 imap-message-flags-set | |
2800 imap-message-flags-del | |
2801 imap-message-flags-add | |
2802 imap-message-copyuid-1 | |
2803 imap-message-copyuid | |
2804 imap-message-copy | |
2805 imap-message-appenduid-1 | |
2806 imap-message-appenduid | |
2807 imap-message-append | |
2808 imap-body-lines | |
2809 imap-envelope-from | |
2810 imap-send-command-1 | |
2811 imap-send-command | |
2812 imap-wait-for-tag | |
2813 imap-sentinel | |
2814 imap-find-next-line | |
2815 imap-arrival-filter | |
2816 imap-parse-greeting | |
2817 imap-parse-response | |
2818 imap-parse-resp-text | |
2819 imap-parse-resp-text-code | |
2820 imap-parse-data-list | |
2821 imap-parse-fetch | |
2822 imap-parse-status | |
2823 imap-parse-acl | |
2824 imap-parse-flag-list | |
2825 imap-parse-envelope | |
2826 imap-parse-body-extension | |
2827 imap-parse-body | |
2828 ))) | |
39064
c545df001cd2
(imap-mailbox-examine, imap-mailbox-examine-1): Fix a typo: `exmine' --> `examine'.
Sam Steingold <sds@gnu.org>
parents:
33299
diff
changeset
|
2829 |
31717 | 2830 (provide 'imap) |
2831 | |
52401 | 2832 ;;; arch-tag: 27369ed6-33e4-482f-96f1-8bb906ba70f7 |
31717 | 2833 ;;; imap.el ends here |