diff --git a/kallithea/controllers/admin/settings.py b/kallithea/controllers/admin/settings.py --- a/kallithea/controllers/admin/settings.py +++ b/kallithea/controllers/admin/settings.py @@ -350,20 +350,23 @@ class SettingsController(BaseController) if request.POST: test_email = request.POST.get('test_email') test_email_subj = 'Kallithea test email' - test_email_body = ('Kallithea Email test, ' + test_body = ('Kallithea Email test, ' 'Kallithea version: %s' % c.kallithea_version) if not test_email: h.flash(_('Please enter email address'), category='error') return redirect(url('admin_settings_email')) + test_email_txt_body = EmailNotificationModel()\ + .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, + 'txt', body=test_body) test_email_html_body = EmailNotificationModel()\ .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, - body=test_email_body) + 'html', body=test_body) recipients = [test_email] if test_email else None run_task(tasks.send_email, recipients, test_email_subj, - test_email_body, test_email_html_body) + test_email_txt_body, test_email_html_body) h.flash(_('Send email task created'), category='success') return redirect(url('admin_settings_email')) diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -118,7 +118,6 @@ class NotificationModel(BaseModel): # send email with notification to all other participants for rec in rec_objs: - email_body = None # we set body to none, we just send HTML emails ## this is passed into template kwargs = {'subject': subject, 'body': h.rst_w_mentions(body), @@ -129,11 +128,13 @@ class NotificationModel(BaseModel): kwargs.update(email_kwargs) email_subject = EmailNotificationModel()\ .get_email_description(type_, **kwargs) - email_body_html = EmailNotificationModel()\ - .get_email_tmpl(type_, **kwargs) + email_txt_body = EmailNotificationModel()\ + .get_email_tmpl(type_, 'txt', **kwargs) + email_html_body = EmailNotificationModel()\ + .get_email_tmpl(type_, 'html', **kwargs) - run_task(tasks.send_email, [rec.email], email_subject, email_body, - email_body_html, headers) + run_task(tasks.send_email, [rec.email], email_subject, email_txt_body, + email_html_body, headers) return notif @@ -270,12 +271,12 @@ class EmailNotificationModel(BaseModel): self._template_root = kallithea.CONFIG['pylons.paths']['templates'][0] self._tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup self.email_types = { - self.TYPE_CHANGESET_COMMENT: 'email_templates/changeset_comment.html', - self.TYPE_PASSWORD_RESET: 'email_templates/password_reset.html', - self.TYPE_REGISTRATION: 'email_templates/registration.html', - self.TYPE_DEFAULT: 'email_templates/default.html', - self.TYPE_PULL_REQUEST: 'email_templates/pull_request.html', - self.TYPE_PULL_REQUEST_COMMENT: 'email_templates/pull_request_comment.html', + self.TYPE_CHANGESET_COMMENT: 'changeset_comment', + self.TYPE_PASSWORD_RESET: 'password_reset', + self.TYPE_REGISTRATION: 'registration', + self.TYPE_DEFAULT: 'default', + self.TYPE_PULL_REQUEST: 'pull_request', + self.TYPE_PULL_REQUEST_COMMENT: 'pull_request_comment', } self._subj_map = { self.TYPE_CHANGESET_COMMENT: _('Comment on %(repo_name)s changeset %(short_id)s on %(branch)s by %(comment_username)s'), @@ -302,12 +303,12 @@ class EmailNotificationModel(BaseModel): subj += ' (%s)' % (', '.join(l)) return subj - def get_email_tmpl(self, type_, **kwargs): + def get_email_tmpl(self, type_, content_type, **kwargs): """ return generated template for email based on given type """ - base = self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT]) + base = 'email_templates/' + self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT]) + '.' + content_type email_template = self._tmpl_lookup.get_template(base) # translator and helpers inject _kwargs = {'_': _, diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -297,11 +297,16 @@ class UserModel(BaseModel): link = h.canonical_url('reset_password_confirmation', key=user.api_key) reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET body = EmailNotificationModel().get_email_tmpl(reg_type, + 'txt', + user=user.short_contact, + reset_url=link) + html_body = EmailNotificationModel().get_email_tmpl(reg_type, + 'html', user=user.short_contact, reset_url=link) log.debug('sending email') run_task(tasks.send_email, [user_email], - _("Password reset link"), body, body) + _("Password reset link"), body, html_body) log.info('send new password mail to %s' % user_email) else: log.debug("password reset email %s not found" % user_email) diff --git a/kallithea/templates/email_templates/changeset_comment.html b/kallithea/templates/email_templates/changeset_comment.txt copy from kallithea/templates/email_templates/changeset_comment.html copy to kallithea/templates/email_templates/changeset_comment.txt --- a/kallithea/templates/email_templates/changeset_comment.html +++ b/kallithea/templates/email_templates/changeset_comment.txt @@ -1,20 +1,19 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> %if is_mention: -

${_('Comment from %s on %s changeset %s mentioned you') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))}:

+${_('Comment from %s on %s changeset %s mentioned you') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))}: %else: -

${_('Comment from %s on %s changeset %s') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))}:

+${_('Comment from %s on %s changeset %s') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))}: %endif -

${body}

+${body} %if status_change: -

${_('The changeset status was changed to')}: ${status_change}

+${_('The changeset status was changed to')}: ${status_change} %endif -

${_('URL')}: ${cs_comment_url}

+${_('URL')}: ${cs_comment_url} -

${_('Changeset')}: ${h.short_id(raw_id)}

-

${_('Description')}:
+${_('Changeset')}: ${h.short_id(raw_id)} +${_('Description')}: ${h.shorter(message, 256)} -

diff --git a/kallithea/templates/email_templates/default.html b/kallithea/templates/email_templates/default.txt copy from kallithea/templates/email_templates/default.html copy to kallithea/templates/email_templates/default.txt --- a/kallithea/templates/email_templates/default.html +++ b/kallithea/templates/email_templates/default.txt @@ -1,4 +1,4 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> ${body} diff --git a/kallithea/templates/email_templates/main.html b/kallithea/templates/email_templates/main.html --- a/kallithea/templates/email_templates/main.html +++ b/kallithea/templates/email_templates/main.html @@ -1,4 +1,6 @@ ${self.body()} + +

--
-${_("This is an automatic notification - don't reply to this mail.")} +${_("This is an automatic notification. Don't reply to this mail.")} diff --git a/kallithea/templates/email_templates/main.html b/kallithea/templates/email_templates/main.txt copy from kallithea/templates/email_templates/main.html copy to kallithea/templates/email_templates/main.txt --- a/kallithea/templates/email_templates/main.html +++ b/kallithea/templates/email_templates/main.txt @@ -1,4 +1,4 @@ ${self.body()} -
---
-${_("This is an automatic notification - don't reply to this mail.")} + +-- +${_("This is an automatic notification. Don't reply to this mail.")} diff --git a/kallithea/templates/email_templates/password_reset.html b/kallithea/templates/email_templates/password_reset.txt copy from kallithea/templates/email_templates/password_reset.html copy to kallithea/templates/email_templates/password_reset.txt --- a/kallithea/templates/email_templates/password_reset.html +++ b/kallithea/templates/email_templates/password_reset.txt @@ -1,10 +1,11 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> -

${_('Hello %s') % user}

+${_('Hello %s') % user} -

${_('We received a request to create a new password for your account.')}

-

${_('You can generate it by clicking following URL')}:

-

${reset_url}

+${_('We received a request to create a new password for your account.')} +${_('You can generate it by clicking following URL')}: -

${_("Please ignore this email if you did not request a new password .")}

+${reset_url} + +${_("Please ignore this email if you did not request a new password .")} diff --git a/kallithea/templates/email_templates/pull_request.html b/kallithea/templates/email_templates/pull_request.txt copy from kallithea/templates/email_templates/pull_request.html copy to kallithea/templates/email_templates/pull_request.txt --- a/kallithea/templates/email_templates/pull_request.html +++ b/kallithea/templates/email_templates/pull_request.txt @@ -1,22 +1,20 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> %if is_mention: -

${_('%s mentioned you on %s pull request "%s"') % (pr_user_created, repo_name, pr_title)}

+${_('%s mentioned you on %s pull request "%s"') % (pr_user_created, repo_name, pr_title)} %else: -

${_('%s requested your review of %s pull request "%s"') % (pr_user_created, repo_name, pr_title)}

+${_('%s requested your review of %s pull request "%s"') % (pr_user_created, repo_name, pr_title)} %endif -

${_('URL')}: ${pr_url}

- -

${_('Description')}:

-

${body}

+${_('URL')}: ${pr_url} -

${_('Changesets')}:

-

+${_('Description')}: +${body} + +${_('Changesets')}: %for r,r_msg in pr_revisions: -${h.short_id(r)}: +${h.short_id(r)}: ${h.shorter(r_msg, 256)} %endfor -

diff --git a/kallithea/templates/email_templates/pull_request_comment.html b/kallithea/templates/email_templates/pull_request_comment.txt copy from kallithea/templates/email_templates/pull_request_comment.html copy to kallithea/templates/email_templates/pull_request_comment.txt --- a/kallithea/templates/email_templates/pull_request_comment.html +++ b/kallithea/templates/email_templates/pull_request_comment.txt @@ -1,15 +1,15 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> -

${_('Comment from %s on %s pull request "%s"') % (pr_comment_user, repo_name, pr_title)}:

-

${body}

+${_('Comment from %s on %s pull request "%s"') % (pr_comment_user, repo_name, pr_title)}: +${body} %if status_change: %if closing_pr: -

${_('The comment closed the pull request with status')}: ${status_change}

+${_('The comment closed the pull request with status')}: ${status_change} %else: -

${_('The comment was made with status')}: ${status_change}

+${_('The comment was made with status')}: ${status_change} %endif %endif -

${_('URL')}: ${pr_comment_url}

+${_('URL')}: ${pr_comment_url} diff --git a/kallithea/templates/email_templates/registration.html b/kallithea/templates/email_templates/registration.txt copy from kallithea/templates/email_templates/registration.html copy to kallithea/templates/email_templates/registration.txt --- a/kallithea/templates/email_templates/registration.html +++ b/kallithea/templates/email_templates/registration.txt @@ -1,6 +1,6 @@ ## -*- coding: utf-8 -*- -<%inherit file="main.html"/> +<%inherit file="main.txt"/> ${body} -${_('View this user here')}: ${registered_user_url} +${_('View this user here')}: ${registered_user_url}