Add default status message to SMTPAccount
darcs-hash:20080509162547-86b55-5704b15905df146b6195487a37412ffe78a03610.gz
This commit is contained in:
@@ -142,6 +142,10 @@ class MYPOP3_SSL(poplib.POP3_SSL):
|
|||||||
self._debugging = 0
|
self._debugging = 0
|
||||||
self.welcome = self._getresp()
|
self.welcome = self._getresp()
|
||||||
|
|
||||||
|
def _get_default_status_msg(self, lang_class):
|
||||||
|
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
||||||
|
unicode(self.port)
|
||||||
|
|
||||||
class MailAccount(PresenceAccount):
|
class MailAccount(PresenceAccount):
|
||||||
""" Wrapper to mail connection and action.
|
""" Wrapper to mail connection and action.
|
||||||
Abstract class, do not represent real mail connection type.
|
Abstract class, do not represent real mail connection type.
|
||||||
@@ -240,6 +244,8 @@ class MailAccount(PresenceAccount):
|
|||||||
|
|
||||||
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
||||||
|
|
||||||
|
get_default_status_msg = _get_default_status_msg
|
||||||
|
|
||||||
def set_status(self, status):
|
def set_status(self, status):
|
||||||
"""Set current Jabber status"""
|
"""Set current Jabber status"""
|
||||||
|
|
||||||
@@ -323,10 +329,6 @@ class MailAccount(PresenceAccount):
|
|||||||
def format_message_summary(self, email_msg):
|
def format_message_summary(self, email_msg):
|
||||||
return self.format_message(email_msg, False)
|
return self.format_message(email_msg, False)
|
||||||
|
|
||||||
def get_default_status_msg(self, lang_class):
|
|
||||||
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
|
||||||
unicode(self.port)
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@@ -782,6 +784,15 @@ class SMTPAccount(Account):
|
|||||||
|
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
|
get_default_status_msg = _get_default_status_msg
|
||||||
|
|
||||||
|
def get_type(self):
|
||||||
|
if self.tls:
|
||||||
|
return "smtps"
|
||||||
|
return "smtp"
|
||||||
|
|
||||||
|
type = property(get_type)
|
||||||
|
|
||||||
def create_email(self, from_email, to_email, subject, body, other_headers=None):
|
def create_email(self, from_email, to_email, subject, body, other_headers=None):
|
||||||
"""Create new email"""
|
"""Create new email"""
|
||||||
_email = MIMEText(body)
|
_email = MIMEText(body)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ from jcl.tests import JCLTestCase
|
|||||||
import jcl.model as model
|
import jcl.model as model
|
||||||
from jcl.model.account import Account, PresenceAccount, User
|
from jcl.model.account import Account, PresenceAccount, User
|
||||||
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, SMTPAccount
|
from jmc.model.account import MailAccount, POP3Account, IMAPAccount, SMTPAccount
|
||||||
|
from jmc.lang import Lang
|
||||||
|
|
||||||
from jcl.model.tests.account import Account_TestCase, \
|
from jcl.model.tests.account import Account_TestCase, \
|
||||||
PresenceAccount_TestCase, InheritableAccount_TestCase, \
|
PresenceAccount_TestCase, InheritableAccount_TestCase, \
|
||||||
@@ -128,6 +129,18 @@ class MailAccount_TestCase(PresenceAccount_TestCase):
|
|||||||
u"Encoded multipart3 with no charset (éàê)\n",
|
u"Encoded multipart3 with no charset (éàê)\n",
|
||||||
u"encoded from (éàê)"))
|
u"encoded from (éàê)"))
|
||||||
|
|
||||||
|
def test_get_default_status_msg(self):
|
||||||
|
"""
|
||||||
|
Get default status message for MailAccount.
|
||||||
|
Should raise NotImplementedError because get_type() method
|
||||||
|
is not implemented
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.account.get_default_status_msg(Lang.en)
|
||||||
|
except NotImplementedError:
|
||||||
|
return
|
||||||
|
fail("No NotImplementedError raised")
|
||||||
|
|
||||||
class POP3Account_TestCase(InheritableAccount_TestCase):
|
class POP3Account_TestCase(InheritableAccount_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
||||||
@@ -361,6 +374,21 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
|
|||||||
self.assertEquals(result, [5])
|
self.assertEquals(result, [5])
|
||||||
self.assertEquals(self.pop3_account.lastmail, 5)
|
self.assertEquals(self.pop3_account.lastmail, 5)
|
||||||
|
|
||||||
|
def test_get_default_status_msg(self):
|
||||||
|
"""
|
||||||
|
Get default status message for POP3Account.
|
||||||
|
"""
|
||||||
|
status_msg = self.pop3_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "pop3://login@localhost:1110")
|
||||||
|
|
||||||
|
def test_get_default_status_msg_ssl(self):
|
||||||
|
"""
|
||||||
|
Get default status message for SSL POP3Account.
|
||||||
|
"""
|
||||||
|
self.pop3_account.ssl = True
|
||||||
|
status_msg = self.pop3_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "pop3s://login@localhost:1110")
|
||||||
|
|
||||||
class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
|
||||||
@@ -752,6 +780,21 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
mail_list = [1, 2, 3, 4]
|
mail_list = [1, 2, 3, 4]
|
||||||
self.check_get_next_mail_index(mail_list)
|
self.check_get_next_mail_index(mail_list)
|
||||||
|
|
||||||
|
def test_get_default_status_msg(self):
|
||||||
|
"""
|
||||||
|
Get default status message for IMAPAccount.
|
||||||
|
"""
|
||||||
|
status_msg = self.imap_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "imap://login@localhost:1143")
|
||||||
|
|
||||||
|
def test_get_default_status_msg_ssl(self):
|
||||||
|
"""
|
||||||
|
Get default status message for SSL IMAPAccount.
|
||||||
|
"""
|
||||||
|
self.imap_account.ssl = True
|
||||||
|
status_msg = self.imap_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "imaps://login@localhost:1143")
|
||||||
|
|
||||||
class SMTPAccount_TestCase(Account_TestCase):
|
class SMTPAccount_TestCase(Account_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
JCLTestCase.setUp(self, tables=[Account, ExampleAccount, User,
|
JCLTestCase.setUp(self, tables=[Account, ExampleAccount, User,
|
||||||
@@ -876,153 +919,181 @@ class SMTPAccount_TestCase(Account_TestCase):
|
|||||||
return inner
|
return inner
|
||||||
|
|
||||||
def test_send_email_esmtp_no_auth(self):
|
def test_send_email_esmtp_no_auth(self):
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jmc.test.com")
|
jid="account11@jmc.test.com")
|
||||||
smtp_account.host = "localhost"
|
smtp_account.host = "localhost"
|
||||||
smtp_account.port = 1025
|
smtp_account.port = 1025
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
email = smtp_account.create_email("from@test.com",
|
email = smtp_account.create_email("from@test.com",
|
||||||
"to@test.com",
|
"to@test.com",
|
||||||
"subject",
|
"subject",
|
||||||
"body")
|
"body")
|
||||||
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
||||||
"250-localhost Hello 127.0.0.1\r\n"
|
"250-localhost Hello 127.0.0.1\r\n"
|
||||||
+ "250-SIZE 52428800\r\n"
|
+ "250-SIZE 52428800\r\n"
|
||||||
+ "250-PIPELINING\r\n"
|
+ "250-PIPELINING\r\n"
|
||||||
+ "250 HELP\r\n",
|
+ "250 HELP\r\n",
|
||||||
"250 OK\r\n",
|
"250 OK\r\n",
|
||||||
"250 Accepted\r\n",
|
"250 Accepted\r\n",
|
||||||
"354 Enter message\r\n",
|
"354 Enter message\r\n",
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
"250 OK\r\n"],
|
"250 OK\r\n"],
|
||||||
["ehlo \[127.0...1\]\r\n",
|
["ehlo \[127.0...1\]\r\n",
|
||||||
"mail FROM:<" + str(email['From']) + ">.*",
|
"mail FROM:<" + str(email['From']) + ">.*",
|
||||||
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
||||||
"data\r\n"] +
|
"data\r\n"] +
|
||||||
email.as_string().split("\n") + [".\r\n"],
|
email.as_string().split("\n") + [".\r\n"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
smtp_account.send_email(email))
|
smtp_account.send_email(email))
|
||||||
test_func()
|
test_func()
|
||||||
|
|
||||||
def test_send_email_no_auth(self):
|
def test_send_email_no_auth(self):
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jmc.test.com")
|
jid="account11@jmc.test.com")
|
||||||
smtp_account.host = "localhost"
|
smtp_account.host = "localhost"
|
||||||
smtp_account.port = 1025
|
smtp_account.port = 1025
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
email = smtp_account.create_email("from@test.com",
|
email = smtp_account.create_email("from@test.com",
|
||||||
"to@test.com",
|
"to@test.com",
|
||||||
"subject",
|
"subject",
|
||||||
"body")
|
"body")
|
||||||
test_func = self.make_test(["220 localhost SMTP\r\n",
|
test_func = self.make_test(["220 localhost SMTP\r\n",
|
||||||
"504 ESMTP not supported\r\n",
|
"504 ESMTP not supported\r\n",
|
||||||
"250-localhost Hello 127.0.0.1\r\n"
|
"250-localhost Hello 127.0.0.1\r\n"
|
||||||
+ "250-SIZE 52428800\r\n"
|
+ "250-SIZE 52428800\r\n"
|
||||||
+ "250-PIPELINING\r\n"
|
+ "250-PIPELINING\r\n"
|
||||||
+ "250 HELP\r\n",
|
+ "250 HELP\r\n",
|
||||||
"250 OK\r\n",
|
"250 OK\r\n",
|
||||||
"250 Accepted\r\n",
|
"250 Accepted\r\n",
|
||||||
"354 Enter message\r\n",
|
"354 Enter message\r\n",
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
"250 OK\r\n"],
|
"250 OK\r\n"],
|
||||||
["ehlo \[127.0...1\]\r\n",
|
["ehlo \[127.0...1\]\r\n",
|
||||||
"helo \[127.0...1\]\r\n",
|
"helo \[127.0...1\]\r\n",
|
||||||
"mail FROM:<" + str(email['From']) + ">.*",
|
"mail FROM:<" + str(email['From']) + ">.*",
|
||||||
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
||||||
"data\r\n"] +
|
"data\r\n"] +
|
||||||
email.as_string().split("\n") + [".\r\n"],
|
email.as_string().split("\n") + [".\r\n"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
smtp_account.send_email(email))
|
smtp_account.send_email(email))
|
||||||
test_func()
|
test_func()
|
||||||
|
|
||||||
def test_send_email_esmtp_auth(self):
|
def test_send_email_esmtp_auth(self):
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jmc.test.com")
|
jid="account11@jmc.test.com")
|
||||||
smtp_account.host = "localhost"
|
smtp_account.host = "localhost"
|
||||||
smtp_account.port = 1025
|
smtp_account.port = 1025
|
||||||
smtp_account.login = "user"
|
smtp_account.login = "user"
|
||||||
smtp_account.password = "pass"
|
smtp_account.password = "pass"
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
email = smtp_account.create_email("from@test.com",
|
email = smtp_account.create_email("from@test.com",
|
||||||
"to@test.com",
|
"to@test.com",
|
||||||
"subject",
|
"subject",
|
||||||
"body")
|
"body")
|
||||||
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
||||||
"250-localhost Hello 127.0.0.1\r\n"
|
"250-localhost Hello 127.0.0.1\r\n"
|
||||||
+ "250-SIZE 52428800\r\n"
|
+ "250-SIZE 52428800\r\n"
|
||||||
+ "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
|
+ "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
|
||||||
+ "250-PIPELINING\r\n"
|
+ "250-PIPELINING\r\n"
|
||||||
+ "250 HELP\r\n",
|
+ "250 HELP\r\n",
|
||||||
"334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
|
"334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
|
||||||
"235 Authentication succeeded\r\n",
|
"235 Authentication succeeded\r\n",
|
||||||
"250 OK\r\n",
|
"250 OK\r\n",
|
||||||
"250 Accepted\r\n",
|
"250 Accepted\r\n",
|
||||||
"354 Enter message\r\n",
|
"354 Enter message\r\n",
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
"250 OK\r\n"],
|
"250 OK\r\n"],
|
||||||
["ehlo \[127.0...1\]\r\n",
|
["ehlo \[127.0...1\]\r\n",
|
||||||
"AUTH CRAM-MD5\r\n",
|
"AUTH CRAM-MD5\r\n",
|
||||||
".*\r\n",
|
".*\r\n",
|
||||||
"mail FROM:<" + str(email['From']) + ">.*",
|
"mail FROM:<" + str(email['From']) + ">.*",
|
||||||
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
||||||
"data\r\n"] +
|
"data\r\n"] +
|
||||||
email.as_string().split("\n") + [".\r\n"],
|
email.as_string().split("\n") + [".\r\n"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
smtp_account.send_email(email))
|
smtp_account.send_email(email))
|
||||||
test_func()
|
test_func()
|
||||||
|
|
||||||
def test_send_email_esmtp_auth_method2(self):
|
def test_send_email_esmtp_auth_method2(self):
|
||||||
model.db_connect()
|
model.db_connect()
|
||||||
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jmc.test.com")
|
jid="account11@jmc.test.com")
|
||||||
smtp_account.host = "localhost"
|
smtp_account.host = "localhost"
|
||||||
smtp_account.port = 1025
|
smtp_account.port = 1025
|
||||||
smtp_account.login = "user"
|
smtp_account.login = "user"
|
||||||
smtp_account.password = "pass"
|
smtp_account.password = "pass"
|
||||||
model.db_disconnect()
|
model.db_disconnect()
|
||||||
email = smtp_account.create_email("from@test.com",
|
email = smtp_account.create_email("from@test.com",
|
||||||
"to@test.com",
|
"to@test.com",
|
||||||
"subject",
|
"subject",
|
||||||
"body")
|
"body")
|
||||||
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
test_func = self.make_test(["220 localhost ESMTP\r\n",
|
||||||
"250-localhost Hello 127.0.0.1\r\n"
|
"250-localhost Hello 127.0.0.1\r\n"
|
||||||
+ "250-SIZE 52428800\r\n"
|
+ "250-SIZE 52428800\r\n"
|
||||||
+ "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
|
+ "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
|
||||||
+ "250-PIPELINING\r\n"
|
+ "250-PIPELINING\r\n"
|
||||||
+ "250 HELP\r\n",
|
+ "250 HELP\r\n",
|
||||||
"334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
|
"334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
|
||||||
"535 Incorrect Authentication data\r\n",
|
"535 Incorrect Authentication data\r\n",
|
||||||
"334 asd235r4\r\n",
|
"334 asd235r4\r\n",
|
||||||
"235 Authentication succeeded\r\n",
|
"235 Authentication succeeded\r\n",
|
||||||
"250 OK\r\n",
|
"250 OK\r\n",
|
||||||
"250 Accepted\r\n",
|
"250 Accepted\r\n",
|
||||||
"354 Enter message\r\n",
|
"354 Enter message\r\n",
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
None, None, None, None,
|
None, None, None, None,
|
||||||
"250 OK\r\n"],
|
"250 OK\r\n"],
|
||||||
["ehlo \[127.0...1\]\r\n",
|
["ehlo \[127.0...1\]\r\n",
|
||||||
"AUTH CRAM-MD5\r\n",
|
"AUTH CRAM-MD5\r\n",
|
||||||
".*\r\n",
|
".*\r\n",
|
||||||
"AUTH LOGIN .*\r\n",
|
"AUTH LOGIN .*\r\n",
|
||||||
".*\r\n",
|
".*\r\n",
|
||||||
"mail FROM:<" + str(email['From']) + ">.*",
|
"mail FROM:<" + str(email['From']) + ">.*",
|
||||||
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
"rcpt TO:<" + str(email['To']) + ">\r\n",
|
||||||
"data\r\n"] +
|
"data\r\n"] +
|
||||||
email.as_string().split("\n") + [".\r\n"],
|
email.as_string().split("\n") + [".\r\n"],
|
||||||
lambda self: \
|
lambda self: \
|
||||||
smtp_account.send_email(email))
|
smtp_account.send_email(email))
|
||||||
test_func()
|
test_func()
|
||||||
|
|
||||||
|
def test_get_default_status_msg(self):
|
||||||
|
"""
|
||||||
|
Get default status message for IMAPAccount.
|
||||||
|
"""
|
||||||
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
|
name="account11",
|
||||||
|
jid="account11@jmc.test.com")
|
||||||
|
smtp_account.host = "localhost"
|
||||||
|
smtp_account.port = 1025
|
||||||
|
smtp_account.login = "user"
|
||||||
|
smtp_account.password = "pass"
|
||||||
|
status_msg = smtp_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "smtp://user@localhost:1025")
|
||||||
|
|
||||||
|
def test_get_default_status_msg_ssl(self):
|
||||||
|
"""
|
||||||
|
Get default status message for SSL IMAPAccount.
|
||||||
|
"""
|
||||||
|
smtp_account = SMTPAccount(user=User(jid="user1@test.com"),
|
||||||
|
name="account11",
|
||||||
|
jid="account11@jmc.test.com")
|
||||||
|
smtp_account.host = "localhost"
|
||||||
|
smtp_account.port = 1025
|
||||||
|
smtp_account.login = "user"
|
||||||
|
smtp_account.password = "pass"
|
||||||
|
smtp_account.tls = True
|
||||||
|
status_msg = smtp_account.get_default_status_msg(Lang.en)
|
||||||
|
self.assertEquals(status_msg, "smtps://user@localhost:1025")
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|||||||
Reference in New Issue
Block a user