diff options
author | Robin Jarry <robin@jarry.cc> | 2022-10-12 23:52:45 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-16 11:35:24 +0200 |
commit | 9bd2e0c84fef66007bcab027883c01414b99b77c (patch) | |
tree | 515414d5d8d95f2360bd1e9db31ef7fdca7cdd86 /commands | |
parent | a4b80bcc8b4427016bfb0c2924ffaa9f8b90916d (diff) | |
download | aerc-9bd2e0c84fef66007bcab027883c01414b99b77c.tar.gz |
msgpart: factorize mime type and filename construction
Reduce code duplication.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/msg/forward.go | 2 | ||||
-rw-r--r-- | commands/msg/recall.go | 2 | ||||
-rw-r--r-- | commands/msg/reply.go | 2 | ||||
-rw-r--r-- | commands/msgview/open.go | 3 | ||||
-rw-r--r-- | commands/msgview/save.go | 7 |
5 files changed, 5 insertions, 11 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go index 4adfd128..78c24380 100644 --- a/commands/msg/forward.go +++ b/commands/msg/forward.go @@ -198,7 +198,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error { continue } store.FetchBodyPart(msg.Uid, p, func(reader io.Reader) { - mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType) + mime := bs.FullMIMEType() params := lib.SetUtf8Charset(bs.Params) name, ok := params["name"] if !ok { diff --git a/commands/msg/recall.go b/commands/msg/recall.go index c5585b05..866266f5 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -204,7 +204,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { continue } msg.FetchBodyPart(p, func(reader io.Reader) { - mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType) + mime := bs.FullMIMEType() params := lib.SetUtf8Charset(bs.Params) name, ok := params["name"] if !ok { diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 1baef838..f577a963 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -326,7 +326,7 @@ func addMimeType(msg *models.MessageInfo, part []int, if err != nil { return err } - orig.MIMEType = fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType) + orig.MIMEType = bs.FullMIMEType() return nil } diff --git a/commands/msgview/open.go b/commands/msgview/open.go index bb22026a..13bd4b11 100644 --- a/commands/msgview/open.go +++ b/commands/msgview/open.go @@ -1,7 +1,6 @@ package msgview import ( - "fmt" "io" "mime" "os" @@ -52,7 +51,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error { // try to determine the correct extension based on mimetype if part, err := mv.MessageView().BodyStructure().PartAtIndex(p.Index); err == nil { - mimeType = fmt.Sprintf("%s/%s", part.MIMEType, part.MIMESubType) + mimeType = part.FullMIMEType() if exts, _ := mime.ExtensionsByType(mimeType); len(exts) > 0 { extension = exts[0] } diff --git a/commands/msgview/save.go b/commands/msgview/save.go index 993f4278..4820ec0f 100644 --- a/commands/msgview/save.go +++ b/commands/msgview/save.go @@ -215,12 +215,7 @@ func isAbsPath(path string) bool { // generateFilename tries to get the filename from the given part. // if that fails it will fallback to a generated one based on the date func generateFilename(part *models.BodyStructure) string { - var filename string - if fn, ok := part.DispositionParams["filename"]; ok { - filename = fn - } else if fn, ok := part.Params["name"]; ok { - filename = fn - } + filename := part.FileName() // Some MUAs send attachments with names like /some/stupid/idea/happy.jpeg // Assuming non hostile intent it does make sense to use just the last // portion of the pathname as the filename for saving it. |