Mu4e config

This commit is contained in:
Thomas Dehaeze 2020-04-06 17:10:39 +02:00
parent 97e66a6215
commit 06603fae36

View File

@ -853,7 +853,7 @@ by spaces.
:message "you need to install the programs: pdflatex and imagemagick."
:image-input-type "pdf"
:image-output-type "png"
:image-size-adjust (0.4 . 0.4)
:image-size-adjust (1.0 . 1.0)
:latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
:image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
(dvipng
@ -2521,209 +2521,21 @@ Map Functions
'append)
#+end_src
* Mails With Mu4e
:PROPERTIES:
:header-args:emacs-lisp+: :tangle no
:END:
- https://github.com/kzar/davemail
- http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/
- http://spacemacs.org/layers/+email/mu4e/README.html
- http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top
- https://notanumber.io/2016-10-03/better-email-with-mu4e/
- https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
- http://www.brool.com/post/using-mu4e/
- https://www.reddit.com/r/emacs/comments/8q84dl/tip_how_to_easily_manage_your_emails_with_mu4e/
- https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
* Mu4e
** Ressources
Documentation:
- [ ] Mu4e documentation: http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top
- [ ] https://github.com/djcb/mu
** Set default mail user agent to mu4e
#+begin_src emacs-lisp
(setq mail-user-agent 'mu4e-user-agent)
#+end_src
Use contexts for multiple accounts:
- [ ] https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
- [ ] http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/
- [ ] https://notanumber.io/2016-10-03/better-email-with-mu4e/
** Default config
*** Default behavior
#+begin_src emacs-lisp
(setq mu4e-maildir "~/.mail"
mu4e-update-interval nil
mu4e-compose-signature-auto-include t
mu4e-view-show-images t
mu4e-view-show-addresses t)
#+end_src
Send math and source code:
- [ ] https://vxlabs.com/2015/01/28/sending-emails-with-math-and-source-code/
*** Default folders
#+begin_src emacs-lisp
(setq mu4e-sent-folder "/gmail/Sent"
mu4e-drafts-folder "/gmail/Drafts"
mu4e-trash-folder "/gmail/Trash"
mu4e-refile-folder "/gmail/Archive"
mu4e-compose-signature "Thomas Dehaeze\n"
user-mail-address "dehaeze.thomas@gmail.com")
#+end_src
*** Default signature and email address
#+begin_src emacs-lisp
(setq mu4e-compose-signature "Thomas Dehaeze\n"
user-mail-address "dehaeze.thomas@gmail.com")
#+end_src
*** Saving the attachment to Downloads directory
#+begin_src emacs-lisp
(setq mu4e-attachment-dir "~/Downloads")
#+end_src
*** A list of user's e-mail addresses
#+begin_src emacs-lisp
(setq mu4e-user-mail-address-list '("dehaeze.thomas@gmail.com" "thomas.dehaeze@esrf.fr" "thomas.dehaeze@doct.ulg.ac.be"))
#+end_src
*** Mail directory shortcuts
#+begin_src emacs-lisp
(setq mu4e-maildir-shortcuts
'(
("/gmail/Inbox" . ?g)
("/esrf/Inbox" . ?e)
("/ulg/Inbox" . ?u)
))
#+end_src
** TODO Contexts - Email accounts
#+begin_src emacs-lisp :tangle no
(setq mu4e-contexts
`( ,(make-mu4e-context
:name "gmail"
:enter-func (lambda () (mu4e-message "Entering Gmail context"))
:leave-func (lambda () (mu4e-message "Leaving Gmail context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/gmail" (mu4e-message-field msg :maildir))))
:vars '(
(mu4e-sent-messages-behavior . (delete))
(user-mail-address . "dehaeze.thomas@gmail.com")
(mu4e-sent-folder . "/gmail/Sent")
(mu4e-trash-folder . "/gmail/Trash")
(mu4e-drafts-folder . "/gmail/Drafts")
(mu4e-refile-folder . "/gmail/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
,(make-mu4e-context
:name "esrf"
:enter-func (lambda () (mu4e-message "Entering ESRF context"))
:leave-func (lambda () (mu4e-message "Leaving ESRF context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/esrf" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "thomas.dehaeze@esrf.fr")
(mu4e-sent-folder . "/esrf/Sent")
(mu4e-trash-folder . "/esrf/Trash")
(mu4e-drafts-folder . "/esrf/Drafts")
(mu4e-refile-folder . "/esrf/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
,(make-mu4e-context
:name "ulg"
:enter-func (lambda () (mu4e-message "Entering ULG context"))
:leave-func (lambda () (mu4e-message "Leaving ULG context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/ulg" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "thomas.dehaeze@doct.ulg.ac.be")
(mu4e-sent-folder . "/ulg/Sent")
(mu4e-trash-folder . "/ulg/Trash")
(mu4e-drafts-folder . "/ulg/Drafts")
(mu4e-refile-folder . "/ulg/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
))
(setq mu4e-context-policy 'pick-first)
#+end_src
** Receiving emails - Mbsync
Let systemd get the mail, then pressing =U= will just run =mu= to reindex everything.
#+begin_src emacs-lisp
(setq mu4e-get-mail-command "true")
#+end_src
Fix for mbsync found [[http://pragmaticemacs.com/emacs/fixing-duplicate-uid-errors-when-using-mbsync-and-mu4e/][here]].
#+begin_src emacs-lisp
(setq mu4e-change-filenames-when-moving t)
#+end_src
** Sending emails - Msmtp
#+begin_src emacs-lisp
(setq smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587)
(setq message-send-mail-function 'message-send-mail-with-sendmail
sendmail-program "msmtp"
user-full-name "Thomas Dehaeze")
#+end_src
** Bookmarks
#+begin_src emacs-lisp :tangle no
(setq mu4e-bookmarks
`(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
("date:today..now" "Today's messages" ?t)
("date:7d..now" "Last 7 days" ?w)
("mime:image/*" "Messages with images" ?p)
(,(mapconcat 'identity
(mapcar
(lambda (maildir)
(concat "maildir:" (car maildir)))
mu4e-maildir-shortcuts) " OR ")
"All inboxes" ?i)))
#+end_src
** TODO Notifications
#+begin_src emacs-lisp
(with-eval-after-load 'mu4e-alert
(mu4e-alert-set-default-style 'libnotify))
(mu4e-alert-enable-notifications)
#+end_src
Mode-line notifications
#+begin_src emacs-lisp
(setq mu4e-enable-mode-line t)
#+end_src
** Use Org-Mode Tables In Emails
#+begin_src emacs-lisp
(add-hook 'message-mode-hook 'turn-on-orgtbl)
(add-hook 'message-mode-hook 'turn-on-orgstruct++)
#+end_src
** TODO Integration with Org-Mode
Store link to message if in header view, not to header query
#+begin_src emacs-lisp
(setq org-mu4e-link-query-in-headers-mode nil)
#+end_src
** TODO When putting something on the Trash, it will be in the archive folder on gmail
Even when totally deleting it. It will stay on gmail. How to fix that?
** TODO Verify that sending mails with gmail account works and that there is no duplicate
Should check this variable: mu4e-sent-messages-behavior
#+begin_src emacs-lisp :tangle no
(setq mu4e-sent-messages-behavior 'delete)
#+end_src
And [[https://www.djcbsoftware.nl/code/mu/mu4e/Gmail-configuration.html][here]].
If I put it to delete, it works for gmail but not for the other ones...
Check [[https://github.com/djcb/mu/issues/179][here]].
** TODO Cheatsheet
** Cheatsheet
| Command | Usage |
|---------+-----------------------|
| =C-j= | Next mail |
@ -2732,6 +2544,175 @@ Check [[https://github.com/djcb/mu/issues/179][here]].
| =t= | Move to Archive |
| =d= | Move to Trash |
** Helping function
This is a helper to help determine which account context I am in based on the folder in my maildir the email (eg. ~/.mail/nine27) is located in.
#+begin_src emacs-lisp
(defun mu4e-message-maildir-matches (msg rx)
(when rx
(if (listp rx)
;; If rx is a list, try each one for a match
(or (mu4e-message-maildir-matches msg (car rx))
(mu4e-message-maildir-matches msg (cdr rx)))
;; Not a list, check rx
(string-match rx (mu4e-message-field msg :maildir)))))
#+end_src
Choose account label to feed msmtp -a option based on From header in Message buffer; This function must be added to message-send-mail-hook for on-the-fly change of From address before sending message since message-send-mail-hook is processed right before sending message.
#+begin_src emacs-lisp
(defun choose-msmtp-account ()
(if (message-mail-p)
(save-excursion
(let*
((from (save-restriction
(message-narrow-to-headers)
(message-fetch-field "from")))
(account
(cond
((string-match "dehaeze.thomas@gmail.com" from) "gmail")
((string-match "thomas.dehaeze@esrf.fr" from) "esrf"))))
(setq message-sendmail-extra-arguments (list '"-a" account))))))
#+end_src
** Basic Config
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq mail-user-agent 'mu4e-user-agent
mu4e-mu-binary "/usr/bin/mu"
mu4e-maildir "~/.mail"
mu4e-compose-format-flowed t
mu4e-compose-in-new-frame nil
mu4e-view-show-images t
mu4e-html2text-command "w3m -dump -T text/html"
mu4e-use-fancy-chars t
mu4e-headers-include-related t
mu4e-attachment-dir "~/Downloads"
message-kill-buffer-on-exit t
mu4e-compose-signature-auto-include t
mu4e-view-show-images t
mu4e-view-show-addresses t)
)
#+end_src
** Additional config
#+begin_src emacs-lisp
(use-package! mu4e
:config
;; Use imagemagick, if available.
(when (fboundp 'imagemagick-register-types)
(imagemagick-register-types))
;; Sometimes html email is just not readable in a text based client, this lets me open the
;; email in my browser.
(add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser) t)
;; Spell checking ftw.
(add-hook 'mu4e-compose-mode-hook 'flyspell-mode)
;; Use Helm to select mailboxes
(setq mu4e-completing-read-function 'completing-read)
;; Don't ask for a 'context' upon opening mu4e
(setq mu4e-context-policy 'pick-first)
;; Don't ask to quit... why is this the default?
(setq mu4e-confirm-quit nil)
)
#+end_src
** Provide Information
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq mu4e-user-mail-address-list '("dehaeze.thomas@gmail.com" "thomas.dehaeze@esrf.fr")
mu4e-compose-signature "Thomas Dehaeze\n"
user-mail-address "dehaeze.thomas@gmail.com")
;; Default Folders
(setq mu4e-sent-folder "/gmail/Sent"
mu4e-drafts-folder "/gmail/Drafts"
mu4e-trash-folder "/gmail/Trash"
mu4e-refile-folder "/gmail/Archive")
)
#+end_src
** Receiving emails using mbsync
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq mu4e-get-mail-command "~/scripts/checkmail.sh"
mu4e-update-interval nil
mu4e-change-filenames-when-moving t) ;; Fix for mbsync
)
#+end_src
** Contexts
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq mu4e-contexts
`( ,(make-mu4e-context
:name "gmail"
:enter-func (lambda () (mu4e-message "Switch to the gmail context"))
:match-func (lambda (msg) (when msg
(string-prefix-p "/gmail" (mu4e-message-field msg :maildir))))
:leave-func (lambda () (mu4e-clear-caches))
:vars '(
(user-mail-address . "dehaeze.thomas@gmail.com")
(user-full-name . "Thomas Dehaeze")
(mu4e-sent-folder . "/gmail/Sent")
(mu4e-trash-folder . "/gmail/Trash")
(mu4e-drafts-folder . "/gmail/Drafts")
(mu4e-refile-folder . "/gmail/Archive")
(mu4e-compose-signature . "Thomas Dehaeze\n")
))
,(make-mu4e-context
:name "esrf"
:enter-func (lambda () (mu4e-message "Switch to the esrf context"))
:match-func (lambda (msg) (when msg
(string-prefix-p "/esrf" (mu4e-message-field msg :maildir))))
:leave-func (lambda () (mu4e-clear-caches))
:vars '(
(user-mail-address . "thomas.dehaeze@esrf.fr")
(user-full-name . "Thomas Dehaeze")
(mu4e-sent-folder . "/esrf/Sent")
(mu4e-trash-folder . "/esrf/Trash")
(mu4e-drafts-folder . "/esrf/Drafts")
(mu4e-refile-folder . "/esrf/Archive")
(mu4e-compose-signature . "Thomas Dehaeze\n")
))
))
)
#+end_src
** Sending mails
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq message-send-mail-function 'message-send-mail-with-sendmail
sendmail-program "/usr/bin/msmtp"
user-full-name "Thomas Dehaeze")
;; This prevents saving the email to the Sent folder since gmail will do this for us on their end.
(setq mu4e-sent-messages-behavior 'delete)
;; Use the correct account context when sending mail based on the from header.
(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'choose-msmtp-account)
)
#+end_src
** Bookmarks
#+begin_src emacs-lisp
(use-package! mu4e
:config
(setq mu4e-bookmarks `(,(make-mu4e-bookmark
:name "All Inboxes"
:query "maildir:/gmail/Inbox OR maildir:/esrf/Inbox"
:key ?i)
("flag:unread" "Unread messages" ?u)
("date:today..now" "Today's messages" ?t)
("date:7d..now" "Last 7 days" ?w)))
)
#+end_src
* PDF-Tools
#+begin_src emacs-lisp
(use-package! pdf-tools
@ -2894,7 +2875,7 @@ they are implemented.
sh ; she sells {ba,z,fi}sh shells on the C xor
:email
;;(mu4e +gmail)
(mu4e +gmail)
:app
calendar