diff options
author | Robin Jarry <robin@jarry.cc> | 2023-02-12 01:36:37 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-02-20 14:48:38 +0100 |
commit | 24f91b0277a1034f731aaf00c3e1f894c5ad27c1 (patch) | |
tree | df48abbc43c8d19f07151b1d02891f23f7fe1864 /lib/templates | |
parent | 87e3d4bafa9f1b8e91172c135644783de548e35b (diff) | |
download | aerc-24f91b0277a1034f731aaf00c3e1f894c5ad27c1.tar.gz |
templates: add firstnames and shortmboxes functions
These can be handy for tab-title-composer.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'lib/templates')
-rw-r--r-- | lib/templates/functions.go | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/templates/functions.go b/lib/templates/functions.go index ec11c1c7..5d2f1928 100644 --- a/lib/templates/functions.go +++ b/lib/templates/functions.go @@ -113,7 +113,25 @@ func names(addresses []*mail.Address) []string { for i, addr := range addresses { name := addr.Name if name == "" { - name = addr.Address + parts := strings.SplitN(addr.Address, "@", 2) + name = parts[0] + } + n[i] = name + } + return n +} + +func firstnames(addresses []*mail.Address) []string { + n := make([]string, len(addresses)) + for i, addr := range addresses { + var name string + if addr.Name == "" { + parts := strings.SplitN(addr.Address, "@", 2) + parts = strings.SplitN(parts[0], ".", 2) + name = parts[0] + } else { + parts := strings.SplitN(addr.Name, " ", 2) + name = parts[0] } n[i] = name } @@ -151,6 +169,16 @@ func mboxes(addresses []*mail.Address) []string { return e } +func shortmboxes(addresses []*mail.Address) []string { + e := make([]string, len(addresses)) + for i, addr := range addresses { + parts := strings.SplitN(addr.Address, "@", 2) + parts = strings.SplitN(parts[0], ".", 2) + e[i] = parts[0] + } + return e +} + func persons(addresses []*mail.Address) []string { e := make([]string, len(addresses)) for i, addr := range addresses { @@ -227,9 +255,11 @@ var templateFuncs = template.FuncMap{ "exec": cmd, "version": func() string { return version }, "names": names, + "firstnames": firstnames, "initials": initials, "emails": emails, "mboxes": mboxes, + "shortmboxes": shortmboxes, "persons": persons, "humanReadable": humanReadable, "cwd": cwd, |