filter root component JID in MailHandler

darcs-hash:20070605194240-86b55-3eac72f253c5b012c713dcc38812452d1d870111.gz
This commit is contained in:
David Rousselie
2007-06-05 21:42:40 +02:00
parent 9a4fb057dd
commit 383370fa22
2 changed files with 18 additions and 1 deletions

View File

@@ -199,7 +199,8 @@ class MailHandler(Handler):
def filter(self, stanza, lang_class): def filter(self, stanza, lang_class):
"""Return empty array if JID match '.*%.*@componentJID'""" """Return empty array if JID match '.*%.*@componentJID'"""
if self.dest_jid_regexp.match(stanza.get_to().node): node = stanza.get_to().node
if node is not None and self.dest_jid_regexp.match(node):
bare_from_jid = unicode(stanza.get_from().bare()) bare_from_jid = unicode(stanza.get_from().bare())
accounts = Account.select(Account.q.user_jid == bare_from_jid) accounts = Account.select(Account.q.user_jid == bare_from_jid)
if accounts.count() == 0: if accounts.count() == 0:

View File

@@ -692,6 +692,22 @@ class MailHandler_TestCase(unittest.TestCase):
self.assertEquals(accounts[0].name, "account11") self.assertEquals(accounts[0].name, "account11")
del account.hub.threadConnection del account.hub.threadConnection
def test_filter_root(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
account11 = SMTPAccount(user_jid="user1@test.com",
name="account11",
jid="account11@jcl.test.com")
account11.default_account = True
account12 = SMTPAccount(user_jid="user1@test.com",
name="account12",
jid="account12@jcl.test.com")
message = Message(from_jid="user1@test.com",
to_jid="jcl.test.com",
body="message")
accounts = self.handler.filter(message, None)
self.assertEquals(accounts, None)
del account.hub.threadConnection
def test_filter_no_default(self): def test_filter_no_default(self):
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
account11 = SMTPAccount(user_jid = "user1@test.com", \ account11 = SMTPAccount(user_jid = "user1@test.com", \