Search in sources :

Example 21 with ItemId

use of com.zimbra.cs.service.util.ItemId 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 22 with ItemId

use of com.zimbra.cs.service.util.ItemId 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 23 with ItemId

use of com.zimbra.cs.service.util.ItemId 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");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) 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 ItemId

use of com.zimbra.cs.service.util.ItemId 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");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) 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 25 with ItemId

use of com.zimbra.cs.service.util.ItemId 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);
    }
}
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)

Aggregations

ItemId (com.zimbra.cs.service.util.ItemId)327 Mailbox (com.zimbra.cs.mailbox.Mailbox)243 OperationContext (com.zimbra.cs.mailbox.OperationContext)231 Account (com.zimbra.cs.account.Account)219 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)189 Message (com.zimbra.cs.mailbox.Message)185 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)168 Test (org.junit.Test)161 Element (com.zimbra.common.soap.Element)81 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)80 MimeMessage (javax.mail.internet.MimeMessage)65 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)58 ServiceException (com.zimbra.common.service.ServiceException)52 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)47 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)45 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 SyntaxException (org.apache.jsieve.exception.SyntaxException)42 Folder (com.zimbra.cs.mailbox.Folder)33 ArrayList (java.util.ArrayList)30 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)29