email/worker: catch some PGP error earlier The writer returned by pgpmail.Encryption() will have the keyring parsed, but it only tries to determine the encryption key once it is being written to. Hence, certain errors will only occur later on, when it is too late to fall back to unencrypted email. Catch these errors earlier by checking if a valid encryption key is found.
1 files changed, 8 insertions(+), 0 deletions(-) M email/worker.go
M email/worker.go => email/worker.go +8 -0
@@ 72,6 72,14 @@ func prepareEncrypted(rcptKey *string, header mail.Header, } rcptEntity := keyring[0] // Make sure we can really encrypt with this key! // pgpmail.Encrypt() returns a writer, and certain errors will only // occur once it is written to. _, ok := rcptEntity.EncryptionKey(time.Now()) if !ok { return nil, fmt.Errorf("No valid encryption key found (expired?)") } return pgpmail.Encrypt(buf, header.Header.Header, []*openpgp.Entity{rcptEntity}, signed, nil) }