mirror of
https://github.com/mjl-/mox.git
synced 2025-07-14 08:14:37 +03:00
add Content-Disposition and Filename to the payload of incoming webhooks
for each message part. The ContentDisposition value is the base value without header key/value parameters. the Filename field is the likely filename of the part. the different email clients encode filenames differently. there is a standard mime mechanism from rfc 2231. and there is the q/b-word-encoding from rfc 2047. instead of letting users of the webhook api deal with those differences, we provide just the parsed filename. for issue #258 by morki, thanks for reporting!
This commit is contained in:
@ -1829,11 +1829,17 @@ func attachmentTypes(log mlog.Log, m store.Message, state *msgState) (map[Attach
|
||||
mt := strings.ToLower(a.Part.MediaType + "/" + a.Part.MediaSubType)
|
||||
if t, ok := attachmentMimetypes[mt]; ok {
|
||||
types[t] = true
|
||||
} else if ext := filepath.Ext(tryDecodeParam(log, a.Part.ContentTypeParams["name"])); ext != "" {
|
||||
continue
|
||||
}
|
||||
_, filename, err := a.Part.DispositionFilename()
|
||||
if err != nil && errors.Is(err, message.ErrParamEncoding) {
|
||||
log.Debugx("parsing disposition/filename", err)
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("reading disposition/filename: %v", err)
|
||||
}
|
||||
if ext := filepath.Ext(filename); ext != "" {
|
||||
if t, ok := attachmentExtensions[strings.ToLower(ext)]; ok {
|
||||
types[t] = true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user