use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.
the class ZMailbox method getMessageElement.
public Element getMessageElement(Element req, ZOutgoingMessage message, ZMountpoint mountpoint) {
Element m = req.addElement(MailConstants.E_MSG);
String id = message.getOriginalMessageId();
if (mountpoint != null) {
// Use normalized id for a shared folder
int idx = id.indexOf(":");
if (idx != -1) {
id = id.substring(idx + 1);
}
}
if (id != null) {
m.addAttribute(MailConstants.A_ORIG_ID, id);
}
String msgId = message.getMessageId();
if (msgId != null) {
m.addAttribute(MailConstants.A_ID, msgId);
}
String draftId = message.getDraftMessageId();
if (draftId != null) {
m.addAttribute(MailConstants.A_DRAFT_ID, draftId);
}
if (message.getReplyType() != null) {
m.addAttribute(MailConstants.A_REPLY_TYPE, message.getReplyType());
}
if (message.getAddresses() != null) {
for (ZEmailAddress addr : message.getAddresses()) {
if (mountpoint != null && addr.getType().equals(ZEmailAddress.EMAIL_TYPE_FROM)) {
// For on behalf of messages, replace the from: and add a sender:
Element e = m.addElement(MailConstants.E_EMAIL);
e.addAttribute(MailConstants.A_TYPE, ZEmailAddress.EMAIL_TYPE_SENDER);
e.addAttribute(MailConstants.A_ADDRESS, addr.getAddress());
e = m.addElement(MailConstants.E_EMAIL);
e.addAttribute(MailConstants.A_TYPE, ZEmailAddress.EMAIL_TYPE_FROM);
e.addAttribute(MailConstants.A_ADDRESS, mountpoint.getOwnerDisplayName());
} else {
Element e = m.addElement(MailConstants.E_EMAIL);
e.addAttribute(MailConstants.A_TYPE, addr.getType());
e.addAttribute(MailConstants.A_ADDRESS, addr.getAddress());
e.addAttribute(MailConstants.A_PERSONAL, addr.getPersonal());
}
}
}
if (message.getSubject() != null) {
m.addElement(MailConstants.E_SUBJECT).setText(message.getSubject());
}
if (message.getPriority() != null && message.getPriority().length() != 0) {
m.addAttribute(MailConstants.A_FLAGS, message.getPriority());
}
if (message.getInReplyTo() != null) {
m.addElement(MailConstants.E_IN_REPLY_TO).setText(message.getInReplyTo());
}
if (message.getMessagePart() != null) {
message.getMessagePart().toElement(m);
}
Element attach = null;
if (message.getAttachmentUploadId() != null) {
attach = m.addElement(MailConstants.E_ATTACH);
attach.addAttribute(MailConstants.A_ATTACHMENT_ID, message.getAttachmentUploadId());
}
if (message.getMessageIdsToAttach() != null) {
if (attach == null) {
attach = m.addElement(MailConstants.E_ATTACH);
}
for (String mid : message.getMessageIdsToAttach()) {
attach.addElement(MailConstants.E_MSG).addAttribute(MailConstants.A_ID, mid);
}
}
if (message.getDocIdsToAttach() != null) {
if (attach == null) {
attach = m.addElement(MailConstants.E_ATTACH);
}
for (String did : message.getDocIdsToAttach()) {
attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, did);
}
}
if (message.getContactIdsToAttach() != null) {
if (attach == null)
attach = m.addElement(MailConstants.E_ATTACH);
for (String cid : message.getContactIdsToAttach()) {
attach.addElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, cid);
}
}
if (message.getMessagePartsToAttach() != null) {
if (attach == null) {
attach = m.addElement(MailConstants.E_ATTACH);
}
for (AttachedMessagePart part : message.getMessagePartsToAttach()) {
if (part.getContentId() == null || part.getContentId().equals("")) {
attach.addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_MESSAGE_ID, part.getMessageId()).addAttribute(MailConstants.A_PART, part.getPartName());
}
}
}
return m;
}
use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.
the class ZMailbox method handleCreated.
private void handleCreated(Element created) throws ServiceException {
if (created == null) {
return;
}
List<ZCreateEvent> events = null;
List<ZFolder> parentFixup = null;
for (Element e : created.listElements()) {
ZCreateEvent event = null;
if (e.getName().equals(MailConstants.E_CONV)) {
event = new ZCreateConversationEvent(e);
} else if (e.getName().equals(MailConstants.E_MSG)) {
event = new ZCreateMessageEvent(e);
} else if (e.getName().equals(MailConstants.E_CONTACT)) {
event = new ZCreateContactEvent(e);
} else if (e.getName().equals(MailConstants.E_APPOINTMENT)) {
event = new ZCreateAppointmentEvent(e);
} else if (e.getName().equals(MailConstants.E_TASK)) {
event = new ZCreateTaskEvent(e);
} else if (e.getName().equals(MailConstants.E_FOLDER)) {
String parentId = e.getAttribute(MailConstants.A_FOLDER);
ZFolder parent = getFolderById(parentId);
ZFolder child = new ZFolder(e, parent, this);
addItemIdMapping(child);
event = new ZCreateFolderEvent(child);
parentFixup = parentCheck(parentFixup, child, parent);
} else if (e.getName().equals(MailConstants.E_MOUNT)) {
String parentId = e.getAttribute(MailConstants.A_FOLDER);
ZFolder parent = getFolderById(parentId);
ZMountpoint child = new ZMountpoint(e, parent, this);
addItemIdMapping(child);
addRemoteItemIdMapping(child.getCanonicalRemoteId(), child);
parentFixup = parentCheck(parentFixup, child, parent);
event = new ZCreateMountpointEvent(child);
} else if (e.getName().equals(MailConstants.E_SEARCH)) {
String parentId = e.getAttribute(MailConstants.A_FOLDER);
ZFolder parent = getFolderById(parentId);
ZSearchFolder child = new ZSearchFolder(e, parent, this);
addItemIdMapping(child);
event = new ZCreateSearchFolderEvent(child);
parentFixup = parentCheck(parentFixup, child, parent);
} else if (e.getName().equals(MailConstants.E_TAG)) {
event = new ZCreateTagEvent(new ZTag(e, this));
addTag(((ZCreateTagEvent) event).getTag());
}
if (event != null) {
if (events == null) {
events = new ArrayList<ZCreateEvent>();
}
events.add(event);
}
}
if (parentFixup != null) {
for (ZFolder f : parentFixup) {
ZFolder parent = getFolderById(f.getParentId());
if (parent != null) {
parent.addChild(f);
f.setParent(parent);
}
}
}
if (events != null) {
for (ZCreateEvent event : events) {
for (ZEventHandler handler : mHandlers) {
handler.handleCreate(event, this);
}
}
}
}
use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.
the class ZMailbox method getConversation.
/**
*
* @param id conversation id
* @param fetch Whether or not fetch none/first/all messages in conv.
* @return conversation
* @throws ServiceException on error
*/
public ZConversation getConversation(String id, Fetch fetch) throws ServiceException {
Element req = newRequestElement(MailConstants.GET_CONV_REQUEST);
Element convEl = req.addUniqueElement(MailConstants.E_CONV);
convEl.addAttribute(MailConstants.A_ID, id);
if (fetch != null && fetch != Fetch.none && fetch != Fetch.hits) {
// use "1" for "first" for backward compat until DF is updated
convEl.addAttribute(MailConstants.A_FETCH, fetch == Fetch.first ? "1" : fetch.name());
}
return new ZConversation(invoke(req).getElement(MailConstants.E_CONV), this);
}
use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.
the class ZGetInfoResult method getMap.
static Map<String, List<String>> getMap(Element e, String root, String elName) {
Map<String, List<String>> result = new HashMap<String, List<String>>();
Element attrsEl = e.getOptionalElement(root);
if (attrsEl != null) {
for (KeyValuePair pair : attrsEl.listKeyValuePairs(elName, AccountConstants.A_NAME)) {
//StringUtil.addToMultiMap(mAttrs, pair.getKey(), pair.getValue());
String name = pair.getKey();
List<String> list = result.get(name);
if (list == null) {
list = new ArrayList<String>();
result.put(name, list);
}
list.add(pair.getValue());
}
}
return result;
}
use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.
the class ZGrant method toElement.
public void toElement(Element parent) {
Element grant = parent.addElement(MailConstants.E_GRANT);
if (mPermissions != null)
grant.addAttribute(MailConstants.A_RIGHTS, mPermissions);
grant.addAttribute(MailConstants.A_GRANT_TYPE, mGranteeType.name());
if (mGranteeId != null)
grant.addAttribute(MailConstants.A_ZIMBRA_ID, mGranteeId);
if (mGranteeName != null)
grant.addAttribute(MailConstants.A_DISPLAY, mGranteeName);
if (mArgs != null && mArgs.length() > 0) {
if (mGranteeType == GranteeType.key)
grant.addAttribute(MailConstants.A_ACCESSKEY, mArgs);
else
grant.addAttribute(MailConstants.A_ARGS, mArgs);
}
}
Aggregations