Skip to content

Commit 17bd46c

Browse files
author
Johannes Gijsbers
committed
mailgw now accepts registration confirmation mail that uses otk
For example, the following could be in the subject line: .-- key <32-char otk, such as Aj4euk4LZSAdwePohj90SME5SpopLETL>.
1 parent 1a07c30 commit 17bd46c

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

roundup/mailgw.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.127 2003-09-05 20:56:39 jlgijsbers Exp $
76+
$Id: mailgw.py,v 1.128 2003-09-06 10:21:18 jlgijsbers Exp $
7777
"""
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -514,9 +514,15 @@ def handle_message(self, message):
514514
# get the classname
515515
classname = m.group('classname')
516516
if classname is None:
517-
# no classname, fallback on the default
518-
if hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \
519-
self.instance.config.MAIL_DEFAULT_CLASS:
517+
# no classname, check if this a registration confirmation email
518+
# or fallback on the default class
519+
otk_re = re.compile('-- key (?P<otk>[a-zA-Z0-9]{32})')
520+
otk = otk_re.search(m.group('title')).group('otk')
521+
if otk:
522+
self.db.confirm_registration(otk)
523+
return
524+
elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \
525+
self.instance.config.MAIL_DEFAULT_CLASS:
520526
classname = self.instance.config.MAIL_DEFAULT_CLASS
521527
else:
522528
# fail

test/test_mailgw.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.46 2003-05-06 21:49:20 kedder Exp $
11+
# $Id: test_mailgw.py,v 1.47 2003-09-06 10:21:03 jlgijsbers Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
1414
import rfc822
@@ -959,9 +959,30 @@ def testRFC2822(self):
959959
self.assertEqual(rfc2822.encode_header(ascii_header), ascii_header)
960960
self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
961961

962+
def testRegistrationConfirmation(self):
963+
otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
964+
self.db.otks.set(otk, username='johannes', __time='')
965+
message = cStringIO.StringIO('''Content-Type: text/plain;
966+
charset="iso-8859-1"
967+
From: Chef <[email protected]>
968+
969+
Cc: richard@test
970+
Message-Id: <dummy_test_message_id>
971+
Subject: Re: Complete your registration to Roundup issue tracker
972+
-- key %s
973+
974+
This is a test confirmation of registration.
975+
''' % otk)
976+
handler = self.instance.MailGW(self.instance, self.db)
977+
handler.trapExceptions = 0
978+
handler.main(message)
979+
980+
self.db.user.lookup('johannes')
981+
962982
def suite():
963983
l = [unittest.makeSuite(MailgwTestCase),
964984
]
985+
l = [MailgwTestCase("testRegistrationConfirmation")]
965986
return unittest.TestSuite(l)
966987

967988

0 commit comments

Comments
 (0)