From 4f2892695e1fdf89274bff434474b5d95e25ef5e Mon Sep 17 00:00:00 2001 From: Leszek CimaƂa Date: Sat, 7 Dec 2019 19:58:12 +0100 Subject: failback to Content-Type filename when encoded Content-Disposition is used Hi! This patch will fix missing filename if it is RFC2231 encoded with charset different then ASCII or UTF8. Example how it looks like in mail: Content-Type: application/pdf; name="=?UTF-8?Q?Opis_przedmiotu_zam=c3=b3wienia_-_za=c5=82=c4=85cznik_nr_1?= =?UTF-8?Q?=2epdf?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0*=iso-8859-2''%4F%70%69%73%20%70%72%7A%65%64%6D%69%6F%74%75%20; filename*1*=%7A%61%6D%F3%77%69%65%6E%69%61%20%2D%20%7A%61%B3%B1%63%7A%6E; filename*2*=%69%6B%20%6E%72%20%31%2E%70%64%66 Yes, this should be forbidden :-). Anyway, best solotion in such cases is to failback to Content-Type name. I am not sure if it is guaranted to be there, but probably it will. Leszek --- widgets/msgviewer.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'widgets') diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 9d71c3e..6de729e 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -319,6 +319,9 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) { 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 += fmt.Sprintf(" (%s)", filename) } ctx.Printf(len(part.index)*2, y+i, style, "%s", name) } -- cgit 1.4.1-2-gfad0