示例#1
0
def handleRequest(environ, start_response):
  setupStderr(environ['wsgi.errors'])

  start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
  if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
    return 'Unsupported request method'

  try:
    request_body_length = int(environ['CONTENT_LENGTH'])
  except:
    return 'Invalid or missing Content-Length header'

  request_body = environ['wsgi.input'].read(request_body_length)
  params = {}
  for key, value in parse_qsl(request_body):
    params[key] = value.decode('utf-8').strip()

  if not 'name' in params or params['name'] == '':
    return 'No name entered'
  if not 'email' in params or params['email'] == '':
    return 'No email address entered'
  if not 'subject' in params or params['subject'] == '':
    return 'No subject entered'
  if not 'message' in params or params['message'] == '':
    return 'No message entered'

  if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$', params['email']):
    return 'Invalid email address'

  sendMail(get_config().get('formmail', 'template'), params)
  return 'Message sent'
示例#2
0
def submit_email(environ, start_response, data):
  email = data.get('email', '').strip()
  try:
    email = encode_email_address(email)
  except ValueError:
    return send_simple_response(
      start_response, 400,
      'Please enter a valid email address.'
    )

  config = get_config()
  params = [('email', email), ('signature', sign(config, email))]
  lang = data.get('lang')
  if lang:
    params.append(('lang', lang))

  sendMail(
    config.get('submit_email', 'verification_email_template'),
    {
      'recipient': email,
      'verification_url': '%s?%s' % (
        urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH),
        urlencode(params)
      )
    }
  )

  return send_simple_response(
    start_response, 200,
    'A confirmation email has been sent. Please check '
    'your email and click the confirmation link.'
  )
示例#3
0
 def handler(environ, start_response, params):
     response_headers = [('Content-Type', 'text/plain; charset=utf-8')]
     errors = validate_fields(fields, params)
     if errors:
         start_response('400 Bad Request', response_headers)
         return '\n'.join(errors)
     time = datetime.datetime.now()
     template_args = {
         'time': time,
         'fields': {field: params.get(field, '')
                    for field in fields},
     }
     try:
         sendMail(template, template_args)
     except:
         print(traceback.print_exc(), file=sys.stderr)
         start_response('500 Server Error', response_headers)
         return ''
     finally:
         if 'csv_log' in config:
             params = {
                 field: params.get(field, '').encode('utf8')
                 for field in fields
             }
             params['time'] = time
             log_formdata(params, config['csv_log'].value)
     start_response('200 OK', response_headers)
     return ''
示例#4
0
def handleRequest(environ, start_response):
    setupStderr(environ['wsgi.errors'])

    start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
    if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get(
            'CONTENT_TYPE',
            '').startswith('application/x-www-form-urlencoded'):
        return 'Unsupported request method'

    try:
        request_body_length = int(environ['CONTENT_LENGTH'])
    except:
        return 'Invalid or missing Content-Length header'

    request_body = environ['wsgi.input'].read(request_body_length)
    params = {}
    for key, value in parse_qsl(request_body):
        params[key] = value.decode('utf-8').strip()

    if not 'name' in params or params['name'] == '':
        return 'No name entered'
    if not 'email' in params or params['email'] == '':
        return 'No email address entered'
    if not 'subject' in params or params['subject'] == '':
        return 'No subject entered'
    if not 'message' in params or params['message'] == '':
        return 'No message entered'

    if not re.match(r'^\w[\w.+!-]+@\w[\w.-]+\.[a-zA-Z]{2,6}$',
                    params['email']):
        return 'Invalid email address'

    params['time'] = datetime.datetime.now()
    sendMail(get_config().get('formmail', 'template'), params)
    return 'Message sent'
def send_installation_link(environ, start_response, data):
    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(start_response, 400,
                                    'Please enter a valid email address.')

    config = get_config()
    template_path = config.get('send_installation_link', 'email_template')
    sendMail(template_path, {'recipient': email})

    return send_simple_response(
        start_response, 200, 'The app is on the way! '
        'Please check your email on your smartphone or tablet.')
def send_installation_link(environ, start_response, data):
    email = data.get("email", "").strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(start_response, 400,
                                    "Please enter a valid email address.")

    config = get_config()
    template_path = config.get("send_installation_link", "email_template")
    sendMail(template_path, {"recipient": email})

    return send_simple_response(
        start_response, 200, "The app is on the way! "
        "Please check your email on your smartphone or tablet.")
示例#7
0
def submit_email(environ, start_response, data):
    config = get_config()

    try:
        product = data['product']
        template = config.get('submit_email',
                              product + '_verification_email_template')
    except (KeyError, ConfigParser.NoOptionError):
        return send_simple_response(start_response, 400, 'Unknown product')

    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response,
            400,
            'Please enter a valid email address.',
        )

    params = [('email', email), ('signature', sign(config, email)),
              ('product', product)]
    lang = data.get('lang')
    if lang:
        params.append(('lang', lang))

    sendMail(
        template,
        {
            'recipient':
            email,
            'verification_url':
            '%s?%s' % (
                urljoin(wsgiref.util.application_uri(environ),
                        VERIFICATION_PATH),
                urlencode(params),
            ),
        },
    )

    return send_simple_response(
        start_response,
        200,
        'A confirmation email has been sent. Please check '
        'your email and click the confirmation link.',
    )
def send_installation_link(environ, start_response, data):
    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response, 400,
            'Please enter a valid email address.',
        )

    config = get_config()
    template_path = config.get('send_installation_link', 'email_template')
    sendMail(template_path, {'recipient': email})

    return send_simple_response(
        start_response, 200,
        'The app is on the way! '
        'Please check your email on your smartphone or tablet.',
    )
示例#9
0
def submit_email(environ, start_response, data):
    config = get_config()

    try:
        product = data['product']
        template = config.get('submit_email', product + '_verification_email_template')
    except (KeyError, ConfigParser.NoOptionError):
        return send_simple_response(start_response, 400, 'Unknown product')

    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response, 400,
            'Please enter a valid email address.',
        )

    params = [('email', email), ('signature', sign(config, email)), ('product', product)]
    lang = data.get('lang')
    if lang:
        params.append(('lang', lang))

    sendMail(
        template,
        {
            'recipient': email,
            'verification_url': '%s?%s' % (
                urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH),
                urlencode(params),
            ),
        },
    )

    return send_simple_response(
        start_response, 200,
        'A confirmation email has been sent. Please check '
        'your email and click the confirmation link.',
    )
示例#10
0
    def handler(environ, start_response, params):
        response_headers = [('Content-Type', 'text/plain; charset=utf-8')]
        errors = []
        for field, spec in fields.items():
            if 'mandatory' in spec.value:
                if field not in params.keys():
                    errors.append(make_error(spec, 'mandatory',
                                             'No {} entered'.format(field)))
            if 'email' in spec.value and field in params.keys():
                try:
                    params[field] = encode_email_address(params[field])
                except ValueError:
                    errors.append(make_error(spec, 'email', 'Invalid email'))
        if errors:
            start_response('400 Bad Request', response_headers)
            return '\n'.join(errors)

        template_args = {
            'time': datetime.datetime.now(),
            'fields': {field: params.get(field, '') for field in fields}
        }
        sendMail(template, template_args)
        start_response('200 OK', response_headers)
        return ''
示例#11
0
def sendUpdateNotification(templateData):
    sendMail(get_config().get('reports', 'notificationTemplate'), templateData)
示例#12
0
def mailDigest(templateData):
    sendMail(get_config().get('reports', 'mailDigestTemplate'), templateData)
示例#13
0
def sendUpdateNotification(templateData):
    sendMail(get_config().get('reports', 'notificationTemplate'), templateData)
示例#14
0
def mailDigest(templateData):
    sendMail(get_config().get('reports', 'mailDigestTemplate'), templateData)
示例#15
0
    gone = processFile(goneData, counts)

    unaccounted = filter(lambda url: counts[url] >= 10, counts.keys())
    unaccounted.sort(key=lambda url: counts[url], reverse=True)
    for i in range(0, len(unaccounted)):
        url = unaccounted[i]
        mark = ' [?]'
        if url in knownURLs:
            mark = ''
        unaccounted[i] = '%5i %s%s' % (counts[url], url, mark)

    return (redirects, gone, unaccounted)


if __name__ == '__main__':
    setupStderr()

    counts = {}
    for i in range(1, 15):
        logPath = os.path.join(get_config().get('logs', 'dataPath'),
                               get_config().get('logs', 'fileName') % i)
        countSubscriptionRequests(logPath, counts)

    (redirects, gone, unaccounted) = loadSubscriptions(counts)

    sendMail(get_config().get('subscriptions', 'reportTemplate'), {
        'redirects': redirects,
        'gone': gone,
        'unaccounted': unaccounted,
    })
示例#16
0
  (redirectData, goneData) = subscriptionParser.getFallbackData()
  redirects = processFile(redirectData, counts)
  gone = processFile(goneData, counts)

  unaccounted = filter(lambda url: counts[url] >= 10, counts.keys())
  unaccounted.sort(key=lambda url: counts[url], reverse=True)
  for i in range(0, len(unaccounted)):
    url = unaccounted[i]
    mark = ' [?]'
    if url in knownURLs:
      mark = ''
    unaccounted[i] = '%5i %s%s' % (counts[url], url, mark)

  return (redirects, gone, unaccounted)

if __name__ == '__main__':
  setupStderr()

  counts = {}
  for i in range(1, 15):
    logPath = os.path.join(get_config().get('logs', 'dataPath'), get_config().get('logs', 'fileName') % i)
    countSubscriptionRequests(logPath, counts)

  (redirects, gone, unaccounted) = loadSubscriptions(counts)

  sendMail(get_config().get('subscriptions', 'reportTemplate'), {
    'redirects': redirects,
    'gone': gone,
    'unaccounted': unaccounted,
  })