summaryrefslogtreecommitdiff
path: root/Mailman/Utils.py
diff options
context:
space:
mode:
authorbwarsaw1998-12-30 21:05:27 +0000
committerbwarsaw1998-12-30 21:05:27 +0000
commitb4998da60873f7aba6023f6c458eb10ff50a8d10 (patch)
tree5c42cdd2a08dc50271ed1fe29cd82daba90123f4 /Mailman/Utils.py
parent6fabfd51a780bf7a8b015cacd727c6c6a9addd18 (diff)
downloadmailman-b4998da60873f7aba6023f6c458eb10ff50a8d10.tar.gz
mailman-b4998da60873f7aba6023f6c458eb10ff50a8d10.tar.zst
mailman-b4998da60873f7aba6023f6c458eb10ff50a8d10.zip
Diffstat (limited to 'Mailman/Utils.py')
-rw-r--r--Mailman/Utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index a26861191..2eeb0247f 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -228,6 +228,7 @@ def TrySMTPDelivery(recipient, sender, text, queue_entry):
def QuotePeriods(text):
return string.join(string.split(text, '\n.\n'), '\n .\n')
+
def ValidEmail(str):
"""Verify that the an email address isn't grossly invalid."""
# Pretty minimal, cheesy check. We could do better...
@@ -248,6 +249,47 @@ def ValidEmail(str):
return 1
+# User J. Person <person@allusers.com>
+_addrcre1 = re.compile('<(.*)>')
+# person@allusers.com (User J. Person)
+_addrcre2 = re.compile('([^(]*)\s(.*)')
+
+def ParseAddrs(addresses):
+ """Parse common types of email addresses:
+
+ User J. Person <person@allusers.com>
+ person@allusers.com (User J. Person)
+
+ TBD: I wish we could use rfc822.parseaddr() but 1) the interface is not
+ convenient, and 2) it doesn't work for the second type of address.
+
+ Argument is a list of addresses, return value is a list of the parsed
+ email addresses. The argument can also be a single string, in which case
+ the return value is a single string.
+
+ """
+ single = 0
+ if type(addresses) == type(''):
+ single = 1
+ addrs = [addresses]
+ else:
+ addrs = addresses
+ parsed = []
+ for a in addrs:
+ mo = _addrcre1.search(a)
+ if mo:
+ parsed.append(mo.group(1))
+ continue
+ mo = _addrcre2.search(a)
+ if mo:
+ parsed.append(mo.group(1))
+ continue
+ parsed.append(a)
+ if single:
+ return parsed[0]
+ return parsed
+
+
def GetPathPieces(path):
l = string.split(path, '/')
try: