コード例 #1
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def editReport(**kwargs):
    context = {
        'report': postgres.connection().selectOne('DMARCReport', kwargs),
        'dMARCReportRows': postgres.connection().select('DMARCReportRow', kwargs),
    }

    return flask.render_template('report.html', **context)
コード例 #2
0
ファイル: user.py プロジェクト: mehulsbhatt/tart-mailer
def redirect(emailHash):
    postgres.connection().call('NewEmailSendFeedback', (emailHash, 'redirected', flask.request.remote_addr))
    redirectURL = postgres.connection().call('EmailSendRedirectURL', emailHash)

    if redirectURL:
        return flask.redirect(redirectURL)
    flask.abort(404)
コード例 #3
0
ファイル: user.py プロジェクト: mehulsbhatt/tart-mailer
def view(emailHash):
    postgres.connection().call('NewEmailSendFeedback', (emailHash, 'viewed', flask.request.remote_addr))
    body = postgres.connection().call('ViewEmailBody', emailHash)

    if body:
        return body
    flask.abort(404)
コード例 #4
0
ファイル: api.py プロジェクト: tart/tart-mailer
def upsertSubscriber(**kwargs):
    try:
        data = postData()
        if data:
            return postgres.connection().updateOne('Subscriber', data, kwargs)
        return postgres.connection().selectOne('Subscriber', kwargs)
    except postgres.NoRow:
        return postgres.connection().insert('Subscriber', postData(kwargs))
コード例 #5
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def editEmail(**kwargs):
    identifiers = {key: kwargs.pop(key) for key in ('fromaddress', 'emailid')}

    if 'email' not in kwargs:
        kwargs['email'] = postgres.connection().selectOne('Email', identifiers)

    kwargs['emailVariations'] = postgres.connection().select('EmailVariation', identifiers, 'variationId')
    kwargs['subscriberLocales'] = postgres.connection().select('SubscriberLocaleStatistics',
                                                               {'fromAddress': identifiers['fromaddress']})
    kwargs['exampleProperties'] = postgres.connection().call('SubscriberExampleProperties', identifiers['fromaddress'])
    kwargs['force'] = flask.request.args

    return flask.render_template('email.html', **kwargs)
コード例 #6
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def prepareBulkEmail(**kwargs):
    identifiers = {key: kwargs.pop(key) for key in ('fromaddress', 'emailid')}

    kwargs['email'] = postgres.connection().selectOne('Email', identifiers)
    kwargs['subscriberLocales'] = postgres.connection().select('EmailSubscriberLocaleStatistics',
                                  dict(list(identifiers.items()) + [('locale', kwargs['email']['locale'])]))
    kwargs['emailVariations'] = postgres.connection().select('EmailVariationStatistics',
                                dict(list(identifiers.items()) + [('state', 'sent')]))
    kwargs['maxSubscriber'] = sum(row['remaining'] for row in kwargs['subscriberLocales'])
    kwargs['exampleProperties'] = postgres.connection().call('SubscriberExampleProperties', identifiers['fromaddress'])
    kwargs['propertyCount'] = 10
    kwargs['canSend'] = (kwargs['email']['bulk'] and kwargs['email']['state'] == 'sent' and
                         kwargs['maxSubscriber'] > 0 and kwargs['emailVariations'])

    return flask.render_template('bulkemail.html', **kwargs)
コード例 #7
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def editSender(**kwargs):
    identifiers = {key: kwargs.pop(key) for key in ('fromaddress',)}

    if 'sender' not in kwargs:
        kwargs['sender'] = postgres.connection().selectOne('Sender', identifiers)

    return flask.render_template('sender.html', **kwargs)
コード例 #8
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def domainStatistics(**kwargs):
    context = {
        'identifiers': kwargs,
        'dMARCReports': postgres.connection().select('DMARCReportDetail', kwargs),
    }

    return flask.render_template('domainstatistics.html', **context)
コード例 #9
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def newSender(**kwargs):
    parts = parseURL(flask.request.url_root)
    kwargs['sender'] = {
        'returnurlroot': parts['protocol'] + '//' + parts['root'] + '/',
        'password': postgres.connection().call('GeneratePassword'),
    }

    return flask.render_template('sender.html', **kwargs)
コード例 #10
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def newEmail(**kwargs):
    identifiers = {key: kwargs.pop(key) for key in ('fromaddress',)}
    kwargs['email'] = {
        'fromaddress': identifiers['fromaddress'],
        'state': 'new',
    }
    kwargs['subscriberLocales'] = postgres.connection().select('SubscriberLocaleStatistics', identifiers)

    return flask.render_template('email.html', **kwargs)
コード例 #11
0
ファイル: api.py プロジェクト: tart/tart-mailer
def paginate(tableName, conditions):
    response = {}
    if 'limit' in conditions:
        response['limit'] = conditions.pop('limit')
    else:
        response['limit'] = 100 # The default limit.
    if 'offset' in conditions:
        response['offset'] = conditions.pop('offset')
    response['records'] = postgres.connection().select(tableName, conditions, **response)
    return response
コード例 #12
0
ファイル: api.py プロジェクト: tart/tart-mailer
    def wrapped(**kwargs):
        if flask.request.method in ('POST', 'PUT'):
            if flask.request.headers['Content-Type'] != 'application/json':
                raise werkzeug.exceptions.BadRequest('Content-Type must be application/json')

            if not isinstance(flask.request.json, dict):
                raise werkzeug.exceptions.BadRequest('data must be a JSON object')

        if not flask.request.authorization:
            raise werkzeug.exceptions.Unauthorized('authentication required')

        with postgres.connection():
            if not postgres.connection().call('SenderAuthenticate', flask.request.authorization):
                raise werkzeug.exceptions.Unauthorized('authentication failed')

            response = operation(fromAddress=flask.request.authorization.username, **kwargs)
            assert isinstance(response, dict)

            return flask.jsonify(response)
コード例 #13
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def saveEmailVariation(**kwargs):
    with postgres.connection() as transaction:
        if 'variationid' not in kwargs:
            transaction.insert('EmailVariation', formData(**kwargs))
            kwargs['saveEmailVariationMessage'] = 'Email Variation created.'
        else:
            transaction.updateOne('EmailVariation', formData(), kwargs)
            kwargs['saveEmailVariationMessage'] = 'Email variation updated.'

        return editEmail(**kwargs)
コード例 #14
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def saveSender(**kwargs):
    with postgres.connection() as transaction:
        if 'fromaddress' not in kwargs:
            kwargs['sender'] = transaction.insert('Sender', formData())
            kwargs['fromaddress'] = kwargs['sender']['fromaddress']
            kwargs['senderMessage'] = 'Sender created.'
        else:
            kwargs['sender'] = transaction.updateOne('Sender', formData(), kwargs)
            kwargs['saveMessage'] = 'Sender updated.'

        return editSender(**kwargs)
コード例 #15
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def saveEmail(**kwargs):
    with postgres.connection() as transaction:
        if 'emailid' not in kwargs:
            kwargs['email'] = transaction.insert('Email', formData(**kwargs))
            kwargs['emailid'] = kwargs['email']['emailid']
            kwargs['saveMessage'] = 'Email created.'
        else:
            kwargs['email'] = transaction.updateOne('Email', formData(), kwargs)
            kwargs['saveMessage'] = 'Email updated.'

        return editEmail(**kwargs)
コード例 #16
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def emailStatistics(**kwargs):
    with postgres.connection() as transaction:
        context = {
            'identifiers': kwargs,
            'emailSentDates': transaction.select('EmailSentDateStatistics', kwargs),
            'emailVariations': transaction.select('EmailVariationStatistics', kwargs),
        }

        if 'emailid' in kwargs:
            context['email'] = transaction.selectOne('Email', kwargs)
            context['emailSubscriberLocales'] = transaction.select('EmailSubscriberLocaleStatistics', kwargs)
        else:
            context['emails'] = transaction.select('EmailStatistics', kwargs)

    return flask.render_template('emailstatistics.html', **context)
コード例 #17
0
ファイル: reprocess.py プロジェクト: mehulsbhatt/tart-mailer
def main():
    import xml.etree.cElementTree as ElementTree

    with postgres.connection() as transaction:
        transaction.truncate('DMARCReportRow')

        for report in transaction.select('DMARCReport'):
            tree = ElementTree.fromstring(report['body'])

            for record in tree.iter('record'):
                transaction.insert('DMARCReportRow', {
                    'reporterAddress': report['reporteraddress'],
                    'reportId': report['reportid'],
                    'source': record.find('row/source_ip').text,
                    'messageCount': record.find('row/count').text,
                    'disposition': record.find('row/policy_evaluated/disposition').text,
                    'dKIMPass': record.find('row/policy_evaluated/dkim').text == 'pass',
                    'sPFPass': record.find('row/policy_evaluated/spf').text == 'pass',
                })
コード例 #18
0
ファイル: admin.py プロジェクト: mehulsbhatt/tart-mailer
def sendTestEmail(**kwargs):
    toAddress = formData()['toaddress']

    with postgres.connection() as transaction:
        transaction.insertIfNotExists('Subscriber', {
           'fromAddress': kwargs['fromaddress'],
           'toAddress': toAddress,
        })

        transaction.upsert('EmailSend', {
            'state': 'new',
            'variationId': kwargs['variationid'],
        }, {
            'fromAddress': kwargs['fromaddress'],
            'toAddress': toAddress,
            'emailId': kwargs['emailid'],
        })

        kwargs['sendTestEmailMessage'] = 'Test email message added to the queue.'
        return editEmail(**kwargs)
コード例 #19
0
ファイル: api.py プロジェクト: tart/tart-mailer
def getEmailVariation(**kwargs):
    return postgres.connection().selectOne('EmailVariation', kwargs)
コード例 #20
0
ファイル: user.py プロジェクト: mehulsbhatt/tart-mailer
def track(emailHash):
    postgres.connection().call('NewEmailSendFeedback', (emailHash, 'tracked', flask.request.remote_addr))

    # Return 1px * 1px transparent image.
    return flask.send_file(io.BytesIO(b'GIF89a\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;'), mimetype='image/gif')
コード例 #21
0
ファイル: api.py プロジェクト: tart/tart-mailer
def getEmail(**kwargs):
    return postgres.connection().selectOne('NestedEmail', kwargs)
コード例 #22
0
ファイル: api.py プロジェクト: tart/tart-mailer
def addEmail(**kwargs):
    return postgres.connection().insert('NestedEmail', postData(kwargs))
コード例 #23
0
ファイル: api.py プロジェクト: tart/tart-mailer
def setSender(**kwargs):
    return postgres.connection().updateOne('Sender', postData(kwargs), kwargs)
コード例 #24
0
ファイル: api.py プロジェクト: tart/tart-mailer
def getSender(**kwargs):
    return postgres.connection().selectOne('Sender', kwargs)
コード例 #25
0
ファイル: api.py プロジェクト: tart/tart-mailer
def addEmailVariation(**kwargs):
    return postgres.connection().insert('EmailVariation', postData(kwargs))
コード例 #26
0
ファイル: api.py プロジェクト: tart/tart-mailer
def sendToSubscriber(**kwargs):
    try:
        return postgres.connection().call('SendToSubscriber', postData(kwargs))
    except postgres.NoRow:
        raise NotAllowed('cannot send to this address')
コード例 #27
0
ファイル: api.py プロジェクト: tart/tart-mailer
def addSubscriber(**kwargs):
    return postgres.connection().insert('Subscriber', postData(kwargs))
コード例 #28
0
ファイル: api.py プロジェクト: tart/tart-mailer
def getSubscriber(**kwargs):
    return postgres.connection().selectOne('Subscriber', kwargs)
コード例 #29
0
ファイル: user.py プロジェクト: mehulsbhatt/tart-mailer
def unsubscribe(emailHash):
    if postgres.connection().call('NewEmailSendFeedback', (emailHash, 'unsubscribed', flask.request.remote_addr)):
        return 'You are successfully unsubscribed.'
    else:
        return 'You have already unsubscribed.'
コード例 #30
0
ファイル: api.py プロジェクト: tart/tart-mailer
def upsertEmailVariation(**kwargs):
    try:
        return postgres.connection().updateOne('EmailVariation', postData(), kwargs)
    except postgres.NoRow:
        return postgres.connection().insert('EmailVariation', postData(kwargs))