Example usage for javax.mail.internet MimeMessage getSubject

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

Introduction

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

Prototype

@Override
public String getSubject() throws MessagingException 

Source Link

Document

Returns the value of the "Subject" header field.

Usage

From source file:Main.java

public static String getSubject(MimeMessage msg) throws UnsupportedEncodingException, MessagingException {
    return decodeText(msg.getSubject());
}

From source file:Main.java

private static String getSubject(MimeMessage msg) throws MessagingException, UnsupportedEncodingException {
    return MimeUtility.decodeText(msg.getSubject());
}

From source file:it.ozimov.springboot.templating.mail.utils.EmailToMimeMessageTest.java

public static void validateSubject(final Email email, final MimeMessage sentMessage)
        throws MessagingException, IOException {
    assertThat(sentMessage.getSubject(), is(email.getSubject()));
}

From source file:javamailclient.GmailAPI.java

public static Map getMessageDetails(String messageId) throws IOException, MessagingException {
    Map<String, String> mapDetails = new HashMap<String, String>();
    Message message = service.users().messages().get("me", messageId).setFormat("raw").execute();
    byte[] bytes = Base64.decodeBase64(message.getRaw());

    Properties prop = new Properties();
    Session session = Session.getDefaultInstance(prop, null);

    MimeMessage email = new MimeMessage(session, new ByteArrayInputStream(bytes));
    mapDetails.put("subject", email.getSubject());
    String from = "None";
    if (email.getSender() != null) {
        from = email.getSender().toString();
    }// w w  w. jav a 2  s .c o  m
    mapDetails.put("from", from);
    String date = "Unknown";
    if (email.getReceivedDate() != null) {
        date = email.getReceivedDate().toString();
    }
    mapDetails.put("receiveddate", date);
    date = "Unknown";
    if (email.getSentDate() != null) {
        date = email.getSentDate().toString();
    }
    mapDetails.put("senddate", date);
    mapDetails.put("body", getMessageBody(email));
    return mapDetails;
}

From source file:com.joshlong.lazyblogger.integrations.EmailToBlogTransformer.java

public Message<?> transformFromMimeMessageToBlogPost(Message<?> msg) {
    Message<?> response = null; // if this is null, the message will just get dropped.
    BlogPost blogPost = new BlogPost();
    try {// w  w w . j av a2s.  c  om

        MimeMessage mimeMessage = (MimeMessage) msg.getPayload();
        blogPost.setSubject(mimeMessage.getSubject());
        blogPost.setDate(mimeMessage.getSentDate());
        blogPost.setBody(IOUtils.toString(mimeMessage.getInputStream()));

        if (mimeMessage.getSender() != null)
            blogPost.addSender(emailFromAddress(mimeMessage.getSender()));

        if (mimeMessage.getFrom() != null)
            for (Address address : mimeMessage.getFrom())
                blogPost.addSender(emailFromAddress(address));

        response = MessageBuilder.withPayload(blogPost).copyHeadersIfAbsent(msg.getHeaders()).build();
    } catch (Throwable e) {
        utilities.log(ExceptionUtils.getFullStackTrace(e));
    }
    return response;
}

From source file:nl.surfnet.coin.shared.service.MockJavaMailSender.java

@Override
public void send(MimeMessage mimeMessage) throws MailException {
    try {//from  w  ww  .j  av a  2  s.  co  m
        String body = mimeMessage.getContent().toString();
        logger.info("Subject: " + mimeMessage.getSubject() + "\n" + "Message: " + body);
    } catch (Exception e) {
        logger.error("Something went wrong", e);
    }
}

From source file:mitm.application.djigzo.james.mailets.FilterSubject.java

@Override
public void serviceMail(Mail mail) {
    try {//from w ww. j a va  2s  .com
        MimeMessage message = mail.getMessage();

        String currentSubject = message.getSubject();

        if (currentSubject != null) {
            String[] filter = getFilter(mail);

            if (filter != null) {
                Pattern pattern = patternCache.getPattern(StringUtils.defaultString(filter[0]));

                if (pattern != null) {
                    String newSubject = pattern.matcher(currentSubject)
                            .replaceAll(StringUtils.defaultString(filter[1]));

                    logger.debug("Currrent subject: {}, new subject: {}", currentSubject, newSubject);

                    message.setSubject(newSubject);
                }
            }
        } else {
            logger.debug("Subject is null");
        }
    } catch (MessagingException e) {
        logger.error("Error adding text to subject", e);
    }
}

From source file:eu.openanalytics.rsb.EmailDepositITCase.java

private MimeMessage ponderForRsbResponse(final String subject) throws InterruptedException, MessagingException {
    final MimeMessage[] rsbResponseMessages = waitForRsbResponse();
    assertThat(rsbResponseMessages.length, is(1));
    final MimeMessage rsbResponseMessage = rsbResponseMessages[0];
    assertThat(rsbResponseMessage.getSubject(), is("RE: " + subject));
    return rsbResponseMessage;
}

From source file:com.it.j2ee.email.MailServiceTest.java

@Test
public void sendSimpleMail() throws MessagingException, InterruptedException, IOException {
    simpleMailService.sendNotificationMail("calvin");

    greenMail.waitForIncomingEmail(2000, 1);

    MimeMessage[] messages = greenMail.getReceivedMessages();
    MimeMessage message = messages[messages.length - 1];

    assertThat(message.getFrom()[0].toString()).isEqualTo("springside3.demo@gmail.com");
    assertThat(message.getSubject()).isEqualTo("");
    // text?/*from   w  w  w. ja va  2  s. c o  m*/
    System.out.println(message.getContent());
    assertThat(((String) message.getContent())).contains("");
}

From source file:com.it.j2ee.email.MailServiceTest.java

@Test
public void sendMimeMail() throws InterruptedException, MessagingException, IOException {
    mimeMailService.sendNotificationMail("calvin");

    greenMail.waitForIncomingEmail(2000, 1);
    MimeMessage[] messages = greenMail.getReceivedMessages();
    MimeMessage message = messages[messages.length - 1];

    assertThat(message.getFrom()[0].toString()).isEqualTo("springside3.demo@gmail.com");
    assertThat(message.getSubject()).isEqualTo("");

    MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();

    assertThat(mimeMultipart.getCount()).isEqualTo(2);

    // Html?// w w  w .j av  a 2 s.  co  m
    String mainPartText = getMainPartText(mimeMultipart.getBodyPart(0));
    System.out.println(mainPartText);
    assertThat(mainPartText).contains("<h1>calvin.</h1>");

    // 
    assertThat(GreenMailUtil.getBody(mimeMultipart.getBodyPart(1)).trim())
            .isEqualTo("Hello,i am a attachment.");
}