1 ;;; imap.el --- imap library
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Simon Josefsson <jas@pdc.kth.se>
8 ;; This file is part of GNU Emacs.
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)
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.
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.
27 ;; imap.el is a elisp library providing an interface for talking to
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.
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.
42 ;; imap-open, imap-opened, imap-authenticate, imap-close,
43 ;; imap-capability, imap-namespace, imap-error-text
47 ;; imap-mailbox-get, imap-mailbox-map, imap-current-mailbox,
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
57 ;; imap-fetch-asynch, imap-fetch,
58 ;; imap-current-message, imap-list-to-message-set,
59 ;; imap-message-get, imap-message-map
60 ;; imap-message-envelope-date, imap-message-envelope-subject,
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
72 ;; It is my hope that theese commands should be pretty self
73 ;; explanatory for someone that know IMAP. All functions have
74 ;; additional documentation on how to invoke them.
76 ;; imap.el support RFC1730/2060 (IMAP4/IMAP4rev1), implemented IMAP
77 ;; extensions are RFC2195 (CRAM-MD5), RFC2086 (ACL), RFC2342
78 ;; (NAMESPACE), RFC2359 (UIDPLUS), the IMAP-part of RFC2595 (STARTTLS,
79 ;; LOGINDISABLED) (with use of external library starttls.el and
80 ;; program starttls) and the GSSAPI / kerberos V4 sections of RFC1731
81 ;; (with use of external program `imtest'). It also take advantage
82 ;; the UNSELECT extension in Cyrus IMAPD.
84 ;; Without the work of John McClary Prevost and Jim Radford this library
85 ;; would not have seen the light of day. Many thanks.
87 ;; This is a transcript of short interactive session for demonstration
90 ;; (imap-open "my.mail.server")
91 ;; => " *imap* my.mail.server:0"
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.
98 ;; (imap-authenticate "myusername" "mypassword")
101 ;; (imap-mailbox-lsub "*")
102 ;; => ("INBOX.sentmail" "INBOX.private" "INBOX.draft" "INBOX.spam")
104 ;; (imap-mailbox-list "INBOX.n%")
105 ;; => ("INBOX.namedroppers" "INBOX.nnimap" "INBOX.ntbugtraq")
107 ;; (imap-mailbox-select "INBOX.nnimap")
110 ;; (imap-mailbox-get 'exists)
113 ;; (imap-mailbox-get 'uidvalidity)
116 ;; (imap-search "FLAGGED SINCE 18-DEC-98")
119 ;; (imap-fetch 235 "RFC822.PEEK" 'RFC822)
120 ;; => "X-Sieve: cmu-sieve 1.3^M\nX-Username: <jas@pdc.kth.se>^M\r...."
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.
128 ;; o Send strings as literal if they contain, e.g., ".
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
140 (eval-when-compile (require 'cl))
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")
155 (autoload 'format-spec-make "format-spec")
156 (autoload 'open-tls-stream "tls")
157 ;; Avoid use gnus-point-at-eol so we're independent of Gnus. These
158 ;; days we have point-at-eol anyhow.
159 (if (fboundp 'point-at-eol)
160 (defalias 'imap-point-at-eol 'point-at-eol)
161 (defun imap-point-at-eol ()
169 "Low-level IMAP issues."
173 (defcustom imap-kerberos4-program '("imtest -m kerberos_v4 -u %l -p %p %s"
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."
181 :type '(repeat string))
183 (defcustom imap-gssapi-program (list
184 (concat "gsasl --client --connect %s:%p "
185 "--imap --application-data "
186 "--mechanism GSSAPI "
187 "--authentication-id %l")
188 "imtest -m gssapi -u %l -p %p %s")
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."
195 :type '(repeat string))
197 (defcustom imap-ssl-program '("openssl s_client -quiet -ssl3 -connect %s:%p"
198 "openssl s_client -quiet -ssl2 -connect %s:%p"
199 "s_client -quiet -ssl3 -connect %s:%p"
200 "s_client -quiet -ssl2 -connect %s:%p")
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."
207 :type '(choice string
210 (defcustom imap-shell-program '("ssh %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."
221 :type '(repeat string))
223 (defcustom imap-process-connection-type nil
224 "*Value for `process-connection-type' to use for Kerberos4, GSSAPI and SSL.
225 The `process-connection-type' variable control type of device
226 used to communicate with subprocesses. Values are nil to use a
227 pipe, or t or `pty' to use a pty. The value has no effect if the
228 system has no ptys or if all ptys are busy: then a pipe is used
229 in any case. The value takes effect when a IMAP server is
230 opened, changing it after that has no effect.."
234 (defcustom imap-use-utf7 t
235 "If non-nil, do utf7 encoding/decoding of mailbox names.
236 Since the UTF7 decoding currently only decodes into ISO-8859-1
237 characters, you may disable this decoding if you need to access UTF7
238 encoded mailboxes which doesn't translate into ISO-8859-1."
242 (defcustom imap-log nil
243 "If non-nil, a imap session trace is placed in *imap-log* buffer."
247 (defcustom imap-debug nil
248 "If non-nil, random debug spews are placed in *imap-debug* buffer."
252 (defcustom imap-shell-host "gateway"
253 "Hostname of rlogin proxy."
257 (defcustom imap-default-user (user-login-name)
258 "Default username to use."
262 (defcustom imap-read-timeout (if (string-match
263 "windows-nt\\|os/2\\|emx\\|cygwin"
264 (symbol-name system-type))
267 "*How long to wait between checking for the end of output.
268 Shorter values mean quicker response, but is more CPU intensive."
272 ;; Various variables.
274 (defvar imap-fetch-data-hook nil
275 "Hooks called after receiving each FETCH response.")
277 (defvar imap-streams '(gssapi kerberos4 starttls tls ssl network shell)
278 "Priority of streams to consider when opening connection to server.")
280 (defvar imap-stream-alist
281 '((gssapi imap-gssapi-stream-p imap-gssapi-open)
282 (kerberos4 imap-kerberos4-stream-p imap-kerberos4-open)
283 (tls imap-tls-p imap-tls-open)
284 (ssl imap-ssl-p imap-ssl-open)
285 (network imap-network-p imap-network-open)
286 (shell imap-shell-p imap-shell-open)
287 (starttls imap-starttls-p imap-starttls-open))
288 "Definition of network streams.
292 NAME names the stream, CHECK is a function returning non-nil if the
293 server support the stream and OPEN is a function for opening the
296 (defvar imap-authenticators '(gssapi
302 "Priority of authenticators to consider when authenticating to server.")
304 (defvar imap-authenticator-alist
305 '((gssapi imap-gssapi-auth-p imap-gssapi-auth)
306 (kerberos4 imap-kerberos4-auth-p imap-kerberos4-auth)
307 (cram-md5 imap-cram-md5-p imap-cram-md5-auth)
308 (login imap-login-p imap-login-auth)
309 (anonymous imap-anonymous-p imap-anonymous-auth)
310 (digest-md5 imap-digest-md5-p imap-digest-md5-auth))
311 "Definition of authenticators.
313 \(NAME CHECK AUTHENTICATE)
315 NAME names the authenticator. CHECK is a function returning non-nil if
316 the server support the authenticator and AUTHENTICATE is a function
317 for doing the actual authentication.")
319 (defvar imap-error nil
320 "Error codes from the last command.")
322 ;; Internal constants. Change theese and die.
324 (defconst imap-default-port 143)
325 (defconst imap-default-ssl-port 993)
326 (defconst imap-default-tls-port 993)
327 (defconst imap-default-stream 'network)
328 (defconst imap-coding-system-for-read 'binary)
329 (defconst imap-coding-system-for-write 'binary)
330 (defconst imap-local-variables '(imap-server
339 imap-current-target-mailbox
348 imap-calculate-literal-size-first
350 (defconst imap-log-buffer "*imap-log*")
351 (defconst imap-debug-buffer "*imap-debug*")
353 ;; Internal variables.
355 (defvar imap-stream nil)
356 (defvar imap-auth nil)
357 (defvar imap-server nil)
358 (defvar imap-port nil)
359 (defvar imap-username nil)
360 (defvar imap-password nil)
361 (defvar imap-calculate-literal-size-first nil)
362 (defvar imap-state 'closed
364 Valid states are `closed', `initial', `nonauth', `auth', `selected'
367 (defvar imap-server-eol "\r\n"
368 "The EOL string sent from the server.")
370 (defvar imap-client-eol "\r\n"
371 "The EOL string we send to the server.")
373 (defvar imap-current-mailbox nil
374 "Current mailbox name.")
376 (defvar imap-current-target-mailbox nil
377 "Current target mailbox for COPY and APPEND commands.")
379 (defvar imap-mailbox-data nil
380 "Obarray with mailbox data.")
382 (defvar imap-mailbox-prime 997
383 "Length of imap-mailbox-data.")
385 (defvar imap-current-message nil
386 "Current message number.")
388 (defvar imap-message-data nil
389 "Obarray with message data.")
391 (defvar imap-message-prime 997
392 "Length of imap-message-data.")
394 (defvar imap-capability nil
395 "Capability for server.")
397 (defvar imap-namespace nil
398 "Namespace for current server.")
400 (defvar imap-reached-tag 0
401 "Lower limit on command tags that have been parsed.")
403 (defvar imap-failed-tags nil
404 "Alist of tags that failed.
405 Each element is a list with four elements; tag (a integer), response
406 state (a symbol, `OK', `NO' or `BAD'), response code (a string), and
407 human readable response text (a string).")
410 "Command tag number.")
412 (defvar imap-process nil
415 (defvar imap-continuation nil
416 "Non-nil indicates that the server emitted a continuation request.
417 The actual value is really the text on the continuation line.")
419 (defvar imap-callbacks nil
420 "List of response tags and callbacks, on the form `(number . function)'.
421 The function should take two arguments, the first the IMAP tag and the
422 second the status (OK, NO, BAD etc) of the command.")
425 ;; Utility functions:
427 (defun imap-remassoc (key alist)
428 "Delete by side effect any elements of LIST whose car is `equal' to KEY.
429 The modified LIST is returned. If the first member
430 of LIST has a car that is `equal' to KEY, there is no way to remove it
431 by side effect; therefore, write `(setq foo (remassoc key foo))' to be
432 sure of changing the value of `foo'."
434 (if (equal key (caar alist))
436 (setcdr alist (imap-remassoc key (cdr alist)))
439 (defsubst imap-disable-multibyte ()
440 "Enable multibyte in the current buffer."
441 (when (fboundp 'set-buffer-multibyte)
442 (set-buffer-multibyte nil)))
444 (defsubst imap-utf7-encode (string)
448 (utf7-encode string t)
450 "imap: Could not UTF7 encode `%s', using it unencoded..."
455 (defsubst imap-utf7-decode (string)
459 (utf7-decode string t)
461 "imap: Could not UTF7 decode `%s', using it undecoded..."
466 (defsubst imap-ok-p (status)
469 (setq imap-error status)
472 (defun imap-error-text (&optional buffer)
473 (with-current-buffer (or buffer (current-buffer))
474 (nth 3 (car imap-failed-tags))))
477 ;; Server functions; stream stuff:
479 (defun imap-kerberos4-stream-p (buffer)
480 (imap-capability 'AUTH=KERBEROS_V4 buffer))
482 (defun imap-kerberos4-open (name buffer server port)
483 (let ((cmds imap-kerberos4-program)
485 (while (and (not done) (setq cmd (pop cmds)))
486 (message "Opening Kerberos 4 IMAP connection with `%s'..." cmd)
488 (let* ((port (or port imap-default-port))
489 (coding-system-for-read imap-coding-system-for-read)
490 (coding-system-for-write imap-coding-system-for-write)
491 (process-connection-type imap-process-connection-type)
492 (process (start-process
493 name buffer shell-file-name shell-command-switch
498 ?p (number-to-string port)
499 ?l imap-default-user))))
502 (with-current-buffer buffer
503 (setq imap-client-eol "\n"
504 imap-calculate-literal-size-first t)
505 (while (and (memq (process-status process) '(open run))
506 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
507 (goto-char (point-min))
508 ;; Athena IMTEST can output SSL verify errors
509 (or (while (looking-at "^verify error:num=")
512 (or (while (looking-at "^TLS connection established")
515 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
516 (or (while (looking-at "^C:")
519 ;; cyrus 1.6 imtest print "S: " before server greeting
520 (or (not (looking-at "S: "))
523 (not (and (imap-parse-greeting)
524 ;; success in imtest < 1.6:
525 (or (re-search-forward
526 "^__\\(.*\\)__\n" nil t)
527 ;; success in imtest 1.6:
529 "^\\(Authenticat.*\\)" nil t))
530 (setq response (match-string 1)))))
531 (accept-process-output process 1)
534 (with-current-buffer (get-buffer-create imap-log-buffer)
535 (imap-disable-multibyte)
536 (buffer-disable-undo)
537 (goto-char (point-max))
538 (insert-buffer-substring buffer)))
540 (message "Opening Kerberos 4 IMAP connection with `%s'...%s" cmd
541 (if response (concat "done, " response) "failed"))
542 (if (and response (let ((case-fold-search nil))
543 (not (string-match "failed" response))))
545 (if (memq (process-status process) '(open run))
546 (imap-send-command "LOGOUT"))
547 (delete-process process)
551 (defun imap-gssapi-stream-p (buffer)
552 (imap-capability 'AUTH=GSSAPI buffer))
554 (defun imap-gssapi-open (name buffer server port)
555 (let ((cmds imap-gssapi-program)
557 (while (and (not done) (setq cmd (pop cmds)))
558 (message "Opening GSSAPI IMAP connection with `%s'..." cmd)
560 (let* ((port (or port imap-default-port))
561 (coding-system-for-read imap-coding-system-for-read)
562 (coding-system-for-write imap-coding-system-for-write)
563 (process-connection-type imap-process-connection-type)
564 (process (start-process
565 name buffer shell-file-name shell-command-switch
570 ?p (number-to-string port)
571 ?l imap-default-user))))
574 (with-current-buffer buffer
575 (setq imap-client-eol "\n"
576 imap-calculate-literal-size-first t)
577 (while (and (memq (process-status process) '(open run))
578 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
579 (goto-char (point-min))
580 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
581 (or (while (looking-at "^C:")
584 ;; cyrus 1.6 imtest print "S: " before server greeting
585 (or (not (looking-at "S: "))
588 (not (and (imap-parse-greeting)
589 ;; success in imtest 1.6:
591 (concat "^\\(\\(Authenticat.*\\)\\|\\("
592 "Client authentication "
595 (setq response (match-string 1)))))
596 (accept-process-output process 1)
599 (with-current-buffer (get-buffer-create imap-log-buffer)
600 (imap-disable-multibyte)
601 (buffer-disable-undo)
602 (goto-char (point-max))
603 (insert-buffer-substring buffer)))
605 (message "GSSAPI IMAP connection: %s" (or response "failed"))
606 (if (and response (let ((case-fold-search nil))
607 (not (string-match "failed" response))))
609 (if (memq (process-status process) '(open run))
610 (imap-send-command "LOGOUT"))
611 (delete-process process)
615 (defun imap-ssl-p (buffer)
618 (defun imap-ssl-open (name buffer server port)
619 "Open a SSL connection to server."
620 (let ((cmds (if (listp imap-ssl-program) imap-ssl-program
621 (list imap-ssl-program)))
623 (while (and (not done) (setq cmd (pop cmds)))
624 (message "imap: Opening SSL connection with `%s'..." cmd)
626 (let* ((port (or port imap-default-ssl-port))
627 (coding-system-for-read imap-coding-system-for-read)
628 (coding-system-for-write imap-coding-system-for-write)
629 (process-connection-type nil)
632 (setq process (start-process
633 name buffer shell-file-name
638 ?p (number-to-string port)))))
639 (process-kill-without-query process)
641 (with-current-buffer buffer
642 (goto-char (point-min))
643 (while (and (memq (process-status process) '(open run))
644 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
645 (goto-char (point-max))
647 (not (imap-parse-greeting)))
648 (accept-process-output process 1)
651 (with-current-buffer (get-buffer-create imap-log-buffer)
652 (imap-disable-multibyte)
653 (buffer-disable-undo)
654 (goto-char (point-max))
655 (insert-buffer-substring buffer)))
657 (when (memq (process-status process) '(open run))
658 (setq done process))))))
661 (message "imap: Opening SSL connection with `%s'...done" cmd)
663 (message "imap: Opening SSL connection with `%s'...failed" cmd)
666 (defun imap-tls-p (buffer)
669 (defun imap-tls-open (name buffer server port)
670 (let* ((port (or port imap-default-tls-port))
671 (coding-system-for-read imap-coding-system-for-read)
672 (coding-system-for-write imap-coding-system-for-write)
673 (process (open-tls-stream name buffer server port)))
675 (while (and (memq (process-status process) '(open run))
676 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
677 (goto-char (point-max))
679 (not (imap-parse-greeting)))
680 (accept-process-output process 1)
683 (with-current-buffer (get-buffer-create imap-log-buffer)
684 (imap-disable-multibyte)
685 (buffer-disable-undo)
686 (goto-char (point-max))
687 (insert-buffer-substring buffer)))
688 (when (memq (process-status process) '(open run))
691 (defun imap-network-p (buffer)
694 (defun imap-network-open (name buffer server port)
695 (let* ((port (or port imap-default-port))
696 (coding-system-for-read imap-coding-system-for-read)
697 (coding-system-for-write imap-coding-system-for-write)
698 (process (open-network-stream name buffer server port)))
700 (while (and (memq (process-status process) '(open run))
701 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
702 (goto-char (point-min))
703 (not (imap-parse-greeting)))
704 (accept-process-output process 1)
707 (with-current-buffer (get-buffer-create imap-log-buffer)
708 (imap-disable-multibyte)
709 (buffer-disable-undo)
710 (goto-char (point-max))
711 (insert-buffer-substring buffer)))
712 (when (memq (process-status process) '(open run))
715 (defun imap-shell-p (buffer)
718 (defun imap-shell-open (name buffer server port)
719 (let ((cmds (if (listp imap-shell-program) imap-shell-program
720 (list imap-shell-program)))
722 (while (and (not done) (setq cmd (pop cmds)))
723 (message "imap: Opening IMAP connection with `%s'..." cmd)
724 (setq imap-client-eol "\n")
725 (let* ((port (or port imap-default-port))
726 (coding-system-for-read imap-coding-system-for-read)
727 (coding-system-for-write imap-coding-system-for-write)
728 (process (start-process
729 name buffer shell-file-name shell-command-switch
735 ?p (number-to-string port)
736 ?l imap-default-user)))))
738 (while (and (memq (process-status process) '(open run))
739 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
740 (goto-char (point-max))
742 (not (imap-parse-greeting)))
743 (accept-process-output process 1)
746 (with-current-buffer (get-buffer-create imap-log-buffer)
747 (imap-disable-multibyte)
748 (buffer-disable-undo)
749 (goto-char (point-max))
750 (insert-buffer-substring buffer)))
752 (when (memq (process-status process) '(open run))
753 (setq done process)))))
756 (message "imap: Opening IMAP connection with `%s'...done" cmd)
758 (message "imap: Opening IMAP connection with `%s'...failed" cmd)
761 (defun imap-starttls-p (buffer)
762 (imap-capability 'STARTTLS buffer))
764 (defun imap-starttls-open (name buffer server port)
765 (let* ((port (or port imap-default-port))
766 (coding-system-for-read imap-coding-system-for-read)
767 (coding-system-for-write imap-coding-system-for-write)
768 (process (starttls-open-stream name buffer server port))
770 (message "imap: Connecting with STARTTLS...")
772 (while (and (memq (process-status process) '(open run))
773 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
774 (goto-char (point-max))
776 (not (imap-parse-greeting)))
777 (accept-process-output process 1)
779 (imap-send-command "STARTTLS")
780 (while (and (memq (process-status process) '(open run))
781 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
782 (goto-char (point-max))
784 (not (re-search-forward "[0-9]+ OK.*\r?\n" nil t)))
785 (accept-process-output process 1)
788 (with-current-buffer (get-buffer-create imap-log-buffer)
789 (buffer-disable-undo)
790 (goto-char (point-max))
791 (insert-buffer-substring buffer)))
792 (when (and (setq tls-info (starttls-negotiate process))
793 (memq (process-status process) '(open run)))
794 (setq done process)))
795 (if (stringp tls-info)
796 (message "imap: STARTTLS info: %s" tls-info))
797 (message "imap: Connecting with STARTTLS...%s" (if done "done" "failed"))
800 ;; Server functions; authenticator stuff:
802 (defun imap-interactive-login (buffer loginfunc)
803 "Login to server in BUFFER.
804 LOGINFUNC is passed a username and a password, it should return t if
805 it where successful authenticating itself to the server, nil otherwise.
806 Returns t if login was successful, nil otherwise."
807 (with-current-buffer buffer
808 (make-local-variable 'imap-username)
809 (make-local-variable 'imap-password)
810 (let (user passwd ret)
811 ;; (condition-case ()
812 (while (or (not user) (not passwd))
813 (setq user (or imap-username
814 (read-from-minibuffer
815 (concat "IMAP username for " imap-server
816 " (using stream `" (symbol-name imap-stream)
818 (or user imap-default-user))))
819 (setq passwd (or imap-password
821 (concat "IMAP password for " user "@"
822 imap-server " (using authenticator `"
823 (symbol-name imap-auth) "'): "))))
824 (when (and user passwd)
825 (if (funcall loginfunc user passwd)
829 (if (and (not imap-password)
830 (y-or-n-p "Store password for this session? "))
831 (setq imap-password passwd)))
832 (message "Login failed...")
834 (setq imap-password nil)
836 ;; (quit (with-current-buffer buffer
839 ;; (error (with-current-buffer buffer
844 (defun imap-gssapi-auth-p (buffer)
845 (eq imap-stream 'gssapi))
847 (defun imap-gssapi-auth (buffer)
848 (message "imap: Authenticating using GSSAPI...%s"
849 (if (eq imap-stream 'gssapi) "done" "failed"))
850 (eq imap-stream 'gssapi))
852 (defun imap-kerberos4-auth-p (buffer)
853 (and (imap-capability 'AUTH=KERBEROS_V4 buffer)
854 (eq imap-stream 'kerberos4)))
856 (defun imap-kerberos4-auth (buffer)
857 (message "imap: Authenticating using Kerberos 4...%s"
858 (if (eq imap-stream 'kerberos4) "done" "failed"))
859 (eq imap-stream 'kerberos4))
861 (defun imap-cram-md5-p (buffer)
862 (imap-capability 'AUTH=CRAM-MD5 buffer))
864 (defun imap-cram-md5-auth (buffer)
865 "Login to server using the AUTH CRAM-MD5 method."
866 (message "imap: Authenticating using CRAM-MD5...")
867 (let ((done (imap-interactive-login
869 (lambda (user passwd)
871 (imap-send-command-wait
873 "AUTHENTICATE CRAM-MD5"
875 (let* ((decoded (base64-decode-string challenge))
876 (hash (rfc2104-hash 'md5 64 16 passwd decoded))
877 (response (concat user " " hash))
878 (encoded (base64-encode-string response)))
881 (message "imap: Authenticating using CRAM-MD5...done")
882 (message "imap: Authenticating using CRAM-MD5...failed"))))
884 (defun imap-login-p (buffer)
885 (and (not (imap-capability 'LOGINDISABLED buffer))
886 (not (imap-capability 'X-LOGIN-CMD-DISABLED buffer))))
888 (defun imap-login-auth (buffer)
889 "Login to server using the LOGIN command."
890 (message "imap: Plaintext authentication...")
891 (imap-interactive-login buffer
892 (lambda (user passwd)
893 (imap-ok-p (imap-send-command-wait
894 (concat "LOGIN \"" user "\" \""
897 (defun imap-anonymous-p (buffer)
900 (defun imap-anonymous-auth (buffer)
901 (message "imap: Logging in anonymously...")
902 (with-current-buffer buffer
903 (imap-ok-p (imap-send-command-wait
904 (concat "LOGIN anonymous \"" (concat (user-login-name) "@"
905 (system-name)) "\"")))))
907 (defun imap-digest-md5-p (buffer)
908 (and (imap-capability 'AUTH=DIGEST-MD5 buffer)
910 (require 'digest-md5)
913 (defun imap-digest-md5-auth (buffer)
914 "Login to server using the AUTH DIGEST-MD5 method."
915 (message "imap: Authenticating using DIGEST-MD5...")
916 (imap-interactive-login
918 (lambda (user passwd)
922 "AUTHENTICATE DIGEST-MD5"
924 (digest-md5-parse-digest-challenge
925 (base64-decode-string challenge))
927 (digest-md5-digest-uri
928 "imap" (digest-md5-challenge 'realm)))
930 (digest-md5-digest-response
931 user passwd digest-uri)))
932 (base64-encode-string response 'no-line-break))))
934 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
936 (setq imap-continuation nil)
937 (imap-send-command-1 "")
938 (imap-ok-p (imap-wait-for-tag tag)))))))
942 (defun imap-open-1 (buffer)
943 (with-current-buffer buffer
945 (setq imap-current-mailbox nil
946 imap-current-message nil
948 imap-process (condition-case ()
949 (funcall (nth 2 (assq imap-stream
951 "imap" buffer imap-server imap-port)
954 (set-process-filter imap-process 'imap-arrival-filter)
955 (set-process-sentinel imap-process 'imap-sentinel)
956 (while (and (eq imap-state 'initial)
957 (memq (process-status imap-process) '(open run)))
958 (message "Waiting for response from %s..." imap-server)
959 (accept-process-output imap-process 1))
960 (message "Waiting for response from %s...done" imap-server)
961 (and (memq (process-status imap-process) '(open run))
964 (defun imap-open (server &optional port stream auth buffer)
965 "Open a IMAP connection to host SERVER at PORT returning a buffer.
966 If PORT is unspecified, a default value is used (143 except
967 for SSL which use 993).
968 STREAM indicates the stream to use, see `imap-streams' for available
969 streams. If nil, it choices the best stream the server is capable of.
970 AUTH indicates authenticator to use, see `imap-authenticators' for
971 available authenticators. If nil, it choices the best stream the
972 server is capable of.
973 BUFFER can be a buffer or a name of a buffer, which is created if
974 necessary. If nil, the buffer name is generated."
975 (setq buffer (or buffer (format " *imap* %s:%d" server (or port 0))))
976 (with-current-buffer (get-buffer-create buffer)
977 (if (imap-opened buffer)
979 (mapcar 'make-local-variable imap-local-variables)
980 (imap-disable-multibyte)
981 (buffer-disable-undo)
982 (setq imap-server (or server imap-server))
983 (setq imap-port (or port imap-port))
984 (setq imap-auth (or auth imap-auth))
985 (setq imap-stream (or stream imap-stream))
986 (message "imap: Connecting to %s..." imap-server)
987 (if (null (let ((imap-stream (or imap-stream imap-default-stream)))
988 (imap-open-1 buffer)))
990 (message "imap: Connecting to %s...failed" imap-server)
992 (when (null imap-stream)
993 ;; Need to choose stream.
994 (let ((streams imap-streams))
995 (while (setq stream (pop streams))
996 ;; OK to use this stream?
997 (when (funcall (nth 1 (assq stream imap-stream-alist)) buffer)
999 (if (not (eq imap-default-stream stream))
1000 (with-current-buffer (get-buffer-create
1001 (generate-new-buffer-name " *temp*"))
1002 (mapcar 'make-local-variable imap-local-variables)
1003 (imap-disable-multibyte)
1004 (buffer-disable-undo)
1005 (setq imap-server (or server imap-server))
1006 (setq imap-port (or port imap-port))
1007 (setq imap-auth (or auth imap-auth))
1008 (message "imap: Reconnecting with stream `%s'..." stream)
1009 (if (null (let ((imap-stream stream))
1010 (imap-open-1 (current-buffer))))
1012 (kill-buffer (current-buffer))
1014 "imap: Reconnecting with stream `%s'...failed"
1016 ;; We're done, kill the first connection
1018 (kill-buffer buffer)
1019 (rename-buffer buffer)
1020 (message "imap: Reconnecting with stream `%s'...done"
1022 (setq imap-stream stream)
1023 (setq imap-capability nil)
1024 (setq streams nil)))
1026 (message "imap: Connecting to %s...done" imap-server)
1027 (setq imap-stream stream)
1028 (setq imap-capability nil)
1029 (setq streams nil))))))
1030 (when (imap-opened buffer)
1031 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0)))
1035 (defun imap-opened (&optional buffer)
1036 "Return non-nil if connection to imap server in BUFFER is open.
1037 If BUFFER is nil then the current buffer is used."
1038 (and (setq buffer (get-buffer (or buffer (current-buffer))))
1039 (buffer-live-p buffer)
1040 (with-current-buffer buffer
1042 (memq (process-status imap-process) '(open run))))))
1044 (defun imap-authenticate (&optional user passwd buffer)
1045 "Authenticate to server in BUFFER, using current buffer if nil.
1046 It uses the authenticator specified when opening the server. If the
1047 authenticator requires username/passwords, they are queried from the
1048 user and optionally stored in the buffer. If USER and/or PASSWD is
1049 specified, the user will not be questioned and the username and/or
1050 password is remembered in the buffer."
1051 (with-current-buffer (or buffer (current-buffer))
1052 (if (not (eq imap-state 'nonauth))
1053 (or (eq imap-state 'auth)
1054 (eq imap-state 'select)
1055 (eq imap-state 'examine))
1056 (make-local-variable 'imap-username)
1057 (make-local-variable 'imap-password)
1058 (if user (setq imap-username user))
1059 (if passwd (setq imap-password passwd))
1061 (and (funcall (nth 2 (assq imap-auth
1062 imap-authenticator-alist)) buffer)
1063 (setq imap-state 'auth))
1064 ;; Choose authenticator.
1065 (let ((auths imap-authenticators)
1067 (while (setq auth (pop auths))
1068 ;; OK to use authenticator?
1069 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) buffer)
1070 (message "imap: Authenticating to `%s' using `%s'..."
1072 (setq imap-auth auth)
1073 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) buffer)
1075 (message "imap: Authenticating to `%s' using `%s'...done"
1078 (message "imap: Authenticating to `%s' using `%s'...failed"
1079 imap-server auth)))))
1082 (defun imap-close (&optional buffer)
1083 "Close connection to server in BUFFER.
1084 If BUFFER is nil, the current buffer is used."
1085 (with-current-buffer (or buffer (current-buffer))
1088 (imap-send-command-wait "LOGOUT")
1090 (when (and imap-process
1091 (memq (process-status imap-process) '(open run)))
1092 (delete-process imap-process))
1093 (setq imap-current-mailbox nil
1094 imap-current-message nil
1099 (defun imap-capability (&optional identifier buffer)
1100 "Return a list of identifiers which server in BUFFER support.
1101 If IDENTIFIER, return non-nil if it's among the servers capabilities.
1102 If BUFFER is nil, the current buffer is assumed."
1103 (with-current-buffer (or buffer (current-buffer))
1104 (unless imap-capability
1105 (unless (imap-ok-p (imap-send-command-wait "CAPABILITY"))
1106 (setq imap-capability '(IMAP2))))
1108 (memq (intern (upcase (symbol-name identifier))) imap-capability)
1111 (defun imap-namespace (&optional buffer)
1112 "Return a namespace hierarchy at server in BUFFER.
1113 If BUFFER is nil, the current buffer is assumed."
1114 (with-current-buffer (or buffer (current-buffer))
1115 (unless imap-namespace
1116 (when (imap-capability 'NAMESPACE)
1117 (imap-send-command-wait "NAMESPACE")))
1120 (defun imap-send-command-wait (command &optional buffer)
1121 (imap-wait-for-tag (imap-send-command command buffer) buffer))
1124 ;; Mailbox functions:
1126 (defun imap-mailbox-put (propname value &optional mailbox buffer)
1127 (with-current-buffer (or buffer (current-buffer))
1128 (if imap-mailbox-data
1129 (put (intern (or mailbox imap-current-mailbox) imap-mailbox-data)
1131 (error "Imap-mailbox-data is nil, prop %s value %s mailbox %s buffer %s"
1132 propname value mailbox (current-buffer)))
1135 (defsubst imap-mailbox-get-1 (propname &optional mailbox)
1136 (get (intern-soft (or mailbox imap-current-mailbox) imap-mailbox-data)
1139 (defun imap-mailbox-get (propname &optional mailbox buffer)
1140 (let ((mailbox (imap-utf7-encode mailbox)))
1141 (with-current-buffer (or buffer (current-buffer))
1142 (imap-mailbox-get-1 propname (or mailbox imap-current-mailbox)))))
1144 (defun imap-mailbox-map-1 (func &optional mailbox-decoder buffer)
1145 (with-current-buffer (or buffer (current-buffer))
1149 (push (funcall func (if mailbox-decoder
1150 (funcall mailbox-decoder (symbol-name s))
1151 (symbol-name s))) result))
1155 (defun imap-mailbox-map (func &optional buffer)
1156 "Map a function across each mailbox in `imap-mailbox-data', returning a list.
1157 Function should take a mailbox name (a string) as
1159 (imap-mailbox-map-1 func 'imap-utf7-decode buffer))
1161 (defun imap-current-mailbox (&optional buffer)
1162 (with-current-buffer (or buffer (current-buffer))
1163 (imap-utf7-decode imap-current-mailbox)))
1165 (defun imap-current-mailbox-p-1 (mailbox &optional examine)
1166 (and (string= mailbox imap-current-mailbox)
1168 (eq imap-state 'examine))
1170 (eq imap-state 'selected)))))
1172 (defun imap-current-mailbox-p (mailbox &optional examine buffer)
1173 (with-current-buffer (or buffer (current-buffer))
1174 (imap-current-mailbox-p-1 (imap-utf7-encode mailbox) examine)))
1176 (defun imap-mailbox-select-1 (mailbox &optional examine)
1177 "Select MAILBOX on server in BUFFER.
1178 If EXAMINE is non-nil, do a read-only select."
1179 (if (imap-current-mailbox-p-1 mailbox examine)
1180 imap-current-mailbox
1181 (setq imap-current-mailbox mailbox)
1182 (if (imap-ok-p (imap-send-command-wait
1183 (concat (if examine "EXAMINE" "SELECT") " \""
1186 (setq imap-message-data (make-vector imap-message-prime 0)
1187 imap-state (if examine 'examine 'selected))
1188 imap-current-mailbox)
1189 ;; Failed SELECT/EXAMINE unselects current mailbox
1190 (setq imap-current-mailbox nil))))
1192 (defun imap-mailbox-select (mailbox &optional examine buffer)
1193 (with-current-buffer (or buffer (current-buffer))
1195 (imap-mailbox-select-1 (imap-utf7-encode mailbox) examine))))
1197 (defun imap-mailbox-examine-1 (mailbox &optional buffer)
1198 (with-current-buffer (or buffer (current-buffer))
1199 (imap-mailbox-select-1 mailbox 'examine)))
1201 (defun imap-mailbox-examine (mailbox &optional buffer)
1202 "Examine MAILBOX on server in BUFFER."
1203 (imap-mailbox-select mailbox 'examine buffer))
1205 (defun imap-mailbox-unselect (&optional buffer)
1206 "Close current folder in BUFFER, without expunging articles."
1207 (with-current-buffer (or buffer (current-buffer))
1208 (when (or (eq imap-state 'auth)
1209 (and (imap-capability 'UNSELECT)
1210 (imap-ok-p (imap-send-command-wait "UNSELECT")))
1212 (imap-send-command-wait (concat "EXAMINE \""
1213 imap-current-mailbox
1215 (imap-ok-p (imap-send-command-wait "CLOSE"))))
1216 (setq imap-current-mailbox nil
1217 imap-message-data nil
1221 (defun imap-mailbox-expunge (&optional asynch buffer)
1222 "Expunge articles in current folder in BUFFER.
1223 If ASYNCH, do not wait for succesful completion of the command.
1224 If BUFFER is nil the current buffer is assumed."
1225 (with-current-buffer (or buffer (current-buffer))
1226 (when (and imap-current-mailbox (not (eq imap-state 'examine)))
1228 (imap-send-command "EXPUNGE")
1229 (imap-ok-p (imap-send-command-wait "EXPUNGE"))))))
1231 (defun imap-mailbox-close (&optional asynch buffer)
1232 "Expunge articles and close current folder in BUFFER.
1233 If ASYNCH, do not wait for succesful completion of the command.
1234 If BUFFER is nil the current buffer is assumed."
1235 (with-current-buffer (or buffer (current-buffer))
1236 (when imap-current-mailbox
1238 (imap-add-callback (imap-send-command "CLOSE")
1239 `(lambda (tag status)
1240 (message "IMAP mailbox `%s' closed... %s"
1241 imap-current-mailbox status)
1242 (when (eq ,imap-current-mailbox
1243 imap-current-mailbox)
1244 ;; Don't wipe out data if another mailbox
1246 (setq imap-current-mailbox nil
1247 imap-message-data nil
1248 imap-state 'auth))))
1249 (when (imap-ok-p (imap-send-command-wait "CLOSE"))
1250 (setq imap-current-mailbox nil
1251 imap-message-data nil
1255 (defun imap-mailbox-create-1 (mailbox)
1256 (imap-ok-p (imap-send-command-wait (list "CREATE \"" mailbox "\""))))
1258 (defun imap-mailbox-create (mailbox &optional buffer)
1259 "Create MAILBOX on server in BUFFER.
1260 If BUFFER is nil the current buffer is assumed."
1261 (with-current-buffer (or buffer (current-buffer))
1262 (imap-mailbox-create-1 (imap-utf7-encode mailbox))))
1264 (defun imap-mailbox-delete (mailbox &optional buffer)
1265 "Delete MAILBOX on server in BUFFER.
1266 If BUFFER is nil the current buffer is assumed."
1267 (let ((mailbox (imap-utf7-encode mailbox)))
1268 (with-current-buffer (or buffer (current-buffer))
1270 (imap-send-command-wait (list "DELETE \"" mailbox "\""))))))
1272 (defun imap-mailbox-rename (oldname newname &optional buffer)
1273 "Rename mailbox OLDNAME to NEWNAME on server in BUFFER.
1274 If BUFFER is nil the current buffer is assumed."
1275 (let ((oldname (imap-utf7-encode oldname))
1276 (newname (imap-utf7-encode newname)))
1277 (with-current-buffer (or buffer (current-buffer))
1279 (imap-send-command-wait (list "RENAME \"" oldname "\" "
1280 "\"" newname "\""))))))
1282 (defun imap-mailbox-lsub (&optional root reference add-delimiter buffer)
1283 "Return a list of subscribed mailboxes on server in BUFFER.
1284 If ROOT is non-nil, only list matching mailboxes. If ADD-DELIMITER is
1285 non-nil, a hierarchy delimiter is added to root. REFERENCE is a
1286 implementation-specific string that has to be passed to lsub command."
1287 (with-current-buffer (or buffer (current-buffer))
1288 ;; Make sure we know the hierarchy separator for root's hierarchy
1289 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1290 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1291 (imap-utf7-encode root) "\"")))
1292 ;; clear list data (NB not delimiter and other stuff)
1293 (imap-mailbox-map-1 (lambda (mailbox)
1294 (imap-mailbox-put 'lsub nil mailbox)))
1296 (imap-send-command-wait
1297 (concat "LSUB \"" reference "\" \"" (imap-utf7-encode root)
1298 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1301 (imap-mailbox-map-1 (lambda (mailbox)
1302 (when (imap-mailbox-get-1 'lsub mailbox)
1303 (push (imap-utf7-decode mailbox) out))))
1306 (defun imap-mailbox-list (root &optional reference add-delimiter buffer)
1307 "Return a list of mailboxes matching ROOT on server in BUFFER.
1308 If ADD-DELIMITER is non-nil, a hierarchy delimiter is added to
1309 root. REFERENCE is a implementation-specific string that has to be
1310 passed to list command."
1311 (with-current-buffer (or buffer (current-buffer))
1312 ;; Make sure we know the hierarchy separator for root's hierarchy
1313 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1314 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1315 (imap-utf7-encode root) "\"")))
1316 ;; clear list data (NB not delimiter and other stuff)
1317 (imap-mailbox-map-1 (lambda (mailbox)
1318 (imap-mailbox-put 'list nil mailbox)))
1320 (imap-send-command-wait
1321 (concat "LIST \"" reference "\" \"" (imap-utf7-encode root)
1322 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1325 (imap-mailbox-map-1 (lambda (mailbox)
1326 (when (imap-mailbox-get-1 'list mailbox)
1327 (push (imap-utf7-decode mailbox) out))))
1330 (defun imap-mailbox-subscribe (mailbox &optional buffer)
1331 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1332 Returns non-nil if successful."
1333 (with-current-buffer (or buffer (current-buffer))
1334 (imap-ok-p (imap-send-command-wait (concat "SUBSCRIBE \""
1335 (imap-utf7-encode mailbox)
1338 (defun imap-mailbox-unsubscribe (mailbox &optional buffer)
1339 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1340 Returns non-nil if successful."
1341 (with-current-buffer (or buffer (current-buffer))
1342 (imap-ok-p (imap-send-command-wait (concat "UNSUBSCRIBE "
1343 (imap-utf7-encode mailbox)
1346 (defun imap-mailbox-status (mailbox items &optional buffer)
1347 "Get status items ITEM in MAILBOX from server in BUFFER.
1348 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1349 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1350 or 'unseen. If ITEMS is a list of symbols, a list of values is
1351 returned, if ITEMS is a symbol only its value is returned."
1352 (with-current-buffer (or buffer (current-buffer))
1354 (imap-send-command-wait (list "STATUS \""
1355 (imap-utf7-encode mailbox)
1363 (mapcar (lambda (item)
1364 (imap-mailbox-get item mailbox))
1366 (imap-mailbox-get items mailbox)))))
1368 (defun imap-mailbox-status-asynch (mailbox items &optional buffer)
1369 "Send status item request ITEM on MAILBOX to server in BUFFER.
1370 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1371 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1372 or 'unseen. The IMAP command tag is returned."
1373 (with-current-buffer (or buffer (current-buffer))
1374 (imap-send-command (list "STATUS \""
1375 (imap-utf7-encode mailbox)
1382 (defun imap-mailbox-acl-get (&optional mailbox buffer)
1383 "Get ACL on mailbox from server in BUFFER."
1384 (let ((mailbox (imap-utf7-encode mailbox)))
1385 (with-current-buffer (or buffer (current-buffer))
1387 (imap-send-command-wait (list "GETACL \""
1388 (or mailbox imap-current-mailbox)
1390 (imap-mailbox-get-1 'acl (or mailbox imap-current-mailbox))))))
1392 (defun imap-mailbox-acl-set (identifier rights &optional mailbox buffer)
1393 "Change/set ACL for IDENTIFIER to RIGHTS in MAILBOX from server in BUFFER."
1394 (let ((mailbox (imap-utf7-encode mailbox)))
1395 (with-current-buffer (or buffer (current-buffer))
1397 (imap-send-command-wait (list "SETACL \""
1398 (or mailbox imap-current-mailbox)
1404 (defun imap-mailbox-acl-delete (identifier &optional mailbox buffer)
1405 "Removes any <identifier,rights> pair for IDENTIFIER in MAILBOX from server in BUFFER."
1406 (let ((mailbox (imap-utf7-encode mailbox)))
1407 (with-current-buffer (or buffer (current-buffer))
1409 (imap-send-command-wait (list "DELETEACL \""
1410 (or mailbox imap-current-mailbox)
1415 ;; Message functions:
1417 (defun imap-current-message (&optional buffer)
1418 (with-current-buffer (or buffer (current-buffer))
1419 imap-current-message))
1421 (defun imap-list-to-message-set (list)
1422 (mapconcat (lambda (item)
1423 (number-to-string item))
1429 (defun imap-range-to-message-set (range)
1434 (car item) (cdr item))
1435 (format "%d" item)))
1436 (if (and (listp range) (not (listp (cdr range))))
1437 (list range) ;; make (1 . 2) into ((1 . 2))
1441 (defun imap-fetch-asynch (uids props &optional nouidfetch buffer)
1442 (with-current-buffer (or buffer (current-buffer))
1443 (imap-send-command (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1445 (imap-list-to-message-set uids)
1449 (defun imap-fetch (uids props &optional receive nouidfetch buffer)
1450 "Fetch properties PROPS from message set UIDS from server in BUFFER.
1451 UIDS can be a string, number or a list of numbers. If RECEIVE
1452 is non-nil return theese properties."
1453 (with-current-buffer (or buffer (current-buffer))
1454 (when (imap-ok-p (imap-send-command-wait
1455 (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1457 (imap-list-to-message-set uids)
1460 (if (or (null receive) (stringp uids))
1463 (mapcar (lambda (uid)
1465 (mapcar (lambda (prop)
1466 (imap-message-get uid prop))
1468 (imap-message-get uid receive)))
1470 (imap-message-get uids receive))))))
1472 (defun imap-message-put (uid propname value &optional buffer)
1473 (with-current-buffer (or buffer (current-buffer))
1474 (if imap-message-data
1475 (put (intern (number-to-string uid) imap-message-data)
1477 (error "Imap-message-data is nil, uid %s prop %s value %s buffer %s"
1478 uid propname value (current-buffer)))
1481 (defun imap-message-get (uid propname &optional buffer)
1482 (with-current-buffer (or buffer (current-buffer))
1483 (get (intern-soft (number-to-string uid) imap-message-data)
1486 (defun imap-message-map (func propname &optional buffer)
1487 "Map a function across each mailbox in `imap-message-data', returning a list."
1488 (with-current-buffer (or buffer (current-buffer))
1492 (push (funcall func (get s 'UID) (get s propname)) result))
1496 (defmacro imap-message-envelope-date (uid &optional buffer)
1497 `(with-current-buffer (or ,buffer (current-buffer))
1498 (elt (imap-message-get ,uid 'ENVELOPE) 0)))
1500 (defmacro imap-message-envelope-subject (uid &optional buffer)
1501 `(with-current-buffer (or ,buffer (current-buffer))
1502 (elt (imap-message-get ,uid 'ENVELOPE) 1)))
1504 (defmacro imap-message-envelope-from (uid &optional buffer)
1505 `(with-current-buffer (or ,buffer (current-buffer))
1506 (elt (imap-message-get ,uid 'ENVELOPE) 2)))
1508 (defmacro imap-message-envelope-sender (uid &optional buffer)
1509 `(with-current-buffer (or ,buffer (current-buffer))
1510 (elt (imap-message-get ,uid 'ENVELOPE) 3)))
1512 (defmacro imap-message-envelope-reply-to (uid &optional buffer)
1513 `(with-current-buffer (or ,buffer (current-buffer))
1514 (elt (imap-message-get ,uid 'ENVELOPE) 4)))
1516 (defmacro imap-message-envelope-to (uid &optional buffer)
1517 `(with-current-buffer (or ,buffer (current-buffer))
1518 (elt (imap-message-get ,uid 'ENVELOPE) 5)))
1520 (defmacro imap-message-envelope-cc (uid &optional buffer)
1521 `(with-current-buffer (or ,buffer (current-buffer))
1522 (elt (imap-message-get ,uid 'ENVELOPE) 6)))
1524 (defmacro imap-message-envelope-bcc (uid &optional buffer)
1525 `(with-current-buffer (or ,buffer (current-buffer))
1526 (elt (imap-message-get ,uid 'ENVELOPE) 7)))
1528 (defmacro imap-message-envelope-in-reply-to (uid &optional buffer)
1529 `(with-current-buffer (or ,buffer (current-buffer))
1530 (elt (imap-message-get ,uid 'ENVELOPE) 8)))
1532 (defmacro imap-message-envelope-message-id (uid &optional buffer)
1533 `(with-current-buffer (or ,buffer (current-buffer))
1534 (elt (imap-message-get ,uid 'ENVELOPE) 9)))
1536 (defmacro imap-message-body (uid &optional buffer)
1537 `(with-current-buffer (or ,buffer (current-buffer))
1538 (imap-message-get ,uid 'BODY)))
1540 (defun imap-search (predicate &optional buffer)
1541 (with-current-buffer (or buffer (current-buffer))
1542 (imap-mailbox-put 'search 'dummy)
1543 (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate)))
1544 (if (eq (imap-mailbox-get-1 'search imap-current-mailbox) 'dummy)
1546 (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...")
1548 (imap-mailbox-get-1 'search imap-current-mailbox)))))
1550 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer)
1551 "Return t iff FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER."
1552 (with-current-buffer (or buffer (current-buffer))
1553 (or (member "\\*" (imap-mailbox-get 'permanentflags mailbox))
1554 (member flag (imap-mailbox-get 'permanentflags mailbox)))))
1556 (defun imap-message-flags-set (articles flags &optional silent buffer)
1557 (when (and articles flags)
1558 (with-current-buffer (or buffer (current-buffer))
1559 (imap-ok-p (imap-send-command-wait
1560 (concat "UID STORE " articles
1561 " FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1563 (defun imap-message-flags-del (articles flags &optional silent buffer)
1564 (when (and articles flags)
1565 (with-current-buffer (or buffer (current-buffer))
1566 (imap-ok-p (imap-send-command-wait
1567 (concat "UID STORE " articles
1568 " -FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1570 (defun imap-message-flags-add (articles flags &optional silent buffer)
1571 (when (and articles flags)
1572 (with-current-buffer (or buffer (current-buffer))
1573 (imap-ok-p (imap-send-command-wait
1574 (concat "UID STORE " articles
1575 " +FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1577 (defun imap-message-copyuid-1 (mailbox)
1578 (if (imap-capability 'UIDPLUS)
1579 (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox))
1580 (string-to-number (nth 2 (imap-mailbox-get-1 'copyuid mailbox))))
1581 (let ((old-mailbox imap-current-mailbox)
1583 (imap-message-data (make-vector 2 0)))
1584 (when (imap-mailbox-examine-1 mailbox)
1586 (and (imap-fetch "*" "UID")
1587 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1588 (apply 'max (imap-message-map
1589 (lambda (uid prop) uid) 'UID))))
1591 (imap-mailbox-select old-mailbox (eq state 'examine))
1592 (imap-mailbox-unselect)))))))
1594 (defun imap-message-copyuid (mailbox &optional buffer)
1595 (with-current-buffer (or buffer (current-buffer))
1596 (imap-message-copyuid-1 (imap-utf7-decode mailbox))))
1598 (defun imap-message-copy (articles mailbox
1599 &optional dont-create no-copyuid buffer)
1600 "Copy ARTICLES (a string message set) to MAILBOX on server in
1601 BUFFER, creating mailbox if it doesn't exist. If dont-create is
1602 non-nil, it will not create a mailbox. On success, return a list with
1603 the UIDVALIDITY of the mailbox the article(s) was copied to as the
1604 first element, rest of list contain the saved articles' UIDs."
1606 (with-current-buffer (or buffer (current-buffer))
1607 (let ((mailbox (imap-utf7-encode mailbox)))
1608 (if (let ((cmd (concat "UID COPY " articles " \"" mailbox "\""))
1609 (imap-current-target-mailbox mailbox))
1610 (if (imap-ok-p (imap-send-command-wait cmd))
1612 (when (and (not dont-create)
1613 ;; removed because of buggy Oracle server
1614 ;; that doesn't send TRYCREATE tags (which
1615 ;; is a MUST according to specifications):
1616 ;;(imap-mailbox-get-1 'trycreate mailbox)
1617 (imap-mailbox-create-1 mailbox))
1618 (imap-ok-p (imap-send-command-wait cmd)))))
1620 (imap-message-copyuid-1 mailbox)))))))
1622 (defun imap-message-appenduid-1 (mailbox)
1623 (if (imap-capability 'UIDPLUS)
1624 (imap-mailbox-get-1 'appenduid mailbox)
1625 (let ((old-mailbox imap-current-mailbox)
1627 (imap-message-data (make-vector 2 0)))
1628 (when (imap-mailbox-examine-1 mailbox)
1630 (and (imap-fetch "*" "UID")
1631 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1632 (apply 'max (imap-message-map
1633 (lambda (uid prop) uid) 'UID))))
1635 (imap-mailbox-select old-mailbox (eq state 'examine))
1636 (imap-mailbox-unselect)))))))
1638 (defun imap-message-appenduid (mailbox &optional buffer)
1639 (with-current-buffer (or buffer (current-buffer))
1640 (imap-message-appenduid-1 (imap-utf7-encode mailbox))))
1642 (defun imap-message-append (mailbox article &optional flags date-time buffer)
1643 "Append ARTICLE (a buffer) to MAILBOX on server in BUFFER.
1644 FLAGS and DATE-TIME is currently not used. Return a cons holding
1645 uidvalidity of MAILBOX and UID the newly created article got, or nil
1647 (let ((mailbox (imap-utf7-encode mailbox)))
1648 (with-current-buffer (or buffer (current-buffer))
1649 (and (let ((imap-current-target-mailbox mailbox))
1651 (imap-send-command-wait
1652 (list "APPEND \"" mailbox "\" " article))))
1653 (imap-message-appenduid-1 mailbox)))))
1655 (defun imap-body-lines (body)
1656 "Return number of lines in article by looking at the mime bodystructure BODY."
1658 (if (stringp (car body))
1659 (cond ((and (string= (upcase (car body)) "TEXT")
1660 (numberp (nth 7 body)))
1662 ((and (string= (upcase (car body)) "MESSAGE")
1663 (numberp (nth 9 body)))
1666 (apply '+ (mapcar 'imap-body-lines body)))
1669 (defun imap-envelope-from (from)
1670 "Return a from string line."
1672 (concat (aref from 0)
1673 (if (aref from 0) " <")
1677 (if (aref from 0) ">"))))
1680 ;; Internal functions.
1682 (defun imap-add-callback (tag func)
1683 (setq imap-callbacks (append (list (cons tag func)) imap-callbacks)))
1685 (defun imap-send-command-1 (cmdstr)
1686 (setq cmdstr (concat cmdstr imap-client-eol))
1688 (with-current-buffer (get-buffer-create imap-log-buffer)
1689 (imap-disable-multibyte)
1690 (buffer-disable-undo)
1691 (goto-char (point-max))
1693 (process-send-string imap-process cmdstr))
1695 (defun imap-send-command (command &optional buffer)
1696 (with-current-buffer (or buffer (current-buffer))
1697 (if (not (listp command)) (setq command (list command)))
1698 (let ((tag (setq imap-tag (1+ imap-tag)))
1700 (setq cmdstr (concat (number-to-string imap-tag) " "))
1701 (while (setq cmd (pop command))
1702 (cond ((stringp cmd)
1703 (setq cmdstr (concat cmdstr cmd)))
1705 (let ((eol imap-client-eol)
1706 (calcfirst imap-calculate-literal-size-first)
1708 (with-current-buffer cmd
1710 (setq size (buffer-size)))
1711 (when (not (equal eol "\r\n"))
1712 ;; XXX modifies buffer!
1713 (goto-char (point-min))
1714 (while (search-forward "\r\n" nil t)
1715 (replace-match eol)))
1717 (setq size (buffer-size))))
1719 (concat cmdstr (format "{%d}" size))))
1722 (imap-send-command-1 cmdstr)
1724 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1725 (setq command nil) ;; abort command if no cont-req
1726 (let ((process imap-process)
1727 (stream imap-stream)
1728 (eol imap-client-eol))
1729 (with-current-buffer cmd
1731 (with-current-buffer (get-buffer-create
1733 (imap-disable-multibyte)
1734 (buffer-disable-undo)
1735 (goto-char (point-max))
1736 (insert-buffer-substring cmd)))
1737 (process-send-region process (point-min)
1739 (process-send-string process imap-client-eol))))
1740 (setq imap-continuation nil)))
1742 (imap-send-command-1 cmdstr)
1745 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1746 (setq command nil) ;; abort command if no cont-req
1747 (setq command (cons (funcall cmd imap-continuation)
1749 (setq imap-continuation nil)))
1751 (error "Unknown command type"))))
1753 (imap-send-command-1 cmdstr))
1756 (defun imap-wait-for-tag (tag &optional buffer)
1757 (with-current-buffer (or buffer (current-buffer))
1758 (let (imap-have-messaged)
1759 (while (and (null imap-continuation)
1760 (memq (process-status imap-process) '(open run))
1761 (< imap-reached-tag tag))
1762 (let ((len (/ (point-max) 1024))
1765 (setq imap-have-messaged t)
1766 (message "imap read: %dk" len))
1767 (accept-process-output imap-process
1768 (truncate imap-read-timeout)
1769 (truncate (* (- imap-read-timeout
1770 (truncate imap-read-timeout))
1772 ;; A process can die _before_ we have processed everything it
1773 ;; has to say. Moreover, this can happen in between the call to
1774 ;; accept-process-output and the call to process-status in an
1775 ;; iteration of the loop above.
1776 (when (and (null imap-continuation)
1777 (< imap-reached-tag tag))
1778 (accept-process-output imap-process 0 0))
1779 (when imap-have-messaged
1781 (and (memq (process-status imap-process) '(open run))
1782 (or (assq tag imap-failed-tags)
1783 (if imap-continuation
1787 (defun imap-sentinel (process string)
1788 (delete-process process))
1790 (defun imap-find-next-line ()
1791 "Return point at end of current line, taking into account literals.
1792 Return nil if no complete line has arrived."
1793 (when (re-search-forward (concat imap-server-eol "\\|{\\([0-9]+\\)}"
1796 (if (match-string 1)
1797 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1799 (goto-char (+ (point) (string-to-number (match-string 1))))
1800 (imap-find-next-line))
1803 (defun imap-arrival-filter (proc string)
1804 "IMAP process filter."
1805 ;; Sometimes, we are called even though the process has died.
1806 ;; Better abstain from doing stuff in that case.
1807 (when (buffer-name (process-buffer proc))
1808 (with-current-buffer (process-buffer proc)
1809 (goto-char (point-max))
1812 (with-current-buffer (get-buffer-create imap-log-buffer)
1813 (imap-disable-multibyte)
1814 (buffer-disable-undo)
1815 (goto-char (point-max))
1818 (goto-char (point-min))
1819 (while (setq end (imap-find-next-line))
1821 (narrow-to-region (point-min) end)
1822 (delete-backward-char (length imap-server-eol))
1823 (goto-char (point-min))
1825 (cond ((eq imap-state 'initial)
1826 (imap-parse-greeting))
1827 ((or (eq imap-state 'auth)
1828 (eq imap-state 'nonauth)
1829 (eq imap-state 'selected)
1830 (eq imap-state 'examine))
1831 (imap-parse-response))
1833 (message "Unknown state %s in arrival filter"
1835 (delete-region (point-min) (point-max)))))))))
1840 (defsubst imap-forward ()
1841 (or (eobp) (forward-char)))
1844 ;; ; Unsigned 32-bit integer
1845 ;; ; (0 <= n < 4,294,967,296)
1847 (defsubst imap-parse-number ()
1848 (when (looking-at "[0-9]+")
1850 (string-to-number (match-string 0))
1851 (goto-char (match-end 0)))))
1853 ;; literal = "{" number "}" CRLF *CHAR8
1854 ;; ; Number represents the number of CHAR8s
1856 (defsubst imap-parse-literal ()
1857 (when (looking-at "{\\([0-9]+\\)}\r\n")
1858 (let ((pos (match-end 0))
1859 (len (string-to-number (match-string 1))))
1860 (if (< (point-max) (+ pos len))
1862 (goto-char (+ pos len))
1863 (buffer-substring pos (+ pos len))))))
1865 ;; string = quoted / literal
1867 ;; quoted = DQUOTE *QUOTED-CHAR DQUOTE
1869 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
1870 ;; "\" quoted-specials
1872 ;; quoted-specials = DQUOTE / "\"
1874 ;; TEXT-CHAR = <any CHAR except CR and LF>
1876 (defsubst imap-parse-string ()
1877 (cond ((eq (char-after) ?\")
1879 (let ((p (point)) (name ""))
1880 (skip-chars-forward "^\"\\\\")
1881 (setq name (buffer-substring p (point)))
1882 (while (eq (char-after) ?\\)
1883 (setq p (1+ (point)))
1885 (skip-chars-forward "^\"\\\\")
1886 (setq name (concat name (buffer-substring p (point)))))
1889 ((eq (char-after) ?{)
1890 (imap-parse-literal))))
1894 (defsubst imap-parse-nil ()
1895 (if (looking-at "NIL")
1896 (goto-char (match-end 0))))
1898 ;; nstring = string / nil
1900 (defsubst imap-parse-nstring ()
1901 (or (imap-parse-string)
1902 (and (imap-parse-nil)
1905 ;; astring = atom / string
1907 ;; atom = 1*ATOM-CHAR
1909 ;; ATOM-CHAR = <any CHAR except atom-specials>
1911 ;; atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
1914 ;; list-wildcards = "%" / "*"
1916 ;; quoted-specials = DQUOTE / "\"
1918 (defsubst imap-parse-astring ()
1919 (or (imap-parse-string)
1920 (buffer-substring (point)
1921 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1922 (goto-char (1- (match-end 0)))
1926 ;; address = "(" addr-name SP addr-adl SP addr-mailbox SP
1929 ;; addr-adl = nstring
1930 ;; ; Holds route from [RFC-822] route-addr if
1933 ;; addr-host = nstring
1934 ;; ; nil indicates [RFC-822] group syntax.
1935 ;; ; Otherwise, holds [RFC-822] domain name
1937 ;; addr-mailbox = nstring
1938 ;; ; nil indicates end of [RFC-822] group; if
1939 ;; ; non-nil and addr-host is nil, holds
1940 ;; ; [RFC-822] group name.
1941 ;; ; Otherwise, holds [RFC-822] local-part
1942 ;; ; after removing [RFC-822] quoting
1944 ;; addr-name = nstring
1945 ;; ; If non-nil, holds phrase from [RFC-822]
1946 ;; ; mailbox after removing [RFC-822] quoting
1949 (defsubst imap-parse-address ()
1951 (when (eq (char-after) ?\()
1953 (setq address (vector (prog1 (imap-parse-nstring)
1955 (prog1 (imap-parse-nstring)
1957 (prog1 (imap-parse-nstring)
1959 (imap-parse-nstring)))
1960 (when (eq (char-after) ?\))
1964 ;; address-list = "(" 1*address ")" / nil
1968 (defsubst imap-parse-address-list ()
1969 (if (eq (char-after) ?\()
1970 (let (address addresses)
1972 (while (and (not (eq (char-after) ?\)))
1973 ;; next line for MS Exchange bug
1974 (progn (and (eq (char-after) ? ) (imap-forward)) t)
1975 (setq address (imap-parse-address)))
1976 (setq addresses (cons address addresses)))
1977 (when (eq (char-after) ?\))
1979 (nreverse addresses)))
1980 (assert (imap-parse-nil) t "In imap-parse-address-list")))
1982 ;; mailbox = "INBOX" / astring
1983 ;; ; INBOX is case-insensitive. All case variants of
1984 ;; ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
1985 ;; ; not as an astring. An astring which consists of
1986 ;; ; the case-insensitive sequence "I" "N" "B" "O" "X"
1987 ;; ; is considered to be INBOX and not an astring.
1988 ;; ; Refer to section 5.1 for further
1989 ;; ; semantic details of mailbox names.
1991 (defsubst imap-parse-mailbox ()
1992 (let ((mailbox (imap-parse-astring)))
1993 (if (string-equal "INBOX" (upcase mailbox))
1997 ;; greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
1999 ;; resp-cond-auth = ("OK" / "PREAUTH") SP resp-text
2000 ;; ; Authentication condition
2002 ;; resp-cond-bye = "BYE" SP resp-text
2004 (defun imap-parse-greeting ()
2005 "Parse a IMAP greeting."
2006 (cond ((looking-at "\\* OK ")
2007 (setq imap-state 'nonauth))
2008 ((looking-at "\\* PREAUTH ")
2009 (setq imap-state 'auth))
2010 ((looking-at "\\* BYE ")
2011 (setq imap-state 'closed))))
2013 ;; response = *(continue-req / response-data) response-done
2015 ;; continue-req = "+" SP (resp-text / base64) CRLF
2017 ;; response-data = "*" SP (resp-cond-state / resp-cond-bye /
2018 ;; mailbox-data / message-data / capability-data) CRLF
2020 ;; response-done = response-tagged / response-fatal
2022 ;; response-fatal = "*" SP resp-cond-bye CRLF
2023 ;; ; Server closes connection immediately
2025 ;; response-tagged = tag SP resp-cond-state CRLF
2027 ;; resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
2028 ;; ; Status condition
2030 ;; resp-cond-bye = "BYE" SP resp-text
2032 ;; mailbox-data = "FLAGS" SP flag-list /
2033 ;; "LIST" SP mailbox-list /
2034 ;; "LSUB" SP mailbox-list /
2035 ;; "SEARCH" *(SP nz-number) /
2036 ;; "STATUS" SP mailbox SP "("
2037 ;; [status-att SP number *(SP status-att SP number)] ")" /
2038 ;; number SP "EXISTS" /
2039 ;; number SP "RECENT"
2041 ;; message-data = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att))
2043 ;; capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
2045 ;; ; IMAP4rev1 servers which offer RFC 1730
2046 ;; ; compatibility MUST list "IMAP4" as the first
2049 (defun imap-parse-response ()
2050 "Parse a IMAP command response."
2052 (case (setq token (read (current-buffer)))
2053 (+ (setq imap-continuation
2054 (or (buffer-substring (min (point-max) (1+ (point)))
2057 (* (case (prog1 (setq token (read (current-buffer)))
2059 (OK (imap-parse-resp-text))
2060 (NO (imap-parse-resp-text))
2061 (BAD (imap-parse-resp-text))
2062 (BYE (imap-parse-resp-text))
2063 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list)))
2064 (LIST (imap-parse-data-list 'list))
2065 (LSUB (imap-parse-data-list 'lsub))
2066 (SEARCH (imap-mailbox-put
2068 (read (concat "(" (buffer-substring (point) (point-max)) ")"))))
2069 (STATUS (imap-parse-status))
2070 (CAPABILITY (setq imap-capability
2071 (read (concat "(" (upcase (buffer-substring
2072 (point) (point-max)))
2074 (ACL (imap-parse-acl))
2075 (t (case (prog1 (read (current-buffer))
2077 (EXISTS (imap-mailbox-put 'exists token))
2078 (RECENT (imap-mailbox-put 'recent token))
2080 (FETCH (imap-parse-fetch token))
2081 (t (message "Garbage: %s" (buffer-string)))))))
2083 (if (not (integerp token))
2084 (message "Garbage: %s" (buffer-string))
2085 (case (prog1 (setq status (read (current-buffer)))
2088 (setq imap-reached-tag (max imap-reached-tag token))
2089 (imap-parse-resp-text)))
2091 (setq imap-reached-tag (max imap-reached-tag token))
2093 (imap-parse-resp-text))
2095 (when (eq (char-after) ?\[)
2096 (setq code (buffer-substring (point)
2097 (search-forward "]")))
2099 (setq text (buffer-substring (point) (point-max)))
2100 (push (list token status code text)
2101 imap-failed-tags))))
2103 (setq imap-reached-tag (max imap-reached-tag token))
2105 (imap-parse-resp-text))
2107 (when (eq (char-after) ?\[)
2108 (setq code (buffer-substring (point)
2109 (search-forward "]")))
2111 (setq text (buffer-substring (point) (point-max)))
2112 (push (list token status code text) imap-failed-tags)
2113 (error "Internal error, tag %s status %s code %s text %s"
2114 token status code text))))
2115 (t (message "Garbage: %s" (buffer-string))))
2116 (when (assq token imap-callbacks)
2117 (funcall (cdr (assq token imap-callbacks)) token status)
2118 (setq imap-callbacks
2119 (imap-remassoc token imap-callbacks)))))))))
2121 ;; resp-text = ["[" resp-text-code "]" SP] text
2123 ;; text = 1*TEXT-CHAR
2125 ;; TEXT-CHAR = <any CHAR except CR and LF>
2127 (defun imap-parse-resp-text ()
2128 (imap-parse-resp-text-code))
2130 ;; resp-text-code = "ALERT" /
2131 ;; "BADCHARSET [SP "(" astring *(SP astring) ")" ] /
2132 ;; "NEWNAME" SP string SP string /
2134 ;; "PERMANENTFLAGS" SP "("
2135 ;; [flag-perm *(SP flag-perm)] ")" /
2139 ;; "UIDNEXT" SP nz-number /
2140 ;; "UIDVALIDITY" SP nz-number /
2141 ;; "UNSEEN" SP nz-number /
2142 ;; resp-text-atom [SP 1*<any TEXT-CHAR except "]">]
2144 ;; resp_code_apnd = "APPENDUID" SPACE nz_number SPACE uniqueid
2146 ;; resp_code_copy = "COPYUID" SPACE nz_number SPACE set SPACE set
2148 ;; set = sequence-num / (sequence-num ":" sequence-num) /
2150 ;; ; Identifies a set of messages. For message
2151 ;; ; sequence numbers, these are consecutive
2152 ;; ; numbers from 1 to the number of messages in
2154 ;; ; Comma delimits individual numbers, colon
2155 ;; ; delimits between two numbers inclusive.
2156 ;; ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13,
2157 ;; ; 14,15 for a mailbox with 15 messages.
2159 ;; sequence-num = nz-number / "*"
2160 ;; ; * is the largest number in use. For message
2161 ;; ; sequence numbers, it is the number of messages
2162 ;; ; in the mailbox. For unique identifiers, it is
2163 ;; ; the unique identifier of the last message in
2166 ;; flag-perm = flag / "\*"
2168 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2169 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2170 ;; ; Does not include "\Recent"
2172 ;; flag-extension = "\" atom
2173 ;; ; Future expansion. Client implementations
2174 ;; ; MUST accept flag-extension flags. Server
2175 ;; ; implementations MUST NOT generate
2176 ;; ; flag-extension flags except as defined by
2177 ;; ; future standard or standards-track
2178 ;; ; revisions of this specification.
2180 ;; flag-keyword = atom
2182 ;; resp-text-atom = 1*<any ATOM-CHAR except "]">
2184 (defun imap-parse-resp-text-code ()
2185 ;; xxx next line for stalker communigate pro 3.3.1 bug
2186 (when (looking-at " \\[")
2188 (when (eq (char-after) ?\[)
2190 (cond ((search-forward "PERMANENTFLAGS " nil t)
2191 (imap-mailbox-put 'permanentflags (imap-parse-flag-list)))
2192 ((search-forward "UIDNEXT \\([0-9]+\\)" nil t)
2193 (imap-mailbox-put 'uidnext (match-string 1)))
2194 ((search-forward "UNSEEN " nil t)
2195 (imap-mailbox-put 'first-unseen (read (current-buffer))))
2196 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
2197 (imap-mailbox-put 'uidvalidity (match-string 1)))
2198 ((search-forward "READ-ONLY" nil t)
2199 (imap-mailbox-put 'read-only t))
2200 ((search-forward "NEWNAME " nil t)
2201 (let (oldname newname)
2202 (setq oldname (imap-parse-string))
2204 (setq newname (imap-parse-string))
2205 (imap-mailbox-put 'newname newname oldname)))
2206 ((search-forward "TRYCREATE" nil t)
2207 (imap-mailbox-put 'trycreate t imap-current-target-mailbox))
2208 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
2209 (imap-mailbox-put 'appenduid
2210 (list (match-string 1)
2211 (string-to-number (match-string 2)))
2212 imap-current-target-mailbox))
2213 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
2214 (imap-mailbox-put 'copyuid (list (match-string 1)
2217 imap-current-target-mailbox))
2218 ((search-forward "ALERT] " nil t)
2219 (message "Imap server %s information: %s" imap-server
2220 (buffer-substring (point) (point-max)))))))
2222 ;; mailbox-list = "(" [mbx-list-flags] ")" SP
2223 ;; (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox
2225 ;; mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag
2226 ;; *(SP mbx-list-oflag) /
2227 ;; mbx-list-oflag *(SP mbx-list-oflag)
2229 ;; mbx-list-oflag = "\Noinferiors" / flag-extension
2230 ;; ; Other flags; multiple possible per LIST response
2232 ;; mbx-list-sflag = "\Noselect" / "\Marked" / "\Unmarked"
2233 ;; ; Selectability flags; only one per LIST response
2235 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
2236 ;; "\" quoted-specials
2238 ;; quoted-specials = DQUOTE / "\"
2240 (defun imap-parse-data-list (type)
2241 (let (flags delimiter mailbox)
2242 (setq flags (imap-parse-flag-list))
2243 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
2244 (setq delimiter (match-string 1))
2245 (goto-char (1+ (match-end 0)))
2246 (when (setq mailbox (imap-parse-mailbox))
2247 (imap-mailbox-put type t mailbox)
2248 (imap-mailbox-put 'list-flags flags mailbox)
2249 (imap-mailbox-put 'delimiter delimiter mailbox)))))
2251 ;; msg_att ::= "(" 1#("ENVELOPE" SPACE envelope /
2252 ;; "FLAGS" SPACE "(" #(flag / "\Recent") ")" /
2253 ;; "INTERNALDATE" SPACE date_time /
2254 ;; "RFC822" [".HEADER" / ".TEXT"] SPACE nstring /
2255 ;; "RFC822.SIZE" SPACE number /
2256 ;; "BODY" ["STRUCTURE"] SPACE body /
2257 ;; "BODY" section ["<" number ">"] SPACE nstring /
2258 ;; "UID" SPACE uniqueid) ")"
2260 ;; date_time ::= <"> date_day_fixed "-" date_month "-" date_year
2261 ;; SPACE time SPACE zone <">
2263 ;; section ::= "[" [section_text / (nz_number *["." nz_number]
2264 ;; ["." (section_text / "MIME")])] "]"
2266 ;; section_text ::= "HEADER" / "HEADER.FIELDS" [".NOT"]
2267 ;; SPACE header_list / "TEXT"
2269 ;; header_fld_name ::= astring
2271 ;; header_list ::= "(" 1#header_fld_name ")"
2273 (defsubst imap-parse-header-list ()
2274 (when (eq (char-after) ?\()
2276 (while (not (eq (char-after) ?\)))
2278 (push (imap-parse-astring) strlist))
2280 (nreverse strlist))))
2282 (defsubst imap-parse-fetch-body-section ()
2284 (buffer-substring (point) (1- (re-search-forward "[] ]" nil t)))))
2285 (if (eq (char-before) ? )
2287 (mapconcat 'identity (cons section (imap-parse-header-list)) " ")
2288 (search-forward "]" nil t))
2291 (defun imap-parse-fetch (response)
2292 (when (eq (char-after) ?\()
2293 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text
2294 rfc822size body bodydetail bodystructure flags-empty)
2295 (while (not (eq (char-after) ?\)))
2297 (let ((token (read (current-buffer))))
2299 (cond ((eq token 'UID)
2300 (setq uid (condition-case ()
2301 (read (current-buffer))
2304 (setq flags (imap-parse-flag-list))
2306 (setq flags-empty 't)))
2307 ((eq token 'ENVELOPE)
2308 (setq envelope (imap-parse-envelope)))
2309 ((eq token 'INTERNALDATE)
2310 (setq internaldate (imap-parse-string)))
2312 (setq rfc822 (imap-parse-nstring)))
2313 ((eq token 'RFC822.HEADER)
2314 (setq rfc822header (imap-parse-nstring)))
2315 ((eq token 'RFC822.TEXT)
2316 (setq rfc822text (imap-parse-nstring)))
2317 ((eq token 'RFC822.SIZE)
2318 (setq rfc822size (read (current-buffer))))
2320 (if (eq (char-before) ?\[)
2322 (upcase (imap-parse-fetch-body-section))
2323 (and (eq (char-after) ?<)
2324 (buffer-substring (1+ (point))
2325 (search-forward ">" nil t)))
2326 (progn (imap-forward)
2327 (imap-parse-nstring)))
2329 (setq body (imap-parse-body))))
2330 ((eq token 'BODYSTRUCTURE)
2331 (setq bodystructure (imap-parse-body))))))
2333 (setq imap-current-message uid)
2334 (imap-message-put uid 'UID uid)
2335 (and (or flags flags-empty) (imap-message-put uid 'FLAGS flags))
2336 (and envelope (imap-message-put uid 'ENVELOPE envelope))
2337 (and internaldate (imap-message-put uid 'INTERNALDATE internaldate))
2338 (and rfc822 (imap-message-put uid 'RFC822 rfc822))
2339 (and rfc822header (imap-message-put uid 'RFC822.HEADER rfc822header))
2340 (and rfc822text (imap-message-put uid 'RFC822.TEXT rfc822text))
2341 (and rfc822size (imap-message-put uid 'RFC822.SIZE rfc822size))
2342 (and body (imap-message-put uid 'BODY body))
2343 (and bodydetail (imap-message-put uid 'BODYDETAIL bodydetail))
2344 (and bodystructure (imap-message-put uid 'BODYSTRUCTURE bodystructure))
2345 (run-hooks 'imap-fetch-data-hook)))))
2347 ;; mailbox-data = ...
2348 ;; "STATUS" SP mailbox SP "("
2349 ;; [status-att SP number
2350 ;; *(SP status-att SP number)] ")"
2353 ;; status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" /
2356 (defun imap-parse-status ()
2357 (let ((mailbox (imap-parse-mailbox)))
2358 (if (eq (char-after) ? )
2360 (when (and mailbox (eq (char-after) ?\())
2361 (while (and (not (eq (char-after) ?\)))
2362 (or (forward-char) t)
2363 (looking-at "\\([A-Za-z]+\\) "))
2364 (let ((token (match-string 1)))
2365 (goto-char (match-end 0))
2366 (cond ((string= token "MESSAGES")
2367 (imap-mailbox-put 'messages (read (current-buffer)) mailbox))
2368 ((string= token "RECENT")
2369 (imap-mailbox-put 'recent (read (current-buffer)) mailbox))
2370 ((string= token "UIDNEXT")
2371 (and (looking-at "[0-9]+")
2372 (imap-mailbox-put 'uidnext (match-string 0) mailbox)
2373 (goto-char (match-end 0))))
2374 ((string= token "UIDVALIDITY")
2375 (and (looking-at "[0-9]+")
2376 (imap-mailbox-put 'uidvalidity (match-string 0) mailbox)
2377 (goto-char (match-end 0))))
2378 ((string= token "UNSEEN")
2379 (imap-mailbox-put 'unseen (read (current-buffer)) mailbox))
2381 (message "Unknown status data %s in mailbox %s ignored"
2383 (read (current-buffer)))))))))
2385 ;; acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE
2388 ;; identifier ::= astring
2390 ;; rights ::= astring
2392 (defun imap-parse-acl ()
2393 (let ((mailbox (imap-parse-mailbox))
2394 identifier rights acl)
2395 (while (eq (char-after) ?\ )
2397 (setq identifier (imap-parse-astring))
2399 (setq rights (imap-parse-astring))
2400 (setq acl (append acl (list (cons identifier rights)))))
2401 (imap-mailbox-put 'acl acl mailbox)))
2403 ;; flag-list = "(" [flag *(SP flag)] ")"
2405 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2406 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2407 ;; ; Does not include "\Recent"
2409 ;; flag-keyword = atom
2411 ;; flag-extension = "\" atom
2412 ;; ; Future expansion. Client implementations
2413 ;; ; MUST accept flag-extension flags. Server
2414 ;; ; implementations MUST NOT generate
2415 ;; ; flag-extension flags except as defined by
2416 ;; ; future standard or standards-track
2417 ;; ; revisions of this specification.
2419 (defun imap-parse-flag-list ()
2420 (let (flag-list start)
2421 (assert (eq (char-after) ?\() t "In imap-parse-flag-list")
2422 (while (and (not (eq (char-after) ?\)))
2425 ;; next line for Courier IMAP bug.
2426 (skip-chars-forward " ")
2428 (> (skip-chars-forward "^ )" (imap-point-at-eol)) 0))
2429 (push (buffer-substring start (point)) flag-list))
2430 (assert (eq (char-after) ?\)) t "In imap-parse-flag-list")
2432 (nreverse flag-list)))
2434 ;; envelope = "(" env-date SP env-subject SP env-from SP env-sender SP
2435 ;; env-reply-to SP env-to SP env-cc SP env-bcc SP
2436 ;; env-in-reply-to SP env-message-id ")"
2438 ;; env-bcc = "(" 1*address ")" / nil
2440 ;; env-cc = "(" 1*address ")" / nil
2442 ;; env-date = nstring
2444 ;; env-from = "(" 1*address ")" / nil
2446 ;; env-in-reply-to = nstring
2448 ;; env-message-id = nstring
2450 ;; env-reply-to = "(" 1*address ")" / nil
2452 ;; env-sender = "(" 1*address ")" / nil
2454 ;; env-subject = nstring
2456 ;; env-to = "(" 1*address ")" / nil
2458 (defun imap-parse-envelope ()
2459 (when (eq (char-after) ?\()
2461 (vector (prog1 (imap-parse-nstring) ;; date
2463 (prog1 (imap-parse-nstring) ;; subject
2465 (prog1 (imap-parse-address-list) ;; from
2467 (prog1 (imap-parse-address-list) ;; sender
2469 (prog1 (imap-parse-address-list) ;; reply-to
2471 (prog1 (imap-parse-address-list) ;; to
2473 (prog1 (imap-parse-address-list) ;; cc
2475 (prog1 (imap-parse-address-list) ;; bcc
2477 (prog1 (imap-parse-nstring) ;; in-reply-to
2479 (prog1 (imap-parse-nstring) ;; message-id
2482 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2484 (defsubst imap-parse-string-list ()
2485 (cond ((eq (char-after) ?\() ;; body-fld-param
2488 (while (setq str (imap-parse-string))
2490 ;; buggy stalker communigate pro 3.0 doesn't print SPC
2491 ;; between body-fld-param's sometimes
2492 (or (eq (char-after) ?\")
2494 (nreverse strlist)))
2498 ;; body-extension = nstring / number /
2499 ;; "(" body-extension *(SP body-extension) ")"
2500 ;; ; Future expansion. Client implementations
2501 ;; ; MUST accept body-extension fields. Server
2502 ;; ; implementations MUST NOT generate
2503 ;; ; body-extension fields except as defined by
2504 ;; ; future standard or standards-track
2505 ;; ; revisions of this specification.
2507 (defun imap-parse-body-extension ()
2508 (if (eq (char-after) ?\()
2511 (push (imap-parse-body-extension) b-e)
2512 (while (eq (char-after) ?\ )
2514 (push (imap-parse-body-extension) b-e))
2515 (assert (eq (char-after) ?\)) t "In imap-parse-body-extension")
2518 (or (imap-parse-number)
2519 (imap-parse-nstring))))
2521 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2522 ;; *(SP body-extension)]]
2523 ;; ; MUST NOT be returned on non-extensible
2526 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2527 ;; *(SP body-extension)]]
2528 ;; ; MUST NOT be returned on non-extensible
2531 (defsubst imap-parse-body-ext ()
2533 (when (eq (char-after) ?\ ) ;; body-fld-dsp
2536 (if (eq (char-after) ?\()
2539 (push (imap-parse-string) dsp)
2541 (push (imap-parse-string-list) dsp)
2543 (assert (imap-parse-nil) t "In imap-parse-body-ext"))
2544 (push (nreverse dsp) ext))
2545 (when (eq (char-after) ?\ ) ;; body-fld-lang
2547 (if (eq (char-after) ?\()
2548 (push (imap-parse-string-list) ext)
2549 (push (imap-parse-nstring) ext))
2550 (while (eq (char-after) ?\ ) ;; body-extension
2552 (setq ext (append (imap-parse-body-extension) ext)))))
2555 ;; body = "(" body-type-1part / body-type-mpart ")"
2557 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2558 ;; *(SP body-extension)]]
2559 ;; ; MUST NOT be returned on non-extensible
2562 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2563 ;; *(SP body-extension)]]
2564 ;; ; MUST NOT be returned on non-extensible
2567 ;; body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP
2568 ;; body-fld-enc SP body-fld-octets
2570 ;; body-fld-desc = nstring
2572 ;; body-fld-dsp = "(" string SP body-fld-param ")" / nil
2574 ;; body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
2575 ;; "QUOTED-PRINTABLE") DQUOTE) / string
2577 ;; body-fld-id = nstring
2579 ;; body-fld-lang = nstring / "(" string *(SP string) ")"
2581 ;; body-fld-lines = number
2583 ;; body-fld-md5 = nstring
2585 ;; body-fld-octets = number
2587 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2589 ;; body-type-1part = (body-type-basic / body-type-msg / body-type-text)
2590 ;; [SP body-ext-1part]
2592 ;; body-type-basic = media-basic SP body-fields
2593 ;; ; MESSAGE subtype MUST NOT be "RFC822"
2595 ;; body-type-msg = media-message SP body-fields SP envelope
2596 ;; SP body SP body-fld-lines
2598 ;; body-type-text = media-text SP body-fields SP body-fld-lines
2600 ;; body-type-mpart = 1*body SP media-subtype
2601 ;; [SP body-ext-mpart]
2603 ;; media-basic = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" /
2604 ;; "MESSAGE" / "VIDEO") DQUOTE) / string) SP media-subtype
2605 ;; ; Defined in [MIME-IMT]
2607 ;; media-message = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE
2608 ;; ; Defined in [MIME-IMT]
2610 ;; media-subtype = string
2611 ;; ; Defined in [MIME-IMT]
2613 ;; media-text = DQUOTE "TEXT" DQUOTE SP media-subtype
2614 ;; ; Defined in [MIME-IMT]
2616 (defun imap-parse-body ()
2618 (when (eq (char-after) ?\()
2620 (if (eq (char-after) ?\()
2622 (while (and (eq (char-after) ?\()
2623 (setq subbody (imap-parse-body)))
2624 ;; buggy stalker communigate pro 3.0 insert a SPC between
2625 ;; parts in multiparts
2626 (when (and (eq (char-after) ?\ )
2627 (eq (char-after (1+ (point))) ?\())
2629 (push subbody body))
2631 (push (imap-parse-string) body) ;; media-subtype
2632 (when (eq (char-after) ?\ ) ;; body-ext-mpart:
2634 (if (eq (char-after) ?\() ;; body-fld-param
2635 (push (imap-parse-string-list) body)
2636 (push (and (imap-parse-nil) nil) body))
2638 (append (imap-parse-body-ext) body))) ;; body-ext-...
2639 (assert (eq (char-after) ?\)) t "In imap-parse-body")
2643 (push (imap-parse-string) body) ;; media-type
2645 (push (imap-parse-string) body) ;; media-subtype
2647 ;; next line for Sun SIMS bug
2648 (and (eq (char-after) ? ) (imap-forward))
2649 (if (eq (char-after) ?\() ;; body-fld-param
2650 (push (imap-parse-string-list) body)
2651 (push (and (imap-parse-nil) nil) body))
2653 (push (imap-parse-nstring) body) ;; body-fld-id
2655 (push (imap-parse-nstring) body) ;; body-fld-desc
2657 ;; next `or' for Sun SIMS bug, it regard body-fld-enc as a
2658 ;; nstring and return nil instead of defaulting back to 7BIT
2659 ;; as the standard says.
2660 (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc
2662 (push (imap-parse-number) body) ;; body-fld-octets
2664 ;; ok, we're done parsing the required parts, what comes now is one
2667 ;; envelope (then we're parsing body-type-msg)
2668 ;; body-fld-lines (then we're parsing body-type-text)
2669 ;; body-ext-1part (then we're parsing body-type-basic)
2671 ;; the problem is that the two first are in turn optionally followed
2672 ;; by the third. So we parse the first two here (if there are any)...
2674 (when (eq (char-after) ?\ )
2677 (cond ((eq (char-after) ?\() ;; body-type-msg:
2678 (push (imap-parse-envelope) body) ;; envelope
2680 (push (imap-parse-body) body) ;; body
2681 ;; buggy stalker communigate pro 3.0 doesn't print
2682 ;; number of lines in message/rfc822 attachment
2683 (if (eq (char-after) ?\))
2686 (push (imap-parse-number) body))) ;; body-fld-lines
2687 ((setq lines (imap-parse-number)) ;; body-type-text:
2688 (push lines body)) ;; body-fld-lines
2690 (backward-char))))) ;; no match...
2692 ;; ...and then parse the third one here...
2694 (when (eq (char-after) ?\ ) ;; body-ext-1part:
2696 (push (imap-parse-nstring) body) ;; body-fld-md5
2697 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part..
2699 (assert (eq (char-after) ?\)) t "In imap-parse-body 2")
2703 (when imap-debug ; (untrace-all)
2705 (buffer-disable-undo (get-buffer-create imap-debug-buffer))
2706 (mapcar (lambda (f) (trace-function-background f imap-debug-buffer))
2717 imap-interactive-login
2733 imap-send-command-wait
2738 imap-current-mailbox
2739 imap-current-mailbox-p-1
2740 imap-current-mailbox-p
2741 imap-mailbox-select-1
2743 imap-mailbox-examine-1
2744 imap-mailbox-examine
2745 imap-mailbox-unselect
2746 imap-mailbox-expunge
2748 imap-mailbox-create-1
2754 imap-mailbox-subscribe
2755 imap-mailbox-unsubscribe
2757 imap-mailbox-acl-get
2758 imap-mailbox-acl-set
2759 imap-mailbox-acl-delete
2760 imap-current-message
2761 imap-list-to-message-set
2768 imap-message-flag-permanent-p
2769 imap-message-flags-set
2770 imap-message-flags-del
2771 imap-message-flags-add
2772 imap-message-copyuid-1
2773 imap-message-copyuid
2775 imap-message-appenduid-1
2776 imap-message-appenduid
2788 imap-parse-resp-text
2789 imap-parse-resp-text-code
2790 imap-parse-data-list
2794 imap-parse-flag-list
2796 imap-parse-body-extension
2802 ;;; imap.el ends here