Aerc: a Well-Crafted Tui for Email

Aerc is a TUI email client. It had its first release ~4 years ago. This makes it a “baby” compared to most of its “competitors” (Pine was released in 1992, Mutt in 1995). I heard about this program shortly after its first release but ignored it at the time, because I was still reasonably happy with Thunderbird and it seemed quite bare-bones in comparison. I recently decided to revisit this piece of software. It seemed to have reached a certain level of maturity and had enough features that I wanted to use it as a daily driver.

Full disclosure: I tried to use neomutt as an email client multiple times but got frustrated and gave up quite quickly. I was prepared for the eventuality that I would have the same experience with aerc, so I approached it with almost zero expectations. I’m glad to say that not only were my expectations more than met, I can tentatively say that I’ve enjoyed using this client more than any other client I’ve ever used. Whether it is better than any other email client remains to be seen.

This article will contain a quick rundown of the different features of the client and how I interacted with them. It tries to highlight how I personally experienced and used the program, so it will be highly subjective.

Documentation

The program has an inbuilt help feature that can be accessed via the command :help. The tutorial is a good place to start and succinctly describes the most important features and keybinds to get set up quickly. The other help pages describe different parts of the application and are written clearly and concisely. It makes it possible to use the client and all of its features without having to rely on any external source. A handy feature is that all of the help articles are just man pages that are piped to less. This means they are also installed as plain man pages (eg. aerc-tutorial (7)). This is a really nice way of shipping a “portable” help system inside your TUI applications! I hope other applications/projects start using this approach.

Account Configuration

Accounts are relatively easy to add, thanks to a simple and intuitive wizard. This wizard creates a new entry in the accounts config file (~/.config/aerc/accounts.conf). This file uses a simple INI syntax, so it is really easy to read and modify. For example, this is my config section for a private account:

[Sergeant Personal]
source        = imaps://user:password@mail.example.com:993
outgoing      = smtps://user:password@mail.example.com:465
default       = INBOX
from          = "User" <user@example.com>
copy-to       = Sent
cache-headers = true
folders-sort  = INBOX, Drafts, Sent, spambucket, Active, Waiting, Done
archive       = Archives
check-mail    = 1m
folder-map    = /home/user/.config/aerc/folder-maps/foo.map

Most of these options are self-explanatory, but there are a few that I want to draw special attention to. These are the options for folder management (folders-sort and folder-map)

folders-sort

This option is really simple: It allows us to override automatic sorting for certain folders. The specified folders are shown at the top of the folder list in the provided order. The rest are sorted alphabetically. This option should be in every email client. Sadly, I’ve never seen it in a graphical client (Thunderbird/Outlook) before.

folder-map

This is an amazing feature that solves a really annoying problem: different email providers have different folder structures. For example, Gmail puts everything in a folder named [Gmail], some providers put ‘Sent’ and ‘Drafts’ under ‘INBOX’, others don’t, etc. Since this folder structure is provided by the server, there is no way to change it (unless you administer the email server). Aerc has a really nice solution for this problem. It consists of a file with mapping rules, that maps server folders to displayed folder names. This makes for a flexible remapping system that works on single and multiple folders, allows removing prefixes from folders and much more. The examples from the man page show this feature quite well.

Remap a single folder:
Spam = [Gmail]/Spam

Remap the folder and all of its subfolders:
G = [Gmail]*

Remove a prefix for all subfolders:
* = [Gmail]/*

Remap all subfolders and avoid a folder collision:
Archive/existing = Archive*
Archive = OldArchive*

It’s hard to overstate how much I love this feature. It allows me to have a consistent folder structure that I can interact with in exactly the same way for each and every one of my accounts (regardless of the folder structure on the server). Consistent folder structures are especially important when you manage emails via a CLI instead of a GUI.

Email Viewing

My email viewing experience has been generally mediocre. This has nothing to do with aerc itself, but rather with HTML emails. I suspected that this would be non-ideal in a TUI client and that fact has been proven correct. In most multipart emails the plain text version is much less readable than the HTML version. It’s possible to grasp the meaning most of the time but sometimes it is just a garbled mess. Aerc has a few features to make this experience less bad. One option is viewing them through a HTML parser/browser (a combination of w3m and dante. This works well for some emails. The generated output is sometimes better than the plain text version of the email. As a last resort I just use :open to open them in my default web browser. The way aerc does this is actually quite nice: it uses custom filters. These are *nix pipelines that allow the message to be piped through the filter before being displayed. It has default filters for plain text (colorising rules), calendar entries and HTML emails. These filters can be set on mimetypes but can also be matched with specific headers. The configuration contains a few examples and shows the flexibility and power of this feature:

text/plain=colorize
text/calendar=calendar
message/delivery-status=colorize
message/rfc822=colorize
#text/html=pandoc -f html -t plain | colorize
text/html=html | colorize
#text/*=bat -fP --file-name="$AERC_FILENAME"
#application/x-sh=bat -fP -l sh
#image/*=catimg -w $(tput cols) -
#subject,~Git(hub|lab)=lolcat -f
#from,thatguywhodoesnothardwraphismessages=wrap -w 100 | colorize

Email Authoring

Email authoring is an absolute pleasure. I really like the fact I can now compose my emails in vim.

Address Book

The address book was something I struggled with quite a bit. Like many things, theoretically this is handled quite elegantly in aerc: it defers address book organisation to an external program. This is done by allowing the user to specify a search query to the address book software in question. The results of that query are then used for autocomplete in relevant header fields. The default program aerc uses for this is abook. My problems with this software were twofold: first (at least in my tests) it did not seem to support names with non-ascii characters. Since I frequently converse with German people, this made this software useless to me. Also, there wasn’t an easy way to get new addresses from the email program to abook, since it can not parse a complete email and take out all of the addresses. This might have been solvable with custom filters, but I didn’t want to put much time into this since it didn’t work with non-ascii characters anyway. The second piece of software I tried was aercbook. This had the same problem with non-ascii characters as abook, but it does support parsing all header fields for email addresses. I then found a third option, called emailbook-janet. This is a rewrite of aercbook that is unfortunately not as performant, but it solves the ascii problem. Using keybinds, one can even select emails, parse them and automatically add all addresses to the address book:

aa = :pipe -m emailbook.janet /home/biggs/.config/aerc/address_book --parse --all<Enter>

One limitation of this software (and aercbook) is that they are not really “address books”. They simply save the name and email of contacts, to make autocomplete work. This is all I need at the moment, so that works out. If I ever need a more powerful solution, I might switch over to khard or some similar solution. Who knows, I might even set up an LDAP Server :)

PGP Support

One big problem I’ve had with Thunderbird is its strange PGP/GPG support. The biggest annoyance is its separate keychain. This makes using Thunderbird with something like a smartcard finicky at best and impossible at worst (at least, I’ve never got it to work properly). Aerc also has its own keychain, but it is entirely optional. The default mode is to just use the GPG keychain. You can set a specific key ID to sign messages, or just let aerc look up the key by email. There are options for automatically signing all emails and to use opportunistic encryption. All in all, as long as you have a working GPG setup, this works flawlessly.

General Configuration

Here are some general features that did not really fit into a separate category, but that I wanted to highlight nonetheless.

The first is that aerc supports signatures. Hardly a surprising or groundbreaking feature for an email client, but nice nonetheless. Signatures are just text files that can be included for each account with signature-file=. Alternatively, aerc can also execute an external command to create a signature.

Aerc also supports email templates. I haven’t looked at those in detail yet, but it seems like a nice feature.

It also tries to intelligently remove repetitions of ‘Re:’ prefixes in email headers (in multiple languages). To accomplish this, it uses a regex that can be optionally overwritten or extended.

Two other nice (but kinda default) features of aerc are its forget subject and attachment reminder. The first just checks if the subject is empty, but the second one is actually quite clever, and very easily extensible: it’s just a regex! Specifically, this one:

^[^>]*attach(ed|ment)

This does several smart things, one of them is filtering the line out if it begins with a ‘>’ (which would mean that someone else mentioned an attachment, not you). Because I also write a lot of emails in German, I decided to extend this regex so it also works in German (NB: the regex is case-insensitive and multi-line by default):

^[^>]*(attach(ed|ment))|an(ge)?h[]ngt?

All in all, I’ve really enjoyed using aerc over the last few days. It seems really polished and it is a pleasure to use. I think I’ll stick with this email client for a while longer and see how it goes.


Articles from blogs I read - Generated by openring