use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class NotifyMailtoTest method testBackslashEscapeSequence.
@Test
public void testBackslashEscapeSequence() {
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 = "require [\"enotify\"];\n" + "notify :from \"\\\"tes\\\\\\\\t1\\\"@zimbra.com\"" + ":message \"sample me\\\\ssa\\\"ge4\" " + "\"mailto:\\\"tes\\\\\\\\t2\\\"@zimbra.com?body=sample_message\";";
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "\"tes\\\\t2\"@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);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
Assert.assertEquals("sample me\\ssa\"ge4", notifyMsg.getSubject());
Assert.assertEquals("<\"tes\\\\t1\"@zimbra.com>", notifyMsg.getSender());
RuleManager.clearCachedRules(acct1);
} 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 RejectTest method testSieveRejectEnabledIsFalse.
@Test
public void testSieveRejectEnabledIsFalse() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
acct1.setSieveRejectMailEnabled(false);
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
RuleManager.clearCachedRules(acct1);
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<test2@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
acct1.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Integer item = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message msg = mbox1.getMessageById(null, item);
Assert.assertEquals("example", msg.getSubject());
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.service.util.ItemId 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.service.util.ItemId 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.service.util.ItemId in project zm-mailbox by Zimbra.
the class RuleManagerWithCustomActionFilterTest method init.
@BeforeClass
public static void init() throws Exception {
// keep original sieve factory
original_sf = RuleManager.getSieveFactory();
ExtensionTestUtil.init();
MailboxTestUtil.initServer();
Provisioning prov = Provisioning.getInstance();
prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
// make sure the behavior before registering custom actions
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
AbstractActionCommand ext = (AbstractActionCommand) ExtensionUtil.getExtension("discard");
Assert.assertNull(ext);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { discard; }");
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(0, ids.size());
// register custom action extensions
ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomDiscard");
ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomTag");
ExtensionUtil.initAll();
}
Aggregations