Download the Cloud chunks
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 5 Feb 2014 03:16:31 +0000 (19:16 -0800)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 5 Feb 2014 03:16:31 +0000 (19:16 -0800)
* nnimap.el (nnimap-request-articles): New command to download several
articles at once.

lisp/ChangeLog
lisp/gnus-cloud.el
lisp/nnimap.el

index 40d6942..fa9bfae 100644 (file)
@@ -1,5 +1,8 @@
 2014-02-05  Lars Ingebrigtsen  <larsi@gnus.org>
 
+       * nnimap.el (nnimap-request-articles): New command to download several
+       articles at once.
+
        * gnus.el (gnus-variable-list): Save Cloud variables.
 
        * gnus-int.el (gnus-request-accept-article): Doc fix.
index f9f7fdc..9739f7c 100644 (file)
@@ -26,6 +26,7 @@
 
 (eval-when-compile (require 'cl))
 (require 'parse-time)
+(require 'nnimap)
 
 (defgroup gnus-cloud nil
   "Syncing Gnus data via IMAP."
        (while (and (not (eobp))
                    (setq head (nnheader-parse-head)))
          (push head headers))))
-    (nreverse headers)))
+    (sort (nreverse headers)
+         (lambda (h1 h2)
+           (> (gnus-cloud-chunk-sequence (mail-header-subject h1))
+              (gnus-cloud-chunk-sequence (mail-header-subject h2)))))))
 
 (defun gnus-cloud-chunk-sequence (string)
   (if (string-match "sequence: \\([0-9]+\\)" string)
     0))
 
 (defun gnus-cloud-prune-old-chunks (headers)
-  (let ((headers
-        (sort (reverse headers)
-              (lambda (h1 h2)
-                (> (gnus-cloud-chunk-sequence (mail-header-subject h1))
-                   (gnus-cloud-chunk-sequence (mail-header-subject h2))))))
+  (let ((headers (reverse headers))
        (found nil))
   (while (and headers
              (not found))
             (nreverse headers))
      (gnus-group-full-name gnus-cloud-group-name gnus-cloud-method)))))
 
+(defun gnus-cloud-download-data ()
+  (let ((articles nil)
+       chunks)
+    (dolist (header (gnus-cloud-available-chunks))
+      (when (> (gnus-cloud-chunk-sequence (mail-header-subject header))
+              gnus-cloud-sequence)
+       (push (mail-header-number header) articles)))
+    (when articles
+      (nnimap-request-articles (nreverse articles) gnus-cloud-group-name)
+      (with-current-buffer nntp-server-buffer
+       (goto-char (point-min))
+       (while (re-search-forward "^Version " nil t)
+         (beginning-of-line)
+         (push (gnus-cloud-parse-chunk) chunks)
+         (forward-line 1))))))
+
 (provide 'gnus-cloud)
 
 ;;; gnus-cloud.el ends here
index ff20075..d0b1d6c 100644 (file)
@@ -624,6 +624,26 @@ textual parts.")
            (nnheader-ms-strip-cr)
            (cons group article)))))))
 
+(deffoo nnimap-request-articles (articles &optional group server)
+  (when group
+    (setq group (nnimap-decode-gnus-group group)))
+  (with-current-buffer nntp-server-buffer
+    (let ((result (nnimap-change-group group server)))
+      (when result
+       (erase-buffer)
+       (with-current-buffer (nnimap-buffer)
+         (erase-buffer)
+         (when (nnimap-command
+                (if (nnimap-ver4-p)
+                    "UID FETCH %s BODY.PEEK[]"
+                  "UID FETCH %s RFC822.PEEK")
+                (nnimap-article-ranges (gnus-compress-sequence articles)))
+           (let ((buffer (current-buffer)))
+             (with-current-buffer nntp-server-buffer
+               (nnheader-insert-buffer-substring buffer)
+               (nnheader-ms-strip-cr)))
+           t))))))
+
 (defun nnimap-get-whole-article (article &optional command)
   (let ((result
         (nnimap-command