Search in sources :

Example 16 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.

the class NotificationTest method testError_AssertError.

public void testError_AssertError() throws Exception {
    Notification noti = new Notification(NotificationType.Processed);
    MimeMultipart mm = noti.getAsMultipart();
    assertNotNull(mm);
    assertEquals(2, mm.getCount());
    BodyPart part = mm.getBodyPart(1);
    assertTrue(part.getContentType().startsWith("message/disposition-notification"));
    InternetHeaders headers = noti.getNotificationFieldsAsHeaders();
    assertNull(headers.getHeader(MDNStandard.Headers.Error));
    // set a new gateway
    noti.setError("Junit Error");
    mm = noti.getAsMultipart();
    assertNotNull(mm);
    assertEquals(2, mm.getCount());
    part = mm.getBodyPart(1);
    assertTrue(part.getContentType().startsWith("message/disposition-notification"));
    headers = noti.getNotificationFieldsAsHeaders();
    assertNotNull(headers.getHeader(MDNStandard.Headers.Error));
    assertEquals("Junit Error", headers.getHeader(MDNStandard.Headers.Error, ","));
    assertEquals(headers.getHeader(MDNStandard.Headers.Error, ","), noti.getError());
}
Also used : BodyPart(javax.mail.BodyPart) InternetHeaders(javax.mail.internet.InternetHeaders) MimeMultipart(javax.mail.internet.MimeMultipart) DispositionNotification(com.sun.mail.dsn.DispositionNotification)

Example 17 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.

the class NotificationTest method testWarning_AssertWarning.

public void testWarning_AssertWarning() throws Exception {
    Notification noti = new Notification(NotificationType.Processed);
    MimeMultipart mm = noti.getAsMultipart();
    assertNotNull(mm);
    assertEquals(2, mm.getCount());
    BodyPart part = mm.getBodyPart(1);
    assertTrue(part.getContentType().startsWith("message/disposition-notification"));
    InternetHeaders headers = noti.getNotificationFieldsAsHeaders();
    assertNull(headers.getHeader(MDNStandard.Headers.FinalRecipient));
    // set a new gateway
    noti.setWarning("junit warning");
    mm = noti.getAsMultipart();
    assertNotNull(mm);
    assertEquals(2, mm.getCount());
    part = mm.getBodyPart(1);
    assertTrue(part.getContentType().startsWith("message/disposition-notification"));
    headers = noti.getNotificationFieldsAsHeaders();
    assertNotNull(headers.getHeader(MDNStandard.Headers.Warning));
    assertEquals("junit warning", headers.getHeader(MDNStandard.Headers.Warning, ","));
}
Also used : BodyPart(javax.mail.BodyPart) InternetHeaders(javax.mail.internet.InternetHeaders) MimeMultipart(javax.mail.internet.MimeMultipart) DispositionNotification(com.sun.mail.dsn.DispositionNotification)

Example 18 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.

the class NotificationTest method testParseFieldsFromMimeMessage.

public void testParseFieldsFromMimeMessage() throws Exception {
    String testMessage = TestUtils.readResource("MDNMessage.txt");
    MimeMessage msg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
    InternetHeaders headers = Notification.getNotificationFieldsAsHeaders(msg);
    assertNotNull(headers.getHeader(MDNStandard.Headers.Disposition));
    assertEquals("automatic-action/MDN-sent-automatically;processed", headers.getHeader(MDNStandard.Headers.Disposition, ","));
    assertNotNull(headers.getHeader(MDNStandard.Headers.ReportingAgent));
    assertEquals("starugh-stateline.com;NHIN Direct Security Agent", headers.getHeader(MDNStandard.Headers.ReportingAgent, ","));
    assertNotNull(headers.getHeader(MDNStandard.Headers.FinalRecipient));
    assertEquals("externUser1@starugh-stateline.com", headers.getHeader(MDNStandard.Headers.FinalRecipient, ","));
    assertNotNull(headers.getHeader(MDNStandard.Headers.OriginalMessageID));
    assertEquals("<9501051053.aa04167@IETF.CNR I.Reston.VA.US>", headers.getHeader(MDNStandard.Headers.OriginalMessageID, ","));
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MimeMessage(javax.mail.internet.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 19 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project logging-log4j2 by apache.

the class SmtpManager method getHeaders.

protected InternetHeaders getHeaders(final String contentType, final String encoding) {
    final InternetHeaders headers = new InternetHeaders();
    headers.setHeader("Content-Type", contentType + "; charset=UTF-8");
    headers.setHeader("Content-Transfer-Encoding", encoding);
    return headers;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders)

Example 20 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project nexus-repository-r by sonatype-nexus-community.

the class RMetadataUtils method parseDescriptionFile.

/**
 * Parses metadata stored in a Debian Control File-like format.
 *
 * @see <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file">Description File</a>
 */
public static Map<String, String> parseDescriptionFile(final InputStream in) {
    checkNotNull(in);
    try {
        LinkedHashMap<String, String> results = new LinkedHashMap<>();
        InternetHeaders headers = new InternetHeaders(in);
        Enumeration headerEnumeration = headers.getAllHeaders();
        while (headerEnumeration.hasMoreElements()) {
            Header header = (Header) headerEnumeration.nextElement();
            String name = header.getName();
            String value = header.getValue().replace("\r\n", "\n").replace("\r", // TODO: "should" be ASCII only, otherwise need to know encoding?
            "\n");
            // TODO: Supposedly no duplicates, is this true?
            results.put(name, value);
        }
        return results;
    } catch (MessagingException e) {
        throw new RException(null, e);
    }
}
Also used : Enumeration(java.util.Enumeration) InternetHeaders(javax.mail.internet.InternetHeaders) Header(javax.mail.Header) MessagingException(javax.mail.MessagingException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

InternetHeaders (javax.mail.internet.InternetHeaders)51 MimeMultipart (javax.mail.internet.MimeMultipart)18 MessagingException (javax.mail.MessagingException)16 BodyPart (javax.mail.BodyPart)14 IOException (java.io.IOException)10 DispositionNotification (com.sun.mail.dsn.DispositionNotification)9 MimeMessage (javax.mail.internet.MimeMessage)8 MimeMultipartReport (org.apache.mailet.base.mail.MimeMultipartReport)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Header (javax.mail.Header)5 MimeEntity (org.nhindirect.stagent.mail.MimeEntity)5 InputStream (java.io.InputStream)4 MimeBodyPart (javax.mail.internet.MimeBodyPart)4 NHINDException (org.nhindirect.stagent.NHINDException)4 MimeException (org.nhindirect.stagent.mail.MimeException)4 X509Certificate (java.security.cert.X509Certificate)3 ContentType (javax.mail.internet.ContentType)3 ParseException (javax.mail.internet.ParseException)3 X509CertificateEx (org.nhindirect.stagent.cert.X509CertificateEx)3