メールの添付ファイルをutf8で保存する必要があります。このコードを試してみましたが、まだいくつかの文字が欠けています:
public static void main(String args[]) throws Exception {
File emlFile = new File("example.eml");
InputStream source;
source = new FileInputStream(emlFile);
MimeMessage message = new MimeMessage(null, source);
Multipart multipart = (Multipart) message.getContent();
for (int x = 0; x < multipart.getCount(); x++) {
BodyPart bodyPart = multipart.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
System.out.println("Mail have some attachment : ");
DataHandler handler = bodyPart.getDataHandler();
System.out.println("file name : " + handler.getName());
//start reading inpustream from attachment
InputStream is = bodyPart.getInputStream();
File f = new File(bodyPart.getFileName());
OutputStreamWriter sout = new OutputStreamWriter(new FileOutputStream(f), "UTF8");
BufferedWriter buff_out = new BufferedWriter(sout);
int bytesRead;
while ((bytesRead = is.read()) != -1) {
buff_out.write(bytesRead);
}
buff_out.close();
}
}
}