aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorGalen Abell <galen@galenabell.com>2020-04-02 09:54:45 -0400
committerReto Brunner <reto@labrat.space>2020-04-06 13:15:56 +0200
commit95fb35b701486057c2aa127e5e94d65ddabeab88 (patch)
tree379757ca842ca1a6a44e26f9bb61bc0088332ac4 /commands
parent35402e21d9b75f0d0a3a4efb8b552e1c9a2e6d59 (diff)
downloadaerc-95fb35b701486057c2aa127e5e94d65ddabeab88.tar.gz
Try to open attachments with correct extension
The temporary file created when opening an attachment is currently saved without an extension, which prevents matching on file ending with xdg-open.
Diffstat (limited to 'commands')
-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 d4eacd4c..44584f98 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