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());
}
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());
}
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);
}
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);
}
}
}
Aggregations