debbugs: Simplify mbox processing.
authorRicardo Wurmus <rekado@elephly.net>
Thu, 7 May 2020 12:10:02 +0000 (14:10 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Thu, 7 May 2020 12:10:02 +0000 (14:10 +0200)
* mumi/debbugs.scm (read-emails-from-bug-log): Use mbox->emails
instead of dropping lines haphazardly.

mumi/debbugs.scm

index 7873c863bb59adfa8506790d1248fd45a85d1502..c08a7bdd770a5e301d052646bb0effe397b91639 100644 (file)
@@ -76,23 +76,16 @@ ends with ^C.
             (#\etx
              (let ((mails*
                     (if (member type keep)
-                        ;; 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"))
+                        (let* ((contents (string-join (drop (reverse lines) 1) "\n"))
                                (mail (catch #t
                                        (lambda ()
-                                         (parse-email content))
+                                         (parse-email
+                                          (and=> (call-with-input-string contents mbox->emails)
+                                                 first)))
                                        (lambda args
                                          (format (current-error-port)
-                                                 "failed to process email~%")
+                                                 "failed to process email~%  ~a~%"
+                                                 args)
                                          #f))))
                           (let ((id (and mail (assoc-ref (email-headers mail) 'message-id))))
                             (if (and id (not (hash-ref msgids id)))