Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dax/jmc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/jmc
diff options
context:
space:
mode:
authorDavid Rousselie <dax@happycoders.org>2007-06-05 23:59:24 +0400
committerDavid Rousselie <dax@happycoders.org>2007-06-05 23:59:24 +0400
commitb69b55e1b1abfa6c22ce01ac035893eb664f670c (patch)
treee052e33f34f7affb3408ff12a173204a34cc7b22 /src/jmc
parent76c1d6968b37db177505ab7d8943313b7ac9d78a (diff)
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
Diffstat (limited to 'src/jmc')
-rw-r--r--src/jmc/jabber/component.py13
-rw-r--r--src/jmc/jabber/tests/component.py19
-rw-r--r--src/jmc/model/account.py8
-rw-r--r--src/jmc/model/tests/account.py2
4 files changed, 32 insertions, 10 deletions
diff --git a/src/jmc/jabber/component.py b/src/jmc/jabber/component.py
index 678dbdf..d5a33da 100644
--- a/src/jmc/jabber/component.py
+++ b/src/jmc/jabber/component.py
@@ -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):
diff --git a/src/jmc/jabber/tests/component.py b/src/jmc/jabber/tests/component.py
index 24aef04..3717b2b 100644
--- a/src/jmc/jabber/tests/component.py
+++ b/src/jmc/jabber/tests/component.py
@@ -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):
diff --git a/src/jmc/model/account.py b/src/jmc/model/account.py
index 6235556..682ecff 100644
--- a/src/jmc/model/account.py
+++ b/src/jmc/model/account.py
@@ -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)
diff --git a/src/jmc/model/tests/account.py b/src/jmc/model/tests/account.py
index fa5e96c..99aa526 100644
--- a/src/jmc/model/tests/account.py
+++ b/src/jmc/model/tests/account.py
@@ -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()