From 5a0a6cc1fef60642ac30c3e24e06b8a45c994612 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 4 Feb 2014 19:16:31 -0800 Subject: [PATCH] Download the Cloud chunks * nnimap.el (nnimap-request-articles): New command to download several articles at once. --- lisp/ChangeLog | 3 +++ lisp/gnus-cloud.el | 28 ++++++++++++++++++++++------ lisp/nnimap.el | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 40d694237..fa9bfaea6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2014-02-05 Lars Ingebrigtsen + * 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. diff --git a/lisp/gnus-cloud.el b/lisp/gnus-cloud.el index f9f7fdcc1..9739f7c53 100644 --- a/lisp/gnus-cloud.el +++ b/lisp/gnus-cloud.el @@ -26,6 +26,7 @@ (eval-when-compile (require 'cl)) (require 'parse-time) +(require 'nnimap) (defgroup gnus-cloud nil "Syncing Gnus data via IMAP." @@ -274,7 +275,10 @@ (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) @@ -282,11 +286,7 @@ 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)) @@ -302,6 +302,22 @@ (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 diff --git a/lisp/nnimap.el b/lisp/nnimap.el index ff200753d..d0b1d6c40 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -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 -- 2.25.1