Without a filename, aerc tries to open a directory. In this case, create
a random filename.
Fixes: d99c49de2fc12b64a7cd79044a8b042e7e59d02b
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
---
commands/msgview/open.go | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 55d085f6..1361b15e 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -3,6 +3,7 @@ package msgview
import (
"errors"
"io"
+ "mime"
"os"
"path/filepath"
@@ -55,7 +56,17 @@ func (o Open) Execute(args []string) error {
app.PushError(err.Error())
return
}
- tmpFile, err := os.Create(filepath.Join(tmpDir, part.FileName()))
+ filename := part.FileName()
+ var tmpFile *os.File
+ if filename == "" {
+ extension := ""
+ if exts, _ := mime.ExtensionsByType(mimeType); len(exts) > 0 {
+ extension = exts[0]
+ }
+ tmpFile, err = os.CreateTemp(tmpDir, "aerc-*"+extension)
+ } else {
+ tmpFile, err = os.Create(filepath.Join(tmpDir, filename))
+ }
if err != nil {
app.PushError(err.Error())
return
--
2.43.2
Bence Ferdinandy <bence@ferdinandy.com> wrote:
> Without a filename, aerc tries to open a directory. In this case, create
> a random filename.
>
> Fixes: d99c49de2fc12b64a7cd79044a8b042e7e59d02b
> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
> ---
Acked-by: Robin Jarry <robin@jarry.cc>
Applied with sanitation of the Fixes: trailer, thanks.
To git@git.sr.ht:~rjarry/aerc
f204c736759f..ae3f7419ce1b master -> master