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