1 ;;; nnimap.el --- IMAP interface for Gnus
3 ;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Simon Josefsson <simon@josefsson.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; nnimap interfaces Gnus with IMAP servers.
42 (autoload 'auth-source-forget
+ "auth-source")
43 (autoload 'auth-source-search
"auth-source")
47 (defvoo nnimap-address nil
48 "The address of the IMAP server.")
50 (defvoo nnimap-user nil
51 "Username to use for authentication to the IMAP server.")
53 (defvoo nnimap-server-port nil
55 If nnimap-stream is `ssl', this will default to `imaps'. If not,
56 it will default to `imap'.")
58 (defvoo nnimap-stream
'undecided
59 "How nnimap talks to the IMAP server.
60 The value should be either `undecided', `ssl' or `tls',
61 `network', `starttls', `plain', or `shell'.
63 If the value is `undecided', nnimap tries `ssl' first, then falls
66 (defvoo nnimap-shell-program
(if (boundp 'imap-shell-program
)
67 (if (listp imap-shell-program
)
68 (car imap-shell-program
)
72 (defvoo nnimap-inbox nil
73 "The mail box where incoming mail arrives and should be split out of.
74 This can be a string or a list of strings
75 For example, \"INBOX\" or (\"INBOX\" \"SENT\").")
77 (defvoo nnimap-split-methods nil
79 Uses the same syntax as `nnmail-split-methods'.")
81 (defvoo nnimap-split-fancy nil
82 "Uses the same syntax as `nnmail-split-fancy'.")
84 (defvoo nnimap-unsplittable-articles
'(%Deleted %Seen
)
85 "Articles with the flags in the list will not be considered when splitting.")
87 (make-obsolete-variable 'nnimap-split-rule
"see `nnimap-split-methods'."
90 (defvoo nnimap-authenticator nil
91 "How nnimap authenticate itself to the server.
92 Possible choices are nil (use default methods), `anonymous',
93 `login', `plain' and `cram-md5'.")
95 (defvoo nnimap-expunge t
96 "If non-nil, expunge articles after deleting them.
97 This is always done if the server supports UID EXPUNGE, but it's
98 not done by default on servers that doesn't support that command.")
100 (defvoo nnimap-streaming t
101 "If non-nil, try to use streaming commands with IMAP servers.
102 Switching this off will make nnimap slower, but it helps with
105 (defvoo nnimap-connection-alist nil
)
107 (defvoo nnimap-current-infos nil
)
109 (defun nnimap-decode-gnus-group (group)
110 (decode-coding-string group
'utf-8
))
112 (defun nnimap-encode-gnus-group (group)
113 (encode-coding-string group
'utf-8
))
115 (defvoo nnimap-fetch-partial-articles nil
116 "If non-nil, Gnus will fetch partial articles.
117 If t, Gnus will fetch only the first part. If a string, it
118 will fetch all parts that have types that match that string. A
119 likely value would be \"text/\" to automatically fetch all
126 (defcustom nnimap-request-articles-find-limit nil
127 "Limit the number of articles to look for after moving an article."
128 :type
'(choice (const nil
) integer
)
132 (defvar nnimap-process nil
)
134 (defvar nnimap-status-string
"")
136 (defvar nnimap-split-download-body-default nil
137 "Internal variable with default value for `nnimap-split-download-body'.")
139 (defvar nnimap-keepalive-timer nil
)
140 (defvar nnimap-process-buffers nil
)
143 group process commands capabilities select-result newlinep server
144 last-command-time greeting examined stream-type initial-resync
)
146 (defvar nnimap-object nil
)
148 (defvar nnimap-mark-alist
149 '((read "\\Seen" %Seen
)
150 (tick "\\Flagged" %Flagged
)
151 (reply "\\Answered" %Answered
)
152 (expire "gnus-expire")
153 (dormant "gnus-dormant")
156 (download "gnus-download")
157 (forward "gnus-forward")))
159 (defvar nnimap-quirks
160 '(("QRESYNC" "Zimbra" "QRESYNC ")
161 ("MOVE" "Dovecot" nil
)))
163 (defvar nnimap-inhibit-logging nil
)
165 (defun nnimap-buffer ()
166 (nnimap-find-process-buffer nntp-server-buffer
))
168 (defun nnimap-header-parameters ()
171 (push "RFC822.SIZE" params
)
172 (when (nnimap-capability "X-GM-EXT-1")
173 (push "X-GM-LABELS" params
))
174 (push "BODYSTRUCTURE" params
)
177 "BODY.PEEK[HEADER.FIELDS %s]"
178 "RFC822.HEADER.LINES %s")
179 (append '(Subject From Date Message-Id
180 References In-Reply-To Xref
)
181 nnmail-extra-headers
))
183 (format "%s" (nreverse params
))))
185 (deffoo nnimap-retrieve-headers
(articles &optional group server _fetch-old
)
187 (setq group
(nnimap-decode-gnus-group group
)))
188 (with-current-buffer nntp-server-buffer
190 (when (nnimap-change-group group server
)
191 (with-current-buffer (nnimap-buffer)
193 (nnimap-wait-for-response
196 (nnimap-article-ranges (gnus-compress-sequence articles
))
197 (nnimap-header-parameters))
199 (unless (process-live-p (get-buffer-process (current-buffer)))
200 (error "Server closed connection"))
201 (nnimap-transform-headers)
202 (nnheader-remove-cr-followed-by-lf))
203 (insert-buffer-substring
204 (nnimap-find-process-buffer (current-buffer))))
207 (defun nnimap-transform-headers ()
208 (goto-char (point-min))
209 (let (article lines size string labels
)
212 (while (not (looking-at "\\* [0-9]+ FETCH"))
213 (delete-region (point) (progn (forward-line 1) (point)))
216 (goto-char (match-end 0))
217 ;; Unfold quoted {number} strings.
218 (while (re-search-forward
219 "[^]][ (]{\\([0-9]+\\)}\r?\n"
221 ;; Start of the header section.
222 (or (re-search-forward "] {[0-9]+}\r?\n" nil t
)
223 ;; Start of the next FETCH.
224 (re-search-forward "\\* [0-9]+ FETCH" nil t
)
227 (setq size
(string-to-number (match-string 1)))
228 (delete-region (+ (match-beginning 0) 2) (point))
229 (setq string
(buffer-substring (point) (+ (point) size
)))
230 (delete-region (point) (+ (point) size
))
231 (insert (format "%S" (subst-char-in-string ?
\n ?\s string
))))
234 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
240 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
245 (when (search-forward "X-GM-LABELS" (line-end-position) t
)
246 (setq labels
(ignore-errors (read (current-buffer)))))
248 (when (search-forward "BODYSTRUCTURE" (line-end-position) t
)
249 (let ((structure (ignore-errors
250 (read (current-buffer)))))
251 (while (and (consp structure
)
252 (not (atom (car structure
))))
253 (setq structure
(car structure
)))
255 (stringp (car structure
))
256 (equal (upcase (nth 0 structure
)) "MESSAGE")
257 (equal (upcase (nth 1 structure
)) "RFC822"))
259 (nth 7 structure
)))))
260 (delete-region (line-beginning-position) (line-end-position))
261 (insert (format "211 %s Article retrieved." article
))
264 (insert (format "Chars: %s\n" size
)))
266 (insert (format "Lines: %s\n" lines
)))
268 (insert (format "X-GM-LABELS: %s\n" labels
)))
269 ;; Most servers have a blank line after the headers, but
271 (unless (re-search-forward "^\r$\\|^)\r?$" nil t
)
272 (goto-char (point-max)))
273 (delete-region (line-beginning-position) (line-end-position))
277 (defun nnimap-unfold-quoted-lines ()
278 ;; Unfold quoted {number} strings.
280 (while (re-search-forward " {\\([0-9]+\\)}\r?\n" nil t
)
281 (setq size
(string-to-number (match-string 1)))
282 (delete-region (1+ (match-beginning 0)) (point))
283 (setq string
(buffer-substring (point) (+ (point) size
)))
284 (delete-region (point) (+ (point) size
))
285 (insert (format "%S" string
)))))
287 (defun nnimap-get-length ()
288 (and (re-search-forward "{\\([0-9]+\\)}" (line-end-position) t
)
289 (string-to-number (match-string 1))))
291 (defun nnimap-article-ranges (ranges)
295 (number-to-string ranges
))
296 ((numberp (cdr ranges
))
297 (format "%d:%d" (car ranges
) (cdr ranges
)))
299 (dolist (elem ranges
)
302 (format "%d:%d" (car elem
) (cdr elem
))
303 (number-to-string elem
))
305 (mapconcat #'identity
(nreverse result
) ",")))))
307 (deffoo nnimap-open-server
(server &optional defs no-reconnect
)
308 (if (nnimap-server-opened server
)
310 (unless (assq 'nnimap-address defs
)
311 (setq defs
(append defs
(list (list 'nnimap-address server
)))))
312 (nnoo-change-server 'nnimap server defs
)
314 (nnimap-find-connection nntp-server-buffer
)
315 (or (nnimap-find-connection nntp-server-buffer
)
316 (nnimap-open-connection nntp-server-buffer
)))))
318 (defun nnimap-make-process-buffer (buffer)
320 (generate-new-buffer (format " *nnimap %s %s %s*"
321 nnimap-address nnimap-server-port
322 (gnus-buffer-exists-p buffer
)))
323 (mm-disable-multibyte)
324 (buffer-disable-undo)
326 (set (make-local-variable 'after-change-functions
) nil
)
327 (set (make-local-variable 'nnimap-object
)
328 (make-nnimap :server
(nnoo-current-server 'nnimap
)
330 (push (list buffer
(current-buffer)) nnimap-connection-alist
)
331 (push (current-buffer) nnimap-process-buffers
)
334 (defvar auth-source-creation-prompts
)
336 (defun nnimap-credentials (address ports user
)
337 (let* ((auth-source-creation-prompts
338 '((user .
"IMAP user at %h: ")
339 (secret .
"IMAP password for %u@%h: ")))
340 (found (nth 0 (auth-source-search :max
1
344 :require
'(:user
:secret
)
347 (list (plist-get found
:user
)
348 (let ((secret (plist-get found
:secret
)))
349 (if (functionp secret
)
352 (plist-get found
:save-function
))
355 (defun nnimap-keepalive ()
356 (let ((now (current-time)))
357 (dolist (buffer nnimap-process-buffers
)
358 (when (buffer-name buffer
)
359 (with-current-buffer buffer
360 (when (and nnimap-object
361 (nnimap-last-command-time nnimap-object
)
365 (nnimap-last-command-time nnimap-object
)))
366 ;; More than five minutes since the last command.
368 (ignore-errors ;E.g. "buffer foo has no process".
369 (nnimap-send-command "NOOP"))))))))
371 (defun nnimap-open-connection (buffer)
372 ;; Be backwards-compatible -- the earlier value of nnimap-stream was
373 ;; `ssl' when nnimap-server-port was nil. Sort of.
374 (when (and nnimap-server-port
375 (eq nnimap-stream
'undecided
))
376 (setq nnimap-stream
'ssl
))
378 (if (eq nnimap-stream
'undecided
)
379 (loop for type in
'(ssl network
)
380 for stream
= (let ((nnimap-stream type
))
381 (nnimap-open-connection-1 buffer
))
382 while
(eq stream
'no-connect
)
383 finally
(return stream
))
384 (nnimap-open-connection-1 buffer
))))
385 (if (eq stream
'no-connect
)
389 (defun nnimap-map-port (port)
390 (if (equal port
"imaps")
394 (defun nnimap-open-connection-1 (buffer)
395 (unless nnimap-keepalive-timer
396 (setq nnimap-keepalive-timer
(run-at-time (* 60 15) (* 60 15)
397 #'nnimap-keepalive
)))
398 (with-current-buffer (nnimap-make-process-buffer buffer
)
399 (let* ((coding-system-for-read 'binary
)
400 (coding-system-for-write 'binary
)
403 ((memq nnimap-stream
'(network plain starttls
))
404 (nnheader-message 7 "Opening connection to %s..."
407 ((eq nnimap-stream
'shell
)
408 (nnheader-message 7 "Opening connection to %s via shell..."
411 ((memq nnimap-stream
'(ssl tls
))
412 (nnheader-message 7 "Opening connection to %s via tls..."
414 '("imaps" "imap" "993" "143"))
416 (error "Unknown stream type: %s" nnimap-stream
))))
417 login-result credentials
)
418 (when nnimap-server-port
419 (push nnimap-server-port ports
))
422 "*nnimap*" (current-buffer) nnimap-address
423 (nnimap-map-port (car ports
))
425 :warn-unless-encrypted t
427 :shell-command nnimap-shell-program
428 :capability-command
"1 CAPABILITY\r\n"
429 :always-query-capabilities t
430 :end-of-command
"\r\n"
433 (lambda (capabilities)
434 (when (string-match-p "STARTTLS" capabilities
)
436 (stream (car stream-list
))
437 (props (cdr stream-list
))
438 (greeting (plist-get props
:greeting
))
439 (capabilities (plist-get props
:capabilities
))
440 (stream-type (plist-get props
:type
)))
441 (when (and stream
(not (memq (process-status stream
) '(open run
))))
444 (when (eq (process-type stream
) 'network
)
445 ;; Use TCP-keepalive so that connections that pass through a NAT
446 ;; router don't hang when left idle.
447 (set-network-process-option stream
:keepalive t
))
449 (setf (nnimap-process nnimap-object
) stream
)
450 (setf (nnimap-stream-type nnimap-object
) stream-type
)
453 (nnheader-report 'nnimap
"Unable to contact %s:%s via %s"
454 nnimap-address
(car ports
) nnimap-stream
)
456 (set-process-query-on-exit-flag stream nil
)
457 (if (not (string-match-p "[*.] \\(OK\\|PREAUTH\\)" greeting
))
458 (nnheader-report 'nnimap
"%s" greeting
)
459 ;; Store the greeting (for debugging purposes).
460 (setf (nnimap-greeting nnimap-object
) greeting
)
461 (setf (nnimap-capabilities nnimap-object
)
463 (split-string capabilities
)))
464 (unless (string-match-p "[*.] PREAUTH" greeting
)
465 (if (not (setq credentials
466 (if (eq nnimap-authenticator
'anonymous
)
468 (message-make-address))
469 ;; Look for the credentials based on
470 ;; the virtual server name and the address
472 (gnus-delete-duplicates
474 (nnoo-current-server 'nnimap
)
478 (setq nnimap-object nil
)
479 (let ((nnimap-inhibit-logging t
))
481 (nnimap-login (car credentials
) (cadr credentials
))))
482 (if (car login-result
)
484 ;; Save the credentials if a save function exists
485 ;; (such a function will only be passed if a new
486 ;; token was created).
487 (when (functionp (nth 2 credentials
))
488 (funcall (nth 2 credentials
)))
489 ;; See if CAPABILITY is set as part of login
491 (dolist (response (cddr (nnimap-command "CAPABILITY")))
492 (when (string= "CAPABILITY" (upcase (car response
)))
493 (setf (nnimap-capabilities nnimap-object
)
494 (mapcar #'upcase
(cdr response
))))))
495 ;; If the login failed, then forget the credentials
496 ;; that are now possibly cached.
497 (dolist (host (list (nnoo-current-server 'nnimap
)
500 (auth-source-forget+ :host host
:port port
)))
501 (delete-process (nnimap-process nnimap-object
))
502 (setq nnimap-object nil
))))
504 (when (nnimap-capability "QRESYNC")
505 (nnimap-command "ENABLE QRESYNC"))
506 (nnheader-message 7 "Opening connection to %s...done"
508 (nnimap-process nnimap-object
))))))))
510 (autoload 'rfc2104-hash
"rfc2104")
512 (defun nnimap-login (user password
)
514 ;; Prefer plain LOGIN if it's enabled (since it requires fewer
515 ;; round trips than CRAM-MD5, and it's less likely to be buggy),
516 ;; and we're using an encrypted connection.
517 ((and (not (nnimap-capability "LOGINDISABLED"))
518 (eq (nnimap-stream-type nnimap-object
) 'tls
)
519 (or (null nnimap-authenticator
)
520 (eq nnimap-authenticator
'login
)))
521 (nnimap-command "LOGIN %S %S" user password
))
522 ((and (nnimap-capability "AUTH=CRAM-MD5")
523 (or (null nnimap-authenticator
)
524 (eq nnimap-authenticator
'cram-md5
)))
526 (let ((sequence (nnimap-send-command "AUTHENTICATE CRAM-MD5"))
527 (challenge (nnimap-wait-for-line "^\\+\\(.*\\)\n")))
529 (get-buffer-process (current-buffer))
531 (base64-encode-string
533 (rfc2104-hash 'md5
64 16 password
534 (base64-decode-string challenge
))))
536 (nnimap-wait-for-response sequence
)))
537 ((and (not (nnimap-capability "LOGINDISABLED"))
538 (or (null nnimap-authenticator
)
539 (eq nnimap-authenticator
'login
)))
540 (nnimap-command "LOGIN %S %S" user password
))
541 ((and (nnimap-capability "AUTH=PLAIN")
542 (or (null nnimap-authenticator
)
543 (eq nnimap-authenticator
'plain
)))
545 "AUTHENTICATE PLAIN %s"
546 (base64-encode-string
547 (format "\000%s\000%s"
548 (nnimap-quote-specials user
)
549 (nnimap-quote-specials password
)))))))
551 (defun nnimap-quote-specials (string)
554 (goto-char (point-min))
555 (while (re-search-forward "[\\\"]" nil t
)
561 (defun nnimap-find-parameter (parameter elems
)
565 ((equal (car elem
) parameter
)
566 (setq result
(cdr elem
)))
567 ((and (equal (car elem
) "OK")
569 (equal (caadr elem
) parameter
))
570 (setq result
(cdr (cadr elem
))))))
573 (deffoo nnimap-close-server
(&optional server
)
574 (when (nnoo-change-server 'nnimap server nil
)
576 (delete-process (get-buffer-process (nnimap-buffer))))
577 (nnoo-close-server 'nnimap server
)
580 (deffoo nnimap-request-close
()
583 (deffoo nnimap-server-opened
(&optional server
)
584 (and (nnoo-current-server-p 'nnimap server
)
586 (gnus-buffer-live-p nntp-server-buffer
)
587 (nnimap-find-connection nntp-server-buffer
)))
589 (deffoo nnimap-status-message
(&optional _server
)
590 nnimap-status-string
)
592 (deffoo nnimap-request-article
(article &optional group server to-buffer
)
594 (setq group
(nnimap-decode-gnus-group group
)))
595 (with-current-buffer nntp-server-buffer
596 (let ((result (nnimap-change-group group server
))
598 (when (stringp article
)
599 (setq article
(nnimap-find-article-by-message-id group server article
)))
603 (with-current-buffer (nnimap-buffer)
605 (when nnimap-fetch-partial-articles
606 (nnimap-command "UID FETCH %d (BODYSTRUCTURE)" article
)
607 (goto-char (point-min))
608 (when (re-search-forward "FETCH.*BODYSTRUCTURE" nil t
)
609 (setq structure
(ignore-errors
610 (let ((start (point)))
612 (downcase-region start
(point))
614 (read (current-buffer))))
615 parts
(nnimap-find-wanted-parts structure
))))
617 (nnimap-get-partial-article article parts structure
)
618 (nnimap-get-whole-article article
))
619 (let ((buffer (current-buffer)))
620 (with-current-buffer (or to-buffer nntp-server-buffer
)
621 (nnheader-insert-buffer-substring buffer
)
622 (nnheader-ms-strip-cr)))
623 (cons group article
)))))))
625 (deffoo nnimap-request-head
(article &optional group server to-buffer
)
627 (setq group
(nnimap-decode-gnus-group group
)))
628 (when (nnimap-change-group group server
)
629 (with-current-buffer (nnimap-buffer)
630 (when (stringp article
)
631 (setq article
(nnimap-find-article-by-message-id group server article
)))
634 (nnimap-get-whole-article
635 article
(format "UID FETCH %%d %s"
636 (nnimap-header-parameters)))
637 (let ((buffer (current-buffer)))
638 (with-current-buffer (or to-buffer nntp-server-buffer
)
640 (insert-buffer-substring buffer
)
641 (nnheader-ms-strip-cr)
642 (cons group article
)))))))
644 (deffoo nnimap-request-articles
(articles &optional group server
)
646 (setq group
(nnimap-decode-gnus-group group
)))
647 (with-current-buffer nntp-server-buffer
648 (let ((result (nnimap-change-group group server
)))
651 (with-current-buffer (nnimap-buffer)
653 (when (nnimap-command
655 "UID FETCH %s BODY.PEEK[]"
656 "UID FETCH %s RFC822.PEEK")
657 (nnimap-article-ranges (gnus-compress-sequence articles
)))
658 (let ((buffer (current-buffer)))
659 (with-current-buffer nntp-server-buffer
660 (nnheader-insert-buffer-substring buffer
)
661 (nnheader-ms-strip-cr)))
664 (defun nnimap-get-whole-article (article &optional command
)
669 "UID FETCH %d BODY.PEEK[]"
670 "UID FETCH %d RFC822.PEEK"))
672 ;; Check that we really got an article.
673 (goto-char (point-min))
674 (unless (re-search-forward "\\* [0-9]+ FETCH" nil t
)
677 ;; Remove any data that may have arrived before the FETCH data.
680 (delete-region (point-min) (point)))
681 (let ((bytes (nnimap-get-length)))
682 (delete-region (line-beginning-position)
683 (progn (forward-line 1) (point)))
684 (goto-char (+ (point) bytes
))
685 (delete-region (point) (point-max)))
688 (defun nnimap-capability (capability)
689 (member capability
(nnimap-capabilities nnimap-object
)))
691 (defun nnimap-ver4-p ()
692 (nnimap-capability "IMAP4REV1"))
694 (defun nnimap-get-partial-article (article parts structure
)
697 "UID FETCH %d (%s %s)"
703 (mapconcat (lambda (part)
704 (format "BODY.PEEK[%s]" part
))
706 (mapconcat (lambda (part)
707 (format "RFC822.PEEK[%s]" part
))
710 (nnimap-convert-partial-article structure
))))
712 (defun nnimap-convert-partial-article (structure)
713 ;; First just skip past the headers.
714 (goto-char (point-min))
715 (let ((bytes (nnimap-get-length))
717 ;; Delete "FETCH" line.
718 (delete-region (line-beginning-position)
719 (progn (forward-line 1) (point)))
720 (goto-char (+ (point) bytes
))
721 ;; Collect all the body parts.
722 (while (looking-at ".*BODY\\[\\([.0-9]+\\)\\]")
723 (setq id
(match-string 1)
724 bytes
(or (nnimap-get-length) 0))
726 (delete-region (point) (progn (forward-line 1) (point)))
727 (push (list id
(buffer-substring (point) (+ (point) bytes
)))
729 (delete-region (point) (+ (point) bytes
)))
730 ;; Delete trailing junk.
731 (delete-region (point) (point-max))
732 ;; Now insert all the parts again where they fit in the structure.
733 (nnimap-insert-partial-structure structure parts
)
736 (defun nnimap-insert-partial-structure (structure parts
&optional subp
)
738 (let ((bstruc structure
))
739 (while (consp (car bstruc
))
741 (setq type
(car bstruc
))
742 (setq bstruc
(car (cdr bstruc
)))
743 (let ((has-boundary (member "boundary" bstruc
)))
745 (setq boundary
(cadr has-boundary
)))))
747 (insert (format "Content-type: multipart/%s; boundary=%S\n\n"
748 (downcase type
) boundary
)))
749 (while (not (stringp (car structure
)))
750 (insert "\n--" boundary
"\n")
751 (if (consp (caar structure
))
752 (nnimap-insert-partial-structure (pop structure
) parts t
)
753 (let ((bit (pop structure
)))
754 (insert (format "Content-type: %s/%s"
755 (downcase (nth 0 bit
))
756 (downcase (nth 1 bit
))))
757 (if (member-ignore-case "CHARSET" (nth 2 bit
))
760 (cadr (member-ignore-case "CHARSET" (nth 2 bit
)))))
762 (insert (format "Content-transfer-encoding: %s\n"
765 (when (assoc (nth 9 bit
) parts
)
766 (insert (cadr (assoc (nth 9 bit
) parts
)))))))
767 (insert "\n--" boundary
"--\n")))
769 (defun nnimap-find-wanted-parts (structure)
770 (message-flatten-list (nnimap-find-wanted-parts-1 structure
"")))
772 (defun nnimap-find-wanted-parts-1 (structure prefix
)
775 (while (consp (car structure
))
776 (let ((sub (pop structure
)))
777 (if (consp (car sub
))
778 (push (nnimap-find-wanted-parts-1
779 sub
(if (string= prefix
"")
780 (number-to-string num
)
781 (format "%s.%s" prefix num
)))
783 (let ((type (format "%s/%s" (nth 0 sub
) (nth 1 sub
)))
784 (id (if (string= prefix
"")
785 (number-to-string num
)
786 (format "%s.%s" prefix num
))))
787 (setcar (nthcdr 9 sub
) id
)
788 (when (if (eq nnimap-fetch-partial-articles t
)
790 (string-match nnimap-fetch-partial-articles type
))
795 (deffoo nnimap-request-group
(group &optional server dont-check info
)
796 (setq group
(nnimap-decode-gnus-group group
))
797 (let ((result (nnimap-change-group
798 ;; Don't SELECT the group if we're going to select it
800 (if (and (not dont-check
)
801 (assoc group nnimap-current-infos
))
805 (info (when info
(list info
)))
807 (with-current-buffer nntp-server-buffer
809 (when (or (not dont-check
)
811 (nth 2 (assoc group nnimap-current-infos
)))))
812 (let ((sequences (nnimap-retrieve-group-data-early
814 (nnimap-finish-retrieve-group-infos server info sequences
816 (setq active
(nth 2 (assoc group nnimap-current-infos
)))))
817 (setq active
(or active
'(0 .
1)))
819 (insert (format "211 %d %d %d %S\n"
820 (- (cdr active
) (car active
))
823 (nnimap-encode-gnus-group group
)))
826 (deffoo nnimap-request-group-scan
(group &optional server info
)
827 (setq group
(nnimap-decode-gnus-group group
))
828 (when (nnimap-change-group nil server
)
829 (let (marks high low
)
830 (with-current-buffer (nnimap-buffer)
832 (let ((group-sequence
833 (nnimap-send-command "SELECT %S" (utf7-encode group t
)))
835 (nnimap-send-command "UID FETCH 1:* FLAGS")))
836 (setf (nnimap-group nnimap-object
) group
)
837 (nnimap-wait-for-response flag-sequence
)
839 (nnimap-flags-to-marks
841 (list (list group-sequence flag-sequence
842 1 group
"SELECT")))))
845 (nnimap-update-infos marks
(list info
))
846 (nnimap-store-info info
(gnus-active (gnus-info-group info
))))
847 (goto-char (point-max))
848 (let ((uidnext (nth 5 (car marks
))))
849 (setq high
(or (if uidnext
853 low
(or (nth 4 (car marks
)) uidnext
1)))))
854 (with-current-buffer nntp-server-buffer
858 "211 %d %d %d %S\n" (1+ (- high low
)) low high
859 (nnimap-encode-gnus-group group
)))
862 (deffoo nnimap-request-create-group
(group &optional server _args
)
863 (setq group
(nnimap-decode-gnus-group group
))
864 (when (nnimap-change-group nil server
)
865 (with-current-buffer (nnimap-buffer)
866 (car (nnimap-command "CREATE %S" (utf7-encode group t
))))))
868 (deffoo nnimap-request-delete-group
(group &optional _force server
)
869 (setq group
(nnimap-decode-gnus-group group
))
870 (when (nnimap-change-group nil server
)
871 (with-current-buffer (nnimap-buffer)
872 (car (nnimap-command "DELETE %S" (utf7-encode group t
))))))
874 (deffoo nnimap-request-rename-group
(group new-name
&optional server
)
875 (setq group
(nnimap-decode-gnus-group group
))
876 (when (nnimap-change-group nil server
)
877 (with-current-buffer (nnimap-buffer)
878 (nnimap-unselect-group)
879 (car (nnimap-command "RENAME %S %S"
880 (utf7-encode group t
) (utf7-encode new-name t
))))))
882 (defun nnimap-unselect-group ()
883 ;; Make sure we don't have this group open read/write by asking
884 ;; to examine a mailbox that doesn't exist. This seems to be
885 ;; the only way that allows us to reliably go back to unselected
887 (nnimap-command "EXAMINE DOES.NOT.EXIST"))
889 (deffoo nnimap-request-expunge-group
(group &optional server
)
890 (setq group
(nnimap-decode-gnus-group group
))
891 (when (nnimap-change-group group server
)
892 (with-current-buffer (nnimap-buffer)
893 (car (nnimap-command "EXPUNGE")))))
895 (defun nnimap-get-flags (spec)
898 (with-current-buffer (nnimap-buffer)
900 (nnimap-wait-for-response (nnimap-send-command
901 "UID FETCH %s FLAGS" spec
))
903 (subst-char-in-region (point-min) (point-max)
905 (goto-char (point-min))
906 (while (search-forward " FETCH " end t
)
907 (setq elems
(read (current-buffer)))
908 (push (cons (cadr (memq 'UID elems
))
909 (cadr (memq 'FLAGS elems
)))
911 (nreverse articles
)))
913 (deffoo nnimap-close-group
(_group &optional _server
)
916 (deffoo nnimap-request-move-article
(article group server accept-form
919 (setq group
(nnimap-decode-gnus-group group
))
920 (when internal-move-group
921 (setq internal-move-group
(nnimap-decode-gnus-group internal-move-group
)))
923 (mm-disable-multibyte)
924 (when (funcall (if internal-move-group
926 'nnimap-request-article
)
927 article group server
(current-buffer))
928 ;; If the move is internal (on the same server), just do it the
930 (let ((message-id (message-field-value "message-id")))
931 (if internal-move-group
932 (with-current-buffer (nnimap-buffer)
933 (let* ((can-move (and (nnimap-capability "MOVE")
934 (equal (nnimap-quirk "MOVE") "MOVE")))
935 (command (if can-move
938 (result (nnimap-command
940 (utf7-encode internal-move-group t
))))
941 (when (and (car result
) (not can-move
))
942 (nnimap-delete-article article
))
943 (cons internal-move-group
944 (or (nnimap-find-uid-response "COPYUID" (caddr result
))
945 (nnimap-find-article-by-message-id
946 internal-move-group server message-id
947 nnimap-request-articles-find-limit
)))))
948 ;; Move the article to a different method.
949 (when-let ((result (eval accept-form
)))
950 (nnimap-change-group group server
)
951 (nnimap-delete-article article
)
954 (deffoo nnimap-request-expire-articles
(articles group
&optional server force
)
955 (setq group
(nnimap-decode-gnus-group group
))
959 ((not (nnimap-change-group group server
))
962 (eq nnmail-expiry-target
'delete
))
963 (unless (nnimap-delete-article (gnus-compress-sequence articles
))
964 (nnheader-message 7 "Article marked for deletion, but not expunged."))
967 (let ((deletable-articles
969 (eq nnmail-expiry-wait
'immediate
))
971 (gnus-sorted-intersection
973 (nnimap-find-expired-articles group
)))))
974 (if (null deletable-articles
)
976 (if (eq nnmail-expiry-target
'delete
)
977 (nnimap-delete-article (gnus-compress-sequence deletable-articles
))
978 (setq deletable-articles
979 (nnimap-process-expiry-targets
980 deletable-articles group server
)))
981 ;; Return the articles we didn't delete.
982 (gnus-sorted-complement articles deletable-articles
))))))
984 (defun nnimap-process-expiry-targets (articles group server
)
985 (let ((deleted-articles nil
)
986 (articles-to-delete nil
))
988 ;; shortcut further processing if we're going to delete the articles
989 ((eq nnmail-expiry-target
'delete
)
990 (setq articles-to-delete articles
)
992 ;; or just move them to another folder on the same IMAP server
993 ((and (not (functionp nnmail-expiry-target
))
994 (gnus-server-equal (gnus-group-method nnmail-expiry-target
)
995 (gnus-server-to-method
996 (format "nnimap:%s" server
))))
997 (and (nnimap-change-group group server
)
998 (with-current-buffer (nnimap-buffer)
999 (nnheader-message 7 "Expiring articles from %s: %s" group articles
)
1000 (let ((can-move (and (nnimap-capability "MOVE")
1001 (equal (nnimap-quirk "MOVE") "MOVE"))))
1006 (nnimap-article-ranges (gnus-compress-sequence articles
))
1007 (utf7-encode (gnus-group-real-name nnmail-expiry-target
) t
))
1008 (set (if can-move
'deleted-articles
'articles-to-delete
) articles
))))
1011 (dolist (article articles
)
1012 (let ((target nnmail-expiry-target
))
1014 (mm-disable-multibyte)
1015 (when (nnimap-request-article article group server
(current-buffer))
1016 (when (functionp target
)
1017 (setq target
(funcall target group
)))
1019 (not (eq target
'delete
)))
1020 (if (or (gnus-request-group target t
)
1021 (gnus-request-create-group target
))
1023 (nnmail-expiry-target-group target group
)
1024 (nnheader-message 7 "Expiring article %s:%d to %s"
1025 group article target
))
1027 (nnheader-message 7 "Expiring article %s:%d" group article
))
1029 (push article articles-to-delete
))))))
1030 (setq articles-to-delete
(nreverse articles-to-delete
))))
1031 ;; Change back to the current group again.
1032 (nnimap-change-group group server
)
1033 (when articles-to-delete
1034 (nnimap-delete-article (gnus-compress-sequence articles-to-delete
))
1035 (setq deleted-articles articles-to-delete
))
1038 (defun nnimap-find-expired-articles (group)
1039 (let ((cutoff (nnmail-expired-article-p group nil nil
)))
1041 (with-current-buffer (nnimap-buffer)
1044 "UID SEARCH SENTBEFORE %s"
1046 (format "%%d-%s-%%Y"
1048 (car (rassoc (nth 4 (decode-time cutoff
))
1049 parse-time-months
))))
1052 (delete 0 (mapcar #'string-to-number
1053 (cdr (assoc "SEARCH" (cdr result
)))))))))))
1055 (defun nnimap-find-article-by-message-id (group server message-id
1057 "Search for message with MESSAGE-ID in GROUP from SERVER.
1058 If LIMIT, first try to limit the search to the N last articles."
1059 (with-current-buffer (nnimap-buffer)
1061 (let* ((change-group-result (nnimap-change-group group server nil t
))
1063 (and (listp change-group-result
)
1065 (dolist (result (cdr change-group-result
))
1066 (when (equal "EXISTS" (cadr result
))
1067 (throw 'found
(car result
)))))))
1069 (nnimap-send-command
1070 "UID SEARCH%s HEADER Message-Id %S"
1071 (if (and limit number-of-article
)
1072 ;; The -1 is because IMAP message
1073 ;; numbers are one-based rather than
1075 (format " %s:*" (- (string-to-number number-of-article
)
1079 (when (nnimap-wait-for-response sequence
)
1080 (let ((article (car (last (cdr (assoc "SEARCH"
1081 (nnimap-parse-response)))))))
1083 (string-to-number article
)
1084 (when (and limit number-of-article
)
1085 (nnimap-find-article-by-message-id group server message-id
))))))))
1087 (defun nnimap-delete-article (articles)
1088 (with-current-buffer (nnimap-buffer)
1089 (nnimap-command "UID STORE %s +FLAGS.SILENT (\\Deleted)"
1090 (nnimap-article-ranges articles
))
1092 ((nnimap-capability "UIDPLUS")
1093 (nnimap-command "UID EXPUNGE %s"
1094 (nnimap-article-ranges articles
))
1097 (nnimap-command "EXPUNGE")
1099 (t (gnus-message 7 (concat "nnimap: nnimap-expunge is not set and the "
1100 "server doesn't support UIDPLUS, so we won't "
1101 "delete this article now"))))))
1103 (deffoo nnimap-request-scan
(&optional group server
)
1105 (setq group
(nnimap-decode-gnus-group group
)))
1106 (when (and (nnimap-change-group nil server
)
1108 nnimap-split-methods
)
1109 (nnheader-message 7 "nnimap %s splitting mail..." server
)
1110 (if (listp nnimap-inbox
)
1111 (dolist (nnimap-inbox nnimap-inbox
)
1112 (nnimap-split-incoming-mail))
1113 (nnimap-split-incoming-mail))
1114 (nnheader-message 7 "nnimap %s splitting mail...done" server
)))
1116 (defun nnimap-marks-to-flags (marks)
1118 (dolist (mark marks
)
1119 (when (setq flag
(cadr (assq mark nnimap-mark-alist
)))
1123 (deffoo nnimap-request-update-group-status
(group status
&optional server
)
1124 (setq group
(nnimap-decode-gnus-group group
))
1125 (when (nnimap-change-group nil server
)
1126 (let ((command (assoc
1128 '((subscribe "SUBSCRIBE")
1129 (unsubscribe "UNSUBSCRIBE")))))
1131 (with-current-buffer (nnimap-buffer)
1132 (nnimap-command "%s %S" (cadr command
) (utf7-encode group t
)))))))
1134 (deffoo nnimap-request-set-mark
(group actions
&optional server
)
1135 (setq group
(nnimap-decode-gnus-group group
))
1136 (when (nnimap-change-group group server
)
1138 (with-current-buffer (nnimap-buffer)
1140 ;; Just send all the STORE commands without waiting for
1141 ;; response. If they're successful, they're successful.
1142 (dolist (action actions
)
1143 (destructuring-bind (range action marks
) action
1144 (let ((flags (nnimap-marks-to-flags marks
)))
1146 (setq sequence
(nnimap-send-command
1147 "UID STORE %s %sFLAGS.SILENT (%s)"
1148 (nnimap-article-ranges range
)
1150 ((eq action
'del
) "-")
1151 ((eq action
'add
) "+")
1152 ((eq action
'set
) ""))
1153 (mapconcat #'identity flags
" ")))))))
1154 ;; Wait for the last command to complete to avoid later
1155 ;; synchronization problems with the stream.
1157 (nnimap-wait-for-response sequence
))))))
1159 (deffoo nnimap-request-accept-article
(group &optional server _last
)
1161 ;; We're respooling. Find out where mail splitting would place
1165 (nnmail-article-group
1166 ;; We don't really care about the article number, because
1167 ;; that's determined by the IMAP server later. So just
1168 ;; return the group name.
1170 (list (list group
)))))))
1171 (setq group
(nnimap-decode-gnus-group group
))
1172 (when (nnimap-change-group nil server
)
1173 (nnmail-check-syntax)
1174 (let ((message-id (message-field-value "message-id"))
1177 (setq message
(buffer-substring-no-properties (point-min) (point-max)))
1178 (with-current-buffer (nnimap-buffer)
1179 (when (setq message
(or (nnimap-process-quirk "OK Gimap " 'append message
)
1181 ;; If we have this group open read-only, then unselect it
1182 ;; before appending to it.
1183 (when (equal (nnimap-examined nnimap-object
) group
)
1184 (nnimap-unselect-group))
1186 (setq sequence
(nnimap-send-command
1187 "APPEND %S {%d}" (utf7-encode group t
)
1189 (unless nnimap-streaming
1190 (nnimap-wait-for-connection "^[+]"))
1191 (process-send-string (get-buffer-process (current-buffer)) message
)
1192 (process-send-string (get-buffer-process (current-buffer))
1193 (if (nnimap-newlinep nnimap-object
)
1196 (let ((result (nnimap-get-response sequence
)))
1197 (if (not (nnimap-ok-p result
))
1199 (nnheader-report 'nnimap
"%s" result
)
1202 (or (nnimap-find-uid-response "APPENDUID" (car result
))
1203 (nnimap-find-article-by-message-id
1204 group server message-id
1205 nnimap-request-articles-find-limit
))))))))))
1207 (defun nnimap-process-quirk (greeting-match type data
)
1208 (when (and (nnimap-greeting nnimap-object
)
1209 (string-match greeting-match
(nnimap-greeting nnimap-object
))
1211 (string-match "\000" data
))
1212 (let ((choice (gnus-multiple-choice
1213 "Message contains NUL characters. Delete, continue, abort? "
1214 '((?d
"Delete NUL characters")
1215 (?c
"Try to APPEND the message as is")
1219 (nnheader-report 'nnimap
"Aborted APPEND due to NUL characters"))
1225 (goto-char (point-min))
1226 (while (search-forward "\000" nil t
)
1227 (replace-match "" t t
))
1228 (buffer-string)))))))
1230 (defun nnimap-ok-p (value)
1233 (equal (caar value
) "OK")))
1235 (defun nnimap-find-uid-response (name list
)
1236 (let ((result (car (last (nnimap-find-response-element name list
)))))
1238 (string-to-number result
))))
1240 (defun nnimap-find-response-element (name list
)
1243 (when (and (consp elem
)
1244 (equal name
(car elem
)))
1245 (setq result elem
)))
1248 (deffoo nnimap-request-replace-article
(article group buffer
)
1249 (setq group
(nnimap-decode-gnus-group group
))
1251 (when (and (nnimap-change-group group
)
1252 ;; Put the article into the group.
1253 (with-current-buffer buffer
1255 (nnimap-request-accept-article group nil t
))))
1256 (nnimap-delete-article (list article
))
1257 ;; Return the new article number.
1260 (defun nnimap-add-cr ()
1261 (goto-char (point-min))
1262 (while (re-search-forward "\r?\n" nil t
)
1263 (replace-match "\r\n" t t
)))
1265 (defun nnimap-get-groups ()
1267 (let ((sequence (nnimap-send-command "LIST \"\" \"*\""))
1269 (nnimap-wait-for-response sequence
)
1270 (subst-char-in-region (point-min) (point-max)
1272 (goto-char (point-min))
1273 (nnimap-unfold-quoted-lines)
1274 (goto-char (point-min))
1275 (while (search-forward "* LIST " nil t
)
1276 (let ((flags (read (current-buffer)))
1277 (_separator (read (current-buffer)))
1278 (group (buffer-substring-no-properties
1279 (progn (skip-chars-forward " \"")
1281 (progn (end-of-line)
1282 (skip-chars-backward " \r\"")
1284 (unless (member '%NoSelect flags
)
1285 (push (utf7-decode (if (stringp group
)
1287 (format "%s" group
))
1292 (defun nnimap-get-responses (sequences)
1294 (dolist (sequence sequences
)
1295 (goto-char (point-min))
1296 (when (re-search-forward (format "^%d " sequence
) nil t
)
1297 (push (list sequence
(nnimap-parse-response))
1301 (deffoo nnimap-request-list
(&optional server
)
1302 (when (nnimap-change-group nil server
)
1303 (with-current-buffer nntp-server-buffer
1306 (with-current-buffer (nnimap-buffer)
1307 (nnimap-get-groups)))
1308 sequences responses
)
1310 (with-current-buffer (nnimap-buffer)
1311 (setf (nnimap-group nnimap-object
) nil
)
1312 (dolist (group groups
)
1313 (setf (nnimap-examined nnimap-object
) group
)
1314 (push (list (nnimap-send-command "EXAMINE %S"
1315 (utf7-encode group t
))
1318 (nnimap-wait-for-response (caar sequences
))
1320 (nnimap-get-responses (mapcar #'car sequences
))))
1321 (dolist (response responses
)
1322 (let* ((sequence (car response
))
1323 (response (cadr response
))
1324 (group (cadr (assoc sequence sequences
)))
1325 (egroup (nnimap-encode-gnus-group group
)))
1327 (equal (caar response
) "OK"))
1328 (let ((uidnext (nnimap-find-parameter "UIDNEXT" response
))
1330 (dolist (elem response
)
1331 (when (equal (cadr elem
) "EXISTS")
1332 (setq exists
(string-to-number (car elem
)))))
1334 (setq highest
(1- (string-to-number (car uidnext
)))))
1337 (insert (format "%S 0 1 y\n" egroup
)))
1340 (insert (format "%S %d %d y\n" egroup
1341 highest
(1+ highest
))))
1343 ;; Return the widest possible range.
1344 (insert (format "%S %d 1 y\n" egroup
1345 (or highest exists
)))))))))
1348 (deffoo nnimap-request-newgroups
(_date &optional server
)
1349 (when (nnimap-change-group nil server
)
1350 (with-current-buffer nntp-server-buffer
1352 (dolist (group (with-current-buffer (nnimap-buffer)
1353 (nnimap-get-groups)))
1354 (unless (assoc group nnimap-current-infos
)
1355 ;; Insert dummy numbers here -- they don't matter.
1356 (insert (format "%S 0 1 y\n" (nnimap-encode-gnus-group group
)))))
1359 (deffoo nnimap-retrieve-group-data-early
(server infos
)
1360 (when (and (nnimap-change-group nil server
)
1362 (with-current-buffer (nnimap-buffer)
1364 (setf (nnimap-group nnimap-object
) nil
)
1365 (setf (nnimap-initial-resync nnimap-object
) 0)
1366 (let ((qresyncp (nnimap-capability "QRESYNC"))
1367 params sequences active uidvalidity modseq group
1369 ;; Go through the infos and gather the data needed to know
1370 ;; what and how to request the data.
1371 (dolist (info infos
)
1372 (setq params
(gnus-info-params info
)
1373 group
(nnimap-decode-gnus-group
1374 (gnus-group-real-name (gnus-info-group info
)))
1375 active
(cdr (assq 'active params
))
1376 unexist
(assq 'unexist
(gnus-info-marks info
))
1377 uidvalidity
(cdr (assq 'uidvalidity params
))
1378 modseq
(cdr (assq 'modseq params
)))
1379 (setf (nnimap-examined nnimap-object
) group
)
1386 (list (nnimap-send-command "EXAMINE %S (%s (%s %s))"
1387 (utf7-encode group t
)
1388 (nnimap-quirk "QRESYNC")
1396 ;; If we don't have a UIDVALIDITY, then this is
1397 ;; the first time we've seen the group, so we
1398 ;; have to do a SELECT (which is slower than an
1399 ;; examine), but will tell us whether the group
1400 ;; is read-only or not.
1403 (if (and active uidvalidity unexist
)
1404 ;; Fetch the last 100 flags.
1405 (setq start
(max 1 (- (cdr active
) 100)))
1406 (incf (nnimap-initial-resync nnimap-object
))
1408 (push (list (nnimap-send-command "%s %S" command
1409 (utf7-encode group t
))
1410 (nnimap-send-command "UID FETCH %d:* FLAGS" start
)
1411 start group command
)
1415 (defun nnimap-quirk (command)
1416 (let ((quirk (assoc command nnimap-quirks
)))
1417 ;; If this server is of a type that matches a quirk, then return
1418 ;; the "quirked" command instead of the proper one.
1419 (if (or (null quirk
)
1420 (not (string-match (nth 1 quirk
) (nnimap-greeting nnimap-object
))))
1424 (deffoo nnimap-finish-retrieve-group-infos
(server infos sequences
1425 &optional dont-insert
)
1426 (when (and sequences
1427 (nnimap-change-group nil server t
)
1428 ;; Check that the process is still alive.
1429 (get-buffer-process (nnimap-buffer))
1430 (memq (process-status (get-buffer-process (nnimap-buffer)))
1432 (with-current-buffer (nnimap-buffer)
1433 ;; Wait for the final data to trickle in.
1434 (when (nnimap-wait-for-response (if (eq (cadar sequences
) 'qresync
)
1438 ;; Now we should have most of the data we need, no matter
1439 ;; whether we're QRESYNCING, fetching all the flags from
1440 ;; scratch, or just fetching the last 100 flags per group.
1441 (nnimap-update-infos (nnimap-flags-to-marks
1443 (nreverse sequences
)))
1446 ;; Finally, just return something resembling an active file in
1447 ;; the nntp buffer, so that the agent can save the info, too.
1448 (with-current-buffer nntp-server-buffer
1450 (dolist (info infos
)
1451 (let* ((group (gnus-info-group info
))
1452 (active (gnus-active group
)))
1454 (insert (format "%S %d %d y\n"
1455 (nnimap-encode-gnus-group
1456 (nnimap-decode-gnus-group
1457 (gnus-group-real-name group
)))
1459 (car active
))))))))))))
1461 (defun nnimap-update-infos (flags infos
)
1462 (dolist (info infos
)
1463 (let* ((group (nnimap-decode-gnus-group
1464 (gnus-group-real-name (gnus-info-group info
))))
1465 (marks (cdr (assoc group flags
))))
1467 (nnimap-update-info info marks
)))))
1469 (defun nnimap-update-info (info marks
)
1470 (destructuring-bind (existing flags high low uidnext start-article
1471 permanent-flags uidvalidity
1472 vanished highestmodseq
) marks
1474 ;; Ignore groups with no UIDNEXT/marks. This happens for
1475 ;; completely empty groups.
1476 ((and (not existing
)
1478 (let ((active (cdr (assq 'active
(gnus-info-params info
)))))
1480 (gnus-set-active (gnus-info-group info
) active
))))
1481 ;; We have a mismatch between the old and new UIDVALIDITY
1482 ;; identifiers, so we have to re-request the group info (the next
1483 ;; time). This virtually never happens.
1484 ((let ((old-uidvalidity
1485 (cdr (assq 'uidvalidity
(gnus-info-params info
)))))
1486 (and old-uidvalidity
1487 (not (equal old-uidvalidity uidvalidity
))
1488 (or (not start-article
)
1489 (> start-article
1))))
1490 (gnus-group-remove-parameter info
'uidvalidity
)
1491 (gnus-group-remove-parameter info
'modseq
))
1492 ;; We have the data needed to update.
1494 (let* ((group (gnus-info-group info
))
1495 (completep (and start-article
1496 (= start-article
1)))
1497 (active (or (gnus-active group
)
1498 (cdr (assq 'active
(gnus-info-params info
))))))
1500 (setq high
(1- uidnext
)))
1501 ;; First set the active ranges based on high/low.
1503 (not (gnus-active group
)))
1504 (gnus-set-active group
1507 (cons (min (or low
(car active
))
1509 (max (or high
(cdr active
))
1514 ;; No articles in this group.
1515 (cons uidnext
(1- uidnext
)))
1517 (cons start-article
(1- start-article
)))
1519 ;; No articles and no uidnext.
1521 (gnus-set-active group
1523 (or high
(1- uidnext
)))))
1524 ;; See whether this is a read-only group.
1525 (unless (eq permanent-flags
'not-scanned
)
1526 (gnus-group-set-parameter
1527 info
'permanent-flags
1528 (and (or (memq '%
* permanent-flags
)
1529 (memq '%Seen permanent-flags
))
1531 ;; Update marks and read articles if this isn't a
1532 ;; read-only IMAP group.
1533 (when (setq permanent-flags
1534 (cdr (assq 'permanent-flags
(gnus-info-params info
))))
1535 (if (and highestmodseq
1536 (not start-article
))
1537 ;; We've gotten the data by QRESYNCing.
1538 (nnimap-update-qresync-info
1539 info existing
(nnimap-imap-ranges-to-gnus-ranges vanished
) flags
)
1540 ;; Do normal non-QRESYNC flag updates.
1541 ;; Update the list of read articles.
1543 (gnus-compress-sequence
1544 (gnus-set-difference
1545 (gnus-set-difference
1548 (cdr (assoc '%Seen flags
))
1549 (cdr (assoc '%Deleted flags
))))
1550 (cdr (assoc '%Flagged flags
)))))
1551 (read (gnus-range-difference
1552 (cons start-article high
) unread
)))
1553 (when (> start-article
1)
1556 (if (> start-article
1)
1557 (gnus-sorted-range-intersection
1558 (cons 1 (1- start-article
))
1559 (gnus-info-read info
))
1560 (gnus-info-read info
))
1562 (when (or (not (listp permanent-flags
))
1563 (memq '%Seen permanent-flags
))
1564 (gnus-info-set-read info read
))
1565 ;; Update the marks.
1566 (setq marks
(gnus-info-marks info
))
1567 (dolist (type (cdr nnimap-mark-alist
))
1568 (when (or (not (listp permanent-flags
))
1569 (memq (car (assoc (caddr type
) flags
))
1571 (memq '%
* permanent-flags
))
1572 (let ((old-marks (assoc (car type
) marks
))
1574 (gnus-compress-sequence
1575 (cdr (or (assoc (caddr type
) flags
) ; %Flagged
1576 (assoc (intern (cadr type
) obarray
) flags
)
1577 (assoc (cadr type
) flags
)))))) ; "\Flagged"
1578 (setq marks
(delq old-marks marks
))
1580 (when (and old-marks
1581 (> start-article
1))
1582 (setq old-marks
(gnus-range-difference
1584 (cons start-article high
)))
1585 (setq new-marks
(gnus-range-nconcat old-marks new-marks
)))
1587 (push (cons (car type
) new-marks
) marks
)))))
1588 ;; Keep track of non-existing articles.
1589 (let* ((old-unexists (assq 'unexist marks
))
1590 (active (gnus-active group
))
1593 (gnus-range-difference
1595 (gnus-compress-sequence existing
))
1598 (gnus-list-range-difference
1599 existing
(gnus-active group
))))))
1600 (when (> (car active
) 1)
1601 (setq unexists
(gnus-range-add
1602 (cons 1 (1- (car active
)))
1605 (setcdr old-unexists unexists
)
1606 (push (cons 'unexist unexists
) marks
)))
1607 (gnus-info-set-marks info marks t
))))
1608 ;; Tell Gnus whether there are any \Recent messages in any of
1610 (let ((recent (cdr (assoc '%Recent flags
))))
1613 (> (car (last recent
)) (cdr active
)))
1614 (push (list (cons (gnus-group-real-name group
) 0))
1615 nnmail-split-history
)))
1616 ;; Note the active level for the next run-through.
1617 (gnus-group-set-parameter info
'active
(gnus-active group
))
1618 (gnus-group-set-parameter info
'uidvalidity uidvalidity
)
1619 (gnus-group-set-parameter info
'modseq highestmodseq
)
1620 (nnimap-store-info info
(gnus-active group
)))))))
1622 (defun nnimap-update-qresync-info (info existing vanished flags
)
1623 ;; Add all the vanished articles to the list of read articles.
1628 (gnus-range-add (gnus-info-read info
)
1630 (cdr (assq '%Flagged flags
)))
1631 (cdr (assq '%Seen flags
))))
1632 (let ((marks (gnus-info-marks info
)))
1633 (dolist (type (cdr nnimap-mark-alist
))
1634 (let ((ticks (assoc (car type
) marks
))
1636 (cdr (or (assoc (caddr type
) flags
) ; %Flagged
1637 (assoc (intern (cadr type
) obarray
) flags
)
1638 (assoc (cadr type
) flags
))))) ; "\Flagged"
1639 (setq marks
(delq ticks marks
))
1641 ;; Add the new marks we got.
1642 (setq ticks
(gnus-add-to-range ticks new-marks
))
1643 ;; Remove the marks from messages that don't have them.
1644 (setq ticks
(gnus-remove-from-range
1646 (gnus-compress-sequence
1647 (gnus-sorted-complement existing new-marks
))))
1649 (push (cons (car type
) ticks
) marks
)))
1650 (gnus-info-set-marks info marks t
))
1651 ;; Add vanished to the list of unexisting articles.
1653 (let* ((old-unexists (assq 'unexist marks
))
1654 (unexists (gnus-range-add (cdr old-unexists
) vanished
)))
1656 (setcdr old-unexists unexists
)
1657 (push (cons 'unexist unexists
) marks
)))
1658 (gnus-info-set-marks info marks t
))))
1660 (defun nnimap-imap-ranges-to-gnus-ranges (irange)
1661 (if (zerop (length irange
))
1664 (dolist (elem (split-string irange
","))
1666 (if (string-match ":" elem
)
1667 (let ((numbers (split-string elem
":")))
1668 (cons (string-to-number (car numbers
))
1669 (string-to-number (cadr numbers
))))
1670 (string-to-number elem
))
1672 (nreverse result
))))
1674 (defun nnimap-store-info (info active
)
1675 (let* ((group (nnimap-decode-gnus-group
1676 (gnus-group-real-name (gnus-info-group info
))))
1677 (entry (assoc group nnimap-current-infos
)))
1679 (setcdr entry
(list info active
))
1680 (push (list group info active
) nnimap-current-infos
))))
1682 (defun nnimap-flags-to-marks (groups)
1683 (let (data group uidnext articles start-article mark permanent-flags
1684 uidvalidity vanished highestmodseq
)
1685 (dolist (elem groups
)
1686 (setq group
(car elem
)
1687 uidnext
(nth 1 elem
)
1688 start-article
(nth 2 elem
)
1689 permanent-flags
(nth 3 elem
)
1690 uidvalidity
(nth 4 elem
)
1691 vanished
(nth 5 elem
)
1692 highestmodseq
(nth 6 elem
)
1693 articles
(nthcdr 7 elem
))
1694 (let ((high (caar articles
))
1696 (dolist (article articles
)
1697 (setq low
(car article
))
1698 (push (car article
) existing
)
1699 (dolist (flag (cdr article
))
1700 (setq mark
(assoc flag marks
))
1702 (push (list flag
(car article
)) marks
)
1703 (setcdr mark
(cons (car article
) (cdr mark
))))))
1704 (push (list group existing marks high low uidnext start-article
1705 permanent-flags uidvalidity vanished highestmodseq
)
1709 (defun nnimap-parse-flags (sequences)
1710 (goto-char (point-min))
1711 ;; Change \Delete etc to %Delete, so that the Emacs Lisp reader can
1713 (subst-char-in-region (point-min) (point-max)
1715 ;; Remove any MODSEQ entries in the buffer, because they may contain
1716 ;; numbers that are too large for 32-bit Emacsen.
1717 (while (re-search-forward " MODSEQ ([0-9]+)" nil t
)
1718 (replace-match "" t t
))
1719 (goto-char (point-min))
1720 (let (start end articles groups uidnext elems permanent-flags
1721 uidvalidity vanished highestmodseq
)
1722 (dolist (elem sequences
)
1723 (destructuring-bind (group-sequence flag-sequence totalp group command
)
1725 (setq start
(point))
1727 ;; The EXAMINE was successful.
1728 (search-forward (format "\n%d OK " group-sequence
) nil t
)
1733 (setq permanent-flags
1734 (if (equal command
"SELECT")
1735 (and (search-forward "PERMANENTFLAGS "
1736 (or end
(point-min)) t
)
1737 (read (current-buffer)))
1741 (and (search-forward "UIDNEXT "
1742 (or end
(point-min)) t
)
1743 (read (current-buffer))))
1746 (and (re-search-forward "UIDVALIDITY \\([0-9]+\\)"
1747 (or end
(point-min)) t
)
1748 ;; Store UIDVALIDITY as a string, as it's
1749 ;; too big for 32-bit Emacsen, usually.
1753 (and (eq flag-sequence
'qresync
)
1754 (re-search-forward "^\\* VANISHED .*? \\([0-9:,]+\\)"
1755 (or end
(point-min)) t
)
1759 (and (re-search-forward "HIGHESTMODSEQ \\([0-9]+\\)"
1760 (or end
(point-min)) t
)
1764 ;; The UID FETCH FLAGS was successful.
1765 (or (eq flag-sequence
'qresync
)
1766 (search-forward (format "\n%d OK " flag-sequence
) nil t
)))
1767 (if (eq flag-sequence
'qresync
)
1771 (setq start
(point))
1773 (while (re-search-forward "^\\* [0-9]+ FETCH " start t
)
1775 (setq elems
(read (current-buffer)))
1776 (push (cons (cadr (memq 'UID elems
))
1777 (cadr (memq 'FLAGS elems
)))
1779 (push (nconc (list group uidnext totalp permanent-flags uidvalidity
1780 vanished highestmodseq
)
1783 (if (eq flag-sequence
'qresync
)
1786 (setq articles nil
))))
1789 (defun nnimap-find-process-buffer (buffer)
1790 (cadr (assoc buffer nnimap-connection-alist
)))
1792 (deffoo nnimap-request-post
(&optional _server
)
1793 (setq nnimap-status-string
"Read-only server")
1796 (defvar gnus-refer-thread-use-nnir
) ;; gnus-sum.el
1797 (declare-function gnus-fetch-headers
"gnus-sum"
1798 (articles &optional limit force-new dependencies
))
1800 (autoload 'nnir-search-thread
"nnir")
1802 (deffoo nnimap-request-thread
(header &optional group server
)
1804 (setq group
(nnimap-decode-gnus-group group
)))
1805 (if gnus-refer-thread-use-nnir
1806 (nnir-search-thread header
)
1807 (when (nnimap-change-group group server
)
1808 (let* ((cmd (nnimap-make-thread-query header
))
1809 (result (with-current-buffer (nnimap-buffer)
1810 (nnimap-command "UID SEARCH %s" cmd
))))
1814 (delete 0 (mapcar #'string-to-number
1815 (cdr (assoc "SEARCH" (cdr result
))))))
1818 (defun nnimap-change-group (group &optional server no-reconnect read-only
)
1819 "Change group to GROUP if non-nil.
1820 If SERVER is set, check that server is connected, otherwise retry
1821 to reconnect, unless NO-RECONNECT is set to t. Return nil if
1822 unsuccessful in connecting.
1823 If GROUP is nil, return t.
1824 If READ-ONLY is set, send EXAMINE rather than SELECT to the server.
1825 Return the server's response to the SELECT or EXAMINE command."
1826 (let ((open-result t
))
1828 (not (nnimap-server-opened server
)))
1829 (setq open-result
(nnimap-open-server server nil no-reconnect
)))
1836 (with-current-buffer (nnimap-buffer)
1837 (let ((result (nnimap-command "%s %S"
1841 (utf7-encode group t
))))
1843 (setf (nnimap-group nnimap-object
) group
1844 (nnimap-select-result nnimap-object
) result
)
1847 (defun nnimap-find-connection (buffer)
1848 "Find the connection delivering to BUFFER."
1849 (let ((entry (assoc buffer nnimap-connection-alist
)))
1851 (if (and (buffer-name (cadr entry
))
1852 (get-buffer-process (cadr entry
))
1853 (memq (process-status (get-buffer-process (cadr entry
)))
1855 (get-buffer-process (cadr entry
))
1856 (setq nnimap-connection-alist
(delq entry nnimap-connection-alist
))
1859 (defvar nnimap-sequence
0)
1861 (defun nnimap-send-command (&rest args
)
1862 (setf (nnimap-last-command-time nnimap-object
) (current-time))
1863 (process-send-string
1864 (get-buffer-process (current-buffer))
1867 (incf nnimap-sequence
)
1868 (apply #'format args
)
1869 (if (nnimap-newlinep nnimap-object
)
1872 ;; Some servers apparently can't have many outstanding
1873 ;; commands, so throttle them.
1874 (unless nnimap-streaming
1875 (nnimap-wait-for-response nnimap-sequence
))
1878 (defvar nnimap-record-commands nil
1879 "If non-nil, log commands to the \"*imap log*\" buffer.")
1881 (defun nnimap-log-buffer ()
1882 (let ((name "*imap log*"))
1883 (or (get-buffer name
)
1884 (with-current-buffer (get-buffer-create name
)
1885 (setq-local window-point-insertion-type t
)
1886 (current-buffer)))))
1888 (defun nnimap-log-command (command)
1889 (when nnimap-record-commands
1890 (with-current-buffer (nnimap-log-buffer)
1891 (goto-char (point-max))
1892 (insert (format-time-string "%H:%M:%S")
1893 " [" nnimap-address
"] "
1894 (if nnimap-inhibit-logging
1899 (defun nnimap-command (&rest args
)
1901 (let* ((sequence (apply #'nnimap-send-command args
))
1902 (response (nnimap-get-response sequence
)))
1903 (if (equal (caar response
) "OK")
1905 (nnheader-report 'nnimap
"%s"
1906 (mapconcat (lambda (a)
1908 (car response
) " "))
1911 (defun nnimap-get-response (sequence)
1912 (nnimap-wait-for-response sequence
)
1913 (nnimap-parse-response))
1915 (defun nnimap-wait-for-connection (&optional regexp
)
1916 (nnimap-wait-for-line (or regexp
"^[*.] .*\n") "[*.] \\([A-Z0-9]+\\)"))
1918 (defun nnimap-wait-for-line (regexp &optional response-regexp
)
1919 (let ((process (get-buffer-process (current-buffer))))
1920 (goto-char (point-min))
1921 (while (and (memq (process-status process
)
1923 (not (re-search-forward regexp nil t
)))
1924 (nnheader-accept-process-output process
)
1925 (goto-char (point-min)))
1927 (and (looking-at (or response-regexp regexp
))
1930 (defun nnimap-wait-for-response (sequence &optional messagep
)
1931 (let ((process (get-buffer-process (current-buffer)))
1935 (goto-char (point-max))
1936 (while (and (setq openp
(memq (process-status process
)
1939 ;; Skip past any "*" lines that the server has
1941 (while (and (not (bobp))
1944 (looking-at "\\*\\|[0-9]+ OK NOOP"))))
1945 (not (looking-at (format "%d .*\n" sequence
)))))
1947 (nnheader-message-maybe
1948 7 "nnimap read %dk from %s%s" (/ (buffer-size) 1000)
1950 (if (not (zerop (nnimap-initial-resync nnimap-object
)))
1951 (format " (initial sync of %d group%s; please wait)"
1952 (nnimap-initial-resync nnimap-object
)
1953 (if (= (nnimap-initial-resync nnimap-object
) 1)
1957 (nnheader-accept-process-output process
)
1958 (goto-char (point-max)))
1959 (setf (nnimap-initial-resync nnimap-object
) 0)
1964 ;; The user hit C-g while we were waiting: kill the process, in case
1965 ;; it's a gnutls-cli process that's stuck (tends to happen a lot behind
1967 (delete-process process
)
1970 (defun nnimap-parse-response ()
1971 (let ((lines (split-string (nnimap-last-response-string) "\r\n" t
))
1973 (dolist (line lines
)
1974 (push (cdr (nnimap-parse-line line
)) result
))
1975 ;; Return the OK/error code first, and then all the "continuation
1976 ;; lines" afterwards.
1978 (nreverse result
))))
1980 ;; Parse an IMAP response line lightly. They look like
1981 ;; "* OK [UIDVALIDITY 1164213559] UIDs valid", typically, so parse
1982 ;; the lines into a list of strings and lists of string.
1983 (defun nnimap-parse-line (line)
1986 (mm-disable-multibyte)
1988 (goto-char (point-min))
1990 (if (eql (setq char
(following-char)) ?
)
1998 (if (search-forward "]" (line-end-position) 'move
)
2005 (if (search-forward ")" (line-end-position) 'move
)
2012 (1- (or (search-forward "\"" (line-end-position) 'move
)
2015 (buffer-substring (point) (if (search-forward " " nil t
)
2017 (goto-char (point-max))))))
2019 (nreverse result
))))
2021 (defun nnimap-last-response-string ()
2024 (let ((end (point)))
2028 (while (and (not (bobp))
2029 (eql (following-char) ?
*))
2031 (unless (eql (following-char) ?
*)
2033 (buffer-substring (point) end
))))
2035 (defvar nnimap-incoming-split-list nil
)
2037 (defun nnimap-fetch-inbox (articles)
2039 (nnimap-wait-for-response
2040 (nnimap-send-command
2042 (nnimap-article-ranges articles
)
2043 (format "(UID %s%s)"
2049 (nnimap-split-download-body-default
2057 (defun nnimap-split-incoming-mail ()
2058 (with-current-buffer (nnimap-buffer)
2059 (let ((nnimap-incoming-split-list nil
)
2060 (nnmail-split-methods
2062 ((eq nnimap-split-methods
'default
)
2063 nnmail-split-methods
)
2064 (nnimap-split-methods
2065 nnimap-split-methods
)
2067 'nnmail-split-fancy
)))
2068 (nnmail-split-fancy (or nnimap-split-fancy
2069 nnmail-split-fancy
))
2070 (nnmail-inhibit-default-split-group t
)
2071 (groups (nnimap-get-groups))
2072 (can-move (and (nnimap-capability "MOVE")
2073 (equal (nnimap-quirk "MOVE") "MOVE")))
2076 (nnimap-command "SELECT %S" nnimap-inbox
)
2077 (setf (nnimap-group nnimap-object
) nnimap-inbox
)
2078 (setq new-articles
(nnimap-new-articles (nnimap-get-flags "1:*")))
2080 (nnimap-fetch-inbox new-articles
)
2081 (nnimap-transform-split-mail)
2082 (nnheader-ms-strip-cr)
2084 (nnmail-split-incoming (current-buffer)
2085 #'nnimap-save-mail-spec
2087 #'nnimap-dummy-active-number
2088 #'nnimap-save-mail-spec
)
2089 (when nnimap-incoming-split-list
2090 (let ((specs (nnimap-make-split-specs nnimap-incoming-split-list
))
2091 sequences junk-articles
)
2092 ;; Create any groups that doesn't already exist on the
2094 (dolist (spec specs
)
2095 (when (and (not (member (car spec
) groups
))
2096 (not (eq (car spec
) 'junk
)))
2097 (nnimap-command "CREATE %S" (utf7-encode (car spec
) t
))))
2098 ;; Then copy over all the messages.
2100 (dolist (spec specs
)
2101 (let ((group (car spec
))
2102 (ranges (cdr spec
)))
2103 (if (eq group
'junk
)
2104 (setq junk-articles ranges
)
2105 ;; Don't copy if the message is already in its
2107 (unless (string= group nnimap-inbox
)
2108 (push (list (nnimap-send-command
2112 (nnimap-article-ranges ranges
)
2113 (utf7-encode group t
))
2116 ;; Wait for the last COPY response...
2117 (when (and (not can-move
) sequences
)
2118 (nnimap-wait-for-response (caar sequences
))
2119 ;; And then mark the successful copy actions as deleted,
2120 ;; and possibly expunge them.
2121 (nnimap-mark-and-expunge-incoming
2122 (nnimap-parse-copied-articles sequences
)))
2123 (nnimap-mark-and-expunge-incoming junk-articles
)))))))
2125 (defun nnimap-mark-and-expunge-incoming (range)
2127 (setq range
(nnimap-article-ranges range
))
2130 (nnimap-send-command
2131 "UID STORE %s +FLAGS.SILENT (\\Deleted)" range
)))
2133 ;; If the server supports it, we now delete the message we have
2134 ;; just copied over.
2135 ((nnimap-capability "UIDPLUS")
2136 (setq sequence
(nnimap-send-command "UID EXPUNGE %s" range
)))
2137 ;; If it doesn't support UID EXPUNGE, then we only expunge if the
2138 ;; user has configured it.
2140 (setq sequence
(nnimap-send-command "EXPUNGE"))))
2141 (nnimap-wait-for-response sequence
))))
2143 (defun nnimap-parse-copied-articles (sequences)
2144 (let (sequence copied range
)
2145 (goto-char (point-min))
2146 (while (re-search-forward "^\\([0-9]+\\) OK\\b" nil t
)
2147 (setq sequence
(string-to-number (match-string 1)))
2148 (when (setq range
(cadr (assq sequence sequences
)))
2149 (push (gnus-uncompress-range range
) copied
)))
2150 (gnus-compress-sequence (sort (apply #'nconc copied
) #'<))))
2152 (defun nnimap-new-articles (flags)
2154 (dolist (elem flags
)
2155 (unless (gnus-list-memq-of-list nnimap-unsplittable-articles
2157 (push (car elem
) new
)))
2158 (gnus-compress-sequence (nreverse new
))))
2160 (defun nnimap-make-split-specs (list)
2164 (destructuring-bind (article spec
) elem
2165 (dolist (group (delete nil
(mapcar #'car spec
)))
2166 (unless (setq entry
(assoc group specs
))
2167 (push (setq entry
(list group
)) specs
))
2168 (setcdr entry
(cons article
(cdr entry
))))))
2169 (dolist (entry specs
)
2170 (setcdr entry
(gnus-compress-sequence (sort (cdr entry
) #'<))))
2173 (defun nnimap-transform-split-mail ()
2174 (goto-char (point-min))
2175 (let (article bytes
)
2178 (while (not (looking-at "\\* [0-9]+ FETCH.+UID \\([0-9]+\\)"))
2179 (delete-region (point) (progn (forward-line 1) (point)))
2182 (setq article
(match-string 1)
2183 bytes
(nnimap-get-length))
2184 (delete-region (line-beginning-position) (line-end-position))
2185 ;; Insert MMDF separator, and a way to remember what this
2187 (insert (format "\^A\^A\^A\^A\n\nX-nnimap-article: %s" article
))
2188 (forward-char (1+ bytes
))
2189 (setq bytes
(nnimap-get-length))
2190 (delete-region (line-beginning-position) (line-end-position))
2191 ;; There's a body; skip past that.
2193 (forward-char (1+ bytes
))
2194 (delete-region (line-beginning-position) (line-end-position)))))))
2196 (defun nnimap-dummy-active-number (_group &optional _server
)
2199 (defun nnimap-save-mail-spec (group-art &optional _server _full-nov
)
2201 (goto-char (point-min))
2202 (if (not (re-search-forward "X-nnimap-article: \\([0-9]+\\)" nil t
))
2203 (error "Invalid nnimap mail")
2204 (setq article
(string-to-number (match-string 1))))
2206 (if (eq group-art
'junk
)
2207 (list (cons 'junk
1))
2209 nnimap-incoming-split-list
)))
2211 (defun nnimap-make-thread-query (header)
2212 (let* ((id (mail-header-id header
))
2214 (or (mail-header-references header
)
2218 "(OR HEADER REFERENCES %S HEADER Message-Id %S)"
2220 (dolist (refid refs value
)
2222 "(OR (OR HEADER Message-Id %S HEADER REFERENCES %S) %s)"
2223 refid refid value
)))))
2228 ;;; nnimap.el ends here