[Collab-qa-commits] r1896 - udd/udd

Andreas Tille tille at alioth.debian.org
Sat Jan 22 23:34:47 UTC 2011


Author: tille
Date: 2011-01-22 23:34:47 +0000 (Sat, 22 Jan 2011)
New Revision: 1896

Modified:
   udd/udd/aux.py
   udd/udd/upload_history_gatherer.py
Log:
Try harder to parse a reasonable e-mail address which works also for names with comma (',') inside as well as if the e-mail addres is included in '()' instead of '<>'


Modified: udd/udd/aux.py
===================================================================
--- udd/udd/aux.py	2011-01-16 19:04:35 UTC (rev 1895)
+++ udd/udd/aux.py	2011-01-22 23:34:47 UTC (rev 1896)
@@ -5,6 +5,8 @@
 import psycopg2
 from os import path
 import fcntl
+import re
+from email.Utils import parseaddr
 
 # If debug is something that evaluates to True, then print_debug actually prints something
 debug = 0
@@ -89,3 +91,13 @@
   if debug:
     sys.stdout.write(*args)
     sys.stdout.write("\n")
+
+def parse_email(str):
+  """Use email.Utils to parse name and email.  Afterwards check whether it was successful and try harder to get a reasonable address"""
+  name, email = parseaddr(str)
+  # if no '@' is detected in email but string contains a '@' anyway try harder to get a reasonable Mail address
+  if email.find('@') == -1 and str.find('@') != -1:
+    email = re.sub('^[^<]+[<\(]([.\w]+@[.\w]+)[>\)].*',                  '\\1', str)
+    name  = re.sub('^[^\w]*([^<]+[.\w\)\]]) *[<\(][.\w]+@[.\w]+[>\)].*', '\\1', str)
+    print_debug("parse_email: %s ---> %s <%s>" % (str, name, email))
+  return name, email

Modified: udd/udd/upload_history_gatherer.py
===================================================================
--- udd/udd/upload_history_gatherer.py	2011-01-16 19:04:35 UTC (rev 1895)
+++ udd/udd/upload_history_gatherer.py	2011-01-22 23:34:47 UTC (rev 1896)
@@ -7,7 +7,6 @@
 import gzip
 import psycopg2
 import sys
-import email.Utils
 import os.path
 
 def get_gatherer(config, connection, source):
@@ -83,10 +82,10 @@
         line = line.lstrip()
         # Stupid multi-line maintainer fields *grml*
         if line == '':
-          current['Changed-By_name'], current['Changed-By_email'] = email.Utils.parseaddr(current['Changed-By'])
-          current['Maintainer_name'], current['Maintainer_email'] = email.Utils.parseaddr(current['Maintainer'])
+          current['Changed-By_name'], current['Changed-By_email'] = aux.parse_email(current['Changed-By'])
+          current['Maintainer_name'], current['Maintainer_email'] = aux.parse_email(current['Maintainer'])
           if current['Signed-By'].find('@') != -1:
-            current['Signed-By_name'], current['Signed-By_email'] = email.Utils.parseaddr(current['Signed-By'])
+            current['Signed-By_name'], current['Signed-By_email'] = aux.parse_email(current['Signed-By'])
           else:
             current['Signed-By_name'] = current['Signed-By']
             current['Signed-By_email'] = ''




More information about the Collab-qa-commits mailing list