Search in sources :

Example 1 with NoSuchItemException

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

the class ItemActionTest method deleteConversation.

@Test
public void deleteConversation() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
    // setup: add the root message
    ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int rootId = mbox.addMessage(null, pm, dopt, null).getId();
    // add additional messages
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT, rootId + "", MailSender.MSGTYPE_REPLY, null, null, 0);
    Message parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft.getConversationId());
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft2 = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT);
    parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft2.getConversationId());
    MailItem.TargetConstraint tcon = new MailItem.TargetConstraint(mbox, MailItem.TargetConstraint.INCLUDE_TRASH);
    ItemId iid = new ItemId(mbox, Mailbox.ID_FOLDER_TRASH);
    // trash the conversation
    ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(parent.getId(), draft.getId(), draft2.getId()), MailItem.Type.MESSAGE, tcon, iid);
    parent = mbox.getMessageById(null, parent.getId());
    draft = mbox.getMessageById(null, draft.getId());
    draft2 = mbox.getMessageById(null, draft2.getId());
    Assert.assertEquals(parent.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    Assert.assertEquals(draft2.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(parent.getConversationId()), MailItem.Type.CONVERSATION, tcon);
    Exception ex = null;
    try {
        mbox.getMessageById(null, parent.getId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (parent/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getMessageById(null, draft.getId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getMessageById(null, draft2.getId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft2/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getConversationById(null, draft2.getConversationId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft2/conversation)", ex instanceof NoSuchItemException);
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) 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) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 2 with NoSuchItemException

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

the class IncomingMessageHandler method fileInto.

@Override
public ItemId fileInto(String folderPath, Collection<ActionFlag> flagActions, String[] tags) throws ServiceException {
    ItemId id = FilterUtil.addMessage(dctxt, mailbox, parsedMessage, recipientAddress, folderPath, false, FilterUtil.getFlagBitmask(flagActions, Flag.BITMASK_UNREAD), tags, Mailbox.ID_AUTO_INCREMENT, octxt);
    // the spam folder (bug 37164).
    try {
        Folder folder = mailbox.getFolderByPath(octxt, folderPath);
        if (folder.getId() == Mailbox.ID_FOLDER_SPAM && id.isLocal()) {
            SpamReport report = new SpamReport(true, "filter", folderPath);
            SpamHandler.getInstance().handle(octxt, mailbox, id.getId(), MailItem.Type.MESSAGE, report);
        }
    } catch (NoSuchItemException e) {
        ZimbraLog.filter.debug("Unable to do spam training for message %s because folder path %s does not exist.", id, folderPath);
    } catch (ServiceException e) {
        ZimbraLog.filter.warn("Unable to do spam training for message %s.", id, e);
    }
    return id;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) SpamReport(com.zimbra.cs.service.util.SpamHandler.SpamReport) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 3 with NoSuchItemException

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

the class Mailbox method reanalyze.

/**
 * Recalculates the size, metadata, etc. for an existing MailItem and
 *  persists that information to the database.  Maintains any existing
 *  mutable metadata.  Updates mailbox and folder sizes appropriately.
 *
 * @param id    The item ID of the MailItem to reanalyze.
 * @param type  The item's type (e.g. {@link MailItem#TYPE_MESSAGE}).
 * @param data  The (optional) extra item data for indexing (e.g.
 *              a Message's {@link ParsedMessage}.
 */
void reanalyze(int id, MailItem.Type type, Object data, long size) throws ServiceException {
    boolean success = false;
    try {
        beginTransaction("reanalyze", null);
        MailItem item;
        try {
            item = getItemById(id, type, false);
        } catch (NoSuchItemException e) {
            // fallback to dumpster
            item = getItemById(id, type, true);
        }
        item.reanalyze(data, size);
        success = true;
    } finally {
        endTransaction(success);
    }
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 4 with NoSuchItemException

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

the class Mailbox method getItemByUuid.

MailItem getItemByUuid(String uuid, MailItem.Type type, boolean fromDumpster) throws ServiceException {
    if (fromDumpster) {
        MailItem item = null;
        try {
            item = MailItem.getByUuid(this, uuid, type, true);
            if (item != null && !isVisibleInDumpster(item)) {
                item = null;
            }
        } catch (NoSuchItemException e) {
        }
        // fault.
        if (item == null) {
            throw MailItem.noSuchItemUuid(uuid, type);
        }
        return item;
    }
    // try the cache first
    MailItem item = getCachedItemByUuid(uuid, type);
    if (item != null) {
        return item;
    }
    // the tag and folder caches contain ALL tags and folders, so cache miss == doesn't exist
    if (isCachedType(type)) {
        throw MailItem.noSuchItemUuid(uuid, type);
    }
    // cache miss, so fetch from the database
    item = MailItem.getByUuid(this, uuid, type);
    return item;
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 5 with NoSuchItemException

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

the class PurgeTest method folderPurgePolicy.

@Test
public void folderPurgePolicy() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    // Create folder and test messages.
    Folder folder = mbox.createFolder(null, "/folderPurgePolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    Message older = TestUtil.addMessage(mbox, folder.getId(), "test1", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
    Message newer = TestUtil.addMessage(mbox, folder.getId(), "test2", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
    folder = mbox.getFolderById(null, folder.getId());
    // Run purge with default settings and make sure nothing was deleted.
    mbox.purgeMessages(null);
    folder = mbox.getFolderById(null, folder.getId());
    assertEquals(2, folder.getSize());
    // Add retention policy.
    Policy p = Policy.newUserPolicy("45m");
    RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p));
    mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
    // Purge the folder cache and make sure that purge policy is reloaded from metadata.
    mbox.purge(MailItem.Type.FOLDER);
    folder = mbox.getFolderById(null, folder.getId());
    List<Policy> purgeList = folder.getRetentionPolicy().getPurgePolicy();
    assertEquals(1, purgeList.size());
    assertEquals("45m", purgeList.get(0).getLifetime());
    // Run purge and make sure one of the messages was deleted.
    mbox.purgeMessages(null);
    assertEquals(1, folder.getSize());
    mbox.getMessageById(null, newer.getId());
    try {
        mbox.getMessageById(null, older.getId());
        fail("Older message was not purged.");
    } catch (NoSuchItemException e) {
    // Older message was purged.
    }
    // Remove purge policy and verify that the folder state was properly updated.
    mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, null);
    mbox.purge(MailItem.Type.FOLDER);
    folder = mbox.getFolderById(null, folder.getId());
    assertEquals(0, folder.getRetentionPolicy().getKeepPolicy().size());
    assertEquals(0, folder.getRetentionPolicy().getPurgePolicy().size());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Aggregations

NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)52 ServiceException (com.zimbra.common.service.ServiceException)21 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)16 ItemId (com.zimbra.cs.service.util.ItemId)12 Test (org.junit.Test)11 Account (com.zimbra.cs.account.Account)10 OperationContext (com.zimbra.cs.mailbox.OperationContext)10 Element (com.zimbra.common.soap.Element)9 MailItem (com.zimbra.cs.mailbox.MailItem)9 Folder (com.zimbra.cs.mailbox.Folder)8 IOException (java.io.IOException)8 MimeMessage (javax.mail.internet.MimeMessage)8 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)7 AccountServiceException (com.zimbra.cs.account.AccountServiceException)6 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)6 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)6 ArrayList (java.util.ArrayList)6 DbMailItem (com.zimbra.cs.db.DbMailItem)5 DbTag (com.zimbra.cs.db.DbTag)5