use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestImap method testAppendTags.
@Test
public void testAppendTags() throws Exception {
Flags flags = Flags.fromSpec("afs");
//new tag; does not exist in mbox
String tag1 = "APPENDTAG1";
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag1));
} finally {
msg.dispose();
}
//should not have created a visible tag
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);
//now create a visible tag, add it to a message in inbox then try append to message in different folder
String tag2 = "APPENDTAG2";
ZTag tag = mbox.getTag(tag2);
if (tag == null) {
tag = mbox.createTag(tag2, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals(tag2, tags.get(0).getName());
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tag2, info.getFlags().isSet(tag2));
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
info = connection.select(folderName);
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));
msg = message(10);
flags = Flags.fromSpec("afs");
flags.set(tag2);
try {
AppendResult res = connection.append(folderName, flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag2));
} finally {
msg.dispose();
}
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFilterExisting method testKeep.
@Test
public void testKeep() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test keep";
String id = TestUtil.addMessage(mbox, subject);
String query = "in:inbox subject:\"" + subject + "\"";
String[] ruleNames = new String[] { KEEP_RULE_NAME };
// Test keep in inbox by id.
Set<String> affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
// Test keep in inbox by query.
affectedIds = runRules(ruleNames, null, "in:inbox");
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
// Move message to folder1.
ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
mbox.moveMessage(id, folder1.getId());
// Test keep in folder1 by id.
affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(0, affectedIds.size());
query = "in:" + FOLDER1_NAME + " subject:\"" + subject + "\"";
TestUtil.getMessage(mbox, query);
// Test keep in folder1 by query.
affectedIds = runRules(ruleNames, null, "in:" + FOLDER1_NAME);
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, query);
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFolderACLCache method setUp.
@Before
public void setUp() throws Exception {
testName = testInfo.getMethodName();
userNamePrefix = "testfolderaclcache-" + testName + "-user-";
ownerName = userNamePrefix + "owner";
user2Name = userNamePrefix + "haswriteaccess";
user3Name = userNamePrefix + "hasreadwriteaccess";
cleanUp();
ownerAcct = createAcct(ownerName);
USER2 = createAcct(user2Name);
USER3 = createAcct(user3Name);
ZMailbox ownerMbx = TestUtil.getZMailbox(ownerAcct.getName());
ZFolder inbox = ownerMbx.getFolderByPath("inbox");
String sub1Path = "/inbox/sub1";
ZFolder sub1 = ownerMbx.getFolderByPath(sub1Path);
if (sub1 == null) {
sub1 = TestUtil.createFolder(ownerMbx, sub1Path);
ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER2.getName(), "w", null);
ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER3.getName(), "rw", null);
}
String sub2Path = "/inbox/sub1/sub2";
ZFolder sub2 = ownerMbx.getFolderByPath(sub2Path);
if (sub2 == null)
sub2 = TestUtil.createFolder(ownerMbx, sub2Path);
String sub3Path = "/inbox/sub3";
ZFolder sub3 = ownerMbx.getFolderByPath(sub3Path);
if (sub3 == null) {
sub3 = TestUtil.createFolder(ownerMbx, sub3Path);
ownerMbx.modifyFolderGrant(sub3.getId(), ZGrant.GranteeType.pub, null, "r", null);
}
OWNER_ACCT_ID = ownerAcct.getId();
INBOX_FID = Integer.valueOf(inbox.getId());
SUB1_FID = Integer.valueOf(sub1.getId());
SUB2_FID = Integer.valueOf(sub2.getId());
SUB3_FID = Integer.valueOf(sub3.getId());
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFolderFilterRules method moveFolder.
private void moveFolder(String folderId, String newParentFolderId) throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder = mbox.getFolderById(folderId);
ZFolder newParent = mbox.getFolderById(newParentFolderId);
String newParentPath = newParent.getPath();
String oldPath = folder.getPath();
if (oldPath.charAt(0) == '/') {
// Path in scripts may not have a leading slash
oldPath = oldPath.substring(1, oldPath.length());
}
// Confirm that the old path is in the script.
String script = account.getAttr(Provisioning.A_zimbraMailSieveScript);
assertTrue("Could not find path " + oldPath + " in script: " + script, script.contains(oldPath));
mbox.moveFolder(folderId, newParentFolderId);
folder = mbox.getFolderById(folder.getId());
String newPath = folder.getPath();
assertFalse("Path '" + oldPath + "' did not change", newPath.equals(oldPath));
assertTrue("Folder path '" + newPath + "' does not start with " + newParentPath, folder.getPath().startsWith(newParentPath));
// Confirm that filter rules are updated
// refresh
account = TestUtil.getAccount(USER_NAME);
script = account.getAttr(Provisioning.A_zimbraMailSieveScript);
assertFalse("Found old path '" + oldPath + " in script: " + script, script.indexOf(oldPath) >= 0);
assertTrue("Could not find new path '" + newPath + " in script: " + script, script.indexOf(newPath) >= 0);
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFilterExisting method testFileIntoSameFolderAndFlag.
/**
* Confirms that a flag rule runs when a message is filed into the same
* folder (bug 44588).
*/
@Test
public void testFileIntoSameFolderAndFlag() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
String subject = NAME_PREFIX + " test folder1 and flag";
String id = TestUtil.addMessage(mbox, subject, folder1.getId(), null);
ZMessage msg = mbox.getMessageById(id);
Assert.assertTrue(StringUtil.isNullOrEmpty(msg.getFlags()));
// Run the rule, make sure the message was flagged but not moved.
Set<String> affectedIds = runRules(new String[] { FOLDER1_AND_FLAG_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
msg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
Assert.assertEquals("f", msg.getFlags());
}
Aggregations