@@ -320,13 +320,16 @@ def testSendMessageWithAddresses(self):
320320 # XXX (see comment in testSend)
321321 time .sleep (0.01 )
322322 smtp .quit ()
323+ # make sure the Bcc header is still in the message.
324+ self .assertEqual (m ['Bcc' ], 'John Root <root@localhost>, "Dinsdale" '
325+ 323326
324327 self .client_evt .set ()
325328 self .serv_evt .wait ()
326329 self .output .flush ()
327330 # Add the X-Peer header that DebuggingServer adds
328331 m ['X-Peer' ] = socket .gethostbyname ('localhost' )
329- # The Bcc header is deleted before serialization .
332+ # The Bcc header should not be transmitted .
330333 del m ['Bcc' ]
331334 mexpect = '%s%s\n %s' % (MSG_BEGIN , m .as_string (), MSG_END )
332335 self .assertEqual (self .output .getvalue (), mexpect )
@@ -365,6 +368,112 @@ def testSendMessageWithSomeAddresses(self):
365368 re .MULTILINE )
366369 self .assertRegex (debugout , to_addr )
367370
371+ def testSendMessageWithSpecifiedAddresses (self ):
372+ # Make sure addresses specified in call override those in message.
373+ m = email .mime .text .MIMEText ('A test message' )
374+ 375+ m ['To' ] = 'John, Dinsdale'
376+ smtp = smtplib .SMTP (HOST , self .port , local_hostname = 'localhost' , timeout = 3 )
377+ smtp .
send_message (
m ,
from_addr = '[email protected] ' ,
to_addrs = '[email protected] ' )
378+ # XXX (see comment in testSend)
379+ time .sleep (0.01 )
380+ smtp .quit ()
381+
382+ self .client_evt .set ()
383+ self .serv_evt .wait ()
384+ self .output .flush ()
385+ # Add the X-Peer header that DebuggingServer adds
386+ m ['X-Peer' ] = socket .gethostbyname ('localhost' )
387+ mexpect = '%s%s\n %s' % (MSG_BEGIN , m .as_string (), MSG_END )
388+ self .assertEqual (self .output .getvalue (), mexpect )
389+ debugout = smtpd .DEBUGSTREAM .getvalue ()
390+ sender = re .
compile (
"^sender: [email protected] $" ,
re .
MULTILINE )
391+ self .assertRegex (debugout , sender )
392+ for addr in ('John' , 'Dinsdale' ):
393+ to_addr = re .compile (r"^recips: .*'{}'.*$" .format (addr ),
394+ re .MULTILINE )
395+ self .assertNotRegex (debugout , to_addr )
396+ recip = re .
compile (
r"^recips: .*'[email protected] '.*$" ,
re .
MULTILINE )
397+ self .assertRegex (debugout , recip )
398+
399+ def testSendMessageWithMultipleFrom (self ):
400+ # Sender overrides To
401+ m = email .mime .text .MIMEText ('A test message' )
402+ m ['From' ] = 'Bernard, Bianca'
403+ 404+ m ['To' ] = 'John, Dinsdale'
405+ smtp = smtplib .SMTP (HOST , self .port , local_hostname = 'localhost' , timeout = 3 )
406+ smtp .send_message (m )
407+ # XXX (see comment in testSend)
408+ time .sleep (0.01 )
409+ smtp .quit ()
410+
411+ self .client_evt .set ()
412+ self .serv_evt .wait ()
413+ self .output .flush ()
414+ # Add the X-Peer header that DebuggingServer adds
415+ m ['X-Peer' ] = socket .gethostbyname ('localhost' )
416+ mexpect = '%s%s\n %s' % (MSG_BEGIN , m .as_string (), MSG_END )
417+ self .assertEqual (self .output .getvalue (), mexpect )
418+ debugout = smtpd .DEBUGSTREAM .getvalue ()
419+ sender = re .
compile (
"^sender: [email protected] $" ,
re .
MULTILINE )
420+ self .assertRegex (debugout , sender )
421+ for addr in ('John' , 'Dinsdale' ):
422+ to_addr = re .compile (r"^recips: .*'{}'.*$" .format (addr ),
423+ re .MULTILINE )
424+ self .assertRegex (debugout , to_addr )
425+
426+ def testSendMessageResent (self ):
427+ m = email .mime .text .MIMEText ('A test message' )
428+ 429+ m ['To' ] = 'John'
430+ m ['CC' ] = 'Sally, Fred'
431+ m [
'Bcc' ]
= 'John Root <root@localhost>, "Dinsdale" <[email protected] >' 432+ m ['Resent-Date' ] = 'Thu, 1 Jan 1970 17:42:00 +0000'
433+ m [
'Resent-From' ]
= '[email protected] ' 434+ m [
'Resent-To' ]
= 'Martha <[email protected] >, Jeff' 435+ m [
'Resent-Bcc' ]
= '[email protected] ' 436+ smtp = smtplib .SMTP (HOST , self .port , local_hostname = 'localhost' , timeout = 3 )
437+ smtp .send_message (m )
438+ # XXX (see comment in testSend)
439+ time .sleep (0.01 )
440+ smtp .quit ()
441+
442+ self .client_evt .set ()
443+ self .serv_evt .wait ()
444+ self .output .flush ()
445+ # The Resent-Bcc headers are deleted before serialization.
446+ del m ['Bcc' ]
447+ del m ['Resent-Bcc' ]
448+ # Add the X-Peer header that DebuggingServer adds
449+ m ['X-Peer' ] = socket .gethostbyname ('localhost' )
450+ mexpect = '%s%s\n %s' % (MSG_BEGIN , m .as_string (), MSG_END )
451+ self .assertEqual (self .output .getvalue (), mexpect )
452+ debugout = smtpd .DEBUGSTREAM .getvalue ()
453+ sender = re .
compile (
"^sender: [email protected] $" ,
re .
MULTILINE )
454+ self .assertRegex (debugout , sender )
455+ 456+ to_addr = re .compile (r"^recips: .*'{}'.*$" .format (addr ),
457+ re .MULTILINE )
458+ self .assertRegex (debugout , to_addr )
459+
460+ def testSendMessageMultipleResentRaises (self ):
461+ m = email .mime .text .MIMEText ('A test message' )
462+ 463+ m ['To' ] = 'John'
464+ m ['CC' ] = 'Sally, Fred'
465+ m [
'Bcc' ]
= 'John Root <root@localhost>, "Dinsdale" <[email protected] >' 466+ m ['Resent-Date' ] = 'Thu, 1 Jan 1970 17:42:00 +0000'
467+ m [
'Resent-From' ]
= '[email protected] ' 468+ m [
'Resent-To' ]
= 'Martha <[email protected] >, Jeff' 469+ m [
'Resent-Bcc' ]
= '[email protected] ' 470+ m ['Resent-Date' ] = 'Thu, 2 Jan 1970 17:42:00 +0000'
471+ m [
'Resent-To' ]
= '[email protected] ' 472+ m [
'Resent-From' ]
= 'Martha <[email protected] >, Jeff' 473+ smtp = smtplib .SMTP (HOST , self .port , local_hostname = 'localhost' , timeout = 3 )
474+ with self .assertRaises (ValueError ):
475+ smtp .send_message (m )
476+ smtp .close ()
368477
369478class NonConnectingTests (unittest .TestCase ):
370479
0 commit comments