use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testDeleteHeaderWithNumericComparisionUsingValue.
/*
* Delete header with numeric comparator :value
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderWithNumericComparisionUsingValue() {
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader :value \"lt\" :comparator \"i;ascii-numeric\" \"X-Numeric-Header\" \"3\" \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-Numeric-Header".equals(header.getName()) && Integer.valueOf(header.getValue()) < 3) {
matchFound = true;
break;
}
}
Assert.assertFalse(matchFound);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testDeleteHeaderUsingMatchesNonASCII.
/*
* Delete header using matches match-type whose key is non-ASCII
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteHeaderUsingMatchesNonASCII() {
try {
String filterScript = "require [\"editheader\"];\n" + "deleteheader :comparator \"i;ascii-casemap\" :is \"X-Test-Header-non-ascii\" \"日本語の件名\";\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-non-ascii".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.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class DeleteHeaderTest method testDeleteNoValuePattern.
/*
* delete header when value-patterns specified is empty should return false
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteNoValuePattern() {
try {
String filterScript = "require [\"editheader\"];\n" + " deleteheader :count \"gt\" :comparator \"i;ascii-numeric\" \"Subject\" \"\" \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 ("Subject".equals(header.getName())) {
matchFound = true;
}
}
Assert.assertTrue(matchFound);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class AddressTest method compareEmptyStringWithAsciiNumeric.
@Test
public void compareEmptyStringWithAsciiNumeric() {
try {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(acct);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
String filterScript = "if address :is :comparator \"i;ascii-numeric\" \"To\" \"\" {" + " tag \"compareEmptyStringWithAsciiNumeric\";" + "}";
acct.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: test1@zimbra.com".getBytes(), false), 0, acct.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("compareEmptyStringWithAsciiNumeric", ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class AddressTest method compareHeaderNameWithLeadingSpaces.
@Test
public void compareHeaderNameWithLeadingSpaces() {
try {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(acct);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
String filterScript = "require [\"tag\"];\n" + "if address :is :comparator \"i;ascii-numeric\" \" To\" \"test1@zimbra.com\" {" + " tag \"t1\";" + "}";
acct.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: test1@zimbra.com".getBytes(), false), 0, acct.getName(), 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");
}
}
Aggregations