Search in sources :

Example 16 with OperationContext

use of com.zimbra.cs.mailbox.OperationContext 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");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 17 with OperationContext

use of com.zimbra.cs.mailbox.OperationContext 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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test) BulkTest(com.zimbra.cs.filter.jsieve.BulkTest)

Example 18 with OperationContext

use of com.zimbra.cs.mailbox.OperationContext 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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test) BulkTest(com.zimbra.cs.filter.jsieve.BulkTest)

Example 19 with OperationContext

use of com.zimbra.cs.mailbox.OperationContext 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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId)

Example 20 with OperationContext

use of com.zimbra.cs.mailbox.OperationContext 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));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

OperationContext (com.zimbra.cs.mailbox.OperationContext)396 Mailbox (com.zimbra.cs.mailbox.Mailbox)365 Account (com.zimbra.cs.account.Account)292 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)266 Message (com.zimbra.cs.mailbox.Message)256 Test (org.junit.Test)255 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)249 ItemId (com.zimbra.cs.service.util.ItemId)231 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)82 MimeMessage (javax.mail.internet.MimeMessage)82 Element (com.zimbra.common.soap.Element)80 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)72 Header (javax.mail.Header)66 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)52 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)50 SyntaxException (org.apache.jsieve.exception.SyntaxException)47 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)46 ServiceException (com.zimbra.common.service.ServiceException)36 Folder (com.zimbra.cs.mailbox.Folder)27 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)26