diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2013-12-01 17:39:53 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-12-01 17:39:53 +0000 |
commit | c04c3052add9aeb0b84d8b9a7c6200ecc2752d07 (patch) | |
tree | 63811ba3fa01e0b289e502cf2633f0b43b7f20da | |
parent | 8dfa339cb436dacfb11413dd278449b417e116e1 (diff) |
add mailto-helper
-rw-r--r-- | alot/db/utils.py | 2 | ||||
-rw-r--r-- | alot/helper.py | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py index cfca8c4b..40b743b9 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -336,7 +336,7 @@ def decode_header(header, normalize=False): decode a header value to a unicode string values are usually a mixture of different substrings - encoded in quoted printable using diffetrent encodings. + encoded in quoted printable using different encodings. This turns it into a single unicode string :param header: the header value diff --git a/alot/helper.py b/alot/helper.py index 95f1c32e..e0c126aa 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -550,3 +550,33 @@ def parse_mailcap_nametemplate(tmplate='%s'): else: template_suffix = tmplate return (template_prefix, template_suffix) + + +def mailto(mailto_str): + """ + Interpret mailto-string + :param mailto_str: the string to interpret. Must conform to :rfc:2368. + :return: pair headers,body. headers is a dict mapping str to lists of str, + body is a str. + :rtype: (dict(str-->[str,..], str) + """ + import urllib + mtrexp = r'mailto:(.*?)[\?\&]([\w\&\=]*)' + M = re.search(mtrexp, mailto_str) + if M is not None: + to = urllib.unquote(M.group(1)) + parms = M.group(2).split('&') + + parms = dict(s.split('=') for s in parms) + + body = u'' + headers = {} + headers['To'] = [to] + for k, v in parms.items(): + if k is 'body': + body = urllib.unquote(parms.get('body', u'')) + else: + headers[k] = [urllib.unquote(v)] + return (headers, body) + else: + return (None, None) |