git » el » commit fcf3971

Improve Message-Id generation

author Alberto Bertogli
2010-05-10 03:57:29 UTC
committer Alberto Bertogli
2010-05-10 03:57:29 UTC
parent fc8628bb408cfbab0e46a815c570925b037fc04c

Improve Message-Id generation

The current message-id generation code uses the $USER environment variable,
which is not available when run under cron.

This patch changes it to a more general, user-agnostic one, which should be
simple but effective.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

el +3 -2

diff --git a/el b/el
index 9607231..15ef8cb 100755
--- a/el
+++ b/el
@@ -188,6 +188,7 @@ def send_events(evts):
 	import email
 	import email.mime.text
 	import socket
+	import random
 
 	if not config.has_option('email', 'to'):
 		print "Error: destination email needed, check config file"
@@ -229,8 +230,8 @@ def send_events(evts):
 	e['To'] = config.get("email", "to")
 	if config.has_option("email", "from"):
 		e['From'] = config.get("email", "from")
-	e['Message-Id'] = "<%s.%s.%f@%s>" % (os.environ['USER'], today,
-			time.time(), socket.gethostname())
+	e['Message-Id'] = "<%f.%d.%d@%s>" % (time.time(), os.getpid(),
+			int(random.random() * 100000), socket.gethostname())
 	e['X-Sender'] = "el"
 	e.set_payload(body, 'utf8')