Add MailCommandManager as default CommandManager with MailComponent
darcs-hash:20071030065654-86b55-f9a304b8dc5d26c94ffe466d70baa2cbc32b0436.gz
This commit is contained in:
@@ -48,6 +48,7 @@ from jmc.jabber.presence import MailSubscribeHandler, \
|
|||||||
from jmc.model.account import MailAccount, IMAPAccount, POP3Account, \
|
from jmc.model.account import MailAccount, IMAPAccount, POP3Account, \
|
||||||
SMTPAccount
|
SMTPAccount
|
||||||
from jmc.lang import Lang
|
from jmc.lang import Lang
|
||||||
|
from jmc.jabber.command import MailCommandManager
|
||||||
|
|
||||||
class MailAccountManager(AccountManager):
|
class MailAccountManager(AccountManager):
|
||||||
def account_get_register(self, info_query,
|
def account_get_register(self, info_query,
|
||||||
@@ -109,7 +110,8 @@ class MailComponent(FeederComponent):
|
|||||||
config,
|
config,
|
||||||
config_file,
|
config_file,
|
||||||
lang=Lang(),
|
lang=Lang(),
|
||||||
account_manager_class=MailAccountManager):
|
account_manager_class=MailAccountManager,
|
||||||
|
command_manager_class=MailCommandManager):
|
||||||
"""Use FeederComponent behavior and setup feeder and sender
|
"""Use FeederComponent behavior and setup feeder and sender
|
||||||
attributes.
|
attributes.
|
||||||
"""
|
"""
|
||||||
@@ -121,7 +123,8 @@ class MailComponent(FeederComponent):
|
|||||||
config,
|
config,
|
||||||
config_file,
|
config_file,
|
||||||
lang=lang,
|
lang=lang,
|
||||||
account_manager_class=account_manager_class)
|
account_manager_class=account_manager_class,
|
||||||
|
command_manager_class=command_manager_class)
|
||||||
self.handler = MailFeederHandler(MailFeeder(self), MailSender(self))
|
self.handler = MailFeederHandler(MailFeeder(self), MailSender(self))
|
||||||
self.account_manager.account_classes = (IMAPAccount,
|
self.account_manager.account_classes = (IMAPAccount,
|
||||||
POP3Account,
|
POP3Account,
|
||||||
@@ -142,10 +145,6 @@ class MailComponent(FeederComponent):
|
|||||||
jabber.replace_handlers(self.disco_get_info_handlers,
|
jabber.replace_handlers(self.disco_get_info_handlers,
|
||||||
AccountDiscoGetInfoHandler,
|
AccountDiscoGetInfoHandler,
|
||||||
IMAPAccountDiscoGetInfoHandler(self))
|
IMAPAccountDiscoGetInfoHandler(self))
|
||||||
# for hg in self.disco_get_items_handlers:
|
|
||||||
# print "----"
|
|
||||||
# for h in hg:
|
|
||||||
# print str(h)
|
|
||||||
|
|
||||||
class MailFeeder(Feeder):
|
class MailFeeder(Feeder):
|
||||||
"""Email check"""
|
"""Email check"""
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from jcl.model import account
|
|||||||
from jcl.jabber.command import CommandRootDiscoGetInfoHandler
|
from jcl.jabber.command import CommandRootDiscoGetInfoHandler
|
||||||
from jcl.jabber.disco import AccountTypeDiscoGetInfoHandler, \
|
from jcl.jabber.disco import AccountTypeDiscoGetInfoHandler, \
|
||||||
AccountDiscoGetInfoHandler, DiscoHandler
|
AccountDiscoGetInfoHandler, DiscoHandler
|
||||||
|
import jcl.jabber.command as command
|
||||||
|
|
||||||
from jmc.model.account import IMAPAccount
|
from jmc.model.account import IMAPAccount
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ class IMAPAccountDiscoGetInfoHandler(AccountDiscoGetInfoHandler):
|
|||||||
lang_class,
|
lang_class,
|
||||||
node, disco_obj,
|
node, disco_obj,
|
||||||
data)
|
data)
|
||||||
|
disco_infos[0].add_feature(command.COMMAND_NS)
|
||||||
splitted_node = node.split("/")
|
splitted_node = node.split("/")
|
||||||
splitted_node_len = len(splitted_node)
|
splitted_node_len = len(splitted_node)
|
||||||
if splitted_node_len > 1 and \
|
if splitted_node_len > 1 and \
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ __revision__ = ""
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from jmc.jabber.tests import component, disco
|
from jmc.jabber.tests import component, disco, command
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(component.suite())
|
suite.addTest(component.suite())
|
||||||
suite.addTest(disco.suite())
|
suite.addTest(disco.suite())
|
||||||
|
suite.addTest(command.suite())
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -153,6 +153,10 @@ class MockIMAPAccount(MockMailAccount, IMAPAccount):
|
|||||||
return ["subdir1", "subdir2"]
|
return ["subdir1", "subdir2"]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_mail_with_attachment_list(self):
|
||||||
|
return [("1", "mail 1"),
|
||||||
|
("2", "mail 2")]
|
||||||
|
|
||||||
class MockPOP3Account(MockMailAccount, POP3Account):
|
class MockPOP3Account(MockMailAccount, POP3Account):
|
||||||
def _init(self, *args, **kw):
|
def _init(self, *args, **kw):
|
||||||
POP3Account._init(self, *args, **kw)
|
POP3Account._init(self, *args, **kw)
|
||||||
|
|||||||
@@ -22,7 +22,9 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from jmc.jabber.disco import MailRootDiscoGetInfoHandler
|
from jmc.jabber.disco import MailRootDiscoGetInfoHandler, \
|
||||||
|
IMAPAccountDiscoGetInfoHandler
|
||||||
|
from jmc.lang import Lang
|
||||||
|
|
||||||
class MockDiscoIndentity(object):
|
class MockDiscoIndentity(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -57,9 +59,24 @@ class MailRootDiscoGetInfoHandler_TestCase(unittest.TestCase):
|
|||||||
self.assertTrue(disco_infos[0].identity_is("gateway", "smtp"))
|
self.assertTrue(disco_infos[0].identity_is("gateway", "smtp"))
|
||||||
self.assertTrue(disco_infos[0].identity_is("headline", "newmail"))
|
self.assertTrue(disco_infos[0].identity_is("headline", "newmail"))
|
||||||
|
|
||||||
|
class IMAPAccountDiscoGetInfoHandler_TestCase(unittest.TestCase):
|
||||||
|
def test_handle_not_imap(self):
|
||||||
|
component = MockComponent()
|
||||||
|
component.name = "Mock component"
|
||||||
|
component.disco_identity.category = "gateway"
|
||||||
|
component.disco_identity.type = "smtp"
|
||||||
|
component.account_manager.has_multiple_account_type = True
|
||||||
|
handler = IMAPAccountDiscoGetInfoHandler(component)
|
||||||
|
# stanza, lang_class, node, disco_obj, data
|
||||||
|
disco_infos = handler.handle(None, Lang.en, "account@jmc.test.com/POP3",
|
||||||
|
None, None)
|
||||||
|
self.assertTrue(disco_infos[0].has_feature("jabber:iq:register"))
|
||||||
|
self.assertTrue(disco_infos[0].has_feature("http://jabber.org/protocol/commands"))
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(unittest.makeSuite(MailRootDiscoGetInfoHandler_TestCase, 'test'))
|
suite.addTest(unittest.makeSuite(MailRootDiscoGetInfoHandler_TestCase, 'test'))
|
||||||
|
suite.addTest(unittest.makeSuite(IMAPAccountDiscoGetInfoHandler_TestCase, 'test'))
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user