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))
141 (eval-when-compile (require 'static))
146 (autoload 'starttls-open-stream "starttls")
147 (autoload 'starttls-negotiate "starttls")
148 (autoload 'rfc2104-hash "rfc2104")
149 (autoload 'md5 "md5")
150 (autoload 'utf7-encode "utf7")
151 (autoload 'utf7-decode "utf7")
152 (autoload 'format-spec "format-spec")
153 (autoload 'format-spec-make "format-spec")
154 (autoload 'open-tls-stream "tls")
155 ;; Avoid use gnus-point-at-eol so we're independent of Gnus. These
156 ;; days we have point-at-eol anyhow.
157 (if (fboundp 'point-at-eol)
158 (defalias 'imap-point-at-eol 'point-at-eol)
159 (defun imap-point-at-eol ()
163 (autoload 'sasl-digest-md5-digest-response "sasl"))
168 "Low-level IMAP issues."
172 (defcustom imap-kerberos4-program '("imtest -m kerberos_v4 -u %l -p %p %s"
174 "List of strings containing commands for Kerberos 4 authentication.
175 %s is replaced with server hostname, %p with port to connect to, and
176 %l with the value of `imap-default-user'. The program should accept
177 IMAP commands on stdin and return responses to stdout. Each entry in
178 the list is tried until a successful connection is made."
180 :type '(repeat string))
182 (defcustom imap-gssapi-program (list
183 (concat "gsasl --client --connect %s:%p "
184 "--imap --application-data "
185 "--mechanism GSSAPI "
186 "--authentication-id %l")
187 "imtest -m gssapi -u %l -p %p %s")
188 "List of strings containing commands for GSSAPI (krb5) authentication.
189 %s is replaced with server hostname, %p with port to connect to, and
190 %l with the value of `imap-default-user'. The program should accept
191 IMAP commands on stdin and return responses to stdout. Each entry in
192 the list is tried until a successful connection is made."
194 :type '(repeat string))
196 (defcustom imap-ssl-program '("openssl s_client -quiet -ssl3 -connect %s:%p"
197 "openssl s_client -quiet -ssl2 -connect %s:%p"
198 "s_client -quiet -ssl3 -connect %s:%p"
199 "s_client -quiet -ssl2 -connect %s:%p")
200 "A string, or list of strings, containing commands for SSL connections.
201 Within a string, %s is replaced with the server address and %p with
202 port number on server. The program should accept IMAP commands on
203 stdin and return responses to stdout. Each entry in the list is tried
204 until a successful connection is made."
206 :type '(choice string
209 (defcustom imap-shell-program '("ssh %s imapd"
211 "ssh %g ssh %s imapd"
212 "rsh %g rsh %s imapd")
213 "A list of strings, containing commands for IMAP connection.
214 Within a string, %s is replaced with the server address, %p with port
215 number on server, %g with `imap-shell-host', and %l with
216 `imap-default-user'. The program should read IMAP commands from stdin
217 and write IMAP response to stdout. Each entry in the list is tried
218 until a successful connection is made."
220 :type '(repeat string))
222 (defcustom imap-process-connection-type nil
223 "*Value for `process-connection-type' to use for Kerberos4, GSSAPI and SSL.
224 The `process-connection-type' variable control type of device
225 used to communicate with subprocesses. Values are nil to use a
226 pipe, or t or `pty' to use a pty. The value has no effect if the
227 system has no ptys or if all ptys are busy: then a pipe is used
228 in any case. The value takes effect when a IMAP server is
229 opened, changing it after that has no effect.."
233 (defcustom imap-use-utf7 t
234 "If non-nil, do utf7 encoding/decoding of mailbox names.
235 Since the UTF7 decoding currently only decodes into ISO-8859-1
236 characters, you may disable this decoding if you need to access UTF7
237 encoded mailboxes which doesn't translate into ISO-8859-1."
241 (defcustom imap-log nil
242 "If non-nil, a imap session trace is placed in *imap-log* buffer."
246 (defcustom imap-debug nil
247 "If non-nil, random debug spews are placed in *imap-debug* buffer."
251 (defcustom imap-shell-host "gateway"
252 "Hostname of rlogin proxy."
256 (defcustom imap-default-user (user-login-name)
257 "Default username to use."
261 (defcustom imap-read-timeout (if (string-match
262 "windows-nt\\|os/2\\|emx\\|cygwin"
263 (symbol-name system-type))
266 "*How long to wait between checking for the end of output.
267 Shorter values mean quicker response, but is more CPU intensive."
271 ;; Various variables.
273 (defvar imap-fetch-data-hook nil
274 "Hooks called after receiving each FETCH response.")
276 (defvar imap-streams '(gssapi kerberos4 starttls tls ssl network shell)
277 "Priority of streams to consider when opening connection to server.")
279 (defvar imap-stream-alist
280 '((gssapi imap-gssapi-stream-p imap-gssapi-open)
281 (kerberos4 imap-kerberos4-stream-p imap-kerberos4-open)
282 (tls imap-tls-p imap-tls-open)
283 (ssl imap-ssl-p imap-ssl-open)
284 (network imap-network-p imap-network-open)
285 (shell imap-shell-p imap-shell-open)
286 (starttls imap-starttls-p imap-starttls-open))
287 "Definition of network streams.
291 NAME names the stream, CHECK is a function returning non-nil if the
292 server support the stream and OPEN is a function for opening the
295 (defvar imap-authenticators '(gssapi
301 "Priority of authenticators to consider when authenticating to server.")
303 (defvar imap-authenticator-alist
304 '((gssapi imap-gssapi-auth-p imap-gssapi-auth)
305 (kerberos4 imap-kerberos4-auth-p imap-kerberos4-auth)
306 (cram-md5 imap-cram-md5-p imap-cram-md5-auth)
307 (login imap-login-p imap-login-auth)
308 (anonymous imap-anonymous-p imap-anonymous-auth)
309 (digest-md5 imap-digest-md5-p imap-digest-md5-auth))
310 "Definition of authenticators.
312 \(NAME CHECK AUTHENTICATE)
314 NAME names the authenticator. CHECK is a function returning non-nil if
315 the server support the authenticator and AUTHENTICATE is a function
316 for doing the actual authentication.")
318 (defvar imap-error nil
319 "Error codes from the last command.")
321 ;; Internal constants. Change theese and die.
323 (defconst imap-default-port 143)
324 (defconst imap-default-ssl-port 993)
325 (defconst imap-default-tls-port 993)
326 (defconst imap-default-stream 'network)
327 (defconst imap-local-variables '(imap-server
336 imap-current-target-mailbox
345 imap-calculate-literal-size-first
347 (defconst imap-log-buffer "*imap-log*")
348 (defconst imap-debug-buffer "*imap-debug*")
350 ;; Internal variables.
352 (defvar imap-stream nil)
353 (defvar imap-auth nil)
354 (defvar imap-server nil)
355 (defvar imap-port nil)
356 (defvar imap-username nil)
357 (defvar imap-password nil)
358 (defvar imap-calculate-literal-size-first nil)
359 (defvar imap-state 'closed
361 Valid states are `closed', `initial', `nonauth', `auth', `selected'
364 (defvar imap-server-eol "\r\n"
365 "The EOL string sent from the server.")
367 (defvar imap-client-eol "\r\n"
368 "The EOL string we send to the server.")
370 (defvar imap-current-mailbox nil
371 "Current mailbox name.")
373 (defvar imap-current-target-mailbox nil
374 "Current target mailbox for COPY and APPEND commands.")
376 (defvar imap-mailbox-data nil
377 "Obarray with mailbox data.")
379 (defvar imap-mailbox-prime 997
380 "Length of imap-mailbox-data.")
382 (defvar imap-current-message nil
383 "Current message number.")
385 (defvar imap-message-data nil
386 "Obarray with message data.")
388 (defvar imap-message-prime 997
389 "Length of imap-message-data.")
391 (defvar imap-capability nil
392 "Capability for server.")
394 (defvar imap-namespace nil
395 "Namespace for current server.")
397 (defvar imap-reached-tag 0
398 "Lower limit on command tags that have been parsed.")
400 (defvar imap-failed-tags nil
401 "Alist of tags that failed.
402 Each element is a list with four elements; tag (a integer), response
403 state (a symbol, `OK', `NO' or `BAD'), response code (a string), and
404 human readable response text (a string).")
407 "Command tag number.")
409 (defvar imap-process nil
412 (defvar imap-continuation nil
413 "Non-nil indicates that the server emitted a continuation request.
414 The actual value is really the text on the continuation line.")
416 (defvar imap-callbacks nil
417 "List of response tags and callbacks, on the form `(number . function)'.
418 The function should take two arguments, the first the IMAP tag and the
419 second the status (OK, NO, BAD etc) of the command.")
422 ;; Utility functions:
424 (defun imap-remassoc (key alist)
425 "Delete by side effect any elements of LIST whose car is `equal' to KEY.
426 The modified LIST is returned. If the first member
427 of LIST has a car that is `equal' to KEY, there is no way to remove it
428 by side effect; therefore, write `(setq foo (remassoc key foo))' to be
429 sure of changing the value of `foo'."
431 (if (equal key (caar alist))
433 (setcdr alist (imap-remassoc key (cdr alist)))
436 (defmacro imap-disable-multibyte ()
437 "Enable multibyte in the current buffer."
438 '(set-buffer-multibyte nil))
440 (defsubst imap-utf7-encode (string)
444 (utf7-encode string t)
446 "imap: Could not UTF7 encode `%s', using it unencoded..."
451 (defsubst imap-utf7-decode (string)
455 (utf7-decode string t)
457 "imap: Could not UTF7 decode `%s', using it undecoded..."
462 (defsubst imap-ok-p (status)
465 (setq imap-error status)
468 (defun imap-error-text (&optional buffer)
469 (with-current-buffer (or buffer (current-buffer))
470 (nth 3 (car imap-failed-tags))))
473 ;; Server functions; stream stuff:
475 (defun imap-kerberos4-stream-p (buffer)
476 (imap-capability 'AUTH=KERBEROS_V4 buffer))
478 (defun imap-kerberos4-open (name buffer server port)
479 (let ((cmds imap-kerberos4-program)
481 (while (and (not done) (setq cmd (pop cmds)))
482 (message "Opening Kerberos 4 IMAP connection with `%s'..." cmd)
484 (let* ((port (or port imap-default-port))
485 (process-connection-type imap-process-connection-type)
486 (process (as-binary-process
488 name buffer shell-file-name shell-command-switch
493 ?p (number-to-string port)
494 ?l imap-default-user)))))
497 (with-current-buffer buffer
498 (setq imap-client-eol "\n"
499 imap-calculate-literal-size-first t)
500 (while (and (memq (process-status process) '(open run))
501 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
502 (goto-char (point-min))
503 ;; Athena IMTEST can output SSL verify errors
504 (or (while (looking-at "^verify error:num=")
507 (or (while (looking-at "^TLS connection established")
510 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
511 (or (while (looking-at "^C:")
514 ;; cyrus 1.6 imtest print "S: " before server greeting
515 (or (not (looking-at "S: "))
518 (not (and (imap-parse-greeting)
519 ;; success in imtest < 1.6:
520 (or (re-search-forward
521 "^__\\(.*\\)__\n" nil t)
522 ;; success in imtest 1.6:
524 "^\\(Authenticat.*\\)" nil t))
525 (setq response (match-string 1)))))
526 (accept-process-output process 1)
529 (with-current-buffer (get-buffer-create imap-log-buffer)
530 (imap-disable-multibyte)
531 (buffer-disable-undo)
532 (goto-char (point-max))
533 (insert-buffer-substring buffer)))
535 (message "Opening Kerberos 4 IMAP connection with `%s'...%s" cmd
536 (if response (concat "done, " response) "failed"))
537 (if (and response (let ((case-fold-search nil))
538 (not (string-match "failed" response))))
540 (if (memq (process-status process) '(open run))
541 (imap-send-command "LOGOUT"))
542 (delete-process process)
546 (defun imap-gssapi-stream-p (buffer)
547 (imap-capability 'AUTH=GSSAPI buffer))
549 (defun imap-gssapi-open (name buffer server port)
550 (let ((cmds imap-gssapi-program)
552 (while (and (not done) (setq cmd (pop cmds)))
553 (message "Opening GSSAPI IMAP connection with `%s'..." cmd)
555 (let* ((port (or port imap-default-port))
556 (process-connection-type imap-process-connection-type)
557 (process (as-binary-process
559 name buffer shell-file-name shell-command-switch
564 ?p (number-to-string port)
565 ?l imap-default-user)))))
568 (with-current-buffer buffer
569 (setq imap-client-eol "\n"
570 imap-calculate-literal-size-first t)
571 (while (and (memq (process-status process) '(open run))
572 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
573 (goto-char (point-min))
574 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
575 (or (while (looking-at "^C:")
578 ;; cyrus 1.6 imtest print "S: " before server greeting
579 (or (not (looking-at "S: "))
582 (not (and (imap-parse-greeting)
583 ;; success in imtest 1.6:
585 (concat "^\\(\\(Authenticat.*\\)\\|\\("
586 "Client authentication "
589 (setq response (match-string 1)))))
590 (accept-process-output process 1)
593 (with-current-buffer (get-buffer-create imap-log-buffer)
594 (imap-disable-multibyte)
595 (buffer-disable-undo)
596 (goto-char (point-max))
597 (insert-buffer-substring buffer)))
599 (message "GSSAPI IMAP connection: %s" (or response "failed"))
600 (if (and response (let ((case-fold-search nil))
601 (not (string-match "failed" response))))
603 (if (memq (process-status process) '(open run))
604 (imap-send-command "LOGOUT"))
605 (delete-process process)
609 (defun imap-ssl-p (buffer)
612 (defun imap-ssl-open (name buffer server port)
613 "Open a SSL connection to server."
614 (let ((cmds (if (listp imap-ssl-program) imap-ssl-program
615 (list imap-ssl-program)))
617 (while (and (not done) (setq cmd (pop cmds)))
618 (message "imap: Opening SSL connection with `%s'..." cmd)
620 (let ((port (or port imap-default-ssl-port))
621 (process-connection-type nil)
624 (setq process (as-binary-process
626 name buffer shell-file-name
631 ?p (number-to-string port))))))
632 (process-kill-without-query process))
633 (with-current-buffer buffer
634 (goto-char (point-min))
635 (while (and (memq (process-status process) '(open run))
636 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
637 (goto-char (point-max))
639 (not (imap-parse-greeting)))
640 (accept-process-output process 1)
643 (with-current-buffer (get-buffer-create imap-log-buffer)
644 (imap-disable-multibyte)
645 (buffer-disable-undo)
646 (goto-char (point-max))
647 (insert-buffer-substring buffer)))
649 (when (memq (process-status process) '(open run))
650 (setq done process))))))
653 (message "imap: Opening SSL connection with `%s'...done" cmd)
655 (message "imap: Opening SSL connection with `%s'...failed" cmd)
658 (defun imap-tls-p (buffer)
661 (defun imap-tls-open (name buffer server port)
662 (let* ((port (or port imap-default-tls-port))
663 (process (open-tls-stream name buffer server port)))
665 (while (and (memq (process-status process) '(open run))
666 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
667 (goto-char (point-max))
669 (not (imap-parse-greeting)))
670 (accept-process-output process 1)
673 (with-current-buffer (get-buffer-create imap-log-buffer)
674 (imap-disable-multibyte)
675 (buffer-disable-undo)
676 (goto-char (point-max))
677 (insert-buffer-substring buffer)))
678 (when (memq (process-status process) '(open run))
681 (defun imap-network-p (buffer)
684 (defun imap-network-open (name buffer server port)
685 (let* ((port (or port imap-default-port))
686 (process (open-network-stream-as-binary name buffer server port)))
688 (while (and (memq (process-status process) '(open run))
689 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
690 (goto-char (point-min))
691 (not (imap-parse-greeting)))
692 (accept-process-output process 1)
695 (with-current-buffer (get-buffer-create imap-log-buffer)
696 (imap-disable-multibyte)
697 (buffer-disable-undo)
698 (goto-char (point-max))
699 (insert-buffer-substring buffer)))
700 (when (memq (process-status process) '(open run))
703 (defun imap-shell-p (buffer)
706 (defun imap-shell-open (name buffer server port)
707 (let ((cmds (if (listp imap-shell-program) imap-shell-program
708 (list imap-shell-program)))
710 (while (and (not done) (setq cmd (pop cmds)))
711 (message "imap: Opening IMAP connection with `%s'..." cmd)
712 (setq imap-client-eol "\n")
713 (let* ((port (or port imap-default-port))
714 (process (as-binary-process
716 name buffer shell-file-name shell-command-switch
722 ?p (number-to-string port)
723 ?l imap-default-user))))))
725 (while (and (memq (process-status process) '(open run))
726 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
727 (goto-char (point-max))
729 (not (imap-parse-greeting)))
730 (accept-process-output process 1)
733 (with-current-buffer (get-buffer-create imap-log-buffer)
734 (imap-disable-multibyte)
735 (buffer-disable-undo)
736 (goto-char (point-max))
737 (insert-buffer-substring buffer)))
739 (when (memq (process-status process) '(open run))
740 (setq done process)))))
743 (message "imap: Opening IMAP connection with `%s'...done" cmd)
745 (message "imap: Opening IMAP connection with `%s'...failed" cmd)
748 (defun imap-starttls-p (buffer)
749 (imap-capability 'STARTTLS buffer))
751 (defun imap-starttls-open (name buffer server port)
752 (let* ((port (or port imap-default-port))
753 (process (as-binary-process
754 (starttls-open-stream name buffer server port)))
756 (message "imap: Connecting with STARTTLS...")
758 (while (and (memq (process-status process) '(open run))
759 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
760 (goto-char (point-max))
762 (not (imap-parse-greeting)))
763 (accept-process-output process 1)
765 (imap-send-command "STARTTLS")
766 (while (and (memq (process-status process) '(open run))
767 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
768 (goto-char (point-max))
770 (not (re-search-forward "[0-9]+ OK.*\r?\n" nil t)))
771 (accept-process-output process 1)
774 (with-current-buffer (get-buffer-create imap-log-buffer)
775 (buffer-disable-undo)
776 (goto-char (point-max))
777 (insert-buffer-substring buffer)))
778 (when (and (setq tls-info (starttls-negotiate process))
779 (memq (process-status process) '(open run)))
780 (setq done process)))
781 (if (stringp tls-info)
782 (message "imap: STARTTLS info: %s" tls-info))
783 (message "imap: Connecting with STARTTLS...%s" (if done "done" "failed"))
786 ;; Server functions; authenticator stuff:
788 (defun imap-interactive-login (buffer loginfunc)
789 "Login to server in BUFFER.
790 LOGINFUNC is passed a username and a password, it should return t if
791 it where successful authenticating itself to the server, nil otherwise.
792 Returns t if login was successful, nil otherwise."
793 (with-current-buffer buffer
794 (make-local-variable 'imap-username)
795 (make-local-variable 'imap-password)
796 (let (user passwd ret)
797 ;; (condition-case ()
798 (while (or (not user) (not passwd))
799 (setq user (or imap-username
800 (read-from-minibuffer
801 (concat "IMAP username for " imap-server
802 " (using stream `" (symbol-name imap-stream)
804 (or user imap-default-user))))
805 (setq passwd (or imap-password
807 (concat "IMAP password for " user "@"
808 imap-server " (using authenticator `"
809 (symbol-name imap-auth) "'): "))))
810 (when (and user passwd)
811 (if (funcall loginfunc user passwd)
815 (if (and (not imap-password)
816 (y-or-n-p "Store password for this session? "))
817 (setq imap-password passwd)))
818 (message "Login failed...")
820 (setq imap-password nil)
822 ;; (quit (with-current-buffer buffer
825 ;; (error (with-current-buffer buffer
830 (defun imap-gssapi-auth-p (buffer)
831 (and (imap-capability 'AUTH=GSSAPI buffer)
832 (eq imap-stream 'gssapi)))
834 (defun imap-gssapi-auth (buffer)
835 (message "imap: Authenticating using GSSAPI...%s"
836 (if (eq imap-stream 'gssapi) "done" "failed"))
837 (eq imap-stream 'gssapi))
839 (defun imap-kerberos4-auth-p (buffer)
840 (and (imap-capability 'AUTH=KERBEROS_V4 buffer)
841 (eq imap-stream 'kerberos4)))
843 (defun imap-kerberos4-auth (buffer)
844 (message "imap: Authenticating using Kerberos 4...%s"
845 (if (eq imap-stream 'kerberos4) "done" "failed"))
846 (eq imap-stream 'kerberos4))
848 (defun imap-cram-md5-p (buffer)
849 (imap-capability 'AUTH=CRAM-MD5 buffer))
851 (defun imap-cram-md5-auth (buffer)
852 "Login to server using the AUTH CRAM-MD5 method."
853 (message "imap: Authenticating using CRAM-MD5...")
854 (let ((done (imap-interactive-login
856 (lambda (user passwd)
858 (imap-send-command-wait
860 "AUTHENTICATE CRAM-MD5"
862 (let* ((decoded (base64-decode-string challenge))
864 (if (and (featurep 'xemacs)
865 (>= (function-max-args 'md5) 4))
866 (lambda (object &optional start end)
867 (md5 object start end 'binary))
869 (hash (rfc2104-hash hash-function 64 16
871 (response (concat user " " hash))
872 (encoded (base64-encode-string response)))
875 (message "imap: Authenticating using CRAM-MD5...done")
876 (message "imap: Authenticating using CRAM-MD5...failed"))))
878 (defun imap-login-p (buffer)
879 (and (not (imap-capability 'LOGINDISABLED buffer))
880 (not (imap-capability 'X-LOGIN-CMD-DISABLED buffer))))
882 (defun imap-login-auth (buffer)
883 "Login to server using the LOGIN command."
884 (message "imap: Plaintext authentication...")
885 (imap-interactive-login buffer
886 (lambda (user passwd)
887 (imap-ok-p (imap-send-command-wait
888 (concat "LOGIN \"" user "\" \""
891 (defun imap-anonymous-p (buffer)
894 (defun imap-anonymous-auth (buffer)
895 (message "imap: Logging in anonymously...")
896 (with-current-buffer buffer
897 (imap-ok-p (imap-send-command-wait
898 (concat "LOGIN anonymous \"" (concat (user-login-name) "@"
899 (system-name)) "\"")))))
901 (defun imap-digest-md5-p (buffer)
902 (and (imap-capability 'AUTH=DIGEST-MD5 buffer)
904 (require 'digest-md5)
907 (defun imap-digest-md5-auth (buffer)
908 "Login to server using the AUTH DIGEST-MD5 method."
909 (message "imap: Authenticating using DIGEST-MD5...")
910 (imap-interactive-login
912 (lambda (user passwd)
916 "AUTHENTICATE DIGEST-MD5"
918 (base64-encode-string
919 (sasl-digest-md5-digest-response
920 (base64-decode-string challenge)
921 user passwd "imap" imap-server)
923 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
925 (setq imap-continuation nil)
926 (imap-send-command-1 "")
927 (imap-ok-p (imap-wait-for-tag tag)))))))
931 (defun imap-open-1 (buffer)
932 (with-current-buffer buffer
934 (setq imap-current-mailbox nil
935 imap-current-message nil
937 imap-process (condition-case ()
938 (funcall (nth 2 (assq imap-stream
940 "imap" buffer imap-server imap-port)
943 (set-process-filter imap-process 'imap-arrival-filter)
944 (set-process-sentinel imap-process 'imap-sentinel)
945 (while (and (eq imap-state 'initial)
946 (memq (process-status imap-process) '(open run)))
947 (message "Waiting for response from %s..." imap-server)
948 (accept-process-output imap-process 1))
949 (message "Waiting for response from %s...done" imap-server)
950 (and (memq (process-status imap-process) '(open run))
953 (defun imap-open (server &optional port stream auth buffer)
954 "Open a IMAP connection to host SERVER at PORT returning a buffer.
955 If PORT is unspecified, a default value is used (143 except
956 for SSL which use 993).
957 STREAM indicates the stream to use, see `imap-streams' for available
958 streams. If nil, it choices the best stream the server is capable of.
959 AUTH indicates authenticator to use, see `imap-authenticators' for
960 available authenticators. If nil, it choices the best stream the
961 server is capable of.
962 BUFFER can be a buffer or a name of a buffer, which is created if
963 necessary. If nil, the buffer name is generated."
964 (setq buffer (or buffer (format " *imap* %s:%d" server (or port 0))))
965 (with-current-buffer (get-buffer-create buffer)
966 (if (imap-opened buffer)
968 (mapcar 'make-local-variable imap-local-variables)
969 (imap-disable-multibyte)
970 (buffer-disable-undo)
971 (setq imap-server (or server imap-server))
972 (setq imap-port (or port imap-port))
973 (setq imap-auth (or auth imap-auth))
974 (setq imap-stream (or stream imap-stream))
975 (message "imap: Connecting to %s..." imap-server)
976 (if (null (let ((imap-stream (or imap-stream imap-default-stream)))
977 (imap-open-1 buffer)))
979 (message "imap: Connecting to %s...failed" imap-server)
981 (when (null imap-stream)
982 ;; Need to choose stream.
983 (let ((streams imap-streams))
984 (while (setq stream (pop streams))
985 ;; OK to use this stream?
986 (when (funcall (nth 1 (assq stream imap-stream-alist)) buffer)
988 (if (not (eq imap-default-stream stream))
989 (with-current-buffer (get-buffer-create
990 (generate-new-buffer-name " *temp*"))
991 (mapcar 'make-local-variable imap-local-variables)
992 (imap-disable-multibyte)
993 (buffer-disable-undo)
994 (setq imap-server (or server imap-server))
995 (setq imap-port (or port imap-port))
996 (setq imap-auth (or auth imap-auth))
997 (message "imap: Reconnecting with stream `%s'..." stream)
998 (if (null (let ((imap-stream stream))
999 (imap-open-1 (current-buffer))))
1001 (kill-buffer (current-buffer))
1003 "imap: Reconnecting with stream `%s'...failed"
1005 ;; We're done, kill the first connection
1007 (kill-buffer buffer)
1008 (rename-buffer buffer)
1009 (message "imap: Reconnecting with stream `%s'...done"
1011 (setq imap-stream stream)
1012 (setq imap-capability nil)
1013 (setq streams nil)))
1015 (message "imap: Connecting to %s...done" imap-server)
1016 (setq imap-stream stream)
1017 (setq imap-capability nil)
1018 (setq streams nil))))))
1019 (when (imap-opened buffer)
1020 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0)))
1024 (defun imap-opened (&optional buffer)
1025 "Return non-nil if connection to imap server in BUFFER is open.
1026 If BUFFER is nil then the current buffer is used."
1027 (and (setq buffer (get-buffer (or buffer (current-buffer))))
1028 (buffer-live-p buffer)
1029 (with-current-buffer buffer
1031 (memq (process-status imap-process) '(open run))))))
1033 (defun imap-authenticate (&optional user passwd buffer)
1034 "Authenticate to server in BUFFER, using current buffer if nil.
1035 It uses the authenticator specified when opening the server. If the
1036 authenticator requires username/passwords, they are queried from the
1037 user and optionally stored in the buffer. If USER and/or PASSWD is
1038 specified, the user will not be questioned and the username and/or
1039 password is remembered in the buffer."
1040 (with-current-buffer (or buffer (current-buffer))
1041 (if (not (eq imap-state 'nonauth))
1042 (or (eq imap-state 'auth)
1043 (eq imap-state 'select)
1044 (eq imap-state 'examine))
1045 (make-local-variable 'imap-username)
1046 (make-local-variable 'imap-password)
1047 (if user (setq imap-username user))
1048 (if passwd (setq imap-password passwd))
1050 (and (funcall (nth 2 (assq imap-auth
1051 imap-authenticator-alist)) buffer)
1052 (setq imap-state 'auth))
1053 ;; Choose authenticator.
1054 (let ((auths imap-authenticators)
1056 (while (setq auth (pop auths))
1057 ;; OK to use authenticator?
1058 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) buffer)
1059 (message "imap: Authenticating to `%s' using `%s'..."
1061 (setq imap-auth auth)
1062 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) buffer)
1064 (message "imap: Authenticating to `%s' using `%s'...done"
1067 (message "imap: Authenticating to `%s' using `%s'...failed"
1068 imap-server auth)))))
1071 (defun imap-close (&optional buffer)
1072 "Close connection to server in BUFFER.
1073 If BUFFER is nil, the current buffer is used."
1074 (with-current-buffer (or buffer (current-buffer))
1077 (imap-send-command-wait "LOGOUT")
1079 (when (and imap-process
1080 (memq (process-status imap-process) '(open run)))
1081 (delete-process imap-process))
1082 (setq imap-current-mailbox nil
1083 imap-current-message nil
1088 (defun imap-capability (&optional identifier buffer)
1089 "Return a list of identifiers which server in BUFFER support.
1090 If IDENTIFIER, return non-nil if it's among the servers capabilities.
1091 If BUFFER is nil, the current buffer is assumed."
1092 (with-current-buffer (or buffer (current-buffer))
1093 (unless imap-capability
1094 (unless (imap-ok-p (imap-send-command-wait "CAPABILITY"))
1095 (setq imap-capability '(IMAP2))))
1097 (memq (intern (upcase (symbol-name identifier))) imap-capability)
1100 (defun imap-namespace (&optional buffer)
1101 "Return a namespace hierarchy at server in BUFFER.
1102 If BUFFER is nil, the current buffer is assumed."
1103 (with-current-buffer (or buffer (current-buffer))
1104 (unless imap-namespace
1105 (when (imap-capability 'NAMESPACE)
1106 (imap-send-command-wait "NAMESPACE")))
1109 (defun imap-send-command-wait (command &optional buffer)
1110 (imap-wait-for-tag (imap-send-command command buffer) buffer))
1113 ;; Mailbox functions:
1115 (defun imap-mailbox-put (propname value &optional mailbox buffer)
1116 (with-current-buffer (or buffer (current-buffer))
1117 (if imap-mailbox-data
1118 (put (intern (or mailbox imap-current-mailbox) imap-mailbox-data)
1120 (error "Imap-mailbox-data is nil, prop %s value %s mailbox %s buffer %s"
1121 propname value mailbox (current-buffer)))
1124 (defsubst imap-mailbox-get-1 (propname &optional mailbox)
1125 (get (intern-soft (or mailbox imap-current-mailbox) imap-mailbox-data)
1128 (defun imap-mailbox-get (propname &optional mailbox buffer)
1129 (let ((mailbox (imap-utf7-encode mailbox)))
1130 (with-current-buffer (or buffer (current-buffer))
1131 (imap-mailbox-get-1 propname (or mailbox imap-current-mailbox)))))
1133 (defun imap-mailbox-map-1 (func &optional mailbox-decoder buffer)
1134 (with-current-buffer (or buffer (current-buffer))
1138 (push (funcall func (if mailbox-decoder
1139 (funcall mailbox-decoder (symbol-name s))
1140 (symbol-name s))) result))
1144 (defun imap-mailbox-map (func &optional buffer)
1145 "Map a function across each mailbox in `imap-mailbox-data', returning a list.
1146 Function should take a mailbox name (a string) as
1148 (imap-mailbox-map-1 func 'imap-utf7-decode buffer))
1150 (defun imap-current-mailbox (&optional buffer)
1151 (with-current-buffer (or buffer (current-buffer))
1152 (imap-utf7-decode imap-current-mailbox)))
1154 (defun imap-current-mailbox-p-1 (mailbox &optional examine)
1155 (and (string= mailbox imap-current-mailbox)
1157 (eq imap-state 'examine))
1159 (eq imap-state 'selected)))))
1161 (defun imap-current-mailbox-p (mailbox &optional examine buffer)
1162 (with-current-buffer (or buffer (current-buffer))
1163 (imap-current-mailbox-p-1 (imap-utf7-encode mailbox) examine)))
1165 (defun imap-mailbox-select-1 (mailbox &optional examine)
1166 "Select MAILBOX on server in BUFFER.
1167 If EXAMINE is non-nil, do a read-only select."
1168 (if (imap-current-mailbox-p-1 mailbox examine)
1169 imap-current-mailbox
1170 (setq imap-current-mailbox mailbox)
1171 (if (imap-ok-p (imap-send-command-wait
1172 (concat (if examine "EXAMINE" "SELECT") " \""
1175 (setq imap-message-data (make-vector imap-message-prime 0)
1176 imap-state (if examine 'examine 'selected))
1177 imap-current-mailbox)
1178 ;; Failed SELECT/EXAMINE unselects current mailbox
1179 (setq imap-current-mailbox nil))))
1181 (defun imap-mailbox-select (mailbox &optional examine buffer)
1182 (with-current-buffer (or buffer (current-buffer))
1184 (imap-mailbox-select-1 (imap-utf7-encode mailbox) examine))))
1186 (defun imap-mailbox-examine-1 (mailbox &optional buffer)
1187 (with-current-buffer (or buffer (current-buffer))
1188 (imap-mailbox-select-1 mailbox 'examine)))
1190 (defun imap-mailbox-examine (mailbox &optional buffer)
1191 "Examine MAILBOX on server in BUFFER."
1192 (imap-mailbox-select mailbox 'examine buffer))
1194 (defun imap-mailbox-unselect (&optional buffer)
1195 "Close current folder in BUFFER, without expunging articles."
1196 (with-current-buffer (or buffer (current-buffer))
1197 (when (or (eq imap-state 'auth)
1198 (and (imap-capability 'UNSELECT)
1199 (imap-ok-p (imap-send-command-wait "UNSELECT")))
1201 (imap-send-command-wait (concat "EXAMINE \""
1202 imap-current-mailbox
1204 (imap-ok-p (imap-send-command-wait "CLOSE"))))
1205 (setq imap-current-mailbox nil
1206 imap-message-data nil
1210 (defun imap-mailbox-expunge (&optional asynch buffer)
1211 "Expunge articles in current folder in BUFFER.
1212 If ASYNCH, do not wait for succesful completion of the command.
1213 If BUFFER is nil the current buffer is assumed."
1214 (with-current-buffer (or buffer (current-buffer))
1215 (when (and imap-current-mailbox (not (eq imap-state 'examine)))
1217 (imap-send-command "EXPUNGE")
1218 (imap-ok-p (imap-send-command-wait "EXPUNGE"))))))
1220 (defun imap-mailbox-close (&optional asynch buffer)
1221 "Expunge articles and close current folder in BUFFER.
1222 If ASYNCH, do not wait for succesful completion of the command.
1223 If BUFFER is nil the current buffer is assumed."
1224 (with-current-buffer (or buffer (current-buffer))
1225 (when imap-current-mailbox
1227 (imap-add-callback (imap-send-command "CLOSE")
1228 `(lambda (tag status)
1229 (message "IMAP mailbox `%s' closed... %s"
1230 imap-current-mailbox status)
1231 (when (eq ,imap-current-mailbox
1232 imap-current-mailbox)
1233 ;; Don't wipe out data if another mailbox
1235 (setq imap-current-mailbox nil
1236 imap-message-data nil
1237 imap-state 'auth))))
1238 (when (imap-ok-p (imap-send-command-wait "CLOSE"))
1239 (setq imap-current-mailbox nil
1240 imap-message-data nil
1244 (defun imap-mailbox-create-1 (mailbox)
1245 (imap-ok-p (imap-send-command-wait (list "CREATE \"" mailbox "\""))))
1247 (defun imap-mailbox-create (mailbox &optional buffer)
1248 "Create MAILBOX on server in BUFFER.
1249 If BUFFER is nil the current buffer is assumed."
1250 (with-current-buffer (or buffer (current-buffer))
1251 (imap-mailbox-create-1 (imap-utf7-encode mailbox))))
1253 (defun imap-mailbox-delete (mailbox &optional buffer)
1254 "Delete MAILBOX on server in BUFFER.
1255 If BUFFER is nil the current buffer is assumed."
1256 (let ((mailbox (imap-utf7-encode mailbox)))
1257 (with-current-buffer (or buffer (current-buffer))
1259 (imap-send-command-wait (list "DELETE \"" mailbox "\""))))))
1261 (defun imap-mailbox-rename (oldname newname &optional buffer)
1262 "Rename mailbox OLDNAME to NEWNAME on server in BUFFER.
1263 If BUFFER is nil the current buffer is assumed."
1264 (let ((oldname (imap-utf7-encode oldname))
1265 (newname (imap-utf7-encode newname)))
1266 (with-current-buffer (or buffer (current-buffer))
1268 (imap-send-command-wait (list "RENAME \"" oldname "\" "
1269 "\"" newname "\""))))))
1271 (defun imap-mailbox-lsub (&optional root reference add-delimiter buffer)
1272 "Return a list of subscribed mailboxes on server in BUFFER.
1273 If ROOT is non-nil, only list matching mailboxes. If ADD-DELIMITER is
1274 non-nil, a hierarchy delimiter is added to root. REFERENCE is a
1275 implementation-specific string that has to be passed to lsub command."
1276 (with-current-buffer (or buffer (current-buffer))
1277 ;; Make sure we know the hierarchy separator for root's hierarchy
1278 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1279 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1280 (imap-utf7-encode root) "\"")))
1281 ;; clear list data (NB not delimiter and other stuff)
1282 (imap-mailbox-map-1 (lambda (mailbox)
1283 (imap-mailbox-put 'lsub nil mailbox)))
1285 (imap-send-command-wait
1286 (concat "LSUB \"" reference "\" \"" (imap-utf7-encode root)
1287 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1290 (imap-mailbox-map-1 (lambda (mailbox)
1291 (when (imap-mailbox-get-1 'lsub mailbox)
1292 (push (imap-utf7-decode mailbox) out))))
1295 (defun imap-mailbox-list (root &optional reference add-delimiter buffer)
1296 "Return a list of mailboxes matching ROOT on server in BUFFER.
1297 If ADD-DELIMITER is non-nil, a hierarchy delimiter is added to
1298 root. REFERENCE is a implementation-specific string that has to be
1299 passed to list command."
1300 (with-current-buffer (or buffer (current-buffer))
1301 ;; Make sure we know the hierarchy separator for root's hierarchy
1302 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1303 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1304 (imap-utf7-encode root) "\"")))
1305 ;; clear list data (NB not delimiter and other stuff)
1306 (imap-mailbox-map-1 (lambda (mailbox)
1307 (imap-mailbox-put 'list nil mailbox)))
1309 (imap-send-command-wait
1310 (concat "LIST \"" reference "\" \"" (imap-utf7-encode root)
1311 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1314 (imap-mailbox-map-1 (lambda (mailbox)
1315 (when (imap-mailbox-get-1 'list mailbox)
1316 (push (imap-utf7-decode mailbox) out))))
1319 (defun imap-mailbox-subscribe (mailbox &optional buffer)
1320 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1321 Returns non-nil if successful."
1322 (with-current-buffer (or buffer (current-buffer))
1323 (imap-ok-p (imap-send-command-wait (concat "SUBSCRIBE \""
1324 (imap-utf7-encode mailbox)
1327 (defun imap-mailbox-unsubscribe (mailbox &optional buffer)
1328 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1329 Returns non-nil if successful."
1330 (with-current-buffer (or buffer (current-buffer))
1331 (imap-ok-p (imap-send-command-wait (concat "UNSUBSCRIBE "
1332 (imap-utf7-encode mailbox)
1335 (defun imap-mailbox-status (mailbox items &optional buffer)
1336 "Get status items ITEM in MAILBOX from server in BUFFER.
1337 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1338 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1339 or 'unseen. If ITEMS is a list of symbols, a list of values is
1340 returned, if ITEMS is a symbol only its value is returned."
1341 (with-current-buffer (or buffer (current-buffer))
1343 (imap-send-command-wait (list "STATUS \""
1344 (imap-utf7-encode mailbox)
1352 (mapcar (lambda (item)
1353 (imap-mailbox-get item mailbox))
1355 (imap-mailbox-get items mailbox)))))
1357 (defun imap-mailbox-status-asynch (mailbox items &optional buffer)
1358 "Send status item request ITEM on MAILBOX to server in BUFFER.
1359 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1360 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1361 or 'unseen. The IMAP command tag is returned."
1362 (with-current-buffer (or buffer (current-buffer))
1363 (imap-send-command (list "STATUS \""
1364 (imap-utf7-encode mailbox)
1371 (defun imap-mailbox-acl-get (&optional mailbox buffer)
1372 "Get ACL on mailbox from server in BUFFER."
1373 (let ((mailbox (imap-utf7-encode mailbox)))
1374 (with-current-buffer (or buffer (current-buffer))
1376 (imap-send-command-wait (list "GETACL \""
1377 (or mailbox imap-current-mailbox)
1379 (imap-mailbox-get-1 'acl (or mailbox imap-current-mailbox))))))
1381 (defun imap-mailbox-acl-set (identifier rights &optional mailbox buffer)
1382 "Change/set ACL for IDENTIFIER to RIGHTS in MAILBOX from server in BUFFER."
1383 (let ((mailbox (imap-utf7-encode mailbox)))
1384 (with-current-buffer (or buffer (current-buffer))
1386 (imap-send-command-wait (list "SETACL \""
1387 (or mailbox imap-current-mailbox)
1393 (defun imap-mailbox-acl-delete (identifier &optional mailbox buffer)
1394 "Removes any <identifier,rights> pair for IDENTIFIER in MAILBOX from server in BUFFER."
1395 (let ((mailbox (imap-utf7-encode mailbox)))
1396 (with-current-buffer (or buffer (current-buffer))
1398 (imap-send-command-wait (list "DELETEACL \""
1399 (or mailbox imap-current-mailbox)
1404 ;; Message functions:
1406 (defun imap-current-message (&optional buffer)
1407 (with-current-buffer (or buffer (current-buffer))
1408 imap-current-message))
1410 (defun imap-list-to-message-set (list)
1411 (mapconcat (lambda (item)
1412 (number-to-string item))
1418 (defun imap-range-to-message-set (range)
1423 (car item) (cdr item))
1424 (format "%d" item)))
1425 (if (and (listp range) (not (listp (cdr range))))
1426 (list range) ;; make (1 . 2) into ((1 . 2))
1430 (defun imap-fetch-asynch (uids props &optional nouidfetch buffer)
1431 (with-current-buffer (or buffer (current-buffer))
1432 (imap-send-command (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1434 (imap-list-to-message-set uids)
1438 (defun imap-fetch (uids props &optional receive nouidfetch buffer)
1439 "Fetch properties PROPS from message set UIDS from server in BUFFER.
1440 UIDS can be a string, number or a list of numbers. If RECEIVE
1441 is non-nil return theese properties."
1442 (with-current-buffer (or buffer (current-buffer))
1443 (when (imap-ok-p (imap-send-command-wait
1444 (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1446 (imap-list-to-message-set uids)
1449 (if (or (null receive) (stringp uids))
1452 (mapcar (lambda (uid)
1454 (mapcar (lambda (prop)
1455 (imap-message-get uid prop))
1457 (imap-message-get uid receive)))
1459 (imap-message-get uids receive))))))
1461 (defun imap-message-put (uid propname value &optional buffer)
1462 (with-current-buffer (or buffer (current-buffer))
1463 (if imap-message-data
1464 (put (intern (number-to-string uid) imap-message-data)
1466 (error "Imap-message-data is nil, uid %s prop %s value %s buffer %s"
1467 uid propname value (current-buffer)))
1470 (defun imap-message-get (uid propname &optional buffer)
1471 (with-current-buffer (or buffer (current-buffer))
1472 (get (intern-soft (number-to-string uid) imap-message-data)
1475 (defun imap-message-map (func propname &optional buffer)
1476 "Map a function across each mailbox in `imap-message-data', returning a list."
1477 (with-current-buffer (or buffer (current-buffer))
1481 (push (funcall func (get s 'UID) (get s propname)) result))
1485 (defmacro imap-message-envelope-date (uid &optional buffer)
1486 `(with-current-buffer (or ,buffer (current-buffer))
1487 (elt (imap-message-get ,uid 'ENVELOPE) 0)))
1489 (defmacro imap-message-envelope-subject (uid &optional buffer)
1490 `(with-current-buffer (or ,buffer (current-buffer))
1491 (elt (imap-message-get ,uid 'ENVELOPE) 1)))
1493 (defmacro imap-message-envelope-from (uid &optional buffer)
1494 `(with-current-buffer (or ,buffer (current-buffer))
1495 (elt (imap-message-get ,uid 'ENVELOPE) 2)))
1497 (defmacro imap-message-envelope-sender (uid &optional buffer)
1498 `(with-current-buffer (or ,buffer (current-buffer))
1499 (elt (imap-message-get ,uid 'ENVELOPE) 3)))
1501 (defmacro imap-message-envelope-reply-to (uid &optional buffer)
1502 `(with-current-buffer (or ,buffer (current-buffer))
1503 (elt (imap-message-get ,uid 'ENVELOPE) 4)))
1505 (defmacro imap-message-envelope-to (uid &optional buffer)
1506 `(with-current-buffer (or ,buffer (current-buffer))
1507 (elt (imap-message-get ,uid 'ENVELOPE) 5)))
1509 (defmacro imap-message-envelope-cc (uid &optional buffer)
1510 `(with-current-buffer (or ,buffer (current-buffer))
1511 (elt (imap-message-get ,uid 'ENVELOPE) 6)))
1513 (defmacro imap-message-envelope-bcc (uid &optional buffer)
1514 `(with-current-buffer (or ,buffer (current-buffer))
1515 (elt (imap-message-get ,uid 'ENVELOPE) 7)))
1517 (defmacro imap-message-envelope-in-reply-to (uid &optional buffer)
1518 `(with-current-buffer (or ,buffer (current-buffer))
1519 (elt (imap-message-get ,uid 'ENVELOPE) 8)))
1521 (defmacro imap-message-envelope-message-id (uid &optional buffer)
1522 `(with-current-buffer (or ,buffer (current-buffer))
1523 (elt (imap-message-get ,uid 'ENVELOPE) 9)))
1525 (defmacro imap-message-body (uid &optional buffer)
1526 `(with-current-buffer (or ,buffer (current-buffer))
1527 (imap-message-get ,uid 'BODY)))
1529 (defun imap-search (predicate &optional buffer)
1530 (with-current-buffer (or buffer (current-buffer))
1531 (imap-mailbox-put 'search 'dummy)
1532 (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate)))
1533 (if (eq (imap-mailbox-get-1 'search imap-current-mailbox) 'dummy)
1535 (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...")
1537 (imap-mailbox-get-1 'search imap-current-mailbox)))))
1539 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer)
1540 "Return t iff FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER."
1541 (with-current-buffer (or buffer (current-buffer))
1542 (or (member "\\*" (imap-mailbox-get 'permanentflags mailbox))
1543 (member flag (imap-mailbox-get 'permanentflags mailbox)))))
1545 (defun imap-message-flags-set (articles flags &optional silent buffer)
1546 (when (and articles flags)
1547 (with-current-buffer (or buffer (current-buffer))
1548 (imap-ok-p (imap-send-command-wait
1549 (concat "UID STORE " articles
1550 " FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1552 (defun imap-message-flags-del (articles flags &optional silent buffer)
1553 (when (and articles flags)
1554 (with-current-buffer (or buffer (current-buffer))
1555 (imap-ok-p (imap-send-command-wait
1556 (concat "UID STORE " articles
1557 " -FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1559 (defun imap-message-flags-add (articles flags &optional silent buffer)
1560 (when (and articles flags)
1561 (with-current-buffer (or buffer (current-buffer))
1562 (imap-ok-p (imap-send-command-wait
1563 (concat "UID STORE " articles
1564 " +FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1566 (defun imap-message-copyuid-1 (mailbox)
1567 (if (imap-capability 'UIDPLUS)
1568 (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox))
1569 (string-to-number (nth 2 (imap-mailbox-get-1 'copyuid mailbox))))
1570 (let ((old-mailbox imap-current-mailbox)
1572 (imap-message-data (make-vector 2 0)))
1573 (when (imap-mailbox-examine-1 mailbox)
1575 (and (imap-fetch "*" "UID")
1576 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1577 (apply 'max (imap-message-map
1578 (lambda (uid prop) uid) 'UID))))
1580 (imap-mailbox-select old-mailbox (eq state 'examine))
1581 (imap-mailbox-unselect)))))))
1583 (defun imap-message-copyuid (mailbox &optional buffer)
1584 (with-current-buffer (or buffer (current-buffer))
1585 (imap-message-copyuid-1 (imap-utf7-decode mailbox))))
1587 (defun imap-message-copy (articles mailbox
1588 &optional dont-create no-copyuid buffer)
1589 "Copy ARTICLES (a string message set) to MAILBOX on server in
1590 BUFFER, creating mailbox if it doesn't exist. If dont-create is
1591 non-nil, it will not create a mailbox. On success, return a list with
1592 the UIDVALIDITY of the mailbox the article(s) was copied to as the
1593 first element, rest of list contain the saved articles' UIDs."
1595 (with-current-buffer (or buffer (current-buffer))
1596 (let ((mailbox (imap-utf7-encode mailbox)))
1597 (if (let ((cmd (concat "UID COPY " articles " \"" mailbox "\""))
1598 (imap-current-target-mailbox mailbox))
1599 (if (imap-ok-p (imap-send-command-wait cmd))
1601 (when (and (not dont-create)
1602 ;; removed because of buggy Oracle server
1603 ;; that doesn't send TRYCREATE tags (which
1604 ;; is a MUST according to specifications):
1605 ;;(imap-mailbox-get-1 'trycreate mailbox)
1606 (imap-mailbox-create-1 mailbox))
1607 (imap-ok-p (imap-send-command-wait cmd)))))
1609 (imap-message-copyuid-1 mailbox)))))))
1611 (defun imap-message-appenduid-1 (mailbox)
1612 (if (imap-capability 'UIDPLUS)
1613 (imap-mailbox-get-1 'appenduid mailbox)
1614 (let ((old-mailbox imap-current-mailbox)
1616 (imap-message-data (make-vector 2 0)))
1617 (when (imap-mailbox-examine-1 mailbox)
1619 (and (imap-fetch "*" "UID")
1620 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1621 (apply 'max (imap-message-map
1622 (lambda (uid prop) uid) 'UID))))
1624 (imap-mailbox-select old-mailbox (eq state 'examine))
1625 (imap-mailbox-unselect)))))))
1627 (defun imap-message-appenduid (mailbox &optional buffer)
1628 (with-current-buffer (or buffer (current-buffer))
1629 (imap-message-appenduid-1 (imap-utf7-encode mailbox))))
1631 (defun imap-message-append (mailbox article &optional flags date-time buffer)
1632 "Append ARTICLE (a buffer) to MAILBOX on server in BUFFER.
1633 FLAGS and DATE-TIME is currently not used. Return a cons holding
1634 uidvalidity of MAILBOX and UID the newly created article got, or nil
1636 (let ((mailbox (imap-utf7-encode mailbox)))
1637 (with-current-buffer (or buffer (current-buffer))
1638 (and (let ((imap-current-target-mailbox mailbox))
1640 (imap-send-command-wait
1641 (list "APPEND \"" mailbox "\" " article))))
1642 (imap-message-appenduid-1 mailbox)))))
1644 (defun imap-body-lines (body)
1645 "Return number of lines in article by looking at the mime bodystructure BODY."
1647 (if (stringp (car body))
1648 (cond ((and (string= (upcase (car body)) "TEXT")
1649 (numberp (nth 7 body)))
1651 ((and (string= (upcase (car body)) "MESSAGE")
1652 (numberp (nth 9 body)))
1655 (apply '+ (mapcar 'imap-body-lines body)))
1658 (defun imap-envelope-from (from)
1659 "Return a from string line."
1661 (concat (aref from 0)
1662 (if (aref from 0) " <")
1666 (if (aref from 0) ">"))))
1669 ;; Internal functions.
1671 (defun imap-add-callback (tag func)
1672 (setq imap-callbacks (append (list (cons tag func)) imap-callbacks)))
1674 (defun imap-send-command-1 (cmdstr)
1675 (setq cmdstr (concat cmdstr imap-client-eol))
1677 (with-current-buffer (get-buffer-create imap-log-buffer)
1678 (imap-disable-multibyte)
1679 (buffer-disable-undo)
1680 (goto-char (point-max))
1682 (process-send-string imap-process cmdstr))
1684 (defun imap-send-command (command &optional buffer)
1685 (with-current-buffer (or buffer (current-buffer))
1686 (if (not (listp command)) (setq command (list command)))
1687 (let ((tag (setq imap-tag (1+ imap-tag)))
1689 (setq cmdstr (concat (number-to-string imap-tag) " "))
1690 (while (setq cmd (pop command))
1691 (cond ((stringp cmd)
1692 (setq cmdstr (concat cmdstr cmd)))
1694 (let ((eol imap-client-eol)
1695 (calcfirst imap-calculate-literal-size-first)
1697 (with-current-buffer cmd
1699 (setq size (buffer-size)))
1700 (when (not (equal eol "\r\n"))
1701 ;; XXX modifies buffer!
1702 (goto-char (point-min))
1703 (while (search-forward "\r\n" nil t)
1704 (replace-match eol)))
1706 (setq size (buffer-size))))
1708 (concat cmdstr (format "{%d}" size))))
1711 (imap-send-command-1 cmdstr)
1713 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1714 (setq command nil) ;; abort command if no cont-req
1715 (let ((process imap-process)
1716 (stream imap-stream)
1717 (eol imap-client-eol))
1718 (with-current-buffer cmd
1720 (with-current-buffer (get-buffer-create
1722 (imap-disable-multibyte)
1723 (buffer-disable-undo)
1724 (goto-char (point-max))
1725 (insert-buffer-substring cmd)))
1726 (process-send-region process (point-min)
1728 (process-send-string process imap-client-eol))))
1729 (setq imap-continuation nil)))
1731 (imap-send-command-1 cmdstr)
1734 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1735 (setq command nil) ;; abort command if no cont-req
1736 (setq command (cons (funcall cmd imap-continuation)
1738 (setq imap-continuation nil)))
1740 (error "Unknown command type"))))
1742 (imap-send-command-1 cmdstr))
1745 (defun imap-wait-for-tag (tag &optional buffer)
1746 (with-current-buffer (or buffer (current-buffer))
1747 (let (imap-have-messaged)
1748 (while (and (null imap-continuation)
1749 (memq (process-status imap-process) '(open run))
1750 (< imap-reached-tag tag))
1751 (let ((len (/ (point-max) 1024))
1754 (setq imap-have-messaged t)
1755 (message "imap read: %dk" len))
1756 (accept-process-output imap-process
1757 (truncate imap-read-timeout)
1758 (truncate (* (- imap-read-timeout
1759 (truncate imap-read-timeout))
1761 ;; A process can die _before_ we have processed everything it
1762 ;; has to say. Moreover, this can happen in between the call to
1763 ;; accept-process-output and the call to process-status in an
1764 ;; iteration of the loop above.
1765 (when (and (null imap-continuation)
1766 (< imap-reached-tag tag))
1767 (accept-process-output imap-process 0 0))
1768 (when imap-have-messaged
1770 (and (memq (process-status imap-process) '(open run))
1771 (or (assq tag imap-failed-tags)
1772 (if imap-continuation
1776 (defun imap-sentinel (process string)
1777 (delete-process process))
1779 (defun imap-find-next-line ()
1780 "Return point at end of current line, taking into account literals.
1781 Return nil if no complete line has arrived."
1782 (when (re-search-forward (concat imap-server-eol "\\|{\\([0-9]+\\)}"
1785 (if (match-string 1)
1786 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1788 (goto-char (+ (point) (string-to-number (match-string 1))))
1789 (imap-find-next-line))
1792 (defun imap-arrival-filter (proc string)
1793 "IMAP process filter."
1794 ;; Sometimes, we are called even though the process has died.
1795 ;; Better abstain from doing stuff in that case.
1796 (when (buffer-name (process-buffer proc))
1797 (with-current-buffer (process-buffer proc)
1798 (goto-char (point-max))
1801 (with-current-buffer (get-buffer-create imap-log-buffer)
1802 (imap-disable-multibyte)
1803 (buffer-disable-undo)
1804 (goto-char (point-max))
1807 (goto-char (point-min))
1808 (while (setq end (imap-find-next-line))
1810 (narrow-to-region (point-min) end)
1811 (delete-backward-char (length imap-server-eol))
1812 (goto-char (point-min))
1814 (cond ((eq imap-state 'initial)
1815 (imap-parse-greeting))
1816 ((or (eq imap-state 'auth)
1817 (eq imap-state 'nonauth)
1818 (eq imap-state 'selected)
1819 (eq imap-state 'examine))
1820 (imap-parse-response))
1822 (message "Unknown state %s in arrival filter"
1824 (delete-region (point-min) (point-max)))))))))
1829 (defsubst imap-forward ()
1830 (or (eobp) (forward-char)))
1833 ;; ; Unsigned 32-bit integer
1834 ;; ; (0 <= n < 4,294,967,296)
1836 (defsubst imap-parse-number ()
1837 (when (looking-at "[0-9]+")
1839 (string-to-number (match-string 0))
1840 (goto-char (match-end 0)))))
1842 ;; literal = "{" number "}" CRLF *CHAR8
1843 ;; ; Number represents the number of CHAR8s
1845 (defsubst imap-parse-literal ()
1846 (when (looking-at "{\\([0-9]+\\)}\r\n")
1847 (let ((pos (match-end 0))
1848 (len (string-to-number (match-string 1))))
1849 (if (< (point-max) (+ pos len))
1851 (goto-char (+ pos len))
1852 (buffer-substring pos (+ pos len))))))
1854 ;; string = quoted / literal
1856 ;; quoted = DQUOTE *QUOTED-CHAR DQUOTE
1858 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
1859 ;; "\" quoted-specials
1861 ;; quoted-specials = DQUOTE / "\"
1863 ;; TEXT-CHAR = <any CHAR except CR and LF>
1865 (defsubst imap-parse-string ()
1866 (cond ((eq (char-after) ?\")
1868 (let ((p (point)) (name ""))
1869 (skip-chars-forward "^\"\\\\")
1870 (setq name (buffer-substring p (point)))
1871 (while (eq (char-after) ?\\)
1872 (setq p (1+ (point)))
1874 (skip-chars-forward "^\"\\\\")
1875 (setq name (concat name (buffer-substring p (point)))))
1878 ((eq (char-after) ?{)
1879 (imap-parse-literal))))
1883 (defsubst imap-parse-nil ()
1884 (if (looking-at "NIL")
1885 (goto-char (match-end 0))))
1887 ;; nstring = string / nil
1889 (defsubst imap-parse-nstring ()
1890 (or (imap-parse-string)
1891 (and (imap-parse-nil)
1894 ;; astring = atom / string
1896 ;; atom = 1*ATOM-CHAR
1898 ;; ATOM-CHAR = <any CHAR except atom-specials>
1900 ;; atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
1903 ;; list-wildcards = "%" / "*"
1905 ;; quoted-specials = DQUOTE / "\"
1907 (defsubst imap-parse-astring ()
1908 (or (imap-parse-string)
1909 (buffer-substring (point)
1910 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1911 (goto-char (1- (match-end 0)))
1915 ;; address = "(" addr-name SP addr-adl SP addr-mailbox SP
1918 ;; addr-adl = nstring
1919 ;; ; Holds route from [RFC-822] route-addr if
1922 ;; addr-host = nstring
1923 ;; ; nil indicates [RFC-822] group syntax.
1924 ;; ; Otherwise, holds [RFC-822] domain name
1926 ;; addr-mailbox = nstring
1927 ;; ; nil indicates end of [RFC-822] group; if
1928 ;; ; non-nil and addr-host is nil, holds
1929 ;; ; [RFC-822] group name.
1930 ;; ; Otherwise, holds [RFC-822] local-part
1931 ;; ; after removing [RFC-822] quoting
1933 ;; addr-name = nstring
1934 ;; ; If non-nil, holds phrase from [RFC-822]
1935 ;; ; mailbox after removing [RFC-822] quoting
1938 (defsubst imap-parse-address ()
1940 (when (eq (char-after) ?\()
1942 (setq address (vector (prog1 (imap-parse-nstring)
1944 (prog1 (imap-parse-nstring)
1946 (prog1 (imap-parse-nstring)
1948 (imap-parse-nstring)))
1949 (when (eq (char-after) ?\))
1953 ;; address-list = "(" 1*address ")" / nil
1957 (defsubst imap-parse-address-list ()
1958 (if (eq (char-after) ?\()
1959 (let (address addresses)
1961 (while (and (not (eq (char-after) ?\)))
1962 ;; next line for MS Exchange bug
1963 (progn (and (eq (char-after) ? ) (imap-forward)) t)
1964 (setq address (imap-parse-address)))
1965 (setq addresses (cons address addresses)))
1966 (when (eq (char-after) ?\))
1968 (nreverse addresses)))
1969 (assert (imap-parse-nil) t "In imap-parse-address-list")))
1971 ;; mailbox = "INBOX" / astring
1972 ;; ; INBOX is case-insensitive. All case variants of
1973 ;; ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
1974 ;; ; not as an astring. An astring which consists of
1975 ;; ; the case-insensitive sequence "I" "N" "B" "O" "X"
1976 ;; ; is considered to be INBOX and not an astring.
1977 ;; ; Refer to section 5.1 for further
1978 ;; ; semantic details of mailbox names.
1980 (defsubst imap-parse-mailbox ()
1981 (let ((mailbox (imap-parse-astring)))
1982 (if (string-equal "INBOX" (upcase mailbox))
1986 ;; greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
1988 ;; resp-cond-auth = ("OK" / "PREAUTH") SP resp-text
1989 ;; ; Authentication condition
1991 ;; resp-cond-bye = "BYE" SP resp-text
1993 (defun imap-parse-greeting ()
1994 "Parse a IMAP greeting."
1995 (cond ((looking-at "\\* OK ")
1996 (setq imap-state 'nonauth))
1997 ((looking-at "\\* PREAUTH ")
1998 (setq imap-state 'auth))
1999 ((looking-at "\\* BYE ")
2000 (setq imap-state 'closed))))
2002 ;; response = *(continue-req / response-data) response-done
2004 ;; continue-req = "+" SP (resp-text / base64) CRLF
2006 ;; response-data = "*" SP (resp-cond-state / resp-cond-bye /
2007 ;; mailbox-data / message-data / capability-data) CRLF
2009 ;; response-done = response-tagged / response-fatal
2011 ;; response-fatal = "*" SP resp-cond-bye CRLF
2012 ;; ; Server closes connection immediately
2014 ;; response-tagged = tag SP resp-cond-state CRLF
2016 ;; resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
2017 ;; ; Status condition
2019 ;; resp-cond-bye = "BYE" SP resp-text
2021 ;; mailbox-data = "FLAGS" SP flag-list /
2022 ;; "LIST" SP mailbox-list /
2023 ;; "LSUB" SP mailbox-list /
2024 ;; "SEARCH" *(SP nz-number) /
2025 ;; "STATUS" SP mailbox SP "("
2026 ;; [status-att SP number *(SP status-att SP number)] ")" /
2027 ;; number SP "EXISTS" /
2028 ;; number SP "RECENT"
2030 ;; message-data = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att))
2032 ;; capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
2034 ;; ; IMAP4rev1 servers which offer RFC 1730
2035 ;; ; compatibility MUST list "IMAP4" as the first
2038 (defun imap-parse-response ()
2039 "Parse a IMAP command response."
2041 (case (setq token (read (current-buffer)))
2042 (+ (setq imap-continuation
2043 (or (buffer-substring (min (point-max) (1+ (point)))
2046 (* (case (prog1 (setq token (read (current-buffer)))
2048 (OK (imap-parse-resp-text))
2049 (NO (imap-parse-resp-text))
2050 (BAD (imap-parse-resp-text))
2051 (BYE (imap-parse-resp-text))
2052 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list)))
2053 (LIST (imap-parse-data-list 'list))
2054 (LSUB (imap-parse-data-list 'lsub))
2055 (SEARCH (imap-mailbox-put
2057 (read (concat "(" (buffer-substring (point) (point-max)) ")"))))
2058 (STATUS (imap-parse-status))
2059 (CAPABILITY (setq imap-capability
2060 (read (concat "(" (upcase (buffer-substring
2061 (point) (point-max)))
2063 (ACL (imap-parse-acl))
2064 (t (case (prog1 (read (current-buffer))
2066 (EXISTS (imap-mailbox-put 'exists token))
2067 (RECENT (imap-mailbox-put 'recent token))
2069 (FETCH (imap-parse-fetch token))
2070 (t (message "Garbage: %s" (buffer-string)))))))
2072 (if (not (integerp token))
2073 (message "Garbage: %s" (buffer-string))
2074 (case (prog1 (setq status (read (current-buffer)))
2077 (setq imap-reached-tag (max imap-reached-tag token))
2078 (imap-parse-resp-text)))
2080 (setq imap-reached-tag (max imap-reached-tag token))
2082 (imap-parse-resp-text))
2084 (when (eq (char-after) ?\[)
2085 (setq code (buffer-substring (point)
2086 (search-forward "]")))
2088 (setq text (buffer-substring (point) (point-max)))
2089 (push (list token status code text)
2090 imap-failed-tags))))
2092 (setq imap-reached-tag (max imap-reached-tag token))
2094 (imap-parse-resp-text))
2096 (when (eq (char-after) ?\[)
2097 (setq code (buffer-substring (point)
2098 (search-forward "]")))
2100 (setq text (buffer-substring (point) (point-max)))
2101 (push (list token status code text) imap-failed-tags)
2102 (error "Internal error, tag %s status %s code %s text %s"
2103 token status code text))))
2104 (t (message "Garbage: %s" (buffer-string))))
2105 (when (assq token imap-callbacks)
2106 (funcall (cdr (assq token imap-callbacks)) token status)
2107 (setq imap-callbacks
2108 (imap-remassoc token imap-callbacks)))))))))
2110 ;; resp-text = ["[" resp-text-code "]" SP] text
2112 ;; text = 1*TEXT-CHAR
2114 ;; TEXT-CHAR = <any CHAR except CR and LF>
2116 (defun imap-parse-resp-text ()
2117 (imap-parse-resp-text-code))
2119 ;; resp-text-code = "ALERT" /
2120 ;; "BADCHARSET [SP "(" astring *(SP astring) ")" ] /
2121 ;; "NEWNAME" SP string SP string /
2123 ;; "PERMANENTFLAGS" SP "("
2124 ;; [flag-perm *(SP flag-perm)] ")" /
2128 ;; "UIDNEXT" SP nz-number /
2129 ;; "UIDVALIDITY" SP nz-number /
2130 ;; "UNSEEN" SP nz-number /
2131 ;; resp-text-atom [SP 1*<any TEXT-CHAR except "]">]
2133 ;; resp_code_apnd = "APPENDUID" SPACE nz_number SPACE uniqueid
2135 ;; resp_code_copy = "COPYUID" SPACE nz_number SPACE set SPACE set
2137 ;; set = sequence-num / (sequence-num ":" sequence-num) /
2139 ;; ; Identifies a set of messages. For message
2140 ;; ; sequence numbers, these are consecutive
2141 ;; ; numbers from 1 to the number of messages in
2143 ;; ; Comma delimits individual numbers, colon
2144 ;; ; delimits between two numbers inclusive.
2145 ;; ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13,
2146 ;; ; 14,15 for a mailbox with 15 messages.
2148 ;; sequence-num = nz-number / "*"
2149 ;; ; * is the largest number in use. For message
2150 ;; ; sequence numbers, it is the number of messages
2151 ;; ; in the mailbox. For unique identifiers, it is
2152 ;; ; the unique identifier of the last message in
2155 ;; flag-perm = flag / "\*"
2157 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2158 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2159 ;; ; Does not include "\Recent"
2161 ;; flag-extension = "\" atom
2162 ;; ; Future expansion. Client implementations
2163 ;; ; MUST accept flag-extension flags. Server
2164 ;; ; implementations MUST NOT generate
2165 ;; ; flag-extension flags except as defined by
2166 ;; ; future standard or standards-track
2167 ;; ; revisions of this specification.
2169 ;; flag-keyword = atom
2171 ;; resp-text-atom = 1*<any ATOM-CHAR except "]">
2173 (defun imap-parse-resp-text-code ()
2174 ;; xxx next line for stalker communigate pro 3.3.1 bug
2175 (when (looking-at " \\[")
2177 (when (eq (char-after) ?\[)
2179 (cond ((search-forward "PERMANENTFLAGS " nil t)
2180 (imap-mailbox-put 'permanentflags (imap-parse-flag-list)))
2181 ((search-forward "UIDNEXT \\([0-9]+\\)" nil t)
2182 (imap-mailbox-put 'uidnext (match-string 1)))
2183 ((search-forward "UNSEEN " nil t)
2184 (imap-mailbox-put 'first-unseen (read (current-buffer))))
2185 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
2186 (imap-mailbox-put 'uidvalidity (match-string 1)))
2187 ((search-forward "READ-ONLY" nil t)
2188 (imap-mailbox-put 'read-only t))
2189 ((search-forward "NEWNAME " nil t)
2190 (let (oldname newname)
2191 (setq oldname (imap-parse-string))
2193 (setq newname (imap-parse-string))
2194 (imap-mailbox-put 'newname newname oldname)))
2195 ((search-forward "TRYCREATE" nil t)
2196 (imap-mailbox-put 'trycreate t imap-current-target-mailbox))
2197 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
2198 (imap-mailbox-put 'appenduid
2199 (list (match-string 1)
2200 (string-to-number (match-string 2)))
2201 imap-current-target-mailbox))
2202 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
2203 (imap-mailbox-put 'copyuid (list (match-string 1)
2206 imap-current-target-mailbox))
2207 ((search-forward "ALERT] " nil t)
2208 (message "Imap server %s information: %s" imap-server
2209 (buffer-substring (point) (point-max)))))))
2211 ;; mailbox-list = "(" [mbx-list-flags] ")" SP
2212 ;; (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox
2214 ;; mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag
2215 ;; *(SP mbx-list-oflag) /
2216 ;; mbx-list-oflag *(SP mbx-list-oflag)
2218 ;; mbx-list-oflag = "\Noinferiors" / flag-extension
2219 ;; ; Other flags; multiple possible per LIST response
2221 ;; mbx-list-sflag = "\Noselect" / "\Marked" / "\Unmarked"
2222 ;; ; Selectability flags; only one per LIST response
2224 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
2225 ;; "\" quoted-specials
2227 ;; quoted-specials = DQUOTE / "\"
2229 (defun imap-parse-data-list (type)
2230 (let (flags delimiter mailbox)
2231 (setq flags (imap-parse-flag-list))
2232 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
2233 (setq delimiter (match-string 1))
2234 (goto-char (1+ (match-end 0)))
2235 (when (setq mailbox (imap-parse-mailbox))
2236 (imap-mailbox-put type t mailbox)
2237 (imap-mailbox-put 'list-flags flags mailbox)
2238 (imap-mailbox-put 'delimiter delimiter mailbox)))))
2240 ;; msg_att ::= "(" 1#("ENVELOPE" SPACE envelope /
2241 ;; "FLAGS" SPACE "(" #(flag / "\Recent") ")" /
2242 ;; "INTERNALDATE" SPACE date_time /
2243 ;; "RFC822" [".HEADER" / ".TEXT"] SPACE nstring /
2244 ;; "RFC822.SIZE" SPACE number /
2245 ;; "BODY" ["STRUCTURE"] SPACE body /
2246 ;; "BODY" section ["<" number ">"] SPACE nstring /
2247 ;; "UID" SPACE uniqueid) ")"
2249 ;; date_time ::= <"> date_day_fixed "-" date_month "-" date_year
2250 ;; SPACE time SPACE zone <">
2252 ;; section ::= "[" [section_text / (nz_number *["." nz_number]
2253 ;; ["." (section_text / "MIME")])] "]"
2255 ;; section_text ::= "HEADER" / "HEADER.FIELDS" [".NOT"]
2256 ;; SPACE header_list / "TEXT"
2258 ;; header_fld_name ::= astring
2260 ;; header_list ::= "(" 1#header_fld_name ")"
2262 (defsubst imap-parse-header-list ()
2263 (when (eq (char-after) ?\()
2265 (while (not (eq (char-after) ?\)))
2267 (push (imap-parse-astring) strlist))
2269 (nreverse strlist))))
2271 (defsubst imap-parse-fetch-body-section ()
2273 (buffer-substring (point) (1- (re-search-forward "[] ]" nil t)))))
2274 (if (eq (char-before) ? )
2276 (mapconcat 'identity (cons section (imap-parse-header-list)) " ")
2277 (search-forward "]" nil t))
2280 (defun imap-parse-fetch (response)
2281 (when (eq (char-after) ?\()
2282 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text
2283 rfc822size body bodydetail bodystructure flags-empty)
2284 (while (not (eq (char-after) ?\)))
2286 (let ((token (read (current-buffer))))
2288 (cond ((eq token 'UID)
2289 (setq uid (condition-case ()
2290 (read (current-buffer))
2293 (setq flags (imap-parse-flag-list))
2295 (setq flags-empty 't)))
2296 ((eq token 'ENVELOPE)
2297 (setq envelope (imap-parse-envelope)))
2298 ((eq token 'INTERNALDATE)
2299 (setq internaldate (imap-parse-string)))
2301 (setq rfc822 (imap-parse-nstring)))
2302 ((eq token 'RFC822.HEADER)
2303 (setq rfc822header (imap-parse-nstring)))
2304 ((eq token 'RFC822.TEXT)
2305 (setq rfc822text (imap-parse-nstring)))
2306 ((eq token 'RFC822.SIZE)
2307 (setq rfc822size (read (current-buffer))))
2309 (if (eq (char-before) ?\[)
2311 (upcase (imap-parse-fetch-body-section))
2312 (and (eq (char-after) ?<)
2313 (buffer-substring (1+ (point))
2314 (search-forward ">" nil t)))
2315 (progn (imap-forward)
2316 (imap-parse-nstring)))
2318 (setq body (imap-parse-body))))
2319 ((eq token 'BODYSTRUCTURE)
2320 (setq bodystructure (imap-parse-body))))))
2322 (setq imap-current-message uid)
2323 (imap-message-put uid 'UID uid)
2324 (and (or flags flags-empty) (imap-message-put uid 'FLAGS flags))
2325 (and envelope (imap-message-put uid 'ENVELOPE envelope))
2326 (and internaldate (imap-message-put uid 'INTERNALDATE internaldate))
2327 (and rfc822 (imap-message-put uid 'RFC822 rfc822))
2328 (and rfc822header (imap-message-put uid 'RFC822.HEADER rfc822header))
2329 (and rfc822text (imap-message-put uid 'RFC822.TEXT rfc822text))
2330 (and rfc822size (imap-message-put uid 'RFC822.SIZE rfc822size))
2331 (and body (imap-message-put uid 'BODY body))
2332 (and bodydetail (imap-message-put uid 'BODYDETAIL bodydetail))
2333 (and bodystructure (imap-message-put uid 'BODYSTRUCTURE bodystructure))
2334 (run-hooks 'imap-fetch-data-hook)))))
2336 ;; mailbox-data = ...
2337 ;; "STATUS" SP mailbox SP "("
2338 ;; [status-att SP number
2339 ;; *(SP status-att SP number)] ")"
2342 ;; status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" /
2345 (defun imap-parse-status ()
2346 (let ((mailbox (imap-parse-mailbox)))
2347 (if (eq (char-after) ? )
2349 (when (and mailbox (eq (char-after) ?\())
2350 (while (and (not (eq (char-after) ?\)))
2351 (or (forward-char) t)
2352 (looking-at "\\([A-Za-z]+\\) "))
2353 (let ((token (match-string 1)))
2354 (goto-char (match-end 0))
2355 (cond ((string= token "MESSAGES")
2356 (imap-mailbox-put 'messages (read (current-buffer)) mailbox))
2357 ((string= token "RECENT")
2358 (imap-mailbox-put 'recent (read (current-buffer)) mailbox))
2359 ((string= token "UIDNEXT")
2360 (and (looking-at "[0-9]+")
2361 (imap-mailbox-put 'uidnext (match-string 0) mailbox)
2362 (goto-char (match-end 0))))
2363 ((string= token "UIDVALIDITY")
2364 (and (looking-at "[0-9]+")
2365 (imap-mailbox-put 'uidvalidity (match-string 0) mailbox)
2366 (goto-char (match-end 0))))
2367 ((string= token "UNSEEN")
2368 (imap-mailbox-put 'unseen (read (current-buffer)) mailbox))
2370 (message "Unknown status data %s in mailbox %s ignored"
2372 (read (current-buffer)))))))))
2374 ;; acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE
2377 ;; identifier ::= astring
2379 ;; rights ::= astring
2381 (defun imap-parse-acl ()
2382 (let ((mailbox (imap-parse-mailbox))
2383 identifier rights acl)
2384 (while (eq (char-after) ?\ )
2386 (setq identifier (imap-parse-astring))
2388 (setq rights (imap-parse-astring))
2389 (setq acl (append acl (list (cons identifier rights)))))
2390 (imap-mailbox-put 'acl acl mailbox)))
2392 ;; flag-list = "(" [flag *(SP flag)] ")"
2394 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2395 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2396 ;; ; Does not include "\Recent"
2398 ;; flag-keyword = atom
2400 ;; flag-extension = "\" atom
2401 ;; ; Future expansion. Client implementations
2402 ;; ; MUST accept flag-extension flags. Server
2403 ;; ; implementations MUST NOT generate
2404 ;; ; flag-extension flags except as defined by
2405 ;; ; future standard or standards-track
2406 ;; ; revisions of this specification.
2408 (defun imap-parse-flag-list ()
2409 (let (flag-list start)
2410 (assert (eq (char-after) ?\() t "In imap-parse-flag-list")
2411 (while (and (not (eq (char-after) ?\)))
2414 ;; next line for Courier IMAP bug.
2415 (skip-chars-forward " ")
2417 (> (skip-chars-forward "^ )" (imap-point-at-eol)) 0))
2418 (push (buffer-substring start (point)) flag-list))
2419 (assert (eq (char-after) ?\)) t "In imap-parse-flag-list")
2421 (nreverse flag-list)))
2423 ;; envelope = "(" env-date SP env-subject SP env-from SP env-sender SP
2424 ;; env-reply-to SP env-to SP env-cc SP env-bcc SP
2425 ;; env-in-reply-to SP env-message-id ")"
2427 ;; env-bcc = "(" 1*address ")" / nil
2429 ;; env-cc = "(" 1*address ")" / nil
2431 ;; env-date = nstring
2433 ;; env-from = "(" 1*address ")" / nil
2435 ;; env-in-reply-to = nstring
2437 ;; env-message-id = nstring
2439 ;; env-reply-to = "(" 1*address ")" / nil
2441 ;; env-sender = "(" 1*address ")" / nil
2443 ;; env-subject = nstring
2445 ;; env-to = "(" 1*address ")" / nil
2447 (defun imap-parse-envelope ()
2448 (when (eq (char-after) ?\()
2450 (vector (prog1 (imap-parse-nstring) ;; date
2452 (prog1 (imap-parse-nstring) ;; subject
2454 (prog1 (imap-parse-address-list) ;; from
2456 (prog1 (imap-parse-address-list) ;; sender
2458 (prog1 (imap-parse-address-list) ;; reply-to
2460 (prog1 (imap-parse-address-list) ;; to
2462 (prog1 (imap-parse-address-list) ;; cc
2464 (prog1 (imap-parse-address-list) ;; bcc
2466 (prog1 (imap-parse-nstring) ;; in-reply-to
2468 (prog1 (imap-parse-nstring) ;; message-id
2471 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2473 (defsubst imap-parse-string-list ()
2474 (cond ((eq (char-after) ?\() ;; body-fld-param
2477 (while (setq str (imap-parse-string))
2479 ;; buggy stalker communigate pro 3.0 doesn't print SPC
2480 ;; between body-fld-param's sometimes
2481 (or (eq (char-after) ?\")
2483 (nreverse strlist)))
2487 ;; body-extension = nstring / number /
2488 ;; "(" body-extension *(SP body-extension) ")"
2489 ;; ; Future expansion. Client implementations
2490 ;; ; MUST accept body-extension fields. Server
2491 ;; ; implementations MUST NOT generate
2492 ;; ; body-extension fields except as defined by
2493 ;; ; future standard or standards-track
2494 ;; ; revisions of this specification.
2496 (defun imap-parse-body-extension ()
2497 (if (eq (char-after) ?\()
2500 (push (imap-parse-body-extension) b-e)
2501 (while (eq (char-after) ?\ )
2503 (push (imap-parse-body-extension) b-e))
2504 (assert (eq (char-after) ?\)) t "In imap-parse-body-extension")
2507 (or (imap-parse-number)
2508 (imap-parse-nstring))))
2510 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2511 ;; *(SP body-extension)]]
2512 ;; ; MUST NOT be returned on non-extensible
2515 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2516 ;; *(SP body-extension)]]
2517 ;; ; MUST NOT be returned on non-extensible
2520 (defsubst imap-parse-body-ext ()
2522 (when (eq (char-after) ?\ ) ;; body-fld-dsp
2525 (if (eq (char-after) ?\()
2528 (push (imap-parse-string) dsp)
2530 (push (imap-parse-string-list) dsp)
2532 (assert (imap-parse-nil) t "In imap-parse-body-ext"))
2533 (push (nreverse dsp) ext))
2534 (when (eq (char-after) ?\ ) ;; body-fld-lang
2536 (if (eq (char-after) ?\()
2537 (push (imap-parse-string-list) ext)
2538 (push (imap-parse-nstring) ext))
2539 (while (eq (char-after) ?\ ) ;; body-extension
2541 (setq ext (append (imap-parse-body-extension) ext)))))
2544 ;; body = "(" body-type-1part / body-type-mpart ")"
2546 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2547 ;; *(SP body-extension)]]
2548 ;; ; MUST NOT be returned on non-extensible
2551 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2552 ;; *(SP body-extension)]]
2553 ;; ; MUST NOT be returned on non-extensible
2556 ;; body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP
2557 ;; body-fld-enc SP body-fld-octets
2559 ;; body-fld-desc = nstring
2561 ;; body-fld-dsp = "(" string SP body-fld-param ")" / nil
2563 ;; body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
2564 ;; "QUOTED-PRINTABLE") DQUOTE) / string
2566 ;; body-fld-id = nstring
2568 ;; body-fld-lang = nstring / "(" string *(SP string) ")"
2570 ;; body-fld-lines = number
2572 ;; body-fld-md5 = nstring
2574 ;; body-fld-octets = number
2576 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2578 ;; body-type-1part = (body-type-basic / body-type-msg / body-type-text)
2579 ;; [SP body-ext-1part]
2581 ;; body-type-basic = media-basic SP body-fields
2582 ;; ; MESSAGE subtype MUST NOT be "RFC822"
2584 ;; body-type-msg = media-message SP body-fields SP envelope
2585 ;; SP body SP body-fld-lines
2587 ;; body-type-text = media-text SP body-fields SP body-fld-lines
2589 ;; body-type-mpart = 1*body SP media-subtype
2590 ;; [SP body-ext-mpart]
2592 ;; media-basic = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" /
2593 ;; "MESSAGE" / "VIDEO") DQUOTE) / string) SP media-subtype
2594 ;; ; Defined in [MIME-IMT]
2596 ;; media-message = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE
2597 ;; ; Defined in [MIME-IMT]
2599 ;; media-subtype = string
2600 ;; ; Defined in [MIME-IMT]
2602 ;; media-text = DQUOTE "TEXT" DQUOTE SP media-subtype
2603 ;; ; Defined in [MIME-IMT]
2605 (defun imap-parse-body ()
2607 (when (eq (char-after) ?\()
2609 (if (eq (char-after) ?\()
2611 (while (and (eq (char-after) ?\()
2612 (setq subbody (imap-parse-body)))
2613 ;; buggy stalker communigate pro 3.0 insert a SPC between
2614 ;; parts in multiparts
2615 (when (and (eq (char-after) ?\ )
2616 (eq (char-after (1+ (point))) ?\())
2618 (push subbody body))
2620 (push (imap-parse-string) body) ;; media-subtype
2621 (when (eq (char-after) ?\ ) ;; body-ext-mpart:
2623 (if (eq (char-after) ?\() ;; body-fld-param
2624 (push (imap-parse-string-list) body)
2625 (push (and (imap-parse-nil) nil) body))
2627 (append (imap-parse-body-ext) body))) ;; body-ext-...
2628 (assert (eq (char-after) ?\)) t "In imap-parse-body")
2632 (push (imap-parse-string) body) ;; media-type
2634 (push (imap-parse-string) body) ;; media-subtype
2636 ;; next line for Sun SIMS bug
2637 (and (eq (char-after) ? ) (imap-forward))
2638 (if (eq (char-after) ?\() ;; body-fld-param
2639 (push (imap-parse-string-list) body)
2640 (push (and (imap-parse-nil) nil) body))
2642 (push (imap-parse-nstring) body) ;; body-fld-id
2644 (push (imap-parse-nstring) body) ;; body-fld-desc
2646 ;; next `or' for Sun SIMS bug, it regard body-fld-enc as a
2647 ;; nstring and return nil instead of defaulting back to 7BIT
2648 ;; as the standard says.
2649 (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc
2651 (push (imap-parse-number) body) ;; body-fld-octets
2653 ;; ok, we're done parsing the required parts, what comes now is one
2656 ;; envelope (then we're parsing body-type-msg)
2657 ;; body-fld-lines (then we're parsing body-type-text)
2658 ;; body-ext-1part (then we're parsing body-type-basic)
2660 ;; the problem is that the two first are in turn optionally followed
2661 ;; by the third. So we parse the first two here (if there are any)...
2663 (when (eq (char-after) ?\ )
2666 (cond ((eq (char-after) ?\() ;; body-type-msg:
2667 (push (imap-parse-envelope) body) ;; envelope
2669 (push (imap-parse-body) body) ;; body
2670 ;; buggy stalker communigate pro 3.0 doesn't print
2671 ;; number of lines in message/rfc822 attachment
2672 (if (eq (char-after) ?\))
2675 (push (imap-parse-number) body))) ;; body-fld-lines
2676 ((setq lines (imap-parse-number)) ;; body-type-text:
2677 (push lines body)) ;; body-fld-lines
2679 (backward-char))))) ;; no match...
2681 ;; ...and then parse the third one here...
2683 (when (eq (char-after) ?\ ) ;; body-ext-1part:
2685 (push (imap-parse-nstring) body) ;; body-fld-md5
2686 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part..
2688 (assert (eq (char-after) ?\)) t "In imap-parse-body 2")
2692 (when imap-debug ; (untrace-all)
2694 (buffer-disable-undo (get-buffer-create imap-debug-buffer))
2695 (mapcar (lambda (f) (trace-function-background f imap-debug-buffer))
2706 imap-interactive-login
2722 imap-send-command-wait
2727 imap-current-mailbox
2728 imap-current-mailbox-p-1
2729 imap-current-mailbox-p
2730 imap-mailbox-select-1
2732 imap-mailbox-examine-1
2733 imap-mailbox-examine
2734 imap-mailbox-unselect
2735 imap-mailbox-expunge
2737 imap-mailbox-create-1
2743 imap-mailbox-subscribe
2744 imap-mailbox-unsubscribe
2746 imap-mailbox-acl-get
2747 imap-mailbox-acl-set
2748 imap-mailbox-acl-delete
2749 imap-current-message
2750 imap-list-to-message-set
2757 imap-message-flag-permanent-p
2758 imap-message-flags-set
2759 imap-message-flags-del
2760 imap-message-flags-add
2761 imap-message-copyuid-1
2762 imap-message-copyuid
2764 imap-message-appenduid-1
2765 imap-message-appenduid
2777 imap-parse-resp-text
2778 imap-parse-resp-text-code
2779 imap-parse-data-list
2783 imap-parse-flag-list
2785 imap-parse-body-extension
2791 ;;; imap.el ends here