use of org.xwiki.mail.internal.thread.PrepareMailQueueItem in project xwiki-platform by xwiki.
the class DefaultMailSender method sendAsynchronously.
@Override
public MailResult sendAsynchronously(Iterable<? extends MimeMessage> messages, Session session, MailListener listener) {
// If the session has specified a batch id, then use it! This can be used for example when resending email.
String batchId = session.getProperty(SESSION_BATCHID_KEY);
if (batchId == null) {
batchId = UUID.randomUUID().toString();
}
// Pass a clone of the current execution context so that the mail message will be prepared and later sent in the
// same context, but in read-only mode (i.e. the preparation of the mail will not impact the current thread's
// context).
ExecutionContext executionContext = this.execution.getContext();
ExecutionContext clonedExecutionContext = this.executionContextCloner.copy(executionContext);
// TODO: Remove once we've found the reason for the functional Mail test flicker: from time to time the wiki
// is not set in the Mail Status LT
XWikiContext xcontext = (XWikiContext) clonedExecutionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
if (xcontext.getWikiId() == null) {
throw new RuntimeException(String.format("Aborting Mail Sending: the Wiki Id must not be null in the " + "XWiki Context. Got [%s] in the original context.", ((XWikiContext) executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).getWikiId()));
}
this.prepareMailQueueManager.addToQueue(new PrepareMailQueueItem(messages, session, listener, batchId, clonedExecutionContext));
return new DefaultMailResult(batchId);
}
Aggregations