        msg=EmailMessage(policy=policy.SMTP);msg['Subject']=str(output.get('subject',''));msg['From']='demo@example.invalid';msg['To']='recipient@example.invalid';msg.set_content(str(output.get('plain','')));msg.add_alternative(str(output.get('html','')),subtype='html');(f/'draft.eml').write_bytes(msg.as_bytes());parsed=BytesParser(policy=policy.default).parsebytes((f/'draft.eml').read_bytes());plain=parsed.get_body(preferencelist=('plain',)).get_content();ht=parsed.get_body(preferencelist=('html',)).get_content();facts=case['input'];ck('原生MIME确有两个alternative部分',parsed.get_content_type()=='multipart/alternative' and len(list(parsed.iter_parts()))==2)
        for key in ['date','fee','url']:ck('两版共同事实 '+key,str(facts[key]) in plain and str(facts[key]) in ht)
        ck('HTML无script或事件属性',not re.search(r'<\s*script|\bon\w+\s*=',ht,re.I));(f/'mail-preview.html').write_text('<meta charset="utf-8"><h1>'+html.escape(str(parsed['Subject']))+'</h1>'+ht);result={'content_type':parsed.get_content_type(),'plain':plain,'html':ht,'sent':False};art+=['draft.eml','mail-preview.html']
