use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetPrefs method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, account))
throw ServiceException.PERM_DENIED("can not access account");
Element response = zsc.createElement(AccountConstants.GET_PREFS_RESPONSE);
handle(request, response, account);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class TagAction 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);
Element action = request.getElement(MailConstants.E_ACTION);
String opAttr = action.getAttribute(MailConstants.A_OPERATION).toLowerCase();
String operation = getOperation(opAttr);
if (operation.equals(OP_TAG) || operation.equals(OP_FLAG)) {
throw ServiceException.INVALID_REQUEST("cannot tag/flag a tag", null);
}
if (!TAG_ACTIONS.contains(operation)) {
throw ServiceException.INVALID_REQUEST("invalid operation on tag: " + opAttr, null);
}
String tn = action.getAttribute(MailConstants.A_TAG_NAMES, null);
if (tn != null) {
// switch tag names to tag IDs, because that's what ItemAction expects
StringBuilder tagids = new StringBuilder();
for (String name : TagUtil.decodeTags(tn)) {
tagids.append(tagids.length() == 0 ? "" : ",").append(mbox.getTagByName(octxt, name).getId());
}
action.addAttribute(MailConstants.A_ID, tagids.toString());
}
String successes;
if (operation.equals(OP_RETENTION_POLICY)) {
ItemId iid = new ItemId(action.getAttribute(MailConstants.A_ID), zsc);
RetentionPolicy rp = new RetentionPolicy(action.getElement(MailConstants.E_RETENTION_POLICY));
mbox.setRetentionPolicy(octxt, iid.getId(), MailItem.Type.TAG, rp);
successes = new ItemIdFormatter(zsc).formatItemId(iid);
} else {
successes = handleCommon(context, request, opAttr, MailItem.Type.TAG);
}
Element response = zsc.createElement(MailConstants.TAG_ACTION_RESPONSE);
Element result = response.addUniqueElement(MailConstants.E_ACTION);
result.addAttribute(MailConstants.A_ID, successes);
result.addAttribute(MailConstants.A_TAG_NAMES, tn);
result.addAttribute(MailConstants.A_OPERATION, opAttr);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SetCalendarItem 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);
int flags = Flag.toBitmask(request.getAttribute(MailConstants.A_FLAGS, null));
String[] tags = TagUtil.parseTags(request, mbox, octxt);
mbox.lock.lock();
try {
int defaultFolder = getItemType() == MailItem.Type.TASK ? Mailbox.ID_FOLDER_TASKS : Mailbox.ID_FOLDER_CALENDAR;
String defaultFolderStr = Integer.toString(defaultFolder);
String folderIdStr = request.getAttribute(MailConstants.A_FOLDER, defaultFolderStr);
ItemId iidFolder = new ItemId(folderIdStr, zsc);
Folder folder = mbox.getFolderById(octxt, iidFolder.getId());
SetCalendarItemParseResult parsed = parseSetAppointmentRequest(request, zsc, octxt, folder, getItemType(), false);
CalendarItem calItem = mbox.setCalendarItem(octxt, iidFolder.getId(), flags, tags, parsed.defaultInv, parsed.exceptions, parsed.replies, parsed.nextAlarm);
Element response = getResponseElement(zsc);
if (parsed.defaultInv != null) {
response.addElement(MailConstants.A_DEFAULT).addAttribute(MailConstants.A_ID, ifmt.formatItemId(parsed.defaultInv.invite.getMailItemId()));
}
if (parsed.exceptions != null) {
for (SetCalendarItemData cur : parsed.exceptions) {
Element e = response.addElement(MailConstants.E_CAL_EXCEPT);
e.addAttribute(MailConstants.A_CAL_RECURRENCE_ID, cur.invite.getRecurId().toString());
e.addAttribute(MailConstants.A_ID, ifmt.formatItemId(cur.invite.getMailItemId()));
}
}
String itemId = ifmt.formatItemId(calItem == null ? 0 : calItem.getId());
response.addAttribute(MailConstants.A_CAL_ID, itemId);
try {
Element inv = request.getElement(MailConstants.A_DEFAULT).getElement(MailConstants.E_MSG).getElement(MailConstants.E_INVITE);
Element comp = inv.getOptionalElement(MailConstants.E_INVITE_COMPONENT);
if (comp != null) {
inv = comp;
}
String reqCalItemId = inv.getAttribute(MailConstants.A_CAL_ID);
String uid = inv.getAttribute(MailConstants.A_UID);
//new or same as requested, or Outlook and case-insensitive equal
boolean uidSame = (calItem == null || (calItem.getUid() == null && uid == null) || (calItem.getUid() != null && (calItem.getUid().equals(uid) || (Invite.isOutlookUid(calItem.getUid()) && calItem.getUid().equalsIgnoreCase(uid)))));
if (ZimbraLog.calendar.isInfoEnabled()) {
StringBuilder logBuf = new StringBuilder();
if (!reqCalItemId.equals(itemId)) {
logBuf.append("Mapped requested id ").append(reqCalItemId).append(" -> ").append(itemId);
}
if (!uidSame) {
logBuf.append(" ?? requested UID ").append(uid).append(" differs from mapped ").append(calItem.getUid());
ZimbraLog.calendar.warn(logBuf.toString());
} else if (logBuf.length() > 0) {
ZimbraLog.calendar.info(logBuf.toString());
}
}
assert (uidSame);
} catch (ServiceException se) {
//one of the elements we wanted to use doesn't exist; ignore; no log/assertion possible
}
if (!parsed.isTodo)
// for backward compat
response.addAttribute(MailConstants.A_APPT_ID_DEPRECATE_ME, itemId);
return response;
} finally {
mbox.lock.release();
}
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SetCustomMetadata 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 meta = request.getElement(MailConstants.E_METADATA);
String section = meta.getAttribute(MailConstants.A_SECTION);
section = section.trim();
if (section.length() == 0 || section.length() > 36)
throw ServiceException.INVALID_REQUEST("invalid length for custom metadata section name", null);
CustomMetadata custom = new CustomMetadata(section);
for (Element.KeyValuePair kvp : meta.listKeyValuePairs()) custom.put(kvp.getKey(), kvp.getValue());
ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);
Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
response.addAttribute(MailConstants.A_ID, ifmt.formatItemId(iid));
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class SnoozeCalendarItemAlarm 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 snoozeUntil = calItemElem.getAttributeLong(MailConstants.A_CAL_ALARM_SNOOZE_UNTIL);
// trace logging
ZimbraLog.calendar.info("<SnoozeCalendarItemAlarm> id=%s,until=%d", iid.toString(), snoozeUntil);
// 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 snooze alarms of a shared calendar");
}
int calItemId = iid.getId();
ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
try {
ciMbox.snoozeCalendarItemAlarm(octxt, calItemId, snoozeUntil);
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 snoozed while a big sync is happening which deletes the item (e.g. bug 48560)
//since item is not in db, it has effectively been snoozed; return ok and no further alarms
Element calItemRespElem = response.addElement(calItemElement);
calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
}
}
}
return response;
}
Aggregations