<commit_before>"""emails.py has the classes that contain the text of the emails we send out.
The main point of this module is to store the text in 1 place.
"""

import urllib
from datetime import datetime, timedelta

from django.conf import settings

from channelguide import util

class EmailMessage(object):
    def __init__(self, title, body):
        self.title = '[Miro Guide] ' + title
        self.body = self.merge_body(body)

    def merge_body(self, body):
        paragraps = body.split('\n\n')
        paragraps = [p.replace('\n', ' ') for p in paragraps]
        return '\n\n'.join(paragraps)

    def send_email(self, recipients, email_from=None, break_lines=True):
        util.send_mail(self.title, self.body, recipients, email_from,
                 break_lines)

class ForgotPasswordEmail(EmailMessage):
    def __init__(self, change_password_url, user):
        EmailMessage.__init__(self, "Forgot Password", """\
To set a new password for your Miro Guide account '%s' click here:

%s.""" % (user.username, change_password_url))

class ChannelOwnersEmail(EmailMessage):
    def __init__(self, owner, title, body):
        self.owner = owner
        EmailMessage.__init__(self, title, body + """\


**Why Did We Contact You?**
You received this message because you have a video feed in the Miro Guide:
(%s) We only send email when there are new features or important updates to
the Guide.

**Unsubscribe Info**
You can change your subscription settings in your user profile: (%s)
""" % (owner.channels[0].get_absolute_url(), owner.get_absolute_url()))

    def send_email(self, email_from):
        EmailMessage.send_email(self, self.owner.email, email_from)

class ChannelNoteEmail(EmailMessage):
    def __init__(self, note):
        EmailMessage.__init__(self, 
                'Note for %s' % note.channel.name, """\
A moderator of the Miro Guide added the following note to your channel:

%s

%s

You may review and respond to the note here: %s""" % \
            (note.title, note.body, note.channel.get_absolute_url()))

class ApprovalEmail(EmailMessage):
    def __init__(self, channel, owner):
        self.channel = channel
        EmailMessage.__init__(self, '%s was approved!' % channel.name, """\
%s,

Your video feed was approved as a channel in the Miro Guide!

You can view your channel here: %s.

If you'd like more viewers to experience your show in Miro, add a 1-click
subscribe button to your web site or myspace page. Then it becomes so easy for
people to get *every* episode of your show: http://subscribe.getmiro.com/

Thanks for adding your show to the Miro Guide.""" % \
        (owner, channel.get_absolute_url()))

    def send_email(self, email_from=None):
        EmailMessage.send_email(self, self.channel.owner.email, email_from)

class RejectionEmail(EmailMessage):
    def __init__(self, channel, header_text, body):
        EmailMessage.__init__(self, '%s was not approved' % channel.name,
                '%s\n\n%s\n' % (self.make_header(header_text), body))

    def make_header(self, text):
        text = ' %s ' % text
        left = '-' * ((50 - len(text)) / 2)
        right = '-' * ((51 - len(text)) / 2)
        return left + text + right

class BrokenChannelEmail(RejectionEmail): 
    def __init__(self, channel):
        feedvalidator_link = 'http://feedvalidator.org/check.cgi?url='
        feedvalidator_link += urllib.quote_plus(channel.url)
        RejectionEmail.__init__(self, channel, 'BROKEN', """\
Your feed doesn't seem to work in Miro. Check it out in feedvalidator.org
(%s). If you're having problems finding the problem, please search the
Miro forums (%s) and post a question if you don't find an answer.

Once you have your feed working in Miro, please post a message for us on
the channel page (%s).""" % (feedvalidator_link, settings.FORUMS_URL,
    channel.get_absolute_url()))

class CopyrightViolationEmail(RejectionEmail):
    def __init__(self, channel):
        RejectionEmail.__init__(self, channel, 'COPYRIGHT ISSUES', """\
It appears that your feed might have copyrighted material in it. Due to
the nature of US copyright laws, we cannot feature it in the Miro Guide.

If we are incorrect in supposing that the material was not cleared for
copyright, please contact us at <EMAIL>""")

class ExplicitContentEmail(RejectionEmail):
    def __init__(self, channel):
        RejectionEmail.__init__(self, channel, 'EXPLICIT CONTENT', """\<commit_msg>update text for emails<commit_after>"""emails.py has the classes that contain the text of the emails we send out.
The main point of this module is to store the text in 1 place.
"""

import urllib
from datetime import datetime, timedelta

from django.conf import settings

from channelguide import util

class EmailMessage(object):
    def __init__(self, title, body):
        self.title = '[Miro Guide] ' + title
        self.body = self.merge_body(body)

    def merge_body(self, body):
        paragraps = body.split('\n\n')
        paragraps = [p.replace('\n', ' ') for p in paragraps]
        return '\n\n'.join(paragraps)

    def send_email(self, recipients, email_from=None, break_lines=True):
        util.send_mail(self.title, self.body, recipients, email_from,
                 break_lines)

class ForgotPasswordEmail(EmailMessage):
    def __init__(self, change_password_url, user):
        EmailMessage.__init__(self, "Forgot Password", """\
To set a new password for your Miro Guide account '%s' click here:

%s.""" % (user.username, change_password_url))

class ChannelOwnersEmail(EmailMessage):
    def __init__(self, owner, title, body):
        self.owner = owner
        EmailMessage.__init__(self, title, body + """\


**Why Did We Contact You?**
You received this message because you have a video feed in the Miro Guide:
(%s) We only send email when there are new features or important updates to
the Guide.

**Unsubscribe Info**
You can change your subscription settings in your user profile: (%s)
""" % (owner.channels[0].get_absolute_url(), owner.get_absolute_url()))

    def send_email(self, email_from):
        EmailMessage.send_email(self, self.owner.email, email_from)

class ChannelNoteEmail(EmailMessage):
    def __init__(self, note):
        EmailMessage.__init__(self, 
                'Note for %s' % note.channel.name, """\
A moderator of the Miro Guide added the following note to your channel:

%s

%s

You may review and respond to the note here: %s""" % \
            (note.title, note.body, note.channel.get_absolute_url()))

class ApprovalEmail(EmailMessage):
    def __init__(self, channel, owner):
        self.channel = channel
        EmailMessage.__init__(self, '%s was approved!' % channel.name, """\
%s,

Your video feed was approved as a channel in the Miro Guide!

You can view your channel here: %s.

If you'd like more viewers to experience your show in Miro, add a 1-click
subscribe button to your web site or myspace page. Then it becomes so easy for
people to get *every* episode of your show: http://subscribe.getmiro.com/

Thanks for adding your show to the Miro Guide.""" % \
        (owner, channel.get_absolute_url()))

    def send_email(self, email_from=None):
        EmailMessage.send_email(self, self.channel.owner.email, email_from)

class RejectionEmail(EmailMessage):
    def __init__(self, channel, header_text, body):
        EmailMessage.__init__(self, '%s was not approved' % channel.name,
                '%s\n\n%s\n' % (self.make_header(header_text), body))

    def make_header(self, text):
        text = ' %s ' % text
        left = '-' * ((50 - len(text)) / 2)
        right = '-' * ((51 - len(text)) / 2)
        return left + text + right

class BrokenChannelEmail(RejectionEmail):
    def __init__(self, channel):
        feedvalidator_link = 'http://feedvalidator.org/check.cgi?url='
        feedvalidator_link += urllib.quote_plus(channel.url)
        RejectionEmail.__init__(self, channel, 'BROKEN', """\
Your feed doesn't seem to work in Miro. You should add your channel into
Miro for yourself to test whether it works or not.  This can easily be done by:
       1. copy your feed
       2. go to the Channels menu, and selecting "Add Channel."

You can also try and see what's wrong by testing it in feedvalidator.org (%s).
If you're having problems finding the problem, please search the Miro forums
(%s) and post a question if you don't find an answer.

Also keep in mind that Miro does not support Shockwave (.swf) files; it does
support Flash video (.flv) files.

Once you have your feed working in Miro, please post a message for us on
the channel page (%s).""" % (feedvalidator_link, settings.FORUMS_URL,
    channel.get_absolute_url()))

class CopyrightViolationEmail(RejectionEmail):
    def __init__(self, channel):
        RejectionEmail.__init__(self, channel, 'COPYRIGHT ISSUES', """\
It appears that your feed might have copyrighted material in it. Due to
the nature of US copyright laws, we cannot feature it in the Miro Guide.

If we are incorrect in supposing that the material was not cleared for
copyright, please contact us at <EMAIL>""")

class ExplicitContentEmail(RejectionEmail):
    def __init__(self, channel):
        RejectionEmail.__init__(self, channel, 'EXPLICIT CONTENT', """\
{'fraction_non_alphanumeric': 0.10478977026441266, 'fraction_numerical': 0.002167316861725184, 'mean_word_length': 3.5869781312127236, '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': '4920064', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2666, 'n_words': 1000}