Search in sources :

Example 26 with MessagingException

use of javax.mail.MessagingException 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;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException)

Example 27 with MessagingException

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

the class Notification method serializeToBytes.

/**
	 * Serializes the notification to an array of bytes.
	 * @return byte array serialized form on this notification.
	 */
public byte[] serializeToBytes() {
    if (report == null)
        updateReport();
    ByteArrayOutputStream oStream = null;
    try {
        oStream = new ByteArrayOutputStream();
        report.writeTo(oStream);
        oStream.flush();
    } catch (MessagingException e) {
    } catch (IOException e) {
    }
    return oStream.toByteArray();
}
Also used : MessagingException(javax.mail.MessagingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 28 with MessagingException

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

the class DefaultNHINDAgent_ProcessOutgoingMessage_Test method testMessageIsWrapped_WrapMessageIsNotCalled.

/**
	 * 
	 * @throws Exception
	 */
public void testMessageIsWrapped_WrapMessageIsNotCalled() throws Exception {
    new TestPlan() {

        protected OutgoingMessage createMessage() throws Exception {
            MimeMessage mimeMsg = new SecondaryMimeMessage();
            mimeMsg.setText("");
            Message msg = new Message(mimeMsg) {

                @Override
                public String getContentType() throws MessagingException {
                    return MailStandard.MediaType.WrappedMessage;
                }
            };
            NHINDAddressCollection recipients = new NHINDAddressCollection();
            recipients.add(new NHINDAddress(""));
            NHINDAddress sender = new NHINDAddress("");
            theCreateMessage = new OutgoingMessage(msg, recipients, sender) {

                @Override
                protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) {
                    categorizeRecipientsCalls++;
                    categorizeRecipients_Internal(minTrustStatus);
                }
            };
            return theCreateMessage;
        }

        protected void doAssertions() throws Exception {
            assertEquals(0, wrapMessageCalls);
        }
    }.perform();
}
Also used : TrustEnforcementStatus(org.nhindirect.stagent.trust.TrustEnforcementStatus) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) BaseTestPlan(org.nhindirect.stagent.utils.BaseTestPlan) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MessagingException(javax.mail.MessagingException)

Example 29 with MessagingException

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

the class SMIMECryptographerImpl method decrypt.

/**
     * Decrypts an entity with the provided certificates' private key.
     * @param encryptedEntity The entity that will be decrypted.
     * @param decryptingCertificate The certificates whose private keys will be used to decrypt the message.
     * @return A MimeEntity containing the decrypted part.
     */
public MimeEntity decrypt(MimeEntity encryptedEntity, Collection<X509CertificateEx> decryptingCertificates) {
    if (decryptingCertificates == null || decryptingCertificates.size() == 0) {
        throw new IllegalArgumentException();
    }
    MimeEntity retEntity = null;
    try {
        if (LOGGER.isDebugEnabled()) {
            final byte[] encryptedContent = encryptedEntity.getContentAsBytes();
            writePreDecrypt(encryptedContent);
        }
        final SMIMEEnveloped m = new SMIMEEnveloped(encryptedEntity);
        if (!this.isAllowedEncryptionAlgorithm(m.getEncryptionAlgOID()))
            throw new NHINDException(MimeError.DisallowedEncryptionAlgorithm, "The encryption algorithm " + m.getEncryptionAlgOID() + " is not allowed");
        for (X509CertificateEx decryptCert : decryptingCertificates) {
            final RecipientId recId = generateRecipientSelector(decryptCert);
            final RecipientInformationStore recipients = m.getRecipientInfos();
            final DirectRecipientInformation recipient = decFactory.createInstance(recipients.get(recId), m);
            if (recipient == null)
                continue;
            final byte[] decryptedPayload = recipient.getDecryptedContent(decryptCert.getPrivateKey());
            if (LOGGER.isDebugEnabled()) {
                writePostDecrypt(decryptedPayload);
            }
            final ByteArrayInputStream inStream = new ByteArrayInputStream(decryptedPayload);
            retEntity = new MimeEntity(inStream);
            break;
        }
    } catch (MessagingException e) {
        throw new MimeException(MimeError.InvalidMimeEntity, e);
    } catch (Exception e) {
        throw new MimeException(MimeError.Unexpected, e);
    }
    if (retEntity == null) {
        throw new NHINDException(MimeError.Unexpected, "None of the the provided decryption certs were found in message's RecipientsInfo set.");
    }
    return retEntity;
}
Also used : RecipientId(org.bouncycastle.cms.RecipientId) MessagingException(javax.mail.MessagingException) DirectRecipientInformation(org.nhindirect.stagent.cryptography.activekeyops.DirectRecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped) NHINDException(org.nhindirect.stagent.NHINDException) MessagingException(javax.mail.MessagingException) MimeException(org.nhindirect.stagent.mail.MimeException) NHINDException(org.nhindirect.stagent.NHINDException) ParseException(javax.mail.internet.ParseException) IOException(java.io.IOException) SignatureValidationException(org.nhindirect.stagent.SignatureValidationException) X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeEntity(org.nhindirect.stagent.mail.MimeEntity) RecipientInformationStore(org.bouncycastle.cms.RecipientInformationStore) MimeException(org.nhindirect.stagent.mail.MimeException)

Example 30 with MessagingException

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

the class Notification method getInputStream.

/**
	 * Gets an input stream of this notification that can be serialized.
	 * @return An input stream of this notification
	 */
public InputStream getInputStream() {
    if (report == null)
        updateReport();
    ByteArrayOutputStream oStream = null;
    try {
        oStream = new ByteArrayOutputStream();
        report.writeTo(oStream);
        oStream.flush();
    } catch (MessagingException e) {
    } catch (IOException e) {
    }
    return new ByteArrayInputStream(oStream.toByteArray());
}
Also used : MessagingException(javax.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

MessagingException (javax.mail.MessagingException)324 MimeMessage (javax.mail.internet.MimeMessage)126 IOException (java.io.IOException)125 InternetAddress (javax.mail.internet.InternetAddress)64 MimeMultipart (javax.mail.internet.MimeMultipart)60 MimeBodyPart (javax.mail.internet.MimeBodyPart)58 Message (javax.mail.Message)45 Session (javax.mail.Session)43 InputStream (java.io.InputStream)41 Properties (java.util.Properties)38 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 Address (javax.mail.Address)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)25 DataHandler (javax.activation.DataHandler)23 BodyPart (javax.mail.BodyPart)23