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:com.haulmont.cuba.core.app.EmailSender.java

@Override
public void sendEmail(SendingMessage sendingMessage) throws MessagingException {
    MimeMessage msg = createMimeMessage(sendingMessage);

    StopWatch sw = new Slf4JStopWatch("EmailSender.send");
    mailSender.send(msg);/*from  ww  w  .ja v a2  s  .c  om*/
    sw.stop();

    log.info("Email '{}' to '{}' has been sent successfully", msg.getSubject(), sendingMessage.getAddress());
}

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

@Test
public void testMissingSubject() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    Mailet mailet = new FilterSubject();

    mailetConfig.setInitParameter("filter", "/(^(.*)$)/ test");

    mailet.init(mailetConfig);/* www  .  ja  v a  2 s . c o m*/

    MockMail mail = new MockMail();

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/test-5K.eml"));

    assertNull(message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertNull(message.getSubject());
}

From source file:fi.foyt.fni.test.ui.base.gamelibrary.GameLibraryProposeGameTestsBase.java

@Test
@SqlSets("basic-users")
public void testPropose() throws Exception {
    if ("chrome".equals(getBrowser())) {
        // FIXME: File uploading fails with bad gateway on Sauce Labs when using Chrome.
        return;//from  ww  w. j  a v  a 2  s . com
    }

    loginInternal("user@foyt.fi", "pass");
    navigate("/gamelibrary/proposegame/");

    File testPng = getTestPng();
    File testPdf = getTestPdf();

    waitAndSendKeys(".gamelibrary-propose-game-form-name", "My awesome game");
    waitAndSendKeys(".gamelibrary-propose-game-form-description", "This game is just pretty awesome");
    waitAndSendKeys(".gamelibrary-propose-game-form-authors-share", "5");

    waitAndSendKeys(".gamelibrary-propose-game-form-section-image input[name='file']",
            testPng.getAbsolutePath());
    waitForSelectorPresent(".gamelibrary-propose-game-form-section-image .upload-field-file-name");
    assertSelectorCount(".gamelibrary-propose-game-form-section-image .upload-field-file-name", 1);
    assertSelectorText(".gamelibrary-propose-game-form-section-image .upload-field-file-name",
            testPng.getName(), true, true);

    waitAndSendKeys(".gamelibrary-propose-game-form-section-downloadable input[name='file']",
            testPdf.getAbsolutePath());
    waitForSelectorPresent(".gamelibrary-propose-game-form-section-downloadable .upload-field-file-name");
    assertSelectorCount(".gamelibrary-propose-game-form-section-downloadable .upload-field-file-name", 1);
    assertSelectorText(".gamelibrary-propose-game-form-section-downloadable .upload-field-file-name",
            testPdf.getName(), true, true);

    waitAndSendKeys(".gamelibrary-propose-game-form-section-printable input[name='file']",
            testPdf.getAbsolutePath());
    waitForSelectorPresent(".gamelibrary-propose-game-form-section-printable .upload-field-file-name");
    assertSelectorCount(".gamelibrary-propose-game-form-section-printable .upload-field-file-name", 1);
    assertSelectorText(".gamelibrary-propose-game-form-section-printable .upload-field-file-name",
            testPdf.getName(), true, true);

    waitAndClick(".gamelibrary-propose-game-send");

    MimeMessage[] messages = getGreenMail().getReceivedMessages();
    assertEquals(2, messages.length);

    List<String> recipientAddressses = new ArrayList<>();

    for (MimeMessage message : messages) {
        assertEquals("New Publication into the Game Library", message.getSubject());
        assertTrue(StringUtils.contains((String) message.getContent(),
                "Test User (user@foyt.fi) has proposed that My awesome game"));
        Address[] recipients = message.getRecipients(RecipientType.TO);

        for (Address recipient : recipients) {
            String address = ((InternetAddress) recipient).getAddress();
            if (!recipientAddressses.contains(address)) {
                recipientAddressses.add(address);
            }
        }

    }

    assertEquals(Arrays.asList("librarian@foyt.fi", "admin@foyt.fi"), recipientAddressses);

    waitForSelectorVisible(".gamelibrary-publication h3 a");

    assertSelectorText(".gamelibrary-publication h3 a", "My awesome game", true, true);
    assertSelectorText(".gamelibrary-publication .gamelibrary-publication-description",
            "This game is just pretty awesome", true, true);

    executeSql(
            "update PublicationFile set contentType = 'DELETE' where id in (select printableFile_id from BookPublication where id in (select id from Publication where creator_id = ?) union select downloadableFile_id from BookPublication where id in (select id from Publication where creator_id = ?))",
            2, 2);
    executeSql("update Publication set defaultImage_id = null where creator_id = ?", 2);
    executeSql(
            "Update BookPublication set printableFile_id = null, downloadableFile_id = null where id in (select id from Publication where creator_id = ?)",
            2);
    executeSql(
            "delete from PublicationImage where publication_id in (select id from Publication where creator_id = ?)",
            2);
    executeSql("delete from PublicationFile where contentType = 'DELETE'");
    executeSql("delete from BookPublication where id in (select id from Publication where creator_id = ?)", 2);
    executeSql("delete from Publication where creator_id = ?", 2);
}

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

@Test
public void testNullFilter() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    Mailet mailet = new FilterSubject();

    mailet.init(mailetConfig);//from  ww  w.  j av  a2s . c  o m

    MockMail mail = new MockMail();

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test simple message", message.getSubject());
}

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

@Test
public void testStaticFilter() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    Mailet mailet = new FilterSubject();

    mailetConfig.setInitParameter("filter", "/e$/ %^&*");

    mailet.init(mailetConfig);//  w w  w  . j  a v  a 2s  .c  om

    MockMail mail = new MockMail();

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test simple messag%^&*", message.getSubject());
}

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

@Test
public void testEmptyReplace() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    Mailet mailet = new FilterSubject();

    mailetConfig.setInitParameter("filter", "/simple/");

    mailet.init(mailetConfig);//from www. j  ava 2s.  c o  m

    MockMail mail = new MockMail();

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test  message", message.getSubject());
}

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

@Test
public void testAttribute() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    Mailet mailet = new FilterSubject();

    mailetConfig.setInitParameter("attribute", "attribute");

    mailet.init(mailetConfig);/*from  www  .  j a  v a2 s  .  com*/

    MockMail mail = new MockMail();

    mail.setAttribute("attribute", "/(simple)/ *$1$1*");

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test *simplesimple* message", message.getSubject());
}

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

@Test
public void testInvalidFilter() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    mailetConfig.setInitParameter("attribute", "attribute");

    Mailet mailet = new FilterSubject();

    mailet.init(mailetConfig);//w  ww .j av  a2 s  .  co  m

    MockMail mail = new MockMail();

    mail.setAttribute("attribute", "invalid");

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test simple message", message.getSubject());
}

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

@Test
public void testInvalidRegExp() throws Exception {
    MockMailetConfig mailetConfig = new MockMailetConfig("test");

    mailetConfig.setInitParameter("attribute", "attribute");

    Mailet mailet = new FilterSubject();

    mailet.init(mailetConfig);//from   w w  w  .  j av  a 2  s  .c om

    MockMail mail = new MockMail();

    mail.setAttribute("attribute", "/[x/ test");

    MimeMessage message = MailUtils.loadMessage(new File(testBase, "mail/simple-text-message.eml"));

    assertEquals("test simple message", message.getSubject());

    mail.setMessage(message);

    Collection<MailAddress> recipients = new LinkedList<MailAddress>();

    recipients.add(new MailAddress("test@example.com"));

    mail.setRecipients(recipients);

    mail.setSender(new MailAddress("sender@example.com"));

    mailet.service(mail);

    message = mail.getMessage();

    assertEquals("test simple message", message.getSubject());
}

From source file:mitm.common.security.smime.SMIMEEnvelopedInspectorImplTest.java

@Test
public void testOutlook2010MissingSubjKeyIdWorkAround() throws Exception {
    MimeMessage message = loadMessage("outlook2010_cert_missing_subjkeyid.eml");

    KeyStoreKeyProvider keyStoreKeyProvider = new KeyStoreKeyProvider(
            loadKeyStore(new File("test/resources/testdata/keys/outlook2010_cert_missing_subjkeyid.p12"), ""),
            "");//from www  .  j a v a2 s  .  c o m

    keyStoreKeyProvider.setUseOL2010Workaround(true);

    SMIMEEnvelopedInspector inspector = new SMIMEEnvelopedInspectorImpl(message, keyStoreKeyProvider,
            securityFactory.getNonSensitiveProvider(), securityFactory.getSensitiveProvider());

    MimeMessage decrypted = inspector.getContentAsMimeMessage();

    File file = new File(tempDir, "test-testOutlook2010MissingSubjKeyId-decrypted.eml");

    MailUtils.writeMessage(decrypted, file);

    assertNotNull(decrypted);
    assertTrue(decrypted.isMimeType("text/plain"));
    assertNull(decrypted.getSubject());
    assertEquals("Created with Outlook 2010 Beta (14.0.4536.1000)",
            StringUtils.trim((String) decrypted.getContent()));
}