FetchBodyPart doesn't need the parent body structure
This commit is contained in:
parent
bae678e8f2
commit
13a6a3fa71
|
@ -138,7 +138,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
|
|
||||||
// TODO: something more intelligent than fetching the 1st part
|
// TODO: something more intelligent than fetching the 1st part
|
||||||
// TODO: add attachments!
|
// TODO: add attachments!
|
||||||
store.FetchBodyPart(msg.Uid, msg.BodyStructure, []int{1}, func(reader io.Reader) {
|
store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(reader)
|
buf.ReadFrom(reader)
|
||||||
original.Text = buf.String()
|
original.Text = buf.String()
|
||||||
|
|
|
@ -127,7 +127,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
} else if pipePart {
|
} else if pipePart {
|
||||||
p := provider.SelectedMessagePart()
|
p := provider.SelectedMessagePart()
|
||||||
store := provider.Store()
|
store := provider.Store()
|
||||||
store.FetchBodyPart(p.Msg.Uid, p.Msg.BodyStructure, p.Index, func(reader io.Reader) {
|
store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
|
||||||
if background {
|
if background {
|
||||||
doExec(reader)
|
doExec(reader)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
path = []int{1}
|
path = []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
store.FetchBodyPart(msgInfo.Uid, part, path, func(reader io.Reader) {
|
store.FetchBodyPart(msgInfo.Uid, 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)
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
template = aerc.Config().Templates.QuotedReply
|
template = aerc.Config().Templates.QuotedReply
|
||||||
}
|
}
|
||||||
|
|
||||||
store.FetchBodyPart(msg.Uid, msg.BodyStructure, []int{1}, func(reader io.Reader) {
|
store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(reader)
|
buf.ReadFrom(reader)
|
||||||
original.Text = buf.String()
|
original.Text = buf.String()
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
p := mv.SelectedMessagePart()
|
p := mv.SelectedMessagePart()
|
||||||
|
|
||||||
store := mv.Store()
|
store := mv.Store()
|
||||||
store.FetchBodyPart(p.Msg.Uid, p.Msg.BodyStructure, p.Index, func(reader io.Reader) {
|
store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
|
||||||
extension := ""
|
extension := ""
|
||||||
// try to determine the correct extension based on mimetype
|
// try to determine the correct extension based on mimetype
|
||||||
if part, err := p.Msg.BodyStructure.PartAtIndex(p.Index); err == nil {
|
if part, err := p.Msg.BodyStructure.PartAtIndex(p.Index); err == nil {
|
||||||
|
|
|
@ -109,21 +109,20 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
|
|
||||||
ch := make(chan error, 1)
|
ch := make(chan error, 1)
|
||||||
store := mv.Store()
|
store := mv.Store()
|
||||||
store.FetchBodyPart(
|
store.FetchBodyPart(pi.Msg.Uid, pi.Index, func(reader io.Reader) {
|
||||||
pi.Msg.Uid, pi.Msg.BodyStructure, pi.Index, func(reader io.Reader) {
|
f, err := os.Create(path)
|
||||||
f, err := os.Create(path)
|
if err != nil {
|
||||||
if err != nil {
|
ch <- err
|
||||||
ch <- err
|
return
|
||||||
return
|
}
|
||||||
}
|
defer f.Close()
|
||||||
defer f.Close()
|
_, err = io.Copy(f, reader)
|
||||||
_, err = io.Copy(f, reader)
|
if err != nil {
|
||||||
if err != nil {
|
ch <- err
|
||||||
ch <- err
|
return
|
||||||
return
|
}
|
||||||
}
|
ch <- nil
|
||||||
ch <- nil
|
})
|
||||||
})
|
|
||||||
|
|
||||||
// we need to wait for the callback prior to displaying a result
|
// we need to wait for the callback prior to displaying a result
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
@ -28,8 +28,7 @@ type MessageView interface {
|
||||||
Store() *MessageStore
|
Store() *MessageStore
|
||||||
|
|
||||||
// Fetches a specific body part for this message
|
// Fetches a specific body part for this message
|
||||||
FetchBodyPart(parent *models.BodyStructure,
|
FetchBodyPart(part []int, cb func(io.Reader))
|
||||||
part []int, cb func(io.Reader))
|
|
||||||
|
|
||||||
PGPDetails() *openpgp.MessageDetails
|
PGPDetails() *openpgp.MessageDetails
|
||||||
}
|
}
|
||||||
|
@ -110,11 +109,10 @@ func (msv *MessageStoreView) PGPDetails() *openpgp.MessageDetails {
|
||||||
return msv.details
|
return msv.details
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msv *MessageStoreView) FetchBodyPart(parent *models.BodyStructure,
|
func (msv *MessageStoreView) FetchBodyPart(part []int, cb func(io.Reader)) {
|
||||||
part []int, cb func(io.Reader)) {
|
|
||||||
|
|
||||||
if msv.message == nil {
|
if msv.message == nil {
|
||||||
msv.messageStore.FetchBodyPart(msv.messageInfo.Uid, parent, part, cb)
|
msv.messageStore.FetchBodyPart(msv.messageInfo.Uid, part, cb)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,7 @@ func (store *MessageStore) FetchFull(uids []uint32, cb func(*types.FullMessage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MessageStore) FetchBodyPart(
|
func (store *MessageStore) FetchBodyPart(uid uint32, part []int, cb func(io.Reader)) {
|
||||||
uid uint32, parent *models.BodyStructure, part []int, cb func(io.Reader)) {
|
|
||||||
|
|
||||||
store.worker.PostAction(&types.FetchMessageBodyPart{
|
store.worker.PostAction(&types.FetchMessageBodyPart{
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
|
|
|
@ -653,8 +653,7 @@ func (pv *PartViewer) Draw(ctx *ui.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !pv.fetched {
|
if !pv.fetched {
|
||||||
pv.msg.FetchBodyPart(pv.msg.BodyStructure(),
|
pv.msg.FetchBodyPart(pv.index, pv.SetSource)
|
||||||
pv.index, pv.SetSource)
|
|
||||||
pv.fetched = true
|
pv.fetched = true
|
||||||
}
|
}
|
||||||
if pv.err != nil {
|
if pv.err != nil {
|
||||||
|
|
Loading…
Reference in New Issue