From ae3f7419ce1b6d4a81c4f240ff1073ba45f45b52 Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Sat, 13 Apr 2024 23:30:20 +0200 Subject: 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 Acked-by: Robin Jarry --- commands/msgview/open.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'commands') 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 -- cgit