| OLD | NEW | 
|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 | 
| 2 | 2 | 
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, | 
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH | 
| 5 # | 5 # | 
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify | 
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as | 
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. | 
| 9 # | 9 # | 
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 106   config = get_config() | 106   config = get_config() | 
| 107   if config.has_option('DEFAULT', 'mailerDebug') and config.get('DEFAULT', 'mail
     erDebug') == 'yes': | 107   if config.has_option('DEFAULT', 'mailerDebug') and config.get('DEFAULT', 'mail
     erDebug') == 'yes': | 
| 108     (handle, path) = mkstemp(prefix='mail_', suffix='.eml', dir='.') | 108     (handle, path) = mkstemp(prefix='mail_', suffix='.eml', dir='.') | 
| 109     os.close(handle) | 109     os.close(handle) | 
| 110     f = codecs.open(path, 'wb', encoding='utf-8') | 110     f = codecs.open(path, 'wb', encoding='utf-8') | 
| 111     print >>f, mail | 111     print >>f, mail | 
| 112     f.close() | 112     f.close() | 
| 113   else: | 113   else: | 
| 114     subprocess.Popen([config.get('DEFAULT', 'mailer'), '-t'], stdin=subprocess.P
     IPE).communicate(mail.encode('utf-8')) | 114     subprocess.Popen([config.get('DEFAULT', 'mailer'), '-t'], stdin=subprocess.P
     IPE).communicate(mail.encode('utf-8')) | 
| 115 | 115 | 
|  | 116 def encode_email_address(email): | 
|  | 117   ''' | 
|  | 118   Validates and encodes an email address. | 
|  | 119 | 
|  | 120   The validation implemented here is very rudamentery and not meant | 
|  | 121   to be complete, as full email validation can get extremly complicated | 
|  | 122   and is rarely needed. This function is primarily making sure that the | 
|  | 123   email address contains no whitespaces and only valid ASCII characters. | 
|  | 124   ''' | 
|  | 125   match = re.search(r'^([^@\s]+)@([^@\s]+)$', email) | 
|  | 126   if not match: | 
|  | 127     raise ValueError | 
|  | 128 | 
|  | 129   try: | 
|  | 130     return email.encode('ascii') | 
|  | 131   except UnicodeEncodeError: | 
|  | 132     return '%s@%s' % (match.group(1).encode('ascii'), | 
|  | 133                       match.group(2).encode('idna')) | 
|  | 134 | 
| 116 _template_cache = {} | 135 _template_cache = {} | 
| 117 | 136 | 
| 118 def get_template(template, autoescape=True): | 137 def get_template(template, autoescape=True): | 
| 119   """Parses and returns a Jinja2 template""" | 138   """Parses and returns a Jinja2 template""" | 
| 120   key = (template, autoescape) | 139   key = (template, autoescape) | 
| 121   if not key in _template_cache: | 140   if not key in _template_cache: | 
| 122     if autoescape: | 141     if autoescape: | 
| 123       env = get_template_environment() | 142       env = get_template_environment() | 
| 124     else: | 143     else: | 
| 125       env = get_unescaped_template_environment() | 144       env = get_unescaped_template_environment() | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 154     Returns a custom Jinja2 template environment with additional filters. | 173     Returns a custom Jinja2 template environment with additional filters. | 
| 155   """ | 174   """ | 
| 156   from sitescripts.templateFilters import filters | 175   from sitescripts.templateFilters import filters | 
| 157   import jinja2 | 176   import jinja2 | 
| 158   if not loader: | 177   if not loader: | 
| 159     loader = jinja2.FileSystemLoader(siteScriptsPath) | 178     loader = jinja2.FileSystemLoader(siteScriptsPath) | 
| 160   env = jinja2.Environment(loader=loader, autoescape=True) | 179   env = jinja2.Environment(loader=loader, autoescape=True) | 
| 161   env.filters.update(filters) | 180   env.filters.update(filters) | 
| 162   env.filters.update(additional_filters) | 181   env.filters.update(additional_filters) | 
| 163   return env | 182   return env | 
| OLD | NEW | 
|---|