Work with default SMTP account
if a default SMTP account is defined, messages sent to root JID are sent with this account parameters. Otherwise, the first SMTP account is used. darcs-hash:20070605195924-86b55-5f8ab38dee873680f32b16619123d909d2ffb4b2.gz
This commit is contained in:
@@ -244,12 +244,15 @@ class RootSendMailMessageHandler(SendMailMessageHandler):
|
||||
def filter(self, message, lang_class):
|
||||
name = message.get_to().node
|
||||
bare_from_jid = unicode(message.get_from().bare())
|
||||
accounts = Account.select(\
|
||||
AND(Account.q.name == name,
|
||||
Account.q.user_jid == bare_from_jid))
|
||||
accounts = SMTPAccount.select(\
|
||||
AND(SMTPAccount.q.default_account == True,
|
||||
SMTPAccount.q.user_jid == bare_from_jid))
|
||||
if accounts.count() != 1:
|
||||
self.__logger.error("Account " + name + " for user " + \
|
||||
bare_from_jid + " must be uniq")
|
||||
self.__logger.error("No default account found for user " +
|
||||
str(bare_from_jid))
|
||||
if accounts.count() == 0:
|
||||
accounts = SMTPAccount.select(\
|
||||
SMTPAccount.q.user_jid == bare_from_jid)
|
||||
return accounts
|
||||
|
||||
def handle(self, message, lang_class, accounts):
|
||||
|
||||
@@ -568,6 +568,7 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
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")
|
||||
@@ -578,6 +579,22 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
self.assertEquals(accounts.count(), 1)
|
||||
del account.hub.threadConnection
|
||||
|
||||
def test_filter_no_default_account(self):
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account12 = SMTPAccount(user_jid="user1@test.com",
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
message = Message(from_jid="user1@test.com",
|
||||
to_jid="account11@jcl.test.com",
|
||||
body="message")
|
||||
accounts = self.handler.filter(message, None)
|
||||
self.assertEquals(accounts.count(), 2)
|
||||
self.assertEquals(accounts[0].name, "account11")
|
||||
del account.hub.threadConnection
|
||||
|
||||
def test_filter_wrong_dest(self):
|
||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||
account11 = SMTPAccount(user_jid="user1@test.com",
|
||||
@@ -590,7 +607,7 @@ class RootSendMailMessageHandler_TestCase(unittest.TestCase):
|
||||
to_jid="user2%test.com@jcl.test.com",
|
||||
body="message")
|
||||
accounts = self.handler.filter(message, None)
|
||||
self.assertEquals(accounts.count(), 0)
|
||||
self.assertEquals(accounts.count(), 2)
|
||||
del account.hub.threadConnection
|
||||
|
||||
def test_filter_wrong_user(self):
|
||||
|
||||
@@ -578,8 +578,7 @@ class SMTPAccount(Account):
|
||||
real_class = cls
|
||||
return Account.get_register_fields(real_class) + \
|
||||
[("login", "text-single", None,
|
||||
lambda field_value, default_func: \
|
||||
account.mandatory_field(field_value),
|
||||
account.default_post_func,
|
||||
lambda : ""),
|
||||
("password", "text-private", None, password_post_func,
|
||||
lambda : ""),
|
||||
@@ -599,7 +598,10 @@ class SMTPAccount(Account):
|
||||
lambda : ""),
|
||||
("store_password", "boolean", None,
|
||||
account.default_post_func,
|
||||
lambda : True)]
|
||||
lambda : True),
|
||||
("default_account", "boolean", None,
|
||||
account.default_post_func,
|
||||
lambda : False)]
|
||||
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ class IMAPAccount_TestCase(unittest.TestCase):
|
||||
class SMTPAccount_TestCase(Account_TestCase):
|
||||
def test_get_register_fields(self):
|
||||
register_fields = SMTPAccount.get_register_fields()
|
||||
self.assertEquals(len(register_fields), 7)
|
||||
self.assertEquals(len(register_fields), 8)
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
|
||||
Reference in New Issue
Block a user