about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--commands/msgview/open.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index d4eacd4..44584f9 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -2,8 +2,10 @@ package msgview
 
 import (
 	"errors"
+	"fmt"
 	"io"
 	"io/ioutil"
+	"mime"
 	"os"
 	"time"
 
@@ -35,7 +37,17 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
 
 	store := mv.Store()
 	store.FetchBodyPart(p.Msg.Uid, p.Msg.BodyStructure, p.Index, func(reader io.Reader) {
-		tmpFile, err := ioutil.TempFile(os.TempDir(), "aerc-")
+		extension := ""
+		// try to determine the correct extension based on mimetype
+		if part, err := p.Msg.BodyStructure.PartAtIndex(p.Index); err == nil {
+			mimeType := fmt.Sprintf("%s/%s", part.MIMEType, part.MIMESubType)
+
+			if exts, _ := mime.ExtensionsByType(mimeType); exts != nil && len(exts) > 0 {
+				extension = exts[0]
+			}
+		}
+
+		tmpFile, err := ioutil.TempFile(os.TempDir(), "aerc-*"+extension)
 		if err != nil {
 			aerc.PushError(" " + err.Error())
 			return
p;id=87fa305848a893b1c85472ea394f24486bd478b6'>87fa305 ^
a15ea01 ^
87fa305 ^





1170893 ^

87fa305 ^














a0c2b1c ^

87fa305 ^
87fa305 ^
3b09c07 ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49