<commit_before># -*- coding: utf-8 -*-
"""
   send_ses_email.py
   =================

   Send email messages using the AWS SES. Credentials are loaded from a
   configuration file.

   (c) 2014, <NAME> Available under the MIT License - see LICENSE
   for details.
"""
import argparse
import ConfigParser
from email.mime.text import MIMEText
import smtplib
import sys
import time

# XXX do need to allow outbound traffic to use this?

# need to have retry logic in sending to amazon


def get_server_reference(
        username, smtp_password, aws_smtp_endpoint, aws_smtp_port):
    """
       Returns smtplib.smtp reference using the specified parameters.
       Call sendmail on the returned reference to send emails.

       See the example configuration file for explanations on where to
       find these parameters.
    """
    smtp_con = smtplib.SMTP(
        host=aws_smtp_endpoint, port=aws_smtp_port, timeout=10)
    smtp_con.starttls()
    smtp_con.ehlo()
    smtp_con.login(username, smtp_password)
    # Will need to re-obtain this reference occasionally as server
    # connections aren't maintained long-term
    return smtp_con


def get_smtp_parameters(config_file_sequence):
    """
       Read the configuration files in config_file_sequence
       and return a dictionary of the parameter specified
       in their 'default' section.
    """
    config_parser = ConfigParser.SafeConfigParser()
    config_parser.read(config_file_sequence)
    return {i[0].lower(): i[1] for i in config_parser.items('default')}


def main():
    """
       Parse command-line arguments.
    """
    parser = argparse.ArgumentParser(
        description="Simple email tool backed by the Amazon SES SMTP interface")
    parser.add_argument('-s', '--subject', help="Subject of email")
    parser.add_argument('-f', '--from_email', help="Email sender")
    parser.add_argument(
        '--config_file', default='smtp_credentials.cfg',
        help="CFG file of SMTP user credentials. Must define variables"
             "USERNAME, SMTP_PASSWORD, AWS_SMTP_ENDPOINT, and AWS_SMTP_PORT"
             "in a 'default' section.")
    parser.add_argument('to_email', help="Email recipient")
    parser.add_argument(
        'message', nargs='?', type=argparse.FileType('r'), default=sys.stdin,
        help="File containing email text. By default, reads text from stdin")

    args = parser.parse_args()
    configuration_params = get_smtp_parameters([args.config_file])

    message = MIMEText(args.message.read())
    message['Subject'] = args.subject
    message['From'] = args.from_email
    message['To'] = args.to_email
    try:
        server = get_server_reference(*configuration_params)
        server.sendmail(args.from_email, args.to_email, message.as_string())
    except smtplib.SMTPException:
        server.quit()
        time.sleep(30)
        server = get_server_reference(*configuration_params)
        server.sendmail(args.from_email, args.to_email, message.as_string())
    finally:
        server.quit()<commit_msg>Fix incorrect named parameter passing<commit_after># -*- coding: utf-8 -*-
"""
   send_ses_email.py
   =================

   Send email messages using the AWS SES. Credentials are loaded from a
   configuration file.

   (c) 2014, <NAME> Available under the MIT License - see LICENSE
   for details.
"""
import argparse
import ConfigParser
from email.mime.text import MIMEText
import smtplib
import sys
import time


def get_server_reference(
        username, smtp_password, aws_smtp_endpoint, aws_smtp_port, **kwargs):
    """
       Returns smtplib.smtp reference using the specified parameters.
       Call sendmail on the returned reference to send emails.

       See the example configuration file for explanations on where to
       find these parameters.
    """
    smtp_con = smtplib.SMTP(
        host=aws_smtp_endpoint, port=aws_smtp_port, timeout=10)
    smtp_con.starttls()
    smtp_con.ehlo()
    smtp_con.login(username, smtp_password)
    # Will need to re-obtain this reference occasionally as server
    # connections aren't maintained long-term
    return smtp_con


def get_smtp_parameters(config_file_sequence):
    """
       Read the configuration files in config_file_sequence
       and return a dictionary of the parameter specified
       in their 'default' section.
    """
    config_parser = ConfigParser.SafeConfigParser()
    config_parser.read(config_file_sequence)
    return {i[0].lower(): i[1] for i in config_parser.items('default')}


def main():
    """
       Parse command-line arguments.
    """
    parser = argparse.ArgumentParser(
        description="Simple email tool backed by the Amazon SES SMTP interface")
    parser.add_argument('-s', '--subject', help="Subject of email")
    parser.add_argument('-f', '--from_email', help="Email sender")
    parser.add_argument(
        '--config_file', default='smtp_credentials.cfg',
        help="CFG file of SMTP user credentials. Must define variables"
             "USERNAME, SMTP_PASSWORD, AWS_SMTP_ENDPOINT, and AWS_SMTP_PORT"
             "in a 'default' section.")
    parser.add_argument('to_email', help="Email recipient")
    parser.add_argument(
        'message', nargs='?', type=argparse.FileType('r'), default=sys.stdin,
        help="File containing email text. By default, reads text from stdin")

    args = parser.parse_args()
    configuration_params = get_smtp_parameters([args.config_file])

    message = MIMEText(args.message.read())
    message['Subject'] = args.subject
    message['From'] = args.from_email
    message['To'] = args.to_email
    try:
        server = get_server_reference(**configuration_params)
        server.sendmail(args.from_email, args.to_email, message.as_string())
    except smtplib.SMTPException:
        server.quit()
        time.sleep(30)
        server = get_server_reference(**configuration_params)
        server.sendmail(args.from_email, args.to_email, message.as_string())
    finally:
        server.quit()
{'fraction_non_alphanumeric': 0.10389176549189912, 'fraction_numerical': 0.003674628361449808, 'mean_word_length': 3.399706098457017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4083430', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1719, 'n_words': 477}