From 6a1c0f60afcbc56d11ef3a2b58f04f83fc67bf3b Mon Sep 17 00:00:00 2001 From: y0ast Date: Thu, 20 Aug 2020 19:22:50 +0200 Subject: 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. --- commands/msg/reply.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'commands/msg/reply.go') diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 7181e1e..8cca2b1 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -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 { -- cgit 1.4.1-2-gfad0