Search in sources :

Example 21 with DeliveryContext

use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.

the class BulkTestTest method zimbraOOO.

@Test
public void zimbraOOO() throws Exception {
    //negative test; don't mark these as bulk
    List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("From: sender@zimbra.com\nPrecedence: bulk\nAuto-Submitted: auto-replied (zimbra; vacation)\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.assertNull(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 22 with DeliveryContext

use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.

the class AddHeaderTest method testAddHeaderSameHeaderNameMultipleHeaderValues1.

/*
     * Add the headers with "X-Dummy-Header: new value"
     * Verify that the order of the header fields does not change.
     */
@SuppressWarnings("unchecked")
@Test
public void testAddHeaderSameHeaderNameMultipleHeaderValues1() {
    StringBuffer triggeringMsg = new StringBuffer();
    for (String line : sampleBaseMsg2) {
        triggeringMsg.append(line).append("\r\n");
    }
    try {
        String filterScript = "require [\"editheader\"];\n" + "addheader \"X-Dummy-Header\" \"new value\"; ";
        Account account = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(triggeringMsg.toString().getBytes(), false), 0, account.getName(), null, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        Message msg = mbox.getMessageById(null, ids.get(0).getId());
        Enumeration e = msg.getMimeMessage().getAllHeaderLines();
        Assert.assertTrue(e.hasMoreElements());
        // The 1st and 2nd line of the headers
        Assert.assertEquals("Return-Path: user1@domain1.zimbra.com", (String) e.nextElement());
        Assert.assertEquals("X-Dummy-Header: new value", (String) e.nextElement());
        // The rest of the headers
        int index = 1;
        while (e.hasMoreElements() && index < sampleBaseMsg2.length) {
            String value = (String) e.nextElement();
            Assert.assertEquals(sampleBaseMsg2[index++], value);
        }
    } catch (Exception e) {
        fail("No exception should be thrown: " + e.getMessage());
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Enumeration(java.util.Enumeration) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 23 with DeliveryContext

use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.

the class AddressBookTestTest method filter.

@Test
public void filter() throws Exception {
    Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    RuleManager.clearCachedRules(account);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    mbox.createContact(null, new ParsedContact(Collections.<String, Object>singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
    account.setMailSieveScript("if addressbook :in \"From\" { tag \"Priority\"; }");
    List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com".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("Priority", ArrayUtil.getFirstElement(msg.getTags()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ParsedContact(com.zimbra.cs.mime.ParsedContact) 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) Test(org.junit.Test)

Example 24 with DeliveryContext

use of com.zimbra.cs.mailbox.DeliveryContext in project zm-mailbox by Zimbra.

the class AddressTest method testAddressContainingBackslash.

@Test
public void testAddressContainingBackslash() {
    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 \"from\" \"\\\"user\\\\1\\\"@cosmonaut.zimbra.com\" {" + "  tag \"TestBackslash\";" + "}";
        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("TestBackslash", ArrayUtil.getFirstElement(msg.getTags()));
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) InputStream(java.io.InputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 25 with DeliveryContext

use of com.zimbra.cs.mailbox.DeliveryContext 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());
    }
}
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) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Header(javax.mail.Header) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Aggregations

DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)253 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)253 OperationContext (com.zimbra.cs.mailbox.OperationContext)249 Mailbox (com.zimbra.cs.mailbox.Mailbox)243 Account (com.zimbra.cs.account.Account)242 Message (com.zimbra.cs.mailbox.Message)235 Test (org.junit.Test)223 ItemId (com.zimbra.cs.service.util.ItemId)168 Header (javax.mail.Header)66 MimeMessage (javax.mail.internet.MimeMessage)64 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)52 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)50 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)49 SyntaxException (org.apache.jsieve.exception.SyntaxException)47 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)23 Ignore (org.junit.Ignore)11 InputStream (java.io.InputStream)10 MockProvisioning (com.zimbra.cs.account.MockProvisioning)9 Provisioning (com.zimbra.cs.account.Provisioning)9 BulkTest (com.zimbra.cs.filter.jsieve.BulkTest)6