<commit_before>#!/usr/bin/env python3

import smtplib
import ssl
from config import config
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import logging

logger = logging.getLogger(__name__)

class Mailer(object):
    """
    Maintains the connection to the mailserver and sends text to users.
    """

    def __init__(self):
        """
        Creates an SMTP client to send a mail. Is called only once
        when you actually want to send a mail. After you sent the
        mail, the SMTP client is shut down again.

        """
        # This generates the From address by stripping the part until the first
        # period from the mail server address and won't work always.
        self.fromaddr = config["mail"]["user"] + "@" + config["mail"]["mailserver"].partition(".")[2]

        # starts a client session with the SMTP server
        self.s = smtplib.SMTP(config["mail"]["mailserver"])
        try:
            context = ssl.create_default_context()
        except:
            logger.error('Creating SSL Context failed.', exc_info=True)
        self.s.starttls(context=context)
        self.s.login(config["mail"]["user"], config["mail"]["passphrase"])

    def send(self, text, recipient, subject, attachment=None):
        """
<commit_msg>getting logging stuff<commit_after>#!/usr/bin/env python3

import smtplib
import ssl
from config import config
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import logging

logger = logging.getLogger(__name__)

class Mailer(object):
    """
    Maintains the connection to the mailserver and sends text to users.
    """

    def __init__(self):
        """
        Creates an SMTP client to send a mail. Is called only once
        when you actually want to send a mail. After you sent the
        mail, the SMTP client is shut down again.

        """
        # This generates the From address by stripping the part until the first
        # period from the mail server address and won't work always.
        self.fromaddr = config["mail"]["user"] + "@" + config["mail"]["mailserver"].partition(".")[2]

        # starts a client session with the SMTP server
        self.s = smtplib.SMTP(config["mail"]["mailserver"])
        try:
            context = ssl.create_default_context()
            self.s.starttls(context=context)
        except:
            logger.error('StartTLS failed.', exc_info=True)
        self.s.login(config["mail"]["user"], config["mail"]["passphrase"])

    def send(self, text, recipient, subject, attachment=None):
        """

{'fraction_non_alphanumeric': 0.10475482912332838, 'fraction_numerical': 0.0014858841010401188, 'mean_word_length': 2.94289897510981, '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': '7074947', 'n_tokens_mistral': 734, 'n_tokens_neox': 741, 'n_words': 252}