users@javamail.java.net

Re: problem with MimeBodyPart.getFileName()

From: Oleg Sukhodolsky <oleg.sukhodolsky_at_gmail.com>
Date: Sat, 1 Aug 2009 08:06:34 +0400

Hi Bill,

On Fri, Jul 31, 2009 at 9:12 PM, Bill Shannon<bill.shannon_at_sun.com> wrote:
> See the mail.mime.decodeparameters System property described in the
> javadocs for the javax.mail.internet package.

as you can see the first variant of params value in the test has no
non-ASCII symbols, but it still doesn't work.
So, I think this is why mail.mime.decodeparameters doesn't help me :(
Do you have any other magic property
to share with me ;) Or I have to try to implement parsing of such
filename format myself?

BTW at http://java.sun.com/products/javamail/javadocs/javax/mail/internet/package-summary.html
description for this property says
"If set to "true", non-ASCII parameters in a ParameterList, e.g., in a
Content-Type header, will be encoded as specified by RFC 2231. The
default is false."
I wonder if it really means that java mail will ENCODE the param value
and I will see it encoded? Why someone may need this?

Oleg.

>
>
> 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.
>
>