diff options
author | Galen Abell <galen@galenabell.com> | 2020-04-02 09:54:45 -0400 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-04-06 13:15:56 +0200 |
commit | 95fb35b701486057c2aa127e5e94d65ddabeab88 (patch) | |
tree | 379757ca842ca1a6a44e26f9bb61bc0088332ac4 /commands | |
parent | 35402e21d9b75f0d0a3a4efb8b552e1c9a2e6d59 (diff) | |
download | aerc-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.go | 14 |
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 |