use of com.zimbra.cs.lmtpserver.LmtpEnvelope 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.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class SetVariableTest method testSetMatchVarWithEnvelope.
@Ignore
public void testSetMatchVarWithEnvelope() {
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\"] \"*\" {\n" + " set \"rcptto\" \"${1}\";\n" + " log \":matches ==> ${1}\";\n" + " log \"variables ==> ${rcptto}\";\n" + " tag \"${rcptto}\";\n" + "}";
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);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Folder folder = mbox.getFolderById(null, msg.getFolderId());
Assert.assertEquals("coyote@ACME.Example.COM", ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class SetVariableTest method testDollar2.
/**
* When the match pattern ${dollar} was defined as '$' and used in the
* header/address/envelope test, this '$' should be treated as a string,
* not a part of the wild-card.
*/
@Test
public void testDollar2() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
filterScript = "require [\"variables\", \"envelope\"];\n" + "set \"dollar\" \"$\";\n" + "set \"val\" \"xyz\";\n" + "if header :matches :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-matches\";\n" + "}\n" + "if header :is :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-is\";\n" + "}\n" + "if header :contains :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-contains\";\n" + "}\n" + "if address :all :matches :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"address-matches\";\n" + "}\n" + "if address :all :is :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"address-is\";\n" + "}\n" + "if address :all :contains :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}\" {\n" + " tag \"address-contains\";\n" + "}" + "if envelope :all :matches :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"envelope-matches\";\n" + "}\n" + "if envelope :all :is :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"envelope-is\";\n" + "}\n" + "if envelope :all :contains :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}\" {\n" + " tag \"envelope-contains\";\n" + "}" + "if not header :matches :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-not-matches\";\n" + "}\n" + "if not header :is :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-not-is\";\n" + "}\n" + "if not header :contains :comparator \"i;ascii-casemap\" \"Subject\" \"${dollar}${val}\" {\n" + " tag \"header-not-contains\";\n" + "}\n" + "if not address :all :matches :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"address-not-matches\";\n" + "}\n" + "if not address :all :is :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"address-not-is\";\n" + "}\n" + "if not address :all :contains :comparator \"i;ascii-casemap\" \"To\" \"${dollar}${val}\" {\n" + " tag \"address-not-contains\";\n" + "}" + "if not envelope :all :matches :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"envelope-not-matches\";\n" + "}\n" + "if not envelope :all :is :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}@zimbra.com\" {\n" + " tag \"envelope-not-is\";\n" + "}\n" + "if not envelope :all :contains :comparator \"i;ascii-casemap\" \"From\" \"${dollar}${val}\" {\n" + " tag \"envelope-not-contains\";\n" + "}\n" + "if header :contains \"X-Header1\" \"${dollar}\" {\n" + " tag \"dollar\";\n" + "}\n" + "if header :contains \"X-Header2\" \"${dollar}{\" {\n" + " tag \"dollar-opening-brace\";\n" + "}\n" + "if header :contains \"X-Header3\" \"${dollar}}\" {\n" + " tag \"dollar-closing-brace\";\n" + "}\n" + "if header :contains \"X-Header4\" \"${dollar}\" {\n" + " tag \"dollar-middle\";\n" + "}\n";
account.setMailSieveScript(filterScript);
String raw = "From: sender@zimbra.com\n" + "To: \"$xyz\"@zimbra.com\n" + "Subject: $xyz\n" + "X-Header1: $\n" + "X-Header2: ${\n" + "X-Header3: $}\n" + "X-Header4: abc$def\n" + "\n" + "Hello World.";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<$xyz@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
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);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(13, msg.getTags().length);
Assert.assertEquals("header-matches", msg.getTags()[0]);
Assert.assertEquals("header-is", msg.getTags()[1]);
Assert.assertEquals("header-contains", msg.getTags()[2]);
Assert.assertEquals("address-matches", msg.getTags()[3]);
Assert.assertEquals("address-is", msg.getTags()[4]);
Assert.assertEquals("address-contains", msg.getTags()[5]);
Assert.assertEquals("envelope-matches", msg.getTags()[6]);
Assert.assertEquals("envelope-is", msg.getTags()[7]);
Assert.assertEquals("envelope-contains", msg.getTags()[8]);
Assert.assertEquals("dollar", msg.getTags()[9]);
Assert.assertEquals("dollar-opening-brace", msg.getTags()[10]);
Assert.assertEquals("dollar-closing-brace", msg.getTags()[11]);
Assert.assertEquals("dollar-middle", msg.getTags()[12]);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class RejectTest method testSieveRejectEnabledIsFalse.
@Test
public void testSieveRejectEnabledIsFalse() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "testRej@zimbra.com");
acct1.setSieveRejectMailEnabled(false);
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<testRej2@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<testRej@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.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class RejectTest method testNotemptyEnvelopeFromAndUsingVariables.
/*
* MDN should be sent to the envelope from (testRej2@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\" \"testRej2@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, "testRej@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "testRej2@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("<testRej2@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<testRej@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("testRej@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());
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());
}
}
Aggregations