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,7 +1,10 @@
|
||||||
package msg
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
|
@ -158,19 +161,44 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
header.SetText("Content-Description", part.Description)
|
header.SetText("Content-Description", part.Description)
|
||||||
entity, err := message.New(header, reader)
|
entity, err := message.New(header, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Do something with the error
|
aerc.PushError(err.Error())
|
||||||
addTab()
|
addTab()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mreader := mail.NewReader(entity)
|
mreader := mail.NewReader(entity)
|
||||||
part, err := mreader.NextPart()
|
part, err := mreader.NextPart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Do something with the error
|
aerc.PushError(err.Error())
|
||||||
addTab()
|
addTab()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
composer.SetContents(part.Body)
|
composer.SetContents(part.Body)
|
||||||
addTab()
|
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
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue