Changes committed gnus/lisp (ChangeLog imap.el nnimap.el)

"Reiner Steib" <[email protected]> Thu, 01 Jan 2009 19:24:40 +0100
Newsgroups gmane.emacs.gnus.commits
Message-ID <[email protected]>
Modified: ChangeLog imap.el nnimap.el

* imap.el (imap-string-to-integer): Fix typo.
(imap-fetch-safe): New function.
(imap-message-copyuid-1, imap-message-appenduid-1): Use it.

* nnimap.el (nnimap-find-minmax-uid): Use imap-fetch-safe.


Index: ChangeLog
diff -u gnus/lisp/ChangeLog:7.1960 gnus/lisp/ChangeLog:7.1961
--- ChangeLog:7.1960	Fri Dec 26 18:23:53 2008
+++ ChangeLog	Thu Jan  1 19:24:40 2009
@@ -1,3 +1,11 @@
+2009-01-01  Dave Love  <[email protected]>
+
+	* imap.el (imap-string-to-integer): Fix typo.
+	(imap-fetch-safe): New function.
+	(imap-message-copyuid-1, imap-message-appenduid-1): Use it.
+
+	* nnimap.el (nnimap-find-minmax-uid): Use imap-fetch-safe.
+
 2008-12-26  Reiner Steib  <[email protected]>
 
 	* dns.el (dns-set-servers): Check "Address".  Fix typo.
Index: imap.el
diff -u gnus/lisp/imap.el:7.48 gnus/lisp/imap.el:7.49
--- imap.el:7.48	Mon Dec 22 23:38:50 2008
+++ imap.el	Thu Jan  1 19:24:40 2009
@@ -1,7 +1,7 @@
 ;;; imap.el --- imap library
 
 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <[email protected]>
 ;; Keywords: mail
@@ -1772,9 +1772,38 @@
   (let ((number (string-to-number string base)))
     (if (> number most-positive-fixnum)
 	(error
-	 (format "String %s cannot be converted to a lisp integer" number))
+	 (format "String %s cannot be converted to a Lisp integer" number))
       number)))
 
+(defun imap-fetch-safe (uids props &optional receive nouidfetch buffer)
+  "Like `imap-fetch', but DTRT with Exchange 2007 bug.
+However, UIDS here is a cons, where the car is the canonical form
+of the UIDS specification, and the cdr is the one which works with
+Exchange 2007 or, potentially, other buggy servers.
+See `imap-enable-exchange-bug-workaround'."
+  ;; We don't unconditionally use the alternative (valid) form, since
+  ;; this is said to be significantly inefficient.  The first time we
+  ;; get here for a given, we'll try the canonical form.  If we get
+  ;; the known error from the buggy server, set the flag
+  ;; buffer-locally (to account for connexions to multiple servers),
+  ;; then re-try with the alternative UIDS spec.
+  (condition-case data
+      (imap-fetch (if imap-enable-exchange-bug-workaround
+		      (cdr uids)
+		    (car uids))
+		  props receive nouidfetch buffer)
+    (error
+     (if (and (not imap-enable-exchange-bug-workaround)
+	      (string-match
+	       "The specified message set is invalid"
+	       (cadr data)))
+	 (with-current-buffer (or buffer (current-buffer))
+	   (set (make-local-variable
+		 'imap-enable-exchange-bug-workaround)
+		t)
+	   (imap-fetch (cdr uids) props receive nouidfetch))
+       (signal (car data) (cdr data))))))
+
 (defun imap-message-copyuid-1 (mailbox)
   (if (imap-capability 'UIDPLUS)
       (list (nth 0 (imap-mailbox-get-1 'copyuid mailbox))
@@ -1784,11 +1813,7 @@
 	  (imap-message-data (make-vector 2 0)))
       (when (imap-mailbox-examine-1 mailbox)
 	(prog1
-	    (and (imap-fetch
-		  ;; why the switch here, since they seem to be
-		  ;; equivalent, and ~ no-one is going to find this
-		  ;; switch?  -- fx
-		  (if imap-enable-exchange-bug-workaround "*:*" "*") "UID")
+	    (and (imap-fetch-safe '("*" . "*:*") "UID")
 		 (list (imap-mailbox-get-1 'uidvalidity mailbox)
 		       (apply 'max (imap-message-map
 				    (lambda (uid prop) uid) 'UID))))
@@ -1832,8 +1857,7 @@
 	  (imap-message-data (make-vector 2 0)))
       (when (imap-mailbox-examine-1 mailbox)
 	(prog1
-	    (and (imap-fetch
-		  (if imap-enable-exchange-bug-workaround "*:*" "*") "UID")
+	    (and (imap-fetch-safe '("*" "*:*") "UID")
 		 (list (imap-mailbox-get-1 'uidvalidity mailbox)
 		       (apply 'max (imap-message-map
 				    (lambda (uid prop) uid) 'UID))))
Index: nnimap.el
diff -u gnus/lisp/nnimap.el:7.55 gnus/lisp/nnimap.el:7.56
--- nnimap.el:7.55	Wed Dec  3 21:33:34 2008
+++ nnimap.el	Thu Jan  1 19:24:40 2009
@@ -1,7 +1,7 @@
 ;;; nnimap.el --- imap backend for Gnus
 
 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;   2007, 2008  Free Software Foundation, Inc.
+;;   2007, 2008, 2009  Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <[email protected]>
 ;;         Jim Radford <[email protected]>
@@ -555,8 +555,7 @@
 	      (imap-mailbox-select group examine))
       (let (minuid maxuid)
 	(when (> (imap-mailbox-get 'exists) 0)
-	  (imap-fetch (if imap-enable-exchange-bug-workaround "1,*:*" "1,*")
-		      "UID" nil 'nouidfetch)
+	  (imap-fetch-safe '("1,*" . "1,*:*") "UID" nil 'nouidfetch)
 	  (imap-message-map (lambda (uid Uid)
 			      (setq minuid (if minuid (min minuid uid) uid)
 				    maxuid (if maxuid (max maxuid uid) uid)))