Skip to content

Commit

Permalink
Allow bounce header/footer to be strings
Browse files Browse the repository at this point in the history
  • Loading branch information
icgood committed Jan 31, 2016
1 parent d12a3d4 commit 5cf416d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions slimta/bounce.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,18 @@ def __init__(self, envelope, reply, headers_only=False):
def _check_custom_templates(cls):
if cls.header_template != default_header_template and \
not isinstance(cls.header_template, BytesFormat):
fix_crlf = re.sub(br'\r?\n', br'\r\n', cls.header_template)
cls.header_template = BytesFormat(fix_crlf, mode='remove')
template_str = cls.header_template
if not isinstance(template_str, bytes):
template_str = template_str.encode('ascii')
template_str = re.sub(br'\r?\n', br'\r\n', template_str)
cls.header_template = BytesFormat(template_str, mode='remove')
if cls.footer_template != default_footer_template and \
not isinstance(cls.footer_template, BytesFormat):
fix_crlf = re.sub(br'\r?\n', br'\r\n', cls.footer_template)
cls.footer_template = BytesFormat(fix_crlf, mode='remove')
template_str = cls.footer_template
if not isinstance(template_str, bytes):
template_str = template_str.encode('ascii')
template_str = re.sub(br'\r?\n', br'\r\n', template_str)
cls.footer_template = BytesFormat(template_str, mode='remove')

def _get_substitution_table(self, envelope, reply, headers_only):
rendered_rcpts = self.recipient_join.join(envelope.recipients)
Expand Down
8 changes: 4 additions & 4 deletions test/test_slimta_bounce.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def test_bounce(self):
""")
reply = Reply('550', '5.0.0 Rejected')

Bounce.header_template = b"""\
Bounce.header_template = """\
X-Reply-Code: {code}
X-Reply-Message: {message}
X-Orig-Sender: {sender}
"""
Bounce.footer_template = b"""\
Bounce.footer_template = """\
EOM
"""
Expand Down Expand Up @@ -58,13 +58,13 @@ def test_bounce_headersonly(self):
""")
reply = Reply('550', '5.0.0 Rejected')

Bounce.header_template = b"""\
Bounce.header_template = """\
X-Reply-Code: {code}
X-Reply-Message: {message}
X-Orig-Sender: {sender}
"""
Bounce.footer_template = b"""\
Bounce.footer_template = """\
EOM
"""
Expand Down

0 comments on commit 5cf416d

Please sign in to comment.