* imap.el (imap-string-to-integer): Fix typo.
authorReiner Steib <Reiner.Steib@gmx.de>
Thu, 1 Jan 2009 18:24:40 +0000 (18:24 +0000)
committerReiner Steib <Reiner.Steib@gmx.de>
Thu, 1 Jan 2009 18:24:40 +0000 (18:24 +0000)
(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.

lisp/ChangeLog
lisp/imap.el
lisp/nnimap.el

index 28dd79b..f4ae9f6 100644 (file)
@@ -1,3 +1,11 @@
+2009-01-01  Dave Love  <fx@gnu.org>
+
+       * 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  <Reiner.Steib@gmx.de>
 
        * dns.el (dns-set-servers): Check "Address".  Fix typo.
index f0161b3..053a95a 100644 (file)
@@ -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 <simon@josefsson.org>
 ;; Keywords: mail
@@ -1772,9 +1772,38 @@ is non-nil return these properties."
   (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 @@ is non-nil return these properties."
          (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 @@ first element.  The rest of list contains the saved articles' UIDs."
          (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 898bec8..2a22ee7 100644 (file)
@@ -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 <jas@pdc.kth.se>
 ;;         Jim Radford <radford@robby.caltech.edu>
@@ -555,8 +555,7 @@ If EXAMINE is non-nil the group is selected read-only."
              (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)))