use of com.zimbra.common.zmime.ZMimeMessage 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);
}
}
use of com.zimbra.common.zmime.ZMimeMessage 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);
}
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class ImapPartSpecifierTest method structure.
@Test
public void structure() throws Exception {
InputStream is = getClass().getResourceAsStream("toplevel-nested-message");
MimeMessage mm = new ZMimeMessage(JMSession.getSession(), is);
checkBody(mm, "", "HEADER", "X-Gmail-Received: ea9cadad8b81db887fe7ca769a31384c1468b618", "X-OriginalArrivalTime: 24 Feb 2005 01:28:49.0382 (UTC) FILETIME=[31002860:01C51A10]");
checkBody(mm, "", "TEXT", "Return-Path: <pubcookie-dev-bounces@mailman.u.washington.edu>", "http://mailman.u.washington.edu/mailman/listinfo/pubcookie-dev");
checkBody(mm, "1", "", "Return-Path: <pubcookie-dev-bounces@mailman.u.washington.edu>", "http://mailman.u.washington.edu/mailman/listinfo/pubcookie-dev");
checkBody(mm, "1.1", "", "On Fri, 27 Feb 2004, Jim Fox wrote:", "http://mailman.u.washington.edu/mailman/listinfo/pubcookie-dev");
checkBody(mm, "1", "MIME", "X-Gmail-Received: ea9cadad8b81db887fe7ca769a31384c1468b618", "X-OriginalArrivalTime: 24 Feb 2005 01:28:49.0382 (UTC) FILETIME=[31002860:01C51A10]");
checkBody(mm, "1", "HEADER", "Return-Path: <pubcookie-dev-bounces@mailman.u.washington.edu>", "X-Evolution: 00000001-0110");
checkBody(mm, "1", "TEXT", "On Fri, 27 Feb 2004, Jim Fox wrote:", "http://mailman.u.washington.edu/mailman/listinfo/pubcookie-dev");
checkBody(mm, "1.1", "MIME", "Return-Path: <pubcookie-dev-bounces@mailman.u.washington.edu>", "X-Evolution: 00000001-0110");
checkPartial(mm, "", "", 0, 100000, "Return-Path: <pubcookie-dev-bounces@mailman.u.washington.edu>", "http://mailman.u.washington.edu/mailman/listinfo/pubcookie-dev");
checkPartial(mm, "", "", 0, 10, "Return-Pat", "Pat");
checkPartial(mm, "", "", 1, 10, "eturn-Path", "Path");
checkPartial(mm, "", "", 100000, 10, "", "");
is = getClass().getResourceAsStream("calendar-bounce");
mm = new ZMimeMessage(JMSession.getSession(), is);
checkBody(mm, "", "HEADER", "Received: from localhost (localhost.localdomain [127.0.0.1])", "Message-Id: <20061109004631.07DB1810C39@mta02.zimbra.com>");
checkBody(mm, "", "TEXT", "This is a MIME-encapsulated message.", "--6E4E3810C27.1163033191/mta02.zimbra.com--");
checkBody(mm, "1", "", "This is the Postfix program at host mta02.zimbra.com.", "c18si105209hub (in reply to RCPT TO command)");
checkBody(mm, "1", "MIME", "Content-Description: Notification", "Content-Type: text/plain");
checkBody(mm, "2", "", "Reporting-MTA: dns; mta02.zimbra.com", "said: 550 5.1.1 No such user c18si105209hub (in reply to RCPT TO command)");
checkBody(mm, "2", "MIME", "Content-Description: Delivery report", "Content-Type: message/delivery-status");
checkBody(mm, "3", "", "Received: from dogfood.zimbra.com (dogfood.liquidsys.com [66.92.25.198])", "------=_Part_235_901532167.1163033483782--");
checkBody(mm, "3", "MIME", "Content-Description: Undelivered Message", "Content-Transfer-Encoding: 8bit");
checkBody(mm, "3", "HEADER", "Received: from dogfood.zimbra.com (dogfood.liquidsys.com [66.92.25.198])", "boundary=\"----=_Part_235_901532167.1163033483782\"");
checkBody(mm, "3", "TEXT", "------=_Part_235_901532167.1163033483782", "------=_Part_235_901532167.1163033483782--");
checkBody(mm, "3.1", "", "The following is a new meeting request:", "Testing bounce messages.");
checkBody(mm, "3.1", "MIME", "Content-Type: text/plain; charset=utf-8", "Content-Transfer-Encoding: 7bit");
checkBody(mm, "3.2", "", "<html><body><h3>The following is a new meeting request:</h3>", "<div>*~*~*~*~*~*~*~*~*~*</div><br>Testing bounce messages.</body></html>");
checkBody(mm, "3.2", "MIME", "Content-Type: text/html; charset=utf-8", "Content-Transfer-Encoding: 7bit");
checkBody(mm, "3.3", "", "BEGIN:VCALENDAR", "END:VCALENDAR");
checkBody(mm, "3.3", "MIME", "Content-Type: text/calendar; name=meeting.ics; method=REQUEST; charset=utf-8", "Content-Transfer-Encoding: 7bit");
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class SmtpTransportTest method dataError.
@Test(timeout = 3000)
public void dataError() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("451 error").recvLine().build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
transport.connect("localhost", PORT, null, null);
String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest";
MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
try {
transport.sendMessage(msg, msg.getAllRecipients());
Assert.fail();
} catch (SendFailedException e) {
Assert.assertEquals(1, e.getValidSentAddresses().length);
Assert.assertEquals(0, e.getValidUnsentAddresses().length);
Assert.assertEquals(0, e.getInvalidAddresses().length);
} finally {
transport.close();
}
server.shutdown(1000);
Assert.assertEquals("EHLO localhost\r\n", server.replay());
Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay());
Assert.assertEquals("DATA\r\n", server.replay());
Assert.assertEquals("QUIT\r\n", server.replay());
Assert.assertNull(server.replay());
}
use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.
the class SmtpTransportTest method quitNoResponse.
@Test(timeout = 3000)
public void quitNoResponse() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("354 OK").swallowUntil("\r\n.\r\n").sendLine("250 OK").recvLine().build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
transport.connect("localhost", PORT, null, null);
String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest";
MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
server.shutdown(1000);
Assert.assertEquals("EHLO localhost\r\n", server.replay());
Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay());
Assert.assertEquals("DATA\r\n", server.replay());
Assert.assertEquals("QUIT\r\n", server.replay());
Assert.assertNull(server.replay());
}
Aggregations