use of com.zimbra.cs.mime.ParsedMessage 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.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class BulkTestTest method proofpoint.
@Test
public void proofpoint() throws Exception {
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage(("To: list@zimbra.com\nX-Proofpoint-Spam-Details: rule=tag_notspam policy=tag " + "score=0 spamscore=0 ipscore=0 suspectscore=49 phishscore=0 bulkscore=100 adultscore=0 " + "classifier=spam adjust=0 reason=mlx engine=6.0.2-1012030000 definitions=main-1108230088\n" + "Subject: bulk").getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("bulk", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class BulkTestTest method unsubscribe.
@Test
public void unsubscribe() throws Exception {
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("To: list@zimbra.com\nList-Unsubscribe: test\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals(0, msg.getTags().length);
ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("To: test@zimbra.com\nList-Unsubscribe: test\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
msg = mailbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("bulk", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mime.ParsedMessage in project zm-mailbox by Zimbra.
the class CommunityTestTest method doRequest.
public void doRequest(String rule, String headerValue, String tag) throws Exception {
account.setMailSieveScript("if " + rule + " { tag \"" + tag + "\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(("From: \"in.Telligent\" <noreply@in.telligent.com>\n" + "X-Zimbra-Community-Notification-Type: " + headerValue + "\n").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(tag, ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mime.ParsedMessage 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));
}
Aggregations