Make flat messageview redirect to md5 of messageid
authorMagnus Hagander <magnus@hagander.net>
Wed, 20 Jun 2018 14:31:36 +0000 (16:31 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 20 Jun 2018 14:31:36 +0000 (16:31 +0200)
Redirecting to the full messageid pollutes the URL pretty badly. md5 is
not the best of hashes, but the likelihood of getting an md5 collission
on the messageid *within a single thread* is extremely low -- and of
course if it happens the only effect is on the initial scroll of the
window.

django/archives/mailarchives/templates/message_flat.html
django/archives/mailarchives/templatetags/pgfilters.py

index c72496faff6e520849dc9bc7f6e0f804970eed46..fd3c53046c1137e095f8df3f23f96d3cf0ac9381 100644 (file)
@@ -1,4 +1,5 @@
 {%extends "page.html"%}
+{%load pgfilters%}
 {%block title%}{%if not msg.hiddenstatus%}{{msg.subject}}{%endif%}{%endblock%}
 {%load pgfilters%}
 {%block extrahead%}
@@ -7,7 +8,7 @@
 <script type="text/javascript">
 function load() {
    if (document.location.href.indexOf('#') < 0) {
-      document.location.href = document.location.href + '#' + '{{msg.messageid}}';
+      document.location.href = document.location.href + '#' + '{{msg.messageid|md5}}';
    }
 }
 window.onload = load;
@@ -26,6 +27,7 @@ window.onload = load;
 {%endif%}
 {%for m in allmsg %}
 <a name="{{m.messageid}}"></a>
+<a name="{{m.messageid|md5}}"></a>
 {% include '_message.html' with msg=m show_all=True %}
 {% if not forloop.last %}
   <hr style="margin-bottom: 0.5rem;" />
index 6dd68a9aa33d8bb8d24f553753064e461990fcf1..4f85e804283cfd3e02e9ada3ebff3a43e2d0bef6 100644 (file)
@@ -3,6 +3,7 @@ from django import template
 from email.utils import parseaddr
 
 import re
+import hashlib
 
 register = template.Library()
 
@@ -43,3 +44,8 @@ def nameonly(value):
        if name:
                return name
        return email.split('@')[0]
+
+@register.filter(name='md5')
+@stringfilter
+def md5(value):
+       return hashlib.md5(value).hexdigest()