Search in sources :

Example 1 with ParsedMessage

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

the class DbVolumeBlobsTest method deleteAllBlobRef.

@Test
public void deleteAllBlobRef() 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();
    DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(1, blobs.size());
    DbVolumeBlobs.deleteAllBlobRef(conn);
    blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(0, blobs.size());
}
Also used : 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) Test(org.junit.Test)

Example 2 with ParsedMessage

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

the class DbVolumeBlobsTest method writeBlobInfo.

@Test
public void writeBlobInfo() 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();
    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());
    BlobReference ref = blobs.get(0);
    Assert.assertEquals(path, getPath(ref));
}
Also used : 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) Test(org.junit.Test)

Example 3 with ParsedMessage

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

the class DbVolumeBlobsTest method testIncrementalBlobs.

@Test
public void testIncrementalBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    int ts1 = (int) (System.currentTimeMillis() / 1000);
    Message msg1 = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Thread.sleep(1000);
    int ts2 = (int) (System.currentTimeMillis() / 1000);
    Message msg2 = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Thread.sleep(1000);
    int ts3 = (int) (System.currentTimeMillis() / 1000);
    Iterable<MailboxBlobInfo> allBlobs = null;
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), ts1, ts2);
    Assert.assertEquals(msg1.getId(), allBlobs.iterator().next().itemId);
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), ts2, ts3);
    Assert.assertEquals(msg2.getId(), allBlobs.iterator().next().itemId);
}
Also used : 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) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Test(org.junit.Test)

Example 4 with ParsedMessage

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

the class DbVolumeBlobsTest method writeAllBlobRefs.

@Test
public void writeAllBlobRefs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    for (int i = 0; i < 10; i++) {
        Message msg = mbox.addMessage(null, new ParsedMessage(("From: from" + i + "@zimbra.com\r\nTo: to1@zimbra.com").getBytes(), false), opt, null);
        digestToPath.put(msg.getDigest(), msg.getBlob().getLocalBlob().getFile().getPath());
    }
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(digestToPath.size(), blobs.size());
    for (BlobReference blob : blobs) {
        String path = digestToPath.remove(blob.getDigest());
        Assert.assertNotNull(path);
        Assert.assertEquals(path, getPath(blob));
    }
    Assert.assertTrue(digestToPath.isEmpty());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) HashMap(java.util.HashMap) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) Volume(com.zimbra.cs.volume.Volume) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 5 with ParsedMessage

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

the class DbVolumeBlobsTest method blobsByVolume.

@Test
public void blobsByVolume() 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 volPath = vol.getRootPath().replace("store", "store2");
    File volFile = new File(volPath);
    volFile.mkdirs();
    Volume vol2 = Volume.builder().setPath(volFile.getAbsolutePath(), true).setType(Volume.TYPE_MESSAGE).setName("volume2").build();
    vol2 = VolumeManager.getInstance().create(vol2);
    VolumeManager.getInstance().setCurrentVolume(Volume.TYPE_MESSAGE, vol2.getId());
    Message msg2 = mbox.addMessage(null, pm, opt, null);
    DbVolumeBlobs.addBlobReference(conn, mbox, vol2, msg2);
    String digest = msg.getBlob().getDigest();
    //add same msg to two different volumes
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(1, blobs.size());
    Set<String> paths = new HashSet<String>();
    paths.add(msg.getBlob().getLocalBlob().getFile().getPath());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
        Assert.assertEquals(vol.getId(), ref.getVolumeId());
    }
    blobs = DbVolumeBlobs.getBlobReferences(conn, vol2);
    Assert.assertEquals(1, blobs.size());
    paths = new HashSet<String>();
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
        Assert.assertEquals(vol2.getId(), ref.getVolumeId());
    }
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    paths = new HashSet<String>();
    paths.add(msg.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(1, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
    paths = new HashSet<String>();
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(1, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    //delete from vol1
    DbVolumeBlobs.deleteBlobRef(conn, vol);
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
    paths = new HashSet<String>();
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(1, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(0, blobs.size());
    blobs = DbVolumeBlobs.getBlobReferences(conn, vol2);
    Assert.assertEquals(1, blobs.size());
    paths = new HashSet<String>();
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol2);
    paths = new HashSet<String>();
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(1, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
}
Also used : 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) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ParsedMessage (com.zimbra.cs.mime.ParsedMessage)388 Mailbox (com.zimbra.cs.mailbox.Mailbox)304 Test (org.junit.Test)300 Message (com.zimbra.cs.mailbox.Message)278 Account (com.zimbra.cs.account.Account)271 OperationContext (com.zimbra.cs.mailbox.OperationContext)264 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)252 ItemId (com.zimbra.cs.service.util.ItemId)186 MimeMessage (javax.mail.internet.MimeMessage)113 Header (javax.mail.Header)66 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)55 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)52 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)50 SyntaxException (org.apache.jsieve.exception.SyntaxException)49 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)45 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)33 ServiceException (com.zimbra.common.service.ServiceException)30 InputStream (java.io.InputStream)24 IOException (java.io.IOException)21 Element (com.zimbra.common.soap.Element)18