Example usage for javax.mail.internet MimeMessage getHeader

List of usage examples for javax.mail.internet MimeMessage getHeader

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage getHeader.

Prototype

@Override
public String getHeader(String name, String delimiter) throws MessagingException 

Source Link

Document

Get all the headers for this header name, returned as a single String, with headers separated by the delimiter.

Usage

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void test3LayersStrictDomainCerts() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");
    mailetConfig.setInitParameter("threshold", "10");
    mailetConfig.setInitParameter("strict", "true");

    mailet.init(mailetConfig);/*from w w w .  j a  va 2 s.co  m*/

    MockMail mail = new MockMail();

    mail.setState(Mail.TRANSPORT);

    /*
     * Make sure sub@subdomain.example.com can decrypt all
     */
    proxy.addDomainCertificate("sub.example.com", (X509Certificate) keyStore.getCertificate("NoEmail"));
    proxy.addDomainCertificate("sub.example.com",
            (X509Certificate) keyStore.getCertificate("ValidCertificate"));
    proxy.addDomainCertificate("sub.example.com", (X509Certificate) keyStore.getCertificate("multipleEmail"));

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/3-layer-encrypted.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new LinkedHashSet<MailAddress>();

    recipients.add(new MailAddress("test@sub.example.com"));
    recipients.add(new MailAddress("test2@sub.example.com"));
    recipients.add(new MailAddress("test3@sub.example.com"));
    recipients.add(new MailAddress("test4@sub.example.com"));
    recipients.add(new MailAddress("test5@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    assertEquals(2, sendMailEventListener.getMails().size());

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));

    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test5@example.com")));

    newMail = sendMailEventListener.getMails().get(1);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    assertEquals(SMIMEType.NONE, inspector.getSMIMEType());

    assertEquals(4, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test@sub.example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test2@sub.example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test3@sub.example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test4@sub.example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertEquals("AES128, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2", ","));

    assertEquals("test", ((String) newMessage.getContent()).trim());

    assertEquals(Mail.GHOST, mail.getState());
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void testNoDecryptionKey() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");

    mailet.init(mailetConfig);//from  w  w  w .  java2 s.co m

    MockMail mail = new MockMail();

    mail.setState("test");

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/encrypted-no-decryption-key.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new HashSet<MailAddress>();

    recipients.add(new MailAddress("aap@noot.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("test@example.com"));

    mailet.service(mail);

    /*
     * With non strict mode, the message is always handled if it's an S/MIME message because
     * the security info is added
     */
    assertEquals(1, sendMailEventListener.getMails().size());

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the message could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * Security information should be added
     */
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));

    assertEquals(Mail.GHOST, mail.getState());
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void testNoDecryptionKeyStrict() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");

    mailetConfig.setInitParameter("strict", "true");

    mailet.init(mailetConfig);//from w  w w.  ja  v  a  2  s. c o m

    MockMail mail = new MockMail();

    mail.setState("test");

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/encrypted-no-decryption-key.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new HashSet<MailAddress>();

    recipients.add(new MailAddress("aap@noot.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("test@example.com"));

    mailet.service(mail);

    /*
     * in strict mode, the message is handled if the recipient has no keys but not decrypted
     */
    assertEquals(1, sendMailEventListener.getMails().size());

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the message could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * Security information should be added
     */
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));

    assertEquals(Mail.GHOST, mail.getState());
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void testAddSecurityInfoToSubject3NoDecryptionKey() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");

    mailet.init(mailetConfig);/*from   w  w  w .ja  v a  2  s. co m*/

    MockMail mail = new MockMail();

    DjigzoMailAttributesImpl.getInstance(mail).setSecurityInfoTags(
            new SecurityInfoTags("[decrypted]", "[signed]", "[signed by: %s]", "[invalid]"));

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/encrypted-no-decryption-key.eml"));

    assertEquals("RE: Test ", message.getSubject());

    mail.setMessage(message);

    Set<MailAddress> recipients = new HashSet<MailAddress>();

    recipients.add(new MailAddress("aap@noot.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("test@example.com"));

    mailet.service(mail);

    /*
     * With non strict mode, the message is always handled if it's an S/MIME message because
     * the security info is added
     */
    assertEquals(1, sendMailEventListener.getMails().size());

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the message could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * Security information should be added
     */
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));

    assertEquals("RE: Test ", newMail.getMessage().getSubject());
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void testDecryptOL2010WithMissingSKIInSubjectWorkaroundEnabled() throws Exception {
    boolean skiWorkaroundEnabled = SecurityConstants.isOutlook2010SKIWorkaroundEnabled();

    try {// w  w w  .  jav  a  2  s.co  m
        SecurityConstants.setOutlook2010SKIWorkaroundEnabled(true);

        importKeyStore(keyAndCertificateWorkflow,
                new File("test/resources/testdata/keys/outlook2010_cert_missing_subjkeyid.p12"), "");

        SMIMEHandler mailet = new SMIMEHandler();

        mailetConfig.setInitParameter("handledProcessor", "handled");

        mailet.init(mailetConfig);

        MockMail mail = new MockMail();

        MimeMessage message = MailUtils
                .loadMessage(new File(testBase, "mail/outlook2010_cert_missing_subjkeyid.eml"));

        mail.setMessage(message);

        Set<MailAddress> recipients = new HashSet<MailAddress>();

        recipients.add(new MailAddress("m.brinkers@pobox.com"));

        mail.setRecipients(recipients);

        mail.setSender(new MailAddress("test@example.com"));

        mailet.service(mail);

        assertEquals(1, sendMailEventListener.getMails().size());

        Mail newMail = sendMailEventListener.getMails().get(0);

        MimeMessage decrypted = newMail.getMessage();

        assertTrue(decrypted.isMimeType("text/plain"));
        assertEquals("A broken S/MIME encrypted message", decrypted.getSubject());
        assertEquals("<000c01cadd1e$d8e3b700$8aab2500$@Domain>", decrypted.getMessageID());
        assertEquals(message.getMessageID(), decrypted.getMessageID());
        assertEquals("3DES, Key size: 168", decrypted.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
        assertEquals("//2219E504D5750B37D20CC930B14129E1A2E583B1/1.2.840.113549.1.1.1",
                decrypted.getHeader("X-Djigzo-Info-Encryption-Recipient-0-0", ","));
        assertEquals("Created with Outlook 2010 Beta (14.0.4536.1000)",
                StringUtils.trim((String) decrypted.getContent()));

        assertEquals(Mail.GHOST, mail.getState());
    } finally {
        SecurityConstants.setOutlook2010SKIWorkaroundEnabled(skiWorkaroundEnabled);
    }
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void test3LayersStrict() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");
    mailetConfig.setInitParameter("threshold", "10");
    mailetConfig.setInitParameter("strictAttribute", "attr.strict");

    mailet.init(mailetConfig);//from   ww w.  j a va2  s.  co  m

    MockMail mail = new MockMail();

    mail.setAttribute("attr.strict", true);

    mail.setState(Mail.TRANSPORT);

    /*
     * message with 3 layers of encryption
     */
    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/3-layer-encrypted.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new HashSet<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));
    recipients.add(new MailAddress("test2@example.com"));
    recipients.add(new MailAddress("test3@example.com"));
    recipients.add(new MailAddress("test4@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    assertEquals(3, sendMailEventListener.getMails().size());

    /* message 1 */

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * Only test@example.com can decrypt the first two layers
     */
    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertEquals("AES128, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2", ","));

    /* message 2 */

    newMail = sendMailEventListener.getMails().get(1);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * test2@example.com and test3@example.com can only decrypt the first layers
     */
    assertEquals(2, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test2@example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test3@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertNull(newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2"));

    newMail = sendMailEventListener.getMails().get(2);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last message could not be decrypted beause of strict mode
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test4@example.com")));

    assertEquals(Mail.GHOST, mail.getState());
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void test3LayersStrictWithExplicitCertificate() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");
    mailetConfig.setInitParameter("threshold", "10");
    mailetConfig.setInitParameter("strictAttribute", "attr.strict");

    mailet.init(mailetConfig);//from  w  w  w .  jav a  2  s.co m

    MockMail mail = new MockMail();

    mail.setAttribute("attr.strict", true);

    mail.setState(Mail.TRANSPORT);

    /*
     * Make sure sub@subdomain.example.com can decrypt all
     */
    proxy.addUserCertificate("sub@subdomain.example.com", (X509Certificate) keyStore.getCertificate("NoEmail"));
    proxy.addUserCertificate("sub@subdomain.example.com",
            (X509Certificate) keyStore.getCertificate("ValidCertificate"));
    proxy.addUserCertificate("sub@subdomain.example.com",
            (X509Certificate) keyStore.getCertificate("multipleEmail"));

    /*
     * message with 3 layers of encryption
     */
    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/3-layer-encrypted.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new LinkedHashSet<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));
    recipients.add(new MailAddress("test2@example.com"));
    recipients.add(new MailAddress("test3@example.com"));
    recipients.add(new MailAddress("test4@example.com"));
    recipients.add(new MailAddress("sub@subdomain.example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    assertEquals(4, sendMailEventListener.getMails().size());

    /* message 1 */

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * Only test@example.com can decrypt the first two layers
     */
    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertEquals("AES128, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2", ","));

    /* message 2 */

    newMail = sendMailEventListener.getMails().get(1);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer could not be decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * test2@example.com and test3@example.com can only decrypt the first layers
     */
    assertEquals(2, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test2@example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test3@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertNull(newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2"));

    /* message 3 */

    newMail = sendMailEventListener.getMails().get(2);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer was also decrypted
     */
    assertEquals(SMIMEType.NONE, inspector.getSMIMEType());

    /*
     * sub@subdomain.example.com can decrypt all layers
     */
    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("sub@subdomain.example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertEquals("AES128, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2", ","));

    assertEquals("test", ((String) newMessage.getContent()).trim());

    newMail = sendMailEventListener.getMails().get(3);

    newMessage = newMail.getMessage();

    inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    /*
     * the last layer was also decrypted
     */
    assertEquals(SMIMEType.ENCRYPTED, inspector.getSMIMEType());

    /*
     * sub@subdomain.example.com can decrypt all layers
     */
    assertEquals(1, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test4@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals(Mail.GHOST, mail.getState());
}

From source file:mitm.common.security.smime.SMIMEBuilderImplTest.java

@Test
public void testClearSignNoCertificates() throws Exception {
    MimeMessage message = loadMessage("simple-text-message.eml");

    SMIMEBuilder builder = new SMIMEBuilderImpl(message);

    builder.addSigner(privateKeyEntry.getPrivateKey(), (X509Certificate) privateKeyEntry.getCertificate(),
            SMIMESigningAlgorithm.SHA1WITHRSA, (X509Certificate) privateKeyEntry.getCertificate());

    builder.sign(SMIMESignMode.CLEAR);/*from w  w  w. j a v a 2s. c  om*/

    MimeMessage newMessage = builder.buildMessage();

    File file = new File(tempDir, "test-signed-no-certificates.eml");

    FileOutputStream output = new FileOutputStream(file);

    MailUtils.writeMessage(newMessage, output);

    newMessage = MailUtils.loadMessage(file);

    assertEquals(SMIMEHeader.Type.CLEAR_SIGNED, SMIMEHeader.getSMIMEContentType(newMessage));

    assertEquals("test@example.com", newMessage.getHeader("from", ","));
    assertEquals("test@example.com", newMessage.getHeader("to", ","));
    assertEquals("test simple message", newMessage.getHeader("subject", ","));
}

From source file:mitm.application.djigzo.james.mailets.SMIMEHandlerTest.java

@Test
public void test3Layers() throws Exception {
    SMIMEHandler mailet = new SMIMEHandler();

    mailetConfig.setInitParameter("handledProcessor", "handled");
    mailetConfig.setInitParameter("threshold", "10");

    mailet.init(mailetConfig);/* ww w . j  av a2 s  .  c  o m*/

    MockMail mail = new MockMail();

    mail.setState(Mail.TRANSPORT);

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/3-layer-encrypted.eml"));

    mail.setMessage(message);

    Set<MailAddress> recipients = new HashSet<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));
    recipients.add(new MailAddress("test2@example.com"));
    recipients.add(new MailAddress("test3@example.com"));
    recipients.add(new MailAddress("test4@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    assertEquals(1, sendMailEventListener.getMails().size());

    Mail newMail = sendMailEventListener.getMails().get(0);

    MimeMessage newMessage = newMail.getMessage();

    SMIMEInspector inspector = new SMIMEInspectorImpl(newMessage, null, "BC");

    assertEquals(SMIMEType.NONE, inspector.getSMIMEType());

    assertEquals(4, newMail.getRecipients().size());
    assertTrue(newMail.getRecipients().contains(new MailAddress("test@example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test2@example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test3@example.com")));
    assertTrue(newMail.getRecipients().contains(new MailAddress("test4@example.com")));
    assertEquals("handled", newMail.getState());

    assertEquals(Mail.GHOST, mail.getState());

    assertEquals("RC2, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-0", ","));
    assertEquals("3DES, Key size: 168", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-1", ","));
    assertEquals("AES128, Key size: 128", newMessage.getHeader("X-Djigzo-Info-Encryption-Algorithm-2", ","));

    assertEquals("test", ((String) newMessage.getContent()).trim());
}

From source file:mitm.common.security.smime.SMIMEBuilderImplTest.java

@Test
public void testSimpleMessageCompress() throws Exception {
    MimeMessage message = loadMessage("simple-text-message.eml");

    SMIMEBuilder builder = new SMIMEBuilderImpl(message);

    builder.compress();//from ww  w.j  a v  a2 s  .c o m

    MimeMessage newMessage = builder.buildMessage();

    File file = new File(tempDir, "test-simple-text-message-compressed.eml");

    FileOutputStream output = new FileOutputStream(file);

    MailUtils.writeMessage(newMessage, output);

    newMessage = MailUtils.loadMessage(file);

    assertEquals(SMIMEHeader.Type.COMPRESSED, SMIMEHeader.getSMIMEContentType(newMessage));

    assertEquals("test@example.com", newMessage.getHeader("from", ","));
    assertEquals("test@example.com", newMessage.getHeader("to", ","));
    assertEquals("test simple message", newMessage.getHeader("subject", ","));
}