1 |
;;; imap.el --- imap library |
;;; imap.el --- imap library |
2 |
;; Copyright (C) 1998, 1999, 2000 |
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 |
3 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Simon Josefsson <jas@pdc.kth.se> |
;; Author: Simon Josefsson <jas@pdc.kth.se> |
138 |
|
|
139 |
(eval-when-compile (require 'cl)) |
(eval-when-compile (require 'cl)) |
140 |
(eval-and-compile |
(eval-and-compile |
|
(autoload 'open-ssl-stream "ssl") |
|
141 |
(autoload 'base64-decode-string "base64") |
(autoload 'base64-decode-string "base64") |
142 |
(autoload 'base64-encode-string "base64") |
(autoload 'base64-encode-string "base64") |
143 |
(autoload 'starttls-open-stream "starttls") |
(autoload 'starttls-open-stream "starttls") |
187 |
:group 'imap |
:group 'imap |
188 |
:type '(repeat string)) |
:type '(repeat string)) |
189 |
|
|
190 |
(defcustom imap-ssl-program '("openssl s_client -ssl3 -connect %s:%p" |
(defcustom imap-ssl-program '("openssl s_client -quiet -ssl3 -connect %s:%p" |
191 |
"openssl s_client -ssl2 -connect %s:%p" |
"openssl s_client -quiet -ssl2 -connect %s:%p" |
192 |
"s_client -ssl3 -connect %s:%p" |
"s_client -quiet -ssl3 -connect %s:%p" |
193 |
"s_client -ssl2 -connect %s:%p") |
"s_client -quiet -ssl2 -connect %s:%p") |
194 |
"A string, or list of strings, containing commands for SSL connections. |
"A string, or list of strings, containing commands for SSL connections. |
195 |
Within a string, %s is replaced with the server address and %p with |
Within a string, %s is replaced with the server address and %p with |
196 |
port number on server. The program should accept IMAP commands on |
port number on server. The program should accept IMAP commands on |
239 |
(starttls imap-starttls-p imap-starttls-open)) |
(starttls imap-starttls-p imap-starttls-open)) |
240 |
"Definition of network streams. |
"Definition of network streams. |
241 |
|
|
242 |
(NAME CHECK OPEN) |
\(NAME CHECK OPEN) |
243 |
|
|
244 |
NAME names the stream, CHECK is a function returning non-nil if the |
NAME names the stream, CHECK is a function returning non-nil if the |
245 |
server support the stream and OPEN is a function for opening the |
server supports the stream and OPEN is a function for opening the |
246 |
stream.") |
stream.") |
247 |
|
|
248 |
(defvar imap-authenticators '(gssapi |
(defvar imap-authenticators '(gssapi |
262 |
(digest-md5 imap-digest-md5-p imap-digest-md5-auth)) |
(digest-md5 imap-digest-md5-p imap-digest-md5-auth)) |
263 |
"Definition of authenticators. |
"Definition of authenticators. |
264 |
|
|
265 |
(NAME CHECK AUTHENTICATE) |
\(NAME CHECK AUTHENTICATE) |
266 |
|
|
267 |
NAME names the authenticator. CHECK is a function returning non-nil if |
NAME names the authenticator. CHECK is a function returning non-nil if |
268 |
the server support the authenticator and AUTHENTICATE is a function |
the server support the authenticator and AUTHENTICATE is a function |
269 |
for doing the actuall authentification.") |
for doing the actual authentication.") |
270 |
|
|
271 |
(defvar imap-use-utf7 t |
(defvar imap-use-utf7 t |
272 |
"If non-nil, do utf7 encoding/decoding of mailbox names. |
"If non-nil, do utf7 encoding/decoding of mailbox names. |
366 |
|
|
367 |
(defvar imap-continuation nil |
(defvar imap-continuation nil |
368 |
"Non-nil indicates that the server emitted a continuation request. |
"Non-nil indicates that the server emitted a continuation request. |
369 |
The actually value is really the text on the continuation line.") |
The actual value is really the text on the continuation line.") |
370 |
|
|
371 |
(defvar imap-log nil |
(defvar imap-log nil |
372 |
"Name of buffer for imap session trace. |
"Name of buffer for imap session trace. |
568 |
(let* ((port (or port imap-default-ssl-port)) |
(let* ((port (or port imap-default-ssl-port)) |
569 |
(coding-system-for-read imap-coding-system-for-read) |
(coding-system-for-read imap-coding-system-for-read) |
570 |
(coding-system-for-write imap-coding-system-for-write) |
(coding-system-for-write imap-coding-system-for-write) |
571 |
(ssl-program-name shell-file-name) |
(process-connection-type nil) |
|
(ssl-program-arguments |
|
|
(list shell-command-switch |
|
|
(format-spec cmd (format-spec-make |
|
|
?s server |
|
|
?p (number-to-string port))))) |
|
572 |
process) |
process) |
573 |
(when (setq process (ignore-errors (open-ssl-stream |
(when (progn |
574 |
name buffer server port))) |
(setq process (start-process |
575 |
|
name buffer shell-file-name |
576 |
|
shell-command-switch |
577 |
|
(format-spec cmd |
578 |
|
(format-spec-make |
579 |
|
?s server |
580 |
|
?p (number-to-string port))))) |
581 |
|
(process-kill-without-query process) |
582 |
|
process) |
583 |
(with-current-buffer buffer |
(with-current-buffer buffer |
584 |
(goto-char (point-min)) |
(goto-char (point-min)) |
585 |
(while (and (memq (process-status process) '(open run)) |
(while (and (memq (process-status process) '(open run)) |
586 |
|
(set-buffer buffer) ;; XXX "blue moon" nntp.el bug |
587 |
(goto-char (point-max)) |
(goto-char (point-max)) |
588 |
(forward-line -1) |
(forward-line -1) |
589 |
(not (imap-parse-greeting))) |
(not (imap-parse-greeting))) |
719 |
(defun imap-interactive-login (buffer loginfunc) |
(defun imap-interactive-login (buffer loginfunc) |
720 |
"Login to server in BUFFER. |
"Login to server in BUFFER. |
721 |
LOGINFUNC is passed a username and a password, it should return t if |
LOGINFUNC is passed a username and a password, it should return t if |
722 |
it where sucessful authenticating itself to the server, nil otherwise. |
it where successful authenticating itself to the server, nil otherwise. |
723 |
Returns t if login was successful, nil otherwise." |
Returns t if login was successful, nil otherwise." |
724 |
(with-current-buffer buffer |
(with-current-buffer buffer |
725 |
(make-local-variable 'imap-username) |
(make-local-variable 'imap-username) |
812 |
t) |
t) |
813 |
|
|
814 |
(defun imap-anonymous-auth (buffer) |
(defun imap-anonymous-auth (buffer) |
815 |
(message "imap: Loging in anonymously...") |
(message "imap: Logging in anonymously...") |
816 |
(with-current-buffer buffer |
(with-current-buffer buffer |
817 |
(imap-ok-p (imap-send-command-wait |
(imap-ok-p (imap-send-command-wait |
818 |
(concat "LOGIN anonymous \"" (concat (user-login-name) "@" |
(concat "LOGIN anonymous \"" (concat (user-login-name) "@" |
885 |
available authenticators. If nil, it choices the best stream the |
available authenticators. If nil, it choices the best stream the |
886 |
server is capable of. |
server is capable of. |
887 |
BUFFER can be a buffer or a name of a buffer, which is created if |
BUFFER can be a buffer or a name of a buffer, which is created if |
888 |
necessery. If nil, the buffer name is generated." |
necessary. If nil, the buffer name is generated." |
889 |
(setq buffer (or buffer (format " *imap* %s:%d" server (or port 0)))) |
(setq buffer (or buffer (format " *imap* %s:%d" server (or port 0)))) |
890 |
(with-current-buffer (get-buffer-create buffer) |
(with-current-buffer (get-buffer-create buffer) |
891 |
(if (imap-opened buffer) |
(if (imap-opened buffer) |
1219 |
ITEMS can be a symbol or a list of symbols, valid symbols are one of |
ITEMS can be a symbol or a list of symbols, valid symbols are one of |
1220 |
the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity |
the STATUS data items -- ie 'messages, 'recent, 'uidnext, 'uidvalidity |
1221 |
or 'unseen. If ITEMS is a list of symbols, a list of values is |
or 'unseen. If ITEMS is a list of symbols, a list of values is |
1222 |
returned, if ITEMS is a symbol only it's value is returned." |
returned, if ITEMS is a symbol only its value is returned." |
1223 |
(with-current-buffer (or buffer (current-buffer)) |
(with-current-buffer (or buffer (current-buffer)) |
1224 |
(when (imap-ok-p |
(when (imap-ok-p |
1225 |
(imap-send-command-wait (list "STATUS \"" |
(imap-send-command-wait (list "STATUS \"" |