Add account alias configuration and correctly set From field

We infer the correct From using the To: and Cc: field of the email that
we reply to.
This commit is contained in:
y0ast 2020-08-20 19:22:50 +02:00 committed by Reto Brunner
parent 2a186cfd71
commit 6a1c0f60af
3 changed files with 34 additions and 1 deletions

View file

@ -64,6 +64,10 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return err
}
alias_of_us, err := format.ParseAddressList(conf.Aliases)
if err != nil {
return err
}
store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
@ -72,7 +76,6 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return err
}
acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
var (
to []*models.Address
@ -84,6 +87,26 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
} else {
to = msg.Envelope.From
}
// figure out the sending from address if we have aliases
if len(alias_of_us) != 0 {
allRecipients := append(msg.Envelope.To, msg.Envelope.Cc...)
outer:
for _, addr := range allRecipients {
if addr.Address == from.Address {
from = addr
break
}
for _, alias := range alias_of_us {
if addr.Address == alias.Address {
from = addr
break outer
}
}
}
}
isMainRecipient := func(a *models.Address) bool {
for _, ta := range to {
if ta.Address == a.Address {

View file

@ -75,6 +75,7 @@ type AccountConfig struct {
Default string
Postpone string
From string
Aliases string
Name string
Source string
SourceCredCmd string
@ -202,6 +203,8 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
account.OutgoingCredCmd = val
} else if key == "from" {
account.From = val
} else if key == "aliases" {
account.Aliases = val
} else if key == "copy-to" {
account.CopyTo = val
} else if key == "archive" {

View file

@ -409,6 +409,13 @@ Note that many of these configuration options are written for you, such as
Default: none
*aliases*
All aliases of the current account. These will be used to fill in the From:
field. Make sure that your email server accepts this value, or for example
use *aerc-sendmail*(5) in combination with msmtp and --read-envelope-from.
Default: none
*outgoing*
Specifies the transport for sending outgoing emails on this account. It
should be a connection string, and the specific meaning of each component