use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testMatchVariables.
/*
* Verify the Match Variables assigned by deleteheader's wild-card match
*/
@SuppressWarnings("unchecked")
@Test
public void testMatchVariables() {
try {
String filterScript = "require [\"editheader\"];\n" + "deleteheader :matches \"X-Dummy-Header\" \"*\";";
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);
String[] expectedTags = { "tag1-ABC", "tag2-123", "tag3-abc", "tag4-\"\"", "tag5-xyz", "tag6-", "tag7-tes", "tag8-\'\'", "tag9-a1b2c3" };
String[] resultTags = message.getTags();
for (String resultTag : resultTags) {
String expectedTag = null;
for (String testTag : expectedTags) {
if (testTag.equalsIgnoreCase(resultTag)) {
expectedTag = testTag;
break;
}
}
Assert.assertEquals(expectedTag, resultTag);
}
} 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 DeleteHeaderTest method testDeleteHeaderUsingMatches.
/*
* Delete header using matches match-type
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderUsingMatches() {
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader :matches \"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);
boolean matchFound = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Test-Header".equals(header.getName())) {
matchFound = true;
break;
}
}
Assert.assertFalse(matchFound);
} 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 DeleteHeaderTest method testDeleteHeaderNinthFromBottom.
/*
* Delete header value of 2nd from bottom
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderNinthFromBottom() {
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader :index 9 :last \"X-Dummy-Header\" \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);
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Dummy-Header".equals(header.getName())) {
Assert.assertEquals("123", header.getValue());
break;
}
}
} 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 DeleteHeaderTest method testDeleteHeaderAtIndex.
/*
* Delete header at index
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderAtIndex() {
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader :index 2 \"X-Test-Header\" \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 matchFound = false;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("X-Test-Header".equals(header.getName()) && "test2".equals(header.getValue())) {
matchFound = true;
}
}
Assert.assertFalse(matchFound);
} 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 EnvelopeTest method testTo_BccTo.
@Test
public void testTo_BccTo() {
/*
* RFC 5228 5.4.
* ----
* If the SMTP transaction involved several RCPT commands, only the data
* from the RCPT command that caused delivery to this user is available
* in the "to" part of the envelope.
* ----
* The bcc recipient (who is specified by RCPT command but not on the
* message header) should not be matched by the 'envelope' test.
*/
String filterScript = "require \"envelope\";\n" + "if envelope :all :is \"to\" \"bccTo@zimbra.com\" {\n" + " tag \"Bcc To\";\n" + "}";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<tim@example.com>", new String[] { "BODY", "SIZE" }, null);
env.setSender(sender);
// To address
LmtpAddress recipient = new LmtpAddress("<test@zimbra.com>", null, null);
env.addLocalRecipient(recipient);
// Bcc address
recipient = new LmtpAddress("<bccTo@zimbra.com>", null, null);
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(null, ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown");
}
}
Aggregations