Opened 3 years ago

Closed 3 years ago

# Message-ID is not unique in 0.11 branch

Reported by: Owned by: anonymous doki_pen highest AnnouncerPlugin blocker 0.11

### Description

Message-ID is not unique in 0.11 branch because it uses to_timestamp(modtime) but modtime will always be "None" resulting in to_timestamp(modtime) to always equal "0".

This is a problem because my email server (and I assume other email servers) will refuse to deliver a message that has the same Message-ID as a previously delivered message. That means we were receiving email for new tickets but any changes to the tickets were using duplicate Message-ID's and so the corresponding email notifications were not being delivered.

I looked at TRUNK where the problem is fixed and made a patch for 0.11.

I kind of wonder if there is any need in the first place to be creating your own Message_ID's. Why not just let the email server handle that for you?

--- email_distributor.py	2010-09-23 14:11:32.671304338 -0400
+++ email_distributor.py	2010-09-23 14:12:18.435317776 -0400
@@ -20,7 +20,7 @@
except:
+import time, Queue, threading, smtplib, random

def __init__(self, queue, sender):
@@ -282,11 +282,13 @@
else:
raise TracError(_('Invalid email encoding setting: %s'%pref))

-    def _message_id(self, realm, id, modtime=None):
+    def _message_id(self, realm):
"""Generate a predictable, but sufficiently unique message ID."""
-        s = '%s.%s.%d.%s' % (self.env.project_url,
-                               id, to_timestamp(modtime),
-                               realm.encode('ascii', 'ignore'))
+        modtime = time.time()
+        rand = random.randint(0,32000)
+        s = '%s.%d.%d.%s' % (self.env.project_url,
+                          modtime, rand,
+                          realm.encode('ascii', 'ignore'))
dig = md5(s).hexdigest()
host = self.smtp_from[self.smtp_from.find('@') + 1:]
msgid = '<%03d.%s@%s>' % (len(s), dig, host)
@@ -325,7 +327,7 @@
rootMessage['X-Trac-Project'] = proj_name
rootMessage['X-Trac-Announcement-Realm'] = event.realm
rootMessage['X-Trac-Announcement-ID'] = self._event_id(event)
-        msgid = self._message_id(event.realm, self._event_id(event))
+        msgid = self._message_id(event.realm)
rootMessage['Message-ID'] = msgid
if event.category is not 'created':


### comment:1 Changed 3 years ago by doki_pen

Check out the threading email decorator. I needed a way to synthesize the message ID. Other then that, I'm not sure. When I took over the code it already was setting Message-ID, I merely fixed it. I believe Trac notification does the same. If you want to wrap it in an if and make a configuration point, I'd except the patch.

### comment:2 Changed 3 years ago by doki_pen

Oh, I'll except this patch too, just give me a day.

### comment:3 Changed 3 years ago by anonymous

Thanks, that was a quick response. I don't have any need or interest in adding the configuration point. I am almost positive that branch 0.11 didn't have the Message-ID until that last revision. But my guess is Message-ID had been in trunk since before you took over and someone (hasienda) finally backported it to 0.11.

I'm pretty sure Trac notifications doesn't create Message-ID's.

I could be wrong.

Thanks for accepting my patch though.

### comment:4 Changed 3 years ago by doki_pen

It's always possible that I don't remember things properly. ;-)

### comment:5 Changed 3 years ago by doki_pen

• Resolution set to fixed
• Status changed from new to closed

I applied your patch and I added a switch for Message-ID. My smtp server doesn't create Message-ID if none is provided. I'm using postfix, but maybe it's not configured too? Anyway, the switch is there if you want it.

### comment:6 Changed 3 years ago by doki_pen

Upon thinking about this more, the downside of this approach is that it breaks threading in the client. In order to generate headers and associate emails with each other, there must be a predictable way to generate message-id. Using random and system time make this impossible.

It's ok, because we have the ThreadingEmailDecorator to override this message id when enabled.

### Modify Ticket

Change Properties