开发者

Extracting email attachment filename : Content-Disposition vs Content-type

开发者 https://www.devze.com 2023-02-19 01:04 出处:网络
I am working on a script that will handle email attachments. I see that, most of the time, both content-type and content-disposition headers have the filename, but I have seen cases where only one had

I am working on a script that will handle email attachments. I see that, most of the time, both content-type and content-disposition headers have the filename, but I have seen cases where only one had proper encoding or valid mime header.

Is there a preferred header to use to extract the f开发者_运维百科ile name? If so, which one?


Quoting wikipedia http://en.wikipedia.org/wiki/MIME:

"Many mail user agents also send messages with the file name in the name parameter of the content-type header instead of the filename parameter of the content-disposition header. This practice is discouraged."

So it seems content-disposition is preferred. However as I am using JavaMail, current JavaMail API seems to have only a String getDisposition() method: http://javamail.kenai.com/nonav/javadocs/javax/mail/Part.html#getDisposition(). So you might need to work with the header directly if you are using JavaMail.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号