<commit_before>package won.bot.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import won.bot.framework.bot.base.EventBot;
import won.bot.framework.eventbot.EventListenerContext;
import won.bot.framework.eventbot.action.impl.mail.receive.*;
import won.bot.framework.eventbot.action.impl.mail.send.*;
import won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionUriAction;
import won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionUriAction;
import won.bot.framework.eventbot.action.impl.wonmessage.SendMessageOnConnectionAction;
import won.bot.framework.eventbot.bus.EventBus;
import won.bot.framework.eventbot.event.impl.command.SendTextMessageOnConnectionEvent;
import won.bot.framework.eventbot.event.impl.mail.*;
import won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent;
import won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent;
import won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent;
import won.bot.framework.eventbot.listener.impl.ActionOnEventListener;

import javax.mail.internet.MimeMessage;

/**
 * This Bot checks the E-Mails from a given set of configured E-Mail Adresses and creates Needs that represent these E-Mails
 * In Future Implementations it will support the bidirectional communication between the node content and the email sender?!
 * Created by fsuda on 27.09.2016.
 */
public class Mail2WonBot extends EventBot{
    @Autowired
    private MessageChannel receiveEmailChannel;

    @Autowired
    private MessageChannel sendEmailChannel;

    @Autowired
    MailContentExtractor mailContentExtractor;

    @Autowired
    WonMimeMessageGenerator mailGenerator;

    private EventBus bus;

    @Override
    protected void initializeEventListeners() {
        EventListenerContext ctx = getEventListenerContext();
        mailGenerator.setEventListenerContext(ctx);

        bus = getEventBus();

        //Mail initiated events
        bus.subscribe(MailReceivedEvent.class,
        new ActionOnEventListener(
                ctx,
                "MailReceived",
                new MailParserAction(ctx, mailContentExtractor)
        ));

        bus.subscribe(CreateNeedFromMailEvent.class,
        new ActionOnEventListener(
                ctx,
                "CreateNeedFromMailEvent",
                new CreateNeedFromMailAction(ctx, mailContentExtractor)

        ));

        bus.subscribe(WelcomeMailEvent.class, new ActionOnEventListener(
          ctx,
          "WelcomeMailAction",
          new WelcomeMailAction(mailGenerator, sendEmailChannel)

        ));

        bus.subscribe(MailCommandEvent.class,
        new ActionOnEventListener(
                ctx,
                "MailCommandEvent",
                new MailCommandAction(ctx, mailContentExtractor)
        ));

        bus.subscribe(SendTextMessageOnConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "SendTextMessage",
                new SendMessageOnConnectionAction(ctx)
        ));

        bus.subscribe(CloseConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "CloseCommandEvent",
                new CloseConnectionUriAction(ctx)
        ));

        bus.subscribe(OpenConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "OpenCommandEvent",<commit_msg>added need close event/action subscription for mailbot<commit_after>package won.bot.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import won.bot.framework.bot.base.EventBot;
import won.bot.framework.eventbot.EventListenerContext;
import won.bot.framework.eventbot.action.impl.mail.receive.*;
import won.bot.framework.eventbot.action.impl.mail.send.*;
import won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateNeedAction;
import won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionUriAction;
import won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionUriAction;
import won.bot.framework.eventbot.action.impl.wonmessage.SendMessageOnConnectionAction;
import won.bot.framework.eventbot.bus.EventBus;
import won.bot.framework.eventbot.event.impl.command.SendTextMessageOnConnectionEvent;
import won.bot.framework.eventbot.event.impl.mail.*;
import won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent;
import won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent;
import won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent;
import won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent;
import won.bot.framework.eventbot.listener.impl.ActionOnEventListener;

import javax.mail.internet.MimeMessage;

/**
 * This Bot checks the E-Mails from a given set of configured E-Mail Adresses and creates Needs that represent these E-Mails
 * In Future Implementations it will support the bidirectional communication between the node content and the email sender?!
 * Created by fsuda on 27.09.2016.
 */
public class Mail2WonBot extends EventBot{
    @Autowired
    private MessageChannel receiveEmailChannel;

    @Autowired
    private MessageChannel sendEmailChannel;

    @Autowired
    MailContentExtractor mailContentExtractor;

    @Autowired
    WonMimeMessageGenerator mailGenerator;

    private EventBus bus;

    @Override
    protected void initializeEventListeners() {
        EventListenerContext ctx = getEventListenerContext();
        mailGenerator.setEventListenerContext(ctx);

        bus = getEventBus();

        //Mail initiated events
        bus.subscribe(MailReceivedEvent.class,
        new ActionOnEventListener(
                ctx,
                "MailReceived",
                new MailParserAction(ctx, mailContentExtractor)
        ));

        bus.subscribe(CreateNeedFromMailEvent.class,
        new ActionOnEventListener(
                ctx,
                "CreateNeedFromMailEvent",
                new CreateNeedFromMailAction(ctx, mailContentExtractor)

        ));

        bus.subscribe(WelcomeMailEvent.class, new ActionOnEventListener(
          ctx,
          "WelcomeMailAction",
          new WelcomeMailAction(mailGenerator, sendEmailChannel)

        ));

        bus.subscribe(MailCommandEvent.class,
        new ActionOnEventListener(
                ctx,
                "MailCommandEvent",
                new MailCommandAction(ctx, mailContentExtractor)
        ));

        bus.subscribe(SendTextMessageOnConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "SendTextMessage",
                new SendMessageOnConnectionAction(ctx)
        ));

        bus.subscribe(CloseConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "CloseCommandEvent",
                new CloseConnectionUriAction(ctx)
        ));

        bus.subscribe(NeedDeactivatedEvent.class,
        new ActionOnEventListener(
                ctx,
                "DeactivateNeedEvent",
                new DeactivateNeedAction(ctx)
        ));

        bus.subscribe(OpenConnectionEvent.class,
        new ActionOnEventListener(
                ctx,
                "OpenCommandEvent",
{'fraction_non_alphanumeric': 0.07781411828836195, 'fraction_numerical': 0.0024529844644317253, 'mean_word_length': 3.016967706622879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4229221', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1818, 'n_words': 344}