# Path: jarr/lib/utils.py
# def rfc_1123_utc(time_obj=None, delta=None):
#     """Return time obj or now formated in the RFC1123 style (with delta)."""
#     if time_obj is None:
#         time_obj = utc_now()
#     if delta is not None:
#         time_obj += delta
#     return time_obj.strftime(RFC_1123_FORMAT)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)


import logging
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from jarr.lib.utils import rfc_1123_utc
from jarr.bootstrap import conf
#! /usr/bin/env python


logger = logging.getLogger(__name__)


def send(to="", bcc="", subject="", plaintext=""):
    """Send an email."""
    # Create message container - the correct MIME type is multipart/alternative
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = conf.NOTIFICATION_EMAIL
    msg['Date'] = rfc_1123_utc()
    msg['To'] = to
    msg.attach(MIMEText(plaintext, 'plain', 'utf-8'))

    with smtplib.SMTP(host=conf.notification.host,
                      port=conf.notification.port) as smtp:
        smtp.ehlo()
        if conf.notification.starttls:
            smtp.starttls()
        smtp.ehlo()

# Path: jarr/lib/utils.py
# def rfc_1123_utc(time_obj=None, delta=None):
#     """Return time obj or now formated in the RFC1123 style (with delta)."""
#     if time_obj is None:
#         time_obj = utc_now()
#     if delta is not None:
#         time_obj += delta
#     return time_obj.strftime(RFC_1123_FORMAT)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)


# Path: jarr/lib/emails.py
import logging
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from jarr.lib.utils import rfc_1123_utc
from jarr.bootstrap import conf

#! /usr/bin/env python


logger = logging.getLogger(__name__)


def send(to="", bcc="", subject="", plaintext=""):
    """Send an email."""
    # Create message container - the correct MIME type is multipart/alternative
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = conf.NOTIFICATION_EMAIL
    msg['Date'] = rfc_1123_utc()
    msg['To'] = to
    msg.attach(MIMEText(plaintext, 'plain', 'utf-8'))

    with smtplib.SMTP(host=conf.notification.host,
                      port=conf.notification.port) as smtp:
        smtp.ehlo()
        if conf.notification.starttls:
            smtp.starttls()
        smtp.ehlo()

        smtp.login(conf.notification.login, conf.notification.password)