use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SetVariableTest method testSetMatchVarMultiLineWithEnvelope2.
@Ignore
public void testSetMatchVarMultiLineWithEnvelope2() {
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<tim@example.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
filterScript = "require [\"log\", \"variables\", \"envelope\" ];\n" + "if envelope :matches [\"To\"] \"*\" {" + " set \"rcptto\" \"${1}\";\n" + "}\n" + "if header :matches [\"Date\"] \"*\" {" + " set \"dateheader\" \"${1}\";\n" + "}\n" + "if header :matches [\"From\"] \"*\" {" + " set \"fromheader\" \"${1}\";\n" + "}\n" + "if header :matches [\"Subject\"] \"*\" {" + " set \"subjectheader\" \"${1}\";\n" + "}\n" + "if anyof(not envelope :is [\"From\"] \"\" ){\n" + " set \"subjectparam\" \"Notification\";\n" + " set \"bodyparam\" text: # This is a comment\r\n" + "Message delivered to ${rcptto}\n" + "Sent : ${fromheader}\n" + "Subject : ${subjectheader} \n" + ".\r\n" + " ;\n" + " log \"${bodyparam}\"; \n" + " log \"subjectparam ==> [${subjectparam}]\";\n" + " log \"rcptto ==> [${rcptto}]\";\n" + " log \"mailfrom ==> [${mailfrom}]\";\n" + "}\n";
System.out.println(filterScript);
account.setMailSieveScript(filterScript);
account.setMail("test@zimbra.com");
String raw = "From: sender@in.telligent.com\n" + "To: coyote@ACME.Example.COM\n" + "Subject: test\n" + "\n" + "Hello World.";
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
} 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 SetVariableTest method testSetMatchVarAndFileInto.
@Test
public void testSetMatchVarAndFileInto() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
filterScript = "require [\"log\", \"variables\"];\n" + "set \"sub\" \"test\";\n" + "if header :contains \"subject\" \"${sub}\" {\n" + " log \"Subject has test\";\n" + " fileinto \"${sub}\";\n" + "}";
System.out.println(filterScript);
account.setMailSieveScript(filterScript);
String raw = "From: sender@in.telligent.com\n" + "To: coyote@ACME.Example.COM\n" + "Subject: test\n" + "\n" + "Hello World.";
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.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());
Folder folder = mbox.getFolderById(null, msg.getFolderId());
Assert.assertEquals("test", folder.getName());
RuleManager.clearCachedRules(account);
filterScript = "require [\"log\", \"variables\"];\n" + "set \"sub\" \"test\";\n" + "if header :contains \"subject\" \"Hello ${sub}\" {\n" + " log \"Subject has test\";\n" + " fileinto \"${sub}\";\n" + "}";
System.out.println(filterScript);
account.setMailSieveScript(filterScript);
raw = "From: sender@in.telligent.com\n" + "To: coyote@ACME.Example.COM\n" + "Subject: Hello test\n" + "\n" + "Hello World.";
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.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());
folder = mbox.getFolderById(null, msg.getFolderId());
Assert.assertEquals("test", folder.getName());
} 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 SetVariableTest method testVariables_Address_HeaderList_KeyList.
@Test
public void testVariables_Address_HeaderList_KeyList() {
try {
String raw = "From: user2@ykomiyam.local\n" + "To: coyote@ACME.Example.COM\n" + "Subject: hello version 1.0 is out\n" + "\n" + "Hello World.";
filterScript = "require [\"variables\", \"tag\"];\n" + "set \"from_address_One\" \"user1@ykomiyam.local\";" + "set \"from_address_Two\" \"user2@ykomiyam.local\";" + "set \"from_header_name\" \"From\";" + "set \"to_header_name\" \"To\";" + "if address :comparator \"i;ascii-casemap\" :is \"From\" [\"${from_address_One}\",\"${from_address_Two}\"] {" + " tag \"KeyListTag\";\n" + "}" + "if address :comparator \"i;ascii-casemap\" :is [\"${from_header_name}\",\"${to_header_name}\"] \"user2@ykomiyam.local\" {" + " tag \"HeaderListTag\";\n" + "}";
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(raw.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());
String[] tags = msg.getTags();
Assert.assertEquals(2, tags.length);
Assert.assertEquals("KeyListTag", tags[0]);
Assert.assertEquals("HeaderListTag", tags[1]);
} 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 RuleManagerTest method tagAndFileinto.
@Test
public void tagAndFileinto() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"priority\"; fileinto \"socialcast\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: test".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("socialcast", mbox.getFolderById(null, msg.getFolderId()).getName());
Assert.assertEquals("priority", ArrayUtil.getFirstElement(msg.getTags()));
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"priority\"; }\n" + "if header :contains [\"Subject\"] [\"Zimbra\"] { fileinto \"zimbra\"; }");
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: Zimbra".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("zimbra", mbox.getFolderById(null, msg.getFolderId()).getName());
Assert.assertEquals("priority", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class RuleManagerTest method tagAndTag.
@Test
public void tagAndTag() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"priority\"; tag \"socialcast\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: test".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.assertArrayEquals(new String[] { "priority", "socialcast" }, msg.getTags());
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"priority\"; }\n" + "if header :contains [\"Subject\"] [\"Zimbra\"] { tag \"zimbra\"; }");
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: Zimbra".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.assertArrayEquals(new String[] { "priority", "zimbra" }, msg.getTags());
}
Aggregations