Skip to content

Commit 8a42f3e

Browse files
author
jomae
committed
1.2.2dev: fix a regression of #12658, ticket notification not sending for authenticated users without email (closes #12759)
git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.2-stable@15757 af82e41b-90c4-0310-8c96-b1721e28e2e2
1 parent 0009c30 commit 8a42f3e

File tree

2 files changed

+47
-38
lines changed

2 files changed

+47
-38
lines changed

trac/notification/mail.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def smtp_default_domain(self):
204204
return self.notify_sys.smtp_default_domain
205205

206206
def match_recipient(self, address):
207-
if not address:
207+
if not address or address == 'anonymous':
208208
return None
209209

210210
def is_email(address):
@@ -215,19 +215,17 @@ def is_email(address):
215215
return False
216216
return True
217217

218-
if address == 'anonymous':
219-
return None
220-
sid = None
221-
auth = 0
222218
if address in self.users:
223219
sid = address
224220
auth = 1
225-
address = self.users[address][1]
226-
if not address:
227-
return sid, auth, None
228-
elif not is_email(address) and self.nodomaddr_re.match(address):
221+
address = (self.users[address][1] or '').strip() or sid
222+
else:
223+
sid = None
224+
auth = 0
225+
226+
if not is_email(address) and self.nodomaddr_re.match(address):
229227
if self.use_short_addr:
230-
return None, 0, address
228+
return sid, auth, address
231229
if self.smtp_default_domain:
232230
address = "%s@%s" % (address, self.smtp_default_domain)
233231
else:

trac/ticket/tests/notification.py

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -395,71 +395,82 @@ def run_bcc_feature(public_cc):
395395

396396
def test_short_login(self):
397397
"""Email addresses without a FQDN"""
398-
def _test_short_login(enabled):
398+
def _test_short_login(use_short_addr, username, address):
399399
config_subscriber(self.env, reporter=True)
400400
ticket = Ticket(self.env)
401-
ticket['reporter'] = 'joeuser'
401+
ticket['reporter'] = username
402402
ticket['summary'] = 'This is a summary'
403403
ticket.insert()
404404
# Be sure that at least one email address is valid, so that we
405405
# send a notification even if other addresses are not valid
406406
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')
409410
notify_ticket_created(self.env, ticket)
410411
message = notifysuite.smtpd.get_message()
412+
recipients = set(notifysuite.smtpd.get_recipients())
411413
headers, body = parse_smtp_message(message)
412414
# Msg should always have a 'To' field
413415
self.assertEqual('undisclosed-recipients: ;', headers['To'])
414416
# Msg should have a 'Cc' field
415417
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:
418420
# 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)
420425
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+
426430
# 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')
429437

430438
def test_default_domain(self):
431439
"""Default domain name"""
432-
def _test_default_domain(enabled):
440+
def _test_default_domain(enable):
433441
config_subscriber(self.env)
434442
self.env.config.set('notification', 'smtp_always_cc', '')
435443
ticket = Ticket(self.env)
436-
ticket['cc'] = 'joenodom, [email protected]'
444+
ticket['cc'] = 'joenodom, foo, bar, qux, [email protected]'
437445
ticket['summary'] = 'This is a summary'
438446
ticket.insert()
439447
# Be sure that at least one email address is valid, so that we
440448
# send a notification even if other addresses are not valid
441449
self.env.config.set('notification', 'smtp_always_cc',
442450
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 '')
446453
notify_ticket_created(self.env, ticket)
447454
message = notifysuite.smtpd.get_message()
448455
headers, body = parse_smtp_message(message)
449456
# Msg should always have a 'Cc' field
450457
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+
'[email protected]']), cclist)
457466
else:
458-
self.assertEqual(2, len(cclist))
459-
self.assertNotIn('joenodom', cclist)
467+
self.assertEqual(set(['[email protected]',
468+
'[email protected]']), cclist)
460469

461470
# 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):
463474
_test_default_domain(enable)
464475

465476
def test_email_map(self):

0 commit comments

Comments
 (0)