<commit_before>#Author: <NAME>waythree Solutions Inc.
#Created on Jan 28 2014

import logging

import datetime
import copy

import ckan as ckan

from ckan.controllers.package import PackageController
from ckan.common import  _, request, c, response, g
import ckan.lib.base as base
import ckan.model as model
import ckan.logic as logic
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.lib.dictization.model_save as model_save
from ckan.controllers.home import CACHE_PARAMETERS
from ckan.logic import get_action, NotFound
import ckan.plugins.toolkit as toolkit
import ckan.lib.helpers as h
from urllib import urlencode
from paste.deploy.converters import asbool
from email.mime.text import MIMEText
from email.header import Header
from email import Utils
from urlparse import urljoin
from time import time

from wsgiref.handlers import format_date_time
from ckanext.edc_schema.util.util import get_user_list

import ckan.lib.render as lib_render

import smtplib
import logging
import uuid
import paste.deploy.converters


import pprint
from pylons import config

#from ckanext.edc_schema.util.util import edc_state_activity_create

log = logging.getLogger(__name__)

ValidationError = logic.ValidationError

render = base.render
abort = base.abort
redirect = base.redirect

check_access = logic.check_access
NotAuthorized = logic.NotAuthorized
clean_dict = logic.clean_dict
tuplize_dict = logic.tuplize_dict
parse_params = logic.parse_params
EDC_DATASET_TYPE_VOCAB = u'dataset_type_vocab'

TemplateNotFound = lib_render.TemplateNotFound


def from_utc(utcTime,fmt="%Y-%m-%dT%H:%M:%S.%f"):
    """
    Convert UTC time string to time.struct_time
    """
    # change datetime.datetime to time, return time.struct_time type
    return datetime.datetime.strptime(utcTime, fmt)

def add_msg_niceties(recipient_name, body, sender_name, sender_url):
    return _(u"Dear %s,<br><br>") % recipient_name \
           + u"\r\n\r\n%s\r\n\r\n" % body \
           + u"<br><br>--<br>\r\n%s (%s)" % (sender_name, sender_url)

def send_email(user_display_name, user_email, email_dict):
    subject = email_dict['subject']
    body = email_dict['body']
    recipient_name = user_display_name
    recipient_email = user_email
    sender_name = g.site_title
    sender_url = g.site_url

    mail_from = config.get('smtp.mail_from')
    body = add_msg_niceties(recipient_name, body, sender_name, sender_url)
    msg = MIMEText(body.encode('utf-8'), 'html', 'utf-8')
    subject = Header(subject.encode('utf-8'), 'utf-8')
    msg['Subject'] = subject
    msg['From'] = _("%s <%s>") % (sender_name, mail_from)
    recipient = u"%s <%s>" % (recipient_name, recipient_email)
    msg['To'] = Header(recipient, 'utf-8')
    msg['Date'] = Utils.formatdate(time())
    #msg['X-Mailer'] = "CKAN %s" % ckan.__version__

    # Send the email using Python's smtplib.
    smtp_connection = smtplib.SMTP()
    if 'smtp.test_server' in config:<commit_msg>Testing email notifications<commit_after>#Author: <NAME> Highwaythree Solutions Inc.
#Created on Jan 28 2014

import logging

import datetime
import copy

import ckan as ckan

from ckan.controllers.package import PackageController
from ckan.common import  _, request, c, response, g
import ckan.lib.base as base
import ckan.model as model
import ckan.logic as logic
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.lib.dictization.model_save as model_save
from ckan.controllers.home import CACHE_PARAMETERS
from ckan.logic import get_action, NotFound
import ckan.plugins.toolkit as toolkit
import ckan.lib.helpers as h
from urllib import urlencode
from paste.deploy.converters import asbool
from email.mime.text import MIMEText
from email.header import Header
from email import Utils
from urlparse import urljoin
from time import time

from wsgiref.handlers import format_date_time
from ckanext.edc_schema.util.util import get_user_list

import ckan.lib.render as lib_render

import smtplib
import logging
import uuid
import paste.deploy.converters


import pprint
from pylons import config

#from ckanext.edc_schema.util.util import edc_state_activity_create

log = logging.getLogger(__name__)

ValidationError = logic.ValidationError

render = base.render
abort = base.abort
redirect = base.redirect

check_access = logic.check_access
NotAuthorized = logic.NotAuthorized
clean_dict = logic.clean_dict
tuplize_dict = logic.tuplize_dict
parse_params = logic.parse_params
EDC_DATASET_TYPE_VOCAB = u'dataset_type_vocab'

TemplateNotFound = lib_render.TemplateNotFound


def from_utc(utcTime,fmt="%Y-%m-%dT%H:%M:%S.%f"):
    """
    Convert UTC time string to time.struct_time
    """
    # change datetime.datetime to time, return time.struct_time type
    return datetime.datetime.strptime(utcTime, fmt)

def add_msg_niceties(recipient_name, body, sender_name, sender_url):
    return _(u"Dear %s,<br><br>") % recipient_name \
           + u"\r\n\r\n%s\r\n\r\n" % body \
           + u"<br><br>--<br>\r\n%s (<a href=\"%s\">%s</a>)" % (sender_name, sender_url, sender_url)

def send_email(user_display_name, user_email, email_dict):
    subject = email_dict['subject']
    body = email_dict['body']
    recipient_name = user_display_name
    recipient_email = user_email
    sender_name = g.site_title
    sender_url = g.site_url

    mail_from = config.get('smtp.mail_from')
    body = add_msg_niceties(recipient_name, body, sender_name, sender_url)
    msg = MIMEText(body.encode('utf-8'), 'html', 'utf-8')
    subject = Header(subject.encode('utf-8'), 'utf-8')
    msg['Subject'] = subject
    msg['From'] = _("%s <%s>") % (sender_name, mail_from)
    recipient = u"%s <%s>" % (recipient_name, recipient_email)
    msg['To'] = Header(recipient, 'utf-8')
    msg['Date'] = Utils.formatdate(time())
    #msg['X-Mailer'] = "CKAN %s" % ckan.__version__

    # Send the email using Python's smtplib.
    smtp_connection = smtplib.SMTP()
    if 'smtp.test_server' in config:
{'fraction_non_alphanumeric': 0.10533423362592843, 'fraction_numerical': 0.003713706954760297, 'mean_word_length': 4.659025787965616, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4042203', 'n_tokens_mistral': 2033, 'n_tokens_neox': 2019, 'n_words': 494}