aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-02-02 11:04:41 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-14 23:20:46 +0100
commitd56e949a339d61da2cc7fc20ce0bf19dadf0095d (patch)
tree0518734795a5e7ae88f28729e2c4321e780b19f4 /commands/msg
parent6afc2d54eb27d6762815315a2de996714a5b8b6b (diff)
downloadaerc-d56e949a339d61da2cc7fc20ce0bf19dadf0095d.tar.gz
commands: allow to forward from eml
Forward messages from the message viewer when they are opened with :eml (e.g. rfc822 attachments). Those messages have no associated message store and currently :forward would complain about that. References: https://todo.sr.ht/~rjarry/aerc/227 Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/forward.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 956d5a38..c40f7aa5 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -60,10 +60,6 @@ func (f forward) Execute(args []string) error {
if acct == nil {
return errors.New("No account selected")
}
- store := widget.Store()
- if store == nil {
- return errors.New("Cannot perform action. Messages still loading")
- }
msg, err := widget.SelectedMessage()
if err != nil {
return err
@@ -110,6 +106,13 @@ func (f forward) Execute(args []string) error {
return composer, nil
}
+ mv, isMsgViewer := widget.(*app.MessageViewer)
+ store := widget.Store()
+ noStore := store == nil
+ if noStore && !isMsgViewer {
+ return errors.New("Cannot perform action. Messages still loading")
+ }
+
if f.AttachFull {
tmpDir, err := os.MkdirTemp("", "aerc-tmp-attachment")
if err != nil {
@@ -117,7 +120,23 @@ func (f forward) Execute(args []string) error {
}
tmpFileName := path.Join(tmpDir,
strings.ReplaceAll(fmt.Sprintf("%s.eml", msg.Envelope.Subject), "/", "-"))
- store.FetchFull([]uint32{msg.Uid}, func(fm *types.FullMessage) {
+
+ var fetchFull func(func(io.Reader))
+
+ if isMsgViewer {
+ fetchFull = mv.MessageView().FetchFull
+ } else {
+ fetchFull = func(cb func(io.Reader)) {
+ store.FetchFull([]uint32{msg.Uid}, func(fm *types.FullMessage) {
+ if fm == nil || (fm != nil && fm.Content == nil) {
+ return
+ }
+ cb(fm.Content.Reader)
+ })
+ }
+ }
+
+ fetchFull(func(r io.Reader) {
tmpFile, err := os.Create(tmpFileName)
if err != nil {
log.Warnf("failed to create temporary attachment: %v", err)
@@ -129,7 +148,7 @@ func (f forward) Execute(args []string) error {
}
defer tmpFile.Close()
- _, err = io.Copy(tmpFile, fm.Content.Reader)
+ _, err = io.Copy(tmpFile, r)
if err != nil {
log.Warnf("failed to write to tmpfile: %v", err)
return
@@ -150,7 +169,6 @@ func (f forward) Execute(args []string) error {
var fetchBodyPart func([]int, func(io.Reader))
- mv, isMsgViewer := widget.(*app.MessageViewer)
if isMsgViewer {
fetchBodyPart = mv.MessageView().FetchBodyPart
} else {