use of com.zimbra.cs.service.mail.ParseMimeMessage.MimeMessageData in project zm-mailbox by Zimbra.
the class SendMsg method handle.
public Element handle(Element request, Map<String, Object> context, QName respQname) throws ServiceException {
try {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
AccountUtil.checkQuotaWhenSendMail(mbox);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
// <m>
Element msgElem = request.getElement(MailConstants.E_MSG);
// check to see whether the entire message has been uploaded under separate cover
String attachId = msgElem.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
boolean needCalendarSentByFixup = request.getAttributeBool(MailConstants.A_NEED_CALENDAR_SENTBY_FIXUP, false);
boolean isCalendarForward = request.getAttributeBool(MailConstants.A_IS_CALENDAR_FORWARD, false);
boolean noSaveToSent = request.getAttributeBool(MailConstants.A_NO_SAVE_TO_SENT, false);
boolean fetchSavedMsg = request.getAttributeBool(MailConstants.A_FETCH_SAVED_MSG, false);
String origId = msgElem.getAttribute(MailConstants.A_ORIG_ID, null);
ItemId iidOrigId = origId == null ? null : new ItemId(origId, zsc);
String replyType = msgElem.getAttribute(MailConstants.A_REPLY_TYPE, MailSender.MSGTYPE_REPLY);
String identityId = msgElem.getAttribute(MailConstants.A_IDENTITY_ID, null);
String dataSourceId = msgElem.getAttribute(MailConstants.A_DATASOURCE_ID, null);
String draftId = msgElem.getAttribute(MailConstants.A_DRAFT_ID, null);
ItemId iidDraft = draftId == null ? null : new ItemId(draftId, zsc);
boolean sendFromDraft = msgElem.getAttributeBool(MailConstants.A_SEND_FROM_DRAFT, false);
SendState state = SendState.NEW;
ItemId savedMsgId = null;
Pair<String, ItemId> sendRecord = null;
// get the "send uid" and check that this isn't a retry of a pending send
String sendUid = request.getAttribute(MailConstants.A_SEND_UID, null);
if (sendUid != null) {
long delay = MAX_IN_FLIGHT_DELAY_MSECS;
do {
if (state == SendState.PENDING) {
try {
delay -= RETRY_CHECK_PERIOD_MSECS;
Thread.sleep(RETRY_CHECK_PERIOD_MSECS);
} catch (InterruptedException ie) {
}
}
Pair<SendState, Pair<String, ItemId>> result = findPendingSend(mbox.getId(), sendUid);
state = result.getFirst();
sendRecord = result.getSecond();
} while (state == SendState.PENDING && delay >= 0);
}
if (state == SendState.SENT) {
// message successfully sent by another thread
savedMsgId = sendRecord.getSecond();
} else if (state == SendState.PENDING) {
// tired of waiting for another thread to complete the send
throw MailServiceException.TRY_AGAIN("message send already in progress: " + sendUid);
} else if (state == SendState.NEW) {
MimeMessageData mimeData = new MimeMessageData();
try {
// holds return data about the MimeMessage
MimeMessage mm;
if (attachId != null) {
mm = parseUploadedMessage(zsc, attachId, mimeData, needCalendarSentByFixup);
} else if (iidDraft != null && sendFromDraft) {
Message msg = mbox.getMessageById(octxt, iidDraft.getId());
mm = msg.getMimeMessage(false);
} else {
mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, null, mimeData);
}
savedMsgId = doSendMessage(octxt, mbox, mm, mimeData.uploads, iidOrigId, replyType, identityId, dataSourceId, noSaveToSent, needCalendarSentByFixup, isCalendarForward);
// a null ItemId makes the send appear to still be PENDING)
if (savedMsgId == null) {
savedMsgId = NO_MESSAGE_SAVED_TO_SENT;
}
// and record it in the table in case the client retries the send
if (sendRecord != null) {
sendRecord.setSecond(savedMsgId);
}
} catch (ServiceException e) {
clearPendingSend(mbox.getId(), sendRecord);
throw e;
} catch (RuntimeException re) {
clearPendingSend(mbox.getId(), sendRecord);
throw re;
} finally {
// purge the messages fetched from other servers.
if (mimeData.fetches != null) {
FileUploadServlet.deleteUploads(mimeData.fetches);
}
}
}
if (iidDraft != null) {
deleteDraft(iidDraft, octxt, mbox, zsc);
}
Element response = zsc.createElement(respQname);
if (savedMsgId != null && savedMsgId != NO_MESSAGE_SAVED_TO_SENT && savedMsgId.getId() > 0) {
if (fetchSavedMsg) {
Message msg = GetMsg.getMsg(octxt, mbox, savedMsgId, false);
ToXML.encodeMessageAsMP(response, ifmt, octxt, msg, null, 0, true, true, null, false, false, LC.mime_encode_missing_blob.booleanValue(), MsgContent.both);
} else {
Element respElement = response.addElement(MailConstants.E_MSG);
respElement.addAttribute(MailConstants.A_ID, ifmt.formatItemId(savedMsgId));
}
} else {
response.addElement(MailConstants.E_MSG);
}
return response;
} finally {
processor = null;
}
}
use of com.zimbra.cs.service.mail.ParseMimeMessage.MimeMessageData in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method sendForwardedMessage.
private MimeMessage sendForwardedMessage(SendMsgRequest req, Message origMsg) throws Exception {
Element reqElt = JaxbUtil.jaxbToElement(req);
Element msgElt = reqElt.getElement(MailConstants.E_MSG);
AuthToken at = AuthProvider.getAuthToken(mbox.getAccount());
ZimbraSoapContext zsc = new ZimbraSoapContext(at, mbox.getAccountId(), SoapProtocol.Soap12, SoapProtocol.Soap12);
return ParseMimeMessage.parseMimeMsgSoap(zsc, null, mbox, msgElt, null, new MimeMessageData());
}
Aggregations