CLI Email of the Future: Office 365 and QUB

This is a quick record of the steps taken to setup a local email copy, index, and reading. All the software should be available in Debian via apt.

sudo apt install getmail notmuch alot pass daemontools

* Optional.

GetMail

Talks to Office365 via IMAP over TLS. Gets all the emails and stores them locally.

$HOME/.getmail/getmailrc

[retriever]
type = SimpleIMAPSSLRetriever
server = outlook.office365.com
port = 993
username = <STAFF ID>@ads.qub.ac.uk
password_command = ("/usr/bin/pass", "qub/staff")
mailboxes = ALL

[destination]
type = Maildir
path = ~/mail/staff/

[options]
read_all = False
verbose = 1
message_log = ~/.getmail/staff.log

notmuch

Indexes the local Maildir, and allows you to apply tags and search mail.

$HOME/.notmuch-config

[database]
path=/home/user/mail/staff/

[user]
name=<My Name>
primary_email=<My Email>@qub.ac.uk

[new]
tags=unread;inbox;
ignore=

[search]
exclude_tags=deleted;spam;

[maildir]
synchronize_flags=true

alot

A terminal-based mail user agent (MUA) based on notmuch mail indexer.

images/posts/2020-01-15/solarized.thread.png

/images/posts/2020-01-15/solarized.search.png

mailcap

Mailcap is a file the defines what should happen when a specific file type is opened in alot (or other MUAs). In this case we want to render text/HTML types using w3m. A CLI browser and web rendering engine.

$HOME/.mailcap

text/html;  w3m -dump -o document_charset=%{charset} '%s'; nametemplate=%s.html; copiousoutput

Work flow

Manually

getmail && notmuch new && alot

Automated

Touch $HOME/.getmail/do-not-run if you want to prevent getmail from running. This might be to save power or you just don’t want emails coming in. We have also used setlock to prevent multiple instances running at once. This is to prevent strange things from happening.

crontab -e

*/10 * * * * [ -f $HOME/.getmail/do-not-run ] || /usr/bin/setlock -n $HOME/.getmail/run.lock /usr/bin/getmail && notmuch new

Future

Syncing the unread/read flags via IMAP. Might need to change over to OfflineIMAP or something?