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>
This commit is contained in:
Robin Jarry 2022-10-12 23:52:45 +02:00
parent a4b80bcc8b
commit 9bd2e0c84f
8 changed files with 30 additions and 28 deletions
commands/msgview

View file

@ -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]
}