Importing Gnus v5.8.4.
[elisp/gnus.git-] / lisp / nnimap.el
index 7581479..9a8bc3f 100644 (file)
@@ -126,6 +126,13 @@ This variable can also have a function as its value, the function will
 be called with the headers narrowed and should return a group where it
 thinks the article should be splitted to.")
 
+(defvar nnimap-split-predicate "UNSEEN UNDELETED"
+  "The predicate used to find articles to split.
+If you use another IMAP client to peek on articles but always would
+like nnimap to split them once it's started, you could change this to
+\"UNDELETED\". Other available predicates are available in
+RFC2060 section 6.4.4.")
+
 (defvar nnimap-split-fancy nil
   "Like `nnmail-split-fancy', which see.")
 
@@ -361,9 +368,10 @@ If EXAMINE is non-nil the group is selected read-only."
                                 nnimap-progress-how-often)
                              nnimap-progress-chars)))
   (with-current-buffer nntp-server-buffer
-    (let (headers lines chars uid)
+    (let (headers lines chars uid mbx)
       (with-current-buffer nnimap-server-buffer
        (setq uid imap-current-message
+             mbx imap-current-mailbox
              headers (if (imap-capability 'IMAP4rev1)
                          ;; xxx don't just use car? alist doesn't contain
                          ;; anything else now, but it might...
@@ -376,10 +384,14 @@ If EXAMINE is non-nil the group is selected read-only."
         (buffer-disable-undo)
         (insert headers)
         (nnheader-ms-strip-cr)
+        (nnheader-fold-continuation-lines)
+        (subst-char-in-region (point-min) (point-max) ?\t ? )
         (let ((head (nnheader-parse-head 'naked)))
           (mail-header-set-number head uid)
           (mail-header-set-chars head chars)
           (mail-header-set-lines head lines)
+          (mail-header-set-xref
+           head (format "%s %s:%d" (system-name) mbx uid))
           head))))))
 
 (defun nnimap-retrieve-which-headers (articles fetch-old)
@@ -492,8 +504,8 @@ If EXAMINE is non-nil the group is selected read-only."
                    ;; remove nov's for articles which has expired on server
                    (goto-char (point-min))
                    (dolist (uid (gnus-set-difference articles uids))
-                     (when (re-search-forward (format "^%d\t" uid) nil t)
-                       (gnus-delete-line)))))
+                      (when (re-search-forward (format "^%d\t" uid) nil t)
+                        (gnus-delete-line)))))
              ;; nothing cached, fetch whole range from server
              (nnimap-retrieve-headers-from-server
               (cons low high) group server))
@@ -602,8 +614,8 @@ function is generally only called when Gnus is shutting down."
     (nnheader-ms-strip-cr)
     (funcall nnimap-callback-callback-function t)))
 
-(defun nnimap-request-article-part (article part prop
-                                           &optional group server to-buffer)
+(defun nnimap-request-article-part (article part prop &optional
+                                            group server to-buffer detail)
   (when (nnimap-possibly-change-group group server)
     (let ((article (if (stringp article)
                       (car-safe (imap-search
@@ -615,9 +627,12 @@ function is generally only called when Gnus is shutting down."
        (if (not nnheader-callback-function)
            (with-current-buffer (or to-buffer nntp-server-buffer)
              (erase-buffer)
-             (insert (nnimap-demule (imap-fetch article part prop nil
-                                                nnimap-server-buffer)))
-             (nnheader-ms-strip-cr)
+              (let ((data (imap-fetch article part prop nil
+                                      nnimap-server-buffer)))
+                (insert (nnimap-demule (if detail
+                                           (nth 2 (car data))
+                                         data))))
+              (nnheader-ms-strip-cr)
              (gnus-message 9 "nnimap: Fetching (part of) article %d...done"
                            article)
              (if (bobp)
@@ -634,16 +649,25 @@ function is generally only called when Gnus is shutting down."
   t)
 
 (deffoo nnimap-request-article (article &optional group server to-buffer)
-  (nnimap-request-article-part
-   article "RFC822.PEEK" 'RFC822 group server to-buffer))
+  (if (imap-capability 'IMAP4rev1 nnimap-server-buffer)
+      (nnimap-request-article-part
+       article "BODY.PEEK[]" 'BODYDETAIL group server to-buffer 'detail)
+    (nnimap-request-article-part
+     article "RFC822.PEEK" 'RFC822 group server to-buffer)))
 
 (deffoo nnimap-request-head (article &optional group server to-buffer)
-  (nnimap-request-article-part
-   article "RFC822.HEADER" 'RFC822.HEADER group server to-buffer))
+  (if (imap-capability 'IMAP4rev1 nnimap-server-buffer)
+      (nnimap-request-article-part
+       article "BODY.PEEK[HEADER]" 'BODYDETAIL group server to-buffer 'detail)
+    (nnimap-request-article-part
+     article "RFC822.HEADER" 'RFC822.HEADER group server to-buffer)))
 
 (deffoo nnimap-request-body (article &optional group server to-buffer)
-  (nnimap-request-article-part
-   article "RFC822.TEXT.PEEK" 'RFC822.TEXT group server to-buffer))
+  (if (imap-capability 'IMAP4rev1 nnimap-server-buffer)
+      (nnimap-request-article-part
+       article "BODY.PEEK[TEXT]" 'BODYDETAIL group server to-buffer 'detail)
+    (nnimap-request-article-part
+     article "RFC822.TEXT.PEEK" 'RFC822.TEXT group server to-buffer)))
 
 (deffoo nnimap-request-group (group &optional server fast)
   (nnimap-request-update-info-internal
@@ -889,7 +913,7 @@ function is generally only called when Gnus is shutting down."
          ;; find split rule for this server / inbox
          (when (setq rule (nnimap-split-find-rule server inbox))
            ;; iterate over articles
-           (dolist (article (imap-search "UNSEEN UNDELETED"))
+           (dolist (article (imap-search nnimap-split-predicate))
              (when (nnimap-request-head article)
                ;; copy article to right group(s)
                (setq removeorig nil)