Search in sources :

Example 31 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class CalendarCollection method getAppointmentsByUids.

public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
    Map<String, String> uidmap = getUidToHrefMap(hrefs);
    Mailbox mbox = getCalendarMailbox(ctxt);
    ArrayList<DavResource> appts = new ArrayList<DavResource>();
    ctxt.setCollectionPath(getUri());
    Map<String, CalendarItem> calItems = mbox.getCalendarItemsByUid(ctxt.getOperationContext(), new ArrayList<String>(uidmap.keySet()));
    for (String uid : calItems.keySet()) {
        CalendarItem calItem = calItems.get(uid);
        if (calItem == null)
            appts.add(new DavResource.InvalidResource(uidmap.get(uid), getOwner()));
        else
            appts.add(new CalendarObject.LocalCalendarObject(ctxt, calItem));
    }
    return appts;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList)

Example 32 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class Collection method createItem.

// create Document at the URI
public DavResource createItem(DavContext ctxt, String name) throws DavException, IOException {
    Mailbox mbox = null;
    try {
        mbox = getMailbox(ctxt);
    } catch (ServiceException e) {
        throw new DavException("cannot get mailbox", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
    }
    FileUploadServlet.Upload upload = ctxt.getUpload();
    String ctype = upload.getContentType();
    if (ctype != null && (ctype.startsWith(DavProtocol.VCARD_CONTENT_TYPE) || ctype.startsWith(MimeConstants.CT_TEXT_VCARD_LEGACY) || ctype.startsWith(MimeConstants.CT_TEXT_VCARD_LEGACY2))) {
        // vCard MIME types such as text/x-vcard or text/directory.
        return createVCard(ctxt, name);
    }
    String author = ctxt.getAuthAccount().getName();
    try {
        // add a revision if the resource already exists
        MailItem item = mbox.getItemByPath(ctxt.getOperationContext(), ctxt.getPath());
        if (item.getType() != MailItem.Type.DOCUMENT && item.getType() != MailItem.Type.WIKI) {
            throw new DavException("no DAV resource for " + item.getType(), HttpServletResponse.SC_NOT_ACCEPTABLE, null);
        }
        Document doc = mbox.addDocumentRevision(ctxt.getOperationContext(), item.getId(), author, name, null, upload.getInputStream());
        return new Notebook(ctxt, doc);
    } catch (ServiceException e) {
        if (!(e instanceof NoSuchItemException))
            throw new DavException("cannot get item ", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
    }
    // create
    try {
        Document doc = mbox.createDocument(ctxt.getOperationContext(), mId, name, ctype, author, null, upload.getInputStream());
        Notebook notebook = new Notebook(ctxt, doc);
        notebook.mNewlyCreated = true;
        return notebook;
    } catch (ServiceException se) {
        throw new DavException("cannot create ", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, se);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException) Document(com.zimbra.cs.mailbox.Document) FileUploadServlet(com.zimbra.cs.service.FileUploadServlet) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 33 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class ScheduleOutbox method adjustOrganizer.

/**
     * For Vanilla CalDAV access where Apple style delegation has not been enabled, attempts by the delegate
     * to use a shared calendar acting as themselves are translated to appear as if acting as a delegate,
     * otherwise the experience can be very poor.
     * @throws ServiceException
     */
private void adjustOrganizer(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo) throws ServiceException {
    // BusyCal 2.5.3 seems to post with the wrong organizer even if ical delegation is switched on - even though
    // it uses the right ORGANIZER in the calendar entry.
    // if (ctxt.useIcalDelegation()) { return; }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
    String uid = req.getPropVal(ICalTok.UID, null);
    CalendarItem matchingCalendarEntry = mbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
    if (matchingCalendarEntry == null) {
        List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
        if (sharedCalendars == null) {
            // Can't work out anything useful
            return;
        }
        Set<Account> accts = Sets.newHashSet();
        for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
            accts.add(Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId()));
        }
        for (Account acct : accts) {
            Mailbox sbox = MailboxManager.getInstance().getMailboxByAccount(acct);
            matchingCalendarEntry = sbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
            if (matchingCalendarEntry != null) {
                break;
            }
        }
    }
    if (matchingCalendarEntry == null) {
        return;
    }
    Invite[] invites = matchingCalendarEntry.getInvites();
    if (invites == null) {
        return;
    }
    for (Invite inv : invites) {
        ZOrganizer org = inv.getOrganizer();
        if (org != null) {
            delegationInfo.setOwner(org.getAddress());
            if (Strings.isNullOrEmpty(org.getCn())) {
                Account ownerAcct = Provisioning.getInstance().get(AccountBy.name, org.getAddress());
                if (!Strings.isNullOrEmpty(ownerAcct.getDisplayName())) {
                    delegationInfo.setOwnerCn(ownerAcct.getDisplayName());
                }
            } else {
                delegationInfo.setOwnerCn(org.getCn());
            }
            break;
        }
    }
    if (delegationInfo.getOwner() == null) {
        return;
    }
    AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
    boolean originatorIsCalEntryOrganizer = acctMatcher.matches(delegationInfo.getOwnerEmail());
    if (originatorIsCalEntryOrganizer) {
        return;
    }
    for (ZComponent component : cal.getComponents()) {
        ZProperty organizerProp = component.getProperty(ICalTok.ORGANIZER);
        if (organizerProp != null) {
            organizerProp.setValue(delegationInfo.getOwner());
            ZParameter cn = organizerProp.getParameter(ICalTok.CN);
            if (cn == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.CN, delegationInfo.getOwnerCn()));
            } else {
                cn.setValue(delegationInfo.getOwnerCn());
            }
            ZParameter sentBy = organizerProp.getParameter(ICalTok.SENT_BY);
            if (sentBy == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.SENT_BY, delegationInfo.getOriginator()));
            } else {
                sentBy.setValue(delegationInfo.getOriginator());
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 34 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class SearchWrapper method getChildren.

@Override
public Collection<DavResource> getChildren(DavContext ctxt) {
    ArrayList<DavResource> children = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    ZimbraQueryResults zqr = null;
    try {
        Account account = prov.get(AccountBy.name, user);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        SearchParams params = new SearchParams();
        params.setQueryString(mQuery.toString());
        params.setTypes(SEARCH_TYPES);
        params.setSortBy(SortBy.NAME_ASC);
        params.setFetchMode(SearchParams.Fetch.NORMAL);
        params.setPrefetch(true);
        params.setChunkSize(SEARCH_LIMIT);
        zqr = mbox.index.search(SoapProtocol.Soap12, ctxt.getOperationContext(), params);
        while (zqr.hasNext()) {
            ZimbraHit hit = zqr.getNext();
            if (hit instanceof MessageHit)
                addAttachmentResources((MessageHit) hit, children);
        }
    } catch (Exception e) {
        ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
    } finally {
        Closeables.closeQuietly(zqr);
    }
    return children;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) SearchParams(com.zimbra.cs.index.SearchParams) Mailbox(com.zimbra.cs.mailbox.Mailbox) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) Provisioning(com.zimbra.cs.account.Provisioning)

Example 35 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.

the class UrlNamespace method getMailItemById.

private static MailItem getMailItemById(DavContext ctxt, String user, int id) throws DavException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of mail item - no such account '%s' id=%d", user, id);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    return mbox.getItemById(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN);
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) Provisioning(com.zimbra.cs.account.Provisioning)

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