use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class Message method extractMimeEntity.
/**
* Gets a copy of this message without any non-mime headers.
* @returns A copy of this message without any non-mime headers.
*/
@SuppressWarnings("unchecked")
public MimeEntity extractMimeEntity() {
MimeEntity retVal = null;
try {
InternetHeaders headers = new InternetHeaders();
if (this.headers.getAllHeaders().hasMoreElements()) {
Enumeration<javax.mail.Header> hEnum = this.headers.getAllHeaders();
while (hEnum.hasMoreElements()) {
javax.mail.Header hdr = hEnum.nextElement();
if (MimeStandard.startsWith(hdr.getName(), MimeStandard.HeaderPrefix))
headers.addHeader(hdr.getName(), hdr.getValue());
}
if (!headers.getAllHeaders().hasMoreElements()) {
throw new MimeException(MimeError.InvalidMimeEntity);
}
retVal = new MimeEntity(headers, getContentAsBytes());
}
} catch (MessagingException e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
}
return retVal;
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class WrappedMessage method copyHeaders.
@SuppressWarnings("unchecked")
private static /*
* Copy the requested headers from the original message into a new header collection.
*/
InternetHeaders copyHeaders(Message message, String[] headersToCopy) throws MessagingException {
InternetHeaders retVal = new InternetHeaders();
// InternetHeaders allow work on the raw message header
Enumeration<String> hdEnum = message.getMatchingHeaderLines(headersToCopy);
while (hdEnum.hasMoreElements()) retVal.addHeaderLine(hdEnum.nextElement());
return retVal;
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class NotificationMessage method createHeaders.
private static InternetHeaders createHeaders(String to, String from, Notification notification) throws MessagingException {
InternetHeaders headers = new InternetHeaders();
if (to != null && !to.isEmpty())
headers.addHeader(MailStandard.Headers.To, to);
if (from != null && !from.isEmpty())
headers.addHeader(MailStandard.Headers.From, from);
headers.addHeader(MimeStandard.VersionHeader, "1.0");
// get the boundary
ContentType type = new ContentType(notification.getAsMultipart().getContentType());
String boundary = type.getParameter("boundary");
headers.addHeader(MailStandard.Headers.ContentType, MDNStandard.MediaType.DispositionReport + "; boundary=\"" + boundary + "\"");
return headers;
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class CryptographerTest method testEncryptAndDecryptMultipartEntity.
private void testEncryptAndDecryptMultipartEntity(EncryptionAlgorithm encAlgo, boolean enforceStrongEncryption) throws Exception {
X509Certificate cert = TestUtils.getExternalCert("user1");
SMIMECryptographerImpl cryptographer = new SMIMECryptographerImpl();
cryptographer.setEncryptionAlgorithm(encAlgo);
cryptographer.setStrongEncryptionEnforced(enforceStrongEncryption);
MimeEntity entityText = new MimeEntity();
entityText.setText("Hello world.");
entityText.setHeader(MimeStandard.ContentTypeHeader, "text/plain");
entityText.setHeader(MimeStandard.ContentTransferEncodingHeader, "7bit");
MimeEntity entityXML = new MimeEntity();
entityXML.setText("<Test></Test>");
entityXML.setHeader(MimeStandard.ContentTypeHeader, "text/xml");
MimeMultipart mpEntity = new MimeMultipart();
mpEntity.addBodyPart(entityText);
mpEntity.addBodyPart(entityXML);
MimeEntity encEntity = cryptographer.encrypt(mpEntity, cert);
assertNotNull(encEntity);
X509CertificateEx certex = TestUtils.getInternalCert("user1");
MimeEntity decryEntity = cryptographer.decrypt(encEntity, certex);
assertNotNull(decryEntity);
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
mpEntity.writeTo(oStream);
InternetHeaders hdrs = new InternetHeaders();
hdrs.addHeader(MimeStandard.ContentTypeHeader, mpEntity.getContentType());
MimeEntity orgEntity = new MimeEntity(hdrs, oStream.toByteArray());
byte[] decryEntityBytes = EntitySerializer.Default.serializeToBytes(decryEntity);
byte[] entityBytes = EntitySerializer.Default.serializeToBytes(orgEntity);
System.out.println("Original:\r\n" + new String(entityBytes));
System.out.println("\r\n\r\n\r\nNew:\r\n" + new String(decryEntityBytes));
assertTrue(Arrays.equals(decryEntityBytes, entityBytes));
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class MDNFactory_createTest method testCreate_withFailure.
public void testCreate_withFailure() throws Exception {
final Disposition disp = new Disposition(NotificationType.Processed);
final MdnGateway gateway = new MdnGateway("junitGateway");
MimeMultipartReport report = MDNFactory.create("test", "junitUA", "junitProduct", "sender@send.com", "final@final.com", "12345", "", gateway, disp, "", "junit failure", new ArrayList<String>());
assertNotNull(report);
final InternetHeaders headers = getNotificationFieldsAsHeaders(report);
assertEquals("junit failure", headers.getHeader("Failure", ","));
}
Aggregations