I can send attachments that have filenames other than ascii to JavaMail, but I cannot upload them. I get java.io.FileNotFoundException specifically for those attachments whose file names contain characters without ascii.
FYI: I use something like messageBodyPart.setFileName(MimeUtility.encodeText(filename[i]))for encoding text and MimeUtility.decodeText(bodyPart.getFileName())for decoding file names without ascii
Is there a workaround for this?
CHANGE
@Bill, that's part of my code that reads investments. I also added properties properties.setProperty ("mail.mime.decodeparameters", "true") and properties.setProperty ("mail.mime.decodefilename", "true") in my code.
if (message[a].getContent() instanceof MimeMultipart) {
Multipart multipart = (Multipart) message[a].getContent();
for (int i = 0; i < multipart.getCount(); i++) {
bodyPart = multipart.getBodyPart(i);
disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT) || (disposition.equals(BodyPart.INLINE)))) {
DataHandler handler = bodyPart.getDataHandler();
String path = bodyPart.getFileName();
String[] str = path.split("/");
String fileName = str[str.length - 1];
String filePath = ReadConfigPropertiesFile.getPropertyValue("server.buildpath");
System.out.println(fileName);
File tempDir = new File(filePath + user);
if (!tempDir.exists()) {
tempDir.mkdir();
}
File saveFile = new File(tempDir + "/" + fileName);
int count = 0;
while (saveFile.exists()) {
count++;
saveFile = new File(tempDir + "/" + count + "_" + fileName);
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveFile));
byte[] buff = new byte[2048];
InputStream is = bodyPart.getInputStream();
int ret = 0;
while ((ret = is.read(buff)) > 0) {
bos.write(buff, 0, ret);
}
bos.close();
is.close();
}else {
}
}
}
FileNotFoundException BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveFile)), , ascii (- ሰላም. pdf). .