From f14188ce0cdfba2bfe27bcf8e88b3945841a3a4b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 14 Jun 2012 10:09:04 +0200 Subject: [PATCH] Add recent argument to nnimap-find-article-by-message-id Signed-off-by: Julien Danjou --- lisp/nnimap.el | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lisp/nnimap.el b/lisp/nnimap.el index 1db8640..e50fc0e 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -123,6 +123,10 @@ will fetch all parts that have types that match that string. A likely value would be \"text/\" to automatically fetch all textual parts.") +(defcustom nnimap-request-move-articles-find-limit nil + "Limit the number of articles to look for after moving an article." + :type 'integer) + (defvar nnimap-process nil) (defvar nnimap-status-string "") @@ -867,7 +871,8 @@ textual parts.") (cons internal-move-group (or (nnimap-find-uid-response "COPYUID" (cadr result)) (nnimap-find-article-by-message-id - internal-move-group server message-id))))) + internal-move-group server message-id + nnimap-request-move-articles-find-limit))))) ;; Move the article to a different method. (let ((result (eval accept-form))) (when result @@ -969,21 +974,28 @@ 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 limit + (format " %s:*" (- number-of-article limit)) + "") + 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 limit + (nnimap-find-article-by-message-id group server message-id)))))))) (defun nnimap-delete-article (articles) (with-current-buffer (nnimap-buffer) -- 1.7.10