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);
}
}
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");
}
}
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");
}
}
use of com.zimbra.cs.lmtpserver.LmtpAddress in project zm-mailbox by Zimbra.
the class NotifyMailtoTest method fromTag.
/**
* == (triggering message) ==
* LMTP; MAIL FROM: <xyz@example.com>
* LMTP; RCPT TO: <test1@zimbra.com>
* LMTP; DATA
* From: xyz@example.com
* to: test1@zimbra.com
*
* == (generated notification message) ==
* SMTP; MAIL FROM: <test1@zimbra.com>
* SMTP; RCPT TO: <test2@zimbra.com>
* 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");
}
}
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;
}
Aggregations