aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-04-13 23:30:20 +0200
committerRobin Jarry <robin@jarry.cc>2024-04-14 11:50:15 +0200
commitae3f7419ce1b6d4a81c4f240ff1073ba45f45b52 (patch)
tree14c15315e6875e2abfb77a0c7f590a4fc9f27d48
parentf204c736759f4d6647a50aa94a415545c0d3a8f7 (diff)
downloadaerc-ae3f7419ce1b6d4a81c4f240ff1073ba45f45b52.tar.gz
open: create a file even if filename is empty
Without a filename, aerc tries to open a directory. In this case, create a random filename. Fixes: d99c49de2fc1 ("open: preserve the original filename") Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/msgview/open.go13
1 files changed, 12 insertions, 1 deletions
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