read your mail inside emacs with mu4e
Here we will configure emacs to
Prerequis
- install mu4e
on debian ubuntu like :
# apt install mu4e
- install and configure mbsync see : mbsync
mu4e emacs configuration
Make sure the following is stored in an .el file that is loaded by emacs, e.g. by the ~.emacs file.
Here is my ~/.emacs.d/mu4e.el
;; mu4e
(require 'org-mu4e)
(setq send-mail-function 'sendmail-send-it)
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq mu4e-maildir (expand-file-name "~/.localsyncmail/mymailserv/"))
(setq mu4e-inbox-folder "/Inbox")
(setq mu4e-drafts-folder "/Drafts")
(setq mu4e-sent-folder "/Inbox")
(setq mu4e-trash-folder "/Trash")
; get mail
(setq mu4e-get-mail-command "mbsync -c ~/.emacs.d/.mbsyncrc authsmtp"
mu4e-html2text-command "w3m -T text/html"
mu4e-update-interval 120
mu4e-headers-auto-update t
;; mu4e-compose-signature-auto-include nil
)
;; enable inline images
(setq mu4e-view-show-images t)
;; use imagemagick, if available
(when (fboundp 'imagemagick-register-types)
(imagemagick-register-types))
(setq mu4e-contexts
`( ,(make-mu4e-context
:name "AuthSMTP"
:enter-func (lambda () (mu4e-message "Entering AuthSMTP context"))
:leave-func (lambda () (mu4e-message "Leaving AuthSMTP context"))
;; we match based on the contact-fields of the message
:match-func (lambda (msg)
(when msg
(mu4e-message-contact-field-matches msg
:to "mypersonnallogin@authsmtp.com")))
:vars '( ( user-mail-address . "mypersonnallogin@authsmtp.com" )
( user-full-name . "Prenom Nom" )
))
,(make-mu4e-context
:name "Work"
:enter-func (lambda () (mu4e-message "Switch to the Work context"))
;; no leave-func
;; we match based on the maildir of the message
;; this matches maildir /Work and its sub-directories
:match-func (lambda (msg)
(when msg
(string-match-p "^/Work" (mu4e-message-field msg :maildir))))
:vars '( ( user-mail-address . "moi@other.net" )
( user-full-name . "Prenom Nom" )
)) ))
(setq message-kill-buffer-on-exit t)
(setq mu4e-attachment-dir "~/Downloads")
(defun cpb-mu4e-is-message-to (msg rx)
"Check if to, cc or bcc field in MSG has any address in RX."
(or (mu4e-message-contact-field-matches msg :to rx)
(mu4e-message-contact-field-matches msg :cc rx)
(mu4e-message-contact-field-matches msg :bcc rx)))
(setq user-mail-address "mypersonnallogin@authsmtp.com"
user-full-name "Prenom Nom")
(setq mu4e-sent-messages-behavior 'delete)
(add-hook 'mu4e-compose-mode-hook
(defun my-do-compose-stuff ()
"My settings for message composition."
(set-fill-column 72)
(flyspell-mode)))
;; mu4e end
Then, you must index that directory with mu:
$ mu index --maildir=~/.localsyncmail/authsmtp
indexing messages under /localstorage/mail/mbsync/authsmtp [/home/user/.mu/xapian]
\ processing mail; processed: 92100; updated/new: 92100, cleaned-up: 0
Now it’s time to try out mu4e. Open up emacs and type M-x mu4e.
create new maildir
From your local sync computer.
Go to the place whre are store your local sync mail.
$ cd ~/.localsyncmail/authsmtp
Go to the subfolder or racine where you want to create your new folder.
$ cd folder1/folder2
Create new maildir folder with this command.
$ mu mkdir MuninAlert
Don’t forget to sync your local folder.
$ mu index --maildir=~/.localsyncmail/authsmtp
mu4e shortcuts
- navigation
key | description |
---|---|
n/p | go to next, previous message |
],[ | move to the next, previous unread message |
y | select the message view (if it’s visible) |
RET | open the message at point in the message view |
P | enable or disable threading in the message view |
- searching
key | description |
---|---|
s | search |
S | edit last query |
/ | narrow the search |
b | search bookmark |
B | edit bookmark before search |
j | jump to maildir e.g. ji jumps to inbox |
M-left, | previous query |
M-right | next query |
O | change sort order |
P | toggle threading |
Q | toggle full-search |
V | toggle skip-duplicates |
W | toggle include-related |
Normally, queries return up to mu4e-headers-results-limit (default: 500) results. That is usually more than enough, and makes things significantly faster. Sometimes, however, you may want to show all results; you can enable this with M-x mu4e-headers-toggle-full-search, or by customizing the variable mu4e-headers-full-search. This applies to all search commands.
- marking
key | description |
---|---|
d | mark message for moving to trash folder |
= | mark for removing trash flag (‘untrash’) |
DEL,D | mark for complete deletion |
m | mark message for moving to another maildir folder |
r | mark for refiling |
+,- | mark for flagging/unflagging |
?,! | mark message as unread/read |
u | unmark message at point |
U | unmark all messages |
% | mark based on a regular expression |
T,t | mark whole thread, subthread |
,* | mark for ‘something’ (decide later) |
# | resolve deferred ‘something’ marks |
x | execute actions for the marked messages |
- composition
key | description |
---|---|
R,F,C | reply/forward/compose |
E | edit (only allowed for draft messages) |
C-c C-a | add attachement |
- misc
key | description |
---|---|
; | switch context |
. | show the raw message view. ‘q’ takes you back. Full Header view |
a | execute some custom action on a header |
| | pipe message through shell command |
C-+,C– | increase / decrease the number of headers shown |
H | get help |
C-S-u | update mail & reindex |
q | leave the headers buffer |
e | save attachement |
- Queries source : https://www.djcbsoftware.nl/code/mu/mu4e/Queries.html
Get all messages regarding bananas:
bananas
Get all messages regarding bananas from John with an attachment:
from:john and flag:attach and bananas
Get all messages with subject wombat in June 2017
subject:wombat and date:20170601..20170630
Get all messages with PDF attachments in the /projects folder
maildir:/projects and mime:application/pdf
Get all messages about Rupert in the /Sent Items folder. Note that maildirs with spaces must be quoted.
"maildir:/Sent Items" and rupert
Get all important messages which are signed:
flag:signed and prio:high
Get all messages from Jim without an attachment:
from:jim and not flag:attach
Get all messages with Alice in one of the contacts-fields (to, from, cc, bcc):
contact:alice
Get all unread messages where the subject mentions Ångström: (search is case-insensitive and accent-insensitive, so this matches Ångström, angstrom, aNGstrøM, …)
subject:Ångström and flag:unread
Get all unread messages between Mar-2012 and Aug-2013 about some bird:
date:20120301..20130831 and nightingale and flag:unread
Get today’s messages:
date:today..now
Get all messages we got in the last two weeks regarding emacs:
date:2w.. and emacs
Get messages from the Mu mailing list:
list:mu-discuss.googlegroups.com
Note — in the Headers view you may see the ‘friendly name’ for a list; however, when searching you need the real name. You can see the real name for a mailing list from the friendly name’s tool-tip. Get messages with a subject soccer, Socrates, society, …; note that the ‘*’-wildcard can only appear as a term’s rightmost character:
subject:soc*
Get all messages not sent to a mailing-list:
NOT flag:list
Get all mails with attachments with filenames starting with pic;
note that the ‘*’ wildcard can only appear as the term’s rightmost character:
file:pic*
Get all messages with PDF-attachments:
mime:application/pdf
Get all messages with image attachments, and note that the ‘*’ wildcard can only appear as the term’s rightmost character:
mime:image/*
Get all messages with files that end in .ppt; this uses the regular-expression support, which is powerful but relatively slow:
file:/\.ppt$/
notes en vrac
- Including related messages
It can be useful to not only show the messages that directly match a certain query, but also include messages that are related to these messages. That is, messages that belong to the same discussion threads are included in the results, just like e.g. Gmail does it. You can enable this behavior by setting mu4e-headers-include-related to t, and you can toggle between including/not-including with W.
message signatures : https://www.djcbsoftware.nl/code/mu/mu4e/Message-signatures.html
you can then still include the signature manually, using the function message-insert-signature, typically bound to C-c C-w.multiple email signature : http://www.macs.hw.ac.uk/~rs46/posts/2014-11-16-mu4e-signatures.html multiple email signature
context template https://www.djcbsoftware.nl/code/mu/mu4e/Contexts-example.html
view mu4e - emacs buffer in browser
(add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t)
Then, a V opens the current message in the default web browsers.
- How can I start a new message-thread from a reply ?
Remove the In-Reply-To header, and mu4e automatically removes the (hidden) References header as well when sending it. This makes the message show up as a top-level message rather than as a response.