<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of VilfredoReloadedCore.
#
# Copyright © 2009-2013 <NAME> / <NAME>.
#
# VilfredoReloadedCore is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation version 3 of the License.
#
# VilfredoReloadedCore is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with VilfredoReloadedCore.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################


'''
Emails
'''

from flask_mail import Message

from . import app, mail

from decorators import async


@async
def send_async_email(msg):
    with app.app_context():
        mail.send(msg)


def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    send_async_email(msg)


def email_question_email_invite(sender, receiver_email, question):
    # print "Sending email:", sender.username, question.title
    send_email("Vilfredo - Invitation to participate",
               '<EMAIL>',
               [receiver_email],
               "User %s invites you to participate in question %s"
               % (sender.username, question.title),
               "User %s invites you to participate in question %s"
               % (sender.username, question.title))

def email_question_invite(sender, receiver, question):
    # print "Sending email:", sender.username, question.title
    send_email("Vilfredo - Invitation to participate",
               '<EMAIL>',
               [receiver.email],
               "User %s invites you to participate in question %s"
               % (sender.username, question.title),
               "User %s invites you to participate in question %s"<commit_msg>Fix email. Old way gave permission errors on Dreamhost.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of VilfredoReloadedCore.
#
# Copyright © 2009-2013 <NAME> / <NAME>.
#
# VilfredoReloadedCore is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation version 3 of the License.
#
# VilfredoReloadedCore is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with VilfredoReloadedCore.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################


'''
Emails
'''

from . import app
from email.mime.text import MIMEText
from subprocess import Popen, PIPE

def send_email(subject, sender_email, recipient_email, text_body):
    msg = MIMEText(text_body)
    msg["From"] = sender_email
    msg["To"] = recipient_email
    msg["Subject"] = subject
    p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
    p.communicate(msg.as_string())

def email_question_email_invite(sender, recipient_email, question):
    # print "Sending email:", sender.username, question.title
    send_email("Vilfredo - Invitation to participate",
               '<EMAIL>',
               recipient_email,
               "User %s invites you to participate in question %s"
               % (sender.username, question.title))

def email_question_invite(sender, recipient, question):
    # print "Sending email:", sender.username, question.title
    send_email("Vilfredo - Invitation to participate",
               '<EMAIL>',
               recipient,
               "User %s invites you to participate in question %s"
{'fraction_non_alphanumeric': 0.12847138372373823, 'fraction_numerical': 0.004829751267809708, 'mean_word_length': 3.4204909284951976, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '99083', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1120, 'n_words': 406}