From d35854851c68ffb5d944952c14efe4a19bfc7cd6 Mon Sep 17 00:00:00 2001 From: zPlus Date: Fri, 29 Jul 2022 14:08:45 +0200 Subject: [PATCH] Add support for tags in mailing lists threads. --- static/css/clif.css | 17 ++++++++------ templates/mailing_list/emails_thread.html | 6 +++++ web.py | 28 ++++++++++++++++++++--- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/static/css/clif.css b/static/css/clif.css index 1713087..dadeb6a 100644 --- a/static/css/clif.css +++ b/static/css/clif.css @@ -231,25 +231,23 @@ div.threads { } .thread .message { - border-radius: .1rem; - margin-bottom: 1rem; } - .thread .message:not(:last-child) { - border-bottom: 1px solid #d0d0d0; + .thread .message:not(:first-child) { + border-top: 1px solid #d0d0d0; + margin-top: 2rem; + padding: 2rem 0rem 0rem 0rem; } .thread .message > .header { font-size: .9rem; - padding: 1rem; } .thread .message > .header > details > .headers { - margin-top: 1rem; } .thread .message > .body { - padding: 1rem; + padding: .5rem 1rem 0 1rem; white-space: pre-wrap; } @@ -257,6 +255,11 @@ div.threads { flex: 30%; padding: 1rem; } + + .thread .info .tag { + margin-bottom: 1rem; + } + /* Alternate background color used when displaying table data */ .striped > *:nth-child(even) { diff --git a/templates/mailing_list/emails_thread.html b/templates/mailing_list/emails_thread.html index 4af90c8..babeb7d 100644 --- a/templates/mailing_list/emails_thread.html +++ b/templates/mailing_list/emails_thread.html @@ -40,6 +40,12 @@
+ {% for tag in tags %} +
+ {{ tag }}: {{ tags[tag]|join(', ') }} +
+ {% endfor %} +
{{ participants|length }} participants {% for address in participants %} diff --git a/web.py b/web.py index 771b355..ed063da 100644 --- a/web.py +++ b/web.py @@ -81,6 +81,21 @@ def list_repositories(): repositories.sort() return repositories +def parse_thread_tags(data): + """ + Parse "tags" file of a mailing list thread. + """ + + tags = {} + + for line in data.splitlines(): + k, v = line.split('=', 1) + k = k.strip() + v = v.strip() + tags[k] = tags.get(k, []) + [ v ] + + return tags + @@ -641,10 +656,17 @@ def thread(repository, thread_id): # displaying purposes only) emails = [] participants = [] + tags = {} for obj in thread_tree: - if obj.type != pygit2.GIT_OBJ_BLOB \ - or not obj.name.endswith('.email'): + if obj.type != pygit2.GIT_OBJ_BLOB: + continue + + if obj.name == 'tags': + tags = parse_thread_tags(obj.data.decode('UTF-8')) + continue + + if not obj.name.endswith('.email'): continue message = email.message_from_string(obj.data.decode('UTF-8'), policy=email.policy.default) @@ -669,5 +691,5 @@ def thread(repository, thread_id): emails.sort(key = lambda email: email['received_at']) return template('mailing_list/emails_thread.html', thread=thread_data, emails=emails, - participants=participants, list_address=list_address, + participants=participants, list_address=list_address, tags=tags, repository=repository)