where = line.index(search_item) message = line[ (where+ len(search_item)+1): -1] match = re.search("orig_to=<(.*?)>", line) if match: orig_to = match.group(1) if args.stdout: print(to_who) print(orig_to) bounce = bounces[to_who] bounce.key = escape(to_who) bounce.count += 1 bounce.messages.append(escape(message)) email = Email(domain) email.add_to('*****@*****.**') email.make_subject("Bounces") email.define_sender('DragonNet Admin <*****@*****.**>') html = "<html>" for bounce in bounces: ns = NS(bounces[bounce]) ns.messages = "<br />".join(ns.messages) ns.BR = '<br />' html += ns('<p>Email{COLON}{SPACE}{key}{SPACE} ' \ 'How many bounces{COLON}{SPACE}{count}{BR}<i>{messages}</i></p>') html+= "</html>" email.define_content(html) if not args.no_emails: email.send() if args.stdout: print(email.htmls['en'])