aboutsummaryrefslogtreecommitdiffstats
path: root/lib/format/format.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-21 11:31:04 +0100
committerRobin Jarry <robin@jarry.cc>2023-01-04 22:57:31 +0100
commit5677f93ff8e0f212be112a110fcfe09663c84f98 (patch)
tree9f47f430b312d1f0dc1acdd3735cfd76ad21e0f0 /lib/format/format.go
parent36fded03e762da97edde61559c8bf60d5749d6a2 (diff)
downloadaerc-5677f93ff8e0f212be112a110fcfe09663c84f98.tar.gz
model: change flags array to bitmask
Using a list of integers is not optimal. Use a bit mask instead. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/format/format.go')
-rw-r--r--lib/format/format.go63
1 files changed, 23 insertions, 40 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index 346702c6..3f00fe18 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -294,53 +294,36 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
}
case 'Z':
// calculate all flags
- readReplyFlag := ""
- delFlag := ""
- flaggedFlag := ""
- markedFlag := ""
- hasattachment := ""
- seen := false
- recent := false
- answered := false
- for _, flag := range ctx.MsgInfo.Flags {
- switch flag {
- case models.SeenFlag:
- seen = true
- case models.RecentFlag:
- recent = true
- case models.AnsweredFlag:
- answered = true
- }
- if flag == models.DeletedFlag {
- delFlag = "D"
- // TODO: check if attachments
- }
- if flag == models.FlaggedFlag {
- flaggedFlag = "!"
- }
- // TODO: check gpg stuff
- }
- if seen {
- if answered {
- readReplyFlag = "r" // message has been replied to
- }
- } else {
- if recent {
- readReplyFlag = "N" // message is new
- } else {
- readReplyFlag = "O" // message is old
- }
+ flags := ctx.MsgInfo.Flags
+ f := ""
+
+ switch {
+ case flags.Has(models.SeenFlag | models.AnsweredFlag):
+ f += "r" // message has been replied to
+ case flags.Has(models.SeenFlag):
+ break
+ case flags.Has(models.RecentFlag):
+ f += "N" // message is new
+ default:
+ f += "O" // message is old
}
- if ctx.MsgIsMarked {
- markedFlag = "*"
+ if flags.Has(models.DeletedFlag) {
+ f += "D"
}
for _, bS := range ctx.MsgInfo.BodyStructure.Parts {
if strings.ToLower(bS.Disposition) == "attachment" {
- hasattachment = iconAttachment
+ f += iconAttachment
+ break
}
}
+ if flags.Has(models.FlaggedFlag) {
+ f += "!"
+ }
+ if ctx.MsgIsMarked {
+ f += "*"
+ }
retval = append(retval, '4', 's')
- args = append(args, readReplyFlag+delFlag+flaggedFlag+markedFlag+hasattachment)
+ args = append(args, f)
// Move the below cases to proper alphabetical positions once
// implemented