use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class LinkedInTestTest method test.
@Test
public void test() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if linkedin { tag \"linkedin\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
// connections@linkedin.com
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(("Sender: messages-noreply@bounce.linkedin.com\n" + "From: LinkedIn Connections <connections@linkedin.com>").getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("linkedin", ArrayUtil.getFirstElement(msg.getTags()));
// deals
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(("Sender: messages-noreply@bounce.linkedin.com\n" + "From: Yuichi Sasaki via LinkedIn <member@linkedin.com>").getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("linkedin", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class HeaderTest method testHeaderMatchWithItself.
@Test
public void testHeaderMatchWithItself() throws Exception {
String script = "if header :matches \"X-Header1\" \"*\" {" + " if header :matches \"X-Header1\" \"${1}\" {" + " tag \"01\";" + " }" + "}" + "if header :matches \"X-Header1\" \"*\" {" + " if header :is \"X-Header1\" \"${1}\" {" + " tag \"02\";" + " }" + "}" + "if header :matches \"X-Header1\" \"*\" {" + " set \"myvar1\" \"${1}\";" + " if header :matches \"X-Header1\" \"${myvar1}\" {" + " tag \"03\";" + " }" + "}" + "if header :matches \"X-Header1\" \"*\" {" + " set :quotewildcard \"myvar2\" \"${1}\";" + " if string :matches \"sample\\\\\\\\\\\\\\\\pattern\" \"${myvar2}\" {" + " tag \"04\";" + " }" + "}";
String sourceMsg = "X-Header1: sample\\\\pattern\n";
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setAdminSieveScriptBefore(script);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sourceMsg.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(4, msg.getTags().length);
Assert.assertEquals("01", msg.getTags()[0]);
Assert.assertEquals("02", msg.getTags()[1]);
Assert.assertEquals("03", msg.getTags()[2]);
Assert.assertEquals("04", msg.getTags()[3]);
} catch (Exception e) {
e.printStackTrace();
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class HeaderTest method doTest.
private void doTest(String filterScript, String expectedResult) {
try {
LmtpEnvelope env = setEnvelopeInfo();
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.getBytes(), false), 0, account.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(expectedResult, ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class MeTestTest method quotedMultiRecipientTo.
@Test
public void quotedMultiRecipientTo() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if me :in \"To\" { tag \"Priority\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: \"bar, foo\" <foo@zimbra.com>, \"user, test\" <test@zimbra.com>, \"aaa bbb\" <aaabbb@test.com>".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("Priority", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class MeTestTest method meInToMultiRecipient.
@Test
public void meInToMultiRecipient() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if me :in \"To\" { tag \"Priority\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: foo@zimbra.com, test@zimbra.com, bar@zimbra.com".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("Priority", ArrayUtil.getFirstElement(msg.getTags()));
}
Aggregations