from textwrap import TextWrapper

BODY_FOOTER_SEPERATOR = "\n\n--\n"

def email_wrapper(text):
    wrapper = TextWrapper()
    wrapper.subsequent_indent = '> '
    wrapper.initial_indent = '> '
    return "\n".join(wrapper.wrap(text))


def normalize_msg_id(msg_id):
    if msg_id[0] == '<':
        msg_id = msg_id[1:]
    if msg_id[-1] == '>':
        msg_id = msg_id[:-1]
    return msg_id

def is_spam_check(email_object):
    return email_object['X-Spam-Flag'] == 'YES'

def get_body_with_footer(body, footer):
    if footer.strip():
        return "{}{}{}".format(body, BODY_FOOTER_SEPERATOR, footer)
    return body

@@ -25,16 +25,45 @@
 tWrapper
+%0Afrom django.utils import six
 %0A%0ABODY_F
@@ -92,16 +92,17 @@
 n--%5Cn%22%0A%0A
+%0A
 def emai
@@ -417,16 +417,17 @@
 msg_id%0A%0A
+%0A
 def is_s
@@ -500,16 +500,17 @@
  'YES'%0A%0A
+%0A
 def get_
@@ -583,16 +583,30 @@
 urn 
+six.text_type(
 %22%7B%7D%7B%7D%7B%7D%22
 .for
@@ -601,16 +601,17 @@
 %22%7B%7D%7B%7D%7B%7D%22
+)
 .format(

Fix encoding in reply footer