diff --git a/email/worker.go b/email/worker.go index e2f48964697e3e04e61eb1b81775579550a07c48..fb9cb89cdc46b2a709f89685cbc32126b34167aa 100644 --- a/email/worker.go +++ b/email/worker.go @@ -72,6 +72,14 @@ return nil, errors.New("Expected user PGP key to contain one key") } 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) }