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)
545 (let* ((port (or port imap-default-port))
546 (coding-system-for-read imap-coding-system-for-read)
547 (coding-system-for-write imap-coding-system-for-write)
548 (process-connection-type imap-process-connection-type)
549 (process (start-process
550 name buffer shell-file-name shell-command-switch
555 ?p (number-to-string port)
556 ?l imap-default-user))))
559 (with-current-buffer buffer
560 (setq imap-client-eol "\n"
561 imap-calculate-literal-size-first t)
562 (while (and (memq (process-status process) '(open run))
563 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
564 (goto-char (point-min))
565 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
566 (or (while (looking-at "^C:")
569 ;; cyrus 1.6 imtest print "S: " before server greeting
570 (or (not (looking-at "S: "))
573 (not (and (imap-parse-greeting)
574 ;; success in imtest 1.6:
576 (concat "^\\(\\(Authenticat.*\\)\\|\\("
577 "Client authentication "
580 (setq response (match-string 1)))))
581 (accept-process-output process 1)
584 (with-current-buffer (get-buffer-create imap-log-buffer)
585 (imap-disable-multibyte)
586 (buffer-disable-undo)
587 (goto-char (point-max))
588 (insert-buffer-substring buffer)))
590 (message "GSSAPI IMAP connection: %s" (or response "failed"))
591 (if (and response (let ((case-fold-search nil))
592 (not (string-match "failed" response))))
594 (if (memq (process-status process) '(open run))
595 (imap-send-command "LOGOUT"))
596 (delete-process process)
600 (defun imap-ssl-p (buffer)
603 (defun imap-ssl-open (name buffer server port)
604 "Open a SSL connection to server."
605 (let ((cmds (if (listp imap-ssl-program) imap-ssl-program
606 (list imap-ssl-program)))
608 (while (and (not done) (setq cmd (pop cmds)))
609 (message "imap: Opening SSL connection with `%s'..." cmd)
610 (let* ((port (or port imap-default-ssl-port))
611 (coding-system-for-read imap-coding-system-for-read)
612 (coding-system-for-write imap-coding-system-for-write)
613 (process-connection-type nil)
616 (setq process (start-process
617 name buffer shell-file-name
622 ?p (number-to-string port)))))
623 (process-kill-without-query process)
625 (with-current-buffer buffer
626 (goto-char (point-min))
627 (while (and (memq (process-status process) '(open run))
628 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
629 (goto-char (point-max))
631 (not (imap-parse-greeting)))
632 (accept-process-output process 1)
635 (with-current-buffer (get-buffer-create imap-log-buffer)
636 (imap-disable-multibyte)
637 (buffer-disable-undo)
638 (goto-char (point-max))
639 (insert-buffer-substring buffer)))
641 (when (memq (process-status process) '(open run))
642 (setq done process))))))
645 (message "imap: Opening SSL connection with `%s'...done" cmd)
647 (message "imap: Opening SSL connection with `%s'...failed" cmd)
650 (defun imap-tls-p (buffer)
653 (defun imap-tls-open (name buffer server port)
654 (let* ((port (or port imap-default-tls-port))
655 (coding-system-for-read imap-coding-system-for-read)
656 (coding-system-for-write imap-coding-system-for-write)
657 (process (open-tls-stream name buffer server port)))
659 (while (and (memq (process-status process) '(open run))
660 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
661 (goto-char (point-max))
663 (not (imap-parse-greeting)))
664 (accept-process-output process 1)
667 (with-current-buffer (get-buffer-create imap-log-buffer)
668 (imap-disable-multibyte)
669 (buffer-disable-undo)
670 (goto-char (point-max))
671 (insert-buffer-substring buffer)))
672 (when (memq (process-status process) '(open run))
675 (defun imap-network-p (buffer)
678 (defun imap-network-open (name buffer server port)
679 (let* ((port (or port imap-default-port))
680 (coding-system-for-read imap-coding-system-for-read)
681 (coding-system-for-write imap-coding-system-for-write)
682 (process (open-network-stream name buffer server port)))
684 (while (and (memq (process-status process) '(open run))
685 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
686 (goto-char (point-min))
687 (not (imap-parse-greeting)))
688 (accept-process-output process 1)
691 (with-current-buffer (get-buffer-create imap-log-buffer)
692 (imap-disable-multibyte)
693 (buffer-disable-undo)
694 (goto-char (point-max))
695 (insert-buffer-substring buffer)))
696 (when (memq (process-status process) '(open run))
699 (defun imap-shell-p (buffer)
702 (defun imap-shell-open (name buffer server port)
703 (let ((cmds (if (listp imap-shell-program) imap-shell-program
704 (list imap-shell-program)))
706 (while (and (not done) (setq cmd (pop cmds)))
707 (message "imap: Opening IMAP connection with `%s'..." cmd)
708 (setq imap-client-eol "\n")
709 (let* ((port (or port imap-default-port))
710 (coding-system-for-read imap-coding-system-for-read)
711 (coding-system-for-write imap-coding-system-for-write)
712 (process (start-process
713 name buffer shell-file-name shell-command-switch
719 ?p (number-to-string port)
720 ?l imap-default-user)))))
722 (while (and (memq (process-status process) '(open run))
723 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
724 (goto-char (point-max))
726 (not (imap-parse-greeting)))
727 (accept-process-output process 1)
730 (with-current-buffer (get-buffer-create imap-log-buffer)
731 (imap-disable-multibyte)
732 (buffer-disable-undo)
733 (goto-char (point-max))
734 (insert-buffer-substring buffer)))
736 (when (memq (process-status process) '(open run))
737 (setq done process)))))
740 (message "imap: Opening IMAP connection with `%s'...done" cmd)
742 (message "imap: Opening IMAP connection with `%s'...failed" cmd)
745 (defun imap-starttls-p (buffer)
746 (imap-capability 'STARTTLS buffer))
748 (defun imap-starttls-open (name buffer server port)
749 (let* ((port (or port imap-default-port))
750 (coding-system-for-read imap-coding-system-for-read)
751 (coding-system-for-write imap-coding-system-for-write)
752 (process (starttls-open-stream name buffer server port))
754 (message "imap: Connecting with STARTTLS...")
756 (while (and (memq (process-status process) '(open run))
757 (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
758 (goto-char (point-min))
759 (not (imap-parse-greeting)))
760 (accept-process-output process 1)
763 (with-current-buffer (get-buffer-create imap-log-buffer)
764 (buffer-disable-undo)
765 (goto-char (point-max))
766 (insert-buffer-substring buffer)))
767 (let ((imap-process process))
770 (set-process-filter imap-process 'imap-arrival-filter)
771 (when (and (eq imap-stream 'starttls)
772 (imap-ok-p (imap-send-command-wait "STARTTLS")))
773 (starttls-negotiate imap-process)))
774 (set-process-filter imap-process nil)))
775 (when (memq (process-status process) '(open run))
776 (setq done process)))
779 (message "imap: Connecting with STARTTLS...done")
781 (message "imap: Connecting with STARTTLS...failed")
784 ;; Server functions; authenticator stuff:
786 (defun imap-interactive-login (buffer loginfunc)
787 "Login to server in BUFFER.
788 LOGINFUNC is passed a username and a password, it should return t if
789 it where successful authenticating itself to the server, nil otherwise.
790 Returns t if login was successful, nil otherwise."
791 (with-current-buffer buffer
792 (make-local-variable 'imap-username)
793 (make-local-variable 'imap-password)
794 (let (user passwd ret)
795 ;; (condition-case ()
796 (while (or (not user) (not passwd))
797 (setq user (or imap-username
798 (read-from-minibuffer
799 (concat "IMAP username for " imap-server
800 " (using stream `" (symbol-name imap-stream)
802 (or user imap-default-user))))
803 (setq passwd (or imap-password
805 (concat "IMAP password for " user "@"
806 imap-server " (using authenticator `"
807 (symbol-name imap-auth) "'): "))))
808 (when (and user passwd)
809 (if (funcall loginfunc user passwd)
813 (if (and (not imap-password)
814 (y-or-n-p "Store password for this session? "))
815 (setq imap-password passwd)))
816 (message "Login failed...")
819 ;; (quit (with-current-buffer buffer
822 ;; (error (with-current-buffer buffer
827 (defun imap-gssapi-auth-p (buffer)
828 (and (imap-capability 'AUTH=GSSAPI buffer)
829 (eq imap-stream 'gssapi)))
831 (defun imap-gssapi-auth (buffer)
832 (message "imap: Authenticating using GSSAPI...%s"
833 (if (eq imap-stream 'gssapi) "done" "failed"))
834 (eq imap-stream 'gssapi))
836 (defun imap-kerberos4-auth-p (buffer)
837 (and (imap-capability 'AUTH=KERBEROS_V4 buffer)
838 (eq imap-stream 'kerberos4)))
840 (defun imap-kerberos4-auth (buffer)
841 (message "imap: Authenticating using Kerberos 4...%s"
842 (if (eq imap-stream 'kerberos4) "done" "failed"))
843 (eq imap-stream 'kerberos4))
845 (defun imap-cram-md5-p (buffer)
846 (imap-capability 'AUTH=CRAM-MD5 buffer))
848 (defun imap-cram-md5-auth (buffer)
849 "Login to server using the AUTH CRAM-MD5 method."
850 (message "imap: Authenticating using CRAM-MD5...")
851 (let ((done (imap-interactive-login
853 (lambda (user passwd)
855 (imap-send-command-wait
857 "AUTHENTICATE CRAM-MD5"
859 (let* ((decoded (base64-decode-string challenge))
860 (hash (rfc2104-hash 'md5 64 16 passwd decoded))
861 (response (concat user " " hash))
862 (encoded (base64-encode-string response)))
865 (message "imap: Authenticating using CRAM-MD5...done")
866 (message "imap: Authenticating using CRAM-MD5...failed"))))
868 (defun imap-login-p (buffer)
869 (and (not (imap-capability 'LOGINDISABLED buffer))
870 (not (imap-capability 'X-LOGIN-CMD-DISABLED buffer))))
872 (defun imap-login-auth (buffer)
873 "Login to server using the LOGIN command."
874 (message "imap: Plaintext authentication...")
875 (imap-interactive-login buffer
876 (lambda (user passwd)
877 (imap-ok-p (imap-send-command-wait
878 (concat "LOGIN \"" user "\" \""
881 (defun imap-anonymous-p (buffer)
884 (defun imap-anonymous-auth (buffer)
885 (message "imap: Logging in anonymously...")
886 (with-current-buffer buffer
887 (imap-ok-p (imap-send-command-wait
888 (concat "LOGIN anonymous \"" (concat (user-login-name) "@"
889 (system-name)) "\"")))))
891 (defun imap-digest-md5-p (buffer)
892 (and (imap-capability 'AUTH=DIGEST-MD5 buffer)
894 (require 'digest-md5)
897 (defun imap-digest-md5-auth (buffer)
898 "Login to server using the AUTH DIGEST-MD5 method."
899 (message "imap: Authenticating using DIGEST-MD5...")
900 (imap-interactive-login
902 (lambda (user passwd)
906 "AUTHENTICATE DIGEST-MD5"
908 (digest-md5-parse-digest-challenge
909 (base64-decode-string challenge))
911 (digest-md5-digest-uri
912 "imap" (digest-md5-challenge 'realm)))
914 (digest-md5-digest-response
915 user passwd digest-uri)))
916 (base64-encode-string response 'no-line-break))))
918 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
920 (setq imap-continuation nil)
921 (imap-send-command-1 "")
922 (imap-ok-p (imap-wait-for-tag tag)))))))
926 (defun imap-open-1 (buffer)
927 (with-current-buffer buffer
929 (setq imap-current-mailbox nil
930 imap-current-message nil
932 imap-process (condition-case ()
933 (funcall (nth 2 (assq imap-stream
935 "imap" buffer imap-server imap-port)
938 (set-process-filter imap-process 'imap-arrival-filter)
939 (set-process-sentinel imap-process 'imap-sentinel)
940 (while (and (eq imap-state 'initial)
941 (memq (process-status imap-process) '(open run)))
942 (message "Waiting for response from %s..." imap-server)
943 (accept-process-output imap-process 1))
944 (message "Waiting for response from %s...done" imap-server)
945 (and (memq (process-status imap-process) '(open run))
948 (defun imap-open (server &optional port stream auth buffer)
949 "Open a IMAP connection to host SERVER at PORT returning a buffer.
950 If PORT is unspecified, a default value is used (143 except
951 for SSL which use 993).
952 STREAM indicates the stream to use, see `imap-streams' for available
953 streams. If nil, it choices the best stream the server is capable of.
954 AUTH indicates authenticator to use, see `imap-authenticators' for
955 available authenticators. If nil, it choices the best stream the
956 server is capable of.
957 BUFFER can be a buffer or a name of a buffer, which is created if
958 necessary. If nil, the buffer name is generated."
959 (setq buffer (or buffer (format " *imap* %s:%d" server (or port 0))))
960 (with-current-buffer (get-buffer-create buffer)
961 (if (imap-opened buffer)
963 (mapcar 'make-local-variable imap-local-variables)
964 (imap-disable-multibyte)
965 (buffer-disable-undo)
966 (setq imap-server (or server imap-server))
967 (setq imap-port (or port imap-port))
968 (setq imap-auth (or auth imap-auth))
969 (setq imap-stream (or stream imap-stream))
970 (message "imap: Connecting to %s..." imap-server)
971 (if (null (let ((imap-stream (or imap-stream imap-default-stream)))
972 (imap-open-1 buffer)))
974 (message "imap: Connecting to %s...failed" imap-server)
976 (when (null imap-stream)
977 ;; Need to choose stream.
978 (let ((streams imap-streams))
979 (while (setq stream (pop streams))
980 ;; OK to use this stream?
981 (when (funcall (nth 1 (assq stream imap-stream-alist)) buffer)
983 (if (not (eq imap-default-stream stream))
984 (with-current-buffer (get-buffer-create
985 (generate-new-buffer-name " *temp*"))
986 (mapcar 'make-local-variable imap-local-variables)
987 (imap-disable-multibyte)
988 (buffer-disable-undo)
989 (setq imap-server (or server imap-server))
990 (setq imap-port (or port imap-port))
991 (setq imap-auth (or auth imap-auth))
992 (message "imap: Reconnecting with stream `%s'..." stream)
993 (if (null (let ((imap-stream stream))
994 (imap-open-1 (current-buffer))))
996 (kill-buffer (current-buffer))
998 "imap: Reconnecting with stream `%s'...failed"
1000 ;; We're done, kill the first connection
1002 (kill-buffer buffer)
1003 (rename-buffer buffer)
1004 (message "imap: Reconnecting with stream `%s'...done"
1006 (setq imap-stream stream)
1007 (setq imap-capability nil)
1008 (setq streams nil)))
1010 (message "imap: Connecting to %s...done" imap-server)
1011 (setq imap-stream stream)
1012 (setq imap-capability nil)
1013 (setq streams nil))))))
1014 (when (imap-opened buffer)
1015 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0)))
1019 (defun imap-opened (&optional buffer)
1020 "Return non-nil if connection to imap server in BUFFER is open.
1021 If BUFFER is nil then the current buffer is used."
1022 (and (setq buffer (get-buffer (or buffer (current-buffer))))
1023 (buffer-live-p buffer)
1024 (with-current-buffer buffer
1026 (memq (process-status imap-process) '(open run))))))
1028 (defun imap-authenticate (&optional user passwd buffer)
1029 "Authenticate to server in BUFFER, using current buffer if nil.
1030 It uses the authenticator specified when opening the server. If the
1031 authenticator requires username/passwords, they are queried from the
1032 user and optionally stored in the buffer. If USER and/or PASSWD is
1033 specified, the user will not be questioned and the username and/or
1034 password is remembered in the buffer."
1035 (with-current-buffer (or buffer (current-buffer))
1036 (if (not (eq imap-state 'nonauth))
1037 (or (eq imap-state 'auth)
1038 (eq imap-state 'select)
1039 (eq imap-state 'examine))
1040 (make-local-variable 'imap-username)
1041 (make-local-variable 'imap-password)
1042 (if user (setq imap-username user))
1043 (if passwd (setq imap-password passwd))
1045 (and (funcall (nth 2 (assq imap-auth
1046 imap-authenticator-alist)) buffer)
1047 (setq imap-state 'auth))
1048 ;; Choose authenticator.
1049 (let ((auths imap-authenticators)
1051 (while (setq auth (pop auths))
1052 ;; OK to use authenticator?
1053 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) buffer)
1054 (message "imap: Authenticating to `%s' using `%s'..."
1056 (setq imap-auth auth)
1057 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) buffer)
1059 (message "imap: Authenticating to `%s' using `%s'...done"
1062 (message "imap: Authenticating to `%s' using `%s'...failed"
1063 imap-server auth)))))
1066 (defun imap-close (&optional buffer)
1067 "Close connection to server in BUFFER.
1068 If BUFFER is nil, the current buffer is used."
1069 (with-current-buffer (or buffer (current-buffer))
1072 (imap-send-command-wait "LOGOUT")
1074 (when (and imap-process
1075 (memq (process-status imap-process) '(open run)))
1076 (delete-process imap-process))
1077 (setq imap-current-mailbox nil
1078 imap-current-message nil
1083 (defun imap-capability (&optional identifier buffer)
1084 "Return a list of identifiers which server in BUFFER support.
1085 If IDENTIFIER, return non-nil if it's among the servers capabilities.
1086 If BUFFER is nil, the current buffer is assumed."
1087 (with-current-buffer (or buffer (current-buffer))
1088 (unless imap-capability
1089 (unless (imap-ok-p (imap-send-command-wait "CAPABILITY"))
1090 (setq imap-capability '(IMAP2))))
1092 (memq (intern (upcase (symbol-name identifier))) imap-capability)
1095 (defun imap-namespace (&optional buffer)
1096 "Return a namespace hierarchy at server in BUFFER.
1097 If BUFFER is nil, the current buffer is assumed."
1098 (with-current-buffer (or buffer (current-buffer))
1099 (unless imap-namespace
1100 (when (imap-capability 'NAMESPACE)
1101 (imap-send-command-wait "NAMESPACE")))
1104 (defun imap-send-command-wait (command &optional buffer)
1105 (imap-wait-for-tag (imap-send-command command buffer) buffer))
1108 ;; Mailbox functions:
1110 (defun imap-mailbox-put (propname value &optional mailbox buffer)
1111 (with-current-buffer (or buffer (current-buffer))
1112 (if imap-mailbox-data
1113 (put (intern (or mailbox imap-current-mailbox) imap-mailbox-data)
1115 (error "Imap-mailbox-data is nil, prop %s value %s mailbox %s buffer %s"
1116 propname value mailbox (current-buffer)))
1119 (defsubst imap-mailbox-get-1 (propname &optional mailbox)
1120 (get (intern-soft (or mailbox imap-current-mailbox) imap-mailbox-data)
1123 (defun imap-mailbox-get (propname &optional mailbox buffer)
1124 (let ((mailbox (imap-utf7-encode mailbox)))
1125 (with-current-buffer (or buffer (current-buffer))
1126 (imap-mailbox-get-1 propname (or mailbox imap-current-mailbox)))))
1128 (defun imap-mailbox-map-1 (func &optional mailbox-decoder buffer)
1129 (with-current-buffer (or buffer (current-buffer))
1133 (push (funcall func (if mailbox-decoder
1134 (funcall mailbox-decoder (symbol-name s))
1135 (symbol-name s))) result))
1139 (defun imap-mailbox-map (func &optional buffer)
1140 "Map a function across each mailbox in `imap-mailbox-data', returning a list.
1141 Function should take a mailbox name (a string) as
1143 (imap-mailbox-map-1 func 'imap-utf7-decode buffer))
1145 (defun imap-current-mailbox (&optional buffer)
1146 (with-current-buffer (or buffer (current-buffer))
1147 (imap-utf7-decode imap-current-mailbox)))
1149 (defun imap-current-mailbox-p-1 (mailbox &optional examine)
1150 (and (string= mailbox imap-current-mailbox)
1152 (eq imap-state 'examine))
1154 (eq imap-state 'selected)))))
1156 (defun imap-current-mailbox-p (mailbox &optional examine buffer)
1157 (with-current-buffer (or buffer (current-buffer))
1158 (imap-current-mailbox-p-1 (imap-utf7-encode mailbox) examine)))
1160 (defun imap-mailbox-select-1 (mailbox &optional examine)
1161 "Select MAILBOX on server in BUFFER.
1162 If EXAMINE is non-nil, do a read-only select."
1163 (if (imap-current-mailbox-p-1 mailbox examine)
1164 imap-current-mailbox
1165 (setq imap-current-mailbox mailbox)
1166 (if (imap-ok-p (imap-send-command-wait
1167 (concat (if examine "EXAMINE" "SELECT") " \""
1170 (setq imap-message-data (make-vector imap-message-prime 0)
1171 imap-state (if examine 'examine 'selected))
1172 imap-current-mailbox)
1173 ;; Failed SELECT/EXAMINE unselects current mailbox
1174 (setq imap-current-mailbox nil))))
1176 (defun imap-mailbox-select (mailbox &optional examine buffer)
1177 (with-current-buffer (or buffer (current-buffer))
1179 (imap-mailbox-select-1 (imap-utf7-encode mailbox) examine))))
1181 (defun imap-mailbox-examine-1 (mailbox &optional buffer)
1182 (with-current-buffer (or buffer (current-buffer))
1183 (imap-mailbox-select-1 mailbox 'examine)))
1185 (defun imap-mailbox-examine (mailbox &optional buffer)
1186 "Examine MAILBOX on server in BUFFER."
1187 (imap-mailbox-select mailbox 'examine buffer))
1189 (defun imap-mailbox-unselect (&optional buffer)
1190 "Close current folder in BUFFER, without expunging articles."
1191 (with-current-buffer (or buffer (current-buffer))
1192 (when (or (eq imap-state 'auth)
1193 (and (imap-capability 'UNSELECT)
1194 (imap-ok-p (imap-send-command-wait "UNSELECT")))
1196 (imap-send-command-wait (concat "EXAMINE \""
1197 imap-current-mailbox
1199 (imap-ok-p (imap-send-command-wait "CLOSE"))))
1200 (setq imap-current-mailbox nil
1201 imap-message-data nil
1205 (defun imap-mailbox-expunge (&optional asynch buffer)
1206 "Expunge articles in current folder in BUFFER.
1207 If ASYNCH, do not wait for succesful completion of the command.
1208 If BUFFER is nil the current buffer is assumed."
1209 (with-current-buffer (or buffer (current-buffer))
1210 (when (and imap-current-mailbox (not (eq imap-state 'examine)))
1212 (imap-send-command "EXPUNGE")
1213 (imap-ok-p (imap-send-command-wait "EXPUNGE"))))))
1215 (defun imap-mailbox-close (&optional asynch buffer)
1216 "Expunge articles and close current folder in BUFFER.
1217 If ASYNCH, do not wait for succesful completion of the command.
1218 If BUFFER is nil the current buffer is assumed."
1219 (with-current-buffer (or buffer (current-buffer))
1220 (when imap-current-mailbox
1222 (imap-add-callback (imap-send-command "CLOSE")
1223 `(lambda (tag status)
1224 (message "IMAP mailbox `%s' closed... %s"
1225 imap-current-mailbox status)
1226 (when (eq ,imap-current-mailbox
1227 imap-current-mailbox)
1228 ;; Don't wipe out data if another mailbox
1230 (setq imap-current-mailbox nil
1231 imap-message-data nil
1232 imap-state 'auth))))
1233 (when (imap-ok-p (imap-send-command-wait "CLOSE"))
1234 (setq imap-current-mailbox nil
1235 imap-message-data nil
1239 (defun imap-mailbox-create-1 (mailbox)
1240 (imap-ok-p (imap-send-command-wait (list "CREATE \"" mailbox "\""))))
1242 (defun imap-mailbox-create (mailbox &optional buffer)
1243 "Create MAILBOX on server in BUFFER.
1244 If BUFFER is nil the current buffer is assumed."
1245 (with-current-buffer (or buffer (current-buffer))
1246 (imap-mailbox-create-1 (imap-utf7-encode mailbox))))
1248 (defun imap-mailbox-delete (mailbox &optional buffer)
1249 "Delete MAILBOX on server in BUFFER.
1250 If BUFFER is nil the current buffer is assumed."
1251 (let ((mailbox (imap-utf7-encode mailbox)))
1252 (with-current-buffer (or buffer (current-buffer))
1254 (imap-send-command-wait (list "DELETE \"" mailbox "\""))))))
1256 (defun imap-mailbox-rename (oldname newname &optional buffer)
1257 "Rename mailbox OLDNAME to NEWNAME on server in BUFFER.
1258 If BUFFER is nil the current buffer is assumed."
1259 (let ((oldname (imap-utf7-encode oldname))
1260 (newname (imap-utf7-encode newname)))
1261 (with-current-buffer (or buffer (current-buffer))
1263 (imap-send-command-wait (list "RENAME \"" oldname "\" "
1264 "\"" newname "\""))))))
1266 (defun imap-mailbox-lsub (&optional root reference add-delimiter buffer)
1267 "Return a list of subscribed mailboxes on server in BUFFER.
1268 If ROOT is non-nil, only list matching mailboxes. If ADD-DELIMITER is
1269 non-nil, a hierarchy delimiter is added to root. REFERENCE is a
1270 implementation-specific string that has to be passed to lsub command."
1271 (with-current-buffer (or buffer (current-buffer))
1272 ;; Make sure we know the hierarchy separator for root's hierarchy
1273 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1274 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1275 (imap-utf7-encode root) "\"")))
1276 ;; clear list data (NB not delimiter and other stuff)
1277 (imap-mailbox-map-1 (lambda (mailbox)
1278 (imap-mailbox-put 'lsub nil mailbox)))
1280 (imap-send-command-wait
1281 (concat "LSUB \"" reference "\" \"" (imap-utf7-encode root)
1282 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1285 (imap-mailbox-map-1 (lambda (mailbox)
1286 (when (imap-mailbox-get-1 'lsub mailbox)
1287 (push (imap-utf7-decode mailbox) out))))
1290 (defun imap-mailbox-list (root &optional reference add-delimiter buffer)
1291 "Return a list of mailboxes matching ROOT on server in BUFFER.
1292 If ADD-DELIMITER is non-nil, a hierarchy delimiter is added to
1293 root. REFERENCE is a implementation-specific string that has to be
1294 passed to list command."
1295 (with-current-buffer (or buffer (current-buffer))
1296 ;; Make sure we know the hierarchy separator for root's hierarchy
1297 (when (and add-delimiter (null (imap-mailbox-get-1 'delimiter root)))
1298 (imap-send-command-wait (concat "LIST \"" reference "\" \""
1299 (imap-utf7-encode root) "\"")))
1300 ;; clear list data (NB not delimiter and other stuff)
1301 (imap-mailbox-map-1 (lambda (mailbox)
1302 (imap-mailbox-put 'list nil mailbox)))
1304 (imap-send-command-wait
1305 (concat "LIST \"" reference "\" \"" (imap-utf7-encode root)
1306 (and add-delimiter (imap-mailbox-get-1 'delimiter root))
1309 (imap-mailbox-map-1 (lambda (mailbox)
1310 (when (imap-mailbox-get-1 'list mailbox)
1311 (push (imap-utf7-decode mailbox) out))))
1314 (defun imap-mailbox-subscribe (mailbox &optional buffer)
1315 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1316 Returns non-nil if successful."
1317 (with-current-buffer (or buffer (current-buffer))
1318 (imap-ok-p (imap-send-command-wait (concat "SUBSCRIBE \""
1319 (imap-utf7-encode mailbox)
1322 (defun imap-mailbox-unsubscribe (mailbox &optional buffer)
1323 "Send the SUBSCRIBE command on the mailbox to server in BUFFER.
1324 Returns non-nil if successful."
1325 (with-current-buffer (or buffer (current-buffer))
1326 (imap-ok-p (imap-send-command-wait (concat "UNSUBSCRIBE "
1327 (imap-utf7-encode mailbox)
1330 (defun imap-mailbox-status (mailbox items &optional buffer)
1331 "Get status items ITEM in MAILBOX from server in BUFFER.
1332 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1333 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1334 or 'unseen. If ITEMS is a list of symbols, a list of values is
1335 returned, if ITEMS is a symbol only its value is returned."
1336 (with-current-buffer (or buffer (current-buffer))
1338 (imap-send-command-wait (list "STATUS \""
1339 (imap-utf7-encode mailbox)
1346 (mapcar (lambda (item)
1347 (imap-mailbox-get item mailbox))
1349 (imap-mailbox-get items mailbox)))))
1351 (defun imap-mailbox-status-asynch (mailbox items &optional buffer)
1352 "Send status item request ITEM on MAILBOX to server in BUFFER.
1353 ITEMS can be a symbol or a list of symbols, valid symbols are one of
1354 the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity
1355 or 'unseen. The IMAP command tag is returned."
1356 (with-current-buffer (or buffer (current-buffer))
1357 (imap-send-command (list "STATUS \""
1358 (imap-utf7-encode mailbox)
1365 (defun imap-mailbox-acl-get (&optional mailbox buffer)
1366 "Get ACL on mailbox from server in BUFFER."
1367 (let ((mailbox (imap-utf7-encode mailbox)))
1368 (with-current-buffer (or buffer (current-buffer))
1370 (imap-send-command-wait (list "GETACL \""
1371 (or mailbox imap-current-mailbox)
1373 (imap-mailbox-get-1 'acl (or mailbox imap-current-mailbox))))))
1375 (defun imap-mailbox-acl-set (identifier rights &optional mailbox buffer)
1376 "Change/set ACL for IDENTIFIER to RIGHTS in MAILBOX from server in BUFFER."
1377 (let ((mailbox (imap-utf7-encode mailbox)))
1378 (with-current-buffer (or buffer (current-buffer))
1380 (imap-send-command-wait (list "SETACL \""
1381 (or mailbox imap-current-mailbox)
1387 (defun imap-mailbox-acl-delete (identifier &optional mailbox buffer)
1388 "Removes any <identifier,rights> pair for IDENTIFIER in MAILBOX from server in BUFFER."
1389 (let ((mailbox (imap-utf7-encode mailbox)))
1390 (with-current-buffer (or buffer (current-buffer))
1392 (imap-send-command-wait (list "DELETEACL \""
1393 (or mailbox imap-current-mailbox)
1398 ;; Message functions:
1400 (defun imap-current-message (&optional buffer)
1401 (with-current-buffer (or buffer (current-buffer))
1402 imap-current-message))
1404 (defun imap-list-to-message-set (list)
1405 (mapconcat (lambda (item)
1406 (number-to-string item))
1412 (defun imap-range-to-message-set (range)
1417 (car item) (cdr item))
1418 (format "%d" item)))
1419 (if (and (listp range) (not (listp (cdr range))))
1420 (list range) ;; make (1 . 2) into ((1 . 2))
1424 (defun imap-fetch-asynch (uids props &optional nouidfetch buffer)
1425 (with-current-buffer (or buffer (current-buffer))
1426 (imap-send-command (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1428 (imap-list-to-message-set uids)
1432 (defun imap-fetch (uids props &optional receive nouidfetch buffer)
1433 "Fetch properties PROPS from message set UIDS from server in BUFFER.
1434 UIDS can be a string, number or a list of numbers. If RECEIVE
1435 is non-nil return theese properties."
1436 (with-current-buffer (or buffer (current-buffer))
1437 (when (imap-ok-p (imap-send-command-wait
1438 (format "%sFETCH %s %s" (if nouidfetch "" "UID ")
1440 (imap-list-to-message-set uids)
1443 (if (or (null receive) (stringp uids))
1446 (mapcar (lambda (uid)
1448 (mapcar (lambda (prop)
1449 (imap-message-get uid prop))
1451 (imap-message-get uid receive)))
1453 (imap-message-get uids receive))))))
1455 (defun imap-message-put (uid propname value &optional buffer)
1456 (with-current-buffer (or buffer (current-buffer))
1457 (if imap-message-data
1458 (put (intern (number-to-string uid) imap-message-data)
1460 (error "Imap-message-data is nil, uid %s prop %s value %s buffer %s"
1461 uid propname value (current-buffer)))
1464 (defun imap-message-get (uid propname &optional buffer)
1465 (with-current-buffer (or buffer (current-buffer))
1466 (get (intern-soft (number-to-string uid) imap-message-data)
1469 (defun imap-message-map (func propname &optional buffer)
1470 "Map a function across each mailbox in `imap-message-data', returning a list."
1471 (with-current-buffer (or buffer (current-buffer))
1475 (push (funcall func (get s 'UID) (get s propname)) result))
1479 (defmacro imap-message-envelope-date (uid &optional buffer)
1480 `(with-current-buffer (or ,buffer (current-buffer))
1481 (elt (imap-message-get ,uid 'ENVELOPE) 0)))
1483 (defmacro imap-message-envelope-subject (uid &optional buffer)
1484 `(with-current-buffer (or ,buffer (current-buffer))
1485 (elt (imap-message-get ,uid 'ENVELOPE) 1)))
1487 (defmacro imap-message-envelope-from (uid &optional buffer)
1488 `(with-current-buffer (or ,buffer (current-buffer))
1489 (elt (imap-message-get ,uid 'ENVELOPE) 2)))
1491 (defmacro imap-message-envelope-sender (uid &optional buffer)
1492 `(with-current-buffer (or ,buffer (current-buffer))
1493 (elt (imap-message-get ,uid 'ENVELOPE) 3)))
1495 (defmacro imap-message-envelope-reply-to (uid &optional buffer)
1496 `(with-current-buffer (or ,buffer (current-buffer))
1497 (elt (imap-message-get ,uid 'ENVELOPE) 4)))
1499 (defmacro imap-message-envelope-to (uid &optional buffer)
1500 `(with-current-buffer (or ,buffer (current-buffer))
1501 (elt (imap-message-get ,uid 'ENVELOPE) 5)))
1503 (defmacro imap-message-envelope-cc (uid &optional buffer)
1504 `(with-current-buffer (or ,buffer (current-buffer))
1505 (elt (imap-message-get ,uid 'ENVELOPE) 6)))
1507 (defmacro imap-message-envelope-bcc (uid &optional buffer)
1508 `(with-current-buffer (or ,buffer (current-buffer))
1509 (elt (imap-message-get ,uid 'ENVELOPE) 7)))
1511 (defmacro imap-message-envelope-in-reply-to (uid &optional buffer)
1512 `(with-current-buffer (or ,buffer (current-buffer))
1513 (elt (imap-message-get ,uid 'ENVELOPE) 8)))
1515 (defmacro imap-message-envelope-message-id (uid &optional buffer)
1516 `(with-current-buffer (or ,buffer (current-buffer))
1517 (elt (imap-message-get ,uid 'ENVELOPE) 9)))
1519 (defmacro imap-message-body (uid &optional buffer)
1520 `(with-current-buffer (or ,buffer (current-buffer))
1521 (imap-message-get ,uid 'BODY)))
1523 (defun imap-search (predicate &optional buffer)
1524 (with-current-buffer (or buffer (current-buffer))
1525 (imap-mailbox-put 'search 'dummy)
1526 (when (imap-ok-p (imap-send-command-wait (concat "UID SEARCH " predicate)))
1527 (if (eq (imap-mailbox-get-1 'search imap-current-mailbox) 'dummy)
1529 (message "Missing SEARCH response to a SEARCH command (server not RFC compliant)...")
1531 (imap-mailbox-get-1 'search imap-current-mailbox)))))
1533 (defun imap-message-flag-permanent-p (flag &optional mailbox buffer)
1534 "Return t iff FLAG can be permanently (between IMAP sessions) saved on articles, in MAILBOX on server in BUFFER."
1535 (with-current-buffer (or buffer (current-buffer))
1536 (or (member "\\*" (imap-mailbox-get 'permanentflags mailbox))
1537 (member flag (imap-mailbox-get 'permanentflags mailbox)))))
1539 (defun imap-message-flags-set (articles flags &optional silent buffer)
1540 (when (and articles flags)
1541 (with-current-buffer (or buffer (current-buffer))
1542 (imap-ok-p (imap-send-command-wait
1543 (concat "UID STORE " articles
1544 " FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1546 (defun imap-message-flags-del (articles flags &optional silent buffer)
1547 (when (and articles flags)
1548 (with-current-buffer (or buffer (current-buffer))
1549 (imap-ok-p (imap-send-command-wait
1550 (concat "UID STORE " articles
1551 " -FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1553 (defun imap-message-flags-add (articles flags &optional silent buffer)
1554 (when (and articles flags)
1555 (with-current-buffer (or buffer (current-buffer))
1556 (imap-ok-p (imap-send-command-wait
1557 (concat "UID STORE " articles
1558 " +FLAGS" (if silent ".SILENT") " (" flags ")"))))))
1560 (defun imap-message-copyuid-1 (mailbox)
1561 (if (imap-capability 'UIDPLUS)
1562 (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox))
1563 (string-to-number (nth 2 (imap-mailbox-get-1 'copyuid mailbox))))
1564 (let ((old-mailbox imap-current-mailbox)
1566 (imap-message-data (make-vector 2 0)))
1567 (when (imap-mailbox-examine-1 mailbox)
1569 (and (imap-fetch "*" "UID")
1570 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1571 (apply 'max (imap-message-map
1572 (lambda (uid prop) uid) 'UID))))
1574 (imap-mailbox-select old-mailbox (eq state 'examine))
1575 (imap-mailbox-unselect)))))))
1577 (defun imap-message-copyuid (mailbox &optional buffer)
1578 (with-current-buffer (or buffer (current-buffer))
1579 (imap-message-copyuid-1 (imap-utf7-decode mailbox))))
1581 (defun imap-message-copy (articles mailbox
1582 &optional dont-create no-copyuid buffer)
1583 "Copy ARTICLES (a string message set) to MAILBOX on server in
1584 BUFFER, creating mailbox if it doesn't exist. If dont-create is
1585 non-nil, it will not create a mailbox. On success, return a list with
1586 the UIDVALIDITY of the mailbox the article(s) was copied to as the
1587 first element, rest of list contain the saved articles' UIDs."
1589 (with-current-buffer (or buffer (current-buffer))
1590 (let ((mailbox (imap-utf7-encode mailbox)))
1591 (if (let ((cmd (concat "UID COPY " articles " \"" mailbox "\""))
1592 (imap-current-target-mailbox mailbox))
1593 (if (imap-ok-p (imap-send-command-wait cmd))
1595 (when (and (not dont-create)
1596 ;; removed because of buggy Oracle server
1597 ;; that doesn't send TRYCREATE tags (which
1598 ;; is a MUST according to specifications):
1599 ;;(imap-mailbox-get-1 'trycreate mailbox)
1600 (imap-mailbox-create-1 mailbox))
1601 (imap-ok-p (imap-send-command-wait cmd)))))
1603 (imap-message-copyuid-1 mailbox)))))))
1605 (defun imap-message-appenduid-1 (mailbox)
1606 (if (imap-capability 'UIDPLUS)
1607 (imap-mailbox-get-1 'appenduid mailbox)
1608 (let ((old-mailbox imap-current-mailbox)
1610 (imap-message-data (make-vector 2 0)))
1611 (when (imap-mailbox-examine-1 mailbox)
1613 (and (imap-fetch "*" "UID")
1614 (list (imap-mailbox-get-1 'uidvalidity mailbox)
1615 (apply 'max (imap-message-map
1616 (lambda (uid prop) uid) 'UID))))
1618 (imap-mailbox-select old-mailbox (eq state 'examine))
1619 (imap-mailbox-unselect)))))))
1621 (defun imap-message-appenduid (mailbox &optional buffer)
1622 (with-current-buffer (or buffer (current-buffer))
1623 (imap-message-appenduid-1 (imap-utf7-encode mailbox))))
1625 (defun imap-message-append (mailbox article &optional flags date-time buffer)
1626 "Append ARTICLE (a buffer) to MAILBOX on server in BUFFER.
1627 FLAGS and DATE-TIME is currently not used. Return a cons holding
1628 uidvalidity of MAILBOX and UID the newly created article got, or nil
1630 (let ((mailbox (imap-utf7-encode mailbox)))
1631 (with-current-buffer (or buffer (current-buffer))
1632 (and (let ((imap-current-target-mailbox mailbox))
1634 (imap-send-command-wait
1635 (list "APPEND \"" mailbox "\" " article))))
1636 (imap-message-appenduid-1 mailbox)))))
1638 (defun imap-body-lines (body)
1639 "Return number of lines in article by looking at the mime bodystructure BODY."
1641 (if (stringp (car body))
1642 (cond ((and (string= (upcase (car body)) "TEXT")
1643 (numberp (nth 7 body)))
1645 ((and (string= (upcase (car body)) "MESSAGE")
1646 (numberp (nth 9 body)))
1649 (apply '+ (mapcar 'imap-body-lines body)))
1652 (defun imap-envelope-from (from)
1653 "Return a from string line."
1655 (concat (aref from 0)
1656 (if (aref from 0) " <")
1660 (if (aref from 0) ">"))))
1663 ;; Internal functions.
1665 (defun imap-add-callback (tag func)
1666 (setq imap-callbacks (append (list (cons tag func)) imap-callbacks)))
1668 (defun imap-send-command-1 (cmdstr)
1669 (setq cmdstr (concat cmdstr imap-client-eol))
1671 (with-current-buffer (get-buffer-create imap-log-buffer)
1672 (imap-disable-multibyte)
1673 (buffer-disable-undo)
1674 (goto-char (point-max))
1676 (process-send-string imap-process cmdstr))
1678 (defun imap-send-command (command &optional buffer)
1679 (with-current-buffer (or buffer (current-buffer))
1680 (if (not (listp command)) (setq command (list command)))
1681 (let ((tag (setq imap-tag (1+ imap-tag)))
1683 (setq cmdstr (concat (number-to-string imap-tag) " "))
1684 (while (setq cmd (pop command))
1685 (cond ((stringp cmd)
1686 (setq cmdstr (concat cmdstr cmd)))
1688 (let ((eol imap-client-eol)
1689 (calcfirst imap-calculate-literal-size-first)
1691 (with-current-buffer cmd
1693 (setq size (buffer-size)))
1694 (when (not (equal eol "\r\n"))
1695 ;; XXX modifies buffer!
1696 (goto-char (point-min))
1697 (while (search-forward "\r\n" nil t)
1698 (replace-match eol)))
1700 (setq size (buffer-size))))
1702 (concat cmdstr (format "{%d}" size))))
1705 (imap-send-command-1 cmdstr)
1707 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1708 (setq command nil) ;; abort command if no cont-req
1709 (let ((process imap-process)
1710 (stream imap-stream)
1711 (eol imap-client-eol))
1712 (with-current-buffer cmd
1714 (with-current-buffer (get-buffer-create
1716 (imap-disable-multibyte)
1717 (buffer-disable-undo)
1718 (goto-char (point-max))
1719 (insert-buffer-substring cmd)))
1720 (process-send-region process (point-min)
1722 (process-send-string process imap-client-eol))))
1723 (setq imap-continuation nil)))
1725 (imap-send-command-1 cmdstr)
1728 (if (not (eq (imap-wait-for-tag tag) 'INCOMPLETE))
1729 (setq command nil) ;; abort command if no cont-req
1730 (setq command (cons (funcall cmd imap-continuation)
1732 (setq imap-continuation nil)))
1734 (error "Unknown command type"))))
1736 (imap-send-command-1 cmdstr))
1739 (defun imap-wait-for-tag (tag &optional buffer)
1740 (with-current-buffer (or buffer (current-buffer))
1741 (let (imap-have-messaged)
1742 (while (and (null imap-continuation)
1743 (memq (process-status imap-process) '(open run))
1744 (< imap-reached-tag tag))
1745 (let ((len (/ (point-max) 1024))
1748 (setq imap-have-messaged t)
1749 (message "imap read: %dk" len))
1750 (accept-process-output imap-process
1751 (truncate imap-read-timeout)
1752 (truncate (* (- imap-read-timeout
1753 (truncate imap-read-timeout))
1755 (when imap-have-messaged
1757 (and (memq (process-status imap-process) '(open run))
1758 (or (assq tag imap-failed-tags)
1759 (if imap-continuation
1763 (defun imap-sentinel (process string)
1764 (delete-process process))
1766 (defun imap-find-next-line ()
1767 "Return point at end of current line, taking into account literals.
1768 Return nil if no complete line has arrived."
1769 (when (re-search-forward (concat imap-server-eol "\\|{\\([0-9]+\\)}"
1772 (if (match-string 1)
1773 (if (< (point-max) (+ (point) (string-to-number (match-string 1))))
1775 (goto-char (+ (point) (string-to-number (match-string 1))))
1776 (imap-find-next-line))
1779 (defun imap-arrival-filter (proc string)
1780 "IMAP process filter."
1781 (with-current-buffer (process-buffer proc)
1782 (goto-char (point-max))
1785 (with-current-buffer (get-buffer-create imap-log-buffer)
1786 (imap-disable-multibyte)
1787 (buffer-disable-undo)
1788 (goto-char (point-max))
1791 (goto-char (point-min))
1792 (while (setq end (imap-find-next-line))
1794 (narrow-to-region (point-min) end)
1795 (delete-backward-char (length imap-server-eol))
1796 (goto-char (point-min))
1798 (cond ((eq imap-state 'initial)
1799 (imap-parse-greeting))
1800 ((or (eq imap-state 'auth)
1801 (eq imap-state 'nonauth)
1802 (eq imap-state 'selected)
1803 (eq imap-state 'examine))
1804 (imap-parse-response))
1806 (message "Unknown state %s in arrival filter"
1808 (delete-region (point-min) (point-max))))))))
1813 (defsubst imap-forward ()
1814 (or (eobp) (forward-char)))
1817 ;; ; Unsigned 32-bit integer
1818 ;; ; (0 <= n < 4,294,967,296)
1820 (defsubst imap-parse-number ()
1821 (when (looking-at "[0-9]+")
1823 (string-to-number (match-string 0))
1824 (goto-char (match-end 0)))))
1826 ;; literal = "{" number "}" CRLF *CHAR8
1827 ;; ; Number represents the number of CHAR8s
1829 (defsubst imap-parse-literal ()
1830 (when (looking-at "{\\([0-9]+\\)}\r\n")
1831 (let ((pos (match-end 0))
1832 (len (string-to-number (match-string 1))))
1833 (if (< (point-max) (+ pos len))
1835 (goto-char (+ pos len))
1836 (buffer-substring pos (+ pos len))))))
1838 ;; string = quoted / literal
1840 ;; quoted = DQUOTE *QUOTED-CHAR DQUOTE
1842 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
1843 ;; "\" quoted-specials
1845 ;; quoted-specials = DQUOTE / "\"
1847 ;; TEXT-CHAR = <any CHAR except CR and LF>
1849 (defsubst imap-parse-string ()
1850 (cond ((eq (char-after) ?\")
1852 (let ((p (point)) (name ""))
1853 (skip-chars-forward "^\"\\\\")
1854 (setq name (buffer-substring p (point)))
1855 (while (eq (char-after) ?\\)
1856 (setq p (1+ (point)))
1858 (skip-chars-forward "^\"\\\\")
1859 (setq name (concat name (buffer-substring p (point)))))
1862 ((eq (char-after) ?{)
1863 (imap-parse-literal))))
1867 (defsubst imap-parse-nil ()
1868 (if (looking-at "NIL")
1869 (goto-char (match-end 0))))
1871 ;; nstring = string / nil
1873 (defsubst imap-parse-nstring ()
1874 (or (imap-parse-string)
1875 (and (imap-parse-nil)
1878 ;; astring = atom / string
1880 ;; atom = 1*ATOM-CHAR
1882 ;; ATOM-CHAR = <any CHAR except atom-specials>
1884 ;; atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
1887 ;; list-wildcards = "%" / "*"
1889 ;; quoted-specials = DQUOTE / "\"
1891 (defsubst imap-parse-astring ()
1892 (or (imap-parse-string)
1893 (buffer-substring (point)
1894 (if (re-search-forward "[(){ \r\n%*\"\\]" nil t)
1895 (goto-char (1- (match-end 0)))
1899 ;; address = "(" addr-name SP addr-adl SP addr-mailbox SP
1902 ;; addr-adl = nstring
1903 ;; ; Holds route from [RFC-822] route-addr if
1906 ;; addr-host = nstring
1907 ;; ; nil indicates [RFC-822] group syntax.
1908 ;; ; Otherwise, holds [RFC-822] domain name
1910 ;; addr-mailbox = nstring
1911 ;; ; nil indicates end of [RFC-822] group; if
1912 ;; ; non-nil and addr-host is nil, holds
1913 ;; ; [RFC-822] group name.
1914 ;; ; Otherwise, holds [RFC-822] local-part
1915 ;; ; after removing [RFC-822] quoting
1917 ;; addr-name = nstring
1918 ;; ; If non-nil, holds phrase from [RFC-822]
1919 ;; ; mailbox after removing [RFC-822] quoting
1922 (defsubst imap-parse-address ()
1924 (when (eq (char-after) ?\()
1926 (setq address (vector (prog1 (imap-parse-nstring)
1928 (prog1 (imap-parse-nstring)
1930 (prog1 (imap-parse-nstring)
1932 (imap-parse-nstring)))
1933 (when (eq (char-after) ?\))
1937 ;; address-list = "(" 1*address ")" / nil
1941 (defsubst imap-parse-address-list ()
1942 (if (eq (char-after) ?\()
1943 (let (address addresses)
1945 (while (and (not (eq (char-after) ?\)))
1946 ;; next line for MS Exchange bug
1947 (progn (and (eq (char-after) ? ) (imap-forward)) t)
1948 (setq address (imap-parse-address)))
1949 (setq addresses (cons address addresses)))
1950 (when (eq (char-after) ?\))
1952 (nreverse addresses)))
1953 (assert (imap-parse-nil) t "In imap-parse-address-list")))
1955 ;; mailbox = "INBOX" / astring
1956 ;; ; INBOX is case-insensitive. All case variants of
1957 ;; ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
1958 ;; ; not as an astring. An astring which consists of
1959 ;; ; the case-insensitive sequence "I" "N" "B" "O" "X"
1960 ;; ; is considered to be INBOX and not an astring.
1961 ;; ; Refer to section 5.1 for further
1962 ;; ; semantic details of mailbox names.
1964 (defsubst imap-parse-mailbox ()
1965 (let ((mailbox (imap-parse-astring)))
1966 (if (string-equal "INBOX" (upcase mailbox))
1970 ;; greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
1972 ;; resp-cond-auth = ("OK" / "PREAUTH") SP resp-text
1973 ;; ; Authentication condition
1975 ;; resp-cond-bye = "BYE" SP resp-text
1977 (defun imap-parse-greeting ()
1978 "Parse a IMAP greeting."
1979 (cond ((looking-at "\\* OK ")
1980 (setq imap-state 'nonauth))
1981 ((looking-at "\\* PREAUTH ")
1982 (setq imap-state 'auth))
1983 ((looking-at "\\* BYE ")
1984 (setq imap-state 'closed))))
1986 ;; response = *(continue-req / response-data) response-done
1988 ;; continue-req = "+" SP (resp-text / base64) CRLF
1990 ;; response-data = "*" SP (resp-cond-state / resp-cond-bye /
1991 ;; mailbox-data / message-data / capability-data) CRLF
1993 ;; response-done = response-tagged / response-fatal
1995 ;; response-fatal = "*" SP resp-cond-bye CRLF
1996 ;; ; Server closes connection immediately
1998 ;; response-tagged = tag SP resp-cond-state CRLF
2000 ;; resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
2001 ;; ; Status condition
2003 ;; resp-cond-bye = "BYE" SP resp-text
2005 ;; mailbox-data = "FLAGS" SP flag-list /
2006 ;; "LIST" SP mailbox-list /
2007 ;; "LSUB" SP mailbox-list /
2008 ;; "SEARCH" *(SP nz-number) /
2009 ;; "STATUS" SP mailbox SP "("
2010 ;; [status-att SP number *(SP status-att SP number)] ")" /
2011 ;; number SP "EXISTS" /
2012 ;; number SP "RECENT"
2014 ;; message-data = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att))
2016 ;; capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
2018 ;; ; IMAP4rev1 servers which offer RFC 1730
2019 ;; ; compatibility MUST list "IMAP4" as the first
2022 (defun imap-parse-response ()
2023 "Parse a IMAP command response."
2025 (case (setq token (read (current-buffer)))
2026 (+ (setq imap-continuation
2027 (or (buffer-substring (min (point-max) (1+ (point)))
2030 (* (case (prog1 (setq token (read (current-buffer)))
2032 (OK (imap-parse-resp-text))
2033 (NO (imap-parse-resp-text))
2034 (BAD (imap-parse-resp-text))
2035 (BYE (imap-parse-resp-text))
2036 (FLAGS (imap-mailbox-put 'flags (imap-parse-flag-list)))
2037 (LIST (imap-parse-data-list 'list))
2038 (LSUB (imap-parse-data-list 'lsub))
2039 (SEARCH (imap-mailbox-put
2041 (read (concat "(" (buffer-substring (point) (point-max)) ")"))))
2042 (STATUS (imap-parse-status))
2043 (CAPABILITY (setq imap-capability
2044 (read (concat "(" (upcase (buffer-substring
2045 (point) (point-max)))
2047 (ACL (imap-parse-acl))
2048 (t (case (prog1 (read (current-buffer))
2050 (EXISTS (imap-mailbox-put 'exists token))
2051 (RECENT (imap-mailbox-put 'recent token))
2053 (FETCH (imap-parse-fetch token))
2054 (t (message "Garbage: %s" (buffer-string)))))))
2056 (if (not (integerp token))
2057 (message "Garbage: %s" (buffer-string))
2058 (case (prog1 (setq status (read (current-buffer)))
2061 (setq imap-reached-tag (max imap-reached-tag token))
2062 (imap-parse-resp-text)))
2064 (setq imap-reached-tag (max imap-reached-tag token))
2066 (imap-parse-resp-text))
2068 (when (eq (char-after) ?\[)
2069 (setq code (buffer-substring (point)
2070 (search-forward "]")))
2072 (setq text (buffer-substring (point) (point-max)))
2073 (push (list token status code text)
2074 imap-failed-tags))))
2076 (setq imap-reached-tag (max imap-reached-tag token))
2078 (imap-parse-resp-text))
2080 (when (eq (char-after) ?\[)
2081 (setq code (buffer-substring (point)
2082 (search-forward "]")))
2084 (setq text (buffer-substring (point) (point-max)))
2085 (push (list token status code text) imap-failed-tags)
2086 (error "Internal error, tag %s status %s code %s text %s"
2087 token status code text))))
2088 (t (message "Garbage: %s" (buffer-string))))
2089 (when (assq token imap-callbacks)
2090 (funcall (cdr (assq token imap-callbacks)) token status)
2091 (setq imap-callbacks
2092 (imap-remassoc token imap-callbacks)))))))))
2094 ;; resp-text = ["[" resp-text-code "]" SP] text
2096 ;; text = 1*TEXT-CHAR
2098 ;; TEXT-CHAR = <any CHAR except CR and LF>
2100 (defun imap-parse-resp-text ()
2101 (imap-parse-resp-text-code))
2103 ;; resp-text-code = "ALERT" /
2104 ;; "BADCHARSET [SP "(" astring *(SP astring) ")" ] /
2105 ;; "NEWNAME" SP string SP string /
2107 ;; "PERMANENTFLAGS" SP "("
2108 ;; [flag-perm *(SP flag-perm)] ")" /
2112 ;; "UIDNEXT" SP nz-number /
2113 ;; "UIDVALIDITY" SP nz-number /
2114 ;; "UNSEEN" SP nz-number /
2115 ;; resp-text-atom [SP 1*<any TEXT-CHAR except "]">]
2117 ;; resp_code_apnd = "APPENDUID" SPACE nz_number SPACE uniqueid
2119 ;; resp_code_copy = "COPYUID" SPACE nz_number SPACE set SPACE set
2121 ;; set = sequence-num / (sequence-num ":" sequence-num) /
2123 ;; ; Identifies a set of messages. For message
2124 ;; ; sequence numbers, these are consecutive
2125 ;; ; numbers from 1 to the number of messages in
2127 ;; ; Comma delimits individual numbers, colon
2128 ;; ; delimits between two numbers inclusive.
2129 ;; ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13,
2130 ;; ; 14,15 for a mailbox with 15 messages.
2132 ;; sequence-num = nz-number / "*"
2133 ;; ; * is the largest number in use. For message
2134 ;; ; sequence numbers, it is the number of messages
2135 ;; ; in the mailbox. For unique identifiers, it is
2136 ;; ; the unique identifier of the last message in
2139 ;; flag-perm = flag / "\*"
2141 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2142 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2143 ;; ; Does not include "\Recent"
2145 ;; flag-extension = "\" atom
2146 ;; ; Future expansion. Client implementations
2147 ;; ; MUST accept flag-extension flags. Server
2148 ;; ; implementations MUST NOT generate
2149 ;; ; flag-extension flags except as defined by
2150 ;; ; future standard or standards-track
2151 ;; ; revisions of this specification.
2153 ;; flag-keyword = atom
2155 ;; resp-text-atom = 1*<any ATOM-CHAR except "]">
2157 (defun imap-parse-resp-text-code ()
2158 ;; xxx next line for stalker communigate pro 3.3.1 bug
2159 (when (looking-at " \\[")
2161 (when (eq (char-after) ?\[)
2163 (cond ((search-forward "PERMANENTFLAGS " nil t)
2164 (imap-mailbox-put 'permanentflags (imap-parse-flag-list)))
2165 ((search-forward "UIDNEXT \\([0-9]+\\)" nil t)
2166 (imap-mailbox-put 'uidnext (match-string 1)))
2167 ((search-forward "UNSEEN " nil t)
2168 (imap-mailbox-put 'first-unseen (read (current-buffer))))
2169 ((looking-at "UIDVALIDITY \\([0-9]+\\)")
2170 (imap-mailbox-put 'uidvalidity (match-string 1)))
2171 ((search-forward "READ-ONLY" nil t)
2172 (imap-mailbox-put 'read-only t))
2173 ((search-forward "NEWNAME " nil t)
2174 (let (oldname newname)
2175 (setq oldname (imap-parse-string))
2177 (setq newname (imap-parse-string))
2178 (imap-mailbox-put 'newname newname oldname)))
2179 ((search-forward "TRYCREATE" nil t)
2180 (imap-mailbox-put 'trycreate t imap-current-target-mailbox))
2181 ((looking-at "APPENDUID \\([0-9]+\\) \\([0-9]+\\)")
2182 (imap-mailbox-put 'appenduid
2183 (list (match-string 1)
2184 (string-to-number (match-string 2)))
2185 imap-current-target-mailbox))
2186 ((looking-at "COPYUID \\([0-9]+\\) \\([0-9,:]+\\) \\([0-9,:]+\\)")
2187 (imap-mailbox-put 'copyuid (list (match-string 1)
2190 imap-current-target-mailbox))
2191 ((search-forward "ALERT] " nil t)
2192 (message "Imap server %s information: %s" imap-server
2193 (buffer-substring (point) (point-max)))))))
2195 ;; mailbox-list = "(" [mbx-list-flags] ")" SP
2196 ;; (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox
2198 ;; mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag
2199 ;; *(SP mbx-list-oflag) /
2200 ;; mbx-list-oflag *(SP mbx-list-oflag)
2202 ;; mbx-list-oflag = "\Noinferiors" / flag-extension
2203 ;; ; Other flags; multiple possible per LIST response
2205 ;; mbx-list-sflag = "\Noselect" / "\Marked" / "\Unmarked"
2206 ;; ; Selectability flags; only one per LIST response
2208 ;; QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> /
2209 ;; "\" quoted-specials
2211 ;; quoted-specials = DQUOTE / "\"
2213 (defun imap-parse-data-list (type)
2214 (let (flags delimiter mailbox)
2215 (setq flags (imap-parse-flag-list))
2216 (when (looking-at " NIL\\| \"\\\\?\\(.\\)\"")
2217 (setq delimiter (match-string 1))
2218 (goto-char (1+ (match-end 0)))
2219 (when (setq mailbox (imap-parse-mailbox))
2220 (imap-mailbox-put type t mailbox)
2221 (imap-mailbox-put 'list-flags flags mailbox)
2222 (imap-mailbox-put 'delimiter delimiter mailbox)))))
2224 ;; msg_att ::= "(" 1#("ENVELOPE" SPACE envelope /
2225 ;; "FLAGS" SPACE "(" #(flag / "\Recent") ")" /
2226 ;; "INTERNALDATE" SPACE date_time /
2227 ;; "RFC822" [".HEADER" / ".TEXT"] SPACE nstring /
2228 ;; "RFC822.SIZE" SPACE number /
2229 ;; "BODY" ["STRUCTURE"] SPACE body /
2230 ;; "BODY" section ["<" number ">"] SPACE nstring /
2231 ;; "UID" SPACE uniqueid) ")"
2233 ;; date_time ::= <"> date_day_fixed "-" date_month "-" date_year
2234 ;; SPACE time SPACE zone <">
2236 ;; section ::= "[" [section_text / (nz_number *["." nz_number]
2237 ;; ["." (section_text / "MIME")])] "]"
2239 ;; section_text ::= "HEADER" / "HEADER.FIELDS" [".NOT"]
2240 ;; SPACE header_list / "TEXT"
2242 ;; header_fld_name ::= astring
2244 ;; header_list ::= "(" 1#header_fld_name ")"
2246 (defsubst imap-parse-header-list ()
2247 (when (eq (char-after) ?\()
2249 (while (not (eq (char-after) ?\)))
2251 (push (imap-parse-astring) strlist))
2253 (nreverse strlist))))
2255 (defsubst imap-parse-fetch-body-section ()
2257 (buffer-substring (point) (1- (re-search-forward "[] ]" nil t)))))
2258 (if (eq (char-before) ? )
2260 (mapconcat 'identity (cons section (imap-parse-header-list)) " ")
2261 (search-forward "]" nil t))
2264 (defun imap-parse-fetch (response)
2265 (when (eq (char-after) ?\()
2266 (let (uid flags envelope internaldate rfc822 rfc822header rfc822text
2267 rfc822size body bodydetail bodystructure flags-empty)
2268 (while (not (eq (char-after) ?\)))
2270 (let ((token (read (current-buffer))))
2272 (cond ((eq token 'UID)
2273 (setq uid (condition-case ()
2274 (read (current-buffer))
2277 (setq flags (imap-parse-flag-list))
2279 (setq flags-empty 't)))
2280 ((eq token 'ENVELOPE)
2281 (setq envelope (imap-parse-envelope)))
2282 ((eq token 'INTERNALDATE)
2283 (setq internaldate (imap-parse-string)))
2285 (setq rfc822 (imap-parse-nstring)))
2286 ((eq token 'RFC822.HEADER)
2287 (setq rfc822header (imap-parse-nstring)))
2288 ((eq token 'RFC822.TEXT)
2289 (setq rfc822text (imap-parse-nstring)))
2290 ((eq token 'RFC822.SIZE)
2291 (setq rfc822size (read (current-buffer))))
2293 (if (eq (char-before) ?\[)
2295 (upcase (imap-parse-fetch-body-section))
2296 (and (eq (char-after) ?<)
2297 (buffer-substring (1+ (point))
2298 (search-forward ">" nil t)))
2299 (progn (imap-forward)
2300 (imap-parse-nstring)))
2302 (setq body (imap-parse-body))))
2303 ((eq token 'BODYSTRUCTURE)
2304 (setq bodystructure (imap-parse-body))))))
2306 (setq imap-current-message uid)
2307 (imap-message-put uid 'UID uid)
2308 (and (or flags flags-empty) (imap-message-put uid 'FLAGS flags))
2309 (and envelope (imap-message-put uid 'ENVELOPE envelope))
2310 (and internaldate (imap-message-put uid 'INTERNALDATE internaldate))
2311 (and rfc822 (imap-message-put uid 'RFC822 rfc822))
2312 (and rfc822header (imap-message-put uid 'RFC822.HEADER rfc822header))
2313 (and rfc822text (imap-message-put uid 'RFC822.TEXT rfc822text))
2314 (and rfc822size (imap-message-put uid 'RFC822.SIZE rfc822size))
2315 (and body (imap-message-put uid 'BODY body))
2316 (and bodydetail (imap-message-put uid 'BODYDETAIL bodydetail))
2317 (and bodystructure (imap-message-put uid 'BODYSTRUCTURE bodystructure))
2318 (run-hooks 'imap-fetch-data-hook)))))
2320 ;; mailbox-data = ...
2321 ;; "STATUS" SP mailbox SP "("
2322 ;; [status-att SP number
2323 ;; *(SP status-att SP number)] ")"
2326 ;; status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" /
2329 (defun imap-parse-status ()
2330 (let ((mailbox (imap-parse-mailbox)))
2331 (if (eq (char-after) ? )
2333 (when (and mailbox (eq (char-after) ?\())
2334 (while (and (not (eq (char-after) ?\)))
2335 (or (forward-char) t)
2336 (looking-at "\\([A-Za-z]+\\) "))
2337 (let ((token (match-string 1)))
2338 (goto-char (match-end 0))
2339 (cond ((string= token "MESSAGES")
2340 (imap-mailbox-put 'messages (read (current-buffer)) mailbox))
2341 ((string= token "RECENT")
2342 (imap-mailbox-put 'recent (read (current-buffer)) mailbox))
2343 ((string= token "UIDNEXT")
2344 (and (looking-at "[0-9]+")
2345 (imap-mailbox-put 'uidnext (match-string 0) mailbox)
2346 (goto-char (match-end 0))))
2347 ((string= token "UIDVALIDITY")
2348 (and (looking-at "[0-9]+")
2349 (imap-mailbox-put 'uidvalidity (match-string 0) mailbox)
2350 (goto-char (match-end 0))))
2351 ((string= token "UNSEEN")
2352 (imap-mailbox-put 'unseen (read (current-buffer)) mailbox))
2354 (message "Unknown status data %s in mailbox %s ignored"
2356 (read (current-buffer)))))))))
2358 ;; acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE
2361 ;; identifier ::= astring
2363 ;; rights ::= astring
2365 (defun imap-parse-acl ()
2366 (let ((mailbox (imap-parse-mailbox))
2367 identifier rights acl)
2368 (while (eq (char-after) ?\ )
2370 (setq identifier (imap-parse-astring))
2372 (setq rights (imap-parse-astring))
2373 (setq acl (append acl (list (cons identifier rights)))))
2374 (imap-mailbox-put 'acl acl mailbox)))
2376 ;; flag-list = "(" [flag *(SP flag)] ")"
2378 ;; flag = "\Answered" / "\Flagged" / "\Deleted" /
2379 ;; "\Seen" / "\Draft" / flag-keyword / flag-extension
2380 ;; ; Does not include "\Recent"
2382 ;; flag-keyword = atom
2384 ;; flag-extension = "\" atom
2385 ;; ; Future expansion. Client implementations
2386 ;; ; MUST accept flag-extension flags. Server
2387 ;; ; implementations MUST NOT generate
2388 ;; ; flag-extension flags except as defined by
2389 ;; ; future standard or standards-track
2390 ;; ; revisions of this specification.
2392 (defun imap-parse-flag-list ()
2393 (let (flag-list start)
2394 (assert (eq (char-after) ?\() t "In imap-parse-flag-list")
2395 (while (and (not (eq (char-after) ?\)))
2398 ;; next line for Courier IMAP bug.
2399 (skip-chars-forward " ")
2401 (> (skip-chars-forward "^ )" (imap-point-at-eol)) 0))
2402 (push (buffer-substring start (point)) flag-list))
2403 (assert (eq (char-after) ?\)) t "In imap-parse-flag-list")
2405 (nreverse flag-list)))
2407 ;; envelope = "(" env-date SP env-subject SP env-from SP env-sender SP
2408 ;; env-reply-to SP env-to SP env-cc SP env-bcc SP
2409 ;; env-in-reply-to SP env-message-id ")"
2411 ;; env-bcc = "(" 1*address ")" / nil
2413 ;; env-cc = "(" 1*address ")" / nil
2415 ;; env-date = nstring
2417 ;; env-from = "(" 1*address ")" / nil
2419 ;; env-in-reply-to = nstring
2421 ;; env-message-id = nstring
2423 ;; env-reply-to = "(" 1*address ")" / nil
2425 ;; env-sender = "(" 1*address ")" / nil
2427 ;; env-subject = nstring
2429 ;; env-to = "(" 1*address ")" / nil
2431 (defun imap-parse-envelope ()
2432 (when (eq (char-after) ?\()
2434 (vector (prog1 (imap-parse-nstring) ;; date
2436 (prog1 (imap-parse-nstring) ;; subject
2438 (prog1 (imap-parse-address-list) ;; from
2440 (prog1 (imap-parse-address-list) ;; sender
2442 (prog1 (imap-parse-address-list) ;; reply-to
2444 (prog1 (imap-parse-address-list) ;; to
2446 (prog1 (imap-parse-address-list) ;; cc
2448 (prog1 (imap-parse-address-list) ;; bcc
2450 (prog1 (imap-parse-nstring) ;; in-reply-to
2452 (prog1 (imap-parse-nstring) ;; message-id
2455 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2457 (defsubst imap-parse-string-list ()
2458 (cond ((eq (char-after) ?\() ;; body-fld-param
2461 (while (setq str (imap-parse-string))
2463 ;; buggy stalker communigate pro 3.0 doesn't print SPC
2464 ;; between body-fld-param's sometimes
2465 (or (eq (char-after) ?\")
2467 (nreverse strlist)))
2471 ;; body-extension = nstring / number /
2472 ;; "(" body-extension *(SP body-extension) ")"
2473 ;; ; Future expansion. Client implementations
2474 ;; ; MUST accept body-extension fields. Server
2475 ;; ; implementations MUST NOT generate
2476 ;; ; body-extension fields except as defined by
2477 ;; ; future standard or standards-track
2478 ;; ; revisions of this specification.
2480 (defun imap-parse-body-extension ()
2481 (if (eq (char-after) ?\()
2484 (push (imap-parse-body-extension) b-e)
2485 (while (eq (char-after) ?\ )
2487 (push (imap-parse-body-extension) b-e))
2488 (assert (eq (char-after) ?\)) t "In imap-parse-body-extension")
2491 (or (imap-parse-number)
2492 (imap-parse-nstring))))
2494 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2495 ;; *(SP body-extension)]]
2496 ;; ; MUST NOT be returned on non-extensible
2499 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2500 ;; *(SP body-extension)]]
2501 ;; ; MUST NOT be returned on non-extensible
2504 (defsubst imap-parse-body-ext ()
2506 (when (eq (char-after) ?\ ) ;; body-fld-dsp
2509 (if (eq (char-after) ?\()
2512 (push (imap-parse-string) dsp)
2514 (push (imap-parse-string-list) dsp)
2516 (assert (imap-parse-nil) t "In imap-parse-body-ext"))
2517 (push (nreverse dsp) ext))
2518 (when (eq (char-after) ?\ ) ;; body-fld-lang
2520 (if (eq (char-after) ?\()
2521 (push (imap-parse-string-list) ext)
2522 (push (imap-parse-nstring) ext))
2523 (while (eq (char-after) ?\ ) ;; body-extension
2525 (setq ext (append (imap-parse-body-extension) ext)))))
2528 ;; body = "(" body-type-1part / body-type-mpart ")"
2530 ;; body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
2531 ;; *(SP body-extension)]]
2532 ;; ; MUST NOT be returned on non-extensible
2535 ;; body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
2536 ;; *(SP body-extension)]]
2537 ;; ; MUST NOT be returned on non-extensible
2540 ;; body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP
2541 ;; body-fld-enc SP body-fld-octets
2543 ;; body-fld-desc = nstring
2545 ;; body-fld-dsp = "(" string SP body-fld-param ")" / nil
2547 ;; body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
2548 ;; "QUOTED-PRINTABLE") DQUOTE) / string
2550 ;; body-fld-id = nstring
2552 ;; body-fld-lang = nstring / "(" string *(SP string) ")"
2554 ;; body-fld-lines = number
2556 ;; body-fld-md5 = nstring
2558 ;; body-fld-octets = number
2560 ;; body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
2562 ;; body-type-1part = (body-type-basic / body-type-msg / body-type-text)
2563 ;; [SP body-ext-1part]
2565 ;; body-type-basic = media-basic SP body-fields
2566 ;; ; MESSAGE subtype MUST NOT be "RFC822"
2568 ;; body-type-msg = media-message SP body-fields SP envelope
2569 ;; SP body SP body-fld-lines
2571 ;; body-type-text = media-text SP body-fields SP body-fld-lines
2573 ;; body-type-mpart = 1*body SP media-subtype
2574 ;; [SP body-ext-mpart]
2576 ;; media-basic = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" /
2577 ;; "MESSAGE" / "VIDEO") DQUOTE) / string) SP media-subtype
2578 ;; ; Defined in [MIME-IMT]
2580 ;; media-message = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE
2581 ;; ; Defined in [MIME-IMT]
2583 ;; media-subtype = string
2584 ;; ; Defined in [MIME-IMT]
2586 ;; media-text = DQUOTE "TEXT" DQUOTE SP media-subtype
2587 ;; ; Defined in [MIME-IMT]
2589 (defun imap-parse-body ()
2591 (when (eq (char-after) ?\()
2593 (if (eq (char-after) ?\()
2595 (while (and (eq (char-after) ?\()
2596 (setq subbody (imap-parse-body)))
2597 ;; buggy stalker communigate pro 3.0 insert a SPC between
2598 ;; parts in multiparts
2599 (when (and (eq (char-after) ?\ )
2600 (eq (char-after (1+ (point))) ?\())
2602 (push subbody body))
2604 (push (imap-parse-string) body) ;; media-subtype
2605 (when (eq (char-after) ?\ ) ;; body-ext-mpart:
2607 (if (eq (char-after) ?\() ;; body-fld-param
2608 (push (imap-parse-string-list) body)
2609 (push (and (imap-parse-nil) nil) body))
2611 (append (imap-parse-body-ext) body))) ;; body-ext-...
2612 (assert (eq (char-after) ?\)) t "In imap-parse-body")
2616 (push (imap-parse-string) body) ;; media-type
2618 (push (imap-parse-string) body) ;; media-subtype
2620 ;; next line for Sun SIMS bug
2621 (and (eq (char-after) ? ) (imap-forward))
2622 (if (eq (char-after) ?\() ;; body-fld-param
2623 (push (imap-parse-string-list) body)
2624 (push (and (imap-parse-nil) nil) body))
2626 (push (imap-parse-nstring) body) ;; body-fld-id
2628 (push (imap-parse-nstring) body) ;; body-fld-desc
2630 ;; next `or' for Sun SIMS bug, it regard body-fld-enc as a
2631 ;; nstring and return nil instead of defaulting back to 7BIT
2632 ;; as the standard says.
2633 (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc
2635 (push (imap-parse-number) body) ;; body-fld-octets
2637 ;; ok, we're done parsing the required parts, what comes now is one
2640 ;; envelope (then we're parsing body-type-msg)
2641 ;; body-fld-lines (then we're parsing body-type-text)
2642 ;; body-ext-1part (then we're parsing body-type-basic)
2644 ;; the problem is that the two first are in turn optionally followed
2645 ;; by the third. So we parse the first two here (if there are any)...
2647 (when (eq (char-after) ?\ )
2650 (cond ((eq (char-after) ?\() ;; body-type-msg:
2651 (push (imap-parse-envelope) body) ;; envelope
2653 (push (imap-parse-body) body) ;; body
2654 ;; buggy stalker communigate pro 3.0 doesn't print
2655 ;; number of lines in message/rfc822 attachment
2656 (if (eq (char-after) ?\))
2659 (push (imap-parse-number) body))) ;; body-fld-lines
2660 ((setq lines (imap-parse-number)) ;; body-type-text:
2661 (push lines body)) ;; body-fld-lines
2663 (backward-char))))) ;; no match...
2665 ;; ...and then parse the third one here...
2667 (when (eq (char-after) ?\ ) ;; body-ext-1part:
2669 (push (imap-parse-nstring) body) ;; body-fld-md5
2670 (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part..
2672 (assert (eq (char-after) ?\)) t "In imap-parse-body 2")
2676 (when imap-debug ; (untrace-all)
2678 (buffer-disable-undo (get-buffer-create imap-debug-buffer))
2679 (mapcar (lambda (f) (trace-function-background f imap-debug-buffer))
2690 imap-interactive-login
2706 imap-send-command-wait
2711 imap-current-mailbox
2712 imap-current-mailbox-p-1
2713 imap-current-mailbox-p
2714 imap-mailbox-select-1
2716 imap-mailbox-examine-1
2717 imap-mailbox-examine
2718 imap-mailbox-unselect
2719 imap-mailbox-expunge
2721 imap-mailbox-create-1
2727 imap-mailbox-subscribe
2728 imap-mailbox-unsubscribe
2730 imap-mailbox-acl-get
2731 imap-mailbox-acl-set
2732 imap-mailbox-acl-delete
2733 imap-current-message
2734 imap-list-to-message-set
2741 imap-message-flag-permanent-p
2742 imap-message-flags-set
2743 imap-message-flags-del
2744 imap-message-flags-add
2745 imap-message-copyuid-1
2746 imap-message-copyuid
2748 imap-message-appenduid-1
2749 imap-message-appenduid
2761 imap-parse-resp-text
2762 imap-parse-resp-text-code
2763 imap-parse-data-list
2767 imap-parse-flag-list
2769 imap-parse-body-extension
2775 ;;; imap.el ends here