diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-20 20:29:12 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-04 22:57:31 +0100 |
commit | 37e9a924894db7e5f232e82066155a60827c339b (patch) | |
tree | 48deeeea33113bbc9e6fcbcb8973a3ba1d62a06d /commands | |
parent | c56027b2e69ec198e41394e5cf906273d80baf79 (diff) | |
download | aerc-37e9a924894db7e5f232e82066155a60827c339b.tar.gz |
config: parse account from and aliases once
Instead of accepting any garbage for these configuration fields, parse
them when parsing accounts.conf and store mail.Address objects. Reuse
these objects everywhere.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/compose/send.go | 11 | ||||
-rw-r--r-- | commands/msg/invite.go | 16 | ||||
-rw-r--r-- | commands/msg/reply.go | 16 |
3 files changed, 7 insertions, 36 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go index 4c2b0503..5af725c4 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -80,15 +80,6 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { return errors.Wrap(err, "listRecipients") } - if config.From == "" { - return errors.New("No 'From' configured for this account") - } - // TODO: the user could conceivably want to use a different From and sender - from, err := mail.ParseAddress(config.From) - if err != nil { - return errors.Wrap(err, "ParseAddress(config.From)") - } - uri, err := url.Parse(outgoing) if err != nil { return errors.Wrap(err, "url.Parse(outgoing)") @@ -107,7 +98,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { scheme: scheme, auth: auth, starttls: starttls, - from: from, + from: config.From, rcpts: rcpts, } diff --git a/commands/msg/invite.go b/commands/msg/invite.go index 2dca259b..ef28b91c 100644 --- a/commands/msg/invite.go +++ b/commands/msg/invite.go @@ -62,20 +62,10 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { } conf := acct.AccountConfig() - from, err := mail.ParseAddress(conf.From) - if err != nil { - return err - } - var aliases []*mail.Address - if conf.Aliases != "" { - aliases, err = mail.ParseAddressList(conf.Aliases) - if err != nil { - return err - } - } + from := conf.From // figure out the sending from address if we have aliases - if len(aliases) != 0 { + if len(conf.Aliases) != 0 { rec := newAddrSet() rec.AddList(msg.Envelope.To) rec.AddList(msg.Envelope.Cc) @@ -83,7 +73,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { if rec.Contains(from) { // do nothing } else { - for _, a := range aliases { + for _, a := range conf.Aliases { if rec.Contains(a) { from = a break diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 52265950..795158ca 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -71,17 +71,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { return errors.New("No account selected") } conf := acct.AccountConfig() - from, err := mail.ParseAddress(conf.From) - if err != nil { - return err - } - var aliases []*mail.Address - if conf.Aliases != "" { - aliases, err = mail.ParseAddressList(conf.Aliases) - if err != nil { - return err - } - } + from := conf.From store := widget.Store() if store == nil { @@ -93,7 +83,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { } // figure out the sending from address if we have aliases - if len(aliases) != 0 { + if len(conf.Aliases) != 0 { rec := newAddrSet() rec.AddList(msg.Envelope.To) rec.AddList(msg.Envelope.Cc) @@ -101,7 +91,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { if rec.Contains(from) { // do nothing } else { - for _, a := range aliases { + for _, a := range conf.Aliases { if rec.Contains(a) { from = a break |