Search in sources :

Example 26 with NoSuchItemException

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

the class CreateDataSource method getUniqueDSFolderName.

private static String getUniqueDSFolderName(Mailbox mbox, String dsName) throws ServiceException {
    String name = dsName;
    while (true) {
        try {
            mbox.getFolderByName(null, Mailbox.ID_FOLDER_USER_ROOT, name);
            name = dsName + "_" + new Random().nextInt(1000);
        } catch (NoSuchItemException e) {
            break;
        }
    }
    return name;
}
Also used : Random(java.util.Random) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 27 with NoSuchItemException

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

the class SendMsgTest method testSendFromDraft.

@Test
public void testSendFromDraft() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    // first, add draft message
    MimeMessage mm = new MimeMessage(Session.getInstance(new Properties()));
    mm.setRecipients(RecipientType.TO, "rcpt@zimbra.com");
    mm.saveChanges();
    ParsedMessage pm = new ParsedMessage(mm, false);
    int draftId = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT).getId();
    // then send a message referencing the draft
    Element request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
    request.addElement(MailConstants.E_MSG).addAttribute(MailConstants.A_DRAFT_ID, draftId).addAttribute(MailConstants.A_SEND_FROM_DRAFT, true);
    Element response = new SendMsg().handle(request, ServiceTestUtil.getRequestContext(acct));
    // make sure sent message exists
    int sentId = (int) response.getElement(MailConstants.E_MSG).getAttributeLong(MailConstants.A_ID);
    Message sent = mbox.getMessageById(null, sentId);
    Assert.assertEquals(pm.getRecipients(), sent.getRecipients());
    // finally, verify that the draft is gone
    try {
        mbox.getMessageById(null, draftId);
        Assert.fail("draft message not deleted");
    } catch (NoSuchItemException nsie) {
    }
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) Properties(java.util.Properties) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 28 with NoSuchItemException

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

the class FolderTest method deleteParent.

/**
     * Confirms that deleting a parent folder also deletes the child.
     */
@Test
public void deleteParent() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Folder parent = mbox.createFolder(null, "/" + "deleteParent - parent", new Folder.FolderOptions());
    int parentId = parent.getId();
    Folder child = mbox.createFolder(null, "deleteParent - child", parent.getId(), new Folder.FolderOptions());
    int childId = child.getId();
    mbox.delete(null, parent.getId(), parent.getType());
    // Look up parent by id
    try {
        mbox.getFolderById(null, parentId);
        Assert.fail("Parent folder lookup by id should have not succeeded");
    } catch (NoSuchItemException e) {
    }
    // Look up parent by query
    String sql = "SELECT id " + "FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " AND id = " + parentId;
    DbResults results = DbUtil.executeQuery(sql);
    Assert.assertEquals("Parent folder query returned data.  id=" + parentId, 0, results.size());
    // Look up child by id
    try {
        mbox.getFolderById(null, childId);
        Assert.fail("Child folder lookup by id should have not succeeded");
    } catch (NoSuchItemException e) {
    }
    // Look up child by query
    sql = "SELECT id " + "FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " AND id = " + childId;
    results = DbUtil.executeQuery(sql);
    Assert.assertEquals("Child folder query returned data.  id=" + childId, 0, results.size());
}
Also used : DbResults(com.zimbra.cs.db.DbResults) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 29 with NoSuchItemException

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

the class TagTest method rename.

@Test
public void rename() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createTag(null, tag1, MailItem.DEFAULT_COLOR);
    try {
        mbox.createTag(null, tag1, MailItem.DEFAULT_COLOR);
        Assert.fail("failed to detect naming conflict when creating tag");
    } catch (MailServiceException e) {
        Assert.assertEquals("incorrect error code when creating tag", MailServiceException.ALREADY_EXISTS, e.getCode());
    }
    Tag tag = mbox.createTag(null, tag2, MailItem.DEFAULT_COLOR);
    int tagId = tag.getId();
    mbox.rename(null, tag.getId(), tag.getType(), tag3, -1);
    Assert.assertEquals("tag rename", tag3, tag.getName());
    mbox.purge(MailItem.Type.TAG);
    try {
        tag = mbox.getTagByName(null, tag3);
        Assert.assertEquals("fetching renamed tag", tagId, tag.getId());
    } catch (NoSuchItemException nsie) {
        Assert.fail("renamed tag could not be fetched");
    }
    try {
        mbox.rename(null, tag.getId(), tag.getType(), tag1, -1);
        Assert.fail("failed to detect naming conflict when renaming tag");
    } catch (MailServiceException e) {
        Assert.assertEquals("incorrect error code when renaming tag", MailServiceException.ALREADY_EXISTS, e.getCode());
    }
}
Also used : DbTag(com.zimbra.cs.db.DbTag) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Example 30 with NoSuchItemException

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

the class ExistingMessageHandler method fileInto.

@Override
public ItemId fileInto(String folderPath, Collection<ActionFlag> flagActions, String[] tags) throws ServiceException {
    Message source = getMessage();
    // See if the message is already in the target folder.
    Folder targetFolder = null;
    try {
        targetFolder = mailbox.getFolderByPath(octxt, folderPath);
    } catch (NoSuchItemException ignored) {
    }
    if (targetFolder != null && source.getFolderId() == targetFolder.getId()) {
        ZimbraLog.filter.debug("Ignoring fileinto action for message %d.  It is already in %s.", messageId, folderPath);
        updateTagsAndFlagsIfNecessary(source, flagActions, tags);
        return null;
    }
    ZimbraLog.filter.info("Copying existing message %d to folder %s.", messageId, folderPath);
    if (isLocalExistingFolder(folderPath)) {
        // Copy item into to a local folder.
        Folder target = mailbox.getFolderByPath(octxt, folderPath);
        Message newMsg = (Message) mailbox.copy(octxt, messageId, MailItem.Type.MESSAGE, target.getId());
        filtered = true;
        filed = true;
        // Apply flags and tags
        mailbox.setTags(octxt, newMsg.getId(), MailItem.Type.MESSAGE, FilterUtil.getFlagBitmask(flagActions, source.getFlagBitmask()), FilterUtil.getTagsUnion(source.getTags(), tags));
        return new ItemId(mailbox, newMsg.getId());
    }
    ItemId id = FilterUtil.addMessage(new DeliveryContext(), mailbox, getParsedMessage(), mailbox.getAccount().getName(), folderPath, false, FilterUtil.getFlagBitmask(flagActions, source.getFlagBitmask()), tags, Mailbox.ID_AUTO_INCREMENT, octxt);
    if (id != null) {
        filtered = true;
        filed = true;
    }
    return id;
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Folder(com.zimbra.cs.mailbox.Folder) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)50 Mailbox (com.zimbra.cs.mailbox.Mailbox)21 ServiceException (com.zimbra.common.service.ServiceException)20 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)15 MailItem (com.zimbra.cs.mailbox.MailItem)11 Test (org.junit.Test)11 Account (com.zimbra.cs.account.Account)10 OperationContext (com.zimbra.cs.mailbox.OperationContext)10 ItemId (com.zimbra.cs.service.util.ItemId)10 Folder (com.zimbra.cs.mailbox.Folder)9 MimeMessage (javax.mail.internet.MimeMessage)8 Element (com.zimbra.common.soap.Element)7 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)7 IOException (java.io.IOException)7 AccountServiceException (com.zimbra.cs.account.AccountServiceException)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 Document (com.zimbra.cs.mailbox.Document)5