Example usage for javax.mail.internet InternetHeaders getHeader

List of usage examples for javax.mail.internet InternetHeaders getHeader

Introduction

In this page you can find the example usage for javax.mail.internet InternetHeaders getHeader.

Prototype

public String[] getHeader(String name) 

Source Link

Document

Return all the values for the specified header.

Usage

From source file:org.sakaiproject.nakamura.smtp.SakaiSmtpServer.java

@SuppressWarnings("unchecked")
private Content writeMessage(Session session, Map<String, Object> mapProperties, InputStream data,
        String storePath)//from   w w  w . j ava  2 s. c  om
        throws MessagingException, AccessDeniedException, StorageClientException, IOException {
    InternetHeaders internetHeaders = new InternetHeaders(data);
    // process the headers into a map.
    for (Enumeration<Header> e = internetHeaders.getAllHeaders(); e.hasMoreElements();) {
        Header h = e.nextElement();
        String name = h.getName();
        String[] values = internetHeaders.getHeader(name);
        if (values != null) {
            if (values.length == 1) {
                mapProperties.put("sakai:" + name.toLowerCase(), values[0]);
            } else {
                mapProperties.put("sakai:" + name.toLowerCase(), values);
            }
        }
    }
    String[] contentType = internetHeaders.getHeader("content-type");
    if (contentType != null && contentType.length > 0 && contentType[0].contains("boundary")
            && contentType[0].contains("multipart/")) {
        MimeMultipart multipart = new MimeMultipart(new SMTPDataSource(contentType[0], data));
        Content message = messagingService.create(session, mapProperties,
                (String) mapProperties.get("sakai:message-id"), storePath);
        writeMultipartToNode(session, message, multipart);
        return message;
    } else {
        Content node = messagingService.create(session, mapProperties);
        // set up to stream the body.
        session.getContentManager().writeBody(node.getPath(), data);
        return node;
    }
}