diff --git a/requirements.txt b/requirements.txt
index f10a9e1..af774f4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
-#https://www.djangoproject.com/download/1.6b4/tarball/
-Django==1.5.2
+https://www.djangoproject.com/download/1.6b4/tarball/
+#Django==1.5.2
South==0.8.1
psycopg2==2.5.1
django-piston==0.2.3
@@ -8,6 +8,7 @@ chardet==1.0.1
python-dateutil==1.5
django-cliauth==0.9
django-mobile==0.3.0
+html2text
gunicorn
gevent
diff --git a/src/super_archives/templates/message-thread.html b/src/super_archives/templates/message-thread.html
index 22f375f..085ff81 100644
--- a/src/super_archives/templates/message-thread.html
+++ b/src/super_archives/templates/message-thread.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load i18n append_to_get gravatar %}
+{% load i18n append_to_get gravatar superarchives %}
{% trans "Anonymous" as anonymous %}
@@ -149,7 +149,7 @@
-
{{ email.body }}
+ {% display_message email emails %}
diff --git a/src/super_archives/templates/superarchives/tags/display_message.html b/src/super_archives/templates/superarchives/tags/display_message.html
new file mode 100644
index 0000000..29957bf
--- /dev/null
+++ b/src/super_archives/templates/superarchives/tags/display_message.html
@@ -0,0 +1,5 @@
+{% for message, class in messages %}
+ {% if class == 'reply' %}
+ ...
+ {% else %}{% endif %}{{ message }}
+{% endfor %}
diff --git a/src/super_archives/templatetags/superarchives.py b/src/super_archives/templatetags/superarchives.py
new file mode 100644
index 0000000..76c20d4
--- /dev/null
+++ b/src/super_archives/templatetags/superarchives.py
@@ -0,0 +1,71 @@
+
+import re
+
+from django import template
+
+from html2text import html2text
+
+
+register = template.Library()
+TEMPLATE_PATH = 'superarchives/tags/'
+
+
+EXTENDED_PUNCTUATION = '!"#$%&\'()*+,-./:;=?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
+RE_WRAPPED_BY_HTML = re.compile(r'^<[a-z]+[^>]*>.*[a-z]+[^>]*>$',
+ re.MULTILINE|re.IGNORECASE|re.DOTALL)
+
+
+def join(block):
+ block_txt = u''.join(block)
+
+ if RE_WRAPPED_BY_HTML.match(block_txt.strip()):
+ return html2text(block_txt)
+
+ return block_txt
+
+def is_reply(line, message, thread):
+ clean_line = line.strip()
+ if clean_line.startswith('>'):
+ return True
+
+ for other_msg in thread:
+ if other_msg == message:
+ return False
+
+ clean_body = other_msg.body.replace('\r', ' ')\
+ .replace('\n', ' ')
+ if clean_line.strip('> ') in clean_body:
+ return True
+
+ return False
+
+
+@register.inclusion_tag(TEMPLATE_PATH + 'display_message.html',
+ takes_context=False)
+def display_message(email, thread):
+ message = email.body
+ messages = []
+
+ block = []
+ reply_block = False
+
+ for line in message.split('\n'):
+ if line.strip(EXTENDED_PUNCTUATION):
+ if is_reply(line, email, thread):
+ if not reply_block:
+ reply_block = True
+ messages.append((join(block), 'normal'))
+ block = []
+ elif reply_block:
+ reply_block = False
+ messages.append((join(block), 'reply'))
+ block = []
+
+ block.append(line.rstrip() + '\n')
+
+ if reply_block:
+ messages.append((join(block), 'reply'))
+ else:
+ messages.append((join(block), 'normal'))
+
+ return {'messages': messages}
--
libgit2 0.21.2