Example usage for javax.mail.internet MimeMessage getSize

List of usage examples for javax.mail.internet MimeMessage getSize

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage getSize.

Prototype

@Override
public int getSize() throws MessagingException 

Source Link

Document

Return the size of the content of this message in bytes.

Usage

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithCcRecipientsAddresses() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("cc", ADDRESSPATTY);
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);//from  w  w  w .  j  av  a  2  s. c o m

    List<WiserMessage> messages = server.getMessages();
    assertEquals(2, messages.size());
    WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());

    message = messages.get(1);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSPATTY, message.getEnvelopeReceiver());
    mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());

    parameters.put("cc", ADDRESSPATTY + ", " + ADDRESSMARK);
    executeConnector(parameters);
    messages = server.getMessages();
    assertEquals(5, messages.size());
    message = messages.get(4);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSMARK, message.getEnvelopeReceiver());
    mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithExtraHeaders() throws Exception {
    final List<List<String>> headers = new ArrayList<List<String>>();
    List<String> row1 = new ArrayList<String>();
    row1.add("X-Mailer");
    row1.add("Bonita Mailer");
    headers.add(row1);//from ww  w.ja v a2 s .  co  m

    List<String> row2 = new ArrayList<String>();
    row2.add("Message-ID");
    row2.add("IWantToHackTheServer");
    headers.add(row2);

    List<String> row3 = new ArrayList<String>();
    row3.add("X-Priority");
    row3.add("2 (High)");
    headers.add(row3);

    List<String> row4 = new ArrayList<String>();
    row4.add("Content-Type");
    row4.add("video/mpeg");
    headers.add(row4);

    List<String> row5 = new ArrayList<String>();
    row5.add("WhatIWant");
    row5.add("anyValue");
    headers.add(row5);

    List<String> row6 = new ArrayList<String>();
    row6.add("From");
    row6.add("alice@bob.charly");
    headers.add(row6);

    List<String> row7 = new ArrayList<String>();
    row7.add(null);
    row7.add(null);
    headers.add(row7);

    final Map<String, Object> parameters = getBasicSettings();

    parameters.put("headers", headers);

    executeConnector(parameters);

    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertEquals("alice@bob.charly", message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
    assertEquals("Bonita Mailer", mime.getHeader("X-Mailer", ""));
    assertEquals("2 (High)", mime.getHeader("X-Priority", ""));
    assertEquals("anyValue", mime.getHeader("WhatIWant", ""));
    assertNotSame("alice@bob.charly", mime.getHeader("From"));
    assertFalse(mime.getContentType().contains("video/mpeg"));
    assertNotSame("IWantToHackTheServer", mime.getHeader("Message-ID"));
}

From source file:org.elasticsearch.river.email.EmailToJson.java

public static XContentBuilder toJson(Message message, String riverName, EmailRiverConfig config)
        throws IOException {
    XContentBuilder out = null;//from ww  w  . j a va2s. c  o m
    MimeMessage msg = (MimeMessage) message;
    try {
        List<AttachmentInfo> attachments = null;
        boolean hasAttachment = isContainAttachment(message);
        if (hasAttachment) {
            attachments = saveAttachmentToWeedFs(msg, attachments, config);
        }

        StringBuffer content = new StringBuffer(30);
        getMailTextContent(msg, content);

        int length = 200;
        String summary = delHTMLTag(content.toString());
        summary = (summary.length() > length ? summary.substring(0, length) + "..." : summary);

        out = jsonBuilder().startObject().field("subject", getSubject(msg))
                .field("sent_date", getSentDate(msg, null))
                //                    .field("recv_date", message.getReceivedDate())
                .field("from_mail", convertAddress(message.getFrom()))
                .field("reply_to_mail", convertAddress(message.getReplyTo())).field("from", getFrom(msg))
                .field("to", getReceiveAddress(msg, null)).field("content_type", getContentType(msg))
                .field("summary", summary).field("content", content.toString())
                .field("priority", getPriority(msg)).field("need_receipt", isReplySign(msg))
                .field("size", (msg.getSize() / 1024) + "kb").field("contain_attachment", hasAttachment)
                .field("timestamp", new Date().getTime()).field("via_river", riverName);
        if (attachments != null && attachments.size() > 0) {
            XContentBuilder array = out.field("attachments").startArray();
            for (int i = 0; i < attachments.size(); i++) {
                AttachmentInfo info = attachments.get(i);
                array.startObject().field("file_name", info.fileName).field("file_size", info.fileSize)
                        .field("file_id", info.fileId).field("summary", info.summary).endObject();
            }
            array.endArray();
        }
    } catch (MessagingException e) {
        logger.error("convert mail to json", e);
    }
    assert out != null;
    return out.endObject();
}