use of org.nhindirect.stagent.mail.MimeEntity in project nhin-d by DirectProject.
the class NotificationTest method testCreateNotification_AssertGetParts.
public void testCreateNotification_AssertGetParts() throws Exception {
Notification noti = new Notification(NotificationType.Processed);
ArrayList<MimeEntity> entities = (ArrayList<MimeEntity>) noti.getParts();
MimeEntity entity = entities.get(0);
assertEquals("Your message was successfully processed.", entity.getContent().toString());
entity = entities.get(1);
assertTrue(entity.getContentType().startsWith("message/disposition-notification"));
DispositionNotification notification = (DispositionNotification) entity.getContent();
assertEquals(notification.getNotifications().getHeader("disposition", ","), "automatic-action/MDN-sent-automatically;processed");
}
use of org.nhindirect.stagent.mail.MimeEntity in project nhin-d by DirectProject.
the class SMIMECryptographerImpl method encrypt.
/**
* Encrypts an entity using the provided certificates.
* @param entity The entity that will be encrypted.
* @param encryptingCertificate The public certificates that will be used to encrypt the message.
* @return A MimeEntity containing the encrypted part.
*/
public MimeEntity encrypt(MimeEntity entity, Collection<X509Certificate> encryptingCertificates) {
if (entity == null) {
throw new IllegalArgumentException();
}
MimeBodyPart partToEncrypt = entity;
MimeBodyPart encryptedPart = this.encrypt(partToEncrypt, encryptingCertificates);
MimeEntity encryptedEntity = null;
try {
byte[] encBytes = EntitySerializer.Default.serializeToBytes(encryptedPart);
ByteArrayInputStream inStream = new ByteArrayInputStream(EntitySerializer.Default.serializeToBytes(encryptedPart));
encryptedEntity = new MimeEntity(inStream);
if (LOGGER.isDebugEnabled()) {
writePostEncypt(encBytes);
}
encryptedEntity.setHeader(MimeStandard.ContentTypeHeader, SMIMEStandard.EncryptedContentTypeHeaderValue);
} catch (Exception e) {
throw new MimeException(MimeError.Unexpected, e);
}
return encryptedEntity;
}
use of org.nhindirect.stagent.mail.MimeEntity in project nhin-d by DirectProject.
the class SMIMECryptographerImpl method decrypt.
/**
* Decrypts an entity with the provided certificate's private key.
* @param encryptedEntity The entity that will be decrypted.
* @param decryptingCertificate The certificate whose private key will be used to decrypt the message.
* @return A MimeEntity containing the decrypted part.
*/
public MimeEntity decrypt(MimeEntity encryptedEntity, X509CertificateEx decryptingCertificate) {
if (encryptedEntity == null || decryptingCertificate == null) {
throw new IllegalArgumentException();
}
if (!decryptingCertificate.hasPrivateKey()) {
throw new IllegalArgumentException("Certificate has no private key");
}
encryptedEntity.verifyContentType(SMIMEStandard.EncryptedContentTypeHeaderValue);
encryptedEntity.verifyTransferEncoding(MimeStandard.TransferEncodingBase64);
Collection<X509CertificateEx> certs = new ArrayList<X509CertificateEx>();
certs.add(decryptingCertificate);
MimeEntity retVal = this.decrypt(encryptedEntity, certs);
//
return retVal;
}
use of org.nhindirect.stagent.mail.MimeEntity in project nhin-d by DirectProject.
the class SMIMECryptographerImpl method encrypt.
/**
* Encrypts a mulit part MIME entity using the provided certificates.
* @param entity The entity that will be encrypted.
* @param encryptingCertificates The public certificates that will be used to encrypt the message.
* @return A MimeEntity containing the encrypted part.
*/
public MimeEntity encrypt(MimeMultipart mmEntity, Collection<X509Certificate> encryptingCertificates) {
MimeEntity entToEncrypt = null;
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
try {
mmEntity.writeTo(oStream);
oStream.flush();
InternetHeaders headers = new InternetHeaders();
headers.addHeader(MimeStandard.ContentTypeHeader, mmEntity.getContentType());
entToEncrypt = new MimeEntity(headers, oStream.toByteArray());
IOUtils.closeQuietly(oStream);
} catch (Exception e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
}
return this.encrypt(entToEncrypt, encryptingCertificates);
}
use of org.nhindirect.stagent.mail.MimeEntity in project nhin-d by DirectProject.
the class Notification method getParts.
/**
* Returns a collection of body parts of the multipart report for this notification.
* @return A collection of body parts of the multipart report for this notification.
*/
public Collection<MimeEntity> getParts() {
if (report == null)
updateReport();
Collection<MimeEntity> retVal = new ArrayList<MimeEntity>();
try {
for (int i = 0; i < report.getCount(); ++i) {
ByteArrayOutputStream oStream = null;
try {
oStream = new ByteArrayOutputStream();
report.getBodyPart(i).writeTo(oStream);
oStream.flush();
} catch (MessagingException e) {
} catch (IOException e) {
}
InputStream str = new ByteArrayInputStream(oStream.toByteArray());
retVal.add(new MimeEntity(str));
}
} catch (MessagingException e) {
/* */
}
return retVal;
}
Aggregations