use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class CreateTag method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element t = request.getElement(MailConstants.E_TAG);
String name = t.getAttribute(MailConstants.A_NAME);
String rgb = t.getAttribute(MailConstants.A_RGB, null);
Tag tag;
if (rgb != null) {
Color color = new Color(rgb);
tag = mbox.createTag(octxt, name, color);
} else {
byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
tag = mbox.createTag(octxt, name, color);
}
Element response = zsc.createElement(MailConstants.CREATE_TAG_RESPONSE);
if (tag != null)
ToXML.encodeTag(response, ifmt, octxt, tag);
return response;
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class TagActionTest method byId.
@Test
public void byId() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Tag tag1 = mbox.createTag(null, name1, (byte) 0);
Tag tag2 = mbox.createTag(null, name2, (byte) 1);
String tagids = getTagIds(tag1, tag2);
Element request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
Element action = request.addElement(MailConstants.E_ACTION);
action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_COLOR).addAttribute(MailConstants.A_COLOR, 4);
action.addAttribute(MailConstants.A_ID, tagids);
Element ack = new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct)).getElement(MailConstants.E_ACTION);
Assert.assertEquals(name1 + " color set", 4, mbox.getTagByName(null, name1).getColor());
Assert.assertEquals(name2 + " color set", 4, mbox.getTagByName(null, name2).getColor());
Assert.assertEquals(tagids, ack.getAttribute(MailConstants.A_ID));
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class TagActionTest method byName.
@Test
public void byName() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Tag tag1 = mbox.createTag(null, name1, (byte) 0);
Tag tag2 = mbox.createTag(null, name2, (byte) 1);
String tagnames = TagUtil.encodeTags(name1, name2);
Element request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
Element action = request.addElement(MailConstants.E_ACTION);
action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_COLOR).addAttribute(MailConstants.A_COLOR, 4);
action.addAttribute(MailConstants.A_TAG_NAMES, tagnames);
Element ack = new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct)).getElement(MailConstants.E_ACTION);
Assert.assertEquals(name1 + " color set", 4, mbox.getTagByName(null, name1).getColor());
Assert.assertEquals(name2 + " color set", 4, mbox.getTagByName(null, name2).getColor());
Assert.assertEquals(getTagIds(tag1, tag2), ack.getAttribute(MailConstants.A_ID));
Assert.assertEquals(tagnames, ack.getAttribute(MailConstants.A_TAG_NAMES));
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class TagTest method test.
@Test
public void test() throws Exception {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("tag \"Hello World\";");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: sender@zimbra.com\nSubject: test1".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Tag tag = mbox.getTagByName(null, "Hello World");
Assert.assertTrue(tag.isListed());
// Send one more message to verify that no exception occurs
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: sender@zimbra.com\nSubject: test2".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Assert.assertTrue(tag.isListed());
} catch (Exception e) {
e.printStackTrace();
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.
the class TagTest method testMimeVariable.
@Test
public void testMimeVariable() throws Exception {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("tag \"${subject} World\";");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: sender@zimbra.com\nSubject: Hello".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Tag tag = mbox.getTagByName(null, "Hello World");
Assert.assertTrue(tag.isListed());
} catch (Exception e) {
e.printStackTrace();
fail("No exception should be thrown");
}
}
Aggregations