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.
131 ;; - 19991218 added starttls/digest-md5 patch,
132 ;; by Daiki Ueno <ueno@ueda.info.waseda.ac.jp>
133 ;; NB! you need SLIM for starttls.el and digest-md5.el
134 ;; - 19991023 commited to pgnus
139 (eval-when-compile (require 'cl))
141 (autoload 'base64-decode-string "base64")
142 (autoload 'base64-encode-string "base64")
143 (autoload 'starttls-open-stream "starttls")
144 (autoload 'starttls-negotiate "starttls")
145 (autoload 'digest-md5-parse-digest-challenge "digest-md5")
146 (autoload 'digest-md5-digest-response "digest-md5")
147 (autoload 'digest-md5-digest-uri "digest-md5")
148 (autoload 'digest-md5-challenge "digest-md5")
149 (autoload 'rfc2104-hash "rfc2104")
150 (autoload 'md5 "md5")
151 (autoload 'utf7-encode "utf7")
152 (autoload 'utf7-decode "utf7")
153 (autoload 'format-spec "format-spec")
154 (autoload 'format-spec-make "format-spec")
155 (autoload 'open-tls-stream "tls")
156 ;; Avoid use gnus-point-at-eol so we're independent of Gnus. These
157 ;; days we have point-at-eol anyhow.
158 (if (fboundp 'point-at-eol)
159 (defalias 'imap-point-at-eol 'point-at-eol)
160 (defun imap-point-at-eol ()
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 and GSSAPI."
227 (defcustom imap-use-utf7 t
228 "If non-nil, do utf7 encoding/decoding of mailbox names.
229 Since the UTF7 decoding currently only decodes into ISO-8859-1
230 characters, you may disable this decoding if you need to access UTF7
231 encoded mailboxes which doesn't translate into ISO-8859-1."
235 (defcustom imap-log nil
236 "If non-nil, a imap session trace is placed in *imap-log* buffer."
240 (defcustom imap-debug nil
241 "If non-nil, random debug spews are placed in *imap-debug* buffer."
245 (defcustom imap-shell-host "gateway"
246 "Hostname of rlogin proxy."
250 (defcustom imap-default-user (user-login-name)
251 "Default username to use."
255 (defcustom imap-read-timeout (if (string-match
256 "windows-nt\\|os/2\\|emx\\|cygwin"
257 (symbol-name system-type))
260 "*How long to wait between checking for the end of output.
261 Shorter values mean quicker response, but is more CPU intensive."
265 ;; Various variables.
267 (defvar imap-fetch-data-hook nil
268 "Hooks called after receiving each FETCH response.")
270 (defvar imap-streams '(gssapi kerberos4 starttls tls ssl network shell)
271 "Priority of streams to consider when opening connection to server.")
273 (defvar imap-stream-alist
274 '((gssapi imap-gssapi-stream-p imap-gssapi-open)
275 (kerberos4 imap-kerberos4-stream-p imap-kerberos4-open)
276 (tls imap-tls-p imap-tls-open)
277 (ssl imap-ssl-p imap-ssl-open)
278 (network imap-network-p imap-network-open)
279 (shell imap-shell-p imap-shell-open)
280 (starttls imap-starttls-p imap-starttls-open))
281 "Definition of network streams.
285 NAME names the stream, CHECK is a function returning non-nil if the
286 server support the stream and OPEN is a function for opening the
289 (defvar imap-authenticators '(gssapi
295 "Priority of authenticators to consider when authenticating to server.")
297 (defvar imap-authenticator-alist
298 '((gssapi imap-gssapi-auth-p imap-gssapi-auth)
299 (kerberos4 imap-kerberos4-auth-p imap-kerberos4-auth)
300 (cram-md5 imap-cram-md5-p imap-cram-md5-auth)
301 (login imap-login-p imap-login-auth)
302 (anonymous imap-anonymous-p imap-anonymous-auth)
303 (digest-md5 imap-digest-md5-p imap-digest-md5-auth))
304 "Definition of authenticators.
306 \(NAME CHECK AUTHENTICATE)
308 NAME names the authenticator. CHECK is a function returning non-nil if
309 the server support the authenticator and AUTHENTICATE is a function
310 for doing the actual authentication.")
312 (defvar imap-error nil
313 "Error codes from the last command.")
315 ;; Internal constants. Change theese and die.
317 (defconst imap-default-port 143)
318 (defconst imap-default-ssl-port 993)
319 (defconst imap-default-tls-port 993)
320 (defconst imap-default-stream 'network)
321 (defconst imap-coding-system-for-read 'binary)
322 (defconst imap-coding-system-for-write 'binary)
323 (defconst imap-local-variables '(imap-server
332 imap-current-target-mailbox
341 imap-calculate-literal-size-first
343 (defconst imap-log-buffer "*imap-log*")
344 (defconst imap-debug-buffer "*imap-debug*")
346 ;; Internal variables.
348 (defvar imap-stream nil)
349 (defvar imap-auth nil)
350 (defvar imap-server nil)
351 (defvar imap-port nil)
352 (defvar imap-username nil)
353 (defvar imap-password nil)
354 (defvar imap-calculate-literal-size-first nil)
355 (defvar imap-state 'closed
357 Valid states are `closed', `initial', `nonauth', `auth', `selected'
360 (defvar imap-server-eol "\r\n"
361 "The EOL string sent from the server.")
363 (defvar imap-client-eol "\r\n"
364 "The EOL string we send to the server.")
366 (defvar imap-current-mailbox nil
367 "Current mailbox name.")
369 (defvar imap-current-target-mailbox nil
370 "Current target mailbox for COPY and APPEND commands.")
372 (defvar imap-mailbox-data nil
373 "Obarray with mailbox data.")
375 (defvar imap-mailbox-prime 997
376 "Length of imap-mailbox-data.")
378 (defvar imap-current-message nil
379 "Current message number.")
381 (defvar imap-message-data nil
382 "Obarray with message data.")
384 (defvar imap-message-prime 997
385 "Length of imap-message-data.")
387 (defvar imap-capability nil
388 "Capability for server.")
390 (defvar imap-namespace nil
391 "Namespace for current server.")
393 (defvar imap-reached-tag 0
394 "Lower limit on command tags that have been parsed.")
396 (defvar imap-failed-tags nil
397 "Alist of tags that failed.
398 Each element is a list with four elements; tag (a integer), response
399 state (a symbol, `OK', `NO' or `BAD'), response code (a string), and
400 human readable response text (a string).")
403 "Command tag number.")
405 (defvar imap-process nil
408 (defvar imap-continuation nil
409 "Non-nil indicates that the server emitted a continuation request.
410 The actual value is really the text on the continuation line.")
412 (defvar imap-callbacks nil
413 "List of response tags and callbacks, on the form `(number . function)'.
414 The function should take two arguments, the first the IMAP tag and the
415 second the status (OK, NO, BAD etc) of the command.")
418 ;; Utility functions:
420 (defun imap-remassoc (key alist)
421 "Delete by side effect any elements of LIST whose car is `equal' to KEY.
422 The modified LIST is returned. If the first member
423 of LIST has a car that is `equal' to KEY, there is no way to remove it
424 by side effect; therefore, write `(setq foo (remassoc key foo))' to be
425 sure of changing the value of `foo'."
427 (if (equal key (caar alist))
429 (setcdr alist (imap-remassoc key (cdr alist)))
432 (defsubst imap-disable-multibyte ()
433 "Enable multibyte in the current buffer."
434 (when (fboundp 'set-buffer-multibyte)
435 (set-buffer-multibyte nil)))
437 (defsubst imap-utf7-encode (string)
441 (utf7-encode string t)
443 "imap: Could not UTF7 encode `%s', using it unencoded..."
448 (defsubst imap-utf7-decode (string)
452 (utf7-decode string t)
454 "imap: Could not UTF7 decode `%s', using it undecoded..."
459 (defsubst imap-ok-p (status)
462 (setq imap-error status)
465 (defun imap-error-text (&optional buffer)
466 (with-current-buffer (or buffer (current-buffer))
467 (nth 3 (car imap-failed-tags))))
470 ;; Server functions; stream stuff:
472 (defun imap-kerberos4-stream-p (buffer)
473 (imap-capability 'AUTH=KERBEROS_V4 buffer))
475 (defun imap-kerberos4-open (name buffer server port)
476 (let ((cmds imap-kerberos4-program)
478 (while (and (not done) (setq cmd (pop cmds)))
479 (message "Opening Kerberos 4 IMAP connection with `%s'..." cmd)
481 (let* ((port (or port imap-default-port))
482 (coding-system-for-read imap-coding-system-for-read)
483 (coding-system-for-write imap-coding-system-for-write)
484 (process-connection-type imap-process-connection-type)
485 (process (start-process
486 name buffer shell-file-name shell-command-switch
491 ?p (number-to-string port)
492 ?l imap-default-user))))
495 (with-current-buffer buffer
496 (setq imap-client-eol "\n"
497 imap-calculate-literal-size-first t)
498 (while (and (memq (process-status process) '(open run))
499 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
500 (goto-char (point-min))
501 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
502 (or (while (looking-at "^C:")
505 ;; cyrus 1.6 imtest print "S: " before server greeting
506 (or (not (looking-at "S: "))
509 (not (and (imap-parse-greeting)
510 ;; success in imtest < 1.6:
511 (or (re-search-forward
512 "^__\\(.*\\)__\n" nil t)
513 ;; success in imtest 1.6:
515 "^\\(Authenticat.*\\)" nil t))
516 (setq response (match-string 1)))))
517 (accept-process-output process 1)
520 (with-current-buffer (get-buffer-create imap-log-buffer)
521 (imap-disable-multibyte)
522 (buffer-disable-undo)
523 (goto-char (point-max))
524 (insert-buffer-substring buffer)))
526 (message "Opening Kerberos 4 IMAP connection with `%s'...%s" cmd
527 (if response (concat "done, " response) "failed"))
528 (if (and response (let ((case-fold-search nil))
529 (not (string-match "failed" response))))
531 (if (memq (process-status process) '(open run))
532 (imap-send-command "LOGOUT"))
533 (delete-process process)
537 (defun imap-gssapi-stream-p (buffer)
538 (imap-capability 'AUTH=GSSAPI buffer))
540 (defun imap-gssapi-open (name buffer server port)
541 (let ((cmds imap-gssapi-program)
543 (while (and (not done) (setq cmd (pop cmds)))
544 (message "Opening GSSAPI IMAP connection with `%s'..." cmd)
546 (let* ((port (or port imap-default-port))
547 (coding-system-for-read imap-coding-system-for-read)
548 (coding-system-for-write imap-coding-system-for-write)
549 (process-connection-type imap-process-connection-type)
550 (process (start-process
551 name buffer shell-file-name shell-command-switch
556 ?p (number-to-string port)
557 ?l imap-default-user))))
560 (with-current-buffer buffer
561 (setq imap-client-eol "\n"
562 imap-calculate-literal-size-first t)
563 (while (and (memq (process-status process) '(open run))
564 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
565 (goto-char (point-min))
566 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
567 (or (while (looking-at "^C:")
570 ;; cyrus 1.6 imtest print "S: " before server greeting
571 (or (not (looking-at "S: "))
574 (not (and (imap-parse-greeting)
575 ;; success in imtest 1.6:
577 (concat "^\\(\\(Authenticat.*\\)\\|\\("
578 "Client authentication "
581 (setq response (match-string 1)))))
582 (accept-process-output process 1)
585 (with-current-buffer (get-buffer-create imap-log-buffer)
586 (imap-disable-multibyte)
587 (buffer-disable-undo)
588 (goto-char (point-max))
589 (insert-buffer-substring buffer)))
591 (message "GSSAPI IMAP connection: %s" (or response "failed"))
592 (if (and response (let ((case-fold-search nil))
593 (not (string-match "failed" response))))
595 (if (memq (process-status process) '(open run))
596 (imap-send-command "LOGOUT"))
597 (delete-process process)
601 (defun imap-ssl-p (buffer)
604 (defun imap-ssl-open (name buffer server port)
605 "Open a SSL connection to server."
606 (let ((cmds (if (listp imap-ssl-program) imap-ssl-program
607 (list imap-ssl-program)))
609 (while (and (not done) (setq cmd (pop cmds)))
610 (message "imap: Opening SSL connection with `%s'..." cmd)
612 (let* ((port (or port imap-default-ssl-port))
613 (coding-system-for-read imap-coding-system-for-read)
614 (coding-system-for-write imap-coding-system-for-write)
615 (process-connection-type nil)
618 (setq process (start-process
619 name buffer shell-file-name
624 ?p (number-to-string port)))))
625 (process-kill-without-query process)
627 (with-current-buffer buffer
628 (goto-char (point-min))
629 (while (and (memq (process-status process) '(open run))
630 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
631 (goto-char (point-max))
633 (not (imap-parse-greeting)))
634 (accept-process-output process 1)
637 (with-current-buffer (get-buffer-create imap-log-buffer)
638 (imap-disable-multibyte)
639 (buffer-disable-undo)
640 (goto-char (point-max))
641 (insert-buffer-substring buffer)))
643 (when (memq (process-status process) '(open run))
644 (setq done process))))))
647 (message "imap: Opening SSL connection with `%s'...done" cmd)
649 (message "imap: Opening SSL connection with `%s'...failed" cmd)
652 (defun imap-tls-p (buffer)
655 (defun imap-tls-open (name buffer server port)
656 (let* ((port (or port imap-default-tls-port))
657 (coding-system-for-read imap-coding-system-for-read)
658 (coding-system-for-write imap-coding-system-for-write)
659 (process (open-tls-stream name buffer server port)))
661 (while (and (memq (process-status process) '(open run))
662 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
663 (goto-char (point-max))
665 (not (imap-parse-greeting)))
666 (accept-process-output process 1)
669 (with-current-buffer (get-buffer-create imap-log-buffer)
670 (imap-disable-multibyte)
671 (buffer-disable-undo)
672 (goto-char (point-max))
673 (insert-buffer-substring buffer)))
674 (when (memq (process-status process) '(open run))
677 (defun imap-network-p (buffer)
680 (defun imap-network-open (name buffer server port)
681 (let* ((port (or port imap-default-port))
682 (coding-system-for-read imap-coding-system-for-read)
683 (coding-system-for-write imap-coding-system-for-write)
684 (process (open-network-stream name buffer server port)))
686 (while (and (memq (process-status process) '(open run))
687 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
688 (goto-char (point-min))
689 (not (imap-parse-greeting)))
690 (accept-process-output process 1)
693 (with-current-buffer (get-buffer-create imap-log-buffer)
694 (imap-disable-multibyte)
695 (buffer-disable-undo)
696 (goto-char (point-max))
697 (insert-buffer-substring buffer)))
698 (when (memq (process-status process) '(open run))
701 (defun imap-shell-p (buffer)
704 (defun imap-shell-open (name buffer server port)
705 (let ((cmds (if (listp imap-shell-program) imap-shell-program
706 (list imap-shell-program)))
708 (while (and (not done) (setq cmd (pop cmds)))
709 (message "imap: Opening IMAP connection with `%s'..." cmd)
710 (setq imap-client-eol "\n")
711 (let* ((port (or port imap-default-port))
712 (coding-system-for-read imap-coding-system-for-read)
713 (coding-system-for-write imap-coding-system-for-write)
714 (process (start-process
715 name buffer shell-file-name shell-command-switch
721 ?p (number-to-string port)
722 ?l imap-default-user)))))
724 (while (and (memq (process-status process) '(open run))
725 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
726 (goto-char (point-max))
728 (not (imap-parse-greeting)))
729 (accept-process-output process 1)
732 (with-current-buffer (get-buffer-create imap-log-buffer)
733 (imap-disable-multibyte)
734 (buffer-disable-undo)
735 (goto-char (point-max))
736 (insert-buffer-substring buffer)))
738 (when (memq (process-status process) '(open run))
739 (setq done process)))))
742 (message "imap: Opening IMAP connection with `%s'...done" cmd)
744 (message "imap: Opening IMAP connection with `%s'...failed" cmd)
747 (defun imap-starttls-p (buffer)
748 (imap-capability 'STARTTLS buffer))
750 (defun imap-starttls-open (name buffer server port)
751 (let* ((port (or port imap-default-port))
752 (coding-system-for-read imap-coding-system-for-read)
753 (coding-system-for-write imap-coding-system-for-write)
754 (process (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))
863 (hash (rfc2104-hash 'md5 64 16 passwd decoded))
864 (response (concat user " " hash))
865 (encoded (base64-encode-string response)))
868 (message "imap: Authenticating using CRAM-MD5...done")
869 (message "imap: Authenticating using CRAM-MD5...failed"))))
871 (defun imap-login-p (buffer)
872 (and (not (imap-capability 'LOGINDISABLED buffer))
873 (not (imap-capability 'X-LOGIN-CMD-DISABLED buffer))))
875 (defun imap-login-auth (buffer)
876 "Login to server using the LOGIN command."
877 (message "imap: Plaintext authentication...")
878 (imap-interactive-login buffer
879 (lambda (user passwd)
880 (imap-ok-p (imap-send-command-wait
881 (concat "LOGIN \"" user "\" \""
884 (defun imap-anonymous-p (buffer)
887 (defun imap-anonymous-auth (buffer)
888 (message "imap: Logging in anonymously...")
889 (with-current-buffer buffer
890 (imap-ok-p (imap-send-command-wait
891 (concat "LOGIN anonymous \"" (concat (user-login-name) "@"
892 (system-name)) "\"")))))
894 (defun imap-digest-md5-p (buffer)
895 (and (imap-capability 'AUTH=DIGEST-MD5 buffer)
897 (require 'digest-md5)
900 (defun imap-digest-md5-auth (buffer)
901 "Login to server using the AUTH DIGEST-MD5 method."
902 (message "imap: Authenticating using DIGEST-MD5...")
903 (imap-interactive-login
905 (lambda (user passwd)
909 "AUTHENTICATE DIGEST-MD5"
911 (digest-md5-parse-digest-challenge
912 (base64-decode-string challenge))
914 (digest-md5-digest-uri
915 "imap" (digest-md5-challenge 'realm)))
917 (digest-md5-digest-response
918 user passwd digest-uri)))
919 (base64-encode-string response 'no-line-break))))
921 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
923 (setq imap-continuation nil)
924 (imap-send-command-1 "")
925 (imap-ok-p (imap-wait-for-tag tag)))))))
929 (defun imap-open-1 (buffer)
930 (with-current-buffer buffer
932 (setq imap-current-mailbox nil
933 imap-current-message nil
935 imap-process (condition-case ()
936 (funcall (nth 2 (assq imap-stream
938 "imap" buffer imap-server imap-port)
941 (set-process-filter imap-process 'imap-arrival-filter)
942 (set-process-sentinel imap-process 'imap-sentinel)
943 (while (and (eq imap-state 'initial)
944 (memq (process-status imap-process) '(open run)))
945 (message "Waiting for response from %s..." imap-server)
946 (accept-process-output imap-process 1))
947 (message "Waiting for response from %s...done" imap-server)
948 (and (memq (process-status imap-process) '(open run))
951 (defun imap-open (server &optional port stream auth buffer)
952 "Open a IMAP connection to host SERVER at PORT returning a buffer.
953 If PORT is unspecified, a default value is used (143 except
954 for SSL which use 993).
955 STREAM indicates the stream to use, see `imap-streams' for available
956 streams. If nil, it choices the best stream the server is capable of.
957 AUTH indicates authenticator to use, see `imap-authenticators' for
958 available authenticators. If nil, it choices the best stream the
959 server is capable of.
960 BUFFER can be a buffer or a name of a buffer, which is created if
961 necessary. If nil, the buffer name is generated."
962 (setq buffer (or buffer (format " *imap* %s:%d" server (or port 0))))
963 (with-current-buffer (get-buffer-create buffer)
964 (if (imap-opened buffer)
966 (mapcar 'make-local-variable imap-local-variables)
967 (imap-disable-multibyte)
968 (buffer-disable-undo)
969 (setq imap-server (or server imap-server))
970 (setq imap-port (or port imap-port))
971 (setq imap-auth (or auth imap-auth))
972 (setq imap-stream (or stream imap-stream))
973 (message "imap: Connecting to %s..." imap-server)
974 (if (null (let ((imap-stream (or imap-stream imap-default-stream)))
975 (imap-open-1 buffer)))
977 (message "imap: Connecting to %s...failed" imap-server)
979 (when (null imap-stream)
980 ;; Need to choose stream.
981 (let ((streams imap-streams))
982 (while (setq stream (pop streams))
983 ;; OK to use this stream?
984 (when (funcall (nth 1 (assq stream imap-stream-alist)) buffer)
986 (if (not (eq imap-default-stream stream))
987 (with-current-buffer (get-buffer-create
988 (generate-new-buffer-name " *temp*"))
989 (mapcar 'make-local-variable imap-local-variables)
990 (imap-disable-multibyte)
991 (buffer-disable-undo)
992 (setq imap-server (or server imap-server))
993 (setq imap-port (or port imap-port))
994 (setq imap-auth (or auth imap-auth))
995 (message "imap: Reconnecting with stream `%s'..." stream)
996 (if (null (let ((imap-stream stream))
997 (imap-open-1 (current-buffer))))
999 (kill-buffer (current-buffer))
1001 "imap: Reconnecting with stream `%s'...failed"
1003 ;; We're done, kill the first connection
1005 (kill-buffer buffer)
1006 (rename-buffer buffer)
1007 (message "imap: Reconnecting with stream `%s'...done"
1009 (setq imap-stream stream)
1010 (setq imap-capability nil)
1011 (setq streams nil)))
1013 (message "imap: Connecting to %s...done" imap-server)
1014 (setq imap-stream stream)
1015 (setq imap-capability nil)
1016 (setq streams nil))))))
1017 (when (imap-opened buffer)
1018 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0)))
1022 (defun imap-opened (&optional buffer)
1023 "Return non-nil if connection to imap server in BUFFER is open.
1024 If BUFFER is nil then the current buffer is used."
1025 (and (setq buffer (get-buffer (or buffer (current-buffer))))
1026 (buffer-live-p buffer)
1027 (with-current-buffer buffer
1029 (memq (process-status imap-process) '(open run))))))
1031 (defun imap-authenticate (&optional user passwd buffer)
1032 "Authenticate to server in BUFFER, using current buffer if nil.
1033 It uses the authenticator specified when opening the server. If the
1034 authenticator requires username/passwords, they are queried from the
1035 user and optionally stored in the buffer. If USER and/or PASSWD is
1036 specified, the user will not be questioned and the username and/or
1037 password is remembered in the buffer."
1038 (with-current-buffer (or buffer (current-buffer))
1039 (if (not (eq imap-state 'nonauth))
1040 (or (eq imap-state 'auth)
1041 (eq imap-state 'select)
1042 (eq imap-state 'examine))
1043 (make-local-variable 'imap-username)
1044 (make-local-variable 'imap-password)
1045 (if user (setq imap-username user))
1046 (if passwd (setq imap-password passwd))
1048 (and (funcall (nth 2 (assq imap-auth
1049 imap-authenticator-alist)) buffer)
1050 (setq imap-state 'auth))
1051 ;; Choose authenticator.
1052 (let ((auths imap-authenticators)
1054 (while (setq auth (pop auths))
1055 ;; OK to use authenticator?
1056 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) buffer)
1057 (message "imap: Authenticating to `%s' using `%s'..."
1059 (setq imap-auth auth)
1060 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) buffer)
1062 (message "imap: Authenticating to `%s' using `%s'...done"
1065 (message "imap: Authenticating to `%s' using `%s'...failed"
1066 imap-server auth)))))
1069 (defun imap-close (&optional buffer)
1070 "Close connection to server in BUFFER.
1071 If BUFFER is nil, the current buffer is used."
1072 (with-current-buffer (or buffer (current-buffer))
1075 (imap-send-command-wait "LOGOUT")
1077 (when (and imap-process
1078 (memq (process-status imap-process) '(open run)))
1079 (delete-process imap-process))
1080 (setq imap-current-mailbox nil
1081 imap-current-message nil
1086 (defun imap-capability (&optional identifier buffer)
1087 "Return a list of identifiers which server in BUFFER support.
1088 If IDENTIFIER, return non-nil if it's among the servers capabilities.
1089 If BUFFER is nil, the current buffer is assumed."
1090 (with-current-buffer (or buffer (current-buffer))
1091 (unless imap-capability
1092 (unless (imap-ok-p (imap-send-command-wait "CAPABILITY"))
1093 (setq imap-capability '(IMAP2))))
1095 (memq (intern (upcase (symbol-name identifier))) imap-capability)
1098 (defun imap-namespace (&optional buffer)
1099 "Return a namespace hierarchy at server in BUFFER.
1100 If BUFFER is nil, the current buffer is assumed."
1101 (with-current-buffer (or buffer (current-buffer))
1102 (unless imap-namespace
1103 (when (imap-capability 'NAMESPACE)
1104 (imap-send-command-wait "NAMESPACE")))
1107 (defun imap-send-command-wait (command &optional buffer)
1108 (imap-wait-for-tag (imap-send-command command buffer) buffer))
1111 ;; Mailbox functions:
1113 (defun imap-mailbox-put (propname value &optional mailbox buffer)
1114 (with-current-buffer (or buffer (current-buffer))
1115 (if imap-mailbox-data
1116 (put (intern (or mailbox imap-current-mailbox) imap-mailbox-data)
1118 (error "Imap-mailbox-data is nil, prop %s value %s mailbox %s buffer %s"
1119 propname value mailbox (current-buffer)))
1122 (defsubst imap-mailbox-get-1 (propname &optional mailbox)
1123 (get (intern-soft (or mailbox imap-current-mailbox) imap-mailbox-data)
1126 (defun imap-mailbox-get (propname &optional mailbox buffer)
1127 (let ((mailbox (imap-utf7-encode mailbox)))
1128 (with-current-buffer (or buffer (current-buffer))
1129 (imap-mailbox-get-1 propname (or mailbox imap-current-mailbox)))))
1131 (defun imap-mailbox-map-1 (func &optional mailbox-decoder buffer)
1132 (with-current-buffer (or buffer (current-buffer))
1136 (push (funcall func (if mailbox-decoder
1137 (funcall mailbox-decoder (symbol-name s))
1138 (symbol-name s))) result))
1142 (defun imap-mailbox-map (func &optional buffer)
1143 "Map a function across each mailbox in `imap-mailbox-data', returning a list.
1144 Function should take a mailbox name (a string) as
1146 (imap-mailbox-map-1 func 'imap-utf7-decode buffer))
1148 (defun imap-current-mailbox (&optional buffer)
1149 (with-current-buffer (or buffer (current-buffer))
1150 (imap-utf7-decode imap-current-mailbox)))
1152 (defun imap-current-mailbox-p-1 (mailbox &optional examine)
1153 (and (string= mailbox imap-current-mailbox)
1155 (eq imap-state 'examine))
1157 (eq imap-state 'selected)))))
1159 (defun imap-current-mailbox-p (mailbox &optional examine buffer)
1160 (with-current-buffer (or buffer (current-buffer))
1161 (imap-current-mailbox-p-1 (imap-utf7-encode mailbox) examine)))
1163 (defun imap-mailbox-select-1 (mailbox &optional examine)
1164 "Select MAILBOX on server in BUFFER.
1165 If EXAMINE is non-nil, do a read-only select."
1166 (if (imap-current-mailbox-p-1 mailbox examine)
1167 imap-current-mailbox
1168 (setq imap-current-mailbox mailbox)
1169 (if (imap-ok-p (imap-send-command-wait
1170 (concat (if examine "EXAMINE" "SELECT") " \""
1173 (setq imap-message-data (make-vector imap-message-prime 0)
1174 imap-state (if examine 'examine 'selected))
1175 imap-current-mailbox)
1176 ;; Failed SELECT/EXAMINE unselects current mailbox
1177 (setq imap-current-mailbox nil))))
1179 (defun imap-mailbox-select (mailbox &optional examine buffer)
1180 (with-current-buffer (or buffer (current-buffer))
1182 (imap-mailbox-select-1 (imap-utf7-encode mailbox) examine))))
1184 (defun imap-mailbox-examine-1 (mailbox &optional buffer)
1185 (with-current-buffer (or buffer (current-buffer))
1186 (imap-mailbox-select-1 mailbox 'examine)))
1188 (defun imap-mailbox-examine (mailbox &optional buffer)
1189 "Examine MAILBOX on server in BUFFER."
1190 (imap-mailbox-select mailbox 'examine buffer))
1192 (defun imap-mailbox-unselect (&optional buffer)
1193 "Close current folder in BUFFER, without expunging articles."
1194 (with-current-buffer (or buffer (current-buffer))
1195 (when (or (eq imap-state 'auth)
1196 (and (imap-capability 'UNSELECT)
1197 (imap-ok-p (imap-send-command-wait "UNSELECT")))
1199 (imap-send-command-wait (concat "EXAMINE \""
1200 imap-current-mailbox
1202 (imap-ok-p (imap-send-command-wait "CLOSE"))))
1203 (setq imap-current-mailbox nil
1204 imap-message-data nil
1208 (defun imap-mailbox-expunge (&optional asynch buffer)
1209 "Expunge articles in current folder in BUFFER.
1210 If ASYNCH, do not wait for succesful completion of the command.
1211 If BUFFER is nil the current buffer is assumed."
1212 (with-current-buffer (or buffer (current-buffer))
1213 (when (and imap-current-mailbox (not (eq imap-state 'examine)))
1215 (imap-send-command "EXPUNGE")
1216 (imap-ok-p (imap-send-command-wait "EXPUNGE"))))))
1218 (defun imap-mailbox-close (&optional asynch buffer)
1219 "Expunge articles and close current folder in BUFFER.
1220 If ASYNCH, do not wait for succesful completion of the command.
1221 If BUFFER is nil the current buffer is assumed."
1222 (with-current-buffer (or buffer (current-buffer))
1223 (when imap-current-mailbox
1225 (imap-add-callback (imap-send-command "CLOSE")
1226 `(lambda (tag status)
1227 (message "IMAP mailbox `%s' closed... %s"
1228 imap-current-mailbox status)
1229 (when (eq ,imap-current-mailbox
1230 imap-current-mailbox)
1231 ;; Don't wipe out data if another mailbox
1233 (setq imap-current-mailbox nil
1234 imap-message-data nil
1235 imap-state 'auth))))
1236 (when (imap-ok-p (imap-send-command-wait "CLOSE"))
1237 (setq imap-current-mailbox nil
1238 imap-message-data nil
1242 (defun imap-mailbox-create-1 (mailbox)
1243 (imap-ok-p (imap-send-command-wait (list "CREATE \"" mailbox "\""))))
1245 (defun imap-mailbox-create (mailbox &optional buffer)
1246 "Create MAILBOX on server in BUFFER.
1247 If BUFFER is nil the current buffer is assumed."
1248 (with-current-buffer (or buffer (current-buffer))
1249 (imap-mailbox-create-1 (imap-utf7-encode mailbox))))
1251 (defun imap-mailbox-delete (mailbox &optional buffer)
1252 "Delete MAILBOX on server in BUFFER.
1253 If BUFFER is nil the current buffer is assumed."
1254 (let ((mailbox (imap-utf7-encode mailbox)))
1255 (with-current-buffer (or buffer (current-buffer))
1257 (imap-send-command-wait (list "DELETE \"" mailbox "\""))))))
1259 (defun imap-mailbox-rename (oldname newname &optional buffer)
1260 "Rename mailbox OLDNAME to NEWNAME on server in BUFFER.
1261 If BUFFER is nil the current buffer is assumed."
1262 (let ((oldname (imap-utf7-encode oldname))
1263 (newname (imap-utf7-encode newname)))
1264 (with-current-buffer (or buffer (current-buffer))
1266 (imap-send-command-wait (list "RENAME \"" oldname "\" "
1267 "\"" newname "\""))))))
1269 (defun imap-mailbox-lsub (&optional root reference add-delimiter buffer)
1270 "Return a list of subscribed mailboxes on server in BUFFER.
1271 If ROOT is non-nil, only list matching mailboxes. If ADD-DELIMITER is
1272 non-nil, a hierarchy delimiter is added to root. REFERENCE is a
1273 implementation-specific string that has to be passed to lsub command."
1274 (with-current-buffer (or buffer (current-buffer))
1275 ;; Make sure we know the hierarchy separator for root's hierarchy
1276 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1277 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1278 (imap-utf7-encode root) "\"")))
1279 ;; clear list data (NB not delimiter and other stuff)
1280 (imap-mailbox-map-1 (lambda (mailbox)
1281 (imap-mailbox-put 'lsub nil mailbox)))
1283 (imap-send-command-wait
1284 (concat "LSUB \"" reference "\" \"" (imap-utf7-encode root)
1285 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1288 (imap-mailbox-map-1 (lambda (mailbox)
1289 (when (imap-mailbox-get-1 'lsub mailbox)
1290 (push (imap-utf7-decode mailbox) out))))
1293 (defun imap-mailbox-list (root &optional reference add-delimiter buffer)
1294 "Return a list of mailboxes matching ROOT on server in BUFFER.
1295 If ADD-DELIMITER is non-nil, a hierarchy delimiter is added to
1296 root. REFERENCE is a implementation-specific string that has to be
1297 passed to list command."
1298 (with-current-buffer (or buffer (current-buffer))
1299 ;; Make sure we know the hierarchy separator for root's hierarchy
1300 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1301 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1302 (imap-utf7-encode root) "\"")))
1303 ;; clear list data (NB not delimiter and other stuff)
1304 (imap-mailbox-map-1 (lambda (mailbox)
1305 (imap-mailbox-put 'list nil mailbox)))
1307 (imap-send-command-wait
1308 (concat "LIST \"" reference "\" \"" (imap-utf7-encode root)
1309 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1312 (imap-mailbox-map-1 (lambda (mailbox)
1313 (when (imap-mailbox-get-1 'list mailbox)
1314 (push (imap-utf7-decode mailbox) out))))
1317 (defun imap-mailbox-subscribe (mailbox &optional buffer)
1318 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1319 Returns non-nil if successful."
1320 (with-current-buffer (or buffer (current-buffer))
1321 (imap-ok-p (imap-send-command-wait (concat "SUBSCRIBE \""
1322 (imap-utf7-encode mailbox)
1325 (defun imap-mailbox-unsubscribe (mailbox &optional buffer)
1326 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1327 Returns non-nil if successful."
1328 (with-current-buffer (or buffer (current-buffer))
1329 (imap-ok-p (imap-send-command-wait (concat "UNSUBSCRIBE "
1330 (imap-utf7-encode mailbox)
1333 (defun imap-mailbox-status (mailbox items &optional buffer)
1334 "Get status items ITEM in MAILBOX from server in BUFFER.
1335 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1336 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1337 or 'unseen. If ITEMS is a list of symbols, a list of values is
1338 returned, if ITEMS is a symbol only its value is returned."
1339 (with-current-buffer (or buffer (current-buffer))
1341 (imap-send-command-wait (list "STATUS \""
1342 (imap-utf7-encode mailbox)
1350 (mapcar (lambda (item)
1351 (imap-mailbox-get item mailbox))
1353 (imap-mailbox-get items mailbox)))))
1355 (defun imap-mailbox-status-asynch (mailbox items &optional buffer)
1356 "Send status item request ITEM on MAILBOX to server in BUFFER.
1357 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1358 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1359 or 'unseen. The IMAP command tag is returned."
1360 (with-current-buffer (or buffer (current-buffer))
1361 (imap-send-command (list "STATUS \""
1362 (imap-utf7-encode mailbox)
1369 (defun imap-mailbox-acl-get (&optional mailbox buffer)
1370 "Get ACL on mailbox from server in BUFFER."
1371 (let ((mailbox (imap-utf7-encode mailbox)))
1372 (with-current-buffer (or buffer (current-buffer))
1374 (imap-send-command-wait (list "GETACL \""
1375 (or mailbox imap-current-mailbox)
1377 (imap-mailbox-get-1 'acl (or mailbox imap-current-mailbox))))))
1379 (defun imap-mailbox-acl-set (identifier rights &optional mailbox buffer)
1380 "Change/set ACL for IDENTIFIER to RIGHTS in MAILBOX from server in BUFFER."
1381 (let ((mailbox (imap-utf7-encode mailbox)))
1382 (with-current-buffer (or buffer (current-buffer))
1384 (imap-send-command-wait (list "SETACL \""
1385 (or mailbox imap-current-mailbox)
1391 (defun imap-mailbox-acl-delete (identifier &optional mailbox buffer)
1392 "Removes any <identifier,rights> pair for IDENTIFIER in MAILBOX from server in BUFFER."
1393 (let ((mailbox (imap-utf7-encode mailbox)))
1394 (with-current-buffer (or buffer (current-buffer))
1396 (imap-send-command-wait (list "DELETEACL \""
1397 (or mailbox imap-current-mailbox)
1402 ;; Message functions:
1404 (defun imap-current-message (&optional buffer)
1405 (with-current-buffer (or buffer (current-buffer))
1406 imap-current-message))
1408 (defun imap-list-to-message-set (list)
1409 (mapconcat (lambda (item)
1410 (number-to-string item))
1416 (defun imap-range-to-message-set (range)
1421 (car item) (cdr item))
1422 (format "%d" item)))
1423 (if (and (listp range) (not (listp (cdr range))))
1424 (list range) ;; make (1 . 2) into ((1 . 2))
1428 (defun imap-fetch-asynch (uids props &optional nouidfetch buffer)
1429 (with-current-buffer (or buffer (current-buffer))
1430 (imap-send-command (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1432 (imap-list-to-message-set uids)
1436 (defun imap-fetch (uids props &optional receive nouidfetch buffer)
1437 "Fetch properties PROPS from message set UIDS from server in BUFFER.
1438 UIDS can be a string, number or a list of numbers. If RECEIVE
1439 is non-nil return theese properties."
1440 (with-current-buffer (or buffer (current-buffer))
1441 (when (imap-ok-p (imap-send-command-wait
1442 (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1444 (imap-list-to-message-set uids)
1447 (if (or (null receive) (stringp uids))
1450 (mapcar (lambda (uid)
1452 (mapcar (lambda (prop)
1453 (imap-message-get uid prop))
1455 (imap-message-get uid receive)))
1457 (imap-message-get uids receive))))))
1459 (defun imap-message-put (uid propname value &optional buffer)
1460 (with-current-buffer (or buffer (current-buffer))
1461 (if imap-message-data
1462 (put (intern (number-to-string uid) imap-message-data)
1464 (error "Imap-message-data is nil, uid %s prop %s value %s buffer %s"
1465 uid propname value (current-buffer)))
1468 (defun imap-message-get (uid propname &optional buffer)
1469 (with-current-buffer (or buffer (current-buffer))
1470 (get (intern-soft (number-to-string uid) imap-message-data)
1473 (defun imap-message-map (func propname &optional buffer)
1474 "Map a function across each mailbox in `imap-message-data', returning a list."
1475 (with-current-buffer (or buffer (current-buffer))
1479 (push (funcall func (get s 'UID) (get s propname)) result))
1483 (defmacro imap-message-envelope-date (uid &optional buffer)
1484 `(with-current-buffer (or ,buffer (current-buffer))
1485 (elt (imap-message-get ,uid 'ENVELOPE) 0)))
1487 (defmacro imap-message-envelope-subject (uid &optional buffer)
1488 `(with-current-buffer (or ,buffer (current-buffer))
1489 (elt (imap-message-get ,uid 'ENVELOPE) 1)))
1491 (defmacro imap-message-envelope-from (uid &optional buffer)
1492 `(with-current-buffer (or ,buffer (current-buffer))
1493 (elt (imap-message-get ,uid 'ENVELOPE) 2)))
1495 (defmacro imap-message-envelope-sender (uid &optional buffer)
1496 `(with-current-buffer (or ,buffer (current-buffer))
1497 (elt (imap-message-get ,uid 'ENVELOPE) 3)))
1499 (defmacro imap-message-envelope-reply-to (uid &optional buffer)
1500 `(with-current-buffer (or ,buffer (current-buffer))
1501 (elt (imap-message-get ,uid 'ENVELOPE) 4)))
1503 (defmacro imap-message-envelope-to (uid &optional buffer)
1504 `(with-current-buffer (or ,buffer (current-buffer))
1505 (elt (imap-message-get ,uid 'ENVELOPE) 5)))
1507 (defmacro imap-message-envelope-cc (uid &optional buffer)
1508 `(with-current-buffer (or ,buffer (current-buffer))
1509 (elt (imap-message-get ,uid 'ENVELOPE) 6)))
1511 (defmacro imap-message-envelope-bcc (uid &optional buffer)
1512 `(with-current-buffer (or ,buffer (current-buffer))
1513 (elt (imap-message-get ,uid 'ENVELOPE) 7)))
1515 (defmacro imap-message-envelope-in-reply-to (uid &optional buffer)
1516 `(with-current-buffer (or ,buffer (current-buffer))
1517 (elt (imap-message-get ,uid 'ENVELOPE) 8)))
1519 (defmacro imap-message-envelope-message-id (uid &optional buffer)
1520 `(with-current-buffer (or ,buffer (current-buffer))
1521 (elt (imap-message-get ,uid 'ENVELOPE) 9)))
1523 (defmacro imap-message-body (uid &optional buffer)
1524 `(with-current-buffer (or ,buffer (current-buffer))
1525 (imap-message-get ,uid 'BODY)))
1527 (defun imap-search (predicate &optional buffer)
1528 (with-current-buffer (or buffer (current-buffer))
1529 (imap-mailbox-put 'search 'dummy)
1530 (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate)))
1531 (if (eq (imap-mailbox-get-1 'search imap-current-mailbox) 'dummy)
1533 (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...")
1535 (imap-mailbox-get-1 'search imap-current-mailbox)))))
1537 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer)
1538 "Return t iff FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER."
1539 (with-current-buffer (or buffer (current-buffer))
1540 (or (member "\\*" (imap-mailbox-get 'permanentflags mailbox))
1541 (member flag (imap-mailbox-get 'permanentflags mailbox)))))
1543 (defun imap-message-flags-set (articles flags &optional silent buffer)
1544 (when (and articles flags)
1545 (with-current-buffer (or buffer (current-buffer))
1546 (imap-ok-p (imap-send-command-wait
1547 (concat "UID STORE " articles
1548 " FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1550 (defun imap-message-flags-del (articles flags &optional silent buffer)
1551 (when (and articles flags)
1552 (with-current-buffer (or buffer (current-buffer))
1553 (imap-ok-p (imap-send-command-wait
1554 (concat "UID STORE " articles
1555 " -FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1557 (defun imap-message-flags-add (articles flags &optional silent buffer)
1558 (when (and articles flags)
1559 (with-current-buffer (or buffer (current-buffer))
1560 (imap-ok-p (imap-send-command-wait
1561 (concat "UID STORE " articles
1562 " +FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1564 (defun imap-message-copyuid-1 (mailbox)
1565 (if (imap-capability 'UIDPLUS)
1566 (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox))
1567 (string-to-number (nth 2 (imap-mailbox-get-1 'copyuid mailbox))))
1568 (let ((old-mailbox imap-current-mailbox)
1570 (imap-message-data (make-vector 2 0)))
1571 (when (imap-mailbox-examine-1 mailbox)
1573 (and (imap-fetch "*" "UID")
1574 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1575 (apply 'max (imap-message-map
1576 (lambda (uid prop) uid) 'UID))))
1578 (imap-mailbox-select old-mailbox (eq state 'examine))
1579 (imap-mailbox-unselect)))))))
1581 (defun imap-message-copyuid (mailbox &optional buffer)
1582 (with-current-buffer (or buffer (current-buffer))
1583 (imap-message-copyuid-1 (imap-utf7-decode mailbox))))
1585 (defun imap-message-copy (articles mailbox
1586 &optional dont-create no-copyuid buffer)
1587 "Copy ARTICLES (a string message set) to MAILBOX on server in
1588 BUFFER, creating mailbox if it doesn't exist. If dont-create is
1589 non-nil, it will not create a mailbox. On success, return a list with
1590 the UIDVALIDITY of the mailbox the article(s) was copied to as the
1591 first element, rest of list contain the saved articles' UIDs."
1593 (with-current-buffer (or buffer (current-buffer))
1594 (let ((mailbox (imap-utf7-encode mailbox)))
1595 (if (let ((cmd (concat "UID COPY " articles " \"" mailbox "\""))
1596 (imap-current-target-mailbox mailbox))
1597 (if (imap-ok-p (imap-send-command-wait cmd))
1599 (when (and (not dont-create)
1600 ;; removed because of buggy Oracle server
1601 ;; that doesn't send TRYCREATE tags (which
1602 ;; is a MUST according to specifications):
1603 ;;(imap-mailbox-get-1 'trycreate mailbox)
1604 (imap-mailbox-create-1 mailbox))
1605 (imap-ok-p (imap-send-command-wait cmd)))))
1607 (imap-message-copyuid-1 mailbox)))))))
1609 (defun imap-message-appenduid-1 (mailbox)
1610 (if (imap-capability 'UIDPLUS)
1611 (imap-mailbox-get-1 'appenduid mailbox)
1612 (let ((old-mailbox imap-current-mailbox)
1614 (imap-message-data (make-vector 2 0)))
1615 (when (imap-mailbox-examine-1 mailbox)
1617 (and (imap-fetch "*" "UID")
1618 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1619 (apply 'max (imap-message-map
1620 (lambda (uid prop) uid) 'UID))))
1622 (imap-mailbox-select old-mailbox (eq state 'examine))
1623 (imap-mailbox-unselect)))))))
1625 (defun imap-message-appenduid (mailbox &optional buffer)
1626 (with-current-buffer (or buffer (current-buffer))
1627 (imap-message-appenduid-1 (imap-utf7-encode mailbox))))
1629 (defun imap-message-append (mailbox article &optional flags date-time buffer)
1630 "Append ARTICLE (a buffer) to MAILBOX on server in BUFFER.
1631 FLAGS and DATE-TIME is currently not used. Return a cons holding
1632 uidvalidity of MAILBOX and UID the newly created article got, or nil
1634 (let ((mailbox (imap-utf7-encode mailbox)))
1635 (with-current-buffer (or buffer (current-buffer))
1636 (and (let ((imap-current-target-mailbox mailbox))
1638 (imap-send-command-wait
1639 (list "APPEND \"" mailbox "\" " article))))
1640 (imap-message-appenduid-1 mailbox)))))
1642 (defun imap-body-lines (body)
1643 "Return number of lines in article by looking at the mime bodystructure BODY."
1645 (if (stringp (car body))
1646 (cond ((and (string= (upcase (car body)) "TEXT")
1647 (numberp (nth 7 body)))
1649 ((and (string= (upcase (car body)) "MESSAGE")
1650 (numberp (nth 9 body)))
1653 (apply '+ (mapcar 'imap-body-lines body)))
1656 (defun imap-envelope-from (from)
1657 "Return a from string line."
1659 (concat (aref from 0)
1660 (if (aref from 0) " <")
1664 (if (aref from 0) ">"))))
1667 ;; Internal functions.
1669 (defun imap-add-callback (tag func)
1670 (setq imap-callbacks (append (list (cons tag func)) imap-callbacks)))
1672 (defun imap-send-command-1 (cmdstr)
1673 (setq cmdstr (concat cmdstr imap-client-eol))
1675 (with-current-buffer (get-buffer-create imap-log-buffer)
1676 (imap-disable-multibyte)
1677 (buffer-disable-undo)
1678 (goto-char (point-max))
1680 (process-send-string imap-process cmdstr))
1682 (defun imap-send-command (command &optional buffer)
1683 (with-current-buffer (or buffer (current-buffer))
1684 (if (not (listp command)) (setq command (list command)))
1685 (let ((tag (setq imap-tag (1+ imap-tag)))
1687 (setq cmdstr (concat (number-to-string imap-tag) " "))
1688 (while (setq cmd (pop command))
1689 (cond ((stringp cmd)
1690 (setq cmdstr (concat cmdstr cmd)))
1692 (let ((eol imap-client-eol)
1693 (calcfirst imap-calculate-literal-size-first)
1695 (with-current-buffer cmd
1697 (setq size (buffer-size)))
1698 (when (not (equal eol "\r\n"))
1699 ;; XXX modifies buffer!
1700 (goto-char (point-min))
1701 (while (search-forward "\r\n" nil t)
1702 (replace-match eol)))
1704 (setq size (buffer-size))))
1706 (concat cmdstr (format "{%d}" size))))
1709 (imap-send-command-1 cmdstr)
1711 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1712 (setq command nil) ;; abort command if no cont-req
1713 (let ((process imap-process)
1714 (stream imap-stream)
1715 (eol imap-client-eol))
1716 (with-current-buffer cmd
1718 (with-current-buffer (get-buffer-create
1720 (imap-disable-multibyte)
1721 (buffer-disable-undo)
1722 (goto-char (point-max))
1723 (insert-buffer-substring cmd)))
1724 (process-send-region process (point-min)
1726 (process-send-string process imap-client-eol))))
1727 (setq imap-continuation nil)))
1729 (imap-send-command-1 cmdstr)
1732 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1733 (setq command nil) ;; abort command if no cont-req
1734 (setq command (cons (funcall cmd imap-continuation)
1736 (setq imap-continuation nil)))
1738 (error "Unknown command type"))))
1740 (imap-send-command-1 cmdstr))
1743 (defun imap-wait-for-tag (tag &optional buffer)
1744 (with-current-buffer (or buffer (current-buffer))
1745 (let (imap-have-messaged)
1746 (while (and (null imap-continuation)
1747 (memq (process-status imap-process) '(open run))
1748 (< imap-reached-tag tag))
1749 (let ((len (/ (point-max) 1024))
1752 (setq imap-have-messaged t)
1753 (message "imap read: %dk" len))
1754 (accept-process-output imap-process
1755 (truncate imap-read-timeout)
1756 (truncate (* (- imap-read-timeout
1757 (truncate imap-read-timeout))
1759 ;; A process can die _before_ we have processed everything it
1760 ;; has to say. Moreover, this can happen in between the call to
1761 ;; accept-process-output and the call to process-status in an
1762 ;; iteration of the loop above.
1763 (when (and (null imap-continuation)
1764 (< imap-reached-tag tag))
1765 (accept-process-output imap-process 0 0))
1766 (when imap-have-messaged
1768 (and (memq (process-status imap-process) '(open run))
1769 (or (assq tag imap-failed-tags)
1770 (if imap-continuation
1774 (defun imap-sentinel (process string)
1775 (delete-process process))
1777 (defun imap-find-next-line ()
1778 "Return point at end of current line, taking into account literals.
1779 Return nil if no complete line has arrived."
1780 (when (re-search-forward (concat imap-server-eol "\\|{\\([0-9]+\\)}"
1783 (if (match-string 1)
1784 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1786 (goto-char (+ (point) (string-to-number (match-string 1))))
1787 (imap-find-next-line))
1790 (defun imap-arrival-filter (proc string)
1791 "IMAP process filter."
1792 ;; Sometimes, we are called even though the process has died.
1793 ;; Better abstain from doing stuff in that case.
1794 (when (buffer-name (process-buffer proc))
1795 (with-current-buffer (process-buffer proc)
1796 (goto-char (point-max))
1799 (with-current-buffer (get-buffer-create imap-log-buffer)
1800 (imap-disable-multibyte)
1801 (buffer-disable-undo)
1802 (goto-char (point-max))
1805 (goto-char (point-min))
1806 (while (setq end (imap-find-next-line))
1808 (narrow-to-region (point-min) end)
1809 (delete-backward-char (length imap-server-eol))
1810 (goto-char (point-min))
1812 (cond ((eq imap-state 'initial)
1813 (imap-parse-greeting))
1814 ((or (eq imap-state 'auth)
1815 (eq imap-state 'nonauth)
1816 (eq imap-state 'selected)
1817 (eq imap-state 'examine))
1818 (imap-parse-response))
1820 (message "Unknown state %s in arrival filter"
1822 (delete-region (point-min) (point-max)))))))))
1827 (defsubst imap-forward ()
1828 (or (eobp) (forward-char)))
1831 ;; ; Unsigned 32-bit integer
1832 ;; ; (0 <= n < 4,294,967,296)
1834 (defsubst imap-parse-number ()
1835 (when (looking-at "[0-9]+")
1837 (string-to-number (match-string 0))
1838 (goto-char (match-end 0)))))
1840 ;; literal = "{" number "}" CRLF *CHAR8
1841 ;; ; Number represents the number of CHAR8s
1843 (defsubst imap-parse-literal ()
1844 (when (looking-at "{\\([0-9]+\\)}\r\n")
1845 (let ((pos (match-end 0))
1846 (len (string-to-number (match-string 1))))
1847 (if (< (point-max) (+ pos len))
1849 (goto-char (+ pos len))
1850 (buffer-substring pos (+ pos len))))))
1852 ;; string = quoted / literal
1854 ;; quoted = DQUOTE *QUOTED-CHAR DQUOTE
1856 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
1857 ;; "\" quoted-specials
1859 ;; quoted-specials = DQUOTE / "\"
1861 ;; TEXT-CHAR = <any CHAR except CR and LF>
1863 (defsubst imap-parse-string ()
1864 (cond ((eq (char-after) ?\")
1866 (let ((p (point)) (name ""))
1867 (skip-chars-forward "^\"\\\\")
1868 (setq name (buffer-substring p (point)))
1869 (while (eq (char-after) ?\\)
1870 (setq p (1+ (point)))
1872 (skip-chars-forward "^\"\\\\")
1873 (setq name (concat name (buffer-substring p (point)))))
1876 ((eq (char-after) ?{)
1877 (imap-parse-literal))))
1881 (defsubst imap-parse-nil ()
1882 (if (looking-at "NIL")
1883 (goto-char (match-end 0))))
1885 ;; nstring = string / nil
1887 (defsubst imap-parse-nstring ()
1888 (or (imap-parse-string)
1889 (and (imap-parse-nil)
1892 ;; astring = atom / string
1894 ;; atom = 1*ATOM-CHAR
1896 ;; ATOM-CHAR = <any CHAR except atom-specials>
1898 ;; atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
1901 ;; list-wildcards = "%" / "*"
1903 ;; quoted-specials = DQUOTE / "\"
1905 (defsubst imap-parse-astring ()
1906 (or (imap-parse-string)
1907 (buffer-substring (point)
1908 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1909 (goto-char (1- (match-end 0)))
1913 ;; address = "(" addr-name SP addr-adl SP addr-mailbox SP
1916 ;; addr-adl = nstring
1917 ;; ; Holds route from [RFC-822] route-addr if
1920 ;; addr-host = nstring
1921 ;; ; nil indicates [RFC-822] group syntax.
1922 ;; ; Otherwise, holds [RFC-822] domain name
1924 ;; addr-mailbox = nstring
1925 ;; ; nil indicates end of [RFC-822] group; if
1926 ;; ; non-nil and addr-host is nil, holds
1927 ;; ; [RFC-822] group name.
1928 ;; ; Otherwise, holds [RFC-822] local-part
1929 ;; ; after removing [RFC-822] quoting
1931 ;; addr-name = nstring
1932 ;; ; If non-nil, holds phrase from [RFC-822]
1933 ;; ; mailbox after removing [RFC-822] quoting
1936 (defsubst imap-parse-address ()
1938 (when (eq (char-after) ?\()
1940 (setq address (vector (prog1 (imap-parse-nstring)
1942 (prog1 (imap-parse-nstring)
1944 (prog1 (imap-parse-nstring)
1946 (imap-parse-nstring)))
1947 (when (eq (char-after) ?\))
1951 ;; address-list = "(" 1*address ")" / nil
1955 (defsubst imap-parse-address-list ()
1956 (if (eq (char-after) ?\()
1957 (let (address addresses)
1959 (while (and (not (eq (char-after) ?\)))
1960 ;; next line for MS Exchange bug
1961 (progn (and (eq (char-after) ? ) (imap-forward)) t)
1962 (setq address (imap-parse-address)))
1963 (setq addresses (cons address addresses)))
1964 (when (eq (char-after) ?\))
1966 (nreverse addresses)))
1967 (assert (imap-parse-nil) t "In imap-parse-address-list")))
1969 ;; mailbox = "INBOX" / astring
1970 ;; ; INBOX is case-insensitive. All case variants of
1971 ;; ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
1972 ;; ; not as an astring. An astring which consists of
1973 ;; ; the case-insensitive sequence "I" "N" "B" "O" "X"
1974 ;; ; is considered to be INBOX and not an astring.
1975 ;; ; Refer to section 5.1 for further
1976 ;; ; semantic details of mailbox names.
1978 (defsubst imap-parse-mailbox ()
1979 (let ((mailbox (imap-parse-astring)))
1980 (if (string-equal "INBOX" (upcase mailbox))
1984 ;; greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
1986 ;; resp-cond-auth = ("OK" / "PREAUTH") SP resp-text
1987 ;; ; Authentication condition
1989 ;; resp-cond-bye = "BYE" SP resp-text
1991 (defun imap-parse-greeting ()
1992 "Parse a IMAP greeting."
1993 (cond ((looking-at "\\* OK ")
1994 (setq imap-state 'nonauth))
1995 ((looking-at "\\* PREAUTH ")
1996 (setq imap-state 'auth))
1997 ((looking-at "\\* BYE ")
1998 (setq imap-state 'closed))))
2000 ;; response = *(continue-req / response-data) response-done
2002 ;; continue-req = "+" SP (resp-text / base64) CRLF
2004 ;; response-data = "*" SP (resp-cond-state / resp-cond-bye /
2005 ;; mailbox-data / message-data / capability-data) CRLF
2007 ;; response-done = response-tagged / response-fatal
2009 ;; response-fatal = "*" SP resp-cond-bye CRLF
2010 ;; ; Server closes connection immediately
2012 ;; response-tagged = tag SP resp-cond-state CRLF
2014 ;; resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
2015 ;; ; Status condition
2017 ;; resp-cond-bye = "BYE" SP resp-text
2019 ;; mailbox-data = "FLAGS" SP flag-list /
2020 ;; "LIST" SP mailbox-list /
2021 ;; "LSUB" SP mailbox-list /
2022 ;; "SEARCH" *(SP nz-number) /
2023 ;; "STATUS" SP mailbox SP "("
2024 ;; [status-att SP number *(SP status-att SP number)] ")" /
2025 ;; number SP "EXISTS" /
2026 ;; number SP "RECENT"
2028 ;; message-data = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att))
2030 ;; capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
2032 ;; ; IMAP4rev1 servers which offer RFC 1730
2033 ;; ; compatibility MUST list "IMAP4" as the first
2036 (defun imap-parse-response ()
2037 "Parse a IMAP command response."
2039 (case (setq token (read (current-buffer)))
2040 (+ (setq imap-continuation
2041 (or (buffer-substring (min (point-max) (1+ (point)))
2044 (* (case (prog1 (setq token (read (current-buffer)))
2046 (OK (imap-parse-resp-text))
2047 (NO (imap-parse-resp-text))
2048 (BAD (imap-parse-resp-text))
2049 (BYE (imap-parse-resp-text))
2050 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list)))
2051 (LIST (imap-parse-data-list 'list))
2052 (LSUB (imap-parse-data-list 'lsub))
2053 (SEARCH (imap-mailbox-put
2055 (read (concat "(" (buffer-substring (point) (point-max)) ")"))))
2056 (STATUS (imap-parse-status))
2057 (CAPABILITY (setq imap-capability
2058 (read (concat "(" (upcase (buffer-substring
2059 (point) (point-max)))
2061 (ACL (imap-parse-acl))
2062 (t (case (prog1 (read (current-buffer))
2064 (EXISTS (imap-mailbox-put 'exists token))
2065 (RECENT (imap-mailbox-put 'recent token))
2067 (FETCH (imap-parse-fetch token))
2068 (t (message "Garbage: %s" (buffer-string)))))))
2070 (if (not (integerp token))
2071 (message "Garbage: %s" (buffer-string))
2072 (case (prog1 (setq status (read (current-buffer)))
2075 (setq imap-reached-tag (max imap-reached-tag token))
2076 (imap-parse-resp-text)))
2078 (setq imap-reached-tag (max imap-reached-tag token))
2080 (imap-parse-resp-text))
2082 (when (eq (char-after) ?\[)
2083 (setq code (buffer-substring (point)
2084 (search-forward "]")))
2086 (setq text (buffer-substring (point) (point-max)))
2087 (push (list token status code text)
2088 imap-failed-tags))))
2090 (setq imap-reached-tag (max imap-reached-tag token))
2092 (imap-parse-resp-text))
2094 (when (eq (char-after) ?\[)
2095 (setq code (buffer-substring (point)
2096 (search-forward "]")))
2098 (setq text (buffer-substring (point) (point-max)))
2099 (push (list token status code text) imap-failed-tags)
2100 (error "Internal error, tag %s status %s code %s text %s"
2101 token status code text))))
2102 (t (message "Garbage: %s" (buffer-string))))
2103 (when (assq token imap-callbacks)
2104 (funcall (cdr (assq token imap-callbacks)) token status)
2105 (setq imap-callbacks
2106 (imap-remassoc token imap-callbacks)))))))))
2108 ;; resp-text = ["[" resp-text-code "]" SP] text
2110 ;; text = 1*TEXT-CHAR
2112 ;; TEXT-CHAR = <any CHAR except CR and LF>
2114 (defun imap-parse-resp-text ()
2115 (imap-parse-resp-text-code))
2117 ;; resp-text-code = "ALERT" /
2118 ;; "BADCHARSET [SP "(" astring *(SP astring) ")" ] /
2119 ;; "NEWNAME" SP string SP string /
2121 ;; "PERMANENTFLAGS" SP "("
2122 ;; [flag-perm *(SP flag-perm)] ")" /
2126 ;; "UIDNEXT" SP nz-number /
2127 ;; "UIDVALIDITY" SP nz-number /
2128 ;; "UNSEEN" SP nz-number /
2129 ;; resp-text-atom [SP 1*<any TEXT-CHAR except "]">]
2131 ;; resp_code_apnd = "APPENDUID" SPACE nz_number SPACE uniqueid
2133 ;; resp_code_copy = "COPYUID" SPACE nz_number SPACE set SPACE set
2135 ;; set = sequence-num / (sequence-num ":" sequence-num) /
2137 ;; ; Identifies a set of messages. For message
2138 ;; ; sequence numbers, these are consecutive
2139 ;; ; numbers from 1 to the number of messages in
2141 ;; ; Comma delimits individual numbers, colon
2142 ;; ; delimits between two numbers inclusive.
2143 ;; ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13,
2144 ;; ; 14,15 for a mailbox with 15 messages.
2146 ;; sequence-num = nz-number / "*"
2147 ;; ; * is the largest number in use. For message
2148 ;; ; sequence numbers, it is the number of messages
2149 ;; ; in the mailbox. For unique identifiers, it is
2150 ;; ; the unique identifier of the last message in
2153 ;; flag-perm = flag / "\*"
2155 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2156 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2157 ;; ; Does not include "\Recent"
2159 ;; flag-extension = "\" atom
2160 ;; ; Future expansion. Client implementations
2161 ;; ; MUST accept flag-extension flags. Server
2162 ;; ; implementations MUST NOT generate
2163 ;; ; flag-extension flags except as defined by
2164 ;; ; future standard or standards-track
2165 ;; ; revisions of this specification.
2167 ;; flag-keyword = atom
2169 ;; resp-text-atom = 1*<any ATOM-CHAR except "]">
2171 (defun imap-parse-resp-text-code ()
2172 ;; xxx next line for stalker communigate pro 3.3.1 bug
2173 (when (looking-at " \\[")
2175 (when (eq (char-after) ?\[)
2177 (cond ((search-forward "PERMANENTFLAGS " nil t)
2178 (imap-mailbox-put 'permanentflags (imap-parse-flag-list)))
2179 ((search-forward "UIDNEXT \\([0-9]+\\)" nil t)
2180 (imap-mailbox-put 'uidnext (match-string 1)))
2181 ((search-forward "UNSEEN " nil t)
2182 (imap-mailbox-put 'first-unseen (read (current-buffer))))
2183 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
2184 (imap-mailbox-put 'uidvalidity (match-string 1)))
2185 ((search-forward "READ-ONLY" nil t)
2186 (imap-mailbox-put 'read-only t))
2187 ((search-forward "NEWNAME " nil t)
2188 (let (oldname newname)
2189 (setq oldname (imap-parse-string))
2191 (setq newname (imap-parse-string))
2192 (imap-mailbox-put 'newname newname oldname)))
2193 ((search-forward "TRYCREATE" nil t)
2194 (imap-mailbox-put 'trycreate t imap-current-target-mailbox))
2195 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
2196 (imap-mailbox-put 'appenduid
2197 (list (match-string 1)
2198 (string-to-number (match-string 2)))
2199 imap-current-target-mailbox))
2200 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
2201 (imap-mailbox-put 'copyuid (list (match-string 1)
2204 imap-current-target-mailbox))
2205 ((search-forward "ALERT] " nil t)
2206 (message "Imap server %s information: %s" imap-server
2207 (buffer-substring (point) (point-max)))))))
2209 ;; mailbox-list = "(" [mbx-list-flags] ")" SP
2210 ;; (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox
2212 ;; mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag
2213 ;; *(SP mbx-list-oflag) /
2214 ;; mbx-list-oflag *(SP mbx-list-oflag)
2216 ;; mbx-list-oflag = "\Noinferiors" / flag-extension
2217 ;; ; Other flags; multiple possible per LIST response
2219 ;; mbx-list-sflag = "\Noselect" / "\Marked" / "\Unmarked"
2220 ;; ; Selectability flags; only one per LIST response
2222 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
2223 ;; "\" quoted-specials
2225 ;; quoted-specials = DQUOTE / "\"
2227 (defun imap-parse-data-list (type)
2228 (let (flags delimiter mailbox)
2229 (setq flags (imap-parse-flag-list))
2230 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
2231 (setq delimiter (match-string 1))
2232 (goto-char (1+ (match-end 0)))
2233 (when (setq mailbox (imap-parse-mailbox))
2234 (imap-mailbox-put type t mailbox)
2235 (imap-mailbox-put 'list-flags flags mailbox)
2236 (imap-mailbox-put 'delimiter delimiter mailbox)))))
2238 ;; msg_att ::= "(" 1#("ENVELOPE" SPACE envelope /
2239 ;; "FLAGS" SPACE "(" #(flag / "\Recent") ")" /
2240 ;; "INTERNALDATE" SPACE date_time /
2241 ;; "RFC822" [".HEADER" / ".TEXT"] SPACE nstring /
2242 ;; "RFC822.SIZE" SPACE number /
2243 ;; "BODY" ["STRUCTURE"] SPACE body /
2244 ;; "BODY" section ["<" number ">"] SPACE nstring /
2245 ;; "UID" SPACE uniqueid) ")"
2247 ;; date_time ::= <"> date_day_fixed "-" date_month "-" date_year
2248 ;; SPACE time SPACE zone <">
2250 ;; section ::= "[" [section_text / (nz_number *["." nz_number]
2251 ;; ["." (section_text / "MIME")])] "]"
2253 ;; section_text ::= "HEADER" / "HEADER.FIELDS" [".NOT"]
2254 ;; SPACE header_list / "TEXT"
2256 ;; header_fld_name ::= astring
2258 ;; header_list ::= "(" 1#header_fld_name ")"
2260 (defsubst imap-parse-header-list ()
2261 (when (eq (char-after) ?\()
2263 (while (not (eq (char-after) ?\)))
2265 (push (imap-parse-astring) strlist))
2267 (nreverse strlist))))
2269 (defsubst imap-parse-fetch-body-section ()
2271 (buffer-substring (point) (1- (re-search-forward "[] ]" nil t)))))
2272 (if (eq (char-before) ? )
2274 (mapconcat 'identity (cons section (imap-parse-header-list)) " ")
2275 (search-forward "]" nil t))
2278 (defun imap-parse-fetch (response)
2279 (when (eq (char-after) ?\()
2280 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text
2281 rfc822size body bodydetail bodystructure flags-empty)
2282 (while (not (eq (char-after) ?\)))
2284 (let ((token (read (current-buffer))))
2286 (cond ((eq token 'UID)
2287 (setq uid (condition-case ()
2288 (read (current-buffer))
2291 (setq flags (imap-parse-flag-list))
2293 (setq flags-empty 't)))
2294 ((eq token 'ENVELOPE)
2295 (setq envelope (imap-parse-envelope)))
2296 ((eq token 'INTERNALDATE)
2297 (setq internaldate (imap-parse-string)))
2299 (setq rfc822 (imap-parse-nstring)))
2300 ((eq token 'RFC822.HEADER)
2301 (setq rfc822header (imap-parse-nstring)))
2302 ((eq token 'RFC822.TEXT)
2303 (setq rfc822text (imap-parse-nstring)))
2304 ((eq token 'RFC822.SIZE)
2305 (setq rfc822size (read (current-buffer))))
2307 (if (eq (char-before) ?\[)
2309 (upcase (imap-parse-fetch-body-section))
2310 (and (eq (char-after) ?<)
2311 (buffer-substring (1+ (point))
2312 (search-forward ">" nil t)))
2313 (progn (imap-forward)
2314 (imap-parse-nstring)))
2316 (setq body (imap-parse-body))))
2317 ((eq token 'BODYSTRUCTURE)
2318 (setq bodystructure (imap-parse-body))))))
2320 (setq imap-current-message uid)
2321 (imap-message-put uid 'UID uid)
2322 (and (or flags flags-empty) (imap-message-put uid 'FLAGS flags))
2323 (and envelope (imap-message-put uid 'ENVELOPE envelope))
2324 (and internaldate (imap-message-put uid 'INTERNALDATE internaldate))
2325 (and rfc822 (imap-message-put uid 'RFC822 rfc822))
2326 (and rfc822header (imap-message-put uid 'RFC822.HEADER rfc822header))
2327 (and rfc822text (imap-message-put uid 'RFC822.TEXT rfc822text))
2328 (and rfc822size (imap-message-put uid 'RFC822.SIZE rfc822size))
2329 (and body (imap-message-put uid 'BODY body))
2330 (and bodydetail (imap-message-put uid 'BODYDETAIL bodydetail))
2331 (and bodystructure (imap-message-put uid 'BODYSTRUCTURE bodystructure))
2332 (run-hooks 'imap-fetch-data-hook)))))
2334 ;; mailbox-data = ...
2335 ;; "STATUS" SP mailbox SP "("
2336 ;; [status-att SP number
2337 ;; *(SP status-att SP number)] ")"
2340 ;; status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" /
2343 (defun imap-parse-status ()
2344 (let ((mailbox (imap-parse-mailbox)))
2345 (if (eq (char-after) ? )
2347 (when (and mailbox (eq (char-after) ?\())
2348 (while (and (not (eq (char-after) ?\)))
2349 (or (forward-char) t)
2350 (looking-at "\\([A-Za-z]+\\) "))
2351 (let ((token (match-string 1)))
2352 (goto-char (match-end 0))
2353 (cond ((string= token "MESSAGES")
2354 (imap-mailbox-put 'messages (read (current-buffer)) mailbox))
2355 ((string= token "RECENT")
2356 (imap-mailbox-put 'recent (read (current-buffer)) mailbox))
2357 ((string= token "UIDNEXT")
2358 (and (looking-at "[0-9]+")
2359 (imap-mailbox-put 'uidnext (match-string 0) mailbox)
2360 (goto-char (match-end 0))))
2361 ((string= token "UIDVALIDITY")
2362 (and (looking-at "[0-9]+")
2363 (imap-mailbox-put 'uidvalidity (match-string 0) mailbox)
2364 (goto-char (match-end 0))))
2365 ((string= token "UNSEEN")
2366 (imap-mailbox-put 'unseen (read (current-buffer)) mailbox))
2368 (message "Unknown status data %s in mailbox %s ignored"
2370 (read (current-buffer)))))))))
2372 ;; acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE
2375 ;; identifier ::= astring
2377 ;; rights ::= astring
2379 (defun imap-parse-acl ()
2380 (let ((mailbox (imap-parse-mailbox))
2381 identifier rights acl)
2382 (while (eq (char-after) ?\ )
2384 (setq identifier (imap-parse-astring))
2386 (setq rights (imap-parse-astring))
2387 (setq acl (append acl (list (cons identifier rights)))))
2388 (imap-mailbox-put 'acl acl mailbox)))
2390 ;; flag-list = "(" [flag *(SP flag)] ")"
2392 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2393 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2394 ;; ; Does not include "\Recent"
2396 ;; flag-keyword = atom
2398 ;; flag-extension = "\" atom
2399 ;; ; Future expansion. Client implementations
2400 ;; ; MUST accept flag-extension flags. Server
2401 ;; ; implementations MUST NOT generate
2402 ;; ; flag-extension flags except as defined by
2403 ;; ; future standard or standards-track
2404 ;; ; revisions of this specification.
2406 (defun imap-parse-flag-list ()
2407 (let (flag-list start)
2408 (assert (eq (char-after) ?\() t "In imap-parse-flag-list")
2409 (while (and (not (eq (char-after) ?\)))
2412 ;; next line for Courier IMAP bug.
2413 (skip-chars-forward " ")
2415 (> (skip-chars-forward "^ )" (imap-point-at-eol)) 0))
2416 (push (buffer-substring start (point)) flag-list))
2417 (assert (eq (char-after) ?\)) t "In imap-parse-flag-list")
2419 (nreverse flag-list)))
2421 ;; envelope = "(" env-date SP env-subject SP env-from SP env-sender SP
2422 ;; env-reply-to SP env-to SP env-cc SP env-bcc SP
2423 ;; env-in-reply-to SP env-message-id ")"
2425 ;; env-bcc = "(" 1*address ")" / nil
2427 ;; env-cc = "(" 1*address ")" / nil
2429 ;; env-date = nstring
2431 ;; env-from = "(" 1*address ")" / nil
2433 ;; env-in-reply-to = nstring
2435 ;; env-message-id = nstring
2437 ;; env-reply-to = "(" 1*address ")" / nil
2439 ;; env-sender = "(" 1*address ")" / nil
2441 ;; env-subject = nstring
2443 ;; env-to = "(" 1*address ")" / nil
2445 (defun imap-parse-envelope ()
2446 (when (eq (char-after) ?\()
2448 (vector (prog1 (imap-parse-nstring) ;; date
2450 (prog1 (imap-parse-nstring) ;; subject
2452 (prog1 (imap-parse-address-list) ;; from
2454 (prog1 (imap-parse-address-list) ;; sender
2456 (prog1 (imap-parse-address-list) ;; reply-to
2458 (prog1 (imap-parse-address-list) ;; to
2460 (prog1 (imap-parse-address-list) ;; cc
2462 (prog1 (imap-parse-address-list) ;; bcc
2464 (prog1 (imap-parse-nstring) ;; in-reply-to
2466 (prog1 (imap-parse-nstring) ;; message-id
2469 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2471 (defsubst imap-parse-string-list ()
2472 (cond ((eq (char-after) ?\() ;; body-fld-param
2475 (while (setq str (imap-parse-string))
2477 ;; buggy stalker communigate pro 3.0 doesn't print SPC
2478 ;; between body-fld-param's sometimes
2479 (or (eq (char-after) ?\")
2481 (nreverse strlist)))
2485 ;; body-extension = nstring / number /
2486 ;; "(" body-extension *(SP body-extension) ")"
2487 ;; ; Future expansion. Client implementations
2488 ;; ; MUST accept body-extension fields. Server
2489 ;; ; implementations MUST NOT generate
2490 ;; ; body-extension fields except as defined by
2491 ;; ; future standard or standards-track
2492 ;; ; revisions of this specification.
2494 (defun imap-parse-body-extension ()
2495 (if (eq (char-after) ?\()
2498 (push (imap-parse-body-extension) b-e)
2499 (while (eq (char-after) ?\ )
2501 (push (imap-parse-body-extension) b-e))
2502 (assert (eq (char-after) ?\)) t "In imap-parse-body-extension")
2505 (or (imap-parse-number)
2506 (imap-parse-nstring))))
2508 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2509 ;; *(SP body-extension)]]
2510 ;; ; MUST NOT be returned on non-extensible
2513 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2514 ;; *(SP body-extension)]]
2515 ;; ; MUST NOT be returned on non-extensible
2518 (defsubst imap-parse-body-ext ()
2520 (when (eq (char-after) ?\ ) ;; body-fld-dsp
2523 (if (eq (char-after) ?\()
2526 (push (imap-parse-string) dsp)
2528 (push (imap-parse-string-list) dsp)
2530 (assert (imap-parse-nil) t "In imap-parse-body-ext"))
2531 (push (nreverse dsp) ext))
2532 (when (eq (char-after) ?\ ) ;; body-fld-lang
2534 (if (eq (char-after) ?\()
2535 (push (imap-parse-string-list) ext)
2536 (push (imap-parse-nstring) ext))
2537 (while (eq (char-after) ?\ ) ;; body-extension
2539 (setq ext (append (imap-parse-body-extension) ext)))))
2542 ;; body = "(" body-type-1part / body-type-mpart ")"
2544 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2545 ;; *(SP body-extension)]]
2546 ;; ; MUST NOT be returned on non-extensible
2549 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2550 ;; *(SP body-extension)]]
2551 ;; ; MUST NOT be returned on non-extensible
2554 ;; body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP
2555 ;; body-fld-enc SP body-fld-octets
2557 ;; body-fld-desc = nstring
2559 ;; body-fld-dsp = "(" string SP body-fld-param ")" / nil
2561 ;; body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
2562 ;; "QUOTED-PRINTABLE") DQUOTE) / string
2564 ;; body-fld-id = nstring
2566 ;; body-fld-lang = nstring / "(" string *(SP string) ")"
2568 ;; body-fld-lines = number
2570 ;; body-fld-md5 = nstring
2572 ;; body-fld-octets = number
2574 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2576 ;; body-type-1part = (body-type-basic / body-type-msg / body-type-text)
2577 ;; [SP body-ext-1part]
2579 ;; body-type-basic = media-basic SP body-fields
2580 ;; ; MESSAGE subtype MUST NOT be "RFC822"
2582 ;; body-type-msg = media-message SP body-fields SP envelope
2583 ;; SP body SP body-fld-lines
2585 ;; body-type-text = media-text SP body-fields SP body-fld-lines
2587 ;; body-type-mpart = 1*body SP media-subtype
2588 ;; [SP body-ext-mpart]
2590 ;; media-basic = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" /
2591 ;; "MESSAGE" / "VIDEO") DQUOTE) / string) SP media-subtype
2592 ;; ; Defined in [MIME-IMT]
2594 ;; media-message = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE
2595 ;; ; Defined in [MIME-IMT]
2597 ;; media-subtype = string
2598 ;; ; Defined in [MIME-IMT]
2600 ;; media-text = DQUOTE "TEXT" DQUOTE SP media-subtype
2601 ;; ; Defined in [MIME-IMT]
2603 (defun imap-parse-body ()
2605 (when (eq (char-after) ?\()
2607 (if (eq (char-after) ?\()
2609 (while (and (eq (char-after) ?\()
2610 (setq subbody (imap-parse-body)))
2611 ;; buggy stalker communigate pro 3.0 insert a SPC between
2612 ;; parts in multiparts
2613 (when (and (eq (char-after) ?\ )
2614 (eq (char-after (1+ (point))) ?\())
2616 (push subbody body))
2618 (push (imap-parse-string) body) ;; media-subtype
2619 (when (eq (char-after) ?\ ) ;; body-ext-mpart:
2621 (if (eq (char-after) ?\() ;; body-fld-param
2622 (push (imap-parse-string-list) body)
2623 (push (and (imap-parse-nil) nil) body))
2625 (append (imap-parse-body-ext) body))) ;; body-ext-...
2626 (assert (eq (char-after) ?\)) t "In imap-parse-body")
2630 (push (imap-parse-string) body) ;; media-type
2632 (push (imap-parse-string) body) ;; media-subtype
2634 ;; next line for Sun SIMS bug
2635 (and (eq (char-after) ? ) (imap-forward))
2636 (if (eq (char-after) ?\() ;; body-fld-param
2637 (push (imap-parse-string-list) body)
2638 (push (and (imap-parse-nil) nil) body))
2640 (push (imap-parse-nstring) body) ;; body-fld-id
2642 (push (imap-parse-nstring) body) ;; body-fld-desc
2644 ;; next `or' for Sun SIMS bug, it regard body-fld-enc as a
2645 ;; nstring and return nil instead of defaulting back to 7BIT
2646 ;; as the standard says.
2647 (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc
2649 (push (imap-parse-number) body) ;; body-fld-octets
2651 ;; ok, we're done parsing the required parts, what comes now is one
2654 ;; envelope (then we're parsing body-type-msg)
2655 ;; body-fld-lines (then we're parsing body-type-text)
2656 ;; body-ext-1part (then we're parsing body-type-basic)
2658 ;; the problem is that the two first are in turn optionally followed
2659 ;; by the third. So we parse the first two here (if there are any)...
2661 (when (eq (char-after) ?\ )
2664 (cond ((eq (char-after) ?\() ;; body-type-msg:
2665 (push (imap-parse-envelope) body) ;; envelope
2667 (push (imap-parse-body) body) ;; body
2668 ;; buggy stalker communigate pro 3.0 doesn't print
2669 ;; number of lines in message/rfc822 attachment
2670 (if (eq (char-after) ?\))
2673 (push (imap-parse-number) body))) ;; body-fld-lines
2674 ((setq lines (imap-parse-number)) ;; body-type-text:
2675 (push lines body)) ;; body-fld-lines
2677 (backward-char))))) ;; no match...
2679 ;; ...and then parse the third one here...
2681 (when (eq (char-after) ?\ ) ;; body-ext-1part:
2683 (push (imap-parse-nstring) body) ;; body-fld-md5
2684 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part..
2686 (assert (eq (char-after) ?\)) t "In imap-parse-body 2")
2690 (when imap-debug ; (untrace-all)
2692 (buffer-disable-undo (get-buffer-create imap-debug-buffer))
2693 (mapcar (lambda (f) (trace-function-background f imap-debug-buffer))
2704 imap-interactive-login
2720 imap-send-command-wait
2725 imap-current-mailbox
2726 imap-current-mailbox-p-1
2727 imap-current-mailbox-p
2728 imap-mailbox-select-1
2730 imap-mailbox-examine-1
2731 imap-mailbox-examine
2732 imap-mailbox-unselect
2733 imap-mailbox-expunge
2735 imap-mailbox-create-1
2741 imap-mailbox-subscribe
2742 imap-mailbox-unsubscribe
2744 imap-mailbox-acl-get
2745 imap-mailbox-acl-set
2746 imap-mailbox-acl-delete
2747 imap-current-message
2748 imap-list-to-message-set
2755 imap-message-flag-permanent-p
2756 imap-message-flags-set
2757 imap-message-flags-del
2758 imap-message-flags-add
2759 imap-message-copyuid-1
2760 imap-message-copyuid
2762 imap-message-appenduid-1
2763 imap-message-appenduid
2775 imap-parse-resp-text
2776 imap-parse-resp-text-code
2777 imap-parse-data-list
2781 imap-parse-flag-list
2783 imap-parse-body-extension
2789 ;;; imap.el ends here