Re: problem with MimeBodyPart.getFileName()
- From: Bill Shannon <bill.shannon@sun.com>
- To: users@javamail.kenai.com
- Subject: Re: problem with MimeBodyPart.getFileName()
- Date: Fri, 31 Jul 2009 10:12:13 -0700
See the mail.mime.decodeparameters System property described in the
javadocs for the javax.mail.internet package.
Oleg Sukhodolsky wrote:
Hi,
while processing mail I want to get file name for every attachment and
so I call getFileName() on every part in multipart message
this works fine (usually), but recently I've got emial which contains
the following Content-Disposition field:
Content-Disposition: attachment;
filename*0*="UTF-8''%D0%B4%D0%B8%D1%80%D0%B5%D0%BA%D1%82 %D0%BF%D1%80%D0%B5"
filename*1*="%D0%B4%D0%BE%D0%BF%D0%BB%D0%B0%D1%82%D0%B0 %D0%9E%D0%A1%D0%9D"
filename*2*=".doc";
As you can see the mailer tries to provide several file name splitted
in several lines.
But this cause the following exception:
javax.mail.internet.ParseException: Expected ';', got "="
at javax.mail.internet.ParameterList.<init>(ParameterList.java:280)
at
javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:96)
at
javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:1123)
at javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:506)
(btw I'm using javamail 1.4.2)
I've debugged the problem a bit and came to simple test which
reproduces the problem:
----
import javax.mail.internet.ParameterList;
import javax.mail.internet.ParseException;
public class mail_test_1 {
public static void main(String[] args) throws ParseException {
System.setProperty("mail.mime.decodetext.strict", "false");
System.setProperty("mail.mime.address.strict", "false");
System.setProperty("mail.mime.parameters.strict", "false");
System.setProperty("mail.mime.base64.ignoreerrors", "true");
final String params =
";\nfilename*0*=\"filename0\"\nfilename*1*=\"filename1\"";
// final String params = ";\r\n
filename*0*=\"UTF-8''%D0%B4%D0%B8%D1%80%D0%B5%D0%BA%D1%82
%D0%BF%D1%80%D0%B5\"\r\n
filename*1*=\"%D0%B4%D0%BE%D0%BF%D0%BB%D0%B0%D1%82%D0%B0
%D0%9E%D0%A1%D0%9D\"\r\n filename*2*=\".doc\";";
new ParameterList(params);
}
}
----
In the test both values of "params" variable cause the same exception.
I understand that the format of Content-Disposition used in this email
is not (let's say) accurate ;) but, by any chance
is there any system property which may help with parsing it? If not,
is it possible to add some code to javamail to
handle such format, or it is against java-mail strategy?
Thanks in advance, Oleg.
| Oleg Sukhodolsky | 07/31/2009 | |
|
Re: problem with MimeBodyPart.getFileName() |
Bill Shannon | 07/31/2009 |





