aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/compose/send.go11
-rw-r--r--commands/msg/invite.go16
-rw-r--r--commands/msg/reply.go16
-rw-r--r--config/accounts.go19
-rw-r--r--config/triggers.go2
-rw-r--r--widgets/account-wizard.go9
-rw-r--r--widgets/aerc.go2
-rw-r--r--widgets/compose.go35
-rw-r--r--widgets/msglist.go2
9 files changed, 38 insertions, 74 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
diff --git a/config/accounts.go b/config/accounts.go
index aa4bde29..6cd30098 100644
--- a/config/accounts.go
+++ b/config/accounts.go
@@ -15,6 +15,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/log"
+ "github.com/emersion/go-message/mail"
"github.com/go-ini/ini"
)
@@ -73,8 +74,8 @@ type AccountConfig struct {
CopyTo string `ini:"copy-to"`
Default string `ini:"default"`
Postpone string `ini:"postpone"`
- From string `ini:"from"`
- Aliases string `ini:"aliases"`
+ From *mail.Address `ini:"-"`
+ Aliases []*mail.Address `ini:"-"`
Name string `ini:"-"`
Source string `ini:"-"`
Folders []string `ini:"folders" delim:","`
@@ -163,6 +164,18 @@ func parseAccounts(root string, accts []string) error {
return fmt.Errorf("%s=%s %w", key, val, err)
}
account.Outgoing.CacheCmd = cache
+ case "from":
+ addr, err := mail.ParseAddress(val)
+ if err != nil {
+ return fmt.Errorf("%s=%s %w", key, val, err)
+ }
+ account.From = addr
+ case "aliases":
+ addrs, err := mail.ParseAddressList(val)
+ if err != nil {
+ return fmt.Errorf("%s=%s %w", key, val, err)
+ }
+ account.Aliases = addrs
case "subject-re-pattern":
re, err := regexp.Compile(val)
if err != nil {
@@ -205,7 +218,7 @@ func parseAccounts(root string, accts []string) error {
if account.Source == "" {
return fmt.Errorf("Expected source for account %s", _sec)
}
- if account.From == "" {
+ if account.From == nil {
return fmt.Errorf("Expected from for account %s", _sec)
}
diff --git a/config/triggers.go b/config/triggers.go
index 7b461e70..906928ae 100644
--- a/config/triggers.go
+++ b/config/triggers.go
@@ -66,7 +66,7 @@ func (trig *TriggersConfig) ExecNewEmail(
Ui.ThisYearTimeFormat,
Ui.IconAttachment,
format.Ctx{
- FromAddress: account.From,
+ FromAddress: format.AddressForHumans(account.From),
AccountName: account.Name,
MsgInfo: msg,
},
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 2ff87241..4b948a30 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -13,6 +13,7 @@ import (
"sync"
"time"
+ "github.com/emersion/go-message/mail"
"github.com/gdamore/tcell/v2"
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
@@ -531,10 +532,16 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
}
+ from, err := mail.ParseAddress(sec.Key("from").String())
+ if err != nil {
+ wizard.errorFor(nil, err)
+ return
+ }
+
account := config.AccountConfig{
Name: sec.Name(),
Default: "INBOX",
- From: sec.Key("from").String(),
+ From: from,
Source: sec.Key("source").String(),
Outgoing: config.RemoteConfig{Value: sec.Key("outgoing").String()},
}
diff --git a/widgets/aerc.go b/widgets/aerc.go
index cf893a7d..f6e5c1ff 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -748,7 +748,7 @@ func (aerc *Aerc) Mbox(source string) error {
aerc.PushStatus(info, 10*time.Second)
log.Debugf(info)
} else {
- acctConf.From = "<user@localhost>"
+ acctConf.From = &mail.Address{Address: "user@localhost"}
}
acctConf.Name = "mbox"
acctConf.Source = source
diff --git a/widgets/compose.go b/widgets/compose.go
index a625e7eb..782e7538 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -141,13 +141,7 @@ func (c *Composer) setupFor(view *AccountView) error {
// Set from header if not already in header
if fl, err := c.header.AddressList("from"); err != nil || fl == nil {
- fl, err = mail.ParseAddressList(view.acct.From)
- if err != nil {
- return err
- }
- if fl != nil {
- c.header.SetAddressList("from", fl)
- }
+ c.header.SetAddressList("from", []*mail.Address{view.acct.From})
}
// update completer
@@ -294,10 +288,7 @@ func (c *Composer) SetAttachKey(attach bool) error {
if c.acctConfig.PgpKeyId != "" {
s = c.acctConfig.PgpKeyId
} else {
- s, err = getSenderEmail(c)
- if err != nil {
- return err
- }
+ s = c.acctConfig.From.Address
}
c.crypto.signKey, err = c.aerc.Crypto.GetSignerKeyId(s)
if err != nil {
@@ -390,10 +381,7 @@ func (c *Composer) updateCrypto() error {
if c.acctConfig.PgpKeyId != "" {
s = c.acctConfig.PgpKeyId
} else {
- s, err = getSenderEmail(c)
- if err != nil {
- return err
- }
+ s = c.acctConfig.From.Address
}
c.crypto.signKey, err = cp.GetSignerKeyId(s)
if err != nil {
@@ -717,18 +705,6 @@ func (c *Composer) PrepareHeader() (*mail.Header, error) {
return c.header, nil
}
-func getSenderEmail(c *Composer) (string, error) {
- // add the from: field also to the 'recipients' list
- if c.acctConfig.From == "" {
- return "", errors.New("No 'From' configured for this account")
- }
- from, err := mail.ParseAddress(c.acctConfig.From)
- if err != nil {
- return "", errors.Wrap(err, "ParseAddress(config.From)")
- }
- return from.Address, nil
-}
-
func getRecipientsEmail(c *Composer) ([]string, error) {
h, err := c.PrepareHeader()
if err != nil {
@@ -776,10 +752,7 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {
if c.acctConfig.PgpKeyId != "" {
signer = c.acctConfig.PgpKeyId
} else {
- signer, err = getSenderEmail(c)
- if err != nil {
- return err
- }
+ signer = c.acctConfig.From.Address
}
}
diff --git a/widgets/msglist.go b/widgets/msglist.go
index c260da1c..839453f2 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -91,7 +91,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
createBaseCtx := func(uid uint32, row int) format.Ctx {
return format.Ctx{
- FromAddress: acct.acct.From,
+ FromAddress: format.AddressForHumans(acct.acct.From),
AccountName: acct.Name(),
MsgInfo: store.Messages[uid],
MsgNum: row,