From 1882c36a719dececfc2cf5425e108d9543477fb2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Oct 2012 12:35:55 +0530 Subject: [PATCH] calibre-smtp: Fix filter mode operation and handle multiple to addresses separated by commas --- src/calibre/utils/smtp.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index e496975507..e15afbd56d 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -211,23 +211,25 @@ def main(args=sys.argv): msg = compose_mail(args[1], args[2], args[3], subject=opts.subject, attachment=opts.attachment) from_, to = args[1:3] - efrom, eto = map(extract_email_address, (from_, to)) - eto = [eto] + eto = [extract_email_address(x.strip()) for x in to.split(',')] + efrom = extract_email_address(from_) else: msg = sys.stdin.read() - from email.parser import Parser + from email import message_from_string from email.utils import getaddresses - eml = Parser.parsestr(msg, headersonly=True) + eml = message_from_string(msg) tos = eml.get_all('to', []) - ccs = eml.get_all('cc', []) - eto = getaddresses(tos + ccs) + ccs = eml.get_all('cc', []) + eml.get_all('bcc', []) + 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: raise ValueError('Email from STDIN does not specify any recipients') efrom = getaddresses(eml.get_all('from', [])) if not efrom: raise ValueError('Email from STDIN does not specify a sender') - efrom = efrom[0] - + efrom = efrom[0][1] outbox = None if opts.outbox is not None: