<commit_before># -*- coding: utf-8 -*-

import logging
logger = logging.getLogger("membership.email_utils")

from django.conf import settings

from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core import mail
from django.core.mail import EmailMessage
from django.template.loader import render_to_string


def format_email(name, email):
    clean_name = name.replace('"', '')  # Strip double quotes
    return u'"{name}" <{email}>'.format(name=clean_name, email=email)


# Address helper
def unix_email(membership):
    if settings.UNIX_EMAIL_DOMAIN:
        from services.models import valid_aliases, Alias
        try:
            alias = valid_aliases(membership).filter(account=True).latest('created')
            email = u"{user}@{domain}".format(user=alias, domain=settings.UNIX_EMAIL_DOMAIN)
            format_email(name=membership.name(), email=email)
        except Alias.DoesNotExist:
            pass
    return None


# Signal handlers
def bill_sender(sender, instance=None, **kwargs):
    membership = instance.billingcycle.membership
    to = [membership.billing_email()]
    if instance.is_reminder():
        if membership.billing_contact:
            to.append(membership.email_to())
        local_email = unix_email(membership)
        if local_email:
            to.append(local_email)

    if settings.BILL_ATTACH_PDF:
        pdf = instance.generate_pdf()
        if instance.is_reminder():
            attachments = [("Kapsi_muistutuslasku_%s.pdf" % instance.billingcycle.reference_number, pdf, "application/pdf")]
        else:
            attachments = [("kapsi_jasenlasku_%s.pdf" % instance.billingcycle.reference_number, pdf, "application/pdf")]
    else:
        attachments = []

    if settings.BILLING_CC_EMAIL != None:
        email = EmailMessage(instance.bill_subject(),
                             instance.render_as_text(),
                             settings.BILLING_FROM_EMAIL,
                             to,<commit_msg>fixed cc to unix email address<commit_after># -*- coding: utf-8 -*-

import logging
logger = logging.getLogger("membership.email_utils")

from django.conf import settings

from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core import mail
from django.core.mail import EmailMessage
from django.template.loader import render_to_string


def format_email(name, email):
    clean_name = name.replace('"', '')  # Strip double quotes
    return u'"{name}" <{email}>'.format(name=clean_name, email=email)


# Address helper
def unix_email(membership):
    if settings.UNIX_EMAIL_DOMAIN:
        from services.models import valid_aliases, Alias
        try:
            alias = valid_aliases(membership).filter(account=True).latest('created')
            email = u"{user}@{domain}".format(user=alias, domain=settings.UNIX_EMAIL_DOMAIN)
            return format_email(name=membership.name(), email=email)
        except Alias.DoesNotExist:
            pass
    return None


# Signal handlers
def bill_sender(sender, instance=None, **kwargs):
    membership = instance.billingcycle.membership
    to = [membership.billing_email()]
    if instance.is_reminder():
        if membership.billing_contact:
            to.append(membership.email_to())
        local_email = unix_email(membership)
        if local_email:
            to.append(local_email)

    if settings.BILL_ATTACH_PDF:
        pdf = instance.generate_pdf()
        if instance.is_reminder():
            attachments = [("Kapsi_muistutuslasku_%s.pdf" % instance.billingcycle.reference_number, pdf, "application/pdf")]
        else:
            attachments = [("kapsi_jasenlasku_%s.pdf" % instance.billingcycle.reference_number, pdf, "application/pdf")]
    else:
        attachments = []

    if settings.BILLING_CC_EMAIL != None:
        email = EmailMessage(instance.bill_subject(),
                             instance.render_as_text(),
                             settings.BILLING_FROM_EMAIL,
                             to,
{'fraction_non_alphanumeric': 0.10266535044422508, 'fraction_numerical': 0.0004935834155972359, 'mean_word_length': 2.9541463414634146, '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': '4791245', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1183, 'n_words': 235}