Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7732 closed defect (fixed)

Message-ID is not unique in 0.11 branch

Reported by: anonymous Owned by: Robert Corsaro
Priority: highest Component: AnnouncerPlugin
Severity: blocker Keywords:
Cc: Trac Release: 0.11


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?

---	2010-09-23 14:11:32.671304338 -0400
+++	2010-09-23 14:12:18.435317776 -0400
@@ -20,7 +20,7 @@
     from email.header import Header
     from email.Header import Header
-import time, Queue, threading, smtplib
+import time, Queue, threading, smtplib, random
 class DeliveryThread(threading.Thread):
     def __init__(self, queue, sender):
@@ -282,11 +282,13 @@
             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':
             rootMessage['In-Reply-To'] = msgid

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by Robert Corsaro

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 8 years ago by Robert Corsaro

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

comment:3 Changed 8 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 8 years ago by Robert Corsaro

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

comment:5 Changed 8 years ago by Robert Corsaro

Resolution: fixed
Status: newclosed

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 8 years ago by Robert Corsaro

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
Set your email in Preferences
as closed The owner will remain Robert Corsaro.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.