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>
This commit is contained in:
parent
cd002567e8
commit
dcd397f776
2 changed files with 41 additions and 0 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
"git.sr.ht/~sircmpwn/getopt"
|
"git.sr.ht/~sircmpwn/getopt"
|
||||||
|
|
||||||
"git.sr.ht/~rjarry/aerc/lib"
|
"git.sr.ht/~rjarry/aerc/lib"
|
||||||
|
"git.sr.ht/~rjarry/aerc/lib/crypto"
|
||||||
"git.sr.ht/~rjarry/aerc/lib/format"
|
"git.sr.ht/~rjarry/aerc/lib/format"
|
||||||
"git.sr.ht/~rjarry/aerc/logging"
|
"git.sr.ht/~rjarry/aerc/logging"
|
||||||
"git.sr.ht/~rjarry/aerc/models"
|
"git.sr.ht/~rjarry/aerc/models"
|
||||||
|
@ -210,6 +211,31 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
template = aerc.Config().Templates.QuotedReply
|
template = aerc.Config().Templates.QuotedReply
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if crypto.IsEncrypted(msg.BodyStructure) {
|
||||||
|
provider := aerc.SelectedTabContent().(widgets.ProvidesMessage)
|
||||||
|
mv, ok := provider.(*widgets.MessageViewer)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("message is encrypted. can only quote reply while message is open")
|
||||||
|
}
|
||||||
|
p := provider.SelectedMessagePart()
|
||||||
|
if p == nil {
|
||||||
|
return fmt.Errorf("could not fetch message part")
|
||||||
|
}
|
||||||
|
mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
_, err := buf.ReadFrom(reader)
|
||||||
|
if err != nil {
|
||||||
|
logging.Warnf("failed to fetch bodypart: %v", err)
|
||||||
|
}
|
||||||
|
original.Text = buf.String()
|
||||||
|
err = addTab()
|
||||||
|
if err != nil {
|
||||||
|
logging.Warnf("failed to add tab: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
part := lib.FindPlaintext(msg.BodyStructure, nil)
|
part := lib.FindPlaintext(msg.BodyStructure, nil)
|
||||||
if part == nil {
|
if part == nil {
|
||||||
// mkey... let's get the first thing that isn't a container
|
// mkey... let's get the first thing that isn't a container
|
||||||
|
|
|
@ -31,3 +31,18 @@ func New(s string) Provider {
|
||||||
return &pgp.Mail{}
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue