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;
}
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) {
}
}
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());
}
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());
}
}
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;
}
Aggregations