public static Message composeMessage()

in server/src/main/java/org/apache/hupa/server/service/SendMessageBaseServiceImpl.java [322:380]


    public static Message composeMessage (Message message, String text, String html, List parts) throws MessagingException, IOException {

        MimeBodyPart txtPart = null;
        MimeBodyPart htmlPart = null;
        MimeMultipart mimeMultipart = null;

        if (text == null && html == null) {
           text = "";
        }
        if (text != null) {
            txtPart = new MimeBodyPart();
            txtPart.setContent(text, "text/plain; charset=UTF-8");
        }
        if (html != null) {
            htmlPart = new MimeBodyPart();
            htmlPart.setContent(html, "text/html; charset=UTF-8");
        }
        if (html != null && text != null) {
            mimeMultipart = new MimeMultipart();
            mimeMultipart.setSubType("alternative");
            mimeMultipart.addBodyPart(txtPart);
            mimeMultipart.addBodyPart(htmlPart);
        }

        if (parts == null || parts.isEmpty()) {
            if (mimeMultipart != null) {
                message.setContent(mimeMultipart);
            } else if (html != null) {
                message.setText(html);
                message.setHeader("Content-type", "text/html");
            } else if (text != null) {
                message.setText(text);
            }
        } else {
            MimeBodyPart bodyPart = new MimeBodyPart();
            if (mimeMultipart != null) {
                bodyPart.setContent(mimeMultipart);
            } else if (html != null) {
                bodyPart.setText(html);
                bodyPart.setHeader("Content-type", "text/html");
            } else if (text != null) {
                bodyPart.setText(text);
            }
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(bodyPart);
            for (Object attachment: parts) {
                if (attachment instanceof FileItem) {
                    multipart.addBodyPart(MessageUtils.fileitemToBodypart((FileItem)attachment));
                } else {
                    multipart.addBodyPart((BodyPart)attachment);
                }
            }
            message.setContent(multipart);
        }

        message.saveChanges();
        return message;

    }