Example usage for javax.mail Message getSubject

List of usage examples for javax.mail Message getSubject

Introduction

In this page you can find the example usage for javax.mail Message getSubject.

Prototype

public abstract String getSubject() throws MessagingException;

Source Link

Document

Get the subject of this message.

Usage

From source file:org.sourceforge.net.javamail4ews.transport.EwsTransport.java

private void createSubject(EmailMessage msg, Message message) throws MessagingException, Exception {
    msg.setSubject(message.getSubject());
}

From source file:com.canoo.webtest.plugins.emailtest.AbstractSelectStep.java

boolean messageMatches(final Message message) throws MessagingException {
    if (!doMatch(getFrom(), message.getFrom()[0].toString())) {
        return false;
    }/* w  w w .j a  v  a 2s  .c om*/
    if (!doMatch(getSubject(), message.getSubject())) {
        return false;
    }
    if (!doMatchMultiple(getReplyTo(), message.getReplyTo())) {
        return false;
    }
    if (!doMatchMultiple(getCc(), message.getRecipients(MimeMessage.RecipientType.CC))) {
        return false;
    }
    return doMatchMultiple(getTo(), message.getRecipients(MimeMessage.RecipientType.TO));
}

From source file:it.greenvulcano.gvesb.virtual.smtp.SMTPCallOperationTest.java

/**
  * Tests email send//  w w  w. j  a v  a  2s  . c  o  m
  *
  * @throws Exception
  *         if any error occurs
  */
public final void testSendEmail() throws Exception {
    Node node = XMLConfig.getNode("GVCore.xml", "//*[@name='SendEmail']");
    CallOperation op = new SMTPCallOperation();
    op.init(node);

    GVBuffer gvBuffer = new GVBuffer(TEST_SYSTEM, TEST_SERVICE);
    gvBuffer.setObject(TEST_MESSAGE);
    gvBuffer.setProperty("MAIL_SENDER", "SENDER ADDITIONAL INFO");

    op.perform(gvBuffer);

    //assertTrue(server.waitForIncomingEmail(5000, 1));

    Message[] messages = server.getReceivedMessages();
    assertEquals(1, messages.length);
    Message email = messages[0];
    Multipart mp = (Multipart) email.getContent();
    assertEquals("Notifica SendEmail", email.getSubject());
    assertEquals(TEST_MESSAGE, GreenMailUtil.getBody(mp.getBodyPart(0)));

    System.out.println("---------MAIL DUMP: START");
    System.out.println("Headers:\n" + GreenMailUtil.getHeaders(email));
    System.out.println("---------");
    System.out.println("Body:\n" + GreenMailUtil.getBody(email));
    System.out.println("---------MAIL DUMP: END");
    assertEquals("Notifica SendEmail", email.getHeader("Subject")[0]);
    assertEquals("1", email.getHeader("X-Priority")[0]);
}

From source file:com.cubusmail.server.mail.util.MessageComparator.java

public int compare(Message msg1, Message msg2) {

    int result = 0;

    if (msg1.isExpunged() || msg2.isExpunged()) {
        return result;
    }// w w  w . j ava  2s.  c  om

    try {
        if (MessageListFields.SUBJECT == this.field) {
            if (msg1.getSubject() != null && msg2.getSubject() != null) {
                result = msg1.getSubject().compareToIgnoreCase(msg2.getSubject());
            } else {
                result = -1;
            }
        } else if (MessageListFields.FROM == this.field) {
            String fromString1 = MessageUtils.getMailAdressString(msg1.getFrom(), AddressStringType.PERSONAL);
            String fromString2 = MessageUtils.getMailAdressString(msg2.getFrom(), AddressStringType.PERSONAL);
            if (fromString1 != null && fromString2 != null) {
                result = fromString1.compareToIgnoreCase(fromString2);
            } else {
                result = -1;
            }
        } else if (MessageListFields.SEND_DATE == this.field) {
            Date date1 = msg1.getSentDate();
            Date date2 = msg2.getSentDate();
            if (date1 != null && date2 != null) {
                result = date1.compareTo(date2);
            } else {
                result = -1;
            }
        } else if (MessageListFields.SIZE == this.field) {
            int size1 = msg1.getSize();
            int size2 = msg2.getSize();
            result = Integer.valueOf(size1).compareTo(Integer.valueOf(size2));

        }
    } catch (MessagingException e) {
        log.warn(e.getMessage(), e);
    }

    if (!this.ascending) {
        result = result * (-1);
    }

    return result;
}

From source file:it.greenvulcano.gvesb.virtual.smtp.SMTPCallOperationTest.java

/**
 * Tests email send/*w  ww .  jav a2 s.  c  o  m*/
 *
 * @throws Exception
 *         if any error occurs
 */
public final void testSendEmailBufferAttach() throws Exception {
    Node node = XMLConfig.getNode("GVCore.xml", "//*[@name='SendEmailBufferAttach']");
    CallOperation op = new SMTPCallOperation();
    op.init(node);

    GVBuffer gvBuffer = new GVBuffer(TEST_SYSTEM, TEST_SERVICE);
    gvBuffer.setObject(TEST_MESSAGE);

    op.perform(gvBuffer);

    Message[] messages = server.getReceivedMessages();
    assertEquals(1, messages.length);
    Message email = messages[0];
    Multipart mp = (Multipart) email.getContent();
    assertEquals("Notifica SendEmailBufferAttach", email.getSubject());
    assertEquals(TEST_MESSAGE_1, GreenMailUtil.getBody(mp.getBodyPart(0)));

    System.out.println("---------MAIL DUMP: START");
    System.out.println("Headers:\n" + GreenMailUtil.getHeaders(email));
    System.out.println("---------");
    System.out.println("Body:\n" + GreenMailUtil.getBody(mp.getBodyPart(0)));
    System.out.println("---------MAIL DUMP: END");
    assertEquals("Notifica SendEmailBufferAttach", email.getHeader("Subject")[0]);
    assertEquals("Current Data", mp.getBodyPart(1).getFileName());
}

From source file:it.greenvulcano.gvesb.virtual.smtp.SMTPCallOperationTest.java

/**
 * Tests email send//from  www  .j av  a2  s .c  o m
 *
 * @throws Exception
 *         if any error occurs
 */
public final void testSendEmailDynamicDest() throws Exception {
    Node node = XMLConfig.getNode("GVCore.xml", "//*[@name='SendEmailDynamicDest']");
    CallOperation op = new SMTPCallOperation();
    op.init(node);

    GVBuffer gvBuffer = new GVBuffer(TEST_SYSTEM, TEST_SERVICE);
    gvBuffer.setObject(TEST_MESSAGE);

    gvBuffer.setProperty("GV_SMTP_TO", "test1@gv.com");
    gvBuffer.setProperty("GV_SMTP_CC", "test2@gv.com");
    gvBuffer.setProperty("GV_SMTP_BCC", "test3@gv.com");

    op.perform(gvBuffer);

    Message[] messages = server.getReceivedMessages();
    assertEquals(3, messages.length);
    Message email = messages[0];
    Multipart mp = (Multipart) email.getContent();
    assertEquals("Notifica SendEmailDynamicDest", email.getSubject());
    assertEquals(TEST_MESSAGE_1, GreenMailUtil.getBody(mp.getBodyPart(0)));

    System.out.println("---------MAIL DUMP: START");
    System.out.println("Headers:\n" + GreenMailUtil.getHeaders(email));
    System.out.println("---------");
    System.out.println("Body:\n" + GreenMailUtil.getBody(email));
    System.out.println("---------MAIL DUMP: END");
    assertEquals("Notifica SendEmailDynamicDest", email.getHeader("Subject")[0]);
    assertEquals("test1@gv.com", email.getHeader("To")[0]);
    assertEquals("test2@gv.com", email.getHeader("Cc")[0]);
}

From source file:org.usergrid.rest.management.RegistrationIT.java

private Message[] getMessages(String host, String user, String password)
        throws MessagingException, IOException {

    Session session = Session.getDefaultInstance(new Properties());
    Store store = session.getStore("imap");
    store.connect(host, user, password);

    Folder folder = store.getFolder("inbox");
    folder.open(Folder.READ_ONLY);// ww w.  ja  v  a 2s .  com
    Message[] msgs = folder.getMessages();

    for (Message m : msgs) {
        logger.info("Subject: " + m.getSubject());
        logger.info("Body content 0 " + (String) ((MimeMultipart) m.getContent()).getBodyPart(0).getContent());
        logger.info("Body content 1 " + (String) ((MimeMultipart) m.getContent()).getBodyPart(1).getContent());
    }
    return msgs;
}

From source file:org.apache.usergrid.rest.management.RegistrationIT.java

private Message[] getMessages(String host, String user, String password)
        throws MessagingException, IOException {

    Session session = Session.getDefaultInstance(new Properties());
    Store store = session.getStore("imap");
    store.connect(host, user, password);

    Folder folder = store.getFolder("inbox");
    folder.open(Folder.READ_ONLY);//  www  .j a v  a  2  s . com
    Message[] msgs = folder.getMessages();

    for (Message m : msgs) {
        logger.info("Subject: " + m.getSubject());
        logger.info("Body content 0 " + ((MimeMultipart) m.getContent()).getBodyPart(0).getContent());
        logger.info("Body content 1 " + ((MimeMultipart) m.getContent()).getBodyPart(1).getContent());
    }
    return msgs;
}

From source file:org.nuxeo.ecm.platform.mail.action.TransformMessageAction.java

public boolean execute(ExecutionContext context) throws MessagingException {
    Message message = context.getMessage();
    if (log.isDebugEnabled()) {
        log.debug("Transforming message" + message.getSubject());
    }//w w  w .  j a  v a  2 s  .c om
    if (message.getFrom() != null && message.getFrom().length != 0) {
        List<String> contributors = new ArrayList<String>();
        for (Address ad : message.getFrom()) {
            contributors.add(safelyDecodeText(ad.toString()));
        }
        dcSchema.put("contributors", contributors);
        dcSchema.put("creator", contributors.get(0));
        dcSchema.put("created", message.getReceivedDate());
    }
    if (message.getAllRecipients() != null && message.getAllRecipients().length != 0) {
        List<String> recipients = new ArrayList<String>();
        for (Address address : message.getAllRecipients()) {
            recipients.add(safelyDecodeText(address.toString()));
        }
        mailSchema.put("recipients", recipients);
    }
    if (message instanceof MimeMessage) {
        try {
            processMimeMessage((MimeMessage) message);
        } catch (IOException e) {
            throw new MessagingException(e.getMessage(), e);
        }
    }
    mailSchema.put("text", text.toString());
    dcSchema.put("title", message.getSubject());
    context.put("transformed", schemas);
    return true;
}

From source file:org.xmlactions.email.EMailParser.java

public void mapMessage(Message message) throws IOException, MessagingException, DocumentException {

    log.info("reading email:" + message.getSubject());
    setLastMessage(message); // if this is set then we have an attached
    // message//from ww  w .j  av  a  2  s .  c  o m
    setFirstMessageProcessed(false);
    Object object = message;

    if (object instanceof Multipart) {
        mapMultiPart((Multipart) object);
    } else if (object instanceof Part) {
        // showPart((Part) content);
        handlePart((Part) object);
    } else {
        throw new IOException("Invalid content found in email:" + object.getClass().getName() + "\n" + object);
    }
}