Search in sources :

Example 1 with MessagePartHit

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

the class SearchResponse method add.

/* We need to pass in a boolean signifying whether to expand the message or not (bug 75990)
    */
void add(ZimbraHit hit, boolean expandMsg) throws ServiceException {
    Element el = null;
    if (params.getFetchMode() == SearchParams.Fetch.IDS) {
        if (hit instanceof ConversationHit) {
            // need to expand the contained messages
            el = element.addElement("hit");
            el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
        } else {
            el = element.addElement("hit");
            el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
        }
    } else if (hit instanceof ProxiedHit) {
        element.addElement(((ProxiedHit) hit).getElement().detach());
        size++;
        return;
    } else {
        if (hit instanceof ConversationHit) {
            el = add((ConversationHit) hit);
        } else if (hit instanceof MessageHit) {
            el = add((MessageHit) hit, expandMsg);
        } else if (hit instanceof MessagePartHit) {
            el = add((MessagePartHit) hit);
        } else if (hit instanceof ContactHit) {
            el = add((ContactHit) hit);
        } else if (hit instanceof NoteHit) {
            el = add((NoteHit) hit);
        } else if (hit instanceof CalendarItemHit) {
            // el could be null
            el = add((CalendarItemHit) hit);
        } else if (hit instanceof DocumentHit) {
            el = add((DocumentHit) hit);
        } else {
            LOG.error("Got an unknown hit type putting search hits: " + hit);
            return;
        }
    }
    if (el != null) {
        size++;
        el.addAttribute(MailConstants.A_SORT_FIELD, hit.getSortField(sortOrder).toString());
        if (includeMailbox) {
            el.addAttribute(MailConstants.A_ID, new ItemId(hit.getAcctIdStr(), hit.getItemId()).toString());
        }
    }
}
Also used : NoteHit(com.zimbra.cs.index.NoteHit) MessagePartHit(com.zimbra.cs.index.MessagePartHit) ProxiedHit(com.zimbra.cs.index.ProxiedHit) ConversationHit(com.zimbra.cs.index.ConversationHit) ContactHit(com.zimbra.cs.index.ContactHit) DocumentHit(com.zimbra.cs.index.DocumentHit) CalendarItemHit(com.zimbra.cs.index.CalendarItemHit) Element(com.zimbra.common.soap.Element) MessageHit(com.zimbra.cs.index.MessageHit) ItemId(com.zimbra.cs.service.util.ItemId)

Example 2 with MessagePartHit

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

the class SearchResponse method add.

//for bug 75990, we are now passing an expandMsg boolean instead of calculating in isInLineExpand
private Element add(MessageHit hit, boolean expandMsg) throws ServiceException {
    Message msg = hit.getMessage();
    // for bug 7568, mark-as-read must happen before the response is encoded.
    if (expandMsg && msg.isUnread() && params.getMarkRead()) {
        // Mark the message as READ
        try {
            msg.getMailbox().alterTag(octxt, msg.getId(), msg.getType(), Flag.FlagInfo.UNREAD, false, null);
        } catch (ServiceException e) {
            if (e.getCode().equals(ServiceException.PERM_DENIED)) {
                LOG.info("no permissions to mark message as read (ignored): %d", msg.getId());
            } else {
                LOG.warn("problem marking message as read (ignored): %d", msg.getId(), e);
            }
        }
    }
    Element el;
    if (expandMsg) {
        el = ToXML.encodeMessageAsMP(element, ifmt, octxt, msg, null, params.getMaxInlinedLength(), params.getWantHtml(), params.getNeuterImages(), params.getInlinedHeaders(), true, params.getWantExpandGroupInfo(), LC.mime_encode_missing_blob.booleanValue(), params.getWantContent());
    } else {
        el = ToXML.encodeMessageSummary(element, ifmt, octxt, msg, params.getWantRecipients(), params.isQuick() ? PendingModifications.Change.CONTENT : ToXML.NOTIFY_FIELDS);
    }
    el.addAttribute(MailConstants.A_CONTENTMATCHED, true);
    List<MessagePartHit> parts = hit.getMatchedMimePartNames();
    if (parts != null) {
        for (MessagePartHit mph : parts) {
            String partNameStr = mph.getPartName();
            if (partNameStr.length() > 0) {
                el.addElement(MailConstants.E_HIT_MIMEPART).addAttribute(MailConstants.A_PART, partNameStr);
            }
        }
    }
    /* Different SOAP interfaces assemble elements in different orders.  WSDL/JAXB require a specific order,
         * so force them into the correct order here.  When/if we change to using the JAXB objects, this problem
         * will go away.
         */
    JaxbInfo jaxbInfo = JaxbInfo.getFromCache(MessageHitInfo.class);
    List<List<org.dom4j.QName>> nameOrder = jaxbInfo.getElementNameOrder();
    return Element.reorderChildElements(el, nameOrder);
}
Also used : MessagePartHit(com.zimbra.cs.index.MessagePartHit) Message(com.zimbra.cs.mailbox.Message) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) List(java.util.List) JaxbInfo(com.zimbra.soap.util.JaxbInfo)

Aggregations

Element (com.zimbra.common.soap.Element)2 MessagePartHit (com.zimbra.cs.index.MessagePartHit)2 ServiceException (com.zimbra.common.service.ServiceException)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 MessageHit (com.zimbra.cs.index.MessageHit)1 NoteHit (com.zimbra.cs.index.NoteHit)1 ProxiedHit (com.zimbra.cs.index.ProxiedHit)1 Message (com.zimbra.cs.mailbox.Message)1 ItemId (com.zimbra.cs.service.util.ItemId)1 JaxbInfo (com.zimbra.soap.util.JaxbInfo)1 List (java.util.List)1