use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class RemoveAttachments method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element msgElem = request.getElement(MailConstants.E_MSG);
ItemId iid = new ItemId(msgElem.getAttribute(MailConstants.A_ID), zsc);
Collection<String> parts = sortPartIds(msgElem.getAttribute(MailConstants.A_PART));
Message msg = mbox.getMessageById(octxt, iid.getId());
InputStream is = null;
try {
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is = StoreManager.getInstance().getContent(msg.getBlob().getLocalBlob()));
// do not allow removing attachments of encrypted/pkcs7-signed messages
if (Mime.isEncrypted(mm.getContentType()) || Mime.isPKCS7Signed(mm.getContentType())) {
throw ServiceException.OPERATION_DENIED("not allowed to remove attachments of encrypted/pkcs7-signed message");
}
for (String part : parts) stripPart(mm, part);
mm.saveChanges();
ParsedMessage pm = new ParsedMessage(mm, msg.getDate(), mbox.attachmentsIndexingEnabled());
msg = removeAttachmentOperation(mbox, octxt, pm, msg);
} catch (IOException ioe) {
throw ServiceException.FAILURE("error reading existing message blob", ioe);
} catch (MessagingException me) {
throw ServiceException.FAILURE("error reading existing message blob", me);
} finally {
ByteUtil.closeStream(is);
}
Element response = zsc.createElement(MailConstants.REMOVE_ATTACHMENTS_RESPONSE);
// FIXME: inefficient -- this recalculates the MimeMessage (but RemoveAttachments is called rarely)
ToXML.encodeMessageAsMP(response, ifmt, octxt, msg, null, -1, true, true, null, true, false, LC.mime_encode_missing_blob.booleanValue());
return response;
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SaveDraft method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element msgElem = request.getElement(MailConstants.E_MSG);
int id = (int) msgElem.getAttributeLong(MailConstants.A_ID, Mailbox.ID_AUTO_INCREMENT);
String originalId = msgElem.getAttribute(MailConstants.A_ORIG_ID, null);
ItemId iidOrigid = originalId == null ? null : new ItemId(originalId, zsc);
String replyType = msgElem.getAttribute(MailConstants.A_REPLY_TYPE, null);
String identity = msgElem.getAttribute(MailConstants.A_IDENTITY_ID, null);
String account = msgElem.getAttribute(MailConstants.A_FOR_ACCOUNT, null);
// allow the caller to update the draft's metadata at the same time as they save the draft
String folderId = msgElem.getAttribute(MailConstants.A_FOLDER, null);
ItemId iidFolder = new ItemId(folderId == null ? "-1" : folderId, zsc);
if (!iidFolder.belongsTo(mbox)) {
throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
} else if (folderId != null && iidFolder.getId() <= 0) {
throw MailServiceException.NO_SUCH_FOLDER(iidFolder.getId());
}
String flags = msgElem.getAttribute(MailConstants.A_FLAGS, null);
String[] tags = TagUtil.parseTags(msgElem, mbox, octxt);
Color color = ItemAction.getColor(msgElem);
// check to see whether the entire message has been uploaded under separate cover
String attachment = msgElem.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
long autoSendTime = new Long(msgElem.getAttribute(MailConstants.A_AUTO_SEND_TIME, "0"));
ParseMimeMessage.MimeMessageData mimeData = new ParseMimeMessage.MimeMessageData();
Message msg;
try {
MimeMessage mm;
if (attachment != null) {
mm = SendMsg.parseUploadedMessage(zsc, attachment, mimeData);
} else {
mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, null, mimeData, true);
}
long date = System.currentTimeMillis();
try {
Date d = new Date();
mm.setSentDate(d);
date = d.getTime();
} catch (Exception ignored) {
}
try {
mm.saveChanges();
} catch (MessagingException me) {
throw ServiceException.FAILURE("completing MIME message object", me);
}
ParsedMessage pm = new ParsedMessage(mm, date, mbox.attachmentsIndexingEnabled());
if (autoSendTime != 0) {
AccountUtil.checkQuotaWhenSendMail(mbox);
}
String origid = iidOrigid == null ? null : iidOrigid.toString(account == null ? mbox.getAccountId() : account);
msg = mbox.saveDraft(octxt, pm, id, origid, replyType, identity, account, autoSendTime);
} catch (IOException e) {
throw ServiceException.FAILURE("IOException while saving draft", e);
} finally {
// purge the messages fetched from other servers.
if (mimeData.fetches != null) {
FileUploadServlet.deleteUploads(mimeData.fetches);
}
}
// we can now purge the uploaded attachments
if (mimeData.uploads != null) {
FileUploadServlet.deleteUploads(mimeData.uploads);
}
// try to set the metadata on the new/revised draft
if (folderId != null || flags != null || !ArrayUtil.isEmpty(tags) || color != null) {
try {
// best not to fail if there's an error here...
ItemActionHelper.UPDATE(octxt, mbox, zsc.getResponseProtocol(), Arrays.asList(msg.getId()), MailItem.Type.MESSAGE, null, null, iidFolder, flags, tags, color);
// and make sure the Message object reflects post-update reality
msg = mbox.getMessageById(octxt, msg.getId());
} catch (ServiceException e) {
ZimbraLog.soap.warn("error setting metadata for draft " + msg.getId() + "; skipping that operation", e);
}
}
if (schedulesAutoSendTask()) {
if (id != Mailbox.ID_AUTO_INCREMENT) {
// Cancel any existing auto-send task for this draft
AutoSendDraftTask.cancelTask(id, mbox.getId());
}
if (autoSendTime != 0) {
// schedule a new auto-send-draft task
AutoSendDraftTask.scheduleTask(msg.getId(), mbox.getId(), autoSendTime);
}
}
return generateResponse(zsc, ifmt, octxt, mbox, msg);
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SearchResponse method doConvMsgHit.
private Element doConvMsgHit(Element el, Message msg, long numMsgsInConv) {
// Folder ID useful when undoing a move to different folder, also determining whether in junk/trash
ConversationMsgHitInfo cMsgHit = ConversationMsgHitInfo.fromIdAndFolderId(ifmt.formatItemId(msg), ifmt.formatItemId(new ItemId(msg.getMailbox().getAccountId(), msg.getFolderId())));
// if it's a 1-message conversation, hand back size for the lone message
if (numMsgsInConv == 1) {
cMsgHit.setSize(msg.getSize());
}
if (msg.isDraft() && msg.getDraftAutoSendTime() != 0) {
cMsgHit.setAutoSendTime(msg.getDraftAutoSendTime());
}
if (!msg.getFlagString().equalsIgnoreCase("")) {
cMsgHit.setFlags(msg.getFlagString());
}
cMsgHit.setDate(msg.getDate());
cMsgHit.toElement(el);
return el;
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SearchResponse method add.
/* We need to pass in a boolean signifying whether to expand the message or not (bug 75990)
*/
void add(ZimbraHit hit, boolean expandMsg) throws ServiceException {
Element el = null;
if (params.getFetchMode() == SearchParams.Fetch.IDS) {
if (hit instanceof ConversationHit) {
// need to expand the contained messages
el = element.addElement("hit");
el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
} else {
el = element.addElement("hit");
el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
}
} else if (hit instanceof ProxiedHit) {
element.addElement(((ProxiedHit) hit).getElement().detach());
size++;
return;
} else {
if (hit instanceof ConversationHit) {
el = add((ConversationHit) hit);
} else if (hit instanceof MessageHit) {
el = add((MessageHit) hit, expandMsg);
} else if (hit instanceof MessagePartHit) {
el = add((MessagePartHit) hit);
} else if (hit instanceof ContactHit) {
el = add((ContactHit) hit);
} else if (hit instanceof NoteHit) {
el = add((NoteHit) hit);
} else if (hit instanceof CalendarItemHit) {
// el could be null
el = add((CalendarItemHit) hit);
} else if (hit instanceof DocumentHit) {
el = add((DocumentHit) hit);
} else {
LOG.error("Got an unknown hit type putting search hits: " + hit);
return;
}
}
if (el != null) {
size++;
el.addAttribute(MailConstants.A_SORT_FIELD, hit.getSortField(sortOrder).toString());
if (includeMailbox) {
el.addAttribute(MailConstants.A_ID, new ItemId(hit.getAcctIdStr(), hit.getItemId()).toString());
}
}
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SendDeliveryReport method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
int msgid = new ItemId(request.getAttribute(MailConstants.A_MESSAGE_ID), zsc).getId();
Message msg = mbox.getMessageById(octxt, msgid);
// sending a read receipt requires write access to the message
if ((mbox.getEffectivePermissions(octxt, msgid, MailItem.Type.MESSAGE) & ACL.RIGHT_WRITE) == 0) {
throw ServiceException.PERM_DENIED("you do not have sufficient permissions on the message");
}
// first, send the notification
sendReport(getSenderAccount(zsc), msg, false, zsc.getRequestIP(), zsc.getUserAgent());
// then mark the message as \Notified
mbox.alterTag(octxt, msgid, MailItem.Type.MESSAGE, Flag.FlagInfo.NOTIFIED, true, null);
Element response = zsc.createElement(MailConstants.SEND_REPORT_RESPONSE);
return response;
}
Aggregations