Search in sources :

Example 66 with Mailbox

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

the class DbMailItem method openConversation.

public static void openConversation(String hash, MailItem item) throws ServiceException {
    Mailbox mbox = item.getMailbox();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    try {
        String command = Db.supports(Db.Capability.REPLACE_INTO) ? "REPLACE" : "INSERT";
        String mailbox_id = DebugConfig.disableMailboxGroups ? "" : "mailbox_id, ";
        stmt = conn.prepareStatement(command + " INTO " + getConversationTableName(item) + "(" + mailbox_id + "hash, conv_id)" + " VALUES (" + (DebugConfig.disableMailboxGroups ? "" : "?, ") + "?, ?)");
        int pos = 1;
        pos = setMailboxId(stmt, mbox, pos);
        stmt.setString(pos++, hash);
        stmt.setInt(pos++, item.getId());
        stmt.executeUpdate();
    } catch (SQLException e) {
        if (Db.errorMatches(e, Db.Error.DUPLICATE_ROW)) {
            try {
                DbPool.closeStatement(stmt);
                stmt = conn.prepareStatement("UPDATE " + getConversationTableName(item) + " SET conv_id = ? WHERE " + IN_THIS_MAILBOX_AND + "hash = ?");
                int pos = 1;
                stmt.setInt(pos++, item.getId());
                pos = setMailboxId(stmt, mbox, pos);
                stmt.setString(pos++, hash);
                stmt.executeUpdate();
            } catch (SQLException nested) {
                throw ServiceException.FAILURE("updating open conversation association for hash " + hash, nested);
            }
        } else {
            throw ServiceException.FAILURE("writing open conversation association for hash " + hash, e);
        }
    } finally {
        DbPool.closeStatement(stmt);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 67 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox 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 68 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox 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 69 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox 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 70 with Mailbox

use of com.zimbra.cs.mailbox.Mailbox 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)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)817 Account (com.zimbra.cs.account.Account)389 Test (org.junit.Test)376 OperationContext (com.zimbra.cs.mailbox.OperationContext)365 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)306 Message (com.zimbra.cs.mailbox.Message)303 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)243 ItemId (com.zimbra.cs.service.util.ItemId)243 Element (com.zimbra.common.soap.Element)138 ServiceException (com.zimbra.common.service.ServiceException)127 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)127 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)106 MimeMessage (javax.mail.internet.MimeMessage)104 Folder (com.zimbra.cs.mailbox.Folder)82 ArrayList (java.util.ArrayList)81 ZMailbox (com.zimbra.client.ZMailbox)73 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)71 PreparedStatement (java.sql.PreparedStatement)67 SQLException (java.sql.SQLException)67 Header (javax.mail.Header)66