diff options
-rw-r--r-- | hyperkitty/static/css/style.css | 4 | ||||
-rw-r--r-- | hyperkitty/templates/messages/message.html | 9 | ||||
-rw-r--r-- | hyperkitty/templates/thread.html | 6 | ||||
-rw-r--r-- | hyperkitty/templatetags/hk_generic.py | 34 | ||||
-rw-r--r-- | hyperkitty/tests/__init__.py | 1 | ||||
-rw-r--r-- | hyperkitty/tests/test_templatetags.py | 64 |
6 files changed, 108 insertions, 10 deletions
diff --git a/hyperkitty/static/css/style.css b/hyperkitty/static/css/style.css index 3a7803d..f68125e 100644 --- a/hyperkitty/static/css/style.css +++ b/hyperkitty/static/css/style.css @@ -697,3 +697,7 @@ ul.attachments-list li { margin-top: 5px; } +.email_body .quoted-text { + display: none; +} + diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html index 0dd93a8..d235813 100644 --- a/hyperkitty/templates/messages/message.html +++ b/hyperkitty/templates/messages/message.html @@ -29,13 +29,8 @@ </div> </div> -{% if unfolded %} -<div class="first_email_body"> -{% else %} -<div class="email_body"> -{% endif %} -{{email.content|urlizetrunc:76|escapeemail}} -</div> +<div class="{% if unfolded %}first_{% endif %}email_body" + >{{ email.content|urlizetrunc:76|escapeemail|snip_quoted }}</div> {% if unfolded and email.attachments|count %} <p class="attachments">Attachments:</p> diff --git a/hyperkitty/templates/thread.html b/hyperkitty/templates/thread.html index 20dc8c6..9e1333f 100644 --- a/hyperkitty/templates/thread.html +++ b/hyperkitty/templates/thread.html @@ -44,9 +44,9 @@ <script src="{{ STATIC_URL }}js/libs/jquery.expander.js"></script> <script type="text/javascript"> $(document).ready(function() { - $('div.email_body').expander({ - userCollapseText : 'View Less', - expandText : 'View More' + $('div.email_body a.quoted-switch').click(function() { + $(this).next(".quoted-text").toggle(); + return false; }); }); </script> diff --git a/hyperkitty/templatetags/hk_generic.py b/hyperkitty/templatetags/hk_generic.py index bfe234c..18d397f 100644 --- a/hyperkitty/templatetags/hk_generic.py +++ b/hyperkitty/templatetags/hk_generic.py @@ -5,6 +5,8 @@ from dateutil.tz import tzutc, tzoffset from django import template from django.utils.datastructures import SortedDict from django.templatetags.tz import localtime +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe register = template.Library() @@ -114,3 +116,35 @@ def sender_date(email): def viewer_date(email): email_date = email.date.replace(tzinfo=tzutc()) return localtime(email_date) + + +SNIPPED_RE = re.compile("^\s*>.*$", re.M) +@register.filter(needs_autoescape=True) +def snip_quoted(content, quotemsg="[...]", autoescape=None): + """Snip quoted text in messages""" + if autoescape: + content = conditional_escape(content) + quoted = [] + current_quote = [] + quoting = False + lastline = None + for line in content.split("\n"): + if SNIPPED_RE.match(line): + quoting = True + if lastline == "": + current_quote.append(lastline) + else: + quoting = False + if current_quote: + quoted.append(current_quote[:]) + current_quote = [] + if quoting: + current_quote.append(line) + lastline = line + for quote in quoted: + replaced = ('<a href="#" class="quoted-switch">%s</a>' % quotemsg + +'<span class="quoted-text">\n' + +"\n".join([q for q in quote if q != ""]) + +'</span>') + content = content.replace("\n".join(quote), replaced) + return mark_safe(content) diff --git a/hyperkitty/tests/__init__.py b/hyperkitty/tests/__init__.py index bf3e6b6..f3ee25f 100644 --- a/hyperkitty/tests/__init__.py +++ b/hyperkitty/tests/__init__.py @@ -22,3 +22,4 @@ from hyperkitty.tests.test_views import * from hyperkitty.tests.test_models import * from hyperkitty.tests.test_forms import * +from hyperkitty.tests.test_templatetags import * diff --git a/hyperkitty/tests/test_templatetags.py b/hyperkitty/tests/test_templatetags.py new file mode 100644 index 0000000..1275b25 --- /dev/null +++ b/hyperkitty/tests/test_templatetags.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of HyperKitty. +# +# HyperKitty is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# HyperKitty is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# HyperKitty. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Aurelien Bompard <abompard@fedoraproject.org> +# + +from django.test import TestCase + +from hyperkitty.templatetags.hk_generic import snip_quoted + +class SnipQuotedTestCase(TestCase): + + quotemsg = "[SNIP]" + + def test_quote_1(self): + contents = """ +On Fri, 09.11.12 11:27, Someone wrote: +> This is the first quoted line +> This is the second quoted line +This is the response. +""" + expected = """ +On Fri, 09.11.12 11:27, Someone wrote: +<a href="#" class="quoted-switch">%s</a><span class="quoted-text"> +> This is the first quoted line +> This is the second quoted line</span> +This is the response. +""" % self.quotemsg + result = snip_quoted(contents, self.quotemsg) + self.assertEqual(result, expected) + + def test_quote_2(self): + """The quote starts with a newline""" + contents = """ +On Fri, 09.11.12 11:27, Someone wrote: + +> This is the first quoted line +> This is the second quoted line +This is the response. +""" + expected = """ +On Fri, 09.11.12 11:27, Someone wrote: +<a href="#" class="quoted-switch">%s</a><span class="quoted-text"> +> This is the first quoted line +> This is the second quoted line</span> +This is the response. +""" % self.quotemsg + result = snip_quoted(contents, self.quotemsg) + self.assertEqual(result, expected) |