use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class FileSystemMailContentStoreTest method saveMessageWhenInstableCustomMessageID.
@Test
public void saveMessageWhenInstableCustomMessageID() throws Exception {
String batchId = UUID.randomUUID().toString();
String mimeMessageId = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>";
ExtendedMimeMessage message = new ExtendedMimeMessage();
message.setHeader("Message-ID", mimeMessageId);
message.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
this.mocker.getComponentUnderTest().save(batchId, message);
File tempDir = new File(TEMPORARY_DIRECTORY);
File batchDirectory = new File(new File(tempDir, this.mocker.getComponentUnderTest().ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8"));
File messageFile = new File(batchDirectory, URLEncoder.encode(message.getUniqueMessageId(), "UTF-8"));
InputStream in = new FileInputStream(messageFile);
String messageContent = IOUtils.toString(in);
assertTrue(messageContent.contains("Message-ID: " + message.getMessageID()));
assertTrue(messageContent.contains("Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
}
use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class FileSystemMailContentStoreTest method saveMessage.
@Test
public void saveMessage() throws Exception {
String batchId = UUID.randomUUID().toString();
ExtendedMimeMessage message = new ExtendedMimeMessage();
message.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
this.mocker.getComponentUnderTest().save(batchId, message);
String messageId = message.getMessageID();
File tempDir = new File(TEMPORARY_DIRECTORY);
File batchDirectory = new File(new File(tempDir, this.mocker.getComponentUnderTest().ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8"));
File messageFile = new File(batchDirectory, URLEncoder.encode(message.getUniqueMessageId(), "UTF-8"));
InputStream in = new FileInputStream(messageFile);
String messageContent = IOUtils.toString(in);
assertTrue(messageContent.contains("Message-ID: " + messageId));
assertTrue(messageContent.contains("Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
}
use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class MemoryMailListenerTest method onErrorAndGetMailStatusResult.
@Test
public void onErrorAndGetMailStatusResult() throws Exception {
MemoryMailListener listener = this.mocker.getComponentUnderTest();
String batchId = UUID.randomUUID().toString();
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap());
ExtendedMimeMessage message1 = mock(ExtendedMimeMessage.class);
when(message1.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID1);
when(message1.getType()).thenReturn("mailtype1");
listener.onPrepareMessageError(message1, new Exception("error1"), Collections.<String, Object>emptyMap());
ExtendedMimeMessage message2 = mock(ExtendedMimeMessage.class);
when(message2.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID2);
when(message2.getType()).thenReturn("mailtype2");
listener.onPrepareMessageError(message2, new Exception("error2"), Collections.<String, Object>emptyMap());
Iterator<MailStatus> results = listener.getMailStatusResult().getByState(MailState.PREPARE_ERROR);
assertTrue("These should be mails in error!", results.hasNext());
MailStatus status = results.next();
assertEquals("Exception: error1", status.getErrorSummary());
assertTrue(status.getErrorDescription().contains("error1"));
assertEquals(batchId, status.getBatchId());
assertEquals(UNIQUE_MESSAGE_ID1, status.getMessageId());
assertEquals("mailtype1", status.getType());
status = results.next();
assertEquals("Exception: error2", status.getErrorSummary());
assertTrue(status.getErrorDescription().contains("error2"));
assertEquals(batchId, status.getBatchId());
assertEquals(UNIQUE_MESSAGE_ID2, status.getMessageId());
assertEquals("mailtype2", status.getType());
assertFalse(results.hasNext());
}
use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class GroupMimeMessageIterator method createMessageInternal.
@Override
protected ExtendedMimeMessage createMessageInternal() throws MessagingException {
ExtendedMimeMessage mimeMessage;
DocumentReference groupsClassReference = this.stringResolver.resolve(USER_SPACE + ".XWikiGroups");
String userFullName = this.documentAccessBridge.getProperty(this.groupReference, groupsClassReference, this.position, "member").toString();
DocumentReference userReference = this.stringResolver.resolve(userFullName);
// If the user has no email address then return a null Mime Message so that it's skipped
Object emailObject = this.documentAccessBridge.getProperty(userReference, new DocumentReference(userReference.getWikiReference().getName(), USER_SPACE, "XWikiUsers"), "email");
if (emailObject != null) {
String email = emailObject.toString();
Map<String, Object> parameters = (Map<String, Object>) this.parameters.get("parameters");
mimeMessage = ExtendedMimeMessage.wrap(this.factory.createMessage(this.parameters.get("source"), parameters));
mimeMessage.addRecipients(Message.RecipientType.TO, email);
} else {
getLogger().warn("User [{}] has no email defined. Email has not been sent to that user.", userReference);
mimeMessage = null;
}
return mimeMessage;
}
use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class FileSystemMailContentStore method load.
@Override
public ExtendedMimeMessage load(Session session, String batchId, String uniqueMessageId) throws MailStoreException {
File messageFile = null;
try {
messageFile = getMessageFile(batchId, uniqueMessageId);
InputStream is = new FileInputStream(messageFile);
return new ExtendedMimeMessage(session, is);
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to load message (id [%s], batch id [%s]) from file [%s]", uniqueMessageId, batchId, messageFile), e);
}
}
Aggregations