Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

email

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 file name? If so, which one?

like image 688
Jimmy Avatar asked Nov 28 '25 15:11

Jimmy


1 Answers

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.

like image 60
Feng Avatar answered Dec 01 '25 21:12

Feng