Contents:
- Overview
- Setup
- Usage
- Configuration
- Implementation details
- mbsync config
- notmuch config
- IMAP IDLE notifications
- pass and systemd
- systemd user service
- msmtp config - TODO
This set of scripts is a glue between mbsync, notmuch, ZX2C4 password-storage and goimapnotify IMAP notification daemon.
Main goal is to provide offline mail system with continuous new mail delivery without network overhead and delays. That means that I want to pull mail from server only when there are new messages and push back only changed IMAP folders. First goal achieved with goimapnotify daemon which monitors specified in it's config IMAP folders and triggers external commands on new events, the second one achieved with mbsync tool from isync package which synchronize changes between IMAP server and local storage. For new mail indexing I've chose notmuch because:
- it's ultra fast;
- easy to use;
- present in Arch's community repo (no need to compile);
- natively integrates with Emacs.
I'm using Emacs for mail reading but EasyMail is mail reader agnostic and will work in background without any MUA at all, supposed that user can use any that supports notmuch.
There are a lot of blogs/articles in network like 'My perfect mail setup' and each author trying to implement something new. So here I've tried to join all found information together.
Copy easymail
script somewhere in PATH
, [email protected]
in ~/${XDG_CONFIG_HOME}/systemd/user
,
and easymail-{pre,post}-new.sh
to ${MAILDIR}/.notmuch/hooks/{pre,post}-new
. Script depends on 3-rd party
tools described above.
Note: for Gmail accounts All Mail
folder Show in IMAP
should be unchecked in Lables
menu, unchecked in
Labels settings menu. Pre-new notmuch hook handles move to trash messages tagged as "+trashed" and to work propery
both with Fastmail and Gmail the last one should set Auto-Expunge -> off
and Immediately delete the message forever
in Forwarding POP/IMAP
settings menu.
➤ easymail help
usage: 'command'
Supported commands:
disable - stop account synchronization using IMAP IDLE,
enable - start account synchronization using IMAP IDLE,
get - get account information,
help - internal commands help,
index - index mailbox with 'notmuch'
list - list configured accounts,
remove - remove account,
setup - setup new mail account,
status - show account status,
sync - sync account with remote server.
Try 'easymail help command' to see 'command' help.
➤ easymail help setup
usage: setup [--enable] [--full-name=name] [--port=port] [--server=server] 'account' 'email' 'pass'
Setup and optionally enable 'account' for 'email' with 'pass' password.
--enable - start new email polling just after setup,
--full-name= - use non-default full user name,
--port= - use non standard IMAP port (default: 993),
--server= - use custom IMAP server.
Server name will be extracted from email address, newly created account will be disabled
after setup, full user name will be taken from global 'notmuch' configuration.
'pass' file should contain 'app-pass' field.
Use: easymail enable 'account' to start new mail polling or specify '--enable' above.
Example 1: I need to setup my work email Vasya Petelkin <[email protected]>
➤ easymail setup Megacorp [email protected] work/megacorp
This will produce four files: ${XDG_CONFIG_HOME}/easymail/{mbsync,notify,notmuch}.conf
and ${PASSORD_STORE_DIR}/.easymail/Megacorp.gpg
relative symlink to ${PASSWORD_STORE_DIR}/work/megacorp.gpg
.
Since ${PASSORD_STORE_DIR}/.easymail
is hidden it will be invisible for regular pass
command
and browserpass
browser extension.
Script will discover all IMAP folders on server 'imap.megacorp.com' and put them into 'mbsync.conf' and 'notify.conf'.
Note: pass file should contain application password field named 'app-pass' (field name may be changed in config), account name should NOT contain spaces.
Example 2: Like (1) but enable messages polling just after setup:
➤ easymail setup --enable Megacorp [email protected] work/megacorp
Example 3: If email does not mutch IMAP server (for example corporate email hosted on Gmail):
➤ easymail setup --enable --server=imap.gmail.com Megacorp [email protected] work/megacorp
All three examples will use default full user name from global notmuch configuration, if need to set it to
different then provide --full-name="Vasiliy Petelkin"
to easymail
script.
Note: if using non-default GNUPGHOME
and/or PASSWORD_STORAGE_DIR
then need to
create ~/.profile.d/env.d/user.env
with proper values or update provided systemd
service and set them there.
I did the first with my bash profile.