def test_sending_raw_mime(patch_smtp, api_client): api_client.post_raw('/send', ('From: [email protected]\r\n' 'To: golang-nuts ' '<*****@*****.**>\r\n' 'Cc: [email protected]\r\n' 'Bcc: Some Guy <*****@*****.**>\r\n' 'Subject: ' '[go-nuts] Runtime Panic On Method Call' '\r\n' 'Mime-Version: 1.0\r\n' 'In-Reply-To: ' '<78pgxboai332pi9p2smo4db73-0' '@mailer.nylas.com>\r\n' 'References: ' '<78pgxboai332pi9p2smo4db73-0' '@mailer.nylas.com>\r\n' 'Content-Type: text/plain; charset=UTF-8' '\r\n' 'Content-Transfer-Encoding: 7bit\r\n' 'X-My-Custom-Header: Random\r\n\r\n' 'Yo.'), headers={'Content-Type': 'message/rfc822'}) _, msg = patch_smtp[-1] parsed = mime.from_string(msg) assert parsed.body == 'Yo.' assert parsed.headers['From'] == '*****@*****.**' assert parsed.headers['Subject'] == \ '[go-nuts] Runtime Panic On Method Call' assert parsed.headers['Cc'] == '*****@*****.**' assert parsed.headers['To'] == \ 'golang-nuts <*****@*****.**>' assert parsed.headers['In-Reply-To'] == \ '<*****@*****.**>' assert parsed.headers['References'] == \ '<*****@*****.**>' assert parsed.headers['X-My-Custom-Header'] == 'Random' assert 'Bcc' not in parsed.headers assert 'X-INBOX-ID' in parsed.headers assert 'Message-Id' in parsed.headers assert 'User-Agent' in parsed.headers
def test_sending_bad_raw_mime(patch_smtp, api_client): res = api_client.post_raw('/send', ('From: [email protected]\r\n' 'To: \r\n' 'Subject: ' '[go-nuts] Runtime Panic On Method' 'Call \r\n' 'Mime-Version: 1.0\r\n' 'Content-Type: ' 'text/plain; charset=UTF-8\r\n' 'Content-Transfer-Encoding: 7bit\r\n' 'X-My-Custom-Header: Random' '\r\n\r\n' 'Yo.'), headers={'Content-Type': 'message/rfc822'}) assert res.status_code == 400