calibre-smtp: Fix filter mode operation and handle multiple to addresses separated by commas

This commit is contained in:
Kovid Goyal 2012-10-07 12:35:55 +05:30
parent a84bdaebeb
commit 1882c36a71

View File

@ -211,23 +211,25 @@ def main(args=sys.argv):
msg = compose_mail(args[1], args[2], args[3], subject=opts.subject, msg = compose_mail(args[1], args[2], args[3], subject=opts.subject,
attachment=opts.attachment) attachment=opts.attachment)
from_, to = args[1:3] from_, to = args[1:3]
efrom, eto = map(extract_email_address, (from_, to)) eto = [extract_email_address(x.strip()) for x in to.split(',')]
eto = [eto] efrom = extract_email_address(from_)
else: else:
msg = sys.stdin.read() msg = sys.stdin.read()
from email.parser import Parser from email import message_from_string
from email.utils import getaddresses from email.utils import getaddresses
eml = Parser.parsestr(msg, headersonly=True) eml = message_from_string(msg)
tos = eml.get_all('to', []) tos = eml.get_all('to', [])
ccs = eml.get_all('cc', []) ccs = eml.get_all('cc', []) + eml.get_all('bcc', [])
eto = getaddresses(tos + ccs) all_tos = []
for x in tos + ccs:
all_tos.extend(y.strip() for y in x.split(','))
eto = list(map(extract_email_address, all_tos))
if not eto: if not eto:
raise ValueError('Email from STDIN does not specify any recipients') raise ValueError('Email from STDIN does not specify any recipients')
efrom = getaddresses(eml.get_all('from', [])) efrom = getaddresses(eml.get_all('from', []))
if not efrom: if not efrom:
raise ValueError('Email from STDIN does not specify a sender') raise ValueError('Email from STDIN does not specify a sender')
efrom = efrom[0] efrom = efrom[0][1]
outbox = None outbox = None
if opts.outbox is not None: if opts.outbox is not None: