From: Mark Wooding Date: Fri, 14 Mar 2025 15:53:05 +0000 (+0000) Subject: el/mdw-gnus-patch.el: Update the `imap-parse-body' hack. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/942deafbf83cccdc9e41ee3ab0dee04be8a50515 el/mdw-gnus-patch.el: Update the `imap-parse-body' hack. I forget now why this is important, but it is. --- diff --git a/el/mdw-gnus-patch.el b/el/mdw-gnus-patch.el index 49e1072..856f513 100644 --- a/el/mdw-gnus-patch.el +++ b/el/mdw-gnus-patch.el @@ -17,118 +17,86 @@ (defun imap-parse-body () (if (eq (char-after) ?\() (let (subbody) (while (and (eq (char-after) ?\() - (setq subbody - (imap-parse-body))) - ;; buggy stalker communigate pro - ;; 3.0 insert a SPC between - ;; parts in multiparts - (when (and (eq (char-after) ?\ - ) - (eq (char-after (1+ - (point))) ?\()) + (setq subbody (imap-parse-body))) + ;; buggy stalker communigate pro 3.0 insert a SPC between parts + ;; in multiparts + (when (and (eq (char-after) ?\ ) + (eq (char-after (1+ (point))) ?\()) (imap-forward)) (push subbody body)) - (imap-forward) - (push (imap-parse-string) body) - ;; media-subtype - (when (eq (char-after) ?\ ) ;; body-ext-mpart: - (imap-forward) - (if (eq - (char-after) - ?\() ;; body-fld-param - (push - (imap-parse-string-list) body) - (push (and - (imap-parse-nil) nil) body)) - (setq body - (append - (imap-parse-body-ext) body))) ;; body-ext-... - (assert (eq (char-after) - ?\)) nil "In imap-parse-body") - (imap-forward) - (nreverse body)) - - (push (imap-parse-string) body) ;; media-type (imap-forward) (push (imap-parse-string) body) ;; media-subtype + (when (eq (char-after) ?\ ) ;; body-ext-mpart: + (imap-forward) + (if (eq (char-after) ?\() ;; body-fld-param + (push (imap-parse-string-list) body) + (push (and (imap-parse-nil) nil) body)) + (setq body + (append (imap-parse-body-ext) body))) ;; body-ext-... + (assert (eq (char-after) ?\)) nil "In imap-parse-body") (imap-forward) - ;; next line for Sun SIMS bug - (and (eq (char-after) ? ) (imap-forward)) - (if (eq (char-after) ?\() ;; body-fld-param - (push (imap-parse-string-list) body) - (push (and (imap-parse-nil) nil) body)) - (imap-forward) - (push (imap-parse-nstring) body) ;; body-fld-id - (imap-forward) - (push (imap-parse-nstring) body) ;; body-fld-desc - (imap-forward) - ;; next `or' for Sun SIMS bug, it regard - ;; body-fld-enc as a - ;; nstring and return nil instead of defaulting - ;; back to 7BIT - ;; as the standard says. - (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc - (imap-forward) - (push (imap-parse-number) body) ;; body-fld-octets + (nreverse body)) - ;; ok, we're done parsing the required parts, - ;; what comes now is one - ;; of three things: - ;; - ;; envelope (then we're parsing - ;; body-type-msg) - ;; body-fld-lines (then we're parsing - ;; body-type-text) - ;; body-ext-1part (then we're parsing - ;; body-type-basic) - ;; - ;; the problem is that the two first are in - ;; turn optionally followed - ;; by the third. So we parse the first two here - ;; (if there are any)... + (push (imap-parse-string) body) ;; media-type + (imap-forward) + (push (imap-parse-string) body) ;; media-subtype + (imap-forward) + ;; next line for Sun SIMS bug + (and (eq (char-after) ? ) (imap-forward)) + (if (eq (char-after) ?\() ;; body-fld-param + (push (imap-parse-string-list) body) + (push (and (imap-parse-nil) nil) body)) + (imap-forward) + (push (imap-parse-nstring) body) ;; body-fld-id + (imap-forward) + (push (imap-parse-nstring) body) ;; body-fld-desc + (imap-forward) + ;; next `or' for Sun SIMS bug, it regards body-fld-enc as a nstring + ;; and return nil instead of defaulting back to 7BIT as the standard + ;; says. + (push (or (imap-parse-nstring) "7BIT") body) ;; body-fld-enc + (imap-forward) + (push (imap-parse-number) body) ;; body-fld-octets - (when (eq (char-after) ?\ ) - (imap-forward) - (let (lines) - (cond ((eq (char-after) ?\() ;; body-type-msg: - (push (imap-parse-envelope) - body) ;; envelope - (imap-forward) - (push - (imap-parse-body) body) ;; body - ;; buggy stalker - ;; communigate pro - ;; 3.0 doesn't - ;; print - ;; number of lines - ;; in - ;; message/rfc822 - ;; attachment - (if (eq - (char-after) ?\)) - (push 0 - body) - (imap-forward) - (push - (imap-parse-number) body))) ;; body-fld-lines - ((setq lines - (imap-parse-number)) ;; body-type-text: - (push lines body)) ;; body-fld-lines - (t - (backward-char))))) ;; no match... + ;; ok, we're done parsing the required parts, what comes now is one + ;; of three things: + ;; + ;; envelope (then we're parsing body-type-msg) + ;; body-fld-lines (then we're parsing body-type-text) + ;; body-ext-1part (then we're parsing body-type-basic) + ;; + ;; the problem is that the two first are in turn optionally followed + ;; by the third. So we parse the first two here (if there are + ;; any)... - ;; ...and then parse the third one here... + (when (eq (char-after) ?\ ) + (imap-forward) + (let (lines) + (cond ((eq (char-after) ?\() ;; body-type-msg: + (push (imap-parse-envelope) body) ;; envelope + (imap-forward) + (push (imap-parse-body) body) ;; body + ;; buggy stalker communigate pro 3.0 doesn't print number + ;; of lines in message/rfc822 attachment + (if (eq (char-after) ?\)) + (push 0 body) + (imap-forward) + (push (imap-parse-number) body))) ;; body-fld-lines + ((setq lines (imap-parse-number)) ;; body-type-text: + (push lines body)) ;; body-fld-lines + (t + (backward-char))))) ;; no match... - (when (eq (char-after) ?\ ) ;; body-ext-1part: - (imap-forward) - (push (imap-parse-nstring) body) ;; body-fld-md5 - (setq body (append (imap-parse-body-ext) - body))) ;; body-ext-1part.. + ;; ...and then parse the third one here... - (assert (eq (char-after) ?\)) nil "In - imap-parse-body 2") - (imap-forward) - (nreverse body))))) + (when (eq (char-after) ?\ ) ;; body-ext-1part: + (imap-forward) + (push (imap-parse-nstring) body) ;; body-fld-md5 + (setq body (append (imap-parse-body-ext) body))) ;; body-ext-1part.. + + (assert (eq (char-after) ?\)) nil "In imap-parse-body 2") + (imap-forward) + (nreverse body))))) (defvar imap-enable-exchange-bug-workaround nil "Send FETCH UID commands as *:* instead of *.