public void testParsedMessage() throws Exception {
    ExpectedResults expected = new ExpectedResults();
    String subject = NAME_PREFIX + " testParsedMessage";
    expected.convertedSubject = subject;
    expected.rawContent = TestUtil.getTestMessage(subject, RECIPIENT_NAME, SENDER_NAME, null);
    expected.wasMutated = false;

    // Test ParsedMessage created from byte[]
    ParsedMessage pm = new ParsedMessage(expected.rawContent.getBytes(), false);
    verifyParsedMessage(pm, expected);
    pm = new ParsedMessage(expected.rawContent.getBytes(), true);
    verifyParsedMessage(pm, expected);

    // Test ParsedMessage created from File
    mFile = File.createTempFile("TestParsedMessage", ".msg");
    FileOutputStream out = new FileOutputStream(mFile);
    out.write(expected.rawContent.getBytes());

    pm = new ParsedMessage(mFile, null, false);
    verifyParsedMessage(pm, expected);
    pm = new ParsedMessage(mFile, null, true);
    verifyParsedMessage(pm, expected);

    // Test ParsedMessage created from MimeMessage.
    MimeMessage mimeMsg =
        new ZMimeMessage(
            JMSession.getSession(), new SharedByteArrayInputStream(expected.rawContent.getBytes()));
    pm = new ParsedMessage(mimeMsg, false);
    verifyParsedMessage(pm, expected);
    pm = new ParsedMessage(mimeMsg, true);
    verifyParsedMessage(pm, expected);
  }
  public void testMimeConverter() throws Exception {
    MimeVisitor.registerConverter(TestMimeVisitor.class);

    ExpectedResults expected = new ExpectedResults();
    String subject = NAME_PREFIX + " testMimeConverter oldsubject";
    expected.convertedSubject = NAME_PREFIX + " testMimeConverter newsubject";
    expected.rawContent = TestUtil.getTestMessage(subject, RECIPIENT_NAME, SENDER_NAME, null);
    expected.wasMutated = false;

    // Test ParsedMessage created from byte[]
    ParsedMessage pm = new ParsedMessage(expected.rawContent.getBytes(), false);
    verifyParsedMessage(pm, expected);
    pm = new ParsedMessage(expected.rawContent.getBytes(), true);
    verifyParsedMessage(pm, expected);

    // Test ParsedMessage created from File
    mFile = File.createTempFile("TestParsedMessage", ".msg");
    FileOutputStream out = new FileOutputStream(mFile);
    out.write(expected.rawContent.getBytes());
    out.close();

    pm = new ParsedMessage(mFile, null, false);
    verifyParsedMessage(pm, expected);
    pm = new ParsedMessage(mFile, null, true);
    verifyParsedMessage(pm, expected);

    // Test ParsedMessage created from MimeMessage.  Can't verify entire content
    // because JavaMail mangles the headers.
    MimeMessage mimeMsg =
        new ZMimeMessage(
            JMSession.getSession(), new SharedByteArrayInputStream(expected.rawContent.getBytes()));
    pm = new ParsedMessage(mimeMsg, false);
    assertTrue((new String(pm.getRawData()).contains("oldsubject")));
    assertTrue(getContent(pm.getMimeMessage()).contains("newsubject"));
    assertTrue(pm.getSubject().contains("newsubject"));
    pm = new ParsedMessage(mimeMsg, true);
    assertTrue((new String(pm.getRawData()).contains("oldsubject")));
    assertTrue(getContent(pm.getMimeMessage()).contains("newsubject"));
    assertTrue(pm.getSubject().contains("newsubject"));
  }