<commit_before>package uk.ac.ox.zoo.seeg.abraid.mp.common.service.core;

import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.log4j.Logger;
import uk.ac.ox.zoo.seeg.abraid.mp.common.config.SmtpConfiguration;
import uk.ac.ox.zoo.seeg.abraid.mp.common.util.EmailFactory;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * A service for sending emails.
 * Copyright (c) 2014 University of Oxford
 */
public class EmailServiceImpl implements EmailService {

    private static final Logger LOGGER = Logger.getLogger(EmailServiceImpl.class);
    private static final String LOG_EMAIL_SENT =
            "Email sent to '%s' with subject '%s'";
    private static final String LOG_FAILED_SEND_EMAIL =
            "Failed to send email (%s - %s)";
    private static final String LOG_FAILED_LOAD_TEMPLATE =
            "Failed to send email (%s - %s) due to failure to load template";
    private static final String LOG_FAILED_APPLY_TEMPLATE =
            "Failed to send email (%s - %s) due to failure to load template";

    private final ExecutorService pool = Executors.newFixedThreadPool(3);

    private final EmailFactory emailFactory;
    private final String fromAddress;
    private final SmtpConfiguration smtpConfig;
    private final Configuration freemarkerConfig;

    public EmailServiceImpl(EmailFactory emailFactory, String fromAddress, SmtpConfiguration smtpConfig,
                            File[] emailTemplateLookupPaths)
            throws IOException {
        this.emailFactory = emailFactory;
        this.fromAddress = fromAddress;
        this.smtpConfig = smtpConfig;
        this.freemarkerConfig = setupFreemarkerConfig(emailTemplateLookupPaths);
    }

    private static void setupSMTP(Email email, SmtpConfiguration smtpConfig) throws EmailException {
        email.setHostName(smtpConfig.getAddress());
        email.setSmtpPort(smtpConfig.getPort());<commit_msg>Correct log message<commit_after>package uk.ac.ox.zoo.seeg.abraid.mp.common.service.core;

import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.log4j.Logger;
import uk.ac.ox.zoo.seeg.abraid.mp.common.config.SmtpConfiguration;
import uk.ac.ox.zoo.seeg.abraid.mp.common.util.EmailFactory;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * A service for sending emails.
 * Copyright (c) 2014 University of Oxford
 */
public class EmailServiceImpl implements EmailService {

    private static final Logger LOGGER = Logger.getLogger(EmailServiceImpl.class);
    private static final String LOG_EMAIL_SENT =
            "Email sent to '%s' with subject '%s'";
    private static final String LOG_FAILED_SEND_EMAIL =
            "Failed to send email (%s - %s)";
    private static final String LOG_FAILED_LOAD_TEMPLATE =
            "Failed to send email (%s - %s) due to failure to load template";
    private static final String LOG_FAILED_APPLY_TEMPLATE =
            "Failed to send email (%s - %s) due to failure to apply template";

    private final ExecutorService pool = Executors.newFixedThreadPool(3);

    private final EmailFactory emailFactory;
    private final String fromAddress;
    private final SmtpConfiguration smtpConfig;
    private final Configuration freemarkerConfig;

    public EmailServiceImpl(EmailFactory emailFactory, String fromAddress, SmtpConfiguration smtpConfig,
                            File[] emailTemplateLookupPaths)
            throws IOException {
        this.emailFactory = emailFactory;
        this.fromAddress = fromAddress;
        this.smtpConfig = smtpConfig;
        this.freemarkerConfig = setupFreemarkerConfig(emailTemplateLookupPaths);
    }

    private static void setupSMTP(Email email, SmtpConfiguration smtpConfig) throws EmailException {
        email.setHostName(smtpConfig.getAddress());
        email.setSmtpPort(smtpConfig.getPort());
{'fraction_non_alphanumeric': 0.08224674022066199, 'fraction_numerical': 0.002407221664994985, 'mean_word_length': 4.113846153846154, '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': '4944196', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1372, 'n_words': 349}