public JasenMessage parse(MimeMessage mm) throws JasenParseException {
try
{
List parts = new LinkedList ();
StandardJasenMessage message = null;
InternetAddress from = null;
try
{
MimeUtils.getParts (parts, mm);
message = new StandardJasenMessage ();
message.setTextPart ((String) MimeUtils.getPartContent (MimeUtils.getFirstPartFromList (parts, MimeType.TEXT_PLAIN, null)));
message.setHtmlPart ((String) MimeUtils.getPartContent (MimeUtils.getFirstPartFromList (parts, MimeType.TEXT_HTML, null)));
from = getFromSafe(mm);
if(from == null) {
throw new JasenParseException("Empty from", ParseErrorType.MALFORMED_MIME);
}
message.setFrom(from);
if(mm.getHeader("x-envelope-sender") != null) {
message.setEnvelopeSender(mm.getHeader("x-envelope-sender")[0]);
}
else
{
message.setEnvelopeSender(message.getFrom().getAddress());
}
// Get attachments
List attachments = MimeUtils.getAllAttachmentParts (parts);
if (attachments != null && attachments.size () > 0)
{
String[] attachmentNames = new String[attachments.size ()];
Iterator i = attachments.iterator ();
int count = 0;
Part p = null;
while (i.hasNext ())
{
p = (Part) i.next ();
try
{
attachmentNames[count] = p.getFileName ();
count++;
}
catch (MessagingException e)
{
// Ignore this
ErrorHandlerBroker.getInstance().getErrorHandler().handleException(e);
}
}
message.setAttachmentNames (attachmentNames);
}
}
catch (ParseException e)
{