use of com.zimbra.cs.account.Account 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.account.Account 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.account.Account in project zm-mailbox by Zimbra.
the class BodyTest method test.
private void test(String script, String message) throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript(script);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(message.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.assertTrue(msg.isTagged(FlagInfo.FLAGGED));
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class AddHeaderTest method testAddHeaderSameHeaderNameMultipleHeaderValues1.
/*
* Add the headers with "X-Dummy-Header: new value"
* Verify that the order of the header fields does not change.
*/
@SuppressWarnings("unchecked")
@Test
public void testAddHeaderSameHeaderNameMultipleHeaderValues1() {
StringBuffer triggeringMsg = new StringBuffer();
for (String line : sampleBaseMsg2) {
triggeringMsg.append(line).append("\r\n");
}
try {
String filterScript = "require [\"editheader\"];\n" + "addheader \"X-Dummy-Header\" \"new value\"; ";
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.toString().getBytes(), false), 0, account.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Enumeration e = msg.getMimeMessage().getAllHeaderLines();
Assert.assertTrue(e.hasMoreElements());
// The 1st and 2nd line of the headers
Assert.assertEquals("Return-Path: user1@domain1.zimbra.com", (String) e.nextElement());
Assert.assertEquals("X-Dummy-Header: new value", (String) e.nextElement());
// The rest of the headers
int index = 1;
while (e.hasMoreElements() && index < sampleBaseMsg2.length) {
String value = (String) e.nextElement();
Assert.assertEquals(sampleBaseMsg2[index++], value);
}
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class AddressBookTestTest method filter.
@Test
public void filter() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
mbox.createContact(null, new ParsedContact(Collections.<String, Object>singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
account.setMailSieveScript("if addressbook :in \"From\" { tag \"Priority\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@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()));
}
Aggregations