I'm finding a way to deal with base64 encoded .eml attachment. I need to parse it to MimeMessage for further process
for (i=0; i<part.getCount(); i++) {
currentPart = (MimePart) part.getBodyPart(i);
if ( file extension is .eml ) {
InputStream input = currentPart.getInputStream();
currentPart = new MimeMessage(null, input);
}
with the above code, I would only get the decoded body of the email content, all header information are missing.
From JavaMail API, getInputStream() and writeTo() would only get/write the content part, so I've tried to use:
for(Enumeration enum = currentPart.getAllHeaderLines(); enum.hasMoreElements();) {
currentPart.addHeaderLine((String)enum.nextElement());
}
I suppose currentPart is a MimeMessage now, but when I try this:
request.setAttribute("part", (MimeMessage) currentPart.getContent());
I would get a ClassCastException
Would anyone give me some suggestion?