check for account login and host with whitespace
This commit is contained in:
@@ -95,6 +95,7 @@ class Lang(jcl.lang.Lang):
|
|||||||
field_email_subject = u"Email Subject"
|
field_email_subject = u"Email Subject"
|
||||||
field_select_more_emails = u"Select more emails to fetch"
|
field_select_more_emails = u"Select more emails to fetch"
|
||||||
mail_subject = u"Email from %s"
|
mail_subject = u"Email from %s"
|
||||||
|
no_whitespace_in_field = u"There must be no whitespace in field"
|
||||||
|
|
||||||
class fr(en, jcl.lang.Lang.fr):
|
class fr(en, jcl.lang.Lang.fr):
|
||||||
component_name = u"Jabber Mail Component"
|
component_name = u"Jabber Mail Component"
|
||||||
@@ -169,6 +170,7 @@ class Lang(jcl.lang.Lang):
|
|||||||
field_email_subject = u"Objet des emails"
|
field_email_subject = u"Objet des emails"
|
||||||
field_select_more_emails = u"Séléctionner plus d'emails à récupérer"
|
field_select_more_emails = u"Séléctionner plus d'emails à récupérer"
|
||||||
mail_subject = u"Email de %s"
|
mail_subject = u"Email de %s"
|
||||||
|
no_whitespace_in_field = u"Le champ ne doit pas contenir d'espace"
|
||||||
|
|
||||||
class nl(en, jcl.lang.Lang.nl):
|
class nl(en, jcl.lang.Lang.nl):
|
||||||
# TODO: when finish, delete this line and uncomment in tests/lang.py the makeSuite(Language_nl_TestCase, 'test') line
|
# TODO: when finish, delete this line and uncomment in tests/lang.py the makeSuite(Language_nl_TestCase, 'test') line
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ from sqlobject.inheritance import InheritableSQLObject
|
|||||||
from sqlobject.col import StringCol, IntCol, BoolCol
|
from sqlobject.col import StringCol, IntCol, BoolCol
|
||||||
from sqlobject.sqlbuilder import AND
|
from sqlobject.sqlbuilder import AND
|
||||||
|
|
||||||
|
from jcl.error import FieldError
|
||||||
from jcl.model import account
|
from jcl.model import account
|
||||||
from jcl.model.account import Account, PresenceAccount
|
from jcl.model.account import Account, PresenceAccount
|
||||||
from jmc.lang import Lang
|
from jmc.lang import Lang
|
||||||
@@ -49,7 +50,7 @@ class NoAccountError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_default_status_msg(self, lang_class):
|
def _get_default_status_msg(self, lang_class):
|
||||||
return self.get_type() + "://" + self.login + "@" + self.host + ":" + \
|
return str(self.get_type()) + "://" + str(self.login) + "@" + str(self.host) + ":" + \
|
||||||
unicode(self.port)
|
unicode(self.port)
|
||||||
|
|
||||||
def validate_password(password, default_func, bare_from_jid):
|
def validate_password(password, default_func, bare_from_jid):
|
||||||
@@ -58,7 +59,10 @@ def validate_password(password, default_func, bare_from_jid):
|
|||||||
return password
|
return password
|
||||||
|
|
||||||
def validate_login(login, default_func, bare_from_jid):
|
def validate_login(login, default_func, bare_from_jid):
|
||||||
return account.mandatory_field("login", login)
|
return account.no_whitespace_field("login", account.mandatory_field("login", login))
|
||||||
|
|
||||||
|
def validate_host(host, default_func, bare_from_jid):
|
||||||
|
return account.no_whitespace_field("host", account.mandatory_field("host", host))
|
||||||
|
|
||||||
class MailAccount(PresenceAccount):
|
class MailAccount(PresenceAccount):
|
||||||
""" Wrapper to mail connection and action.
|
""" Wrapper to mail connection and action.
|
||||||
@@ -104,13 +108,10 @@ class MailAccount(PresenceAccount):
|
|||||||
real_class = cls
|
real_class = cls
|
||||||
return PresenceAccount.get_register_fields(real_class) + \
|
return PresenceAccount.get_register_fields(real_class) + \
|
||||||
[("login", "text-single", None,
|
[("login", "text-single", None,
|
||||||
validate_login,
|
validate_login, lambda bare_from_jid: ""),
|
||||||
lambda bare_from_jid: ""),
|
|
||||||
("password", "text-private", None, validate_password,
|
("password", "text-private", None, validate_password,
|
||||||
lambda bare_from_jid: ""),
|
lambda bare_from_jid: ""),
|
||||||
("host", "text-single", None,
|
("host", "text-single", None, validate_host,
|
||||||
lambda field_value, default_func, bare_from_jid: \
|
|
||||||
account.mandatory_field("host", field_value),
|
|
||||||
lambda bare_from_jid: ""),
|
lambda bare_from_jid: ""),
|
||||||
("port", "text-single", None,
|
("port", "text-single", None,
|
||||||
account.int_post_func,
|
account.int_post_func,
|
||||||
@@ -272,8 +273,7 @@ class IMAPAccount(MailAccount):
|
|||||||
delimiter = StringCol(default=".")
|
delimiter = StringCol(default=".")
|
||||||
|
|
||||||
def _get_register_fields(cls, real_class=None):
|
def _get_register_fields(cls, real_class=None):
|
||||||
"""See Account._get_register_fields
|
"""See Account._get_register_fields"""
|
||||||
"""
|
|
||||||
if real_class is None:
|
if real_class is None:
|
||||||
real_class = cls
|
real_class = cls
|
||||||
return MailAccount.get_register_fields(real_class) + \
|
return MailAccount.get_register_fields(real_class) + \
|
||||||
@@ -370,7 +370,7 @@ class IMAPAccount(MailAccount):
|
|||||||
if typ == 'OK':
|
if typ == 'OK':
|
||||||
return self.format_message(\
|
return self.format_message(\
|
||||||
email.message_from_string(data[0][1]))
|
email.message_from_string(data[0][1]))
|
||||||
raise Exception(data[0] + " (email " + str(index) + ")")
|
raise Exception(str(data[0]) + " (email " + str(index) + ")")
|
||||||
|
|
||||||
def get_mail_summary(self, index):
|
def get_mail_summary(self, index):
|
||||||
self.__logger.debug("Getting mail summary " + str(index))
|
self.__logger.debug("Getting mail summary " + str(index))
|
||||||
@@ -380,7 +380,7 @@ class IMAPAccount(MailAccount):
|
|||||||
if typ == 'OK':
|
if typ == 'OK':
|
||||||
return self.format_message_summary(\
|
return self.format_message_summary(\
|
||||||
email.message_from_string(data[0][1]))
|
email.message_from_string(data[0][1]))
|
||||||
raise Exception(data[0] + " (email " + str(index) + ")")
|
raise Exception(str(data[0]) + " (email " + str(index) + ")")
|
||||||
|
|
||||||
def get_next_mail_index(self, mail_list):
|
def get_next_mail_index(self, mail_list):
|
||||||
"""
|
"""
|
||||||
@@ -455,7 +455,7 @@ class IMAPAccount(MailAccount):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
raise Exception("Cannot find mailbox " + self.mailbox)
|
raise Exception("Cannot find mailbox " + str(self.mailbox))
|
||||||
else:
|
else:
|
||||||
match = self._regexp_list.match(line)
|
match = self._regexp_list.match(line)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
@@ -463,10 +463,10 @@ class IMAPAccount(MailAccount):
|
|||||||
else:
|
else:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
raise Exception("Cannot find delimiter for mailbox "
|
raise Exception("Cannot find delimiter for mailbox "
|
||||||
+ self.mailbox)
|
+ str(self.mailbox))
|
||||||
else:
|
else:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
raise Exception("Cannot find mailbox " + self.mailbox)
|
raise Exception("Cannot find mailbox " + str(self.mailbox))
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
# replace any previous delimiter in self.mailbox by "/"
|
# replace any previous delimiter in self.mailbox by "/"
|
||||||
if self.delimiter != testing_delimiter:
|
if self.delimiter != testing_delimiter:
|
||||||
@@ -498,7 +498,7 @@ class POP3Account(MailAccount):
|
|||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.__logger.debug("Connecting to POP3 server "
|
self.__logger.debug("Connecting to POP3 server "
|
||||||
+ self.login + "@" + self.host + ":" +
|
+ str(self.login) + "@" + str(self.host) + ":" +
|
||||||
str(self.port) + ". SSL=" + str(self.ssl))
|
str(self.port) + ". SSL=" + str(self.ssl))
|
||||||
if self.ssl:
|
if self.ssl:
|
||||||
self.connection = poplib.POP3_SSL(self.host, self.port)
|
self.connection = poplib.POP3_SSL(self.host, self.port)
|
||||||
@@ -513,7 +513,7 @@ class POP3Account(MailAccount):
|
|||||||
|
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.__logger.debug("Disconnecting from POP3 server " + self.host)
|
self.__logger.debug("Disconnecting from POP3 server " + str(self.host))
|
||||||
self.connection.quit()
|
self.connection.quit()
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
@@ -748,17 +748,17 @@ class GlobalSMTPAccount(AbstractSMTPAccount):
|
|||||||
current_error = None
|
current_error = None
|
||||||
for auth_method in auth_methods:
|
for auth_method in auth_methods:
|
||||||
self.__logger.debug("Trying to authenticate using "
|
self.__logger.debug("Trying to authenticate using "
|
||||||
+ auth_method + " method")
|
+ str(auth_method) + " method")
|
||||||
smtp_connection.esmtp_features["auth"] = auth_method
|
smtp_connection.esmtp_features["auth"] = auth_method
|
||||||
try:
|
try:
|
||||||
smtp_connection.login(self.login, self.password)
|
smtp_connection.login(self.login, self.password)
|
||||||
current_error = None
|
current_error = None
|
||||||
self.__logger.debug("Successfuly to authenticate using "
|
self.__logger.debug("Successfuly to authenticate using "
|
||||||
+ auth_method + " method")
|
+ str(auth_method) + " method")
|
||||||
break
|
break
|
||||||
except smtplib.SMTPAuthenticationError, error:
|
except smtplib.SMTPAuthenticationError, error:
|
||||||
self.__logger.debug("Failed to authenticate using "
|
self.__logger.debug("Failed to authenticate using "
|
||||||
+ auth_method + " method")
|
+ str(auth_method) + " method")
|
||||||
current_error = error
|
current_error = error
|
||||||
if current_error is not None:
|
if current_error is not None:
|
||||||
raise current_error
|
raise current_error
|
||||||
|
|||||||
@@ -43,6 +43,18 @@ class AccountModule_TestCase(unittest.TestCase):
|
|||||||
self.assertRaises(FieldError, jmc.model.account.validate_login,
|
self.assertRaises(FieldError, jmc.model.account.validate_login,
|
||||||
None, None, None)
|
None, None, None)
|
||||||
|
|
||||||
|
def test_validate_login_with_login_with_whitespace(self):
|
||||||
|
self.assertRaises(FieldError, jmc.model.account.validate_login,
|
||||||
|
"login with spaces", None, None)
|
||||||
|
|
||||||
|
def test_validate_host_with_empty_login(self):
|
||||||
|
self.assertRaises(FieldError, jmc.model.account.validate_host,
|
||||||
|
None, None, None)
|
||||||
|
|
||||||
|
def test_validate_host_with_host_with_whitespace(self):
|
||||||
|
self.assertRaises(FieldError, jmc.model.account.validate_host,
|
||||||
|
"host with spaces", None, None)
|
||||||
|
|
||||||
class MailAccount_TestCase(PresenceAccount_TestCase):
|
class MailAccount_TestCase(PresenceAccount_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
PresenceAccount_TestCase.setUp(self, tables=[MailAccount])
|
||||||
|
|||||||
Reference in New Issue
Block a user