use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class ErejectTest method init.
@BeforeClass
public static void init() throws Exception {
MailboxTestUtil.initServer();
MailboxTestUtil.clearData();
Provisioning prov = Provisioning.getInstance();
Map<String, Object> attrs = Maps.newHashMap();
prov.createDomain("zimbra.com", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test@zimbra.com", "secret", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test2@zimbra.com", "secret", attrs);
// this MailboxManager does everything except actually send mail
MailboxManager.setInstance(new DirectInsertionMailboxManager());
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class FilterUtilTest method init.
@BeforeClass
public static void init() throws Exception {
MailboxTestUtil.initServer();
Provisioning prov = Provisioning.getInstance();
Account acct1 = prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
Server server = Provisioning.getInstance().getServer(acct1);
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class EnvelopeTest method testCountForEmptyFromHeader.
@Test
public void testCountForEmptyFromHeader() {
String filterScript = "require \"envelope\";\n" + "if envelope :count \"eq\" :comparator \"i;ascii-numeric\" :all \"FROM\" \"0\" {\n" + "tag \"0\";\n" + "}\n" + "if envelope :all :matches \"from\" \"\" {\n" + " tag \"empty\";\n" + "}\n" + "if envelope :count \"eq\" :comparator \"i;ascii-numeric\" :all \"to\" \"1\" {\n" + "tag \"1\";\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", ArrayUtil.getFirstElement(msg.getTags()));
Assert.assertEquals("empty", msg.getTags()[1]);
Assert.assertEquals("1", msg.getTags()[2]);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class EnvelopeTest method testHeaderNameWithLeadingSpace.
@Test
public void testHeaderNameWithLeadingSpace() {
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.Provisioning in project zm-mailbox by Zimbra.
the class EnvelopeTest method testInvalidHeaderName.
@Test
public void testInvalidHeaderName() {
String filterScript = "require \"envelope\";\n" + "if anyof envelope :matches \"to123\" \"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");
}
}
Aggregations