Search in sources :

Example 56 with LmtpEnvelope

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

the class EnvelopeTest method testHeaderNameWithTrailingSpace.

@Test
public void testHeaderNameWithTrailingSpace() {
    String filterScript = "require \"envelope\";\n" + "if envelope :matches \"TO \" \"*@zimbra.com\" {\n" + "    tag \"t1\";\n" + "}\n";
    LmtpEnvelope env = new LmtpEnvelope();
    LmtpAddress sender = new LmtpAddress("<>", new String[] { "BODY", "SIZE" }, null);
    LmtpAddress recipient = new LmtpAddress("<xyz@zimbra.com>", null, null);
    env.setSender(sender);
    env.addLocalRecipient(recipient);
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.createAccount("xyz@zimbra.com", "secret", new HashMap<String, Object>());
        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(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) 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) Provisioning(com.zimbra.cs.account.Provisioning) Mailbox(com.zimbra.cs.mailbox.Mailbox) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Aggregations

LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)56 Account (com.zimbra.cs.account.Account)54 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)54 Mailbox (com.zimbra.cs.mailbox.Mailbox)54 OperationContext (com.zimbra.cs.mailbox.OperationContext)54 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)54 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)53 ItemId (com.zimbra.cs.service.util.ItemId)49 Message (com.zimbra.cs.mailbox.Message)46 Test (org.junit.Test)42 MimeMessage (javax.mail.internet.MimeMessage)11 Provisioning (com.zimbra.cs.account.Provisioning)8 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)8 SyntaxException (org.apache.jsieve.exception.SyntaxException)8 Ignore (org.junit.Ignore)5 DeliveryServiceException (com.zimbra.common.service.DeliveryServiceException)2 ServiceException (com.zimbra.common.service.ServiceException)2 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)2 ErejectException (com.zimbra.cs.filter.jsieve.ErejectException)2 MPartInfo (com.zimbra.cs.mime.MPartInfo)2