From 28e3cf8574dca17746f5d87af36ed7ac116c8077 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 7 Feb 2012 03:32:39 +0100 Subject: [PATCH] Allow nnimap to parse headers with spaces in odd places (nnimap-transform-headers): Fix parsing BODYSTRUCTURE elements that have newlines within the strings, and where the UID comes after the BODYSTRUCTURE element (bug#10537). --- lisp/ChangeLog | 7 +++++-- lisp/nnimap.el | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2ce4caee4..26547d190 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,8 +1,11 @@ 2012-02-07 Lars Ingebrigtsen - * nnimap.el (nnimap-transform-headers): Removed unused variable. + * nnimap.el (nnimap-transform-headers): Remove unused variable. + (nnimap-transform-headers): Fix parsing BODYSTRUCTURE elements that + have newlines within the strings, and where the UID comes after the + BODYSTRUCTURE element (bug#10537). - * shr-color.el (shr-color-set-minimum-interval): Renamed to add prefix + * shr-color.el (shr-color-set-minimum-interval): Rename to add prefix (bug#10732). * shr.el (shr-insert-document): Add doc string. diff --git a/lisp/nnimap.el b/lisp/nnimap.el index 57c81ad18..c5b77dbef 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -192,21 +192,30 @@ textual parts.") (let (article lines size string) (block nil (while (not (eobp)) - (while (not (looking-at "\\* [0-9]+ FETCH.+?UID \\([0-9]+\\)")) + (while (not (looking-at "\\* [0-9]+ FETCH")) (delete-region (point) (progn (forward-line 1) (point))) (when (eobp) (return))) - (setq article (match-string 1)) + (goto-char (match-end 0)) ;; Unfold quoted {number} strings. - (while (re-search-forward "[^]][ (]{\\([0-9]+\\)}\r?\n" - (1+ (line-end-position)) t) + (while (re-search-forward + "[^]][ (]{\\([0-9]+\\)}\r?\n" + (save-excursion + (or (re-search-forward "\\* [0-9]+ FETCH" nil t) + (point-max))) + t) (setq size (string-to-number (match-string 1))) (delete-region (+ (match-beginning 0) 2) (point)) (setq string (buffer-substring (point) (+ (point) size))) (delete-region (point) (+ (point) size)) - (insert (format "%S" string))) - (setq lines nil) + (insert (format "%S" (subst-char-in-string + ?\n ?\s string)))) (beginning-of-line) + (setq article + (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position) + t) + (match-string 1))) + (setq lines nil) (setq size (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)" (line-end-position) -- 2.25.1