Element response = lc.createElement(MailService.SEND_MSG_RESPONSE);
SendState state = SendState.NEW; int savedMsgId = -1; Pair<String, Integer> sendRecord = null;   String sendUid = request.getAttribute(MailService.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, Integer>> result = findPendingSend(mbox.getId(), sendUid); state = result.getFirst(); sendRecord = result.getSecond(); } while (state == SendState.PENDING && delay >= 0); }  if (state == SendState.SENT) {  savedMsgId = sendRecord.getSecond(); } else if (state == SendState.PENDING) {  throw MailServiceException.TRY_AGAIN("message send already in progress: " + sendUid); } else if (state == SendState.NEW) { try {  MimeMessageData mimeData = new MimeMessageData(); MimeMessage mm; if (attachId != null) { mm = parseUploadedMessage(zsc, attachId, mimeData); } else { mm = ParseMimeMessage.parseMimeMsgSoap(zsc, mbox, msgElem, null, mimeData); }   SendMsgOperation op = new SendMsgOperation(session, octxt, mbox, Requester.SOAP, saveToSent, mm, mimeData.newContacts, mimeData.uploads, origId, replyType, false, needCalendarSentByFixup); op.schedule(); savedMsgId = op.getMsgId();   if (sendRecord != null) sendRecord.setSecond(savedMsgId); } catch (ServiceException e) { clearPendingSend(mbox.getId(), sendRecord); throw e; } catch (RuntimeException re) { clearPendingSend(mbox.getId(), sendRecord); throw re; } }  Element response = zsc.createElement(MailService.SEND_MSG_RESPONSE);
    public Element handle(Element request, Map<String, Object> context) throws ServiceException {        ZimbraSoapContext lc = getZimbraSoapContext(context);        Account acct = getRequestedAccount(lc);        Mailbox mbox = getRequestedMailbox(lc);        OperationContext octxt = lc.getOperationContext();        Session session = getSession(context);        mLog.info("<SendMsg> " + lc.toString());        boolean needCalendarSentByFixup =            request.getAttributeBool(MailService.A_NEED_CALENDAR_SENTBY_FIXUP, false);        // <M>        Element msgElem = request.getElement(MailService.E_MSG);        boolean saveToSent = acct.saveToSent();        // check to see whether the entire message has been uploaded under separate cover        String attachment = msgElem.getAttribute(MailService.A_ATTACHMENT_ID, null);        // holds return data about the MimeMessage        MimeMessageData mimeData = new MimeMessageData();        MimeMessage mm;        if (attachment != null) {            mm = parseUploadedMessage(lc, attachment, mimeData);        } else {            mm = ParseMimeMessage.parseMimeMsgSoap(lc, mbox, msgElem, null, mimeData);        }        int origId = (int) msgElem.getAttributeLong(MailService.A_ORIG_ID, 0);        String replyType = msgElem.getAttribute(MailService.A_REPLY_TYPE, MailSender.MSGTYPE_REPLY);        SendMsgOperation op = new SendMsgOperation(session, octxt, mbox, Requester.SOAP,                    saveToSent, mm,                    mimeData.newContacts, mimeData.uploads,                    origId, replyType, false, needCalendarSentByFixup);        op.schedule();        int msgId = op.getMsgId();        Element response = lc.createElement(MailService.SEND_MSG_RESPONSE);        Element respElement = response.addElement(MailService.E_MSG);        if (saveToSent && msgId > 0)            respElement.addAttribute(MailService.A_ID, msgId);        return response;    }