Search in sources :

Example 46 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method blobsByMbox.

@Test
public void blobsByMbox() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    ParsedMessage pm = new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false);
    Message msg = mbox.addMessage(null, pm, opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
    String digest = msg.getBlob().getDigest();
    String path = msg.getBlob().getLocalBlob().getFile().getPath();
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    Assert.assertEquals(path, getPath(blobs.get(0)));
    Account acct2 = Provisioning.getInstance().getAccount("test2@zimbra.com");
    Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
    Message msg2 = mbox2.addMessage(null, pm, opt, null);
    DbVolumeBlobs.addBlobReference(conn, mbox2, vol, msg2);
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Set<String> paths = new HashSet<String>();
    paths.add(path);
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(2, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    Assert.assertTrue(paths.isEmpty());
    DbVolumeBlobs.deleteBlobRef(conn, mbox);
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    BlobReference ref = blobs.get(0);
    path = msg2.getBlob().getLocalBlob().getFile().getPath();
    Assert.assertEquals(path, getPath(ref));
    Assert.assertEquals(mbox2.getId(), ref.getMailboxId());
}
Also used : Account(com.zimbra.cs.account.Account) BlobReference(com.zimbra.cs.store.file.BlobReference) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method testDuplicateRow.

@Test
public void testDuplicateRow() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    MailboxBlobInfo blobInfo = new MailboxBlobInfo(null, mbox.getId(), msg.getId(), msg.getSavedSequence(), String.valueOf(vol.getId()), null);
    DbVolumeBlobs.addBlobReference(conn, blobInfo);
    try {
        DbVolumeBlobs.addBlobReference(conn, blobInfo);
        Assert.fail("expected exception");
    } catch (ServiceException e) {
    // expected
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ServiceException(com.zimbra.common.service.ServiceException) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Example 48 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemQueryTest method testInvalidRangeQuery.

@Test
public void testInvalidRangeQuery() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
    Message msg1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
    Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject4"), dopt, null);
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    String q = String.format("item:{%d--%d--%d}", msg1.getId(), msg2.getId(), msg3.getId());
    sr.setQuery(q);
    try {
        doSearch(sr, acct);
        Assert.fail("Should have thrown a PARSE_ERROR exception for " + q);
    } catch (ServiceException e) {
        Assert.assertEquals(e.getCode(), ServiceException.PARSE_ERROR);
    }
    sr.setSearchTypes("message");
    q = String.format("item:{%d--%d,%d}", msg1.getId(), msg2.getId(), msg3.getId());
    sr.setQuery(q);
    try {
        doSearch(sr, acct);
        Assert.fail("Should have thrown an INVALID_REQUEST exception for " + q);
    } catch (ServiceException e) {
        Assert.assertEquals(e.getCode(), ServiceException.INVALID_REQUEST);
    }
    sr.setSearchTypes("message");
    q = String.format("item:{%d,%d--%d}", msg1.getId(), msg2.getId(), msg3.getId());
    sr.setQuery(q);
    try {
        doSearch(sr, acct);
        Assert.fail("Should have thrown an INVALID_REQUEST exception for " + q);
    } catch (ServiceException e) {
        Assert.assertEquals(e.getCode(), ServiceException.INVALID_REQUEST);
    }
}
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) ServiceException(com.zimbra.common.service.ServiceException) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 49 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemQueryTest method testOneItemQuery.

@Test
public void testOneItemQuery() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery(String.format("item:{%d}", msg2.getId()));
    sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 1, hits.size());
    int msgId = Integer.parseInt(hits.get(0).getId());
    Assert.assertEquals("correct hit 1", msg2.getId(), msgId);
}
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 50 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemQueryTest method testAllItemsQuery.

@Test
public void testAllItemsQuery() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery("item:{all}");
    sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Aggregations

DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)73 Mailbox (com.zimbra.cs.mailbox.Mailbox)63 Test (org.junit.Test)57 Message (com.zimbra.cs.mailbox.Message)53 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)51 Account (com.zimbra.cs.account.Account)28 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 ItemId (com.zimbra.cs.service.util.ItemId)13 ServiceException (com.zimbra.common.service.ServiceException)12 Element (com.zimbra.common.soap.Element)12 MimeMessage (javax.mail.internet.MimeMessage)12 Volume (com.zimbra.cs.volume.Volume)11 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)11 SearchHit (com.zimbra.soap.type.SearchHit)10 IOException (java.io.IOException)10 Folder (com.zimbra.cs.mailbox.Folder)9 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)8 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 MailItem (com.zimbra.cs.mailbox.MailItem)6