use of com.zimbra.cs.mailbox.OperationContext 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()));
}
use of com.zimbra.cs.mailbox.OperationContext in project zm-mailbox by Zimbra.
the class NotifyTest method filterValidToField.
@Test
public void filterValidToField() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@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);
RuleManager.clearCachedRules(acct1);
String filterScript = "if anyof (true) { notify \"test2@zimbra.com\" \"\" \"Hello World\"" + "[\"*\"];" + " keep;" + "}";
acct1.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage("To: test@zimbra.com".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("Hello World", notifyMsg.getFragment());
Assert.assertEquals("text/plain; charset=us-ascii", notifyMsg.getMimeMessage().getContentType());
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.OperationContext in project zm-mailbox by Zimbra.
the class RedirectCopyTest method testCopyRedirect.
@Test
public void testCopyRedirect() {
String filterScript = "require [\"copy\", \"redirect\"];\n" + "if header :contains \"Subject\" \"Test\" { redirect :copy \"test3@zimbra.com\"; }";
try {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Account account2 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(account2);
account.setMailSieveScript(filterScript);
String raw = "From: test1@zimbra.com\n" + "To: test2@zimbra.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());
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
Assert.assertEquals("Hello World", notifyMsg.getFragment());
Assert.assertEquals(2, notifyMsg.getFolderId());
} catch (Exception e) {
e.printStackTrace();
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.OperationContext in project zm-mailbox by Zimbra.
the class RejectTest method testNotemptyEnvelopeFromAndUsingVariables.
/*
* MDN should be sent to the envelope from (test2@zimbra.com)
*/
@Test
public void testNotemptyEnvelopeFromAndUsingVariables() {
try {
filterScript = "require [\"log\", \"variables\", \"envelope\" , \"reject\"];\n" + "if envelope :matches [\"To\"] \"*\" {" + "set \"rcptto\" \"hello\";}\n" + "if header :matches [\"From\"] \"*\" {" + "set \"fromheader\" \"test2@zimbra.com\";}\n" + "if header :matches [\"Subject\"] \"*\" {" + "set \"subjectheader\" \"New Subject\";}\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 \"Subject: ${subjectheader}\"; \n" + "reject \"${bodyparam}\"; \n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@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);
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);
String raw = "From: sender@in.telligent.com\n" + "To: coyote@ACME.Example.COM\n" + "Subject: test\n" + "\n" + "Hello World.";
acct1.setMailSieveScript(filterScript);
acct1.setMail("test@zimbra.com");
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(0, ids.size());
List<Integer> ll = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE);
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message mdnMsg = mbox2.getMessageById(null, item);
String ctStr = mdnMsg.getMimeMessage().getContentType().toLowerCase();
boolean isReport = ctStr.startsWith("multipart/report;");
boolean isMdn = ctStr.indexOf("report-type=disposition-notification") < 0 ? false : true;
Assert.assertEquals(isReport & isMdn, true);
} catch (Exception e) {
e.printStackTrace();
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mailbox.OperationContext in project zm-mailbox by Zimbra.
the class RejectTest method testNotemptyEnvelopeFrom.
/*
* MDN should be sent to the envelope from (test2@zimbra.com)
*/
@Test
public void testNotemptyEnvelopeFrom() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@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);
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(0, ids.size());
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message mdnMsg = mbox2.getMessageById(null, item);
String ctStr = mdnMsg.getMimeMessage().getContentType().toLowerCase();
boolean isReport = ctStr.startsWith("multipart/report;");
boolean isMdn = ctStr.indexOf("report-type=disposition-notification") < 0 ? false : true;
Assert.assertEquals(isReport & isMdn, true);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
Aggregations