use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class RejectTest method testSieveRejectEnabledIsFalse.
@Test
public void testSieveRejectEnabledIsFalse() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
acct1.setSieveRejectMailEnabled(false);
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@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("<test2@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test@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.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class ReplaceHeaderTest method testReplaceHeaderStartingWithSpacesAsHeaderName.
/*
* Replace header with name starting with spaces as name, should not replace the original header
*/
@SuppressWarnings("unchecked")
@Test
public void testReplaceHeaderStartingWithSpacesAsHeaderName() {
try {
String filterScript = "require [\"editheader\"];\n" + " replaceheader :newname \"X-Test-New-Name\" :newvalue \"0\" :value \"lt\" :comparator \"i;ascii-casemap\" \" X-Test-Header\" \"test2\" \r\n" + " ;\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
boolean found = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
Assert.assertFalse(header.getName().equals(""));
if (header.getName().equals("X-Test-Header") && header.getValue().equals("test2")) {
found = true;
}
}
Assert.assertTrue(found);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class ReplaceHeaderTest method testReplaceLastHeader.
/*
* Replace last header value
*/
@SuppressWarnings("unchecked")
@Test
public void testReplaceLastHeader() {
try {
String filterScript = "require [\"editheader\"];\n" + " replaceheader :last :newvalue \"new test\" :contains \"X-Test-Header\" \"test\" \r\n" + " ;\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
int indexMatch = 0;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Test-Header".equals(header.getName())) {
indexMatch++;
if (indexMatch == 3) {
Assert.assertEquals("new test", header.getValue());
break;
}
}
}
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class ReplaceHeaderTest method testReplaceHeaderNewNameFromCondition.
/*
* Replace header with new name from the matching condition
*/
@SuppressWarnings("unchecked")
@Test
public void testReplaceHeaderNewNameFromCondition() {
try {
String filterScript = "require [\"editheader\", \"variables\"];\n" + "replaceheader :newname \"${1}\" :newvalue \"${2}\" :matches \"X-Test-Header\" \"t*t*\";\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
boolean matchNotFound = false;
boolean matchFound = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Test-Header".equals(header.getName()) && "test1".equals(header.getValue())) {
matchNotFound = true;
}
if ("es".equals(header.getName()) && "1".equals(header.getValue())) {
matchFound = true;
}
}
Assert.assertFalse(matchNotFound);
Assert.assertTrue(matchFound);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.
the class ReplaceHeaderTest method testReplaceHeaderWithEmptyHeaderNewName.
/*
* Replace header with empty new name should not replace the original header
*/
@SuppressWarnings("unchecked")
@Test
public void testReplaceHeaderWithEmptyHeaderNewName() {
try {
String filterScript = "require [\"editheader\"];\n" + " replaceheader :newname \"\" :newvalue \"0\" :value \"lt\" :comparator \"i;ascii-casemap\" \"X-Test-Header\" \"test2\" \r\n" + " ;\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox1.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox1.getMessageById(null, itemId);
boolean found = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
Assert.assertFalse(header.getName().equals(""));
if (header.getName().equals("X-Test-Header") && header.getValue().equals("test2")) {
found = true;
}
}
Assert.assertTrue(found);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
Aggregations