Mercurial > emacs
comparison lisp/net/imap.el @ 105254:c31b6489ac68
Synch with Gnus trunk.
2009-09-10 Teodor Zlatanov <tzz@lifelogs.com>
* net/imap.el (imap-interactive-login): Better messages.
(imap-open): Fix bug with renamed buffer on reconnect.
(imap-authenticate): Add buffer-local imap-last-authenticator variable
for easier debugging and cleaner code. On successful (guessed based on
server capabilities) secondary authentication, set imap-state
correctly.
(imap-last-authenticator): Define imap-last-authenticator as a variable
to avoid warnings.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Mon, 28 Sep 2009 12:09:13 +0000 |
parents | 2e22af528b76 |
children | 1d1d5d9bd884 |
comparison
equal
deleted
inserted
replaced
105253:baa4e6ac9e46 | 105254:c31b6489ac68 |
---|---|
378 (defvar imap-auth nil) | 378 (defvar imap-auth nil) |
379 (defvar imap-server nil) | 379 (defvar imap-server nil) |
380 (defvar imap-port nil) | 380 (defvar imap-port nil) |
381 (defvar imap-username nil) | 381 (defvar imap-username nil) |
382 (defvar imap-password nil) | 382 (defvar imap-password nil) |
383 (defvar imap-last-authenticator nil) | |
383 (defvar imap-calculate-literal-size-first nil) | 384 (defvar imap-calculate-literal-size-first nil) |
384 (defvar imap-state 'closed | 385 (defvar imap-state 'closed |
385 "IMAP state. | 386 "IMAP state. |
386 Valid states are `closed', `initial', `nonauth', `auth', `selected' | 387 Valid states are `closed', `initial', `nonauth', `auth', `selected' |
387 and `examine'.") | 388 and `examine'.") |
870 (let (user passwd ret) | 871 (let (user passwd ret) |
871 ;; (condition-case () | 872 ;; (condition-case () |
872 (while (or (not user) (not passwd)) | 873 (while (or (not user) (not passwd)) |
873 (setq user (or imap-username | 874 (setq user (or imap-username |
874 (read-from-minibuffer | 875 (read-from-minibuffer |
875 (concat "IMAP username for " imap-server | 876 (concat "imap: username for " imap-server |
876 " (using stream `" (symbol-name imap-stream) | 877 " (using stream `" (symbol-name imap-stream) |
877 "'): ") | 878 "'): ") |
878 (or user imap-default-user)))) | 879 (or user imap-default-user)))) |
879 (setq passwd (or imap-password | 880 (setq passwd (or imap-password |
880 (read-passwd | 881 (read-passwd |
881 (concat "IMAP password for " user "@" | 882 (concat "imap: password for " user "@" |
882 imap-server " (using authenticator `" | 883 imap-server " (using authenticator `" |
883 (symbol-name imap-auth) "'): ")))) | 884 (symbol-name imap-auth) "'): ")))) |
884 (when (and user passwd) | 885 (when (and user passwd) |
885 (if (funcall loginfunc user passwd) | 886 (if (funcall loginfunc user passwd) |
886 (progn | 887 (progn |
888 (message "imap: Login successful...") | |
887 (setq ret t | 889 (setq ret t |
888 imap-username user) | 890 imap-username user) |
889 (when (and (not imap-password) | 891 (when (and (not imap-password) |
890 (or imap-store-password | 892 (or imap-store-password |
891 (y-or-n-p "Store password for this session? "))) | 893 (y-or-n-p "imap: Store password for this IMAP session? "))) |
892 (setq imap-password passwd))) | 894 (setq imap-password passwd))) |
893 (message "Login failed...") | 895 (message "imap: Login failed...") |
894 (setq passwd nil) | 896 (setq passwd nil) |
895 (setq imap-password nil) | 897 (setq imap-password nil) |
896 (sit-for 1)))) | 898 (sit-for 1)))) |
897 ;; (quit (with-current-buffer buffer | 899 ;; (quit (with-current-buffer buffer |
898 ;; (setq user nil | 900 ;; (setq user nil |
1158 (imap-close buffer) | 1160 (imap-close buffer) |
1159 (let ((name (if (stringp buffer) | 1161 (let ((name (if (stringp buffer) |
1160 buffer | 1162 buffer |
1161 (buffer-name buffer)))) | 1163 (buffer-name buffer)))) |
1162 (kill-buffer buffer) | 1164 (kill-buffer buffer) |
1163 (rename-buffer name)) | 1165 (rename-buffer name) |
1166 ;; set the passed buffer to the current one, | |
1167 ;; so that (imap-opened buffer) later will work | |
1168 (setq buffer (current-buffer))) | |
1164 (message "imap: Reconnecting with stream `%s'...done" | 1169 (message "imap: Reconnecting with stream `%s'...done" |
1165 stream) | 1170 stream) |
1166 (setq imap-stream stream) | 1171 (setq imap-stream stream) |
1167 (setq imap-capability nil) | 1172 (setq imap-capability nil) |
1168 (setq streams nil))) | 1173 (setq streams nil))) |
1171 (setq imap-stream stream) | 1176 (setq imap-stream stream) |
1172 (setq imap-capability nil) | 1177 (setq imap-capability nil) |
1173 (setq streams nil)))))) | 1178 (setq streams nil)))))) |
1174 (when (imap-opened buffer) | 1179 (when (imap-opened buffer) |
1175 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0))) | 1180 (setq imap-mailbox-data (make-vector imap-mailbox-prime 0))) |
1181 ;; (debug "opened+state+auth+buffer" (imap-opened buffer) imap-state imap-auth buffer) | |
1176 (when imap-stream | 1182 (when imap-stream |
1177 buffer)))) | 1183 buffer)))) |
1178 | 1184 |
1179 (defcustom imap-ping-server t | 1185 (defcustom imap-ping-server t |
1180 "If non-nil, check if IMAP is open. | 1186 "If non-nil, check if IMAP is open. |
1215 (or (eq imap-state 'auth) | 1221 (or (eq imap-state 'auth) |
1216 (eq imap-state 'selected) | 1222 (eq imap-state 'selected) |
1217 (eq imap-state 'examine)) | 1223 (eq imap-state 'examine)) |
1218 (make-local-variable 'imap-username) | 1224 (make-local-variable 'imap-username) |
1219 (make-local-variable 'imap-password) | 1225 (make-local-variable 'imap-password) |
1220 (if user (setq imap-username user)) | 1226 (make-local-variable 'imap-last-authenticator) |
1221 (if passwd (setq imap-password passwd)) | 1227 (when user (setq imap-username user)) |
1228 (when passwd (setq imap-password passwd)) | |
1222 (if imap-auth | 1229 (if imap-auth |
1223 (and (funcall (nth 2 (assq imap-auth | 1230 (and (setq imap-last-authenticator |
1224 imap-authenticator-alist)) (current-buffer)) | 1231 (assq imap-auth imap-authenticator-alist)) |
1232 (funcall (nth 2 imap-last-authenticator) (current-buffer)) | |
1225 (setq imap-state 'auth)) | 1233 (setq imap-state 'auth)) |
1226 ;; Choose authenticator. | 1234 ;; Choose authenticator. |
1227 (let ((auths imap-authenticators) | 1235 (let ((auths imap-authenticators) |
1228 auth) | 1236 auth) |
1229 (while (setq auth (pop auths)) | 1237 (while (setq auth (pop auths)) |
1230 ;; OK to use authenticator? | 1238 ;; OK to use authenticator? |
1231 (when (funcall (nth 1 (assq auth imap-authenticator-alist)) (current-buffer)) | 1239 (setq imap-last-authenticator |
1240 (assq auth imap-authenticator-alist)) | |
1241 (when (funcall (nth 1 imap-last-authenticator) (current-buffer)) | |
1232 (message "imap: Authenticating to `%s' using `%s'..." | 1242 (message "imap: Authenticating to `%s' using `%s'..." |
1233 imap-server auth) | 1243 imap-server auth) |
1234 (setq imap-auth auth) | 1244 (setq imap-auth auth) |
1235 (if (funcall (nth 2 (assq auth imap-authenticator-alist)) (current-buffer)) | 1245 (if (funcall (nth 2 imap-last-authenticator) (current-buffer)) |
1236 (progn | 1246 (progn |
1237 (message "imap: Authenticating to `%s' using `%s'...done" | 1247 (message "imap: Authenticating to `%s' using `%s'...done" |
1238 imap-server auth) | 1248 imap-server auth) |
1249 ;; set imap-state correctly on successful auth attempt | |
1250 (setq imap-state 'auth) | |
1251 ;; stop iterating through the authenticator list | |
1239 (setq auths nil)) | 1252 (setq auths nil)) |
1240 (message "imap: Authenticating to `%s' using `%s'...failed" | 1253 (message "imap: Authenticating to `%s' using `%s'...failed" |
1241 imap-server auth))))) | 1254 imap-server auth))))) |
1242 imap-state)))) | 1255 imap-state)))) |
1243 | 1256 |