Search in sources :

Example 1 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project zm-mailbox by Zimbra.

the class MockHttpStore method handle.

static void handle(Socket socket) throws IOException {
    InputStream in = null;
    OutputStream out = null;
    try {
        in = new BufferedInputStream(socket.getInputStream());
        out = socket.getOutputStream();
        StringBuilder reqline = new StringBuilder();
        int b;
        while ((b = in.read()) != -1 && b != '\n') {
            reqline.append((char) b);
        }
        String[] reqparts = reqline.toString().trim().split(" ");
        if (fail.compareAndSet(true, false)) {
            out.write("HTTP/1.0 400 force fail".getBytes());
        } else if (delay.compareAndSet(true, false)) {
            try {
                Thread.sleep(LC.httpclient_internal_connmgr_so_timeout.longValue() + 10000);
            } catch (InterruptedException e) {
            }
        } else {
            if (reqparts.length != 3 || !reqparts[2].startsWith("HTTP/")) {
                out.write("HTTP/1.0 400 malformed request-line\r\n\r\n".getBytes());
            } else {
                String method = reqparts[0].toUpperCase(), filename = getFilename(reqparts[1]), version = reqparts[2];
                try {
                    InternetHeaders headers = new InternetHeaders(in);
                    if (method.equals("GET")) {
                        doGet(version, filename, out);
                    } else if (method.equals("POST") || method.equals("PUT")) {
                        doPost(version, headers, in, out);
                    } else if (method.equals("DELETE")) {
                        doDelete(version, filename, out);
                    } else {
                        out.write((version + " 400 unknown method: " + reqparts[0] + "\r\n\r\n").getBytes());
                    }
                } catch (MessagingException e) {
                    out.write((version + " 500 Internal Server Error\r\n\r\n").getBytes());
                    return;
                }
            }
        }
        out.flush();
    } finally {
        ByteUtil.closeStream(in);
        ByteUtil.closeStream(out);
        socket.close();
    }
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) BufferedInputStream(java.io.BufferedInputStream) MessagingException(javax.mail.MessagingException) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 2 with InternetHeaders

use of javax.mail.internet.InternetHeaders in project ats-framework by Axway.

the class MimePackage method getInternetHeaders.

private InternetHeaders getInternetHeaders(Object partContent) throws PackageException {
    InternetHeaders internetHeaders = null;
    if (partContent instanceof InputStream) {
        try {
            InputStream is = (InputStream) partContent;
            internetHeaders = new InternetHeaders(is);
        } catch (MessagingException e) {
            // error converting to InternetHeaders
            throw new PackageException("Error parsing internet headers with type rfc822-headers", e);
        }
    }
    return internetHeaders;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SeekInputStream(com.axway.ats.core.io.SeekInputStream) InputStream(java.io.InputStream) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 3 with InternetHeaders

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

the class MDNStandard method getNotificationFieldsAsHeaders.

/**
	 * Parses the notification part fields of the MimeMultipart body of a MDN message.  The multipart is expected to conform to the MDN specification
	 * as described in RFC3798.
	 * @return The notification part fields as a set of Internet headers. 
	 */
public static InternetHeaders getNotificationFieldsAsHeaders(MimeMultipart mm) {
    InternetHeaders retVal = null;
    if (mm == null)
        throw new IllegalArgumentException("Multipart can not be null");
    try {
        if (mm.getCount() < 2)
            throw new IllegalArgumentException("Multipart can not be null");
        // the second part should be the notification
        BodyPart part = mm.getBodyPart(1);
        try {
            Object contecntObj = part.getContent();
            if (dsnClass != null && dsnClass.getCanonicalName().equals(contecntObj.getClass().getCanonicalName())) {
                retVal = (InternetHeaders) getHeaders.invoke(contecntObj);
                return retVal;
            }
        } catch (Exception e) {
        /* no-op */
        }
        if (!part.getContentType().equalsIgnoreCase(MDNStandard.MediaType.DispositionNotification))
            throw new IllegalArgumentException("Notification part content type is not " + MDNStandard.MediaType.DispositionNotification);
        // parse fields
        retVal = new InternetHeaders();
        String[] fields = getPartContentBodyAsString(part).split("\r\n");
        for (String field : fields) {
            int idx = field.indexOf(":");
            if (idx > -1) {
                String name = field.substring(0, idx);
                String value = field.substring(idx + 1).trim();
                retVal.setHeader(name, value);
            }
        }
    } catch (MessagingException e) {
        throw new IllegalArgumentException("Failed to parse notification fields.", e);
    }
    return retVal;
}
Also used : BodyPart(javax.mail.BodyPart) InternetHeaders(javax.mail.internet.InternetHeaders) MessagingException(javax.mail.MessagingException) MessagingException(javax.mail.MessagingException)

Example 4 with InternetHeaders

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

the class DSNStandard method getFinalRecipients.

/**
     * Get the list final recipients as a comma delimited string from the delivery status part
     * of a DSN message
     * @param status The deliver status structure
     * @return List of the final recipients as a command delimited string or an empty string if 
     * no final recipients exist.
     */
public static String getFinalRecipients(DeliveryStatus status) {
    StringBuilder builder = new StringBuilder();
    final int cnt = status.getRecipientDSNCount();
    int recipientCount = 0;
    for (int i = 0; i < cnt; ++i) {
        final InternetHeaders recipHeaders = status.getRecipientDSN(i);
        if (recipHeaders != null) {
            final String value = recipHeaders.getHeader(DSNStandard.Headers.FinalRecipient, ",");
            if (value != null && value.length() > 0) {
                String recipient = value.substring(value.indexOf(";") + 1);
                if (recipient != null && recipient.length() > 0) {
                    if (recipientCount > 0) {
                        builder.append(",");
                    }
                    builder.append(recipient.trim());
                    ++recipientCount;
                }
            }
        }
    }
    return builder.toString();
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders)

Example 5 with InternetHeaders

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

the class DSNStandard method getHeaderValueFromDeliveryStatus.

/**
	 * Get header values from the delivery status part of a DNS message
	 * @param status The delivery status structure
	 * @param headerName The header name to get the value for.
	 * @return Return the value of the header, or an empty string if the header does not exist.
	 */
public static String getHeaderValueFromDeliveryStatus(DeliveryStatus status, String headerName) {
    String result = "";
    final int cnt = status.getRecipientDSNCount();
    for (int i = 0; i < cnt; ++i) {
        final InternetHeaders recipHeaders = status.getRecipientDSN(i);
        if (recipHeaders != null) {
            final String value = recipHeaders.getHeader(headerName, ",");
            if (value != null && value.length() > 0) {
                result = value;
                break;
            }
        }
    }
    return result;
}
Also used : InternetHeaders(javax.mail.internet.InternetHeaders)

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