Search in sources :

Example 26 with Mailbox

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;
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 27 with Mailbox

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);
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher)

Example 28 with Mailbox

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);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException) ArrayList(java.util.ArrayList)

Example 29 with Mailbox

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);
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ItemId(com.zimbra.cs.service.util.ItemId)

Example 30 with Mailbox

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);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) FreeBusy(com.zimbra.cs.fb.FreeBusy)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)817 Account (com.zimbra.cs.account.Account)389 Test (org.junit.Test)376 OperationContext (com.zimbra.cs.mailbox.OperationContext)365 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)306 Message (com.zimbra.cs.mailbox.Message)303 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)243 ItemId (com.zimbra.cs.service.util.ItemId)243 Element (com.zimbra.common.soap.Element)138 ServiceException (com.zimbra.common.service.ServiceException)127 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)127 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)106 MimeMessage (javax.mail.internet.MimeMessage)104 Folder (com.zimbra.cs.mailbox.Folder)82 ArrayList (java.util.ArrayList)81 ZMailbox (com.zimbra.client.ZMailbox)73 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)71 PreparedStatement (java.sql.PreparedStatement)67 SQLException (java.sql.SQLException)67 Header (javax.mail.Header)66