about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-12-23 12:51:58 +0100
committerDrew DeVault <sir@cmpwn.com>2019-12-27 10:20:29 -0700
commit63391b7dca09e3f2cf3c4ff903592d23fe8f56a3 (patch)
tree4d1d4f918bd1a9536991a763c945139f89b8065e
parent6794ce0d9cce89d5fab726d7bc93a77b47cea677 (diff)
downloadaerc-63391b7dca09e3f2cf3c4ff903592d23fe8f56a3.tar.gz
Add labels to index format (%g)
Exposes the notmuch tags accordingly, stubs it for the maildir worker.
-rw-r--r--doc/aerc-config.5.scd2
-rw-r--r--lib/format/format.go4
-rw-r--r--lib/msgstore.go1
-rw-r--r--models/models.go1
-rw-r--r--worker/lib/parse.go6
-rw-r--r--worker/maildir/message.go4
-rw-r--r--worker/notmuch/message.go4
7 files changed, 22 insertions, 0 deletions
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 1d6294e..5dac4ac 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -59,6 +59,8 @@ These options are configured in the *[ui]* section of aerc.conf.
 |  %F
 :  author name, or recipient name if the message is from you.
    The adderss is shown if no name part.
+|  %g
+:  message labels (for example notmuch tags)
 |  %i
 :  message id
 |  %n
diff --git a/lib/format/format.go b/lib/format/format.go
index 0cb9693..b66a180 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -138,6 +138,10 @@ func ParseMessageFormat(
 			retval = append(retval, 's')
 			args = append(args, val)
 
+		case 'g':
+			retval = append(retval, 's')
+			args = append(args, strings.Join(msg.Labels, ", "))
+
 		case 'i':
 			retval = append(retval, 's')
 			args = append(args, msg.Envelope.MessageId)
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 9075a26..f67c49f 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -149,6 +149,7 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) {
 		to.Envelope = from.Envelope
 	}
 	to.Flags = from.Flags
+	to.Labels = from.Labels
 	if from.Size != 0 {
 		to.Size = from.Size
 	}
diff --git a/models/models.go b/models/models.go
index 28d256c..fa3baf2 100644
--- a/models/models.go
+++ b/models/models.go
@@ -57,6 +57,7 @@ type MessageInfo struct {
 	BodyStructure *BodyStructure
 	Envelope      *Envelope
 	Flags         []Flag
+	Labels        []string
 	InternalDate  time.Time
 	RFC822Headers *mail.Header
 	Size          uint32
diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index c3a43ca..eed39cb 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -207,6 +207,7 @@ func parseAddressList(h *mail.Header, key string) ([]*models.Address, error) {
 type RawMessage interface {
 	NewReader() (io.Reader, error)
 	ModelFlags() ([]models.Flag, error)
+	Labels() ([]string, error)
 	UID() uint32
 }
 
@@ -233,10 +234,15 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) {
 	if err != nil {
 		return nil, err
 	}
+	labels, err := raw.Labels()
+	if err != nil {
+		return nil, err
+	}
 	return &models.MessageInfo{
 		BodyStructure: bs,
 		Envelope:      env,
 		Flags:         flags,
+		Labels:        labels,
 		InternalDate:  env.Date,
 		RFC822Headers: &mail.Header{msg.Header},
 		Size:          0,
diff --git a/worker/maildir/message.go b/worker/maildir/message.go
index dc5646b..45b1ca6 100644
--- a/worker/maildir/message.go
+++ b/worker/maildir/message.go
@@ -119,3 +119,7 @@ func translateFlags(maildirFlags []maildir.Flag) []models.Flag {
 func (m Message) UID() uint32 {
 	return m.uid
 }
+
+func (m Message) Labels() ([]string, error) {
+	return nil, nil
+}
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go
index c51e2e9..ec1adb9 100644
--- a/worker/notmuch/message.go
+++ b/worker/notmuch/message.go
@@ -102,6 +102,10 @@ func (m *Message) Tags() ([]string, error) {
 	return m.db.MsgTags(m.key)
 }
 
+func (m *Message) Labels() ([]string, error) {
+	return m.Tags()
+}
+
 func (m *Message) ModelFlags() ([]models.Flag, error) {
 	var flags []models.Flag
 	seen := true