about summary refs log tree commit diff stats
path: root/commands/msg/reply.go
diff options
context:
space:
mode:
authory0ast <joost@joo.st>2020-08-20 19:22:50 +0200
committerReto Brunner <reto@labrat.space>2020-08-20 21:54:31 +0200
commit6a1c0f60afcbc56d11ef3a2b58f04f83fc67bf3b (patch)
tree5daa961ae9d44d6f57da530e621a57ad0345fbe4 /commands/msg/reply.go
parent2a186cfd713e5ba5ae649f6794b58f1bd02393fc (diff)
downloadaerc-6a1c0f60afcbc56d11ef3a2b58f04f83fc67bf3b.tar.gz
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.
Diffstat (limited to 'commands/msg/reply.go')
-rw-r--r--commands/msg/reply.go25
1 files changed, 24 insertions, 1 deletions
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 {