diff options
author | Robin Jarry <robin@jarry.cc> | 2023-05-15 14:36:42 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-05-20 22:08:21 +0200 |
commit | 02099cc6ea29e8595f43abe5b6a475edc92e24e0 (patch) | |
tree | 1ba85ed9b8e4bb3cd4a75fa32834ace71b92e891 /lib/state | |
parent | 30c1a30168dfff8ca5eecb8d0fa42ab4b638f79d (diff) | |
download | aerc-02099cc6ea29e8595f43abe5b6a475edc92e24e0.tar.gz |
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>
Diffstat (limited to 'lib/state')
-rw-r--r-- | lib/state/templates.go | 43 |
1 files changed, 43 insertions, 0 deletions
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 "" |