* elmo-imap4.el (elmo-imap4-folder-list-flagged)
[elisp/wanderlust.git] / elmo / elmo-imap4.el
index e377dc6..18a3027 100644 (file)
@@ -852,11 +852,15 @@ Returns response value if selecting folder succeed. "
     (t
      (elmo-imap4-flag-to-imap-search-key flag))))
 
-(defun elmo-imap4-folder-list-flagged (folder flag)
+(defun elmo-imap4-folder-list-flagged (folder flag &optional type)
   "List flagged message numbers in the FOLDER.
-FLAG is one of the `unread', `read', `important', `answered', `any'."
+FLAG is one of the `unread', `read', `important', `answered',
+`any'.
+When optional argument TYPE is symbol 'unmatch, negate search
+condition."
   (let ((session (elmo-imap4-get-session folder))
-       (criteria (elmo-imap4-flag-to-imap-criteria flag)))
+       (criteria (concat (if (eq type 'unmatch) "not " "")
+                         (elmo-imap4-flag-to-imap-criteria flag))))
     (if (elmo-imap4-session-flag-available-p session flag)
        (elmo-imap4-list folder criteria)
       ;; List flagged messages in the msgdb.
@@ -1145,7 +1149,15 @@ If CHOP-LENGTH is not specified, message set is not chopped."
                       (if (sasl-step-data step)
                           (elmo-base64-encode-string (sasl-step-data step)
                                                      'no-line-break)
-                        ""))))))))))))
+                        "")))))))
+;; Some servers return reduced capabilities when client asks for them
+;; before login. It might be a good idea to ask them again, otherwise
+;; we can miss some useful feature.
+        (elmo-imap4-session-set-capability-internal
+         session
+         (elmo-imap4-response-value
+          (elmo-imap4-send-command-wait session "capability")
+          'capability)))))))
 
 (luna-define-method elmo-network-setup-session ((session
                                                 elmo-imap4-session))
@@ -2279,7 +2291,7 @@ If optional argument REMOVE is non-nil, remove FLAG."
        numbers))
      ((string= "flag" search-key)
       (elmo-imap4-folder-list-flagged
-       folder (intern (elmo-filter-value filter))))
+       folder (intern (elmo-filter-value filter)) (elmo-filter-type filter)))
      ((or (string= "since" search-key)
          (string= "before" search-key))
       (setq search-key (concat "sent" search-key)