* nnimap.el (nnimap-need-unselect-to-notice-new-mail)
[gnus] / lisp / nnimap.el
index 724c192..d597770 100644 (file)
 
 ;;; Code:
 
-(eval-and-compile
-  (require 'cl)
-  (require 'imap))
-
+(require 'imap)
 (require 'nnoo)
 (require 'nnmail)
 (require 'nnheader)
@@ -95,7 +92,7 @@ If nil, the first match found will be used."
   :type 'boolean)
 
 (defcustom nnimap-split-inbox nil
-  "*Name of mailbox to split mail from.
+  "Name of mailbox to split mail from.
 
 Mail is read from this mailbox and split according to rules in
 `nnimap-split-rule'.
@@ -197,6 +194,28 @@ RFC2060 section 6.4.4."
   :group 'nnimap
   :type 'sexp)
 
+;; Performance / bug workaround variables
+
+(defcustom nnimap-close-asynchronous nil
+  "Close mailboxes asynchronously in `nnimap-close-group'.
+This means that errors cought by nnimap when closing the mailbox will
+not prevent Gnus from updating the group status, which may be harmful.
+However, it increases speed."
+  :type 'boolean
+  :group 'nnimap)
+
+(defcustom nnimap-dont-close t
+  "Never close mailboxes.
+This increases the speed of closing mailboxes (quiting group) but may
+decrease the speed of selecting another mailbox later.  Re-selecting
+the same mailbox will be faster though."
+  :type 'boolean
+  :group 'nnimap)
+
+(defvoo nnimap-need-unselect-to-notice-new-mail nil
+  "Unselect mailboxes before looking for new mail in them.
+Some servers seem to need this under some circumstances.")
+
 ;; Authorization / Privacy variables
 
 (defvoo nnimap-auth-method nil
@@ -300,7 +319,7 @@ similar which you wouldn't want to set up a mailing list for, you can
 use this to make replies go directly to the group.")
 
 (defvoo nnimap-expunge-search-string "UID %s NOT SINCE %s"
-  "*IMAP search command to use for articles that are to be expired.
+  "IMAP search command to use for articles that are to be expired.
 The first %s is replaced by a UID set of articles to search on,
 and the second %s is replaced by a date criterium.
 
@@ -310,7 +329,7 @@ instead of the internal date of messages.  See section 6.4.4 of RFC
 2060 for more information on valid strings.")
 
 (defvoo nnimap-importantize-dormant t
-  "*If non-nil, mark \"dormant\" articles as \"ticked\" for other IMAP clients.
+  "If non-nil, mark \"dormant\" articles as \"ticked\" for other IMAP clients.
 Note that within Gnus, dormant articles will still (only) be
 marked as ticked.  This is to make \"dormant\" articles stand out,
 just like \"ticked\" articles, in other IMAP clients.")
@@ -414,16 +433,18 @@ If SERVER is nil, uses the current server."
 (defun nnimap-before-find-minmax-bugworkaround ()
   "Function called before iterating through mailboxes with
 `nnimap-find-minmax-uid'."
-  ;; XXX this is for UoW imapd problem, it doesn't notice new mail in
-  ;; currently selected mailbox without a re-select/examine.
-  (or (null (imap-current-mailbox nnimap-server-buffer))
-      (imap-mailbox-unselect nnimap-server-buffer)))
+  (when nnimap-need-unselect-to-notice-new-mail
+    ;; XXX this is for UoW imapd problem, it doesn't notice new mail in
+    ;; currently selected mailbox without a re-select/examine.
+    (or (null (imap-current-mailbox nnimap-server-buffer))
+       (imap-mailbox-unselect nnimap-server-buffer))))
 
 (defun nnimap-find-minmax-uid (group &optional examine)
   "Find lowest and highest active article nummber in GROUP.
 If EXAMINE is non-nil the group is selected read-only."
   (with-current-buffer nnimap-server-buffer
-    (when (imap-mailbox-select group examine)
+    (when (or (string= group (imap-current-mailbox))
+             (imap-mailbox-select group examine))
       (let (minuid maxuid)
        (when (> (imap-mailbox-get 'exists) 0)
          (imap-fetch "1,*" "UID" nil 'nouidfetch)
@@ -480,7 +501,7 @@ If EXAMINE is non-nil the group is selected read-only."
              mbx imap-current-mailbox
              headers (nnimap-demule
                       (if (imap-capability 'IMAP4rev1)
-                     ;; xxx don't just use car? alist doesn't contain
+                          ;; xxx don't just use car? alist doesn't contain
                           ;; anything else now, but it might...
                           (nth 2 (car (imap-message-get uid 'BODYDETAIL)))
                         (imap-message-get uid 'RFC822.HEADER)))
@@ -838,15 +859,16 @@ function is generally only called when Gnus is shutting down."
     (when (and (imap-opened)
               (nnimap-possibly-change-group group server))
       (case nnimap-expunge-on-close
-       ('always (imap-mailbox-expunge)
-                (imap-mailbox-close))
-       ('ask (if (and (imap-search "DELETED")
-                      (gnus-y-or-n-p (format
-                                      "Expunge articles in group `%s'? "
-                                      imap-current-mailbox)))
-                 (progn (imap-mailbox-expunge)
-                        (imap-mailbox-close))
-               (imap-mailbox-unselect)))
+       (always (unless nnimap-dont-close
+                 (imap-mailbox-expunge nnimap-close-asynchronous)
+                 (imap-mailbox-close nnimap-close-asynchronous)))
+       (ask (if (and (imap-search "DELETED")
+                     (gnus-y-or-n-p (format "Expunge articles in group `%s'? "
+                                            imap-current-mailbox)))
+                (unless nnimap-dont-close
+                  (imap-mailbox-expunge nnimap-close-asynchronous)
+                  (imap-mailbox-close nnimap-close-asynchronous))
+              (imap-mailbox-unselect)))
        (t (imap-mailbox-unselect)))
       (not imap-current-mailbox))))
 
@@ -1308,7 +1330,7 @@ function is generally only called when Gnus is shutting down."
 
 (defun nnimap-expunge (mailbox server)
   (when (nnimap-possibly-change-group mailbox server)
-    (imap-mailbox-expunge nnimap-server-buffer)))
+    (imap-mailbox-expunge nil nnimap-server-buffer)))
 
 (defun nnimap-acl-get (mailbox server)
   (when (nnimap-possibly-change-server server)