示例#1
0
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
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
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
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
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
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
def domainStatistics(**kwargs):
    context = {
        'identifiers': kwargs,
        'dMARCReports': postgres.connection().select('DMARCReportDetail', kwargs),
    }

    return flask.render_template('domainstatistics.html', **context)
示例#9
0
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
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
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
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
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
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
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
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
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
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))