aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Abrahamsen2019-07-15 10:43:40 -0700
committerEric Abrahamsen2019-07-15 10:43:40 -0700
commit0797b39185e66983c7286e89f93dd4f6c83b6ea7 (patch)
treea3d21de82fd55a0ebb4231a07a0fbeb3e44d6139
parentd6bc55ae2dc98c83e58a28e380ce4bcf2ed00bb3 (diff)
downloademacs-0797b39185e66983c7286e89f93dd4f6c83b6ea7.tar.gz
emacs-0797b39185e66983c7286e89f93dd4f6c83b6ea7.zip
Possibly skip IMAP server FETCH responses
See bug#35433 * lisp/gnus/nnimap.el (nnimap-transform-headers): Skip FETCH responses that only provide message flags, not message headers.
-rw-r--r--lisp/gnus/nnimap.el93
1 files changed, 53 insertions, 40 deletions
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 06817f452d2..67c5db1e044 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -231,8 +231,9 @@ textual parts.")
231 'headers)) 231 'headers))
232 232
233(defun nnimap-transform-headers () 233(defun nnimap-transform-headers ()
234 "Transform server's FETCH response into parseable headers."
234 (goto-char (point-min)) 235 (goto-char (point-min))
235 (let (article lines size string labels) 236 (let (seen-articles article lines size string labels)
236 (cl-block nil 237 (cl-block nil
237 (while (not (eobp)) 238 (while (not (eobp))
238 (while (not (looking-at "\\* [0-9]+ FETCH")) 239 (while (not (looking-at "\\* [0-9]+ FETCH"))
@@ -261,45 +262,57 @@ textual parts.")
261 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position) 262 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
262 t) 263 t)
263 (match-string 1))) 264 (match-string 1)))
264 (setq lines nil) 265 ;; If we've already got headers for this article, or this
265 (beginning-of-line) 266 ;; FETCH line doesn't provide headers for the article, skip
266 (setq size 267 ;; it. See bug#35433.
267 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)" 268 (if (or (member article seen-articles)
268 (line-end-position) 269 (save-excursion
269 t) 270 (forward-line)
270 (match-string 1))) 271 (null (looking-at-p
271 (beginning-of-line) 272 ;; We're expecting a mail header.
272 (when (search-forward "X-GM-LABELS" (line-end-position) t) 273 "^[!-9;-~]+: "))))
273 (setq labels (ignore-errors (read (current-buffer))))) 274 (delete-region (line-beginning-position)
274 (beginning-of-line) 275 (1+ (line-end-position)))
275 (when (search-forward "BODYSTRUCTURE" (line-end-position) t) 276 (setq lines nil)
276 (let ((structure (ignore-errors 277 (beginning-of-line)
277 (read (current-buffer))))) 278 (setq size
278 (while (and (consp structure) 279 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
279 (not (atom (car structure)))) 280 (line-end-position)
280 (setq structure (car structure))) 281 t)
281 (setq lines (if (and 282 (match-string 1)))
282 (stringp (car structure)) 283 (beginning-of-line)
283 (equal (upcase (nth 0 structure)) "MESSAGE") 284 (when (search-forward "X-GM-LABELS" (line-end-position) t)
284 (equal (upcase (nth 1 structure)) "RFC822")) 285 (setq labels (ignore-errors (read (current-buffer)))))
285 (nth 9 structure) 286 (beginning-of-line)
286 (nth 7 structure))))) 287 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
287 (delete-region (line-beginning-position) (line-end-position)) 288 (let ((structure (ignore-errors
288 (insert (format "211 %s Article retrieved." article)) 289 (read (current-buffer)))))
289 (forward-line 1) 290 (while (and (consp structure)
290 (when size 291 (not (atom (car structure))))
291 (insert (format "Chars: %s\n" size))) 292 (setq structure (car structure)))
292 (when lines 293 (setq lines (if (and
293 (insert (format "Lines: %s\n" lines))) 294 (stringp (car structure))
294 (when labels 295 (equal (upcase (nth 0 structure)) "MESSAGE")
295 (insert (format "X-GM-LABELS: %s\n" labels))) 296 (equal (upcase (nth 1 structure)) "RFC822"))
296 ;; Most servers have a blank line after the headers, but 297 (nth 9 structure)
297 ;; Davmail doesn't. 298 (nth 7 structure)))))
298 (unless (re-search-forward "^\r$\\|^)\r?$" nil t) 299 (delete-region (line-beginning-position) (line-end-position))
299 (goto-char (point-max))) 300 (insert (format "211 %s Article retrieved." article))
300 (delete-region (line-beginning-position) (line-end-position)) 301 (forward-line 1)
301 (insert ".") 302 (when size
302 (forward-line 1))))) 303 (insert (format "Chars: %s\n" size)))
304 (when lines
305 (insert (format "Lines: %s\n" lines)))
306 (when labels
307 (insert (format "X-GM-LABELS: %s\n" labels)))
308 ;; Most servers have a blank line after the headers, but
309 ;; Davmail doesn't.
310 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
311 (goto-char (point-max)))
312 (delete-region (line-beginning-position) (line-end-position))
313 (insert ".")
314 (forward-line 1)
315 (push article seen-articles))))))
303 316
304(defun nnimap-unfold-quoted-lines () 317(defun nnimap-unfold-quoted-lines ()
305 ;; Unfold quoted {number} strings. 318 ;; Unfold quoted {number} strings.