use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class EnvelopeTest method testInvalidHeaderName2.
@Test
public void testInvalidHeaderName2() {
String filterScript = "require \"envelope\";\n" + "if anyof envelope :matches \"from123\" \"t1@zimbra.com\" {\n" + " fileinto \"Junk\";\n" + "}\n";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<t1@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<xyz@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Provisioning prov = Provisioning.getInstance();
Account account = prov.createAccount("xyz@zimbra.com", "secret", new HashMap<String, Object>());
account.setMail("xyz@zimbra.com");
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(Mailbox.ID_FOLDER_INBOX, msg.getFolderId());
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class EnvelopeTest method testVariable.
public void testVariable(String filterScript) {
/*
* Checks if numeric variable works
*/
String triggeringMsg = "from: message_header_from@example.com\n" + "to: message_header_to@zimbra.com\n" + "Subject: Example\n";
String[] expectedTagName = { "env_envelope_from@example.com", "env_test@zimbra.com", "adr_message_header_from@example.com", "adr_message_header_to@zimbra.com", "hdr_message_header_from@example.com", "hdr_message_header_to@zimbra.com" };
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<envelope_from@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);
Map<String, Object> attrs = Maps.newHashMap();
attrs = Maps.newHashMap();
Provisioning.getInstance().getServer(account).modify(attrs);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.setMailSieveScript(filterScript);
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());
String[] tags = msg.getTags();
Assert.assertTrue(tags != null);
Assert.assertEquals(expectedTagName.length, tags.length);
for (int i = 0; i < expectedTagName.length; i++) {
Assert.assertEquals(expectedTagName[i], tags[i]);
}
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class EnvelopeTest method testHeaderNameWithLeadingAndTrailingSpace.
@Test
public void testHeaderNameWithLeadingAndTrailingSpace() {
String filterScript = "require \"envelope\";\n" + "if envelope :matches \" TO \" \"*@zimbra.com\" {\n" + " tag \"t1\";\n" + "}\n";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<xyz@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Provisioning prov = Provisioning.getInstance();
Account account = prov.createAccount("xyz@zimbra.com", "secret", new HashMap<String, Object>());
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(0, msg.getTags().length);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class EnvelopeTest method testCompareEmptyStringWithAsciiNumeric.
@Test
public void testCompareEmptyStringWithAsciiNumeric() {
String filterScript = "require \"envelope\";\n" + "if envelope :comparator \"i;ascii-numeric\" :all :is \"from\" \"\" {\n" + " tag \"testCompareEmptyStringWithAsciiNumeric envelope\";" + "}" + "if header :comparator \"i;ascii-numeric\" :is \"from\" \"\" {\n" + " tag \"testCompareEmptyStringWithAsciiNumeric header\";" + "}";
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);
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(2, tags.length);
Assert.assertEquals("testCompareEmptyStringWithAsciiNumeric envelope", tags[0]);
Assert.assertEquals("testCompareEmptyStringWithAsciiNumeric header", tags[1]);
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.cs.account.Account 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");
}
}
Aggregations