aboutsummaryrefslogtreecommitdiffstats
path: root/lib/templates
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-02-12 01:36:37 +0100
committerRobin Jarry <robin@jarry.cc>2023-02-20 14:48:38 +0100
commit24f91b0277a1034f731aaf00c3e1f894c5ad27c1 (patch)
treedf48abbc43c8d19f07151b1d02891f23f7fe1864 /lib/templates
parent87e3d4bafa9f1b8e91172c135644783de548e35b (diff)
downloadaerc-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.go32
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,