use of com.zimbra.cs.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class EnvelopeTest method testTo.
@Test
public void testTo() {
String filterScript = "require \"envelope\";\n" + "if envelope :all :is \"to\" \"test@zimbra.com\" {\n" + " tag \"To\";\n" + "}";
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);
account.setMailSieveScript(filterScript);
account.setMail("test@zimbra.com");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.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("To", 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 EnvelopeTest method testTo_Alias.
@Test
public void testTo_Alias() {
String filterScript = "require \"envelope\";\n" + "set \"rcptto\" \"unknown\";\n" + "if envelope :all :matches \"to\" \"*\" {\n" + " set \"rcptto\" \"${1}\";\n" + " tag \"${rcptto}\";\n" + "}\n" + "if envelope :all :matches \"to\" \"alias1*\" {\n" + " tag \"${1}\";\n" + "}\n" + "if envelope :all :matches \"to\" \"alias2*\" {\n" + " tag \"bad\";\n" + "}\n" + "if envelope :count \"eq\" :comparator \"i;ascii-numeric\" \"to\" \"1\" {" + " tag \"1\";\n" + "}";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<tim@example.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<alias1@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Provisioning prov = Provisioning.getInstance();
Account account = prov.createAccount("original1@zimbra.com", "secret", new HashMap<String, Object>());
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.setAdminSieveScriptBefore(filterScript);
account.setMail("original1@zimbra.com");
String[] alias = { "alias1@zimbra.com", "alias2@zimbra.com" };
account.setMailAlias(alias);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.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());
String[] tags = msg.getTags();
Assert.assertTrue(tags != null);
Assert.assertEquals(3, tags.length);
Assert.assertEquals("alias1@zimbra.com", tags[0]);
Assert.assertEquals("@zimbra.com", tags[1]);
Assert.assertEquals("1", tags[2]);
} catch (Exception e) {
fail("No exception should be thrown:" + e);
}
}
use of com.zimbra.cs.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class EnvelopeTest method testMailFromBackslash.
@Test
public void testMailFromBackslash() {
String filterScript = "require \"envelope\";\n" + "if envelope :all :is \"from\" \"ti\\\\m@example.com\" {\n" + " tag \"From\";\n" + "}";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<\"ti\\\\m\"@example.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<xyz@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);
account.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.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("From", 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 EscapeSequencesTest method doTestHeaderEscapePattern.
/*
* MAIL FROM: <user123@zimbra.com>
* RCPT TO: <test1@zimbra.com>
* DATA
* To: user123@zimbra.com
* From: sender@zimbra.com
* Subject: test\123
* X-Header-0BackSlash: testSample
* X-Header-1BaskSlash: test\Sample
* X-Header-2BackSlash: test\\Sample
* X-Header-DoubleQuote: test"Sample
*/
public void doTestHeaderEscapePattern(String filterScript) {
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<user123@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
RuleManager.clearCachedRules(account);
account.setMailSieveScript(filterScript);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.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(1, msg.getTags().length);
Assert.assertEquals("list", msg.getTags()[0]);
} catch (Exception e) {
fail("No exception should be thrown " + e);
}
}
use of com.zimbra.cs.lmtpserver.LmtpEnvelope in project zm-mailbox by Zimbra.
the class EnvelopeTest method testNumericNegativeValueCount.
@Test
public void testNumericNegativeValueCount() {
String filterScript = "require [\"envelope\", \"tag\", \"relational\"];\n" + "if envelope :all :count \"lt\" :comparator \"i;ascii-numeric\" \"to\" \"-1\" {\n" + " tag \"To\";\n" + "}";
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);
account.setMailSieveScript(filterScript);
account.setMail("test@zimbra.com");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.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(null, ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown");
}
}
Aggregations