Methods Summary |
---|
protected javax.mail.internet.MimeMessage | getMessageFromSources(java.lang.String sources)
MimeMessageInputStreamSource mmis = null;
try {
mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
} catch (MessagingException e) {
}
return new TestableMimeMessageWrapper(mmis);
|
protected void | setUp()
mw = (TestableMimeMessageWrapper) getMessageFromSources(content+sep+body);
|
protected void | tearDown()
ContainerUtil.dispose(mw);
|
public void | testAddHeaderAndSave()
try {
mw.addHeader("X-Test", "X-Value");
assertEquals("X-Value", mw.getHeader("X-Test")[0]);
mw.saveChanges();
ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
mw.writeTo(rawMessage);
assertEquals("X-Value", mw.getHeader("X-Test")[0]);
String res = rawMessage.toString();
boolean found = res.indexOf("X-Test: X-Value") > 0;
assertEquals(true,found);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|
public void | testAddReturnPathOnBadMessage()
MimeMessage message = getMessageWithBadReturnPath();
message.addHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
// test that we have now 2 return-paths
Enumeration e = message.getMatchingHeaderLines(new String[] {"Return-Path"});
assertEquals("Return-Path: <test@test.de>",e.nextElement());
assertEquals("Return-Path: <mybadreturn@example.com>",e.nextElement());
// test that return-path is the first line
Enumeration h = message.getAllHeaderLines();
assertEquals("Return-Path: <test@test.de>",h.nextElement());
|
public void | testDeferredHeaderLoading()this is commented out due optimisation reverts (JAMES-559)
public void testDeferredMessageLoadingWhileWriting() throws MessagingException, IOException {
mw.setMessageLoadable(false);
assertEquals("foo",mw.getSubject());
assertFalse(mw.isModified());
mw.setSubject("newSubject");
assertEquals("newSubject",mw.getSubject());
assertFalse(mw.messageParsed());
assertTrue(mw.isModified());
mw.setMessageLoadable(true);
}
mw.setHeadersLoadable(false);
try {
assertEquals("foo",mw.getSubject());
fail("subject should not be loadable here, headers loading is disabled");
} catch (IllegalStateException e) {
}
|
public void | testDeferredMessageLoading()
assertEquals("foo",mw.getSubject());
assertFalse(mw.messageParsed());
assertEquals("bar\r\n",mw.getContent());
assertTrue(mw.messageParsed());
assertFalse(mw.isModified());
|
public void | testGetSubjectFolding()
try {
StringBuffer res = new StringBuffer();
BufferedReader r = new BufferedReader(new InputStreamReader(mw.getInputStream()));
String line;
while (r.ready()) {
line = r.readLine();
res.append(line+"\r\n");
}
r.close();
assertEquals(body,res.toString());
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|
public void | testMessageCloned()See JAMES-474
MimeMessageWrapper(MimeMessage) should clone the original message.
MimeMessageWrapper mmw = new MimeMessageWrapper(mw);
ContainerUtil.dispose(mw);
mw = null;
System.gc();
Thread.sleep(200);
mmw.writeTo(System.out);
|
public void | testReplaceReturnPathOnBadMessage()
MimeMessage message = getMessageWithBadReturnPath();
message.setHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
Enumeration e = message.getMatchingHeaderLines(new String[] {"Return-Path"});
assertEquals("Return-Path: <test@test.de>",e.nextElement());
assertFalse(e.hasMoreElements());
Enumeration h = message.getAllHeaderLines();
assertEquals("Return-Path: <test@test.de>",h.nextElement());
assertFalse(h.nextElement().toString().startsWith("Return-Path:"));
|