Commits

Mike Bayer  committed 864af4e

add extra logic to parse out direct email addresses in changeset authors

  • Participants
  • Parent commits 2ef0612

Comments (0)

Files changed (1)

File tracvatar/web_ui.py

 from pkg_resources import resource_filename
 import itertools
 import hashlib
+import re
 
 class AvatarModule(Component):
     implements(ITemplateStreamFilter, ITemplateProvider)
         return Transformer('//div[@id="content"]/dl/dt/a/span[@class="time"]').\
                             filter(find_change)
 
+    # from trac source
+    _long_author_re = re.compile(r'.*<([^@]+)@([^@]+)>\s*|([^@]+)@([^@]+)')
+
     def _lookup_email(self, author_data):
         if not author_data:
             return
-        authors = sorted(author_data)
+
+        lookup_authors = sorted([a for a in author_data if '@' not in a])
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         cursor.execute(
             "select sid, value from session_attribute where name=%%s and sid in (%s)" % (
-                ",".join(["%s" for author in authors])
-            ), ("email",) + tuple(authors)
+                ",".join(["%s" for author in lookup_authors])
+            ), ("email",) + tuple(lookup_authors)
         )
         for sid, email in cursor.fetchall():
             author_data[sid] = hashlib.md5(email.lower()).hexdigest()
+
+        for author in set(author_data).difference(lookup_authors):
+            author_info = self._long_author_re.match(author)
+            if author_info:
+                if author_info.group(1):
+                    name, host = author_info.group(1, 2)
+                elif author_info.group(3):
+                    name, host = author_info.group(3, 4)
+                else:
+                    continue
+                author_data[name] = \
+                    author_data[author] = \
+                    hashlib.md5(("%s@%s" % (name, host)).lower()).hexdigest()