1.1 --- a/imiptools/data.py Tue Sep 29 13:50:30 2015 +0200
1.2 +++ b/imiptools/data.py Tue Sep 29 14:04:57 2015 +0200
1.3 @@ -706,18 +706,30 @@
1.4 # Conversion functions.
1.5
1.6 def get_addresses(values):
1.7 +
1.8 + """
1.9 + Return only addresses from the given 'values' which may be of the form
1.10 + "Common Name <recipient@domain>", with the latter part being the address
1.11 + itself.
1.12 + """
1.13 +
1.14 return [address for name, address in email.utils.getaddresses(values)]
1.15
1.16 def get_address(value):
1.17 +
1.18 + "Return an e-mail address from the given 'value'."
1.19 +
1.20 if not value: return None
1.21 - value = value.lower()
1.22 - return value.startswith("mailto:") and value[7:] or value
1.23 + return get_addresses([value.startswith("mailto:") and value[7:] or value])[0]
1.24
1.25 def get_uri(value):
1.26 +
1.27 + "Return a URI for the given 'value'."
1.28 +
1.29 if not value: return None
1.30 - return value.lower().startswith("mailto:") and value.lower() or \
1.31 + return value.lower().startswith("mailto:") and ("mailto:%s" % value[7:]) or \
1.32 ":" in value and value or \
1.33 - "mailto:%s" % value.lower()
1.34 + "mailto:%s" % get_address(value)
1.35
1.36 uri_value = get_uri
1.37