301.1. aerc-0.22.0
A terminal mail client that speaks IMAP, Maildir and notmuch
| Version | 0.22.0, release 1 |
| Shelf | mail — Email clients, fetch and send tools, mail libraries, and feed readers |
| Phase | 44_apps (Applications), 275 of 422 in build order |
| Licence | MIT |
| Homepage | https://aerc-mail.org/ |
| Build time | 0.3 SBU |
| Installed size | 18.3 MiB in 46 files |
| Recipe | ports/core/mail/aerc/kpkgbuild |
About
aerc is a terminal mail client that reads IMAP, JMAP, Maildir, mbox and notmuch accounts and sends over SMTP. KDOS builds it with its notmuch backend, so mail already indexed on the machine is searched from the client through that one index. The shipped ~/.config/aerc/aerc.conf names the filters that render each kind of message part; see Mail, calendar and contacts.
Why it is in KDOS
The comment above it in script/phases/44_apps/packages.d/mail.txt:
The mail client. Its notmuch binding is cgo, which is why it is built with CGO_ENABLED=1. /etc/skel's aerc.conf names the filter chain the console reads mail with, and this recipe installs the one filter that is ours; the rest are aerc's own.
Sources
aerc-0.22.0.tar.gz(626.6 KiB)
sha256f1cd5e358fd836051d4d88c189ecaa025a108b729281985525b45b13bc49e70f
upstream: https://git.sr.ht/~rjarry/aerc/archive/0.22.0.tar.gz
archive copy: sources-3/mail--aerc-0.22.0.tar.gzaerc-vendor-0.22.0.tar.xz(2.1 MiB)
sha2561e5fa2c4e541b1f1429bca2acd18b8e6eda1e70fa6f89f1f25147364ebe7ea42
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-3/mail--aerc-vendor-0.22.0.tar.xz
Dependencies
Depends on: go, scdoc, notmuch, w3m, mupdf, chafa, docx2txt, gawk, util-linux.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/44_apps/phase.env && kpkg install aerc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/mail/aerc.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/mail/aerc
echo 'f1cd5e358fd836051d4d88c189ecaa025a108b729281985525b45b13bc49e70f aerc-0.22.0.tar.gz' | sha256sum -c -
echo '1e5fa2c4e541b1f1429bca2acd18b8e6eda1e70fa6f89f1f25147364ebe7ea42 aerc-vendor-0.22.0.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/aerc
SRC=$SRC_ROOT/aerc-0.22.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf aerc-0.22.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CGO_ENABLED=1
make PREFIX=/usr GOFLAGS="$GOFLAGS -mod=vendor -tags=notmuch" GO_EXTRA_LDFLAGS="-s -w"
make PREFIX=/usr DESTDIR=$PKG install
install -d "$PKG/usr/libexec/aerc/filters"
cat > "$PKG/usr/libexec/aerc/filters/kdos-part" <<'KDOS_SH'
#!/bin/sh
# kdos-part — one spool, five renderers, for aerc's [filters].
#
# ONE SPOOL, BECAUSE mutool OPENS A DOCUMENT BY PATH. aerc hands a part to a
# filter on STDIN and four of the five renderers read a pipe perfectly well;
# `mutool draw ... -` answers "cannot open -". One shape for all five is
# simpler than one exception, and the file costs nothing a message view does
# not already cost.
#
# NO ARM MAY `exec`. The trap is what removes the spool, and exec replaces this
# shell and its traps together; the file would then outlive every message
# viewed and hold its bytes in $TMPDIR for the rest of the login.
#
# NO SHELL EXPANSION OF THE ARGUMENT. The word below is matched against a fixed
# list and every command is written out in full: a filter line is
# configuration, and configuration that reached `eval` would be a shell for
# anyone who can write to a config file.
set -e
t=$(mktemp "${TMPDIR:-/tmp}/aerc-part.XXXXXX") || exit 1
trap 'rm -f "$t"' EXIT INT TERM HUP
cat > "$t"
case "$1" in
# -q BECAUSE A FILTER'S STDERR IS THE MESSAGE BODY. aerc gives every filter the
# pager's own pipe for stderr, so mutool's per-page progress line would be read
# as part of the document. Errors still print, which is what the reader needs.
pdf)
mutool draw -q -F txt -o - "$t"
;;
image)
# --animate off OR A SENDER CHOOSES HOW LONG THE MESSAGE TAKES. chafa
# animates a GIF even into a pipe, sleeping each frame's delay, and a
# GIF's delay field is 16-bit centiseconds with no limit on the frame
# count, and nothing on aerc's side times a filter out.
#
# aerc puts the view's width in $COLUMNS; the fallback is for a hand
# run. Height is fixed because the pager scrolls. `less -Rc` is that
# pager and passes the colour through.
chafa --format symbols --animate off \
--size "${COLUMNS:-100}x30" "$t"
;;
docx)
docx2txt "$t" -
;;
# THE ISOLATION IS PROBED, NOT ASSUMED, AND ON THE LIVE MEDIUM THE PROBE FAILS:
# no process there can create a user namespace, root included, though every
# other namespace works and the kernel carries CONFIG_USER_NS=y. aerc's own
# html filter picks the namespace path on `command -v unshare` — and the binary
# IS on this image — so it runs a command that cannot start and the reader gets
# `unshare: Operation not permitted` where the message should be. Probing means
# the worst case is a message behind an unroutable proxy rather than no
# message.
#
# ONE PROCESS EITHER WAY. The argument vector is built in the positional
# parameters and unshare prefixes it. Re-entering this script under unshare
# instead would read a stdin the first `cat` has already drained to end of
# file, and every HTML message would render empty.
html)
# w3m LAYS TABLES OUT ON THE GRID, which is why it and not lynx is this
# image's text browser and why marketing HTML — which is nothing but
# tables — is readable at all. Always -dump: aerc pipes this into its
# pager, so the filter must not take the terminal.
set -- w3m -I UTF-8 -O UTF-8 -T text/html \
-s -graph -cols "${COLUMNS:-100}" -dump \
-o fold_line=true -o decode_url=true -o display_link=true \
-o disable_center=true \
-o no_cache=true -o use_cookie=false
if unshare --map-root-user --net true >/dev/null 2>&1; then
unshare --map-root-user --net "$@" "$t"
else
# Best effort without a namespace: an unroutable proxy, so a
# tracking pixel resolves to a connection nothing can make.
"$@" -o use_proxy=true \
-o http_proxy=127.0.0.1:1 \
-o https_proxy=127.0.0.1:1 "$t"
fi
;;
# A READING, NOT AN IMPORT. aerc's calendar filter writes nothing, which is the
# property that matters: a filter runs every time a message scrolls past, and
# one that imported an invitation would accept meetings by being looked at. It
# is run through gawk by name, the awk it is written for, so it does not
# depend on its own `#!/usr/bin/awk -f`. `command -v` finds the script
# because aerc puts its own filter directory on this filter's PATH.
ics)
_cal=$(command -v calendar) || {
echo "kdos-part: aerc's calendar filter is not on the path" >&2
exit 2
}
gawk -f "$_cal" "$t"
;;
*)
echo "kdos-part: no renderer named '$1'" >&2
exit 2
;;
esac
KDOS_SH
chmod 755 "$PKG/usr/libexec/aerc/filters/kdos-part"
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/aerc.desktop" <<'EOF'
[Desktop Entry]
Type=Application
Name=aerc
GenericName=Terminal Mail Client
Comment=Read and send mail in a terminal
Exec=aerc %u
Icon=mail-message
Terminal=true
Categories=Network;Email;ConsoleOnly;
Keywords=mail;email;imap;smtp;aerc;
EOF
chmod 644 "$PKG/usr/share/applications/aerc.desktop"
The switches, and why each is set:
CGO_ENABLED=1— let the Go compiler build cgo code. aerc’s notmuch worker is a cgo binding tolibnotmuch, so without cgo the backend cannot be compiled. Most Go ports in the tree build with cgo off; see go.-mod=vendor— build from the modulevendor/tree unpacked from the vendor bundle. It is added to the exportedGOFLAGSrather than replacing them, which keeps the tree’s-trimpath,-buildvcs=falseand-buildmode=pie.-tags=notmuch— compile the notmuch backend. Upstream’s makefile setsGOFLAGS ?= $(shell contrib/goflags.sh), a probe that adds the tag only after a test compile againstnotmuch.hsucceeds.?=runs it only whenGOFLAGSis unset, and the tree exportsGOFLAGS, so the probe never runs here: without the tag on this line the client is built with no notmuch backend. Named outright, a missinglibnotmuchstops the build instead.GO_EXTRA_LDFLAGS— upstream’s makefile writes its own-ldflags(the version, date and the share and libexec directories) and appends this variable to it;-s -wthere leaves out the symbol table and DWARF, which kpkg does not strip.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/aerc, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf aerc-0.22.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/aerc, and runs the triggers its paths call for.
Contents
Installed programs: aerc, carddav-query.
Installed directories: /usr/libexec/aerc, /usr/share/aerc, /usr/share/licenses/aerc.
Short descriptions
aerc |
a pretty good email client. |
carddav-query |
Query a CardDAV server for contact names and emails. |
Notes
The vendor bundle, aerc-vendor-<version>.tar.xz, is go mod vendor run at the top of the source by ports/fetch (vendoring = go) and held to its own sha256 = line in the recipe like the upstream tarball; see Vendoring. build.sh unpacks it into the source tree, beside go.mod.
build.sh writes one filter of KDOS’s own, kdos-part, into aerc’s filter directory, /usr/libexec/aerc/filters. aerc puts that directory on the PATH it runs a filter with, so aerc.conf names the script by bare word. Its argument picks a renderer: pdf (mutool from mupdf), image (chafa), docx (docx2txt), html (w3m) and ics (aerc’s own calendar awk script, run through gawk by name). The part is spooled to a temporary file first, because mutool opens a document by path.
- chafa runs with
--animate off. chafa animates a GIF even into a pipe, sleeping each frame’s delay, and nothing on aerc’s side times a filter out, so the sender of an animated picture would otherwise decide how long the message takes to open. - w3m always runs with
-dump, so the filter never takes the terminal and the output goes to aerc’s pager. It runs inside a new network namespace (unshare --map-root-user --netfrom util-linux) when the kernel grants one, and otherwise with every proxy set to127.0.0.1:1, so a remote image or tracking link in the HTML cannot be fetched either way. - A filter’s error output is shown as the message body, so a renderer missing from the image shows as
command not foundin place of the message. Each program the script calls is independs.
The desktop entry is KDOS’s own, written over upstream’s contrib/aerc.desktop. Its Name is aerc and its GenericName and Comment say it runs in a terminal: the entry is the component Discover and the Kickoff menu list it by, and a name of Mail there would offer a terminal client to someone looking for a mail program that draws a window. Keywords keep mail and email, and the ConsoleOnly category is what Discover’s search ranks a terminal program by, so a search for “mail” lists thunderbird and kmail ahead of aerc and still finds it. It sets Terminal=true and passes %u, so a mailto: link opened through the entry reaches aerc as its argument. It claims no MIME type. Every row of /usr/share/kdos/xdg/kde-mimeapps.list names an application that draws its own window, so mailto: and message/rfc822 go to thunderbird there, and aerc, which needs a terminal around it, is run by name.