use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class BrowseWrapper method browseByType.
private List<DavResource> browseByType(DavContext ctxt) throws IOException, ServiceException {
ArrayList<DavResource> res = new ArrayList<DavResource>();
String user = ctxt.getUser();
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(AccountBy.name, user);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<BrowseTerm> terms = mbox.browse(ctxt.getOperationContext(), Mailbox.BrowseBy.attachments, "", 0);
for (BrowseTerm term : terms) {
String ctype = term.getText();
int index = ctype.indexOf('/');
if (index != -1 || ctype.equals("message") || ctype.equals("none")) {
continue;
// the client still gets confused about having a slash in the
// path even after encoding
//ctype = ctype.substring(0,index) + "%2F" + ctype.substring(index+1);
}
res.add(new BrowseWrapper(generateUri(ctype), getOwner()));
}
res.add(new BrowseWrapper(generateUri("word"), getOwner()));
res.add(new BrowseWrapper(generateUri("excel"), getOwner()));
res.add(new BrowseWrapper(generateUri("ppt"), getOwner()));
res.add(new BrowseWrapper(generateUri("pdf"), getOwner()));
return res;
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method patchProperties.
/* Modifies the set of dead properties saved for this resource.
* Properties in the parameter 'set' are added to the existing properties.
* Properties in 'remove' are removed.
*/
@Override
public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException {
List<QName> reqProps = new ArrayList<QName>();
for (QName n : remove) {
mDeadProps.remove(n);
reqProps.add(n);
}
for (Element e : set) {
QName name = e.getQName();
if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// rename folder
try {
String val = e.getText();
String uri = getUri();
Mailbox mbox = getMailbox(ctxt);
mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId);
setProperty(DavElements.P_DISPLAYNAME, val);
UrlNamespace.addToRenamedResource(getOwner(), uri, this);
UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) {
// change color
String colorStr = e.getText();
Color color = new Color(colorStr.substring(0, 7));
byte col = (byte) COLOR_LIST.indexOf(colorStr);
if (col >= 0)
color.setColor(col);
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color);
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
mDeadProps.remove(name);
continue;
} else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) {
// change default view
@SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP);
boolean isTodo = false;
boolean isEvent = false;
for (Element element : elements) {
Attribute attr = element.attribute(DavElements.P_NAME);
if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) {
isTodo = true;
} else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) {
isEvent = true;
}
}
if (isEvent ^ isTodo) {
// we support a calendar collection of type event or todo, not both or none.
Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK;
try {
Mailbox mbox = getMailbox(ctxt);
mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type);
// See UrlNamespace.addToRenamedResource()
if (this instanceof Collection) {
((Collection) this).view = type;
}
} catch (ServiceException se) {
ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY));
}
} else {
ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name));
}
continue;
}
mDeadProps.put(name, e);
reqProps.add(name);
}
String configVal = "";
if (mDeadProps.size() > 0) {
org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument();
Element top = doc.addElement(CONFIG_KEY);
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach());
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputFormat format = OutputFormat.createCompactFormat();
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
configVal = new String(out.toByteArray(), "UTF-8");
if (configVal.length() > PROP_LENGTH_LIMIT)
for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE));
}
Mailbox mbox = null;
try {
mbox = getMailbox(ctxt);
mbox.lock.lock();
Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY);
if (data == null) {
data = new Metadata();
}
data.put(Integer.toString(mId), configVal);
mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data);
} catch (ServiceException se) {
for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN));
} finally {
if (mbox != null)
mbox.lock.release();
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method setAce.
public void setAce(DavContext ctxt, List<Ace> aceList) throws ServiceException, DavException {
ACL acl = new ACL();
for (Ace ace : aceList) {
if (ace.getRights() > 0)
acl.grantAccess(ace.getZimbraId(), ace.getGranteeType(), ace.getRights(), null);
}
Mailbox mbox = getMailbox(ctxt);
mbox.setPermissions(ctxt.getOperationContext(), getId(), acl);
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method moveORcopyWithOverwrite.
public void moveORcopyWithOverwrite(DavContext ctxt, Collection dest, String newName, boolean deleteOriginal) throws DavException {
try {
if (deleteOriginal)
move(ctxt, dest, newName);
else
copy(ctxt, dest, newName);
} catch (DavException e) {
if (e.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
// in case of name conflict, delete the existing mail item and
// attempt the move operation again.
// return if the error is not ALREADY_EXISTS
ServiceException se = (ServiceException) e.getCause();
int id = 0;
try {
if (se.getCode().equals(MailServiceException.ALREADY_EXISTS) == false)
throw e;
else {
// get the conflicting item-id
if (se instanceof SoapFaultException) {
// destination belongs other mailbox.
String itemIdStr = ((SoapFaultException) se).getArgumentValue("id");
ItemId itemId = new ItemId(itemIdStr, dest.getItemId().getAccountId());
id = itemId.getId();
} else {
// destination belongs to same mailbox.
String name = null;
for (Argument arg : se.getArgs()) {
if (arg.name != null && arg.value != null && arg.value.length() > 0) {
if (arg.name.equals("name"))
name = arg.value;
/* commented out since the exception is giving wrong itemId for copy.
If the the item is conflicting with an existing item we want the
id of the existing item. But, the exception has the proposed id of
the new item which does not exist yet.
else if (arg.mName.equals("itemId"))
id = Integer.parseInt(arg.mValue);
*/
}
}
if (id <= 0) {
if (name == null && !deleteOriginal) {
// in case of copy get the id from source name since we don't support copy with rename.
name = ctxt.getItem();
}
if (name != null) {
Mailbox mbox = getMailbox(ctxt);
MailItem item = mbox.getItemByPath(ctxt.getOperationContext(), name, dest.getId());
id = item.getId();
} else
throw e;
}
}
}
deleteDestinationItem(ctxt, dest, id);
} catch (ServiceException se1) {
throw new DavException("cannot move/copy item", HttpServletResponse.SC_FORBIDDEN, se1);
}
if (deleteOriginal)
move(ctxt, dest, newName);
else
copy(ctxt, dest, newName);
} else {
throw e;
}
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method getAce.
public List<Ace> getAce(DavContext ctxt) throws ServiceException, DavException {
ArrayList<Ace> aces = new ArrayList<Ace>();
Mailbox mbox = getMailbox(ctxt);
MailItem item = mbox.getItemById(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN);
Folder f = null;
if (item.getType() == MailItem.Type.FOLDER)
f = (Folder) item;
else
f = mbox.getFolderById(ctxt.getOperationContext(), item.getParentId());
ACL effectiveAcl = f.getEffectiveACL();
if (effectiveAcl == null) {
return aces;
}
List<Grant> grants = effectiveAcl.getGrants();
if (grants == null) {
return aces;
}
for (ACL.Grant g : grants) {
if (!g.hasGrantee())
continue;
aces.add(new Ace(g.getGranteeId(), g.getGrantedRights(), g.getGranteeType()));
}
return aces;
}
Aggregations