~sircmpwn/aerc

correctly set sender in cases of alias and smtp sending v3 PROPOSED

y0ast: 1
 correctly set sender in cases of alias and smtp sending

 2 files changed, 23 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/14199/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v3] correctly set sender in cases of alias and smtp sending Export this patch

Use the From: field in the "mail from" part of the email, when it's an
alias. Properly document this behavior in the aliases config
description.

---
Added the extra guard for a nil headerFrom, as requested.
Thanks for the check Reto, completely missed this case.

 commands/compose/send.go | 20 +++++++++++++++++---
 doc/aerc-config.5.scd    |  8 ++++++--
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/commands/compose/send.go b/commands/compose/send.go
index abbcb54..aa64dda 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -4,7 +4,6 @@ import (
	"crypto/tls"
	"fmt"
	"io"
	"net/mail"
	"net/url"
	"os/exec"
	"strings"
@@ -17,6 +16,7 @@ import (
	"github.com/pkg/errors"

	"git.sr.ht/~sircmpwn/aerc/lib"
	"git.sr.ht/~sircmpwn/aerc/lib/format"
	"git.sr.ht/~sircmpwn/aerc/models"
	"git.sr.ht/~sircmpwn/aerc/widgets"
	"git.sr.ht/~sircmpwn/aerc/worker/types"
@@ -79,11 +79,26 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
	if config.From == "" {
		return errors.New("No 'From' configured for this account")
	}
	from, err := mail.ParseAddress(config.From)
	from, err := format.ParseAddress(config.From)
	if err != nil {
		return errors.Wrap(err, "ParseAddress(config.From)")
	}

	// check if header from is an alias, if so send from there
	aliases, err := format.ParseAddressList(config.Aliases)
	if err != nil {
		return errors.Wrap(err, "ParseAddressList(config.Aliases)")
	}
	headerFrom, err := header.AddressList("From")
	if err == nil && headerFrom != nil {
		for _, a := range aliases {
			if headerFrom[0].Address == a.Address {
				from = a
				break
			}
		}
	} // else just use the account config value

	var (
		saslClient sasl.Client
		conn       *smtp.Client
@@ -196,7 +211,6 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
				return 0, errors.Wrap(err, "conn.Auth")
			}
		}
		// TODO: the user could conceivably want to use a different From and sender
		if err = conn.Mail(from.Address, nil); err != nil {
			return 0, errors.Wrap(err, "conn.Mail")
		}
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index c96ea12..b9a2769 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -413,8 +413,12 @@ Note that many of these configuration options are written for you, such as

*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.
	and "mail from" (RFC2821) field. Make sure that your email server accepts
	the alias as "mail from" when sending through smtp, or for example use
	*aerc-sendmail*(5) in combination with msmtp and --read-envelope-from to
	customize the outgoing server. If you only want to overwrite the From:
	field, but not the header then do not set an alias, but overwrite the value
	manually during compose.

	Default: none

-- 
2.28.0