Search in sources :

Example 6 with MimeMessageFactory

use of org.xwiki.mail.MimeMessageFactory in project xwiki-platform by xwiki.

the class WatchListEventMimeMessageFactory method createMessage.

@Override
public Iterator<MimeMessage> createMessage(Object sourceObject, Map<String, Object> parameters) throws MessagingException {
    Map<String, Object> source = getTypedSource(sourceObject, Map.class);
    validateParameters(parameters, HINT_PARAMETER, TEMPLATE_PARAMETER, PARAMETERS_PARAMETER);
    // Extract from the passed parameters the MimeMessageFactory to use to create a single mail
    String factoryHint = (String) parameters.get(HINT_PARAMETER);
    // TODO: is this configurable or should we always use "template" instead?
    MimeMessageFactory factory = getInternalMimeMessageFactory(factoryHint);
    // Parse the source.
    EventsAndSubscribersSource sourceData = EventsAndSubscribersSource.parse(source);
    // UserDataExtractor to be used for each subscriber.
    WatchListMessageDataExtractor userDataExtractor = new WatchListMessageDataExtractor(sourceData, parameters, eventMatcher, execution, explicitDocumentReferenceResolver);
    // The iterator that will be checking each subscriber and that will extract the WatchListMessageData.
    UserIterator<WatchListMessageData> userIterator = new UserIterator<WatchListMessageData>(EventsAndSubscribersSource.parse(source).getSubscribers(), null, userDataExtractor, explicitDocumentReferenceResolver, execution);
    // The iterator that will be producing a MimeMessage for each WatchListMessageData produced by the userIterator.
    WatchListEventMimeMessageIterator messageIterator = new WatchListEventMimeMessageIterator(userIterator, factory, parameters, avatarExtractor, serializer, sessionFactory);
    return messageIterator;
}
Also used : MimeMessageFactory(org.xwiki.mail.MimeMessageFactory) AbstractIteratorMimeMessageFactory(org.xwiki.mail.internal.factory.AbstractIteratorMimeMessageFactory) UserIterator(com.xpn.xwiki.internal.plugin.rightsmanager.UserIterator)

Aggregations

MimeMessageFactory (org.xwiki.mail.MimeMessageFactory)6 AbstractIteratorMimeMessageFactory (org.xwiki.mail.internal.factory.AbstractIteratorMimeMessageFactory)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Session (javax.mail.Session)2 MimeMessage (javax.mail.internet.MimeMessage)2 Test (org.junit.Test)2 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)2 ComponentManager (org.xwiki.component.manager.ComponentManager)2 ExtendedMimeMessage (org.xwiki.mail.ExtendedMimeMessage)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 UserIterator (com.xpn.xwiki.internal.plugin.rightsmanager.UserIterator)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 DocumentReferenceResolver (org.xwiki.model.reference.DocumentReferenceResolver)1