recall: support pgp/mime messages

PGP/MIME messages are stored encrypted and/or signed in the draft folder
for security reasons. Recall will open them through the lib.MessageView
interface in order to display the message content properly in the
composer tab. If the stored message was encrypted or signed, the
recalled message in the composer will also be encrypted or signed.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-07-05 21:42:45 +02:00 committed by Robin Jarry
parent a293a39454
commit e19b411e52

View file

@ -139,21 +139,26 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}) })
} }
// find the main body part and add it to the editor lib.NewMessageStoreView(msgInfo, store, aerc.Crypto, aerc.DecryptKeys,
// TODO: copy all parts of the message over? func(msg lib.MessageView, err error) {
if err != nil {
aerc.PushError(err.Error())
return
}
var ( var (
path []int path []int
part *models.BodyStructure part *models.BodyStructure
) )
if len(msgInfo.BodyStructure.Parts) != 0 { if len(msg.BodyStructure().Parts) != 0 {
path = lib.FindPlaintext(msgInfo.BodyStructure, path) path = lib.FindPlaintext(msg.BodyStructure(), path)
} }
part, err = msgInfo.BodyStructure.PartAtIndex(path) part, err = msg.BodyStructure().PartAtIndex(path)
if part == nil || err != nil { if part == nil || err != nil {
part = msgInfo.BodyStructure part = msg.BodyStructure()
} }
store.FetchBodyPart(msgInfo.Uid, path, func(reader io.Reader) { msg.FetchBodyPart(path, func(reader io.Reader) {
header := message.Header{} header := message.Header{}
header.SetText( header.SetText(
"Content-Transfer-Encoding", part.Encoding) "Content-Transfer-Encoding", part.Encoding)
@ -173,21 +178,29 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
return return
} }
composer.SetContents(part.Body) composer.SetContents(part.Body)
if md := msg.MessageDetails(); md != nil {
if md.IsEncrypted {
composer.SetEncrypt(md.IsEncrypted)
}
if md.IsSigned {
composer.SetSign(md.IsSigned)
}
}
addTab() addTab()
// add attachements if present // add attachements if present
var mu sync.Mutex var mu sync.Mutex
parts := lib.FindAllNonMultipart(msgInfo.BodyStructure, nil, nil) parts := lib.FindAllNonMultipart(msg.BodyStructure(), nil, nil)
for _, p := range parts { for _, p := range parts {
if lib.EqualParts(p, path) { if lib.EqualParts(p, path) {
continue continue
} }
bs, err := msgInfo.BodyStructure.PartAtIndex(p) bs, err := msg.BodyStructure().PartAtIndex(p)
if err != nil { if err != nil {
acct.Logger().Println("recall: PartAtIndex:", err) acct.Logger().Println("recall: PartAtIndex:", err)
continue continue
} }
store.FetchBodyPart(msgInfo.Uid, p, func(reader io.Reader) { msg.FetchBodyPart(p, func(reader io.Reader) {
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType) mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
name, ok := bs.Params["name"] name, ok := bs.Params["name"]
if !ok { if !ok {
@ -201,5 +214,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}) })
})
return nil return nil
} }