aerc/lib/crypto/crypto.go
Tim Culverhouse dcd397f776 pgp: enable quoted replies of encrypted messages
When quoting an encrypted message for reply, the quoted text is shown as
"Version: 1.0". This is due to this being the first non-multipart text
portion of the message, which is what the quoted reply logic looks for.
Properly quote replies to encrypted messages by decrypting the message,
and quoting the content. The message must be open in a message view in
order to quote it (it must be decrypted, which is handled by the message
viewer).

Suggested-by: Moritz Poldrack <moritz@poldrack.dev>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Jens Grassel <jens@wegtam.com>
2022-08-31 10:10:03 +02:00

49 lines
1.1 KiB
Go

package crypto
import (
"bytes"
"io"
"git.sr.ht/~rjarry/aerc/lib/crypto/gpg"
"git.sr.ht/~rjarry/aerc/lib/crypto/pgp"
"git.sr.ht/~rjarry/aerc/models"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/emersion/go-message/mail"
)
type Provider interface {
Decrypt(io.Reader, openpgp.PromptFunction) (*models.MessageDetails, error)
Encrypt(*bytes.Buffer, []string, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
Sign(*bytes.Buffer, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
ImportKeys(io.Reader) error
Init() error
Close()
GetSignerKeyId(string) (string, error)
GetKeyId(string) (string, error)
ExportKey(string) (io.Reader, error)
}
func New(s string) Provider {
switch s {
case "gpg":
return &gpg.Mail{}
default:
return &pgp.Mail{}
}
}
func IsEncrypted(bs *models.BodyStructure) bool {
if bs == nil {
return false
}
if bs.MIMEType == "application" && bs.MIMESubType == "pgp-encrypted" {
return true
}
for _, part := range bs.Parts {
if IsEncrypted(part) {
return true
}
}
return false
}