use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class ScheduleInbox method getCalendarFolders.
private java.util.Collection<Folder> getCalendarFolders(DavContext ctxt) throws ServiceException, DavException {
ArrayList<Folder> calendars = new ArrayList<Folder>();
Mailbox mbox = getMailbox(ctxt);
for (Folder f : mbox.getFolderList(ctxt.getOperationContext(), SortBy.NONE)) {
if (!(f instanceof Mountpoint) && (f.getDefaultView() == MailItem.Type.APPOINTMENT || f.getDefaultView() == MailItem.Type.TASK)) {
calendars.add(f);
}
}
return calendars;
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class ScheduleOutbox method validateRequest.
/**
* Check for illegal requests like trying to CANCEL a meeting when not the organizer or a delegate for
* the organizer
* e.g. Bug 85875 Mac OS X/10.8.5 Calendar sometimes sending CANCEL when ATTENDEE deletes an instance,
* resulting in other attendees getting invalid CANCELs
*/
private void validateRequest(boolean isOrganizerMethod, DelegationInfo delegationInfo, String organizer, DavContext ctxt, ZComponent req) throws ServiceException, DavException {
if ((!isOrganizerMethod) || (organizer != null && organizer.equals(delegationInfo.getOriginator()))) {
return;
}
// If here, only the ORGANIZER or a delegate acting as the ORGANIZER should be able to do this
AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
if (!acctMatcher.matches(delegationInfo.getOriginatorEmail())) {
throw new DavException(String.format("invalid POST to scheduling outbox '%s'. originator '%s' is not authorized account or ORGANIZER", ctxt.getRequest().getRequestURI(), delegationInfo.getOriginatorEmail()), HttpServletResponse.SC_BAD_REQUEST);
}
String organizerEmail = CalDavUtils.stripMailto(organizer);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
if (sharedCalendars != null) {
for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
Account acct = Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId());
if (acct != null) {
acctMatcher = new AccountAddressMatcher(acct);
if (acctMatcher.matches(organizerEmail)) {
return;
}
}
}
}
// We haven't found a shared calendar for the ORGANIZER that we are a delegate for.
throw new DavException(String.format("invalid POST to scheduling outbox '%s'. '%s' cannot act as ORGANIZER '%s'", ctxt.getRequest().getRequestURI(), delegationInfo.getOriginatorEmail(), organizerEmail), HttpServletResponse.SC_BAD_REQUEST);
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method move.
/* Moves this resource to another Collection. */
public void move(DavContext ctxt, Collection dest, String newName) throws DavException {
try {
Mailbox mbox = getMailbox(ctxt);
ArrayList<Integer> ids = new ArrayList<Integer>();
ids.add(mId);
if (newName != null)
ItemActionHelper.RENAME(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, type, null, newName, dest.getItemId());
else
ItemActionHelper.MOVE(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, type, null, dest.getItemId());
} 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 move item", resCode, se);
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class MailItemResource method deleteDestinationItem.
private void deleteDestinationItem(DavContext ctxt, Collection dest, int id) throws ServiceException, DavException {
Mailbox mbox = getMailbox(ctxt);
if (dest.getItemId().belongsTo(mbox)) {
mbox.delete(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN, null);
} else {
ZMailbox zmbx = getZMailbox(ctxt, dest);
ItemId itemId = new ItemId(dest.getItemId().getAccountId(), id);
zmbx.deleteItem(itemId.toString(), null);
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class CalendarCollection method getFreeBusyReport.
/* Returns iCalalendar (RFC 2445) representation of freebusy report for specified time range. */
public String getFreeBusyReport(DavContext ctxt, TimeRange range) throws ServiceException, DavException {
Mailbox mbox = getCalendarMailbox(ctxt);
FreeBusy fb = mbox.getFreeBusy(ctxt.getOperationContext(), range.getStart(), range.getEnd(), FreeBusyQuery.CALENDAR_FOLDER_ALL);
return fb.toVCalendar(FreeBusy.Method.REPLY, ctxt.getAuthAccount().getName(), mbox.getAccount().getName(), null);
}
Aggregations