From b5b19a7a01402b9e344ffd6cee023231ce2f14fd Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 22 Oct 2012 18:24:21 +0200 Subject: [PATCH] [FIX] generate_tracking_message_id: use more randomness to avoid duplicates When several message IDs had to be generated for the same record at the same time, there was a high chance to get non-unique results. This possibly lead to data loss because some mail implementations might ignore multiple mails with the same ID (including OpenERP itself). On most operating systems the available time resolution precision is better than what we used (due to the float rounding of `%s`). Adding a bit of randomness doesn't hurt, as OpenERP will be used in increasingly distributed environments, so we now add an extra random part as well. bzr revid: odo@openerp.com-20121022162421-qr7nq8idihp5781u --- openerp/tools/misc.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index c9283a839d4..ba6ea1137d1 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -27,12 +27,11 @@ Miscellaneous tools used by OpenERP. """ from functools import wraps -import inspect import subprocess import logging import os +import random import re -import smtplib import socket import sys import threading @@ -40,13 +39,6 @@ import time import zipfile from collections import defaultdict from datetime import datetime -from email.MIMEText import MIMEText -from email.MIMEBase import MIMEBase -from email.MIMEMultipart import MIMEMultipart -from email.Header import Header -from email.Utils import formatdate, COMMASPACE -from email import Utils -from email import Encoders from itertools import islice, izip from lxml import etree from which import which @@ -363,7 +355,12 @@ def generate_tracking_message_id(res_id): Used to track the replies related to a given object thanks to the "In-Reply-To" or "References" fields that Mail User Agents will set. """ - return "<%s-openerp-%s@%s>" % (time.time(), res_id, socket.gethostname()) + try: + rnd = random.SystemRandom().random() + except NotImplementedError: + rnd = random.random() + rndstr = ("%.15f" % rnd)[2:] + return "<%.15f.%s-openerp-%s@%s>" % (time.time(), rndstr, res_id, socket.gethostname()) def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, attachments=None, message_id=None, references=None, openobject_id=False, debug=False, subtype='plain', headers=None,