use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class GetSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetSystemRetentionPolicyRequest req = JaxbUtil.elementToJaxb(request);
Provisioning prov = Provisioning.getInstance();
// assume default retention policy to be set in globalConfig (for backward compatibility)
Entry entry = prov.getConfig();
// check if cos is specified
CosSelector cosSelector = req.getCos();
if (cosSelector != null) {
entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
if (entry == null)
throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
}
// check right
checkGetRight(entry, zsc, context);
RetentionPolicy rp = RetentionPolicyManager.getInstance().getSystemRetentionPolicy(entry);
GetSystemRetentionPolicyResponse res = new GetSystemRetentionPolicyResponse(rp);
return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
}
use of com.zimbra.soap.mail.type.RetentionPolicy 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.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class ToXML method encodeFolder.
public static Element encodeFolder(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Folder folder, int fields, boolean exposeAclAccessKey) throws ServiceException {
if (folder instanceof SearchFolder) {
return encodeSearchFolder(parent, ifmt, (SearchFolder) folder, fields);
} else if (folder instanceof Mountpoint) {
return encodeMountpoint(parent, ifmt, octxt, (Mountpoint) folder, fields);
}
Element elem = parent.addElement(MailConstants.E_FOLDER);
encodeFolderCommon(elem, ifmt, folder, fields);
if (needToOutput(fields, Change.SIZE)) {
int deleted = folder.getDeletedCount();
elem.addAttribute(MailConstants.A_NUM, folder.getItemCount() - deleted);
if (deleted > 0) {
elem.addAttribute(MailConstants.A_IMAP_NUM, folder.getItemCount());
}
elem.addAttribute(MailConstants.A_SIZE, folder.getTotalSize());
elem.addAttribute(MailConstants.A_IMAP_MODSEQ, folder.getImapMODSEQ());
elem.addAttribute(MailConstants.A_IMAP_UIDNEXT, folder.getImapUIDNEXT());
}
if (needToOutput(fields, Change.URL)) {
String url = folder.getUrl();
if (!url.isEmpty() || fields != NOTIFY_FIELDS) {
// Note: in this case, a url on a folder object
// is not a url to the folder, but the url to another item that's
// external of the mail system. In most cases this is a 'synced' folder
// that is either RSS or a remote calendar object
elem.addAttribute(MailConstants.A_URL, HttpUtil.sanitizeURL(url));
}
}
Mailbox mbox = folder.getMailbox();
boolean remote = octxt != null && octxt.isDelegatedRequest(mbox);
boolean canAdminister = !remote;
boolean canDelete = canAdminister;
if (remote) {
// return effective permissions only for remote folders
String perms = encodeEffectivePermissions(folder, octxt);
elem.addAttribute(MailConstants.A_RIGHTS, perms);
canAdminister = perms != null && perms.indexOf(ACL.ABBR_ADMIN) != -1;
// Need to know retention policy if grantees can delete from a folder so clients can warn
// them when they try to delete something within the retention period
canDelete = canAdminister || (perms != null && perms.indexOf(ACL.ABBR_DELETE) != -1);
}
if (canAdminister) {
// return full ACLs for folders we have admin rights on
if (needToOutput(fields, Change.ACL)) {
if (fields != NOTIFY_FIELDS || folder.isTagged(Flag.FlagInfo.NO_INHERIT)) {
encodeACL(octxt, elem, folder.getEffectiveACL(), exposeAclAccessKey);
}
}
}
if (canDelete) {
if (needToOutput(fields, Change.RETENTION_POLICY)) {
RetentionPolicy rp = folder.getRetentionPolicy();
if (fields != NOTIFY_FIELDS || rp.isSet()) {
// Only output retention policy if it's being modified, or if we're returning all
// folder data and policy is set.
encodeRetentionPolicy(elem, RetentionPolicyManager.getInstance().getCompleteRetentionPolicy(folder.getAccount(), rp));
}
}
}
return elem;
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class Folder method decodeMetadata.
@Override
void decodeMetadata(Metadata meta) throws ServiceException {
super.decodeMetadata(meta);
// avoid a painful data migration...
Type view;
switch(mId) {
case Mailbox.ID_FOLDER_INBOX:
case Mailbox.ID_FOLDER_SPAM:
case Mailbox.ID_FOLDER_SENT:
case Mailbox.ID_FOLDER_DRAFTS:
view = Type.MESSAGE;
break;
case Mailbox.ID_FOLDER_CALENDAR:
view = Type.APPOINTMENT;
break;
case Mailbox.ID_FOLDER_TASKS:
view = Type.TASK;
break;
case Mailbox.ID_FOLDER_AUTO_CONTACTS:
case Mailbox.ID_FOLDER_CONTACTS:
view = Type.CONTACT;
break;
case Mailbox.ID_FOLDER_IM_LOGS:
view = Type.MESSAGE;
break;
default:
view = Type.UNKNOWN;
break;
}
byte bview = (byte) meta.getLong(Metadata.FN_VIEW, -1);
defaultView = bview >= 0 ? Type.of(bview) : view;
attributes = (byte) meta.getLong(Metadata.FN_ATTRS, 0);
totalSize = meta.getLong(Metadata.FN_TOTAL_SIZE, 0L);
imapUIDNEXT = (int) meta.getLong(Metadata.FN_UIDNEXT, 0);
imapMODSEQ = (int) meta.getLong(Metadata.FN_MODSEQ, 0);
imapRECENT = (int) meta.getLong(Metadata.FN_RECENT, -1);
imapRECENTCutoff = (int) meta.getLong(Metadata.FN_RECENT_CUTOFF, 0);
deletedCount = (int) meta.getLong(Metadata.FN_DELETED, 0);
deletedUnreadCount = (int) meta.getLong(Metadata.FN_DELETED_UNREAD, 0);
if (meta.containsKey(Metadata.FN_URL) || meta.containsKey(Metadata.FN_SYNC_DATE)) {
syncData = new SyncData(meta.get(Metadata.FN_URL, null), meta.get(Metadata.FN_SYNC_GUID, null), meta.getLong(Metadata.FN_SYNC_DATE, 0));
}
Metadata rp = meta.getMap(Metadata.FN_RETENTION_POLICY, true);
if (rp != null) {
retentionPolicy = RetentionPolicyManager.retentionPolicyFromMetadata(rp, true);
} else {
retentionPolicy = new RetentionPolicy();
}
activeSyncDisabled = meta.getBool(Metadata.FN_DISABLE_ACTIVESYNC, false);
webOfflineSyncDays = meta.getInt(Metadata.FN_WEB_OFFLINE_SYNC_DAYS, -1);
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class JaxbToElementTest method standalonElementToJaxbTest.
@Test
public void standalonElementToJaxbTest() throws Exception {
InputStream is = getClass().getResourceAsStream("retentionPolicy.xml");
Element elem = Element.parseXML(is);
String eXml = elem.toString();
ZimbraLog.test.debug("retentionPolicy.xml from Element:\n%s", eXml);
RetentionPolicy rp = JaxbUtil.elementToJaxb(elem, RetentionPolicy.class);
Assert.assertNotNull("elementToJaxb RetentionPolicy returned object", rp);
Element elem2 = JaxbUtil.jaxbToElement(rp, XMLElement.mFactory);
String eXml2 = elem2.toString();
ZimbraLog.test.debug("Round tripped retentionPolicy.xml from Element:\n%s", eXml2);
XMLAssert.assertXMLEqual(eXml, eXml2);
}
Aggregations