Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mu4e rfe] Make it easier to access MIME part of given type #2647

Open
stefanv opened this issue Mar 1, 2024 · 1 comment
Open

[mu4e rfe] Make it easier to access MIME part of given type #2647

stefanv opened this issue Mar 1, 2024 · 1 comment
Labels
mu4e specific for mu4e rfe

Comments

@stefanv
Copy link
Contributor

stefanv commented Mar 1, 2024

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:

(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)))

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))))
@stefanv stefanv added mu4e specific for mu4e new rfe labels Mar 1, 2024
@djcb
Copy link
Owner

djcb commented Mar 1, 2024

Sounds useful. Something for the next development series :)

@djcb djcb removed the new label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mu4e specific for mu4e rfe
Projects
None yet
Development

No branches or pull requests

2 participants