| author | Julien Danjou <julien@danjou.info> | 2012-06-14 08:09:04 (GMT) |
|---|---|---|
| committer | Dave Abrahams <dave@boostpro.com> | 2012-09-01 04:49:56 (GMT) |
| commit | b3f5f69040ed69dea5264c43f6c32e329107c62f (patch) (side-by-side diff) | |
| tree | 8f5f2b79b9645cbde743cf3ba37d27dc1bbff509 | |
| parent | 2fb0b7ac1adacec45fd50f7aa7de5ea57fda4d19 (diff) | |
| download | gnus-b3f5f69040ed69dea5264c43f6c32e329107c62f.zip | |
Add recent argument to nnimap-find-article-by-message-id
Signed-off-by: Julien Danjou <julien@danjou.info>
Conflicts:
lisp/ChangeLog
lisp/nnimap.el
| -rw-r--r-- | lisp/nnimap.el | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/lisp/nnimap.el b/lisp/nnimap.el index 9b460f3..4952c4e 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -980,21 +980,31 @@ textual parts.") (cdr (assoc "SEARCH" (cdr result)))))))))) -(defun nnimap-find-article-by-message-id (group server message-id) - "Search for message with MESSAGE-ID in GROUP from SERVER." +(defun nnimap-find-article-by-message-id (group server message-id &optional limit) + "Search for message with MESSAGE-ID in GROUP from SERVER. +If LIMIT, first try to limit the search to the N last articles." (with-current-buffer (nnimap-buffer) (erase-buffer) - (nnimap-change-group group server nil t) - (let ((sequence - (nnimap-send-command "UID SEARCH HEADER Message-Id %S" message-id)) - article result) - (setq result (nnimap-wait-for-response sequence)) - (when (and result - (car (setq result (nnimap-parse-response)))) - ;; Select the last instance of the message in the group. - (and (setq article - (car (last (cdr (assoc "SEARCH" (cdr result)))))) - (string-to-number article)))))) + (let* ((number-of-article + (catch 'found + (dolist (result (cdr (nnimap-change-group group server nil t))) + (when (equal "EXISTS" (cadr result)) + (throw 'found (car result)))))) + (sequence + (nnimap-send-command "UID SEARCH%s HEADER Message-Id %S" + (if (and limit number-of-article) + ;; The -1 is because IMAP message + ;; numbers are one-based rather than + ;; zero-based. + (format " %s:*" (- (string-to-number number-of-article) limit -1)) + "") + message-id))) + (when (nnimap-wait-for-response sequence) + (let ((article (car (last (cdr (assoc "SEARCH" (nnimap-parse-response))))))) + (if article + (string-to-number article) + (when (and limit number-of-article) + (nnimap-find-article-by-message-id group server message-id)))))))) (defun nnimap-delete-article (articles) (with-current-buffer (nnimap-buffer) |
