use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class AppendMessage method store.
private int store(Mailbox mbox, Folder folder) throws ImapSessionClosedException, ServiceException, IOException {
boolean idxAttach = mbox.attachmentsIndexingEnabled();
Long receivedDate = date != null ? date.getTime() : null;
ParsedMessage pm = new ParsedMessage(content, receivedDate, idxAttach);
try {
if (!pm.getSender().isEmpty()) {
InternetAddress ia = new JavaMailInternetAddress(pm.getSender());
if (AccountUtil.addressMatchesAccountOrSendAs(mbox.getAccount(), ia.getAddress())) {
flags |= Flag.BITMASK_FROM_ME;
}
}
} catch (Exception e) {
}
DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(true).setFlags(flags).setTags(tags);
Message msg = mbox.addMessage(handler.getContext(), pm, dopt, null);
if (msg != null && sflags != 0 && handler.getState() == ImapHandler.State.SELECTED) {
ImapFolder selectedFolder = handler.getSelectedFolder();
// (note that this leaves session flags unset on remote appended messages)
if (selectedFolder != null) {
ImapMessage i4msg = selectedFolder.getById(msg.getId());
if (i4msg != null) {
i4msg.setSessionFlags(sflags, selectedFolder);
}
}
}
return msg == null ? -1 : msg.getId();
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class LuceneQueryOperationTest method subjectQuery.
@Test
public void subjectQuery() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, new ParsedMessage("Subject: one two three".getBytes(), false), dopt, null);
MailboxTestUtil.index(mbox);
// phrase query
SearchParams params = new SearchParams();
params.setQueryString("subject:\"one two three\"");
params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
params.setSortBy(SortBy.NONE);
ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
ZimbraQueryResults results = query.execute();
Assert.assertTrue(results.hasNext());
Assert.assertEquals(msg.getId(), results.getNext().getItemId());
results.close();
// verify subject is not repeated during index
params = new SearchParams();
params.setQueryString("subject:\"three one\"");
params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
params.setSortBy(SortBy.NONE);
query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
results = query.execute();
Assert.assertFalse(results.hasNext());
results.close();
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class LuceneQueryOperationTest method notClause.
@Test
public void notClause() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
mbox.addMessage(null, new ParsedMessage("From: test1@zimbra.com".getBytes(), false), dopt, null);
Message msg2 = mbox.addMessage(null, new ParsedMessage("From: test2@zimbra.com".getBytes(), false), dopt, null);
Message msg3 = mbox.addMessage(null, new ParsedMessage("From: test3@zimbra.com".getBytes(), false), dopt, null);
MailboxTestUtil.index(mbox);
SearchParams params = new SearchParams();
params.setQueryString("-from:test1@zimbra.com");
params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
params.setSortBy(SortBy.NONE);
ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
ZimbraQueryResults results = query.execute();
List<Integer> expecteds = Lists.newArrayList();
List<Integer> matches = Lists.newArrayList();
Assert.assertTrue(results.hasNext());
matches.add(results.getNext().getItemId());
Assert.assertTrue(results.hasNext());
matches.add(results.getNext().getItemId());
Assert.assertFalse(results.hasNext());
expecteds.add(msg2.getId());
expecteds.add(msg3.getId());
Collections.sort(matches);
Collections.sort(expecteds);
Assert.assertEquals("Match Item ID", expecteds.get(0), matches.get(0));
Assert.assertEquals("Match Item ID", expecteds.get(1), matches.get(1));
results.close();
}
use of com.zimbra.cs.mailbox.DeliveryOptions 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.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemActionTest method deleteConversation.
@Test
public void deleteConversation() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
// setup: add the root message
ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
int rootId = mbox.addMessage(null, pm, dopt, null).getId();
// add additional messages
pm = MailboxTestUtil.generateMessage("Re: test subject");
Message draft = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT, rootId + "", MailSender.MSGTYPE_REPLY, null, null, 0);
Message parent = mbox.getMessageById(null, rootId);
Assert.assertEquals(parent.getConversationId(), draft.getConversationId());
pm = MailboxTestUtil.generateMessage("Re: test subject");
Message draft2 = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT);
parent = mbox.getMessageById(null, rootId);
Assert.assertEquals(parent.getConversationId(), draft2.getConversationId());
MailItem.TargetConstraint tcon = new MailItem.TargetConstraint(mbox, MailItem.TargetConstraint.INCLUDE_TRASH);
ItemId iid = new ItemId(mbox, Mailbox.ID_FOLDER_TRASH);
// trash the conversation
ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(parent.getId(), draft.getId(), draft2.getId()), MailItem.Type.MESSAGE, tcon, iid);
parent = mbox.getMessageById(null, parent.getId());
draft = mbox.getMessageById(null, draft.getId());
draft2 = mbox.getMessageById(null, draft2.getId());
Assert.assertEquals(parent.getFolderId(), Mailbox.ID_FOLDER_TRASH);
Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
Assert.assertEquals(draft2.getFolderId(), Mailbox.ID_FOLDER_TRASH);
ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(parent.getConversationId()), MailItem.Type.CONVERSATION, tcon);
Exception ex = null;
try {
mbox.getMessageById(null, parent.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (parent/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getMessageById(null, draft.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getMessageById(null, draft2.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft2/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getConversationById(null, draft2.getConversationId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft2/conversation)", ex instanceof NoSuchItemException);
}
Aggregations