aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-05-15 14:36:42 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-20 22:08:21 +0200
commit02099cc6ea29e8595f43abe5b6a475edc92e24e0 (patch)
tree1ba85ed9b8e4bb3cd4a75fa32834ace71b92e891
parent30c1a30168dfff8ca5eecb8d0fa42ab4b638f79d (diff)
downloadaerc-02099cc6ea29e8595f43abe5b6a475edc92e24e0.tar.gz
aerc-02099cc6ea29e8595f43abe5b6a475edc92e24e0.zip
templates: add boolean flags
Allow accessing email flags via boolean properties instead of having to rely on obscure regular expressions on (.Flags | join ""). With this patch, it is now possible to do this: [ui] index-columns = star:1,name<15%,reply:1,subject,size>=,date>= column-star = {{if .IsFlagged}}★{{end}} column-name = {{if eq .Role "sent"}}{{.To | names | join ", "}}{{else}}{{.From | names | join ", "}}{{end}} column-reply = {{if .IsReplied}}{{end}} column-subject = {{.ThreadPrefix}}{{.Subject}} column-size = {{if .HasAttachment}}📎 {{end}}{{humanReadable .Size}} column-date = {{.DateAutoFormat .Date.Local}} Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Koni Marti <koni.marti@gmail.com>
-rw-r--r--commands/commands_test.go6
-rw-r--r--config/templates.go6
-rw-r--r--doc/aerc-templates.7.scd8
-rw-r--r--lib/state/templates.go43
-rw-r--r--models/templates.go6
5 files changed, 69 insertions, 0 deletions
diff --git a/commands/commands_test.go b/commands/commands_test.go
index dccb8572..e510ebe1 100644
--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -80,6 +80,12 @@ func (d *dummyData) SubjectBase() string { return "[PATCH]
func (d *dummyData) Number() int { return 0 }
func (d *dummyData) Labels() []string { return nil }
func (d *dummyData) Flags() []string { return nil }
+func (d *dummyData) IsReplied() bool { return true }
+func (d *dummyData) HasAttachment() bool { return true }
+func (d *dummyData) IsRecent() bool { return false }
+func (d *dummyData) IsUnread() bool { return false }
+func (d *dummyData) IsFlagged() bool { return false }
+func (d *dummyData) IsMarked() bool { return false }
func (d *dummyData) MessageId() string { return "123456789@foo.org" }
func (d *dummyData) Size() int { return 420 }
func (d *dummyData) OriginalText() string { return "Blah blah blah" }
diff --git a/config/templates.go b/config/templates.go
index 2b16fb22..40e7e450 100644
--- a/config/templates.go
+++ b/config/templates.go
@@ -81,6 +81,12 @@ func (d *dummyData) SubjectBase() string { return "[PATCH] hey" }
func (d *dummyData) Number() int { return 0 }
func (d *dummyData) Labels() []string { return nil }
func (d *dummyData) Flags() []string { return nil }
+func (d *dummyData) IsReplied() bool { return true }
+func (d *dummyData) HasAttachment() bool { return true }
+func (d *dummyData) IsRecent() bool { return false }
+func (d *dummyData) IsUnread() bool { return false }
+func (d *dummyData) IsFlagged() bool { return false }
+func (d *dummyData) IsMarked() bool { return false }
func (d *dummyData) MessageId() string { return "123456789@foo.org" }
func (d *dummyData) Size() int { return 420 }
func (d *dummyData) OriginalText() string { return "Blah blah blah" }
diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd
index ae9bc6dc..6919e5dd 100644
--- a/doc/aerc-templates.7.scd
+++ b/doc/aerc-templates.7.scd
@@ -98,6 +98,14 @@ available always.
{{.Flags | join ""}}
```
+*IsReplied*, *HasAttachment*, *IsFlagged*, *IsRecent*, *IsUnread*, *IsMarked*
+ Individual boolean flags. not available when composing, replying nor
+ forwarding.
+
+ ```
+ {{if .IsFlagged}}★{{end}}
+ ```
+
*Labels*
Message labels (for example notmuch tags). Not available when composing,
replying nor forwarding. This is a list of strings that may be converted
diff --git a/lib/state/templates.go b/lib/state/templates.go
index b0daa2cc..8c7df3e8 100644
--- a/lib/state/templates.go
+++ b/lib/state/templates.go
@@ -336,6 +336,49 @@ func (d *templateData) Flags() []string {
return flags
}
+func (d *templateData) IsReplied() bool {
+ if d.info != nil && d.info.Flags.Has(models.AnsweredFlag) {
+ return true
+ }
+ return false
+}
+
+func (d *templateData) HasAttachment() bool {
+ if d.info != nil && d.info.BodyStructure != nil {
+ for _, bS := range d.info.BodyStructure.Parts {
+ if strings.ToLower(bS.Disposition) == "attachment" {
+ return true
+ }
+ }
+ }
+ return false
+}
+
+func (d *templateData) IsRecent() bool {
+ if d.info != nil && d.info.Flags.Has(models.RecentFlag) {
+ return true
+ }
+ return false
+}
+
+func (d *templateData) IsUnread() bool {
+ if d.info != nil && !d.info.Flags.Has(models.SeenFlag) {
+ return true
+ }
+ return false
+}
+
+func (d *templateData) IsFlagged() bool {
+ if d.info != nil && d.info.Flags.Has(models.FlaggedFlag) {
+ return true
+ }
+ return false
+}
+
+func (d *templateData) IsMarked() bool {
+ return d.marked
+}
+
func (d *templateData) MessageId() string {
if d.info == nil || d.info.Envelope == nil {
return ""
diff --git a/models/templates.go b/models/templates.go
index f6d79c36..ae57c3fb 100644
--- a/models/templates.go
+++ b/models/templates.go
@@ -25,6 +25,12 @@ type TemplateData interface {
Number() int
Labels() []string
Flags() []string
+ IsReplied() bool
+ HasAttachment() bool
+ IsFlagged() bool
+ IsRecent() bool
+ IsUnread() bool
+ IsMarked() bool
MessageId() string
Role() string
Size() int