def make_make_email_data(to, cc=None, bcc=None, subject=None, body=None):
"""\
Creates either a simple "mailto:" URL or complete e-mail message with
(blind) carbon copies and a subject and a body.
:param str|iterable to: The email address (recipient). Multiple
values are allowed.
:param str|iterable|None cc: The carbon copy recipient. Multiple
values are allowed.
:param str|iterable|None bcc: The blind carbon copy recipient.
Multiple values are allowed.
:param str|None subject: The subject.
:param str|None body: The message body.
"""
def multi(val):
if not val:
return ()
if isinstance(val, str_type):
return (val,)
return tuple(val)
delim = '?'
data = ['mailto:']
if not to:
raise ValueError('"to" must not be empty or None')
data.append(','.join(multi(to)))
for key, val in (('cc', cc), ('bcc', bcc)):
vals = multi(val)
if vals:
data.append('{0}{1}={2}'.format(delim, key, ','.join(vals)))
delim = '&'
for key, val in (('subject', subject), ('body', body)):
if val is not None:
data.append('{0}{1}={2}'.format(delim, key, quote(val.encode('utf-8'))))
delim = '&'
return ''.join(data)
评论列表
文章目录