Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> email.utils.getaddresses(['[email protected], John Smith <[email protected]>,"Smith, Jane" <[email protected]>'])
- [('', '[email protected]'), ('John Smith', '[email protected]'), ('Smith, Jane', '[email protected]')]
- from email.utils import getaddresses
- addrstring = ',[email protected], John Smith <[email protected]>,"Smith, Jane" <[email protected]>,'
- def addrparser(addrstring):
- addrlist = ['']
- quoted = False
- # ignore comma at beginning or end
- addrstring = addrstring.strip(',')
- for char in addrstring:
- if char == '"':
- # toggle quoted mode
- quoted = not quoted
- addrlist[-1] += char
- # a comma outside of quotes means a new address
- elif char == ',' and not quoted:
- addrlist.append('')
- # anything else is the next letter of the current address
- else:
- addrlist[-1] += char
- return getaddresses(addrlist)
- print addrparser(addrstring)
- [('', '[email protected]'), ('John Smith', '[email protected]'),
- ('Smith, Jane', '[email protected]')]
Advertisement
Add Comment
Please, Sign In to add comment