Неправильное имя прикрепленного файла в javax.mailJAVA

Программисты JAVA общаются здесь
Anonymous
Неправильное имя прикрепленного файла в javax.mail

Сообщение Anonymous »

У меня есть приложение Javax.mail, которое принимает электронные письма и находит текст в прикрепленных файлах pdf и docx. Если имя файла содержит символы utf-8, оно выглядит так:
=?utf-8?Q?Sz=C3=A1mla.docx?=
В функции оно получено из: String fileName = part.getFileName();

Код: Выделить всё

private boolean findInAttachment(Message message, String filterText) throws MessagingException, IOException, Exception {
boolean attachContains = false;

if(message.getContentType().contains("multipart")) {
Multipart multiPart = (Multipart) message.getContent();
int numberOfParts = multiPart.getCount();

for(int partCount = 0; partCount < numberOfParts; partCount++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
if(Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
// this part is attachment
String fileName = part.getFileName();
String fullName = AnalyzeEmailsApp.getUserDir() + File.separator + fileName;

if(isFileExtension(fileName, "docx")) {
part.saveFile(fullName);
attachContains = findInDocx(fullName, filterText);
DeleteAttachmentFile(fullName);
} else if(isFileExtension(fileName, "pdf")) {
part.saveFile(fullName);
attachContains = findInPdf(fullName, filterText);
DeleteAttachmentFile(fullName);
}
} // if
} // for
} // if

return attachContains;
}
Как получить правильное имя файла (Számla.docx)?

Подробнее здесь: https://stackoverflow.com/questions/798 ... javax-mail

Вернуться в «JAVA»