Search in sources :

Example 1 with MailReceivedEvent

use of won.bot.framework.eventbot.event.impl.mail.MailReceivedEvent in project webofneeds by researchstudio-sat.

the class MailParserAction method doRun.

protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (event instanceof MailReceivedEvent) {
        EventBus bus = getEventListenerContext().getEventBus();
        MimeMessage message = ((MailReceivedEvent) event).getMessage();
        String senderMailAddress = MailContentExtractor.getMailSender(message);
        try {
            if (mailContentExtractor.isCreateNeedMail(message)) {
                processCreateNeedMail(message);
            } else if (mailContentExtractor.isCommandMail(message)) {
                logger.debug("received a command mail publishing the MailCommand event");
                bus.publish(new MailCommandEvent(message));
            } else {
                logger.warn("unknown mail from user '{}' with subject '{}', no further processing required", senderMailAddress, message.getSubject());
            }
        } catch (MessagingException me) {
            logger.error("Messaging exception occurred while processing MimeMessage: {}", me);
            logger.warn("mail from user '{}' with subject '{}' could not be processed", senderMailAddress, message.getSubject());
        }
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) EventBus(won.bot.framework.eventbot.bus.EventBus) MailReceivedEvent(won.bot.framework.eventbot.event.impl.mail.MailReceivedEvent) MailCommandEvent(won.bot.framework.eventbot.event.impl.mail.MailCommandEvent)

Aggregations

MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 MailCommandEvent (won.bot.framework.eventbot.event.impl.mail.MailCommandEvent)1 MailReceivedEvent (won.bot.framework.eventbot.event.impl.mail.MailReceivedEvent)1