Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail signature #485

Merged
merged 6 commits into from
May 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/pretix/base/services/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
subject = "[%s] %s" % (prefix, subject)

body_plain += "\r\n\r\n-- \r\n"

signature = str(event.settings.get('mail_text_signature'))
if signature:
signature = signature.format(event=event.name)
signature_md = signature.replace('\n', '<br>\n')
signature_md = bleach.linkify(bleach.clean(markdown.markdown(signature_md), tags=bleach.ALLOWED_TAGS + ['p', 'br']))
htmlctx['signature'] = signature_md
body_plain += signature
body_plain += "\r\n\r\n-- \r\n"

body_plain += _(
"You are receiving this email because you placed an order for {event}."
).format(event=event.name)
Expand Down
4 changes: 4 additions & 0 deletions src/pretix/base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
'default': settings.MAIL_FROM,
'type': str
},
'mail_text_signature': {
'type': LazyI18nString,
'default': ""
},
'mail_text_resend_link': {
'type': LazyI18nString,
'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,
Expand Down
12 changes: 12 additions & 0 deletions src/pretix/base/templates/pretixbase/email/plainwrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ <h1><a href="{{ site_url }}" target="_blank">{{ site }}</a></h1>
</td>
</tr>
{% endif %}
{% if signature %}
<tr>
<td class="gap"></td>
</tr>
<tr>
<td class="order containertd">
<div class="content">
{{ signature | safe }}
</div>
</td>
</tr>
{% endif %}
<tr>
<td class="footer">
<div>
Expand Down
9 changes: 9 additions & 0 deletions src/pretix/control/forms/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,15 @@ class MailSettingsForm(SettingsForm):
label=_("Sender address"),
help_text=_("Sender address for outgoing emails")
)

mail_text_signature = I18nFormField(
label=_("Signature"),
required=False,
widget=I18nTextarea,
help_text=_("This will be attached to every email. Available placeholders: {event}"),
validators=[PlaceholderValidator(['{event}'])]
)

mail_text_order_placed = I18nFormField(
label=_("Text"),
required=False,
Expand Down
1 change: 1 addition & 0 deletions src/pretix/control/templates/pretixcontrol/event/mail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<legend>{% trans "E-mail settings" %}</legend>
{% bootstrap_field form.mail_prefix layout="horizontal" %}
{% bootstrap_field form.mail_from layout="horizontal" %}
{% bootstrap_field form.mail_text_signature layout="horizontal" %}
</fieldset>
<fieldset>
<legend>{% trans "E-mail content" %}</legend>
Expand Down
12 changes: 12 additions & 0 deletions src/tests/base/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_send_mail_with_event_sender(env):
assert djmail.outbox[0].from_email == 'foo@bar'


@pytest.mark.django_db
def test_send_mail_with_event_signature(env):
djmail.outbox = []
event, user, organizer = env
event.settings.set('mail_text_signature', 'This is a test signature.')
mail('dummy@dummy.dummy', 'Test subject', 'mailtest.txt', {}, event)

assert len(djmail.outbox) == 1
assert djmail.outbox[0].to == [user.email]
assert 'This is a test signature.' in djmail.outbox[0].body


@pytest.mark.django_db
def test_send_mail_with_default_sender(env):
djmail.outbox = []
Expand Down