An emacs package for extracting microdata from HTML and emails. Useful for executing email actions from Emacs.
Personally, I use this package to open Discourse and GitHub PR/issue notifications from notmuch. These examples demonstrate how that works.
Here we display an Ivy menu with all available actions.
(require 'microdata)
(require 'notmuch)
(defun notmuch-show--get-actions ()
(let (html)
(with-current-notmuch-show-message (setq html (microdata-email-actions)))
html))
(defun notmuch-show-action ()
"Pick an action to perform on the email."
(interactive)
(if-let ((actions (notmuch-show--get-actions)))
(when-let* ((selected (completing-read "Action: " actions nil t))
(action (alist-get selected actions nil nil 'equal))
(url (alist-get 'url action)))
(browse-url url))
(user-error "No actions defined!")))
Here we execute the “view” action for the currently viewed email, if any.
(require 'microdata)
(require 'notmuch)
;; This can be used to quickly open an email's "view target" in a web browser.
(defun notmuch-show-action-view ()
"Execute the `view' action."
(interactive)
(with-current-notmuch-show-message
(when-let ((action (car (microdata-email-actions-by-type "ViewAction"))))
(message "%s: %s" (car action) (cdr action))
(browse-url (cdr action)))))
Here we execute the “view” action for the currently selected email (in search mode) if any. I usually bind this to C-c C-c
or equivalent to quickly view issues/PRs from GitHub notification emails.
(require 'microdata)
(require 'notmuch)
(defun notmuch-show-action-view ()
"Execute the `view' action."
(interactive)
(with-current-notmuch-show-message
(when-let ((action (car (microdata-email-actions-by-type "ViewAction"))))
(message "%s: %s" (car action) (cdr action))
(browse-url (cdr action)))))