use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class TestParsedMessage method testMimeMutator.
/**
* Tests message mutation. We can't verify the entire content, since mutation
* calls JavaMail, which mangles the headers. We'll have to settle for confirming
* that the subject was updated correctly.
*/
@Test
public void testMimeMutator() throws Exception {
MimeVisitor.registerMutator(TestMimeVisitor.class);
String subject = NAME_PREFIX + " testMimeConverter oldsubject";
String content = TestUtil.getTestMessage(subject, RECIPIENT_NAME, SENDER_NAME, null);
// Test ParsedMessage created from byte[]
ParsedMessage pm = new ParsedMessage(content.getBytes(), false);
pm = new ParsedMessage(content.getBytes(), true);
String substring = "newsubject";
verifyMutatedMessage(pm, substring, true);
// Test ParsedMessage created from File
mFile = createTempFile(content);
pm = new ParsedMessage(mFile, null, false);
verifyMutatedMessage(pm, substring, true);
mFile.delete();
mFile = createTempFile(content);
pm = new ParsedMessage(mFile, null, true);
verifyMutatedMessage(pm, substring, true);
// Test ParsedMessage created from MimeMessage, attachment indexing off.
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
pm = new ParsedMessage(mimeMsg, false);
verifyMutatedMessage(pm, substring, true);
// Test ParsedMessage created from MimeMessage, attachment indexing on.
mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
pm = new ParsedMessage(mimeMsg, true);
verifyMutatedMessage(pm, substring, true);
}
Aggregations