Search in sources :

Example 1 with MailCommandEvent

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

the class MailCommandAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof MailCommandEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
        MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
        MimeMessage message = ((MailCommandEvent) event).getMessage();
        String referenceId = MailContentExtractor.getMailReference(message);
        WonURI wonUri = botContextWrapper.getWonURIForMailId(referenceId);
        // determine if the mail is referring to some other mail/need/connection or not
        if (wonUri != null) {
            processReferenceMailCommands(message, wonUri);
        } else {
            processNonReferenceMailCommand(message);
        }
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) MailBotContextWrapper(won.bot.framework.bot.context.MailBotContextWrapper) MimeMessage(javax.mail.internet.MimeMessage) MailCommandEvent(won.bot.framework.eventbot.event.impl.mail.MailCommandEvent)

Example 2 with MailCommandEvent

use of won.bot.framework.eventbot.event.impl.mail.MailCommandEvent 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

MimeMessage (javax.mail.internet.MimeMessage)2 MailCommandEvent (won.bot.framework.eventbot.event.impl.mail.MailCommandEvent)2 MessagingException (javax.mail.MessagingException)1 MailBotContextWrapper (won.bot.framework.bot.context.MailBotContextWrapper)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 MailReceivedEvent (won.bot.framework.eventbot.event.impl.mail.MailReceivedEvent)1