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 /widgets/msgviewer.go | |
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 'widgets/msgviewer.go')
-rw-r--r-- | widgets/msgviewer.go | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 19a28f02..70c079a3 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -230,8 +230,7 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher, if switcher.selected == -1 && pv.part.MIMEType != "multipart" { switcher.selected = i } - mime := strings.ToLower(pv.part.MIMEType) + - "/" + strings.ToLower(pv.part.MIMESubType) + mime := pv.part.FullMIMEType() for idx, m := range conf.Viewer.Alternatives { if m != mime { continue @@ -422,13 +421,9 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) { style = ps.mv.uiConfig.GetStyleSelected(config.STYLE_DEFAULT) } ctx.Fill(0, y+i, ctx.Width(), 1, ' ', style) - name := fmt.Sprintf("%s/%s", - strings.ToLower(part.part.MIMEType), - strings.ToLower(part.part.MIMESubType)) - if filename, ok := part.part.DispositionParams["filename"]; ok { - name += fmt.Sprintf(" (%s)", filename) - } else if filename, ok := part.part.Params["name"]; ok { - // workaround golang not supporting RFC2231 besides ASCII and UTF8 + name := part.part.FullMIMEType() + filename := part.part.FileName() + if filename != "" { name += fmt.Sprintf(" (%s)", filename) } ctx.Printf(len(part.index)*2, y+i, style, "%s", name) @@ -547,8 +542,7 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig, info := msg.MessageInfo() for _, f := range conf.Filters { - mime := strings.ToLower(part.MIMEType) + - "/" + strings.ToLower(part.MIMESubType) + mime := part.FullMIMEType() switch f.FilterType { case config.FILTER_MIMETYPE: if fnmatch.Match(f.Filter, mime, 0) { @@ -813,8 +807,8 @@ func newNoFilterConfigured(pv *PartViewer) *ui.Grid { uiConfig := pv.conf.Ui - noFilter := fmt.Sprintf(`No filter configured for this mimetype ('%s/%s') -What would you like to do?`, pv.part.MIMEType, pv.part.MIMESubType) + noFilter := fmt.Sprintf(`No filter configured for this mimetype ('%s') +What would you like to do?`, pv.part.FullMIMEType()) grid.AddChild(ui.NewText(noFilter, uiConfig.GetStyle(config.STYLE_TITLE))).At(0, 0) for i, action := range actions { |