diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-07-05 21:42:44 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-10 20:39:46 +0200 |
commit | a293a39454aa04073a4325b90aa4570b31da63b7 (patch) | |
tree | 55312726a976edf3af4b4340e15c8509f121d499 | |
parent | 4335eeceb39184165eef7b0fc608b5c563e62a72 (diff) | |
download | aerc-a293a39454aa04073a4325b90aa4570b31da63b7.zip |
recall: append attachments
Append attachments to the composer when a message with attachments is
recalled. Before the attachement refactoring in the composer, the
recalled attachments were ignored.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | commands/msg/recall.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 8f21868..8a70a0a 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -1,7 +1,10 @@ package msg import ( + "fmt" "io" + "math/rand" + "sync" "time" "github.com/emersion/go-message" @@ -158,19 +161,44 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { header.SetText("Content-Description", part.Description) entity, err := message.New(header, reader) if err != nil { - // TODO: Do something with the error + aerc.PushError(err.Error()) addTab() return } mreader := mail.NewReader(entity) part, err := mreader.NextPart() if err != nil { - // TODO: Do something with the error + 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 + } + bs, err := msgInfo.BodyStructure.PartAtIndex(p) + if err != nil { + acct.Logger().Println("recall: PartAtIndex:", err) + continue + } + 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()) + } + mu.Lock() + composer.AddPartAttachment(name, mime, bs.Params, reader) + mu.Unlock() + }) + } + }) return nil |