mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 12:24:38 +03:00
webmail: recognize q/b-word-encoded filenames in attachments in messages
according to the rfc's (2231, and 2047), non-ascii filenames in content-type and content-disposition headers should be encoded like this: Content-Type: text/plain; name*=utf-8''hi%E2%98%BA.txt Content-Disposition: attachment; filename*=utf-8''hi%E2%98%BA.txt and that is what the Go standard library mime.ParseMediaType and mime.FormatMediaType parse and generate. this is what thunderbird sends: Content-Type: text/plain; charset=UTF-8; name="=?UTF-8?B?aGnimLoudHh0?=" Content-Disposition: attachment; filename*=UTF-8''%68%69%E2%98%BA%2E%74%78%74 (thunderbird will also correctly split long filenames over multiple parameters, named "filename*0*", "filename*1*", etc.) this is what gmail sends: Content-Type: text/plain; charset="US-ASCII"; name="=?UTF-8?B?aGnimLoudHh0?=" Content-Disposition: attachment; filename="=?UTF-8?B?aGnimLoudHh0?=" i cannot find where the q/b-word encoded values in "name" and "filename" are allowed. until that time, we try parsing them unless in pedantic mode. we didn't generate correctly encoded filenames yet, this commit also fixes that. for issue #82 by mattfbacon, thanks for reporting!
This commit is contained in:
@ -1786,7 +1786,7 @@ func attachmentTypes(log *mlog.Log, m store.Message, state *msgState) (map[Attac
|
||||
mt := strings.ToLower(a.Part.MediaType + "/" + a.Part.MediaSubType)
|
||||
if t, ok := attachmentMimetypes[mt]; ok {
|
||||
types[t] = true
|
||||
} else if ext := filepath.Ext(a.Part.ContentTypeParams["name"]); ext != "" {
|
||||
} else if ext := filepath.Ext(tryDecodeParam(log, a.Part.ContentTypeParams["name"])); ext != "" {
|
||||
if t, ok := attachmentExtensions[strings.ToLower(ext)]; ok {
|
||||
types[t] = true
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user