use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class CreateContact 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);
boolean verbose = request.getAttributeBool(MailConstants.A_VERBOSE, true);
Element cn = request.getElement(MailConstants.E_CONTACT);
ItemId iidFolder = new ItemId(cn.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER), zsc);
String[] tags = TagUtil.parseTags(cn, mbox, octxt);
Element vcard = cn.getOptionalElement(MailConstants.E_VCARD);
List<ParsedContact> pclist;
if (vcard != null) {
pclist = parseAttachedVCard(zsc, octxt, mbox, vcard);
} else {
pclist = new ArrayList<ParsedContact>(1);
Pair<Map<String, Object>, List<Attachment>> cdata = parseContact(cn, zsc, octxt);
pclist.add(new ParsedContact(cdata.getFirst(), cdata.getSecond()));
}
if (needToMigrateDlist(zsc)) {
for (ParsedContact pc : pclist) {
migrateFromDlist(pc);
}
}
List<Contact> contacts = createContacts(octxt, mbox, iidFolder, pclist, tags);
Contact con = null;
if (contacts.size() > 0)
con = contacts.get(0);
Element response = zsc.createElement(MailConstants.CREATE_CONTACT_RESPONSE);
if (con != null) {
if (verbose)
ToXML.encodeContact(response, ifmt, octxt, con, true, null);
else
response.addElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, con.getId());
}
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class GetConv 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 econv = request.getElement(MailConstants.E_CONV);
ItemId iid = new ItemId(econv.getAttribute(MailConstants.A_ID), zsc);
SearchParams params = new SearchParams();
params.setInlineRule(ExpandResults.valueOf(econv.getAttribute(MailConstants.A_FETCH, null), zsc));
if (params.getInlineRule() != ExpandResults.NONE) {
params.setWantHtml(econv.getAttributeBool(MailConstants.A_WANT_HTML, false));
params.setMaxInlinedLength((int) econv.getAttributeLong(MailConstants.A_MAX_INLINED_LENGTH, -1));
params.setWantExpandGroupInfo(econv.getAttributeBool(MailConstants.A_NEED_EXP, false));
for (Element eHdr : econv.listElements(MailConstants.A_HEADER)) {
params.addInlinedHeader(eHdr.getAttribute(MailConstants.A_ATTRIBUTE_NAME));
}
}
Conversation conv = mbox.getConversationById(octxt, iid.getId());
if (conv == null) {
throw MailServiceException.NO_SUCH_CONV(iid.getId());
}
List<Message> msgs = mbox.getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_ASC, -1);
if (msgs.isEmpty() && zsc.isDelegatedRequest()) {
throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
}
Element response = zsc.createElement(MailConstants.GET_CONV_RESPONSE);
ToXML.encodeConversation(response, ifmt, octxt, conv, msgs, params);
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class DismissCalendarItemAlarm method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
String acctId = mbox.getAccountId();
Account authAcct = getAuthenticatedAccount(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element response = getResponseElement(zsc);
for (String calItemElement : sCalItemElems) {
for (Iterator<Element> iter = request.elementIterator(calItemElement); iter.hasNext(); ) {
Element calItemElem = iter.next();
ItemId iid = new ItemId(calItemElem.getAttribute(MailConstants.A_ID), zsc);
long dismissedAt = calItemElem.getAttributeLong(MailConstants.A_CAL_ALARM_DISMISSED_AT);
// trace logging
ZimbraLog.calendar.info("<DismissCalendarItemAlarm> id=%s, at=%d", iid.toString(), dismissedAt);
// mailbox for this calendar item; not necessarily same as requested mailbox
Mailbox ciMbox = null;
String ciAcctId = iid.getAccountId();
if (ciAcctId == null || ciAcctId.equals(acctId)) {
ciMbox = mbox;
} else {
// Let's see if the account is a Desktop account.
if (AccountUtil.isZDesktopLocalAccount(zsc.getAuthtokenAccountId()))
ciMbox = MailboxManager.getInstance().getMailboxByAccountId(ciAcctId, false);
if (ciMbox == null)
throw MailServiceException.PERM_DENIED("cannot dismiss alarms of a shared calendar");
}
int calItemId = iid.getId();
ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
try {
ciMbox.dismissCalendarItemAlarm(octxt, calItemId, dismissedAt);
CalendarItem calItem = ciMbox.getCalendarItemById(octxt, calItemId);
Element calItemRespElem;
if (calItem instanceof Appointment)
calItemRespElem = response.addElement(MailConstants.E_APPOINTMENT);
else
calItemRespElem = response.addElement(MailConstants.E_TASK);
calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
boolean hidePrivate = !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
boolean showAll = !hidePrivate || calItem.isPublic();
if (showAll) {
AlarmData alarmData = calItem.getAlarmData();
if (alarmData != null)
ToXML.encodeAlarmData(calItemRespElem, calItem, alarmData);
}
} catch (NoSuchItemException nsie) {
//item must not exist in db anymore.
//this can happen if an alarm is dismissed while a big sync is happening which deletes the item (e.g. bug 48560)
//since item is not in db, it has effectively been dismissed; return ok and no further alarms
Element calItemRespElem = response.addElement(calItemElement);
calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
}
}
}
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class CreateTag method handle.
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 t = request.getElement(MailConstants.E_TAG);
String name = t.getAttribute(MailConstants.A_NAME);
String rgb = t.getAttribute(MailConstants.A_RGB, null);
Tag tag;
if (rgb != null) {
Color color = new Color(rgb);
tag = mbox.createTag(octxt, name, color);
} else {
byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
tag = mbox.createTag(octxt, name, color);
}
Element response = zsc.createElement(MailConstants.CREATE_TAG_RESPONSE);
if (tag != null)
ToXML.encodeTag(response, ifmt, octxt, tag);
return response;
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class CreateMountpoint 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 t = request.getElement(MailConstants.E_MOUNT);
String name = t.getAttribute(MailConstants.A_NAME);
String view = t.getAttribute(MailConstants.A_DEFAULT_VIEW, null);
String flags = t.getAttribute(MailConstants.A_FLAGS, null);
byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
String rgb = t.getAttribute(MailConstants.A_RGB, null);
ItemId iidParent = new ItemId(t.getAttribute(MailConstants.A_FOLDER), zsc);
boolean fetchIfExists = t.getAttributeBool(MailConstants.A_FETCH_IF_EXISTS, false);
boolean reminderEnabled = t.getAttributeBool(MailConstants.A_REMINDER, false);
Account target = null;
String ownerId = t.getAttribute(MailConstants.A_ZIMBRA_ID, null);
if (ownerId == null) {
String ownerName = t.getAttribute(MailConstants.A_OWNER_NAME);
target = Provisioning.getInstance().get(AccountBy.name, ownerName, zsc.getAuthToken());
// prevent directory harvest attack, mask no such account as permission denied
if (target == null)
throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
ownerId = target.getId();
if (ownerId.equalsIgnoreCase(zsc.getRequestedAccountId()))
throw ServiceException.INVALID_REQUEST("cannot mount your own folder", null);
}
Element remote = fetchRemoteFolder(zsc, context, ownerId, (int) t.getAttributeLong(MailConstants.A_REMOTE_ID, -1), t.getAttribute(MailConstants.A_PATH, null));
int remoteId = new ItemId(remote.getAttribute(MailConstants.A_ID), zsc).getId();
String remoteUuid = remote.getAttribute(MailConstants.A_UUID, null);
if (view == null)
view = remote.getAttribute(MailConstants.A_DEFAULT_VIEW, null);
Mountpoint mpt;
try {
Color itemColor = rgb != null ? new Color(rgb) : new Color(color);
mpt = mbox.createMountpoint(octxt, iidParent.getId(), name, ownerId, remoteId, remoteUuid, MailItem.Type.of(view), Flag.toBitmask(flags), itemColor, reminderEnabled);
} catch (ServiceException se) {
if (se.getCode() == MailServiceException.ALREADY_EXISTS && fetchIfExists) {
Folder folder = mbox.getFolderByName(octxt, iidParent.getId(), name);
if (folder instanceof Mountpoint)
mpt = (Mountpoint) folder;
else
throw se;
} else {
throw se;
}
}
Element response = zsc.createElement(MailConstants.CREATE_MOUNTPOINT_RESPONSE);
if (mpt != null) {
Element eMount = ToXML.encodeMountpoint(response, ifmt, octxt, mpt);
// transfer folder counts and subfolders to the serialized mountpoint from the serialized target folder
ToXML.transferMountpointContents(eMount, remote);
}
return response;
}
Aggregations