use of com.zimbra.soap.mail.type.BulkAction in project zm-mailbox by Zimbra.
the class SearchActionTest method testSearchActionRead.
@Test
public void testSearchActionRead() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testRead@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// Add two messages to inbox, one with search match and other with no match
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
Message message1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message message2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
TypedIdList ids = mbox.getItemIds(null, 2);
Assert.assertEquals(2, ids.size());
Assert.assertEquals(true, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
SearchRequest sRequest = new SearchRequest();
sRequest.setSearchTypes("conversation");
// search with query 'test'
sRequest.setQuery("test");
BulkAction bAction = new BulkAction();
// search action - mark search result with 'read'
bAction.setOp(BulkAction.Operation.read);
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
List<SearchHit> searchHits = sResponse.getSearchHits();
ConvActionRequest req = SearchAction.getConvActionRequest(searchHits, "read");
ConvAction convAction = new ConvAction();
PowerMockito.stub(PowerMockito.method(SoapHttpTransport.class, "invokeWithoutSession")).toReturn(convAction.handle(zsc.jaxbToElement(req), ServiceTestUtil.getRequestContext(acct)));
SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
// check search result message is marked read
Assert.assertEquals(false, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
}
use of com.zimbra.soap.mail.type.BulkAction in project zm-mailbox by Zimbra.
the class SearchAction 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);
SearchActionRequest req = zsc.elementToJaxb(request);
SearchRequest searchRequest = req.getSearchRequest();
Account acct = mbox.getAccount();
Server server = Provisioning.getInstance().getServer(acct);
String url = URLUtil.getSoapURL(server, false);
com.zimbra.soap.mail.message.SearchResponse resp = null;
Element searchResponse;
SoapHttpTransport transport = new SoapHttpTransport(url);
transport.setTargetAcctId(acct.getId());
try {
transport.setAuthToken(octxt.getAuthToken().getEncoded());
searchResponse = transport.invokeWithoutSession(JaxbUtil.jaxbToElement(searchRequest));
resp = (com.zimbra.soap.mail.message.SearchResponse) JaxbUtil.elementToJaxb(searchResponse);
List<SearchHit> searchHits = resp.getSearchHits();
BulkAction action = req.getBulkAction();
performAction(action, searchRequest, searchHits, mbox, octxt);
} catch (AuthTokenException | IOException | HttpException e) {
throw ServiceException.FAILURE("Failed to execute search request", e);
}
SearchActionResponse searchActionResponse = new SearchActionResponse();
return zsc.jaxbToElement(searchActionResponse);
}
use of com.zimbra.soap.mail.type.BulkAction in project zm-mailbox by Zimbra.
the class SearchActionTest method testSearchActionMove.
@Test
public void testSearchActionMove() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testMove@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// Add two messages to inbox, one with search match and other with no match
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
TypedIdList ids = mbox.getItemIds(null, 2);
Assert.assertEquals(2, ids.size());
SearchRequest sRequest = new SearchRequest();
sRequest.setSearchTypes("conversation");
// search with query 'test'
sRequest.setQuery("test");
BulkAction bAction = new BulkAction();
// search action - move search result to 'Trash'
bAction.setOp(BulkAction.Operation.move);
bAction.setFolder("Trash");
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
List<SearchHit> searchHits = sResponse.getSearchHits();
SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
// check inbox contains only 1 unmatched mail item after move
List<MailItem> mailItems = mbox.getItemList(null, MailItem.Type.MESSAGE, 2, com.zimbra.cs.index.SortBy.DATE_DESC);
Assert.assertEquals(1, mailItems.size());
Assert.assertEquals("unmatched subject", mailItems.get(0).getSubject());
// check trash contains mail item having 'test subject' after move
mailItems = mbox.getItemList(null, MailItem.Type.MESSAGE, 3, com.zimbra.cs.index.SortBy.DATE_DESC);
Assert.assertEquals(1, mailItems.size());
Assert.assertEquals("test subject", mailItems.get(0).getSubject());
}
Aggregations