Search in sources :

Example 1 with EmailAddress

use of org.opencastproject.kernel.mail.EmailAddress in project opencast by opencast.

the class MailService method toMimeMessage.

/**
 * Message -> MimeMessage.
 */
private MimeMessage toMimeMessage(Mail mail) throws Exception {
    final MimeMessage msg = smtpService.createMessage();
    for (EmailAddress reply : mail.getReplyTo()) msg.setReplyTo(new Address[] { new InternetAddress(reply.getAddress(), reply.getName(), "UTF-8") });
    // recipient
    for (EmailAddress recipient : mail.getRecipients()) {
        msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(recipient.getAddress(), recipient.getName(), "UTF-8"));
    }
    // subject
    msg.setSubject(mail.getSubject());
    EmailAddress from = mail.getSender();
    msg.setFrom(new InternetAddress(from.getAddress(), from.getName(), "UTF-8"));
    // body
    msg.setText(mail.getBody(), "UTF-8");
    return msg;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) EmailAddress.getAddress(org.opencastproject.kernel.mail.EmailAddress.getAddress) InternetAddress(javax.mail.internet.InternetAddress) EmailAddress(org.opencastproject.kernel.mail.EmailAddress) MimeMessage(javax.mail.internet.MimeMessage) EmailAddress(org.opencastproject.kernel.mail.EmailAddress)

Example 2 with EmailAddress

use of org.opencastproject.kernel.mail.EmailAddress in project opencast by opencast.

the class MessageSignatureDto method toMessageSignature.

/**
 * Returns the business object of this message signature
 *
 * @return the business object model of this message signature
 */
public MessageSignature toMessageSignature(UserDirectoryService userDirectoryService) {
    final Option<EmailAddress> reply;
    if (replyTo != null && replyToName != null) {
        reply = some(new EmailAddress(replyTo, replyToName));
    } else {
        reply = none();
    }
    User user = userDirectoryService.loadUser(creator);
    return new MessageSignature(id, name, user, new EmailAddress(sender, senderName), reply, signature, creationDate);
}
Also used : User(org.opencastproject.security.api.User) MessageSignature(org.opencastproject.messages.MessageSignature) EmailAddress(org.opencastproject.kernel.mail.EmailAddress)

Example 3 with EmailAddress

use of org.opencastproject.kernel.mail.EmailAddress in project opencast by opencast.

the class UserSettingsTest method toJsonInputSettingAndSignatureExpectedAllInJson.

@Test
public void toJsonInputSettingAndSignatureExpectedAllInJson() throws Exception {
    InputStream stream = SeriesEndpointTest.class.getResourceAsStream("/user_settings_test_example.json");
    InputStreamReader reader = new InputStreamReader(stream);
    JSONObject expected = (JSONObject) new JSONParser().parse(reader);
    User creator = EasyMock.createMock(User.class);
    EasyMock.expect(creator.getName()).andReturn("Users Name").anyTimes();
    EasyMock.expect(creator.getUsername()).andReturn("username12").anyTimes();
    EasyMock.expect(creator.getEmail()).andReturn("adam@fake.com").anyTimes();
    EasyMock.replay(creator);
    EmailAddress sender = new EmailAddress("adam@fake.com", "Other Name");
    Option<EmailAddress> replyTo = none();
    DateTime dateTime = new DateTime(1401465634101L);
    dateTime.toDateTime(DateTimeZone.UTC);
    // MessageSignature messageSignature = new MessageSignature(10L, "Adam McKenzie", creator, sender, replyTo,
    // "This is the signature", dateTime.toDate(), nil(Comment.class));
    Collection<MessageSignature> signatures = new LinkedList<MessageSignature>();
    // signatures.add(messageSignature);
    UserSetting userSetting = new UserSetting(98, "Test Key", "Test Value");
    UserSettings userSettings = new UserSettings();
    userSettings.setTotal(1);
    userSettings.addUserSetting(userSetting);
    assertThat(expected.toJSONString(), SameJSONAs.sameJSONAs(userSettings.toJson().toJson()));
}
Also used : User(org.opencastproject.security.api.User) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) EmailAddress(org.opencastproject.kernel.mail.EmailAddress) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) MessageSignature(org.opencastproject.messages.MessageSignature) SeriesEndpointTest(org.opencastproject.adminui.endpoint.SeriesEndpointTest) Test(org.junit.Test)

Aggregations

EmailAddress (org.opencastproject.kernel.mail.EmailAddress)3 MessageSignature (org.opencastproject.messages.MessageSignature)2 User (org.opencastproject.security.api.User)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LinkedList (java.util.LinkedList)1 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 DateTime (org.joda.time.DateTime)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1 Test (org.junit.Test)1 SeriesEndpointTest (org.opencastproject.adminui.endpoint.SeriesEndpointTest)1 EmailAddress.getAddress (org.opencastproject.kernel.mail.EmailAddress.getAddress)1