Search in sources :

Example 21 with MailItem

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

the class UserServlet method doAuthGet.

private void doAuthGet(HttpServletRequest req, HttpServletResponse resp, UserServletContext context) throws ServletException, IOException, ServiceException, UserServletException {
    if (log.isDebugEnabled()) {
        StringBuffer reqURL = context.req.getRequestURL();
        String queryParam = context.req.getQueryString();
        if (queryParam != null)
            reqURL.append('?').append(queryParam);
        log.debug("UserServlet: " + reqURL.toString());
    }
    context.opContext = new OperationContext(context.getAuthAccount(), isAdminRequest(req));
    Mailbox mbox = UserServletUtil.getTargetMailbox(context);
    if (mbox != null) {
        ZimbraLog.addMboxToContext(mbox.getId());
        if (context.reqListIds != null) {
            resolveItems(context);
        } else {
            MailItem item = resolveItem(context);
            if (proxyIfMountpoint(req, resp, context, item)) {
                // if the target is a mountpoint, the request was already proxied to the resolved target
                return;
            }
        }
    }
    if (FormatType.FREE_BUSY.equals(context.format)) {
        /* Always reference Calendar.  This is the fallback for non-existent paths, thus, could harvest
             * emails by asking for freebusy against, say the Drafts folder.  Without this change, the returned
             * HTML would reference Drafts for valid emails and Calendar for invalid ones.
             */
        context.fakeTarget = new UserServletContext.FakeFolder(context.accountPath, "/Calendar", "Calendar");
    }
    resolveFormatter(context);
    // authentication, call the formatter and let it deal with preventing harvest attacks.
    if (mbox == null && context.formatter.requiresAuth())
        throw ServiceException.PERM_DENIED(L10nUtil.getMessage(MsgKey.errPermissionDenied, req));
    String cacheControlValue = LC.rest_response_cache_control_value.value();
    if (!StringUtil.isNullOrEmpty(cacheControlValue)) {
        resp.addHeader("Cache-Control", cacheControlValue);
    }
    FormatType formatType = context.formatter.getType();
    if (formatType != null) {
        context.resp.setContentType(formatType.getContentType());
    }
    context.formatter.format(context);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) FormatType(com.zimbra.cs.service.formatter.FormatterFactory.FormatType)

Example 22 with MailItem

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

the class ZimbraQueryResultsImpl method getZimbraHit.

/**
     * We've got a {@link Mailbox}, a {@link DbSearch.Result} and (optionally) a Lucene Doc...
     * that's everything we need to build a real ZimbraHit.
     *
     * @param doc - Optional, only set if this search had a Lucene part
     */
ZimbraHit getZimbraHit(Mailbox mbox, DbSearch.Result sr, Document doc, DbSearch.FetchMode fetch) {
    MailItem item = null;
    ImapMessage i4msg = null;
    int modseq = -1, parentId = 0;
    switch(fetch) {
        case MAIL_ITEM:
            item = sr.getItem();
            break;
        case IMAP_MSG:
            i4msg = sr.getImapMessage();
            break;
        case MODSEQ:
            modseq = sr.getModSeq();
            break;
        case PARENT:
            parentId = sr.getParentId();
            break;
    }
    ZimbraHit result = null;
    switch(sr.getType()) {
        case CHAT:
        case MESSAGE:
            if (doc != null) {
                result = getMessagePartHit(mbox, sr.getId(), (Message) item, doc, sr.getSortValue());
            } else {
                result = getMessageHit(mbox, sr.getId(), (Message) item, null, sr.getSortValue());
            }
            break;
        case CONTACT:
            result = getContactHit(mbox, sr.getId(), (Contact) item, sr.getSortValue());
            break;
        case NOTE:
            result = getNoteHit(mbox, sr.getId(), (Note) item, sr.getSortValue());
            break;
        case APPOINTMENT:
            result = getAppointmentHit(mbox, sr.getId(), (CalendarItem) item, sr.getSortValue());
            break;
        case TASK:
            result = getTaskHit(mbox, sr.getId(), (Task) item, sr.getSortValue());
            break;
        case DOCUMENT:
        case WIKI:
            result = getDocumentHit(mbox, sr.getId(), (com.zimbra.cs.mailbox.Document) item, doc, sr.getSortValue());
            break;
        default:
            assert (false);
    }
    if (i4msg != null) {
        result.cacheImapMessage(i4msg);
    }
    if (modseq > 0) {
        result.cacheModifiedSequence(modseq);
    }
    if (parentId != 0) {
        result.cacheParentId(parentId);
    }
    return result;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) MailItem(com.zimbra.cs.mailbox.MailItem) Task(com.zimbra.cs.mailbox.Task) ImapMessage(com.zimbra.cs.imap.ImapMessage) Message(com.zimbra.cs.mailbox.Message) ImapMessage(com.zimbra.cs.imap.ImapMessage) Note(com.zimbra.cs.mailbox.Note) Document(org.apache.lucene.document.Document) Contact(com.zimbra.cs.mailbox.Contact)

Example 23 with MailItem

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

the class ZimbraHit method getModifiedSequence.

public int getModifiedSequence() throws ServiceException {
    if (cachedModseq < 0) {
        MailItem item = getMailItem();
        cachedModseq = item != null ? item.getModifiedSequence() : 0;
    }
    return cachedModseq;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem)

Example 24 with MailItem

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

the class ZimbraHit method getImapMessage.

public ImapMessage getImapMessage() throws ServiceException {
    if (cachedImapMessage == null) {
        MailItem item = getMailItem();
        if (item == null) {
            return null;
        }
        cachedImapMessage = new ImapMessage(item);
    }
    return cachedImapMessage;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ImapMessage(com.zimbra.cs.imap.ImapMessage)

Example 25 with MailItem

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

the class MailDocumentHandler method getProxyTarget.

protected static ItemId getProxyTarget(ZimbraSoapContext zsc, OperationContext octxt, ItemId iid, boolean checkMountpoint) throws ServiceException {
    if (zsc == null || iid == null) {
        return null;
    }
    Account acct = getRequestedAccount(zsc);
    if (!iid.belongsTo(acct)) {
        return iid;
    }
    if (!checkMountpoint || !Provisioning.onLocalServer(acct)) {
        return null;
    }
    Mailbox mbox = getRequestedMailbox(zsc);
    MailItem item = mbox.getItemById(octxt, iid.getId(), MailItem.Type.UNKNOWN);
    if (!(item instanceof Mountpoint)) {
        return null;
    }
    return ((Mountpoint) item).getTarget();
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Aggregations

MailItem (com.zimbra.cs.mailbox.MailItem)74 Mailbox (com.zimbra.cs.mailbox.Mailbox)36 ServiceException (com.zimbra.common.service.ServiceException)30 Folder (com.zimbra.cs.mailbox.Folder)23 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)23 Message (com.zimbra.cs.mailbox.Message)19 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)16 OperationContext (com.zimbra.cs.mailbox.OperationContext)15 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)14 Element (com.zimbra.common.soap.Element)13 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)13 Account (com.zimbra.cs.account.Account)12 Document (com.zimbra.cs.mailbox.Document)12 ItemId (com.zimbra.cs.service.util.ItemId)11 HashMap (java.util.HashMap)11 ZMailbox (com.zimbra.client.ZMailbox)9 Contact (com.zimbra.cs.mailbox.Contact)9 HashSet (java.util.HashSet)9