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());
}
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, ","));
}
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, ","));
}
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;
}
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);
}
}
Aggregations