@@ -395,71 +395,82 @@ def run_bcc_feature(public_cc):
395
395
396
396
def test_short_login (self ):
397
397
"""Email addresses without a FQDN"""
398
- def _test_short_login (enabled ):
398
+ def _test_short_login (use_short_addr , username , address ):
399
399
config_subscriber (self .env , reporter = True )
400
400
ticket = Ticket (self .env )
401
- ticket ['reporter' ] = 'joeuser'
401
+ ticket ['reporter' ] = username
402
402
ticket ['summary' ] = 'This is a summary'
403
403
ticket .insert ()
404
404
# Be sure that at least one email address is valid, so that we
405
405
# send a notification even if other addresses are not valid
406
406
self .env .config .set ('notification' , 'smtp_always_cc' ,
407
-
408
- self .env .config .set ('notification' , 'use_short_addr' , enabled )
407
+
408
+ self .env .config .set ('notification' , 'use_short_addr' ,
409
+ 'enabled' if use_short_addr else 'disabled' )
409
410
notify_ticket_created (self .env , ticket )
410
411
message = notifysuite .smtpd .get_message ()
412
+ recipients = set (notifysuite .smtpd .get_recipients ())
411
413
headers , body = parse_smtp_message (message )
412
414
# Msg should always have a 'To' field
413
415
self .assertEqual ('undisclosed-recipients: ;' , headers ['To' ])
414
416
# Msg should have a 'Cc' field
415
417
self .assertIn ('Cc' , headers )
416
- cclist = [ addr .strip () for addr in headers ['Cc' ].split (',' )]
417
- if enabled :
418
+ cclist = set ( addr .strip () for addr in headers ['Cc' ].split (',' ))
419
+ if use_short_addr :
418
420
# Msg should be delivered to the reporter
419
- self .assertIn (ticket ['reporter' ], cclist )
421
+ self .
assertEqual (
set ([
address ,
'[email protected] ' ,
422
+ 'john' ]), cclist )
423
+ self .
assertEqual (
set ([
address ,
'[email protected] ' ,
424
+ 'john' ]), recipients )
420
425
else :
421
- # Msg should not be delivered to joeuser
422
- self .assertNotIn (ticket ['reporter' ], cclist )
423
- # Msg should still be delivered to the always_cc list
424
- self .assertIn (self .env .config .get ('notification' ,
425
- 'smtp_always_cc' ), cclist )
426
+ # Msg should not be delivered to the reporter
427
+ self .
assertEqual (
set ([
'[email protected] ' ]),
cclist )
428
+ self .
assertEqual (
set ([
'[email protected] ' ]),
recipients )
429
+
426
430
# Validate with and without the short addr option enabled
427
- for enable in False , True :
428
- _test_short_login (enable )
431
+ self .env .insert_users ([('bar' , 'Bar User' , '' ),
432
+ ('qux' , 'Qux User' , 'qux-mail' )])
433
+ for use_short_addr in (False , True ):
434
+ _test_short_login (use_short_addr , 'foo' , 'foo' )
435
+ _test_short_login (use_short_addr , 'bar' , 'bar' )
436
+ _test_short_login (use_short_addr , 'qux' , 'qux-mail' )
429
437
430
438
def test_default_domain (self ):
431
439
"""Default domain name"""
432
- def _test_default_domain (enabled ):
440
+ def _test_default_domain (enable ):
433
441
config_subscriber (self .env )
434
442
self .env .config .set ('notification' , 'smtp_always_cc' , '' )
435
443
ticket = Ticket (self .env )
436
- ticket [
'cc' ]
= 'joenodom, [email protected] '
444
+ ticket [
'cc' ]
= 'joenodom, foo, bar, qux, [email protected] '
437
445
ticket ['summary' ] = 'This is a summary'
438
446
ticket .insert ()
439
447
# Be sure that at least one email address is valid, so that we
440
448
# send a notification even if other addresses are not valid
441
449
self .env .config .set ('notification' , 'smtp_always_cc' ,
442
450
443
- if enabled :
444
- self .env .config .set ('notification' , 'smtp_default_domain' ,
445
- 'example.org' )
451
+ self .env .config .set ('notification' , 'smtp_default_domain' ,
452
+ 'example.org' if enable else '' )
446
453
notify_ticket_created (self .env , ticket )
447
454
message = notifysuite .smtpd .get_message ()
448
455
headers , body = parse_smtp_message (message )
449
456
# Msg should always have a 'Cc' field
450
457
self .assertIn ('Cc' , headers )
451
- cclist = [addr .strip () for addr in headers ['Cc' ].split (',' )]
452
- self .
assertIn (
'[email protected] ' ,
cclist )
453
- self .
assertIn (
'[email protected] ' ,
cclist )
454
- if enabled :
455
- self .assertEqual (3 , len (cclist ))
456
- self .
assertIn (
'[email protected] ' ,
cclist )
458
+ cclist = set (addr .strip () for addr in headers ['Cc' ].split (',' ))
459
+ if enable :
460
+ self .
assertEqual (
set ([
'[email protected] ' ,
461
+
462
+
463
+
464
+
465
+
457
466
else :
458
- self .assertEqual (2 , len ( cclist ))
459
- self . assertNotIn ( 'joenodom' , cclist )
467
+ self .
assertEqual (
set ([ '[email protected] ' ,
468
+
460
469
461
470
# Validate with and without a default domain
462
- for enable in False , True :
471
+ self .env .insert_users ([('bar' , 'Bar User' , '' ),
472
+ ('qux' , 'Qux User' , 'qux-mail' )])
473
+ for enable in (False , True ):
463
474
_test_default_domain (enable )
464
475
465
476
def test_email_map (self ):
0 commit comments