diff options
author | Reto Brunner <reto@labrat.space> | 2019-12-23 12:51:59 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-27 10:20:30 -0700 |
commit | b360cca977bdf29d19764712d97af22e9165e2d0 (patch) | |
tree | dab310e9dd85d6eeba2856703527f5a99cfeee15 /widgets/msgviewer.go | |
parent | 63391b7dca09e3f2cf3c4ff903592d23fe8f56a3 (diff) | |
download | aerc-b360cca977bdf29d19764712d97af22e9165e2d0.tar.gz |
msgviewer: Add Labels as a virtual header
In order to accommodate for that, the headerlayout needed to be rewritten
to pass the filter criteria back to the msgviewer, instead of just using
the normal headers.
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r-- | widgets/msgviewer.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index ee7dd504..25bebfa3 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -52,7 +52,16 @@ type PartSwitcher struct { func NewMessageViewer(acct *AccountView, conf *config.AercConfig, store *lib.MessageStore, msg *models.MessageInfo) *MessageViewer { - layout := HeaderLayout(conf.Viewer.HeaderLayout).forMessage(msg) + hf := HeaderLayoutFilter{ + layout: HeaderLayout(conf.Viewer.HeaderLayout), + keep: func(msg *models.MessageInfo, header string) bool { + if fmtHeader(msg, header, "2") != "" { + return true + } + return false + }, + } + layout := hf.forMessage(msg) header, headerHeight := layout.grid( func(header string) ui.Drawable { return &HeaderView{ @@ -109,6 +118,8 @@ func fmtHeader(msg *models.MessageInfo, header string, timefmt string) string { return msg.Envelope.Date.Local().Format(timefmt) case "Subject": return msg.Envelope.Subject + case "Labels": + return strings.Join(msg.Labels, ", ") default: return msg.RFC822Headers.Get(header) } @@ -580,6 +591,11 @@ func (pv *PartViewer) attemptCopy() { "%s: %s\n", fields.Key(), fields.Value()) pv.sink.Write([]byte(field)) } + // virtual header + if len(pv.msg.Labels) != 0 { + labels := fmtHeader(pv.msg, "Labels", "") + pv.sink.Write([]byte(fmt.Sprintf("Labels: %s\n", labels))) + } pv.sink.Write([]byte{'\n'}) } |