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 TextQueryTest method sortByIsFlagged.
@Test
public void sortByIsFlagged() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_FLAGGED);
Message msgWithFlag = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject flag"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithFlagId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.FLAG_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(0).getId());
msgWithFlagId = Integer.parseInt(hits.get(1).getId());
Assert.assertEquals("correct hit ascending unflagged", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending flagged", msgWithFlag.getId(), msgWithFlagId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.FLAG_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithFlagId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit descending unflagged", msg.getId(), msgId);
Assert.assertEquals("correct hit descending flagged", msgWithFlag.getId(), msgWithFlagId);
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class TextQueryTest method sortByPriority.
@Test
public void sortByPriority() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msgWithHighPri = mbox.addMessage(null, MailboxTestUtil.generateHighPriorityMessage("test subject is HI-PRI"), dopt, null);
Message msgWithLowPri = mbox.addMessage(null, MailboxTestUtil.generateLowPriorityMessage("test subject is LOW-PRI"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithLowPriId;
int msgWithHiPriId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.PRIORITY_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 3, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithHiPriId = Integer.parseInt(hits.get(2).getId());
msgWithLowPriId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit ascending high", msgWithHighPri.getId(), msgWithHiPriId);
Assert.assertEquals("correct hit ascending med", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending low", msgWithLowPri.getId(), msgWithLowPriId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.PRIORITY_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 3, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithHiPriId = Integer.parseInt(hits.get(0).getId());
msgWithLowPriId = Integer.parseInt(hits.get(2).getId());
Assert.assertEquals("correct hit descending high", msgWithHighPri.getId(), msgWithHiPriId);
Assert.assertEquals("correct hit descending med", msg.getId(), msgId);
Assert.assertEquals("correct hit descending low", msgWithLowPri.getId(), msgWithLowPriId);
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class TextQueryTest method sortByHasAttach.
@Test
public void sortByHasAttach() throws Exception {
Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message msgWithAttach = mbox.addMessage(null, MailboxTestUtil.generateMessageWithAttachment("test subject has attach"), dopt, null);
SearchResponse resp;
List<SearchHit> hits;
int msgId;
int msgWithAttachId;
SearchRequest sr = new SearchRequest();
sr.setSearchTypes("message");
sr.setQuery("test");
sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(0).getId());
msgWithAttachId = Integer.parseInt(hits.get(1).getId());
Assert.assertEquals("correct hit ascending no attachments", msg.getId(), msgId);
Assert.assertEquals("correct hit ascending has attachments", msgWithAttach.getId(), msgWithAttachId);
/* Check that we get them in the opposite order if we change the search direction */
sr.setSortBy(SortBy.ATTACHMENT_DESC.toString());
resp = doSearch(sr, acct);
hits = resp.getSearchHits();
Assert.assertEquals("Number of hits", 2, hits.size());
msgId = Integer.parseInt(hits.get(1).getId());
msgWithAttachId = Integer.parseInt(hits.get(0).getId());
Assert.assertEquals("correct hit descending no attachments", msg.getId(), msgId);
Assert.assertEquals("correct hit descending has attachments", msgWithAttach.getId(), msgWithAttachId);
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testBug98015.
/*
* Tests that the message from bug 98015 retains the correct Content Transfer Encoding via the mechanism of
* inferring it from the existing message referenced by the "origid" parameter.
* This scenario also happens to test the case when a CTE header on a sub-part is inherited from the top-level.
*/
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testBug98015() throws Exception {
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getBug98015MimeString().getBytes()));
ParsedMessage pm = new ParsedMessage(mimeMsg, true);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
MsgToSend msgToSend = new MsgToSend();
msgToSend.setOrigId(String.valueOf(msg.getId()));
msgToSend.setReplyType("w");
msgToSend.setSubject("Fwd: QP bug");
msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "\n\n----- Forwarded Message -----\nSubject: QP Bug\n\n\\รถ/\nid=577281"));
AttachmentsInfo attach = new AttachmentsInfo();
attach.addAttachment(new MimePartAttachSpec(String.valueOf(msg.getId()), "2"));
msgToSend.setAttachments(attach);
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
MimeMessage parsed = sendForwardedMessage(req, msg);
ZMimeMultipart mmp = (ZMimeMultipart) parsed.getContent();
assertEquals("8bit", mmp.getBodyPart(0).getHeader("Content-Transfer-Encoding")[0]);
assertEquals("base64", mmp.getBodyPart(1).getHeader("Content-Transfer-Encoding")[0]);
}
Aggregations