I have an action that parses GitHub notifications to find a pull request link and open it in the browser. To do that, I need to extract the plain text version of the email.
Before, I used the :body-txt field, but I guess GitHub changed to using MIME attachments.
As far as I can tell, extracting the first plain-text MIME attachment is not entirely trivial:
Would it make sense to add a utility to either (a) grab the first MIME part of a certain type or (b) provide some logic to extract the plain text version of the email?
Here is the full action, in case it's useful:
(defun stefan/mu4e-action-view-pull-request (msg)
"Locate a GitHub pull request URL and open in the browser.
The browser used is specified in `browse-url-generic-program'."
(let* ((parts (mu4e-view-mime-parts))
(text-parts (seq-filter
(lambda (el) (equal (plist-get el :mime-type) "text/plain"))
parts))
(txt (mm-get-part (plist-get (car text-parts) :handle)))
(pr-re (rx line-start "https://github.com"
"/" (one-or-more (not "/"))
"/" (one-or-more (not "/"))
"/" (or "pull" "issues")
"/" (one-or-more digit)
(optional "#" (one-or-more not-newline)))))
(unless txt
(mu4e-error "No text part for this message"))
(unless (string-match pr-re txt)
(mu4e-error "No pull request URL found"))
(browse-url (match-string 0 txt))))
I have an action that parses GitHub notifications to find a pull request link and open it in the browser. To do that, I need to extract the plain text version of the email.
Before, I used the
:body-txt
field, but I guess GitHub changed to using MIME attachments. As far as I can tell, extracting the first plain-text MIME attachment is not entirely trivial:Would it make sense to add a utility to either (a) grab the first MIME part of a certain type or (b) provide some logic to extract the plain text version of the email?
Here is the full action, in case it's useful: