use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class NotifyMailtoTest method testPercentEncodingVariable_WithoutEncodeurl_BadEncodedString.
@Test
public void testPercentEncodingVariable_WithoutEncodeurl_BadEncodedString() {
String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: foo@example.com, baz@example.com\n" + "cc: qux@example.com\n";
String filterScript_WithoutPercentEncodingVariable = "require [\"enotify\", \"variables\"];\n" + "set \"body_param\" \"Bad%body&evil=evilbody\";\n" + "notify \"mailto:test2@zimbra.com?body=${body_param}\";";
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
acct1.setMail("test1@zimbra.com");
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript_WithoutPercentEncodingVariable);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
// The triggered message should be delivered to the target mailbox
Assert.assertEquals(1, ids.size());
// Notification message should be delivered to mailto and to= addresses
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
// Since the message body was originally incorrectly percent-encoded,
// URLDecoder is failed to decode the message contents. Keep using the
// original message string.
Assert.assertEquals("Bad%body", notifyMsg.getFragment());
String[] headers = notifyMsg.getMimeMessage().getHeader("evil");
Assert.assertTrue(headers.length == 1);
Assert.assertEquals("evilbody", headers[0]);
RuleManager.clearCachedRules(acct1);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class NotifyMailtoTest method testPercentEncodingVariable_WithEncodeurl.
@Test
public void testPercentEncodingVariable_WithEncodeurl() {
String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: foo@example.com, baz@example.com\n" + "cc: qux@example.com\n";
String filterScript_PercentEncodingVariable = "require [\"enotify\", \"variables\"];\n" + "set :encodeurl \"body_param\" \"Safe body&evil=evilbody\";\n" + "notify \"mailto:test2@zimbra.com?body=${body_param}\";";
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
acct1.setMail("test1@zimbra.com");
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript_PercentEncodingVariable);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
// The triggered message should be delivered to the target mailbox
Assert.assertEquals(1, ids.size());
// Notification message should be delivered to mailto and to= addresses
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
Assert.assertEquals("Safe body&evil=evilbody", notifyMsg.getFragment());
String[] headers = notifyMsg.getMimeMessage().getHeader("evil");
Assert.assertFalse(notifyMsg.getSender() == null);
RuleManager.clearCachedRules(acct1);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.DeliveryContext 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.mailbox.DeliveryContext 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.mailbox.DeliveryContext 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");
}
}
Aggregations