diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2023-12-30 16:50:42 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-31 11:56:48 +0100 |
commit | 930e50328c3a57faeec7fd23881e044257eda157 (patch) | |
tree | 8f90ac9ccfaf4e2d15ce7392269c93a05c6b842e | |
parent | 90c44dab95a315d05e32a8f5e700b4ad8efdd38f (diff) | |
download | aerc-930e50328c3a57faeec7fd23881e044257eda157.tar.gz |
templates: add full path of file(s) as Filename(s)
For the maildir and notmuch backends, add the full path of the message
as Filename to templates. In case of a notmuch message having multiple
files associated with it, it returns a random path. Also add Filenames
to templates, which is a list of all associated message paths. This is
relevant for the notmuch backend, where a single messages is shown, if
there are multiple copies of it.
Changelog-added: Add filepath to messages in templates as .Filename(s)
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | config/templates.go | 2 | ||||
-rw-r--r-- | doc/aerc-templates.7.scd | 10 | ||||
-rw-r--r-- | lib/state/templates.go | 17 | ||||
-rw-r--r-- | models/models.go | 1 | ||||
-rw-r--r-- | models/templates.go | 2 | ||||
-rw-r--r-- | worker/maildir/worker.go | 5 | ||||
-rw-r--r-- | worker/notmuch/message.go | 4 |
7 files changed, 41 insertions, 0 deletions
diff --git a/config/templates.go b/config/templates.go index cab8efb2..d8c0c336 100644 --- a/config/templates.go +++ b/config/templates.go @@ -85,6 +85,8 @@ func (d *dummyData) SubjectBase() string { return "[PATCH] hey" } func (d *dummyData) Attach(string) string { return "" } func (d *dummyData) Number() int { return 0 } func (d *dummyData) Labels() []string { return nil } +func (d *dummyData) Filename() string { return "" } +func (d *dummyData) Filenames() []string { return nil } func (d *dummyData) Flags() []string { return nil } func (d *dummyData) IsReplied() bool { return true } func (d *dummyData) HasAttachment() bool { return true } diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd index 026d54e0..06b34781 100644 --- a/doc/aerc-templates.7.scd +++ b/doc/aerc-templates.7.scd @@ -141,6 +141,16 @@ available always. {{.Size | humanReadable}} ``` +*Filename* + The full path of the message file. Not available when composing, + replying nor forwarding. For the notmuch backend, it returns a random + filename if there are multiple files associated with the message. + +*Filenames* + A list of the full paths of the files associated with the message. For + maildir this is always a list with a single element. Not available when + composing, replying nor forwarding. + *Any header value* Any header value of the email. diff --git a/lib/state/templates.go b/lib/state/templates.go index ef84f071..22cdbfa6 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -354,6 +354,23 @@ func (d *templateData) Labels() []string { return d.info.Labels } +func (d *templateData) Filename() string { + if d.info == nil { + return "" + } + if (d.info.Filenames != nil) && len(d.info.Filenames) > 0 { + return d.info.Filenames[0] + } + return "" +} + +func (d *templateData) Filenames() []string { + if d.info == nil { + return nil + } + return d.info.Filenames +} + func (d *templateData) Flags() []string { var flags []string if d.info == nil { diff --git a/models/models.go b/models/models.go index 42e60b8b..55dd2347 100644 --- a/models/models.go +++ b/models/models.go @@ -97,6 +97,7 @@ type MessageInfo struct { Envelope *Envelope Flags Flags Labels []string + Filenames []string InternalDate time.Time RFC822Headers *mail.Header Refs []string diff --git a/models/templates.go b/models/templates.go index d6b90e88..77f6b787 100644 --- a/models/templates.go +++ b/models/templates.go @@ -28,6 +28,8 @@ type TemplateData interface { SubjectBase() string Number() int Labels() []string + Filename() string + Filenames() []string Flags() []string IsReplied() bool HasAttachment() bool diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index f843d002..5ca648c4 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -883,6 +883,11 @@ func (w *Worker) msgInfoFromUid(uid uint32) (*models.MessageInfo, error) { if err != nil { return nil, err } + name, err := m.dir.Filename(m.key) + if err != nil { + return nil, err + } + info.Filenames = []string{name} if w.c.IsRecent(uid) { info.Flags |= models.RecentFlag } diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index 19011679..2beda4d6 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -48,6 +48,10 @@ func (m *Message) MessageInfo() (*models.MessageInfo, error) { log.Errorf("failed to obtain file size: %v", err) } } + filenames, err := m.db.MsgFilenames(m.key) + if err == nil { + info.Filenames = filenames + } return info, nil } |