Search in sources :

Example 1 with SearchConvRequest

use of com.zimbra.soap.mail.message.SearchConvRequest in project zm-mailbox by Zimbra.

the class JaxbToElementTest method doXmlSearchConvRecipCheck.

private void doXmlSearchConvRecipCheck(String recipValue, WantRecipsSetting expected) throws ServiceException {
    Element elem = null;
    String xmlStr = searchConvXml.replace("%%VALUE%%", recipValue);
    elem = Element.parseXML(xmlStr);
    SearchConvRequest req = JaxbUtil.elementToJaxb(elem);
    Assert.assertEquals(String.format("recips=%s should map to %s", recipValue, expected), expected, req.getWantRecipients());
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) SearchConvRequest(com.zimbra.soap.mail.message.SearchConvRequest)

Example 2 with SearchConvRequest

use of com.zimbra.soap.mail.message.SearchConvRequest in project zm-mailbox by Zimbra.

the class JaxbToElementTest method doJsonSearchConvRecipCheck.

private void doJsonSearchConvRecipCheck(String recipValue, WantRecipsSetting expected) throws ServiceException {
    Element elem = getElementForEnvelopedJSON(searchConvJson.replace("%%VALUE%%", recipValue));
    SearchConvRequest req = JaxbUtil.elementToJaxb(elem);
    Assert.assertEquals(String.format("recips:%s should map to %s", recipValue, expected), expected, req.getWantRecipients());
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) SearchConvRequest(com.zimbra.soap.mail.message.SearchConvRequest)

Example 3 with SearchConvRequest

use of com.zimbra.soap.mail.message.SearchConvRequest in project zm-mailbox by Zimbra.

the class TestExpandGroupInfo method searchConversation.

@Test
public void searchConversation() throws Exception {
    // send a to acct, recipient is a group
    String SUBJECT = getTestName();
    sendMsg(acct, group.getName(), SUBJECT, "blah");
    SoapTransport transport = authUser(acct.getName());
    SearchRequest searchReq = new SearchRequest();
    searchReq.setSearchTypes(MailItem.Type.CONVERSATION.toString());
    searchReq.setQuery(String.format("in:inbox and subject:%s", SUBJECT));
    SearchResponse searchResp = invokeJaxb(transport, searchReq);
    List<SearchHit> searchHits = searchResp.getSearchHits();
    assertEquals(1, searchHits.size());
    SearchHit searchHit = searchHits.get(0);
    String convId = searchHit.getId();
    SearchConvRequest searchConvReq = new SearchConvRequest(convId);
    searchConvReq.setNeedCanExpand(Boolean.TRUE);
    searchConvReq.setFetch(SearchParams.ExpandResults.ALL.toString());
    SearchConvResponse searchConvResp = invokeJaxb(transport, searchConvReq);
    List<MessageHitInfo> hits = searchConvResp.getMessages();
    // 2 - one in inbox, one in sent folder
    assertEquals(2, hits.size());
    verifyGroupInfo(hits.get(0), Boolean.TRUE, Boolean.TRUE);
    verifyGroupInfo(hits.get(1), Boolean.TRUE, Boolean.TRUE);
}
Also used : SearchConvResponse(com.zimbra.soap.mail.message.SearchConvResponse) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) SearchHit(com.zimbra.soap.type.SearchHit) SearchConvRequest(com.zimbra.soap.mail.message.SearchConvRequest) MessageHitInfo(com.zimbra.soap.mail.type.MessageHitInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 4 with SearchConvRequest

use of com.zimbra.soap.mail.message.SearchConvRequest in project zm-mailbox by Zimbra.

the class SearchConv method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    SearchConvRequest req = JaxbUtil.elementToJaxb(request);
    boolean nest = ZmBoolean.toBool(req.getNestMessages(), false);
    Account acct = getRequestedAccount(zsc);
    SearchParams params = SearchParams.parse(req, zsc, acct.getPrefMailInitialSearch());
    // append (conv:(convid)) onto the beginning of the queryStr
    ItemId cid = new ItemId(req.getConversationId(), zsc);
    params.setQueryString("conv:\"" + cid.toString(ifmt) + "\" (" + params.getQueryString() + ')');
    // force to group-by-message
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    Element response = null;
    if (cid.belongsTo(mbox)) {
        // local
        ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
        try {
            response = zsc.createElement(MailConstants.SEARCH_CONV_RESPONSE);
            response.addAttribute(MailConstants.A_QUERY_OFFSET, Integer.toString(params.getOffset()));
            SortBy sort = results.getSortBy();
            response.addAttribute(MailConstants.A_SORTBY, sort.toString());
            List<Message> msgs = mbox.getMessagesByConversation(octxt, cid.getId(), sort, -1);
            if (msgs.isEmpty() && zsc.isDelegatedRequest()) {
                throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
            }
            // filter out IMAP \Deleted messages from the message lists
            Conversation conv = mbox.getConversationById(octxt, cid.getId());
            if (conv.isTagged(Flag.FlagInfo.DELETED)) {
                List<Message> raw = msgs;
                msgs = new ArrayList<Message>();
                for (Message msg : raw) {
                    if (!msg.isTagged(Flag.FlagInfo.DELETED)) {
                        msgs.add(msg);
                    }
                }
            }
            Element container = nest ? ToXML.encodeConversationSummary(response, ifmt, octxt, conv, CONVERSATION_FIELD_MASK) : response;
            SearchResponse builder = new SearchResponse(zsc, octxt, container, params);
            builder.setAllRead(conv.getUnreadCount() == 0);
            boolean more = putHits(octxt, ifmt, builder, msgs, results, params, conv);
            response.addAttribute(MailConstants.A_QUERY_MORE, more);
            // call me AFTER putHits since some of the <info> is generated by the getting of the hits!
            builder.add(results.getResultInfo());
        } finally {
            Closeables.closeQuietly(results);
        }
        return response;
    } else {
        // remote
        try {
            Element proxyRequest = zsc.createElement(MailConstants.SEARCH_CONV_REQUEST);
            Account target = Provisioning.getInstance().get(AccountBy.id, cid.getAccountId(), zsc.getAuthToken());
            if (target != null) {
                params.setInlineRule(params.getInlineRule().toLegacyExpandResults(target.getServer()));
            }
            params.encodeParams(proxyRequest);
            proxyRequest.addAttribute(MailConstants.A_NEST_MESSAGES, nest);
            proxyRequest.addAttribute(MailConstants.A_CONV_ID, cid.toString());
            // okay, lets run the search through the query parser -- this has the side-effect of
            // re-writing the query in a format that is OK to proxy to the other server -- since the
            // query has an "AND conv:remote-conv-id" part, the query parser will figure out the right
            // format for us.  TODO somehow make this functionality a bit more exposed in the
            // ZimbraQuery APIs...
            String rewrittenQueryString = mbox.getRewrittenQueryString(octxt, params);
            proxyRequest.addAttribute(MailConstants.E_QUERY, rewrittenQueryString, Element.Disposition.CONTENT);
            // proxy to remote account
            response = proxyRequest(proxyRequest, context, target.getId());
            return response.detach();
        } catch (SoapFaultException e) {
            throw ServiceException.FAILURE("SoapFaultException: ", e);
        }
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) SearchParams(com.zimbra.cs.index.SearchParams) Message(com.zimbra.cs.mailbox.Message) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) SortBy(com.zimbra.cs.index.SortBy) Element(com.zimbra.common.soap.Element) Conversation(com.zimbra.cs.mailbox.Conversation) ItemId(com.zimbra.cs.service.util.ItemId) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) SearchConvRequest(com.zimbra.soap.mail.message.SearchConvRequest)

Aggregations

SearchConvRequest (com.zimbra.soap.mail.message.SearchConvRequest)4 Element (com.zimbra.common.soap.Element)3 JSONElement (com.zimbra.common.soap.Element.JSONElement)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 JAXBElement (javax.xml.bind.JAXBElement)2 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Account (com.zimbra.cs.account.Account)1 SearchParams (com.zimbra.cs.index.SearchParams)1 SortBy (com.zimbra.cs.index.SortBy)1 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)1 Conversation (com.zimbra.cs.mailbox.Conversation)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Message (com.zimbra.cs.mailbox.Message)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 SearchConvResponse (com.zimbra.soap.mail.message.SearchConvResponse)1 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)1