use of com.zimbra.cs.lmtpserver.LmtpAddress in project zm-mailbox by Zimbra.
the class RejectTest method testNotemptyEnvelopeFrom.
/*
* MDN should be sent to the envelope from (testRej2@zimbra.com)
*/
@Ignore
public /*Bug ZCS-1708 */
void testNotemptyEnvelopeFrom() {
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "testRej@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "testRej2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
RuleManager.clearCachedRules(acct1);
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<testRej2@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<testRej@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
acct1.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleBaseMsg.getBytes(), false), 0, acct1.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(0, ids.size());
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message mdnMsg = mbox2.getMessageById(null, item);
String ctStr = mdnMsg.getMimeMessage().getContentType().toLowerCase();
boolean isReport = ctStr.startsWith("multipart/report;");
boolean isMdn = ctStr.indexOf("report-type=disposition-notification") < 0 ? false : true;
Assert.assertEquals(isReport & isMdn, true);
} catch (Exception e) {
fail("No exception should be thrown: " + e.getMessage());
}
}
use of com.zimbra.cs.lmtpserver.LmtpAddress in project zm-mailbox by Zimbra.
the class SetVariableTest method testVariables_Envelope_KeyList.
@Test
public void testVariables_Envelope_KeyList() {
String sampleMsg = "from: tim@example.com\n" + "to: test@zimbra.com\n" + "Subject: Example\n";
String filterScript = "require [\"envelope\", \"variables\", \"tag\"];\n" + "set \"from_address\" \"tim@example.com\";" + "set \"to_address\" \"test1@zimbra.com\";" + "set \"from_header_name\" \"From\";" + "if envelope :all :is \"from\" [\"to_address\", \"${from_address}\"] {\n" + " tag \"KeyListTag\";" + "}";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<tim@example.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient = new LmtpAddress("<test1@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient);
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
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());
String[] tags = msg.getTags();
Assert.assertEquals(1, tags.length);
Assert.assertEquals("KeyListTag", tags[0]);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.lmtpserver.LmtpAddress in project zm-mailbox by Zimbra.
the class SetVariableTest method testVariables_Header_HeaderNames.
@Test
public void testVariables_Header_HeaderNames() {
try {
String sampleMsg = "Received: from edge01e.zimbra.com ([127.0.0.1])\n" + "\tby localhost (edge01e.zimbra.com [127.0.0.1]) (amavisd-new, port 10032)\n" + "\twith ESMTP id DN6rfD1RkHD7; Fri, 24 Jun 2016 01:45:31 -0400 (EDT)\n" + "Received: from localhost (localhost [127.0.0.1])\n" + "\tby edge01e.zimbra.com (Postfix) with ESMTP id 9245B13575C;\n" + "\tFri, 24 Jun 2016 01:45:31 -0400 (EDT)\n" + "x-priority: 1\n" + "from: tim@zimbra.com\n" + "Subject: =?ISO-2022-JP?B?GyRCJDMkcyRLJEEkTxsoQg==?=\n" + "to: test1@zimbra.com, test2@zimbra.com\n";
String filterScript = "require [\"variables\", \"tag\"];\n" + "set \"header_name\" \"x-priority\";" + "if header :contains [\"${header_name}\"] [\"\"] { tag \"zimbra\"; }";
LmtpEnvelope env = new LmtpEnvelope();
LmtpAddress sender = new LmtpAddress("<tim@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
LmtpAddress recipient1 = new LmtpAddress("<test1@zimbra.com>", null, null);
LmtpAddress recipient2 = new LmtpAddress("<test2@zimbra.com>", null, null);
env.setSender(sender);
env.addLocalRecipient(recipient1);
env.addLocalRecipient(recipient2);
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
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("zimbra", ArrayUtil.getFirstElement(msg.getTags()));
} 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 testEmptyMessageBody.
@Test
public void testEmptyMessageBody() {
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_EmptyBodyParameter);
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("", 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 test.
/**
* Tests 'notify' filter rule:
* - Set :message (Subject field), :from (From field) and mechanism (mailto:...)
* - Body of the notification message contains non-ascii characters
* - Additional header fields are specified via mechanism (maito:) parameter
*/
@Test
public void test() {
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);
RuleManager.clearCachedRules(acct1);
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);
acct1.setMailSieveScript(filterScript1);
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());
boolean header1 = false;
boolean header2 = false;
boolean header3 = false;
boolean header4 = false;
for (Enumeration<Header> e = notifyMsg.getMimeMessage().getAllHeaders(); e.hasMoreElements(); ) {
Header temp = e.nextElement();
if ("X-HEADER1".equals(temp.getName())) {
header1 = true;
}
if ("X-header2".equals(temp.getName())) {
header2 = true;
}
if ("X-HeAdEr3".equals(temp.getName())) {
header3 = true;
}
if ("X-hEader4".equals(temp.getName())) {
header4 = true;
}
}
Assert.assertTrue(header1);
Assert.assertTrue(header2);
Assert.assertTrue(header3);
Assert.assertTrue(header4);
notifyMsg = mbox3.getMessageById(null, item);
Assert.assertEquals("おしらせ", notifyMsg.getSubject());
} catch (Exception e) {
fail("No exception should be thrown");
}
}
Aggregations