Debian Codegraph @

doc/aerc-templates.7.scd

raw
1 AERC-TEMPLATES(7)
2
3 # NAME
4
5 aerc-templates - template file specification for *aerc*(1)
6
7 # SYNOPSIS
8
9 aerc uses the go text/template package for the template parsing.
10 Refer to the go text/template documentation for the general syntax.
11 The template syntax described below can be used for message template files and
12 for dynamic formatting of some UI app.
13
14 Template files are composed of headers, followed by a newline, followed by the
15 body text.
16
17 Example:
18
19 ```
20 X-Clacks-Overhead: GNU Terry Pratchett
21
22 Hello,
23
24 Greetings,
25 Chuck
26 ```
27
28 If you have a template that doesn't add any header, it *must* be preceded by a
29 newline, to avoid parsing parts of the body as header text.
30
31 All headers defined in the template will have precedence over any headers that
32 are initialized by aerc (e.g. Subject, To, From, Cc) when composing a new
33 message, forwarding or replying.
34
35 # MESSAGE DATA
36
37 The following data can be used in templates. Though they are not all
38 available always.
39
40 *Addresses*
41 An array of mail.Address. That can be used to add sender or recipient
42 names to the template.
43
44 - _{{.From}}_: List of senders.
45 - _{{.Peer}}_: List of senders or To recipients if the message is from
46 you.
47 - _{{.To}}_: List of To recipients. Not always Available.
48 - _{{.ReplyTo}}_: List of ReplyTo recipients. Not always Available.
49 - _{{.Cc}}_: List of Cc recipients. Not always Available.
50 - _{{.Bcc}}_: List of Cc recipients. Not always Available.
51 - _{{.OriginalFrom}}_: List of senders of the original message.
52 Available for quoted reply and forward.
53
54 Example:
55
56 Get the name of the first sender.
57 ```
58 {{(index .From 0).Name}}
59 {{index (.From | names) 0}}
60 ```
61
62 Get the email address of the first sender.
63 ```
64 {{(index .From 0).Address}}
65 ```
66
67 *Date and Time*
68 The date and time information is always available and can be easily
69 formatted.
70
71 - _{{.Date}}_: Date and time information when the compose window is opened.
72 - _{{.OriginalDate}}_: Date and time when the original message was received.
73 Available for quoted reply and forward.
74
75 To format the date fields, _dateFormat_ and _.Local_ are provided.
76 Refer to the *TEMPLATE FUNCTIONS* section for details.
77
78 *Subject*
79 The subject of the email (_ThreadPrefix_ will be empty unless threading
80 is enabled).
81
82 ```
83 {{.ThreadPrefix}}{{if .ThreadFolded}}{{printf "{%d}" .ThreadCount}}{{end}}{{.Subject}}
84 ```
85
86 The subject of the email stripped of any _Re:_ and _Fwd:_ prefixes.
87
88 ```
89 {{.SubjectBase}}
90 ```
91
92 *Number*
93 The message number in the message list (starting from 1).
94
95 ```
96 {{.Number}}
97 ```
98
99 *Threading*
100 When threading is enabled, these attributes are available in the message
101 list:
102
103 _ThreadPrefix_
104 If the message is part of a thread, this will contain arrows
105 that represent the message tree based on _In-Reply-To_ and
106 _References_ headers.
107
108 _ThreadFolded_
109 Will be _true_ if the message has thread children which are
110 hidden by *:fold*.
111
112 _ThreadCount_
113 The number of messages in the thread.
114
115 _ThreadUnread_
116 The number of unread messages in the thread.
117
118 _ThreadContext_
119 Will be _true_ if the message is shown for display context
120 only.
121
122 _ThreadOrphan_
123 Will be _true_ if the message has missing ancestors.
124
125 *Flags*
126 List of message flags, not available when composing, replying nor
127 forwarding. This is a list of strings that may be converted to a single
128 string with *join*.
129
130 ```
131 {{.Flags | join ""}}
132 ```
133
134 *IsReplied*, *IsForwarded*, *HasAttachment*, *IsFlagged*, *IsRecent*, *IsUnread*,
135 *IsMarked*, *IsDraft*
136 Individual boolean flags. Not available when composing, replying nor
137 forwarding.
138
139 ```
140 {{if .IsFlagged}}★{{end}}
141 ```
142
143 *Labels*
144 Message labels (for example notmuch tags). Not available when composing,
145 replying nor forwarding. This is a list of strings that may be converted
146 to a single string with *join*.
147
148 ```
149 {{.Labels | join " "}}
150 ```
151
152 *Size*
153 The size of the message in bytes. Not available when composing, replying
154 nor forwarding. It can be formatted with *humanReadable*.
155
156 ```
157 {{.Size | humanReadable}}
158 ```
159
160 *Filename*
161 The full path of the message file. Not available when composing,
162 replying nor forwarding. For the notmuch backend, it returns a random
163 filename if there are multiple files associated with the message.
164
165 *Filenames*
166 A list of the full paths of the files associated with the message. For
167 maildir this is always a list with a single element. Not available when
168 composing, replying nor forwarding.
169
170 *Any header value*
171 Any header value of the email.
172
173 ```
174 {{.Header "x-foo-bar"}}
175 ```
176
177 Any header values of the original forwarded or replied message:
178
179 ```
180 {{.OriginalHeader "x-foo-bar"}}
181 ```
182 *Message-ID*
183 The message-ID of the message.
184
185 ```
186 :term b4 am {{.MessageId}}
187 ```
188
189 *MIME Type*
190 MIME type is available for quoted reply and forward.
191
192 - _{{.OriginalMIMEType}}_: MIME type info of quoted mail part. Usually
193 _text/plain_ or _text/html_.
194
195 *Original Message*
196 When using quoted reply or forward, the original message is available in a
197 field called _OriginalText_.
198
199 ```
200 {{.OriginalText}}
201 ```
202
203 *Signature*
204 The signature of the currently selected account obtained from
205 *signature-file* or *signature-cmd*.
206
207 ```
208 {{.Signature}}
209 ```
210
211 *Account info*
212 The current account name:
213
214 ```
215 {{.Account}}
216 ```
217
218 The current account's backend:
219
220 ```
221 {{.AccountBackend}}
222 ```
223
224 The current account's from address:
225
226 ```
227 {{.AccountFrom}}
228 {{.AccountFrom.Address}}
229 ```
230
231 Currently selected mailbox folder:
232
233 ```
234 {{.Folder}}
235 ```
236
237 Current message counts for all folders:
238
239 ```
240 {{.Recent}} {{.Unread}} {{.Exists}}
241 {{.RUE}}
242 ```
243
244 The new message status for the account. New messages are such that have
245 arrived since the account tab last had focus. The flag is currently only
246 set when aerc is running at the time of the arrival, i.e. messages that
247 have arrived while aerc was not running will not be indicated.
248
249 ```
250 {{.HasNew}}
251 ```
252
253 IANA role of the mailbox, converted to lowercase:
254
255 ```
256 {{.Role}}
257 ```
258
259 *aerc* implements two additional custom roles: A 'query' role is given
260 to folders from a notmuch query-map
261 and 'virtual' indicates a virtual node in the directory tree listing:
262
263 ```
264 {{if eq .Role "query"}}{{...}}{{else}}{{...}}{{end}}
265 ```
266
267 Current message counts for specific folders:
268
269 ```
270 {{.Recent "inbox"}}
271 {{.Unread "inbox" "aerc/pending"}}
272 {{.Exists "archive" "spam" "foo/baz" "foo/bar"}}
273 {{.RUE "inbox"}}
274 ```
275
276 *Status line*
277
278 The following data will only be available in the status line templates:
279
280 Connection state.
281
282 ```
283 {{.Connected}}
284 {{.ConnectionInfo}}
285 ```
286
287 General status information (e.g. filter, search) separated with
288 *[statusline].separator*.
289
290 ```
291 {{.ContentInfo}}
292 ```
293
294 Combination of *{{.ConnectionInfo}}* and *{{.StatusInfo}}* separated
295 with *[statusline].separator*.
296
297 ```
298 {{.StatusInfo}}
299 ```
300
301 General on/off information (e.g. passthrough, threading, sorting, visual
302 mode), separated with *[statusline].separator*.
303
304 ```
305 {{.TrayInfo}}
306 ```
307
308 Currently pressed key sequence that does not match any key binding
309 and/or is incomplete.
310
311 ```
312 {{.PendingKeys}}
313 ```
314
315 *Terminal*
316
317 The following can only be used in the terminal tab title template:
318
319 Bell state indicating whether the bell was rung since the terminal tab
320 last had focus.
321
322 ```
323 {{.Bell}}
324 ```
325
326 Title of the terminal. This is typically what the program running in the
327 terminal requests it to be or the name of the command.
328
329 ```
330 {{.Title}}
331 ```
332
333 # TEMPLATE FUNCTIONS
334
335 Besides the standard functions described in go's text/template documentation,
336 aerc provides the following additional functions:
337
338 *wrap*
339 Wrap the original text to the specified number of characters per line.
340
341 ```
342 {{wrap 72 .OriginalText}}
343 ```
344
345 *quote*
346 Prepends each line with _"> "_.
347
348 ```
349 {{quote .OriginalText}}
350 ```
351
352 *trimSignature*
353 Removes the signature from a passed in mail. Quoted signatures are kept
354 as they are.
355
356 ```
357 {{trimSignature .OriginalText}}
358 ```
359
360 *join*
361 Join the provided list of strings with a separator:
362
363 ```
364 {{.To | names | join ", "}}
365 ```
366
367 *split*
368 Split a string into a string slice with a separator:
369
370 ```
371 {{.To | names | join ", " | split ", "}}
372 ```
373
374 *names*
375 Extracts the names part from a mail.Address list. If there is no name
376 available, the mbox (email address without @domain) is returned instead.
377
378 ```
379 {{.To | names | join ", "}}
380 {{index (.To | names) 0}}
381 ```
382
383 *firstnames*
384 Extracts the first names part from a mail.Address list. If there is no
385 name available, the short mbox (start of email address without @domain)
386 is returned instead.
387
388 ```
389 {{.To | firstnames | join ", "}}
390 {{index (.To | firstnames) 0}}
391 ```
392
393 *initials*
394 Extracts the initials from the names part from a mail.Address list. If
395 there is no name available, the first letter of the email address is
396 returned instead.
397
398 ```
399 {{.To | initials | join ", "}}
400 {{index (.To | initials) 0}}
401 ```
402
403 *emails*
404 Extracts the addresses part from a mail.Address list.
405
406 ```
407 {{.To | emails | join ", "}}
408 {{index (.To | emails) 0}}
409 ```
410
411 *mboxes*
412 Extracts the mbox part from a mail.Address list (i.e. _smith_ from
413 [email protected]_).
414
415 ```
416 {{.To | mboxes | join ", "}}
417 {{index (.To | mboxes) 0}}
418 ```
419
420 *shortmboxes*
421 Extracts the short mbox part from a mail.Address list (i.e. _smith_ from
422 [email protected]_).
423
424 ```
425 {{.To | shortmboxes | join ", "}}
426 {{index (.To | shortmboxes) 0}}
427 ```
428
429 *persons*
430 Formats a list of mail.Address into a list of strings containing the
431 human readable form of RFC5322 (e.g. _Firstname Lastname
432 <[email protected]>_).
433
434 ```
435 {{.To | persons | join ", "}}
436 {{index (.To | persons) 0}}
437 ```
438
439 *.Attach*
440 Attaches a file to the message being composed.
441
442 ```
443 {{.Attach '/usr/libexec/aerc/filters/html'}}
444 ```
445
446 *exec*
447 Execute external command, provide the second argument to its stdin.
448 The command is executed with the same search *$PATH* than aerc filters
449 (see *aerc-config*(5) in the *FILTERS* section for more details).
450
451 ```
452 {{exec `html` .OriginalText}}
453 ```
454
455 *.Local*
456 Convert the date to the local timezone as specified by the locale.
457
458 ```
459 {{.Date.Local}}
460 ```
461
462 *dateFormat*
463 Format date and time according to the format passed as the second argument.
464 The format must be specified according to go's time package format.
465
466 ```
467 {{dateFormat .Date "Mon Jan 2 15:04:05 -0700 MST 2006"}}
468 ```
469
470 You can also use the _.DateAutoFormat_ method to format the date
471 according to *\*-time\*format* settings:
472
473 ```
474 {{.DateAutoFormat .OriginalDate.Local}}
475 ```
476
477 *now*
478 Return the current date as a golang time.Time object that can be
479 formatted with *dateFormat*.
480
481 ```
482 {{dateFormat now "Mon Jan 2 15:04:05 -0700 MST 2006"}}
483 ```
484
485 *humanReadable*
486 Return the human readable form of an integer value.
487
488 ```
489 {{humanReadable 3217653721}}
490 ```
491
492 *cwd*
493 Return the current working directory with the user home dir replaced by
494 _~_.
495
496 ```
497 {{cwd}}
498 ```
499
500 *compactDir*
501 Reduce a directory path into a compact form. The directory name will be
502 split with _/_ and each part will be reduced to the first letter in its
503 name: _INBOX/01_WORK/PROJECT_ will become _I/W/PROJECT_.
504
505 ```
506 {{compactDir .Folder}}
507 ```
508
509 *contains*
510 Checks if a string contains a substring.
511
512 ```
513 {{contains "<!DOCTYPE html>" .OriginalText}}
514 ```
515
516 *hasPrefix*
517 Checks if a string has a prefix.
518
519 ```
520 {{hasPrefix "Business" .Folder}}
521 ```
522
523 *toLower*
524 Convert a string to lowercase.
525
526 ```
527 {{toLower "SPECIAL OFFER!"}}
528 ```
529
530 *toUpper*
531 Convert a string to uppercase.
532
533 ```
534 {{toUpper "important"}}
535 ```
536
537 *replace*
538 Perform a regular expression substitution on the passed string.
539
540 ```
541 {{replace `(.+) - .+ at .+\..+` `$1` ((index .OriginalFrom 0).Name)}}
542 ```
543
544 *head*
545 Return first n characters from string.
546
547 ```
548 {{"hello" | head 2}}
549 ```
550
551 *tail*
552 Return last n characters from string.
553
554 ```
555 {{"hello" | tail 2}}
556 ```
557
558 *.Style*
559 Apply a user-defined style (see *aerc-stylesets*(7)) to a string.
560
561 ```
562 {{.Style .Account "red"}}
563 {{.Style .ThreadPrefix "thread"}}{{.Subject}}
564 ```
565
566 *.StyleSwitch*
567 Apply a user-defined style (see *aerc-stylesets*(7)) to a string if it
568 matches one of the associated regular expressions. If the string does
569 not match any of the expressions, leave it unstyled.
570
571 ```
572 {{.StyleSwitch .Subject (case `^(\[[\w-]+\]\s*)?\[(RFC )?PATCH` "cyan")}}
573 {{.StyleSwitch (.From | names | join ", ") (case `Tim` "cyan") (case `Robin` "pink-blink") (default "blue")}}
574 ```
575
576 *.StyleMap*
577 Apply user-defined styles (see *aerc-stylesets*(7)) to elements of
578 a string list. The logic is the same as *.StyleSwitch* but works on
579 a list of elements. An additional *exclude* option is available to
580 remove the matching elements from the list.
581
582 ```
583 {{.StyleMap .Labels (exclude .Folder) (exclude `^spam$`) (case `^inbox$` "red") (case `^Archive/.*` "green") (default "blue") | join " "}}
584 ```
585
586 *version*
587 Returns the version of aerc, which can be useful for things like X-Mailer.
588
589 ```
590 X-Mailer: aerc {{version}}
591 ```
592
593 *match*
594 Check if a string matches a regular expression. This is intended for
595 use in conditional control flow:
596
597 ```
598 {{if match .Folder `.*/Archive-[0-9]+`}}{{humanReadable .Unread}}{{end}}
599 ```
600
601 *switch*
602 Do switch/case/default control flows. The switch value is compared with
603 regular expressions. If none of the case/default arms match, an empty
604 string is returned.
605
606 ```
607 {{switch .Folder (case `^INBOX$` "📥") (case `^Archive/.*` "🗃") (default "📁")}}
608 ```
609
610 *map*
611 Transform a string list into another one. The logic is the same as
612 *switch* but works on a list of elements. An additional *exclude* option
613 is available to remove the matching elements from the list.
614
615 ```
616 {{map .Labels (exclude .Folder) (exclude `^spam$`) (case `^inbox$` "📥") (case `^Archive/.*` "🗃") | join " "}}
617 ```
618
619 *Function chaining*
620 All of the template functions can be chained together if needed.
621
622 Example: Automatic HTML parsing for text/html mime type messages
623
624 ```
625 {{if eq .OriginalMIMEType "text/html"}}
626 {{exec `/usr/libexec/aerc/filters/html` .OriginalText | wrap 72 | quote}}
627 {{else}}
628 {{wrap 72 .OriginalText | trimSignature | quote}}
629 {{end}}
630 ```
631
632 # SEE ALSO
633
634 *aerc*(1) *aerc-config*(5)
635
636 # AUTHORS
637
638 Originally created by Drew DeVault and maintained by Robin Jarry who is assisted
639 by other open source contributors. For more information about aerc development,
640 see _https://sr.ht/~rjarry/aerc/_.