Search in sources :

Example 6 with MessageHit

use of com.zimbra.cs.index.MessageHit 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;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) DavException(com.zimbra.cs.dav.DavException) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults)

Example 7 with MessageHit

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

the class Search method putHits.

private void putHits(ZimbraSoapContext zsc, OperationContext octxt, Element el, ZimbraQueryResults results, SearchParams params) throws ServiceException {
    if (params.getInlineRule() == ExpandResults.HITS || params.getInlineRule() == ExpandResults.FIRST_MSG || params.getInlineRule() == ExpandResults.HITS_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.UNREAD || params.getInlineRule() == ExpandResults.UNREAD_FIRST || params.getInlineRule() == ExpandResults.U_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.U1_OR_FIRST_MSG) {
        // these are not valid values for Search (according to soap.txt)
        params.setInlineRule(ExpandResults.NONE);
    }
    ResultsPager pager = ResultsPager.create(results, params);
    if (params.getCursor() != null) {
        if (params.getCursor().isIncludeOffset()) {
            long offset = pager.getCursorOffset();
            if (offset >= 0) {
                el.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
            }
        }
    } else {
        el.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    }
    SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
    resp.setIncludeMailbox(false);
    resp.setSortOrder(pager.getSortOrder());
    boolean expand;
    ExpandResults expandValue = params.getInlineRule();
    int hitNum = 0;
    while (pager.hasNext() && resp.size() < params.getLimit()) {
        hitNum++;
        ZimbraHit hit = pager.getNextHit();
        if (hit instanceof MessageHit) {
            /*
                 * Determine whether or not to expand MessageHits.
                 * This logic used to be in SearchResponse.isInlineExpand, but was moved
                 * to the handler classes because in some cases
                 * the decision to expand any particular hit is dependent on
                 * other hits (see SearchConv)
                 */
            if (expandValue == ExpandResults.NONE) {
                expand = false;
            } else if (expandValue == ExpandResults.ALL) {
                expand = true;
            } else if (expandValue == ExpandResults.FIRST) {
                expand = params.getOffset() > 0 ? false : hitNum == 1;
            } else {
                expand = expandValue.matches(hit.getParsedItemID());
            }
            resp.add(hit, expand);
        } else {
            resp.add(hit);
        }
    }
    resp.addHasMore(pager.hasNext());
    resp.add(results.getResultInfo());
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) ExpandResults(com.zimbra.cs.index.SearchParams.ExpandResults) ResultsPager(com.zimbra.cs.index.ResultsPager) MessageHit(com.zimbra.cs.index.MessageHit)

Aggregations

MessageHit (com.zimbra.cs.index.MessageHit)7 ZimbraHit (com.zimbra.cs.index.ZimbraHit)4 Message (com.zimbra.cs.mailbox.Message)4 Element (com.zimbra.common.soap.Element)3 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Account (com.zimbra.cs.account.Account)2 Provisioning (com.zimbra.cs.account.Provisioning)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ServiceException (com.zimbra.common.service.ServiceException)1 ShareNotification (com.zimbra.common.share.ShareNotification)1 DavException (com.zimbra.cs.dav.DavException)1 CalendarItemHit (com.zimbra.cs.index.CalendarItemHit)1 ContactHit (com.zimbra.cs.index.ContactHit)1 ConversationHit (com.zimbra.cs.index.ConversationHit)1 DocumentHit (com.zimbra.cs.index.DocumentHit)1 MessagePartHit (com.zimbra.cs.index.MessagePartHit)1 NoteHit (com.zimbra.cs.index.NoteHit)1 ProxiedHit (com.zimbra.cs.index.ProxiedHit)1