Ejemplo n.º 1
0
    def test_sender_as_tuple(self):

        msg = Message(subject="testing",
                      sender=("tester", "*****@*****.**"),
                      body="test")

        msg_str = msg.dump()
        self.assertTrue("From: tester <*****@*****.**>" in str(msg_str))
Ejemplo n.º 2
0
    def test_recipients_properly_initialized(self):

        msg = Message(subject="subject")
        self.assertEqual(msg.recipients, [])

        msg2 = Message(subject="subject")
        msg2.add_recipient("*****@*****.**")
        self.assertEqual(len(msg2.recipients), 1)
Ejemplo n.º 3
0
    def test_sender_as_tuple(self):

        msg = Message(subject="testing",
                      sender=("tester", "*****@*****.**"),
                      body="test")

        msg_str = msg.dump()
        self.assertTrue("From: tester <*****@*****.**>" in str(msg_str))
Ejemplo n.º 4
0
    def test_recipients_properly_initialized(self):

        msg = Message(subject="subject")
        self.assertEqual(msg.recipients, [])

        msg2 = Message(subject="subject")
        msg2.add_recipient("*****@*****.**")
        self.assertEqual(len(msg2.recipients), 1)
Ejemplo n.º 5
0
    def test_cc(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      body="testing",
                      cc=["*****@*****.**"])

        msg_str = msg.dump()
        self.assertTrue("Cc: [email protected]" in str(msg_str))
Ejemplo n.º 6
0
def submit_note():
    msg = Message("New con-mon note from %s" % request.form['note_email'],
        sender = "*****@*****.**",
        reply_to = request.form['note_email'],
        recipients = ["*****@*****.**"])
    msg.body = "%s\n\nFrom: %s\n" % (request.form['note_body'], request.form['note_email'])
    mail.send(msg)
    flash('Your note was sent ok! Thanks!')
    return redirect(url_for('index'))
Ejemplo n.º 7
0
    def test_cc(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      body="testing",
                      cc=["*****@*****.**"])

        msg_str = msg.dump()
        self.assertTrue("Cc: [email protected]" in str(msg_str))
Ejemplo n.º 8
0
    def test_reply_to(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      sender="spammer <*****@*****.**>",
                      reply_to="somebody <*****@*****.**>",
                      body="testing")

        msg_str = msg.dump()
        self.assertTrue("Reply-To: somebody <*****@*****.**>" in str(msg_str))
Ejemplo n.º 9
0
    def test_reply_to(self):

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      sender="spammer <*****@*****.**>",
                      reply_to="somebody <*****@*****.**>",
                      body="testing")

        msg_str = msg.dump()
        self.assertTrue(
            "Reply-To: somebody <*****@*****.**>" in str(msg_str))
Ejemplo n.º 10
0
    def test_send_without_sender(self):

        del self.app.config['DEFAULT_MAIL_SENDER']

        msg = Message(subject="testing",
                      recipients=["*****@*****.**"],
                      body="testing")

        self.assertRaises(AssertionError, self.mail.send, msg)
Ejemplo n.º 11
0
    def send_email_message(self, recipient, subject, html_message,
                           text_message, sender_email, sender_name):
        """ Send email message via Flask-Sendmail.

        Args:
            recipient: Email address or tuple of (Name, Email-address).
            subject: Subject line.
            html_message: The message body in HTML.
            text_message: The message body in plain text.
        """

        if not current_app.testing:  # pragma: no cover

            # Prepare email message
            from flask_sendmail import Message
            message = Message(subject,
                              recipients=[recipient],
                              html=html_message,
                              body=text_message)

            # Send email message
            self.mail.send(message)
Ejemplo n.º 12
0
def send_mail(to, sender, cc=None, subject=None, message=None):
    #in order to get this to work, had to change the libraries as follows:
    #/home/admin/wagsv_python/venv/lib/python3.5/site-packages/flask_sendmail/connection.py[23]
    #   sm.stdin.write(str.encode(message.dump()))
    #/usr/lib/python3.5/email/mime/text.py[17]
    #   def __init__(self, _text, _subtype='plain', _charset='utf-8'):
    to = force_list(to)
    msg = Message(subject)
    msg.sender = sender
    msg.recipients = to
    msg.cc = force_list(cc)
    msg.body = '\n'.join(force_list(message))
    app = current_app._get_current_object()
    if config.get('send_mail'):
        #send_async_email(app, msg)
        mail.send(msg)
    else:
        out = [
            'Email:', 'from: ' + sender, 'to: ' + ', '.join(to),
            'subject: ' + subject, 'message:'
        ]
        print('\n'.join(out + force_list(message)))
Ejemplo n.º 13
0
    def test_add_recipient(self):

        msg = Message("testing")
        msg.add_recipient("*****@*****.**")

        self.assertEqual(msg.recipients, ["*****@*****.**"])
Ejemplo n.º 14
0
def submit_condate():
    if request.form['diebots_5000']:
        flash('Your submission is suspected as spam!')
        return redirect(url_for('index'))

    if request.form['convention'] == 'other':
        convention = Convention.query.filter(Convention.title == request.form['convention_title']).first()
        if not convention:
            convention = Convention(
                title=request.form['convention_title'],
                twitter=request.form['convention_twitter'],
                location=request.form['convention_location'],
                url=request.form['convention_url']
                )
            db.session.add(convention)
            db.session.commit()
        # any tags for convention?
        if request.form['convention_tags']:
            for tag in request.form.getlist('convention_tags'):
                tag = Tag.query.filter(Tag.id == tag).first()
                convention.tags.append(tag)
    else:
        convention = Convention.query.filter(Convention.id == request.form['convention']).first()

    end_date, registration_opens, registration_closes = [None, None, None]
    start_date = parser.parse(request.form['start_date'])
    if request.form['end_date']:
        end_date = parser.parse(request.form['end_date'])
    if request.form['registration_opens']:
        registration_opens = parser.parse(request.form['registration_opens'])
    if request.form['registration_closes']:
        registration_closes = parser.parse(request.form['registration_closes'])

    condate = Condate(
        convention_id=convention.id,
        title=convention.title + ' ' + request.form['start_date'][:4],
        start_date=start_date,
        end_date=end_date,
        registration_opens=registration_opens,
        registration_closes=registration_closes,
        notes=request.form['notes'],
        published=False
        )
    db.session.add(condate)
    db.session.commit()

    # email details
    submit_msg = "New Condate submission!\n\n"
    submit_msg = submit_msg + "Convention: %s\n" % convention.title
    submit_msg = submit_msg + "Start date: %s\n" % request.form['start_date']
    submit_msg = submit_msg + "End date: %s\n" % request.form['end_date']
    submit_msg = submit_msg + "Registration opens: %s\n" % request.form['registration_opens']
    submit_msg = submit_msg + "Registration closes: %s\n" % request.form['registration_closes']
    if request.form['notes']:
        submit_msg = submit_msg + "\nNotes:\n%s\n" % request.form['notes']
    if request.form['email']:
        submit_msg = submit_msg + "\nSender:\n%s\n" % request.form['email']
        reply_to = request.form['email']
    else:
        reply_to = ''
    submit_msg = submit_msg + "\n\nEdit Condate: %sadmin/condate/%s/\n" % (request.url_root, condate.id)
    if request.form['convention'] == 'other':
        submit_msg = submit_msg + "Edit Convention: %sadmin/convention/%s/\n" % (request.url_root, convention.id)
    msg = Message("New con-mon submission (%s)" % condate.title,
        sender="*****@*****.**",
        reply_to = reply_to,
        recipients=["*****@*****.**"])
    msg.body = submit_msg
    mail.send(msg)
    flash('The condate was submitted ok and is in review!')
    return redirect(url_for('index'))
Ejemplo n.º 15
0
    def test_initialize(self):

        msg = Message(subject="subject", recipients=['*****@*****.**'])

        self.assertEqual(msg.sender, "*****@*****.**")
        self.assertEqual(msg.recipients, ['*****@*****.**'])
Ejemplo n.º 16
0
    def test_send_without_body(self):

        msg = Message(subject="testing", recipients=["*****@*****.**"])

        self.assertRaises(AssertionError, self.mail.send, msg)
Ejemplo n.º 17
0
    def test_send_without_recipients(self):

        msg = Message(subject="testing", recipients=[], body="testing")

        self.assertRaises(AssertionError, self.mail.send, msg)
Ejemplo n.º 18
0
def submit_condate():
    start_date = request.form.get('start_date', '')
    if request.form.get('diebots_5000', None) or start_date == '' or start_date == str(datetime.now())[:10]:
        if request.is_xhr:
            return jsonify({ 'message': 'Suspected as spam.' })
        else:
            flash('Suspected as spam.')
            return redirect(url_for('index'))

    convention_id = request.form.get('convention', None)
    if not convention_id:
        return jsonify({ 'message': 'Bad request' })
    elif convention_id == 'other':
        convention = Convention.query.filter(Convention.title == request.form.get('convention_title', '')).first()
        if not convention:
            twitter_handle = request.form.get('convention_twitter', '').replace('@','')
            convention = Convention(
                title = request.form.get('convention_title', ''),
                twitter = twitter_handle,
                location = request.form.get('convention_location', ''),
                url = request.form.get('convention_url', '')
                )
            db.session.add(convention)
            db.session.commit()
        # any tags for convention?
        if request.form.get('convention_tags', None):
            for tag in request.form.getlist('convention_tags'):
                tag = Tag.query.filter(Tag.id == tag).first()
                convention.tags.append(tag)
    else:
        convention = Convention.query.filter(Convention.id == convention_id).first()

    notes = request.form.get('notes', '')
    email = request.form.get('email', None)
    if email:
        notes = "%s (submitted by %s)" % (notes, email)
    title = convention.title + ' ' + start_date[:4]
    condate = Condate(
        convention_id = convention.id,
        title = title,
        start_date = parser.parse(start_date),
        notes = notes,
        published = False
        )

    # optional dates
    registration_opens = request.form.get('registration_opens', None)
    registration_closes = request.form.get('registration_closes', None)
    end_date = request.form.get('end_date', None)
    if end_date:
        condate.end_date = parser.parse(end_date)
    if registration_opens:
        condate.registration_opens = parser.parse(registration_opens)
    if registration_closes:
        condate.registration_closes = parser.parse(registration_closes)

    db.session.add(condate)
    db.session.commit()

    # email details
    submit_msg = "New Condate submission!\n\n"
    submit_msg = submit_msg + "Convention: %s\n" % convention.title
    submit_msg = submit_msg + "Start date: %s\n" % condate.start_date
    submit_msg = submit_msg + "End date: %s\n" % condate.end_date
    submit_msg = submit_msg + "Registration opens: %s\n" % condate.registration_opens
    submit_msg = submit_msg + "Registration closes: %s\n" % condate.registration_closes
    if notes:
        submit_msg = submit_msg + "\nNotes:\n%s\n" % notes
    if email:
        submit_msg = submit_msg + "\nSender:\n%s\n" % email
        reply_to = email
    else:
        reply_to = ''
    submit_msg = submit_msg + "\n\nEdit Condate: %sadmin/condate/%s/\n" % (request.url_root, condate.id)
    if convention_id == 'other':
        submit_msg = submit_msg + "Edit Convention: %sadmin/convention/%s/\n" % (request.url_root, convention.id)
    msg = Message("New con-mon submission (%s)" % condate.title,
        sender = "*****@*****.**",
        reply_to = reply_to,
        recipients = ["*****@*****.**"])
    msg.body = submit_msg
    mail.send(msg)

    if request.is_xhr:
        return jsonify({
            'success': True,
            'message': 'The condate was submitted ok and is in review!'
            })
    else:
        flash('The condate was submitted ok and is in review!')
        return redirect(url_for('index'))
Ejemplo n.º 19
0
    def test_add_recipient(self):

        msg = Message("testing")
        msg.add_recipient("*****@*****.**")

        self.assertEqual(msg.recipients, ["*****@*****.**"])