[gnus git] branch master updated: =1= Implement AUTH=CRAM-MD5, and refactor some code.

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  fd35ba81e6258dd946a1e3c71dca391f64672afa (commit)
      from  91b06d4b174a8a2e578595e95314234e03bdc9f4 (commit)


- Log -----------------------------------------------------------------
commit fd35ba81e6258dd946a1e3c71dca391f64672afa
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Sun Jan 2 21:10:59 2011 +0100

    Implement AUTH=CRAM-MD5, and refactor some code.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 075833e..f3ca14b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
 2011-01-02  Lars Magne Ingebrigtsen  <[email protected]>
 
+	* nnimap.el (nnimap-login): Refactored out into own function, and
+	implement CRAM-MD5.
+	(nnimap-wait-for-line): Refactored out.
+
 	* mm-view.el (mml-smime): Require.
 
 2010-12-20  David Engster  <[email protected]>
diff --git a/lisp/nnimap.el b/lisp/nnimap.el
index 1899b0e..d316015 100644
--- a/lisp/nnimap.el
+++ b/lisp/nnimap.el
@@ -390,17 +390,7 @@ textual parts.")
 				(nnimap-credentials nnimap-address ports)))))
 		  (setq nnimap-object nil)
 		(setq login-result
-		      (if (and (nnimap-capability "AUTH=PLAIN")
-			       (nnimap-capability "LOGINDISABLED"))
-			  (nnimap-command
-			   "AUTHENTICATE PLAIN %s"
-			   (base64-encode-string
-			    (format "\000%s\000%s"
-				    (nnimap-quote-specials (car credentials))
-				    (nnimap-quote-specials (cadr credentials)))))
-			(nnimap-command "LOGIN %S %S"
-					(car credentials)
-					(cadr credentials))))
+		      (nnimap-login (car credentials) (cadr credentials)))
 		(unless (car login-result)
 		  ;; If the login failed, then forget the credentials
 		  ;; that are now possibly cached.
@@ -417,6 +407,33 @@ textual parts.")
 		(nnimap-command "ENABLE QRESYNC"))
 	      (nnimap-process nnimap-object))))))))
 
+(autoload 'rfc2104-hash "rfc2104")
+
+(defun nnimap-login (user password)
+  (cond
+   ((not (nnimap-capability "LOGINDISABLED"))
+    (nnimap-command "LOGIN %S %S" user password))
+   ((nnimap-capability "AUTH=PLAIN")
+    (nnimap-command
+     "AUTHENTICATE PLAIN %s"
+     (base64-encode-string
+      (format "\000%s\000%s"
+	      (nnimap-quote-specials user)
+	      (nnimap-quote-specials password)))))
+   ((nnimap-capability "AUTH=CRAM-MD5")
+    (erase-buffer)
+    (let ((sequence (nnimap-send-command "AUTHENTICATE CRAM-MD5"))
+	  (challenge (nnimap-wait-for-line "^\\+\\(.*\\)\n")))
+      (process-send-string
+       (get-buffer-process (current-buffer))
+       (concat
+	(base64-encode-string
+	 (concat user " "
+		 (rfc2104-hash 'md5 64 16 password
+			       (base64-decode-string challenge))))
+	"\r\n"))
+      (nnimap-wait-for-response sequence)))))
+
 (defun nnimap-quote-specials (string)
   (with-temp-buffer
     (insert string)
@@ -1541,8 +1558,9 @@ textual parts.")
   (nnimap-parse-response))
 
 (defun nnimap-wait-for-connection (&optional regexp)
-  (unless regexp
-    (setq regexp "^[*.] .*\n"))
+  (nnimap-wait-for-line (or regexp "^[*.] .*\n") "[*.] \\([A-Z0-9]+\\)"))
+
+(defun nnimap-wait-for-line (regexp &optional response-regexp)
   (let ((process (get-buffer-process (current-buffer))))
     (goto-char (point-min))
     (while (and (memq (process-status process)
@@ -1551,7 +1569,7 @@ textual parts.")
       (nnheader-accept-process-output process)
       (goto-char (point-min)))
     (forward-line -1)
-    (and (looking-at "[*.] \\([A-Z0-9]+\\)")
+    (and (looking-at (or response-regexp regexp))
 	 (match-string 1))))
 
 (defun nnimap-wait-for-response (sequence &optional messagep)

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog |    4 ++++
 lisp/nnimap.el |   46 ++++++++++++++++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 14 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.