Search in sources :

Example 36 with LmtpAddress

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

the class NotifyMailtoTest method testNotOverridableParams.

/**
 * Verify the "header fields of the notification message
 * that are normally related to an individual new message
 * (such as "Message-ID" and "Date") are generated for the
 * notification message in the normal manner, and MUST NOT
 * be copied from the triggering message" (RFC 5436-2.7)
 */
@Test
public void testNotOverridableParams() {
    String sampleMsg = "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: test1@zimbra.com\n";
    try {
        Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
        Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
        Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
        Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
        Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
        Mailbox mbox3 = MailboxManager.getInstance().getMailboxByAccount(acct3);
        RuleManager.clearCachedRules(acct1);
        LmtpEnvelope env = new LmtpEnvelope();
        LmtpAddress sender = new LmtpAddress("<xyz@example.com>", new String[] { "BODY", "SIZE" }, null);
        LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
        env.setSender(sender);
        env.addLocalRecipient(recipient);
        acct1.setMailSieveScript(filterScript_MsgIDDate);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        // The triggered message should be delivered to the target mailbox
        Assert.assertEquals(1, ids.size());
        // Notification message should be delivered to mailto and to= addresses
        Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
        Message notifyMsg = mbox2.getMessageById(null, item);
        Assert.assertEquals("notifybody", notifyMsg.getFragment());
        String[] headers = notifyMsg.getMimeMessage().getHeader("Message-ID");
        Assert.assertTrue(headers.length == 1);
        Assert.assertNotSame("dummymessageid", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("Date");
        Assert.assertTrue(headers.length == 1);
        Assert.assertNotSame("dummydate", headers[0]);
    } catch (Exception e) {
        fail("No exception should be thrown:" + e);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) 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) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 37 with LmtpAddress

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

the class NotifyMailtoTest method testNoMessage.

@Test
public void testNoMessage() {
    String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: test1@zimbra.com\n";
    try {
        Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
        Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
        Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
        Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
        Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
        Mailbox mbox3 = MailboxManager.getInstance().getMailboxByAccount(acct3);
        RuleManager.clearCachedRules(acct1);
        LmtpEnvelope env = new LmtpEnvelope();
        LmtpAddress sender = new LmtpAddress("<xyz@example.com>", new String[] { "BODY", "SIZE" }, null);
        LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
        env.setSender(sender);
        env.addLocalRecipient(recipient);
        acct1.setMailSieveScript(filterScript_NoMessage);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        // The triggered message should be delivered to the target mailbox
        Assert.assertEquals(1, ids.size());
        // Notification message should be delivered to mailto and to= addresses
        Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
        Message notifyMsg = mbox2.getMessageById(null, item);
        Assert.assertEquals("新しいメールが届きました。 You've got a mail. Chao!", notifyMsg.getFragment());
        String[] headers = notifyMsg.getMimeMessage().getHeader("Auto-Submitted");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("auto-notified; owner-email=\"test1@zimbra.com\"", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("to");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("test2@zimbra.com, test3@zimbra.com", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("from");
        Assert.assertFalse(notifyMsg.getSender() == null);
        Assert.assertEquals("test1@zimbra.com", notifyMsg.getSender());
        notifyMsg = mbox3.getMessageById(null, item);
        Assert.assertEquals("じゅげむ じゅげむ ごこうのすりきれ かいじゃりすいぎょの すいぎょうまつ うんらいまつ ふうらいまつ くうねるところにすむところ やぶらこうじのぶらこうじ ぱいぽ ぱいぽ ぱいぽのしゅーりんがん しゅーりんがんのぐーりんだい ぐーりんだいのぽんぽこぴーの ぽんぽこなーの ちょうきゅうめいのちょうすけ", notifyMsg.getSubject());
    } 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) MimeMessage(javax.mail.internet.MimeMessage) 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) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 38 with LmtpAddress

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

the class NotifyMailtoTest method testNoMessageNoSubjectInURL.

@Test
public void testNoMessageNoSubjectInURL() {
    String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: test1@zimbra.com\n";
    try {
        Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
        Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
        Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
        Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
        Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
        Mailbox mbox3 = MailboxManager.getInstance().getMailboxByAccount(acct3);
        RuleManager.clearCachedRules(acct1);
        LmtpEnvelope env = new LmtpEnvelope();
        LmtpAddress sender = new LmtpAddress("<xyz@example.com>", new String[] { "BODY", "SIZE" }, null);
        LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
        env.setSender(sender);
        env.addLocalRecipient(recipient);
        acct1.setMailSieveScript(filterScript_NoMessageNoSubjectInURL);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        // The triggered message should be delivered to the target mailbox
        Assert.assertEquals(1, ids.size());
        // Notification message should be delivered to mailto and to= addresses
        Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
        Message notifyMsg = mbox2.getMessageById(null, item);
        Assert.assertEquals("新しいメールが届きました。 You've got a mail. Chao!", notifyMsg.getFragment());
        String[] headers = notifyMsg.getMimeMessage().getHeader("Auto-Submitted");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("auto-notified; owner-email=\"test1@zimbra.com\"", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("to");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("test2@zimbra.com, test3@zimbra.com", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("from");
        Assert.assertFalse(notifyMsg.getSender() == null);
        Assert.assertEquals("test1@zimbra.com", notifyMsg.getSender());
        notifyMsg = mbox3.getMessageById(null, item);
        Assert.assertEquals("[acme-users] [fwd] version 1.0 is out", notifyMsg.getSubject());
    } 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) MimeMessage(javax.mail.internet.MimeMessage) 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) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 39 with LmtpAddress

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

the class NotifyMailtoTest method fromTag.

/**
 * == (triggering message) ==
 * LMTP; MAIL FROM: &lt;xyz@example.com&gt;
 * LMTP; RCPT TO: &lt;test1@zimbra.com&gt;
 * LMTP; DATA
 * From: xyz@example.com
 * to: test1@zimbra.com
 *
 * == (generated notification message) ==
 * SMTP; MAIL FROM: &lt;test1@zimbra.com&gt;
 * SMTP; RCPT TO: &lt;test2@zimbra.com&gt;
 * SMTP; DATA
 * From: test1@zimbra.com
 * To: test2@zimbra.com
 * Subject: おしらせ
 *
 * 新しいメールが届きました。
 * You've got a mail.
 * Chao!
 */
private void fromTag(String script) {
    String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: foo@example.com, baz@example.com\n" + "cc: qux@example.com\n";
    try {
        Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
        Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
        Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
        Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
        Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
        Mailbox mbox3 = MailboxManager.getInstance().getMailboxByAccount(acct3);
        acct1.setMail("test1@zimbra.com");
        RuleManager.clearCachedRules(acct1);
        LmtpEnvelope env = new LmtpEnvelope();
        LmtpAddress sender = new LmtpAddress("<xyz@example.com>", new String[] { "BODY", "SIZE" }, null);
        LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
        env.setSender(sender);
        env.addLocalRecipient(recipient);
        acct1.setMailSieveScript(script);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        // The triggered message should be delivered to the target mailbox
        Assert.assertEquals(1, ids.size());
        // Notification message should be delivered to mailto and to= addresses
        Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
        Message notifyMsg = mbox2.getMessageById(null, item);
        Assert.assertEquals("新しいメールが届きました。 You've got a mail. Chao!", notifyMsg.getFragment());
        String[] headers = notifyMsg.getMimeMessage().getHeader("Auto-Submitted");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("auto-notified; owner-email=\"test1@zimbra.com\"", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("to");
        Assert.assertTrue(headers.length == 1);
        Assert.assertEquals("test2@zimbra.com, test3@zimbra.com", headers[0]);
        headers = notifyMsg.getMimeMessage().getHeader("from");
        Assert.assertFalse(notifyMsg.getSender() == null);
        Assert.assertEquals("test1@zimbra.com", notifyMsg.getSender());
        notifyMsg = mbox3.getMessageById(null, item);
        Assert.assertEquals("おしらせ", notifyMsg.getSubject());
    } 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) MimeMessage(javax.mail.internet.MimeMessage) 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) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext)

Example 40 with LmtpAddress

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

the class HeaderTest method setEnvelopeInfo.

private LmtpEnvelope setEnvelopeInfo() {
    LmtpEnvelope env = new LmtpEnvelope();
    LmtpAddress sender = new LmtpAddress("<abc@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
    LmtpAddress recipient1 = new LmtpAddress("<xyz@zimbra.com>", null, null);
    LmtpAddress recipient2 = new LmtpAddress("<uvw@zimbra.com>", null, null);
    env.setSender(sender);
    env.addLocalRecipient(recipient1);
    env.addLocalRecipient(recipient2);
    return env;
}
Also used : LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope)

Aggregations

LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)55 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)53 Account (com.zimbra.cs.account.Account)51 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)51 Mailbox (com.zimbra.cs.mailbox.Mailbox)51 OperationContext (com.zimbra.cs.mailbox.OperationContext)51 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)51 ItemId (com.zimbra.cs.service.util.ItemId)46 Message (com.zimbra.cs.mailbox.Message)43 Test (org.junit.Test)41 MimeMessage (javax.mail.internet.MimeMessage)9 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 ServiceException (com.zimbra.common.service.ServiceException)3 DeliveryServiceException (com.zimbra.common.service.DeliveryServiceException)2 ErejectException (com.zimbra.cs.filter.jsieve.ErejectException)2 MPartInfo (com.zimbra.cs.mime.MPartInfo)2 List (java.util.List)2