Search in sources :

Example 11 with DeliveryOptions

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();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 12 with DeliveryOptions

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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 13 with DeliveryOptions

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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 14 with DeliveryOptions

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);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 15 with DeliveryOptions

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]);
}
Also used : AttachmentsInfo(com.zimbra.soap.mail.type.AttachmentsInfo) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) MimePartAttachSpec(com.zimbra.soap.mail.type.MimePartAttachSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)59 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)46 Message (com.zimbra.cs.mailbox.Message)45 Test (org.junit.Test)44 Account (com.zimbra.cs.account.Account)18 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 MimeMessage (javax.mail.internet.MimeMessage)12 ItemId (com.zimbra.cs.service.util.ItemId)11 Volume (com.zimbra.cs.volume.Volume)11 ServiceException (com.zimbra.common.service.ServiceException)10 Element (com.zimbra.common.soap.Element)9 IOException (java.io.IOException)9 Folder (com.zimbra.cs.mailbox.Folder)7 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 MailItem (com.zimbra.cs.mailbox.MailItem)5 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)5 BlobConsistencyChecker (com.zimbra.cs.store.file.BlobConsistencyChecker)5