Search in sources :

Example 66 with DeliveryOptions

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

the class AbstractBlobConsistencyCheckTest method missingBlobs.

@Test
public void missingBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int msgs = 10;
    for (int i = 0; i < msgs; i++) {
        mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    }
    deleteAllBlobs();
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(msgs, results.missingBlobs.size());
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(0, results.incorrectSize.size());
    Assert.assertEquals(0, results.incorrectModContent.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Results(com.zimbra.cs.store.file.BlobConsistencyChecker.Results) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobConsistencyChecker(com.zimbra.cs.store.file.BlobConsistencyChecker) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 67 with DeliveryOptions

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

the class AbstractBlobConsistencyCheckTest method singleBlob.

@Test
public void singleBlob() 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-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(0, results.incorrectSize.size());
    Assert.assertEquals(0, results.incorrectModContent.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Results(com.zimbra.cs.store.file.BlobConsistencyChecker.Results) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobConsistencyChecker(com.zimbra.cs.store.file.BlobConsistencyChecker) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 68 with DeliveryOptions

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

the class IncomingMessageHandler method addMessage.

private Message addMessage(int folderId, Collection<ActionFlag> flagActions, String[] tags) throws ServiceException {
    try {
        DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setNoICal(noICal).setRecipientEmail(recipientAddress);
        dopt.setFlags(FilterUtil.getFlagBitmask(flagActions, Flag.BITMASK_UNREAD)).setTags(tags);
        return mailbox.addMessage(octxt, parsedMessage, dopt, dctxt);
    } catch (IOException e) {
        throw ServiceException.FAILURE("Unable to add incoming message", e);
    }
}
Also used : IOException(java.io.IOException) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions)

Example 69 with DeliveryOptions

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

the class TestBlobDeduper method testBlobDeduper.

@Test
public void testBlobDeduper() throws Exception {
    StoreManager storeMgr = StoreManager.getInstance();
    TestUtil.assumeTrue(String.format("StoreManager class=%s is not FileBlobStore", storeMgr.getClass().getName()), storeMgr instanceof FileBlobStore);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    String[] paths = new String[5];
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 5; i++) {
        Message msg = mbox.addMessage(null, new ParsedMessage(("From: test@zimbra.com\r\nTo: to1@zimbra.com\r\nSubject: " + TEST_NAME).getBytes(), false), opt, null);
        paths[i] = msg.getBlob().getLocalBlob().getFile().getPath();
    }
    // Make sure inodes are different for paths
    for (int i = 0; i < 4; i++) {
        Assert.assertFalse(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[i + 1]).getInodeNum());
    }
    // wait for a seconds, so that timestamp gets changed.
    Thread.sleep(1000);
    BlobDeduper deduper = BlobDeduper.getInstance();
    List<Short> volumeIds = new ArrayList<Short>();
    volumeIds.add(vol.getId());
    deduper.process(volumeIds);
    while (deduper.isRunning()) {
        // wait until deduper finishes.
        Thread.sleep(1000);
    }
    // Make sure inodes are same for paths
    for (int i = 0; i < 4; i++) {
        Assert.assertTrue(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[i + 1]).getInodeNum());
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobDeduper(com.zimbra.cs.store.file.BlobDeduper) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ArrayList(java.util.ArrayList) StoreManager(com.zimbra.cs.store.StoreManager) Volume(com.zimbra.cs.volume.Volume) FileBlobStore(com.zimbra.cs.store.file.FileBlobStore) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 70 with DeliveryOptions

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

the class TestZClient method testImapMODSEQ.

@Test
public void testImapMODSEQ() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    Folder folder = mbox.createFolder(null, NAME_PREFIX, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    int folderId = folder.getId();
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder zfolder = zmbox.getFolderById(Integer.toString(folderId));
    int zmodSeq = zfolder.getImapMODSEQ();
    assertEquals("Before adding a message, ZFolder modseq is not the same as folder modseq", zmodSeq, folder.getImapMODSEQ());
    // add a message to the folder (there is a test in FolderTest which verifies that adding a message modifies imapmodseq)
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setFlags(Flag.BITMASK_UNREAD);
    String message = TestUtil.getTestMessage(NAME_PREFIX, mbox.getAccount().getName(), "someone@zimbra.com", "nothing here", new Date(System.currentTimeMillis()));
    ParsedMessage pm = new ParsedMessage(message.getBytes(), System.currentTimeMillis(), false);
    mbox.addMessage(null, pm, dopt, null);
    // get notifications and update folder cache
    zmbox.noOp();
    zfolder = zmbox.getFolderById(Integer.toString(folderId));
    folder = mbox.getFolderById(null, folderId);
    assertEquals("After adding a message, ZFolder modseq is not the same as folder modseq", zfolder.getImapMODSEQ(), folder.getImapMODSEQ());
    assertFalse("ZFolder modseq did not change after adding a message", zmodSeq == zfolder.getImapMODSEQ());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ZMountpoint(com.zimbra.client.ZMountpoint) Date(java.util.Date) 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