Search in sources :

Example 21 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project raml-module-builder by folio-org.

the class DemoRamlRestTest method checkClientCode.

/**
 * @param context
 */
private void checkClientCode(TestContext context) {
    Async async = context.async(1);
    log.info("checkClientCode test");
    try {
        MimeMultipart mmp = new MimeMultipart();
        BodyPart bp = new MimeBodyPart(new InternetHeaders(), IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("job.json")));
        bp.setDisposition("form-data");
        bp.setFileName("abc.raml");
        BodyPart bp2 = new MimeBodyPart(new InternetHeaders(), IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("job.json")));
        bp2.setDisposition("form-data");
        bp2.setFileName("abcd.raml");
        log.debug("--- bp content --- " + bp.getContent());
        mmp.addBodyPart(bp);
        mmp.addBodyPart(bp2);
        AdminClient aClient = new AdminClient("localhost", port, "abc", "abc", false);
        aClient.postUploadmultipart(PersistMethod.SAVE, null, "abc", mmp, reply -> {
            if (reply.statusCode() != 200) {
                context.fail();
            }
            log.debug("checkClientCode statusCode 1 " + reply.statusCode());
            String key;
            try {
                SecretKey sk = AES.generateSecretKey();
                key = AES.convertSecretKeyToString(sk);
                final String expected = AES.encryptPasswordAsBase64("abc", sk);
                aClient.postGetPassword(key, reply2 -> {
                    reply2.bodyHandler(bodyHandler -> {
                        if (!expected.equals(bodyHandler.toString())) {
                            context.fail("expected : " + expected + " got " + bodyHandler.toString());
                        } else {
                            log.info("received expected password: " + expected);
                            aClient.getModuleStats(r -> {
                                r.bodyHandler(br -> {
                                    log.info("received: " + br.toString());
                                });
                                async.countDown();
                            });
                        }
                    });
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        context.fail();
    }
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) SecretKey(javax.crypto.SecretKey) InternetHeaders(javax.mail.internet.InternetHeaders) MimeMultipart(javax.mail.internet.MimeMultipart) Async(io.vertx.ext.unit.Async) MimeBodyPart(javax.mail.internet.MimeBodyPart) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AdminClient(org.folio.rest.client.AdminClient)

Example 22 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project raml-module-builder by folio-org.

the class FileUploadsUtil method split.

private static MimeMultipart split(byte[] pattern, byte[] input, int sizeLimit) {
    MimeMultipart mmp = new MimeMultipart();
    int start = 0;
    int pos = Bytes.indexOf(input, pattern);
    int size = input.length;
    int entryCount = 0;
    ByteBuffer buffer = ByteBuffer.wrap(input);
    while (pos != -1 && start < size) {
        int end = pos + pattern.length;
        if (entryCount != 0) {
            // dont add the boundary itself - which is what you have in the first iteration
            buffer.position(start);
            // not a copy but points to the buffer
            // used for the indexOf functionality to keep checking
            // further on in the buffer - current pos -> end of buffer
            byte[] tmpBuffer = buffer.slice().array();
            // set limit - now that limit is set re-slice to only get the needed
            // area -
            buffer.limit(end);
            try {
                MimeBodyPart mbp = new MimeBodyPart(new InternetHeaders(), buffer.slice().array());
                mmp.addBodyPart(mbp);
            } catch (MessagingException e) {
                log.error(e.getMessage(), e);
            }
            pos = Bytes.indexOf(tmpBuffer, pattern);
        }
        entryCount++;
        start = end;
    }
    return mmp;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteBuffer(java.nio.ByteBuffer)

Example 23 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project legacy-webos by JayCanuck.

the class ControlFile method addControlFile.

/**
 * Add the control file to the tar file.
 */
private void addControlFile(TarOutputStream tar, PackageInfo info, PackageTarFile dataTar) throws IOException {
    // setup the RFC822 formatted header used for package metadata.
    final InternetHeaders headers = info.getControlHeaders();
    final StringBuilder controlFile = new StringBuilder();
    @SuppressWarnings("unchecked") final Enumeration<String> en = headers.getAllHeaderLines();
    while (en.hasMoreElements()) {
        controlFile.append(en.nextElement()).append('\n');
    }
    final TarEntry entry = standardEntry(CONTROL_FILE, UnixStandardPermissions.STANDARD_FILE_MODE, controlFile.length());
    tar.putNextEntry(entry);
    IOUtils.write(controlFile.toString(), tar);
    tar.closeEntry();
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) TarEntry(org.apache.tools.tar.TarEntry)

Example 24 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 25 with InternetHeaders

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

the class ReliableDispatchedNotificationProducer_produceTest method testCreateAckWithNoText.

public void testCreateAckWithNoText() throws Exception {
    final MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("PlainOutgoingMessage.txt")));
    final NHINDAddressCollection recipients = getMailRecipients(msg);
    final NotificationProducer prod = new ReliableDispatchedNotificationProducer(new NotificationSettings(true, "Local Direct Delivery Agent", ""));
    final Collection<NotificationMessage> notifications = prod.produce(new Message(msg), recipients.toInternetAddressCollection());
    assertNotNull(notifications);
    for (NotificationMessage noteMsg : notifications) {
        // assert that we removed the notification option from the headers as part of the fix of 
        // version 1.5.1
        assertNull(noteMsg.getHeader(MDNStandard.Headers.DispositionNotificationOptions, ","));
        final InternetHeaders headers = Notification.getNotificationFieldsAsHeaders(noteMsg);
        assertEquals("", headers.getHeader(MDNStandard.DispositionOption_TimelyAndReliable, ","));
    }
}
Also used : Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) InternetHeaders(javax.mail.internet.InternetHeaders) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

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