AERC-TEMPLATES(7) | Miscellaneous Information Manual | AERC-TEMPLATES(7) |
NAME
aerc-templates - template file specification for aerc(1)
SYNOPSIS
aerc uses the go text/template package for the template parsing. Refer to the go text/template documentation for the general syntax. The template syntax described below can be used for message template files and for dynamic formatting of some UI app.
Template files are composed of headers, followed by a newline, followed by the body text.
Example:
X-Clacks-Overhead: GNU Terry Pratchett Hello, Greetings, Chuck
If you have a template that doesn't add any header, it must be preceded by a newline, to avoid parsing parts of the body as header text.
All headers defined in the template will have precedence over any headers that are initialized by aerc (e.g. Subject, To, From, Cc) when composing a new message, forwarding or replying.
MESSAGE DATA
The following data can be used in templates. Though they are not all available always.
Addresses
- {{.From}}: List of senders.
- {{.Peer}}: List of senders or To recipients if the message is from you.
- {{.To}}: List of To recipients. Not always Available.
- {{.ReplyTo}}: List of ReplyTo recipients. Not always Available.
- {{.Cc}}: List of Cc recipients. Not always Available.
- {{.Bcc}}: List of Cc recipients. Not always Available.
- {{.OriginalFrom}}: List of senders of the original message. Available for quoted reply and forward.
Example:
Get the name of the first sender.
{{(index .From 0).Name}} {{index (.From | names) 0}}
Get the email address of the first sender.
{{(index .From 0).Address}}
Date and Time
- {{.Date}}: Date and time information when the compose window is opened.
- {{.OriginalDate}}: Date and time when the original message was received. Available for quoted reply and forward.
To format the date fields, dateFormat and .Local are provided. Refer to the TEMPLATE FUNCTIONS section for details.
Subject
{{.ThreadPrefix}}{{if .ThreadFolded}}{{printf "{%d}" .ThreadCount}}{{end}}{{.Subject}}
The subject of the email stripped of any Re: and Fwd: prefixes.
{{.SubjectBase}}
ThreadPrefix
ThreadFolded
ThreadCount
ThreadUnread
Flags
{{.Flags | join ""}}
IsReplied, HasAttachment, IsFlagged, IsRecent, IsUnread, IsMarked, IsDraft
{{if .IsFlagged}}★{{end}}
Labels
{{.Labels | join " "}}
Size
{{.Size | humanReadable}}
Filename
Filenames
Any header value
{{.Header "x-foo-bar"}}
Any header values of the original forwared or replied message:
{{.OriginalHeader "x-foo-bar"}}
:term b4 am {{.MessageId}}
MIME Type
- •
- {{.OriginalMIMEType}}: MIME type info of quoted mail part. Usually text/plain or text/html.
Original Message
{{.OriginalText}}
Signature
{{.Signature}}
Account info
{{.Account}}
The current account's backend:
{{.AccountBackend}}
Currently selected mailbox folder:
{{.Folder}}
Current message counts for all folders:
{{.Recent}} {{.Unread}} {{.Exists}} {{.RUE}}
IANA role of the mailbox, converted to lowercase:
{{.Role}}
aerc implements two additional custom roles: A 'query' role is given to folders from a notmuch query-map and 'virtual' indicates a virtual node in the directory tree listing:
{{if eq .Role "query"}}{{...}}{{else}}{{...}}{{end}}
Current message counts for specific folders:
{{.Recent "inbox"}} {{.Unread "inbox" "aerc/pending"}} {{.Exists "archive" "spam" "foo/baz" "foo/bar"}} {{.RUE "inbox"}}
Status line
Connection state.
{{.Connected}} {{.ConnectionInfo}}
General status information (e.g. filter, search) separated with [statusline].separator.
{{.ContentInfo}}
Combination of {{.ConnectionInfo}} and {{.StatusInfo}} separated with [statusline].separator.
{{.StatusInfo}}
General on/off information (e.g. passthrough, threading, sorting, visual mode), separated with [statusline].separator.
{{.TrayInfo}}
Currently pressed key sequence that does not match any key binding and/or is incomplete.
{{.PendingKeys}}
TEMPLATE FUNCTIONS
Besides the standard functions described in go's text/template documentation, aerc provides the following additional functions:
wrap
{{wrap 72 .OriginalText}}
quote
{{quote .OriginalText}}
trimSignature
{{trimSignature .OriginalText}}
join
{{.To | names | join ", "}}
split
{{.To | names | join ", " | split ", "}}
names
{{.To | names | join ", "}} {{index (.To | names) 0}}
firstnames
{{.To | firstnames | join ", "}} {{index (.To | firstnames) 0}}
initials
{{.To | initials | join ", "}} {{index (.To | initials) 0}}
emails
{{.To | emails | join ", "}} {{index (.To | emails) 0}}
mboxes
{{.To | mboxes | join ", "}} {{index (.To | mboxes) 0}}
shortmboxes
{{.To | shortmboxes | join ", "}} {{index (.To | shortmboxes) 0}}
persons
{{.To | persons | join ", "}} {{index (.To | persons) 0}}
.Attach
{{.Attach '/usr/libexec/aerc/filters/html'}}
exec
{{exec `/usr/libexec/aerc/filters/html` .OriginalText}}
.Local
{{.Date.Local}}
dateFormat
{{dateFormat .Date "Mon Jan 2 15:04:05 -0700 MST 2006"}}
You can also use the .DateAutoFormat method to format the date according to *-time*format settings:
{{.DateAutoFormat .OriginalDate.Local}}
now
{{dateFormat now "Mon Jan 2 15:04:05 -0700 MST 2006"}}
humanReadable
{{humanReadable 3217653721}}
cwd
{{cwd}}
compactDir
{{compactDir .Folder}}
contains
{{contains "<!DOCTYPE html>" .OriginalText}}
hasPrefix
{{hasPrefix "Business" .Folder}}
toLower
{{toLower "SPECIAL OFFER!"}}
toUpper
{{toUpper "important"}}
replace
{{replace `(.+) - .+ at .+..+` `$1` ((index .OriginalFrom 0).Name)}}
.Style
{{.Style .Account "red"}} {{.Style .ThreadPrefix "thread"}}{{.Subject}}
.StyleSwitch
{{.StyleSwitch .Subject (`^([[w-]+]s*)?[(RFC )?PATCH` "cyan")}} {{.StyleSwitch (.From | names | join ", ") (case `Tim` "cyan") (case `Robin` "pink-blink") (default "blue")}}
.StyleMap
{{.StyleMap .Labels (exclude .Folder) (exclude `^spam$`) (case `^inbox$` "red") (case `^Archive/.*` "green") (default "blue") | join " "}}
version
X-Mailer: aerc {{version}}
match
{{if match .Folder `.*/Archive-[0-9]+`}}{{humanReadable .Unread}}{{end}}
switch
{{switch .Folder (case `^INBOX$` "📥") (case `^Archive/.*` "🗃") (default "📁")}}
map
{{map .Labels (exclude .Folder) (exclude `^spam$`) (case `^inbox$` "📥") (case `^Archive/.*` "🗃") | join " "}}
Function chaining
Example: Automatic HTML parsing for text/html mime type messages
{{if eq .OriginalMIMEType "text/html"}} {{exec `/usr/libexec/aerc/filters/html` .OriginalText | wrap 72 | quote}} {{else}} {{wrap 72 .OriginalText | trimSignature | quote}} {{end}}
SEE ALSO
AUTHORS
Originally created by Drew DeVault and maintained by Robin Jarry who is assisted by other open source contributors. For more information about aerc development, see https://sr.ht/~rjarry/aerc/.
2024-07-30 |