diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2022-12-24 23:44:43 +0100 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2022-12-24 23:44:43 +0100 |
commit | 0a90eeda9b5e12a2f83e3917c46fa539f308d0c8 (patch) | |
tree | 1a8749ce12c22cb7883b0ff8af78eb79e68e0f3f | |
parent | 52f15bc1134ba2477f8461dd13c02f275f3d9660 (diff) |
debbugs: Swap first two lines of raw emails.
Fixes <https://issues.guix.gnu.org/41906>.
-rw-r--r-- | mumi/debbugs.scm | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/mumi/debbugs.scm b/mumi/debbugs.scm index 75e55b4..263b4e5 100644 --- a/mumi/debbugs.scm +++ b/mumi/debbugs.scm @@ -102,35 +102,35 @@ ends with ^C. (loop msgids mails lines 'recips #t)) ;; Ctrl-C, end of record (#\etx + ;; For some reason Debbugs stores the first two lines out + ;; of order. Swap them. See + ;; https://issues.guix.gnu.org/41906 for details. (let ((mails* (if (member type keep) - (if raw? - (cons (string-join (reverse lines) "\n") - mails) - ;; TODO: This is very ugly. The first few - ;; lines of the raw messages stored in Debbugs - ;; logs seem to confuse the email parser, so we - ;; try to strip them off. - (let* ((content (string-join - (drop-while (lambda (line) - (or (string-prefix? "From " line) - (string-prefix? "Received" line) - (string-prefix? "\t" line) - (string-prefix? " " line))) - (reverse lines)) "\n")) - (mail (catch #t - (lambda () - (parse-email content)) - (lambda args - (format (current-error-port) - "failed to process email~%") - #f)))) - (let ((id (and mail (assoc-ref (email-headers mail) 'message-id)))) - (if (and id (not (hash-ref msgids id))) - (begin - (hash-set! msgids id #t) - (cons mail mails)) - mails)))) + (let ((lines* (match (reverse lines) + ((first second . rest) + (cons* second first rest)) + (other other)))) + (if raw? + (cons (string-join lines* "\n") mails) + ;; TODO: The first line of the raw + ;; messages stored in Debbugs logs seem + ;; to confuse the email parser, so we + ;; drop it. + (let* ((content (string-join (drop lines* 1) "\n")) + (mail (catch #t + (lambda () + (parse-email content)) + (lambda args + (format (current-error-port) + "failed to process email~%") + #f)))) + (let ((id (and mail (assoc-ref (email-headers mail) 'message-id)))) + (if (and id (not (hash-ref msgids id))) + (begin + (hash-set! msgids id #t) + (cons mail mails)) + mails))))) mails))) (loop msgids mails* '() 'init #f))) ;; Ctrl-E, beginning of email in recips |