aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2023-05-04 17:18:44 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2023-05-04 17:18:44 -0400
commit488ae833ac6b7a74b0f0279dc158dff914505d5d (patch)
tree62e963dffbd0bebe3cb3bb5aba3143135df01334
parent730baca36a8f6506ee002732f1b1dd5e7929945c (diff)
downloadpeebz-488ae833ac6b7a74b0f0279dc158dff914505d5d.tar.gz
Make date increment in threads
When we convert a bug with pre-existing comments into a mail thread, we send all messages with the same Date: header, which may cause things to render out of order. Increment the Date: header by a second for each comment count, to help sort them correctly. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--peebz/bz2pi.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/peebz/bz2pi.py b/peebz/bz2pi.py
index 0559d53..77eea1f 100644
--- a/peebz/bz2pi.py
+++ b/peebz/bz2pi.py
@@ -6,10 +6,12 @@
import argparse
import peebz
import datetime
+import time
import re
import b4
import email.message
+import email.utils
from fnmatch import fnmatch
@@ -19,6 +21,7 @@ logger = peebz.logger
def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = False):
config = peebz.get_config()
cdatas = peebz.bz_get_newest_comments_for_bid(bid)
+ msgts = int(time.time())
for cdata in cdatas:
# Check if we've already notified about this bug
cid = cdata['id']
@@ -88,6 +91,11 @@ def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = F
msg = email.message.EmailMessage()
if not privacy_mode:
msg['Reply-To'] = b4.format_addrs([('', cdata['creator'])])
+ # A little hack to make sure Date: is consecutive for threads
+ try:
+ msg['Date'] = email.utils.formatdate(msgts + int(cdata['count']), localtime=True)
+ except ValueError:
+ pass
body = bodytpt.safe_substitute(bodyvals)
body = peebz.add_bot_signature(body)
msg.set_payload(body, charset='utf-8')