aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-05 21:42:45 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-10 20:39:53 +0200
commite19b411e5209bab209fa8d0ee11a0880175ea0e6 (patch)
tree001ffb4db677c8cbc31ea6b87fa2e030fb74da97
parenta293a39454aa04073a4325b90aa4570b31da63b7 (diff)
downloadaerc-e19b411e5209bab209fa8d0ee11a0880175ea0e6.tar.gz
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>
-rw-r--r--commands/msg/recall.go125
1 files changed, 70 insertions, 55 deletions
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 8a70a0a1..b59372a6 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -139,67 +139,82 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
})
}
- // find the main body part and add it to the editor
- // TODO: copy all parts of the message over?
- var (
- path []int
- part *models.BodyStructure
- )
- if len(msgInfo.BodyStructure.Parts) != 0 {
- path = lib.FindPlaintext(msgInfo.BodyStructure, path)
- }
- part, err = msgInfo.BodyStructure.PartAtIndex(path)
- if part == nil || err != nil {
- part = msgInfo.BodyStructure
- }
+ lib.NewMessageStoreView(msgInfo, store, aerc.Crypto, aerc.DecryptKeys,
+ func(msg lib.MessageView, err error) {
+ if err != nil {
+ aerc.PushError(err.Error())
+ return
+ }
- store.FetchBodyPart(msgInfo.Uid, path, func(reader io.Reader) {
- header := message.Header{}
- header.SetText(
- "Content-Transfer-Encoding", part.Encoding)
- header.SetContentType(part.MIMEType, part.Params)
- header.SetText("Content-Description", part.Description)
- entity, err := message.New(header, reader)
- if err != nil {
- aerc.PushError(err.Error())
- addTab()
- return
- }
- mreader := mail.NewReader(entity)
- part, err := mreader.NextPart()
- if err != nil {
- aerc.PushError(err.Error())
- addTab()
- return
- }
- composer.SetContents(part.Body)
- addTab()
-
- // add attachements if present
- var mu sync.Mutex
- parts := lib.FindAllNonMultipart(msgInfo.BodyStructure, nil, nil)
- for _, p := range parts {
- if lib.EqualParts(p, path) {
- continue
+ var (
+ path []int
+ part *models.BodyStructure
+ )
+ if len(msg.BodyStructure().Parts) != 0 {
+ path = lib.FindPlaintext(msg.BodyStructure(), path)
}
- bs, err := msgInfo.BodyStructure.PartAtIndex(p)
- if err != nil {
- acct.Logger().Println("recall: PartAtIndex:", err)
- continue
+ part, err = msg.BodyStructure().PartAtIndex(path)
+ if part == nil || err != nil {
+ part = msg.BodyStructure()
}
- store.FetchBodyPart(msgInfo.Uid, p, func(reader io.Reader) {
- mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
- name, ok := bs.Params["name"]
- if !ok {
- name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
+
+ msg.FetchBodyPart(path, func(reader io.Reader) {
+ header := message.Header{}
+ header.SetText(
+ "Content-Transfer-Encoding", part.Encoding)
+ header.SetContentType(part.MIMEType, part.Params)
+ header.SetText("Content-Description", part.Description)
+ entity, err := message.New(header, reader)
+ if err != nil {
+ aerc.PushError(err.Error())
+ addTab()
+ return
+ }
+ mreader := mail.NewReader(entity)
+ part, err := mreader.NextPart()
+ if err != nil {
+ aerc.PushError(err.Error())
+ addTab()
+ return
}
- mu.Lock()
- composer.AddPartAttachment(name, mime, bs.Params, reader)
- mu.Unlock()
+ 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()
+
+ // add attachements if present
+ var mu sync.Mutex
+ parts := lib.FindAllNonMultipart(msg.BodyStructure(), nil, nil)
+ for _, p := range parts {
+ if lib.EqualParts(p, path) {
+ continue
+ }
+ bs, err := msg.BodyStructure().PartAtIndex(p)
+ if err != nil {
+ acct.Logger().Println("recall: PartAtIndex:", err)
+ continue
+ }
+ msg.FetchBodyPart(p, func(reader io.Reader) {
+ mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
+ name, ok := bs.Params["name"]
+ if !ok {
+ name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
+ }
+ mu.Lock()
+ composer.AddPartAttachment(name, mime, bs.Params, reader)
+ mu.Unlock()
+ })
+ }
+
})
- }
- })
+ })
return nil
}