use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class MailItemResource method copy.
/* Copies this resource to another Collection. */
public void copy(DavContext ctxt, Collection dest, String newName) throws DavException {
try {
Mailbox mbox = getMailbox(ctxt);
ArrayList<Integer> ids = new ArrayList<Integer>();
if (newName == null) {
ids.add(mId);
ItemActionHelper.COPY(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, type, null, dest.getItemId());
} else {
// TODO add COPY with RENAME (e.g> cp a.txt b.txt) functionality in ItemActionHelper
throw MailServiceException.CANNOT_COPY(mId);
}
} catch (ServiceException se) {
int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
if (se.getCode().equals(MailServiceException.ALREADY_EXISTS))
resCode = HttpServletResponse.SC_PRECONDITION_FAILED;
throw new DavException("cannot copy item", resCode, se);
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class ScheduleOutbox method getAddressFromPrincipalURL.
/*
* to workaround the pre release iCal bugs
*/
protected String getAddressFromPrincipalURL(String url) throws ServiceException, DavException {
url = url.trim();
if (url.startsWith("http://")) {
// iCal sets the organizer field to be the URL of
// CalDAV account.
// ORGANIZER:http://jylee-macbook:7070/service/dav/user1
int pos = url.indexOf("/service/dav/");
if (pos != -1) {
int start = pos + 13;
int end = url.indexOf("/", start);
String userId = (end == -1) ? url.substring(start) : url.substring(start, end);
Account organizer = Provisioning.getInstance().get(AccountBy.name, userId);
if (organizer == null)
throw new DavException("user not found: " + userId, HttpServletResponse.SC_BAD_REQUEST, null);
return organizer.getName();
}
} else if (url.toLowerCase().startsWith("mailto:")) {
// iCal sometimes prefixes the email addr with more than one mailto:
while (url.toLowerCase().startsWith("mailto:")) {
url = url.substring(7);
}
}
return url;
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class ScheduleInbox method getAppointmentsByUids.
@Override
public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
List<DavResource> result = new ArrayList<DavResource>();
if (!DavResource.isSchedulingEnabled()) {
return result;
}
Account target = null;
Provisioning prov = Provisioning.getInstance();
if (ctxt.getActingAsDelegateFor() != null) {
target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
}
String query = "is:invite is:unread inid:" + getId() + " after:\"-1month\" ";
Mailbox mbox = getMailbox(ctxt);
ZimbraQueryResults zqr = null;
try {
zqr = mbox.index.search(ctxt.getOperationContext(), query, SEARCH_TYPES, SortBy.DATE_ASC, 100);
while (zqr.hasNext()) {
ZimbraHit hit = zqr.getNext();
if (hit instanceof MessageHit) {
Message msg = ((MessageHit) hit).getMessage();
if (target == null && msg.getCalendarIntendedFor() != null) {
continue;
}
if (!msg.isInvite() || !msg.hasCalendarItemInfos()) {
continue;
}
/* Bug 40567. hide replies to avoid them being deleted by CalDAV clients.
* TODO: An alternative approach would be to show them but when they are "deleted", flag them as
* absent from the scheduling inbox.
*/
if ("REPLY".equals(msg.getCalendarItemInfo(0).getInvite().getMethod())) {
continue;
}
if (target != null) {
if (msg.getCalendarIntendedFor() == null) {
continue;
}
Account apptRcpt = prov.getAccountByName(msg.getCalendarIntendedFor());
if (apptRcpt == null || !apptRcpt.getId().equals(target.getId())) {
continue;
}
}
DavResource rs = UrlNamespace.getResourceFromMailItem(ctxt, msg);
if (rs != null) {
String href = UrlNamespace.getRawResourceUrl(rs);
if (hrefs == null)
result.add(rs);
else {
boolean found = false;
for (String ref : hrefs) {
if (HttpUtil.urlUnescape(ref).equals(href)) {
result.add(rs);
found = true;
break;
}
}
if (!found)
result.add(new DavResource.InvalidResource(href, getOwner()));
}
}
}
}
} catch (Exception e) {
ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
} finally {
Closeables.closeQuietly(zqr);
}
return result;
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class MailItemResource method delete.
/* Deletes this resource by moving to Trash folder. Hard deletes if the item is in Trash folder.*/
@Override
public void delete(DavContext ctxt) throws DavException {
if (mId == 0) {
throw new DavException("cannot delete resource", HttpServletResponse.SC_FORBIDDEN, null);
}
try {
Mailbox mbox = getMailbox(ctxt);
if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
DavNames.remove(mbox.getId(), mId);
}
// hard delete if the item is in Trash.
if (getMailItem(ctxt).inTrash()) {
hardDelete(ctxt);
return;
}
mbox.move(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN, Mailbox.ID_FOLDER_TRASH);
} catch (ServiceException se) {
if (se.getCode().equals(MailServiceException.ALREADY_EXISTS)) {
hardDelete(ctxt);
return;
}
int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
throw new DavException("cannot delete item", resCode, se);
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class MailItemResource method hardDelete.
/* hard delete */
public void hardDelete(DavContext ctxt) throws DavException {
if (mId == 0)
throw new DavException("cannot hard delete resource", HttpServletResponse.SC_FORBIDDEN, null);
try {
Mailbox mbox = getMailbox(ctxt);
mbox.delete(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN);
} catch (ServiceException se) {
int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
throw new DavException("cannot delete item", resCode, se);
}
}
Aggregations