<commit_before>from django.conf.urls import url
from django.http import HttpResponse, Http404
from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied
from mod import PatchewModule
import smtplib
import email
import uuid
import traceback
from string import Template
from api.models import Message
from event import register_handler

_default_config = """
[smtp]
server = smtp.example.com
ssl = True
port = 465
username = youruser
password = <PASSWORD>
from = <EMAIL>

[mail a]
enabled = false
event = TestingReport
passed = false
project = QEMU
to = <EMAIL>
template = template_a

"""
class EmailModule(PatchewModule):
    name = "email" # The notify method name
    default_config = _default_config

    def __init__(self):
        register_handler("TestingReport", self.on_testing_report)

    def _get_smtp(self):
        server = self.get_config("smtp", "server")
        port = self.get_config("smtp", "port")
        username = self.get_config("smtp", "username")
        password = self.get_config("smtp", "password")
        ssl = self.get_config("smtp", "ssl", "getboolean")
        if ssl:
            smtp = smtplib.SMTP_SSL(server, port)
        else:
            smtp = smtplib.SMTP(server, port)
        smtp.login(username, password)<commit_msg>email: Update documentation<commit_after>from django.conf.urls import url
from django.http import HttpResponse, Http404
from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied
from mod import PatchewModule
import smtplib
import email
import uuid
import traceback
from string import Template
from api.models import Message
from event import register_handler

_default_config = """
[smtp]
server = smtp.example.com
ssl = True
port = 465
username = youruser
password = <PASSWORD>
from = <EMAIL>

[mail a]
enabled = false
event = TestingReport
passed = false
project = QEMU
to = <EMAIL>
template = template_a

"""
class EmailModule(PatchewModule):
    """

Documentation
-------------

This module is configured in "INI" style.

It has a global `[smtp]` section and one or more `[mail XXX]` sections. The
`[smtp]` section stores the usual SMTP information for sending emails:

    [smtp]
    server = smtp.example.com
    ssl = True
    port = 465
    username = youruser
    password = <PASSWORD>
    from = <EMAIL>

Each `[mail XXX]` section stores a scenario for the system to send out email:

    [mail a]
    enabled = false
    event = TestingReport
    template = template_a
    to = <EMAIL>
    passed = false
    project = QEMU

The meaning of each option is:

  * **enabled**: Whether the email should be sent.

  * **event**: The event type of the scenario.

  * **to**: The address to which the email should be sent.

  * **template**: The email message text template.

  * Other fields are supported depending on the type of event.

"""
    name = "email" # The notify method name
    default_config = _default_config

    def __init__(self):
        register_handler("TestingReport", self.on_testing_report)

    def _get_smtp(self):
        server = self.get_config("smtp", "server")
        port = self.get_config("smtp", "port")
        username = self.get_config("smtp", "username")
        password = self.get_config("smtp", "password")
        ssl = self.get_config("smtp", "ssl", "getboolean")
        if ssl:
            smtp = smtplib.SMTP_SSL(server, port)
        else:
            smtp = smtplib.SMTP(server, port)
        smtp.login(username, password)
{'fraction_non_alphanumeric': 0.09982935153583618, 'fraction_numerical': 0.004266211604095563, 'mean_word_length': 3.446270543615676, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '1944667', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1051, 'n_words': 344}