|
|
@ -19,18 +19,12 @@ from __future__ import print_function |
|
|
|
import email.utils |
|
|
|
import email.utils |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
import os |
|
|
|
import os |
|
|
|
import sys |
|
|
|
|
|
|
|
import textwrap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ._base import Config |
|
|
|
import pkg_resources |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
from ._base import Config, ConfigError |
|
|
|
|
|
|
|
|
|
|
|
TEMPLATE_DIR_WARNING = """\ |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
WARNING: The email notifier is configured to look for templates in '%(template_dir)s', |
|
|
|
|
|
|
|
but no templates could be found there. We will fall back to using the example templates; |
|
|
|
|
|
|
|
to get rid of this warning, leave 'email.template_dir' unset. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmailConfig(Config): |
|
|
|
class EmailConfig(Config): |
|
|
@ -78,20 +72,22 @@ class EmailConfig(Config): |
|
|
|
self.email_notif_template_html = email_config["notif_template_html"] |
|
|
|
self.email_notif_template_html = email_config["notif_template_html"] |
|
|
|
self.email_notif_template_text = email_config["notif_template_text"] |
|
|
|
self.email_notif_template_text = email_config["notif_template_text"] |
|
|
|
|
|
|
|
|
|
|
|
self.email_template_dir = email_config.get("template_dir") |
|
|
|
template_dir = email_config.get("template_dir") |
|
|
|
|
|
|
|
# we need an absolute path, because we change directory after starting (and |
|
|
|
# backwards-compatibility hack |
|
|
|
# we don't yet know what auxilliary templates like mail.css we will need). |
|
|
|
if ( |
|
|
|
# (Note that loading as package_resources with jinja.PackageLoader doesn't |
|
|
|
self.email_template_dir == "res/templates" |
|
|
|
# work for the same reason.) |
|
|
|
and not os.path.isfile( |
|
|
|
if not template_dir: |
|
|
|
os.path.join(self.email_template_dir, self.email_notif_template_text) |
|
|
|
template_dir = pkg_resources.resource_filename( |
|
|
|
|
|
|
|
'synapse', 'res/templates' |
|
|
|
) |
|
|
|
) |
|
|
|
): |
|
|
|
template_dir = os.path.abspath(template_dir) |
|
|
|
t = TEMPLATE_DIR_WARNING % { |
|
|
|
|
|
|
|
"template_dir": self.email_template_dir, |
|
|
|
for f in self.email_notif_template_text, self.email_notif_template_html: |
|
|
|
} |
|
|
|
p = os.path.join(template_dir, f) |
|
|
|
print(textwrap.fill(t, width=80) + "\n", file=sys.stderr) |
|
|
|
if not os.path.isfile(p): |
|
|
|
self.email_template_dir = None |
|
|
|
raise ConfigError("Unable to find email template file %s" % (p, )) |
|
|
|
|
|
|
|
self.email_template_dir = template_dir |
|
|
|
|
|
|
|
|
|
|
|
self.email_notif_for_new_users = email_config.get( |
|
|
|
self.email_notif_for_new_users = email_config.get( |
|
|
|
"notif_for_new_users", True |
|
|
|
"notif_for_new_users", True |
|
|
|