diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-05-30 11:30:17 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-06-05 08:41:13 +0200 |
commit | 47c226687265ff29969fd73cdc69a938fae20d4c (patch) | |
tree | ca4e07dd81816a2725f2bf8f3ef9b727bbbf03bd | |
parent | 74bba6745d2bf1120d143a9898c8a7204d9d20e9 (diff) | |
download | aerc-47c226687265ff29969fd73cdc69a938fae20d4c.tar.gz |
templates: add .AccountBackend
It's useful to know what the current account's backend is, especially if
one has multiple configs where the same account name might use
a different backend. Add AccountBackend to templates.
Changelog-added: Added `{{.AccountBackend}}` to templates.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | config/accounts.go | 22 | ||||
-rw-r--r-- | config/templates.go | 1 | ||||
-rw-r--r-- | doc/aerc-templates.7.scd | 6 | ||||
-rw-r--r-- | lib/state/templates.go | 7 | ||||
-rw-r--r-- | models/templates.go | 1 |
5 files changed, 36 insertions, 1 deletions
diff --git a/config/accounts.go b/config/accounts.go index 4d1d60bf..77afa0f9 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -69,7 +69,8 @@ func (c *RemoteConfig) ConnectionString() (string, error) { } type AccountConfig struct { - Name string + Name string + Backend string // backend specific Params map[string]string @@ -247,6 +248,8 @@ func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, erro if account.Source == "" { return nil, fmt.Errorf("missing 'source' parameter") } + + account.Backend = parseBackend(account.Source) if account.From == nil { return nil, fmt.Errorf("missing 'from' parameter") } @@ -269,6 +272,23 @@ func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, erro return &account, nil } +func parseBackend(source string) string { + u, err := url.Parse(source) + if err != nil { + return "" + } + if strings.HasPrefix(u.Scheme, "imap") { + return "imap" + } + if strings.HasPrefix(u.Scheme, "maildir") { + return "maildir" + } + if strings.HasPrefix(u.Scheme, "jmap") { + return "jmap" + } + return u.Scheme +} + func (a *AccountConfig) ParseSource(sec *ini.Section, key *ini.Key) (string, error) { var remote RemoteConfig remote.Value = key.String() diff --git a/config/templates.go b/config/templates.go index edcd3abb..5a38cd61 100644 --- a/config/templates.go +++ b/config/templates.go @@ -65,6 +65,7 @@ var ( ) func (d *dummyData) Account() string { return "work" } +func (d *dummyData) AccountBackend() string { return "maildir" } func (d *dummyData) Signature() string { return "" } func (d *dummyData) Folder() string { return "INBOX" } func (d *dummyData) To() []*mail.Address { return []*mail.Address{&addr1} } diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd index 71acc6b1..b5681030 100644 --- a/doc/aerc-templates.7.scd +++ b/doc/aerc-templates.7.scd @@ -200,6 +200,12 @@ available always. {{.Account}} ``` + The current account's backend: + + ``` + {{.AccountBackend}} + ``` + Currently selected mailbox folder: ``` diff --git a/lib/state/templates.go b/lib/state/templates.go index 37767660..e5206cf0 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -160,6 +160,13 @@ func (d *templateData) Account() string { return "" } +func (d *templateData) AccountBackend() string { + if d.account != nil { + return d.account.Backend + } + return "" +} + func (d *templateData) Folder() string { if d.folder != nil { return d.folder.Name diff --git a/models/templates.go b/models/templates.go index 5caed158..c9b5d5b3 100644 --- a/models/templates.go +++ b/models/templates.go @@ -9,6 +9,7 @@ import ( // This interface needs to be implemented for compliance with aerc-templates(7) type TemplateData interface { Account() string + AccountBackend() string Folder() string To() []*mail.Address Cc() []*mail.Address |