use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class AddressTest method testAddressContainingDot.
@Test
public void testAddressContainingDot() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String filterScript = "if address :comparator \"i;ascii-casemap\" :matches \"to\" \"user.1@cosmonaut.zimbra.com\" {" + " tag \"TestDot\";" + "}";
account.setMailSieveScript(filterScript);
InputStream is = getClass().getResourceAsStream("TestFilter-testBackslashDotInAddress.msg");
MimeMessage mm = new ZMimeMessage(JMSession.getSession(), is);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(mm, 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("TestDot", ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class AddHeaderTest method testAddHeaderNameAsMultipleSpace.
/*
* Try adding new header with multiple spaces as header name, which should fail
*/
@Test
public void testAddHeaderNameAsMultipleSpace() {
try {
String filterScript = "require [\"editheader\"];\n" + " addheader \" \" \"my-new-header-value\" \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 mdnMsg = mbox1.getMessageById(null, itemId);
for (Enumeration<Header> e = mdnMsg.getMimeMessage().getAllHeaders(); e.hasMoreElements(); ) {
Header temp = e.nextElement();
Assert.assertFalse(temp.getValue().equals("my-new-header-value"));
}
} 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 AddHeaderTest method testAddHeader.
/*
* Adding new header
*/
@Test
public void testAddHeader() {
try {
String filterScript = "require [\"editheader\"];\n" + "if header :contains \"Subject\" \"example\" {\n" + " addheader \"my-new-header\" \"my-new-header-value\" \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);
int index = 0;
Message mdnMsg = mbox1.getMessageById(null, itemId);
for (Enumeration<Header> e = mdnMsg.getMimeMessage().getAllHeaders(); e.hasMoreElements(); ) {
Header temp = e.nextElement();
index++;
if ("my-new-header".equals(temp.getName())) {
break;
}
}
// the header field is inserted at the beginning of the existing message header.
Assert.assertEquals(1, index);
} 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 EscapeSequencesTest method doTestHeaderEscapePattern.
/*
* MAIL FROM: <user123@zimbra.com>
* RCPT TO: <test1@zimbra.com>
* DATA
* To: user123@zimbra.com
* From: sender@zimbra.com
* Subject: test\123
* X-Header-0BackSlash: testSample
* X-Header-1BaskSlash: test\Sample
* X-Header-2BackSlash: test\\Sample
* X-Header-DoubleQuote: test"Sample
*/
public void doTestHeaderEscapePattern(String filterScript) {
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<user123@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
RuleManager.clearCachedRules(account);
account.setMailSieveScript(filterScript);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.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(1, msg.getTags().length);
Assert.assertEquals("list", msg.getTags()[0]);
} catch (Exception e) {
fail("No exception should be thrown " + e);
}
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class EscapeSequencesTest method doTestReplaceheaderEscapePattern.
private void doTestReplaceheaderEscapePattern(String filterScript) {
try {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.setMailSieveScript(filterScript);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.getBytes(), false), 0, account.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox.getMessageById(null, itemId);
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements(); ) {
Header header = enumeration.nextElement();
if ("Subject".equals(header.getName())) {
Assert.assertEquals("[replaced]", header.getValue());
break;
}
}
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
Aggregations