(defvoo nnimap-stream 'ssl
"How nnimap will talk to the IMAP server.
-Values are `ssl' and `network'.")
+Values are `ssl', `network' or `shell'.")
(defvoo nnimap-shell-program (if (boundp 'imap-shell-program)
(if (listp imap-shell-program)
"Internal variable with default value for `nnimap-split-download-body'.")
(defstruct nnimap
- group process commands capabilities select-result newlinep)
+ group process commands capabilities select-result newlinep server)
(defvar nnimap-object nil)
(defun nnimap-transform-headers ()
(goto-char (point-min))
- (let (article bytes lines size)
+ (let (article bytes lines size string)
(block nil
(while (not (eobp))
(while (not (looking-at "^\\* [0-9]+ FETCH.*UID \\([0-9]+\\)"))
(delete-region (point) (progn (forward-line 1) (point)))
(when (eobp)
(return)))
- (setq article (match-string 1)
- bytes (nnimap-get-length)
+ (setq article (match-string 1))
+ ;; Unfold quoted {number} strings.
+ (while (re-search-forward "[^]] {\\([0-9]+\\)}\r\n"
+ (1+ (line-end-position)) t)
+ (setq size (string-to-number (match-string 1)))
+ (delete-region (+ (match-beginning 0) 2) (point))
+ (setq string (delete-region (point) (+ (point) size)))
+ (insert (format "%S" string)))
+ (setq bytes (nnimap-get-length)
lines nil)
(beginning-of-line)
(setq size
(match-string 1)))
(beginning-of-line)
(when (search-forward "BODYSTRUCTURE" (line-end-position) t)
- (let ((structure (ignore-errors (read (current-buffer)))))
+ (let ((structure (ignore-errors
+ (read (current-buffer)))))
(while (and (consp structure)
(not (stringp (car structure))))
(setq structure (car structure)))
(buffer-disable-undo)
(gnus-add-buffer)
(set (make-local-variable 'after-change-functions) nil)
- (set (make-local-variable 'nnimap-object) (make-nnimap))
+ (set (make-local-variable 'nnimap-object)
+ (make-nnimap :server (nnoo-current-server 'nnimap)))
(push (list buffer (current-buffer)) nnimap-connection-alist)
(current-buffer)))
(when info
(nnimap-update-infos marks (list info)))
(goto-char (point-max))
- (cond
- (marks
- (setq high (nth 3 (car marks))
- low (nth 4 (car marks))))
- ((re-search-backward "UIDNEXT \\([0-9]+\\)" nil t)
- (setq high (1- (string-to-number (match-string 1)))
- low 1)))))
+ (let ((uidnext (nth 5 (car marks))))
+ (setq high (if uidnext
+ (1- uidnext)
+ (nth 3 (car marks)))
+ low (or (nth 4 (car marks)) uidnext)))))
(erase-buffer)
(insert
(format
nil)
(t
(let ((deletable-articles
- (if force
+ (if (or force
+ (eq nnmail-expiry-wait 'immediate))
articles
(gnus-sorted-intersection
articles
(deffoo nnimap-request-scan (&optional group server)
(when (and (nnimap-possibly-change-group nil server)
- (equal group nnimap-inbox)
nnimap-inbox
nnimap-split-methods)
(message "nnimap %s splitting mail..." server)
(defun nnimap-update-info (info marks)
(when marks
- (destructuring-bind (existing flags high low uidnext start-article) marks
+ (destructuring-bind (existing flags high low uidnext start-article
+ permanent-flags) marks
(let ((group (gnus-info-group info))
(completep (and start-article
(= start-article 1))))
+ (when uidnext
+ (setq high (1- uidnext)))
;; First set the active ranges based on high/low.
(if (or completep
(not (gnus-active group)))
(gnus-set-active group
- (if high
+ (if (and low high)
(cons low high)
;; No articles in this group.
- (cons (1- uidnext) uidnext)))
- (setcdr (gnus-active group) high))
+ (cons uidnext (1- uidnext))))
+ (setcdr (gnus-active group) (or high (1- uidnext))))
+ (unless high
+ (setq high (1- uidnext)))
;; Then update the list of read articles.
(let* ((unread
(gnus-compress-sequence
(new-marks
(gnus-compress-sequence
(cdr (or (assoc (caddr type) flags) ; %Flagged
+ (assoc (intern (cadr type) obarray) flags)
(assoc (cadr type) flags)))))) ; "\Flagged"
(setq marks (delq old-marks marks))
(pop old-marks)
(push (list group info active) nnimap-current-infos))))
(defun nnimap-flags-to-marks (groups)
- (let (data group totalp uidnext articles start-article mark)
+ (let (data group totalp uidnext articles start-article mark permanent-flags)
(dolist (elem groups)
(setq group (car elem)
uidnext (nth 1 elem)
(setq mark (assoc flag marks))
(if (not mark)
(push (list flag (car article)) marks)
- (setcdr mark (cons (car article) (cdr mark)))))
- (push (list group existing marks high low uidnext start-article)
- data))))
+ (setcdr mark (cons (car article) (cdr mark))))))
+ (push (list group existing marks high low uidnext start-article
+ permanent-flags)
+ data)))
data))
(defun nnimap-parse-flags (sequences)
(forward-line 1)
(setq end (point))
(goto-char start)
- (setq permanent-forward
+ (setq permanent-flags
(and (search-forward "PERMANENTFLAGS "
(or end (point-min)) t)
(read (current-buffer))))
+ (goto-char start)
(setq uidnext
(and (search-forward "UIDNEXT "
(or end (point-min)) t)
(read (current-buffer))))
- (goto-char end))
+ (goto-char end)
+ (forward-line -1))
;; The UID FETCH FLAGS was successful.
(search-forward (format "\n%d OK " flag-sequence) nil t))
(setq start (point))