aboutsummaryrefslogtreecommitdiffstats
path: root/lib/format
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-04-28 22:09:53 +0200
committerRobin Jarry <robin@jarry.cc>2022-04-29 13:41:38 +0200
commite1ae7b80cc49bf28d93943438ac4e68d22ee7ada (patch)
treea0172d2931a5fe97aef72a13461c5a1adab810ee /lib/format
parent8f976af17bdb049dab21bd4f7d24f352a54c9ba0 (diff)
downloadaerc-e1ae7b80cc49bf28d93943438ac4e68d22ee7ada.tar.gz
dirlist: add format specifier to compact folder name
Add the format specifier %N to the dirlist-format to display compacted folder names. A folder such as INBOX/WORK/PROJECT will be compacted to I/W/PROJECT in the directoy list. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/format')
-rw-r--r--lib/format/format.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index 59b5c479..ca90ac4a 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -39,6 +39,33 @@ func FormatAddresses(l []*mail.Address) string {
return strings.Join(formatted, ", ")
}
+// CompactPath reduces a directory path into a compact form. The directory
+// name will be split with the provided separator and each part will be reduced
+// to the first letter in its name: INBOX/01_WORK/PROJECT will become
+// I/W/PROJECT.
+func CompactPath(name string, sep rune) (compact string) {
+ parts := strings.Split(name, string(sep))
+ for i, part := range parts {
+ if i == len(parts)-1 {
+ compact += part
+ } else {
+ if len(part) != 0 {
+ r := part[0]
+ for i := 0; i < len(part)-1; i++ {
+ if unicode.IsLetter(rune(part[i])) {
+ r = part[i]
+ break
+ }
+ }
+ compact += fmt.Sprintf("%c%c", r, sep)
+ } else {
+ compact += fmt.Sprintf("%c", sep)
+ }
+ }
+ }
+ return
+}
+
type Ctx struct {
FromAddress string
AccountName string