javamail's encoding of the attached file name
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, July 31, 2002 05:50 PM

using outstream i'm saving message object and attached files in the different folder respectively. when saving files, make new filename to avoid overwriting. the moment of reading the message object from the saved files to match the attached file name and the saved file name, i rewrote file name in the message object using part.setFileName() before saving the object in the file. when read the file name, it was encoded. so i did.. but the encoded file name changes into two pieces. please help me. followings are the brief source code and error message. -------------------------------------------------------- source code -------------------------------------------------------- while(file.exists( )   More>>

using outstream i'm saving message object and attached files in the different folder respectively.
when saving files, make new filename to avoid overwriting.
the moment of reading the message object from the saved files to match the attached file name and the saved file name, i rewrote file name in the message object using part.setFileName() before saving the object in the file.
when read the file name, it was encoded. so i did.. but the encoded file name changes into two pieces.
please help me.
followings are the brief source code and error message.
--------------------------------------------------------
source code
--------------------------------------------------------
while(file.exists( )) {
i++;
file = null;
file = new File(cmfolder.getPath( )+"\"+savefolder.getName( )+"\"+name + "-" + i +kind);
}
try{
FileOutputStream fo = new FileOutputStream(file);
InputStream is2 = new BufferedInputStream(is);
int b;
while((b=is2.read( ))!=-1) {
fo.write(b);
}
System.out.println("File : "+filename +" saved");
fo.close( );
is2.close( );
is.close( );
}catch(IOException ioe) {
System.err.println(ioe);
ioe.printStackTrace( );
}
try{
//encoding and setting the changed file name
part.setFileName(MimeUtility.encodeWord(file.getPath(), "iso-2022-jp", "B"));
System.out.println("encoded word : "+(MimeUtility.encodeWord(file.getPath(), "iso-2022-jp", "B")));
//after making new file name//works well
System.out.println("Encoded filename : "+part.getFileName());
---------------------------------------------------------
the result of execution
---------------------------------------------------------
// original file name (file name having japanese and english characters mixed)
saveFile Method filename : =?iso-2022-jp?B?GyRCJTMlXiE8JTklYSE8JWkbKEIoQ29tbWVy
Y2UgTWFpbGVyKS5wcHQ=?=
// result of print using MimeUtility.decodeText(filename) the encoded file name
File : ƒRƒ}[ƒXƒ[ƒ‰(Commerce Mailer).ppt saved
// encoded changed file name splits into two pieces
encoded word : =?iso-2022-jp?B?YzpcQ01cMjAwMi03LTNcGyRCJTMlXiE8JTklYSE8GyhC?=
=?iso-2022-jp?B?GyRCJWkbKEIoQ29tbWVyY2UgTWFpbGVyKS5wcHQ=?=
Encoded filename : =?iso-2022-jp?B?YzpcQ01cMjAwMi03LTNcGyRCJTMlXiE8JTklYSE8GyhC
?=
=?iso-2022-jp?B?GyRCJWkbKEIoQ29tbWVyY2UgTWFpbGVyKS5wcHQ=?=

// split encoding causes parsing problem.
javax.mail.internet.ParseException: Unbalanced quoted string
javax.mail.internet.ParseException: Unbalanced quoted string
at javax.mail.internet.HeaderTokenizer.getNext(HeaderTokenizer.java:292)

at javax.mail.internet.HeaderTokenizer.next(HeaderTokenizer.java:177)
at javax.mail.internet.ParameterList. (ParameterList.java:70)
at javax.mail.internet.ContentDisposition. (ContentDisposition.java
:70)
at javax.mail.internet.MimeBodyPart.getDisposition(MimeBodyPart.java:827
)
at javax.mail.internet.MimeBodyPart.getDisposition(MimeBodyPart.java:241
)
at ReadMessage9.treatMultipart(ReadMessage9.java:171)
at ReadMessage9.showMessage(ReadMessage9.java:142)
at javamailFrame.showMessage(javamailFrame.java:274)
at javamailFrame. (javamailFrame.java:90)
at javamailClass. (javamailClass.java:21)
at StartGUI. (StartGUI.java:35)
at StartGUI.main(StartGUI.java:49)
----------------------------------------------------------
help me please!!!

   <<Less
About | Sitemap | Contact