likely value would be \"text/\" to automatically fetch all
textual parts.")
+(defgroup nnimap nil
+ "IMAP for Gnus."
+ :group 'gnus)
+
+(defcustom nnimap-request-articles-find-limit nil
+ "Limit the number of articles to look for after moving an article."
+ :type 'integer
+ :version "24.2"
+ :group 'nnimap)
+
(defvar nnimap-process nil)
(defvar nnimap-status-string "")
(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-articles-find-limit)))))
;; Move the article to a different method.
(let ((result (eval accept-form)))
(when result
(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)
(cons group
(or (nnimap-find-uid-response "APPENDUID" (car result))
(nnimap-find-article-by-message-id
- group server message-id))))))))))
+ group server message-id
+ nnimap-request-articles-find-limit))))))))))
(defun nnimap-process-quirk (greeting-match type data)
(when (and (nnimap-greeting nnimap-object)
(cdr (assoc "SEARCH" (cdr result))))))
nil t))))))
-(defun nnimap-change-group (group server &optional no-reconnect read-only)
+(defun nnimap-change-group (group &optional server no-reconnect read-only)
"Change group to GROUP.
If SERVER is set, check that server is connected, otherwise retry
to reconnect, unless NO-RECONNECT is set to t.
(defvar nnimap-record-commands nil
"If non-nil, log commands to the \"*imap log*\" buffer.")
+(defun nnimap-log-buffer ()
+ (let ((name "*imap log*"))
+ (or (get-buffer name)
+ (with-current-buffer (get-buffer-create name)
+ (when (boundp 'window-point-insertion-type)
+ (make-local-variable 'window-point-insertion-type)
+ (setq window-point-insertion-type t))
+ (current-buffer)))))
+
(defun nnimap-log-command (command)
(when nnimap-record-commands
- (with-current-buffer (get-buffer-create "*imap log*")
+ (with-current-buffer (nnimap-log-buffer)
(goto-char (point-max))
(insert (format-time-string "%H:%M:%S")
- " [" nnimap-address "] "
- (if nnimap-inhibit-logging
- "(inhibited)\n"
- command))))
+ " [" nnimap-address "] "
+ (if nnimap-inhibit-logging
+ "(inhibited)\n"
+ command))))
command)
(defun nnimap-command (&rest args)
(forward-line 1)))
(buffer-substring (point) end))))
-(defun nnimap-get-responses (sequences)
- (let (responses)
- (dolist (sequence sequences)
- (goto-char (point-min))
- (when (re-search-forward (format "^%d " sequence) nil t)
- (push (list sequence (nnimap-parse-response))
- responses)))
- responses))
-
(defvar nnimap-incoming-split-list nil)
(defun nnimap-fetch-inbox (articles)