~rjarry/aerc-devel

aerc: pgp: automatically determine signer from sender v1 APPLIED

witcher: 1
 pgp: automatically determine signer from sender

 1 files changed, 31 insertions(+), 12 deletions(-)
#950729 alpine-edge.yml success
#950730 openbsd.yml success
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/~rjarry/aerc-devel/patches/39460/mbox | git am -3
Learn more about email & git

[PATCH aerc] pgp: automatically determine signer from sender Export this patch

This patch automatically determines the signing account from the sender
of the email (i.e. the `From` email header).
To reflect this in the compose view after changing the `From` field, the
restriction in `updateCrypto()` to only run the update if the signing
key is empty has been lifted, so the key always gets updated when
calling `updateCrypt()`.
Additionally, a `Signer()` method has been added to the `Composer` to
avoid specifying the same logic twice; once in `updateCrypto()` and once
in `WriteMessage(...)`.
If the `From` header is not populated for any reason the `Signer()`
method falls back to the `From` field specified in `accounts.conf`.

Signed-off-by: witcher <witcher@wiredspace.de>
---
 widgets/compose.go | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)

diff --git a/widgets/compose.go b/widgets/compose.go
index 74493ac..4f36b29 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -388,15 +388,11 @@ func (c *Composer) updateCrypto() error {
		uiConfig := c.acct.UiConfig()
		c.crypto = newCryptoStatus(uiConfig)
	}
	var err error
	// Check if signKey is empty so we only run this once
	if c.sign && c.crypto.signKey == "" {
	if c.sign {
		cp := c.aerc.Crypto
		var s string
		if c.acctConfig.PgpKeyId != "" {
			s = c.acctConfig.PgpKeyId
		} else {
			s = c.acctConfig.From.Address
		s, err := c.Signer()
		if err != nil {
			return errors.Wrap(err, "Signer")
		}
		c.crypto.signKey, err = cp.GetSignerKeyId(s)
		if err != nil {
@@ -769,6 +765,30 @@ func getRecipientsEmail(c *Composer) ([]string, error) {
	return results, nil
}

func (c *Composer) Signer() (string, error) {
	signer := ""

	if c.acctConfig.PgpKeyId != "" {
		// get key from explicitly set keyid
		signer = c.acctConfig.PgpKeyId
	} else {
		// get signer from `from` header
		from, err := c.header.AddressList("from")
		if err != nil {
			return "", err
		}

		if len(from) > 0 {
			signer = from[0].Address
		} else {
			// fall back to address from config
			signer = c.acctConfig.From.Address
		}
	}

	return signer, nil
}

func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {
	if err := c.reloadEmail(); err != nil {
		return err
@@ -785,10 +805,9 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {

		signer := ""
		if c.sign {
			if c.acctConfig.PgpKeyId != "" {
				signer = c.acctConfig.PgpKeyId
			} else {
				signer = c.acctConfig.From.Address
			signer, err = c.Signer()
			if err != nil {
				return errors.Wrap(err, "Signer")
			}
		}

-- 
2.39.2
aerc/patches: SUCCESS in 4m25s

[pgp: automatically determine signer from sender][0] from [witcher][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/39460
[1]: mailto:witcher@wiredspace.de

✓ #950730 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/950730
✓ #950729 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/950729
witcher, Mar 02, 2023 at 21:50: