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>
This commit is contained in:
parent
4335eeceb3
commit
a293a39454
1 changed files with 30 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue