use of com.zimbra.cs.mime.Mime.FixedMimeMessage in project zm-mailbox by Zimbra.
the class CalendarItem method decomposeBlob.
/**
* Break up a multipart/digest blob into separate MimeMessages keyed by InvId header value.
* @param digestStream
* @return
* @throws MessagingException
*/
public static Map<Integer, MimeMessage> decomposeBlob(byte[] digestBlob) throws ServiceException {
Map<Integer, MimeMessage> map = new HashMap<Integer, MimeMessage>();
try {
InputStream bais = new SharedByteArrayInputStream(digestBlob);
FixedMimeMessage digestMm = new FixedMimeMessage(JMSession.getSession(), bais);
// It should be multipart/digest.
MimeMultipart mmp;
Object obj = digestMm.getContent();
if (obj instanceof MimeMultipart)
mmp = (MimeMultipart) obj;
else
throw ServiceException.FAILURE("Expected MimeMultipart, but got " + obj.getClass().getName() + ": " + obj.toString(), null);
int numParts = mmp.getCount();
for (int i = 0; i < numParts; i++) {
MimeBodyPart mbp = (MimeBodyPart) mmp.getBodyPart(i);
int invId = 0;
String[] hdrs = mbp.getHeader("invId");
if (hdrs != null && hdrs.length > 0) {
invId = Integer.parseInt(hdrs[0]);
MimeMessage mm;
Object objMbp = mbp.getContent();
if (objMbp instanceof MimeMessage)
mm = (MimeMessage) objMbp;
else
throw ServiceException.FAILURE("Expected MimeMessage, but got " + objMbp.getClass().getName() + ": " + objMbp.toString(), null);
map.put(invId, mm);
}
}
} catch (MessagingException e) {
throw ServiceException.FAILURE("Can't parse calendar item blob", e);
} catch (IOException e) {
throw ServiceException.FAILURE("Can't parse calendar item blob", e);
} catch (NumberFormatException e) {
throw ServiceException.FAILURE("Can't parse calendar item blob", e);
}
return map;
}
Aggregations