aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-20 20:29:12 +0100
committerRobin Jarry <robin@jarry.cc>2023-01-04 22:57:31 +0100
commit37e9a924894db7e5f232e82066155a60827c339b (patch)
tree48deeeea33113bbc9e6fcbcb8973a3ba1d62a06d /commands/msg
parentc56027b2e69ec198e41394e5cf906273d80baf79 (diff)
downloadaerc-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/msg')
-rw-r--r--commands/msg/invite.go16
-rw-r--r--commands/msg/reply.go16
2 files changed, 6 insertions, 26 deletions
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