[Emacs] Give mu4e the ability to export mails to PDF again!

This commit is contained in:
Lucien Cartier-Tilet 2021-03-26 13:49:22 +01:00
parent 4f7927a5f7
commit 841f6b7f85
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -4494,6 +4494,22 @@ signature to emails to the hook called when creating a new email.
(add-hook 'mu4e-compose-mode-hook 'mml-secure-message-sign-pgpmime)
#+END_SRC
mu4e used to be able to export emails to PDFs, but unfortunately this
possibility was discontinued. But we can (sort of) bring it back!
#+BEGIN_SRC emacs-lisp
(defun mu4e-action-open-as-pdf (msg)
"Export and open as PDF a mu4e `MSG'"
(let* ((date (mu4e-message-field msg :date))
(infile (mu4e~write-body-to-html msg))
(outfile (format-time-string "/tmp/%Y-%m-%d%H%M%S.pdf" date)))
(with-temp-buffer
(shell-command
(format "wkhtmltopdf %s %s" infile outfile) t))
(find-file outfile)))
(add-to-list 'mu4e-view-actions '("PDF view" . mu4e-action-open-as-pdf) t)
#+END_SRC
Lastly, some emails are better displayed in a browser than in Emacs. My Emacs
build has the webkit browser enabled, so Ill add an option to open with it
emails.