John Hampton wrote:
Kilian CAVALOTTI wrote:
from_str = self.to_unicode(msg['from'])
+ # if space in from_str, extract real mail address
+ if ' ' in from_str:
+ import re
+ email_re =
re.compile(r"([\w\d_\.\-])+\@(([\w\d\-])+\.)+([\w\d]{2,4})+")
+ mo = email_re.search(from_str)
+ if mo:
+ from_str = mo.group(0)
+email_re
What about something like this (warning, untested):
from email.Utils import parseaddr
from_str = self.to_unicode(parseaddr(msg['from'])[1])
Don't want to knock regex or anything, but seems like it's a little
bit more straightforward.
Oh yes, that's better I think. I took the regexp from
http://projects.edgewall.com/trac/browser/sandbox/notification/trac/tests/notification.py
and I wasn't aware of those email.Utils functions, but well, why would we
reinvent the wheel?
Btw, I like what you've done.
Thanks ;)
--
Kilian CAVALOTTI Administrateur réseaux et systèmes
Université P&M Curie - LIP6 (C870)
8, rue du Capitaine Scott Tel. : 01 44 27 88 54
75015 Paris - FRANCE Fax. : 01 44 27 70 00
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac