Example #1
0
 def _html_template(self, config, tpl_names, elems=None):
     theme_path = os.path.join(config.data_directory("html_theme"), "html")
     env = Environment(
         loader=FileSystemLoader("%s" % theme_path),
         extensions=["jinja2.ext.i18n", "jinja2.ext.with_", "mailpile.jinjaextensions.MailpileCommand"],
     )
     env.session = self.session
     for tpl_name in tpl_names:
         try:
             fn = "%s.html" % tpl_name
             # FIXME(Security): Here we need to sanitize the file name very
             #                  strictly in case it somehow came from user
             #                  data.
             template = env.get_template(fn)
             return template
         except (IOError, OSError, AttributeError), e:
             emsg = "<h1>Template not found: %s</h1>%s\n"
             return emsg % (fn, e)
         except (
             TemplateError,
             UndefinedError,
             TemplateSyntaxError,
             TemplateAssertionError,
             TemplateNotFound,
             TemplatesNotFound,
         ), e:
             emsg = (
                 "<h1>Template error in %s</h1>\n"
                 "Parsing template %s: <b>%s</b> on line %s<br/>"
                 "<div><xmp>%s</xmp></div>"
             )
             return emsg % (e.name, e.filename, e.message, e.lineno, e.source)
Example #2
0
 def _web_template(self, config, tpl_names, elems=None, ext='html'):
     # FIXME: would be nice to rename html folder to web
     theme_path = os.path.join(config.data_directory('html_theme'), 'html')
     plugin_path = os.path.join(config.data_directory('html_theme'),
                                'plugins')
     templatepaths = [theme_path, plugin_path]
     env = Environment(loader=FileSystemLoader(templatepaths),
                       autoescape=True,
                       extensions=[
                           'jinja2.ext.i18n', 'jinja2.ext.with_',
                           'jinja2.ext.do',
                           'mailpile.jinjaextensions.MailpileCommand'
                       ])
     env.install_gettext_translations(config.get_i18n_translation(),
                                      newstyle=True)
     env.session = Session(config)
     env.session.ui = HttpUserInteraction(None, config)
     for tpl_name in tpl_names:
         try:
             fn = '%s.%s' % (tpl_name, ext)
             # FIXME(Security): Here we need to sanitize the file name
             #                  very strictly in case it somehow came
             #                  from user data.
             return env.get_template(fn)
         except (IOError, OSError, AttributeError), e:
             pass
Example #3
0
 def _html_template(self, config, tpl_names, elems=None):
   theme_path = os.path.join(config.data_directory('html_theme'), 'html')
   env = Environment(loader=FileSystemLoader('%s' % theme_path),
                     extensions=['jinja2.ext.i18n', 'jinja2.ext.with_',
                                 'mailpile.jinjaextensions.MailpileCommand'])
   env.session = Session(config)
   env.session.ui = HttpUserInteraction(None, config)
   for tpl_name in tpl_names:
     try:
       fn = '%s.html' % tpl_name
       # FIXME(Security): Here we need to sanitize the file name very
       #                  strictly in case it somehow came from user
       #                  data.
       return env.get_template(fn)
     except (IOError, OSError, AttributeError), e:
       pass
Example #4
0
 def _html_template(self, config, tpl_names, elems=None):
   theme_path = os.path.join(config.data_directory('html_theme'), 'html')
   env = Environment(loader=FileSystemLoader('mailpile', '%s' % theme_path),
                     extensions=['jinja2.ext.i18n', 'jinja2.ext.with_', 'mailpile.jinjaextensions.MailpileCommand'])
   env.session = self.session
   for tpl_name in tpl_names:
     try:
       fn = '%s.html' % tpl_name
       template = env.get_template(fn)
       return template
     except (IOError, OSError, AttributeError), e:
       emsg = "<h1>Template not found: %s</h1>%s\n"
       return emsg % (fn, e)
     except (TemplateError, UndefinedError, TemplateSyntaxError, TemplateAssertionError, TemplateNotFound, TemplatesNotFound), e:
       emsg = "<h1>Template error in %s</h1>\nParsing template %s: <b>%s</b> on line %s<br/><div><xmp>%s</xmp></div>"
       return emsg % (e.name, e.filename, e.message, e.lineno, e.source)
Example #5
0
 def _html_template(self, config, tpl_names, elems=None):
   theme_path = os.path.join(config.data_directory('html_theme'), 'html')
   env = Environment(loader=FileSystemLoader('%s' % theme_path),
                     extensions=['jinja2.ext.i18n', 'jinja2.ext.with_',
                                 'mailpile.jinjaextensions.MailpileCommand'])
   env.install_gettext_translations(config.get_i18n_translation(), newstyle=True)
   env.session = Session(config)
   env.session.ui = HttpUserInteraction(None, config)
   for tpl_name in tpl_names:
     try:
       fn = '%s.html' % tpl_name
       # FIXME(Security): Here we need to sanitize the file name very
       #                  strictly in case it somehow came from user
       #                  data.
       return env.get_template(fn)
     except (IOError, OSError, AttributeError), e:
       pass
Example #6
0
 def _html_template(self, config, tpl_names, elems=None):
     theme_path = os.path.join(config.data_directory("html_theme"), "html")
     env = Environment(
         loader=FileSystemLoader("%s" % theme_path),
         extensions=["jinja2.ext.i18n", "jinja2.ext.with_", "mailpile.jinjaextensions.MailpileCommand"],
     )
     env.install_gettext_translations(config.get_i18n_translation(), newstyle=True)
     env.session = Session(config)
     env.session.ui = HttpUserInteraction(None, config)
     for tpl_name in tpl_names:
         try:
             fn = "%s.html" % tpl_name
             # FIXME(Security): Here we need to sanitize the file name very
             #                  strictly in case it somehow came from user
             #                  data.
             return env.get_template(fn)
         except (IOError, OSError, AttributeError), e:
             pass
Example #7
0
 def _web_template(self, config, tpl_names, elems=None, ext='html'):
     # FIXME: would be nice to rename html folder to web
     theme_path = os.path.join(config.data_directory('html_theme'), 'html')
     env = Environment(loader=FileSystemLoader('%s' % theme_path),
                       autoescape=True,
                       extensions=[
                           'jinja2.ext.i18n', 'jinja2.ext.with_',
                           'jinja2.ext.do',
                           'mailpile.jinjaextensions.MailpileCommand'])
     env.install_gettext_translations(config.get_i18n_translation(),
                                      newstyle=True)
     env.session = Session(config)
     env.session.ui = HttpUserInteraction(None, config)
     for tpl_name in tpl_names:
         try:
             fn = '%s.%s' % (tpl_name, ext)
             # FIXME(Security): Here we need to sanitize the file name
             #                  very strictly in case it somehow came
             #                  from user data.
             return env.get_template(fn)
         except (IOError, OSError, AttributeError), e:
             pass