diff options
-rw-r--r-- | commands/commands_test.go | 6 | ||||
-rw-r--r-- | config/templates.go | 6 | ||||
-rw-r--r-- | doc/aerc-templates.7.scd | 8 | ||||
-rw-r--r-- | lib/state/templates.go | 43 | ||||
-rw-r--r-- | models/templates.go | 6 |
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 |