clean TODO comments
darcs-hash:20080310191927-86b55-89a714525eaf472ba9902a6c5064f81b85dd9900.gz
This commit is contained in:
@@ -53,7 +53,6 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
# Delayed to JMC 0.3.1
|
# Delayed to JMC 0.3.1
|
||||||
def execute_retrieve_attachment_1(self, info_query, session_context,
|
def execute_retrieve_attachment_1(self, info_query, session_context,
|
||||||
command_node, lang_class):
|
command_node, lang_class):
|
||||||
# TODO : translate
|
|
||||||
self.__logger.debug("Executing command 'retrieve-attachment' step 1")
|
self.__logger.debug("Executing command 'retrieve-attachment' step 1")
|
||||||
self.add_actions(command_node, [command.ACTION_NEXT])
|
self.add_actions(command_node, [command.ACTION_NEXT])
|
||||||
bare_from_jid = info_query.get_from().bare()
|
bare_from_jid = info_query.get_from().bare()
|
||||||
@@ -62,8 +61,8 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
MailAccount)
|
MailAccount)
|
||||||
if _account is not None:
|
if _account is not None:
|
||||||
result_form = Form(xmlnode_or_type="form",
|
result_form = Form(xmlnode_or_type="form",
|
||||||
title="TODO:TITLE",
|
title="TITLE",
|
||||||
instructions="TODO:INS")
|
instructions="INS")
|
||||||
field = result_form.add_field(name="attachments",
|
field = result_form.add_field(name="attachments",
|
||||||
field_type="list-multi",
|
field_type="list-multi",
|
||||||
label="select attachments")
|
label="select attachments")
|
||||||
@@ -75,10 +74,10 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
result_form.as_xml(command_node)
|
result_form.as_xml(command_node)
|
||||||
return (result_form, [])
|
return (result_form, [])
|
||||||
else:
|
else:
|
||||||
# TODO Error
|
# ERROR
|
||||||
return (None, [])
|
return (None, [])
|
||||||
|
|
||||||
# TODO: retrieve step2: Delayed to JMC 0.3.1
|
# retrieve step2: Delayed to JMC 0.3.1
|
||||||
|
|
||||||
def execute_force_check_root_node(self, info_query, session_context,
|
def execute_force_check_root_node(self, info_query, session_context,
|
||||||
command_node, lang_class):
|
command_node, lang_class):
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class MailFeeder(Feeder):
|
|||||||
"""Check for new emails for given MailAccount and return a list of
|
"""Check for new emails for given MailAccount and return a list of
|
||||||
those emails or a summary.
|
those emails or a summary.
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("MailFeeder.feed")
|
self.__logger.debug("MailFeeder.feed")
|
||||||
result = []
|
result = []
|
||||||
if _account.first_check and _account.live_email_only:
|
if _account.first_check and _account.live_email_only:
|
||||||
continue_checking = self.initialize_live_email(_account)
|
continue_checking = self.initialize_live_email(_account)
|
||||||
@@ -105,25 +105,20 @@ class MailFeeder(Feeder):
|
|||||||
mail_list = _account.get_new_mail_list()
|
mail_list = _account.get_new_mail_list()
|
||||||
default_lang_class = _account.default_lang_class
|
default_lang_class = _account.default_lang_class
|
||||||
if action == MailAccount.RETRIEVE:
|
if action == MailAccount.RETRIEVE:
|
||||||
# TODO : use generator (yield)
|
for mail_index in _account.get_next_mail_index(mail_list):
|
||||||
mail_index = _account.get_next_mail_index(mail_list)
|
|
||||||
while mail_index is not None:
|
|
||||||
(body, email_from) = _account.get_mail(mail_index)
|
(body, email_from) = _account.get_mail(mail_index)
|
||||||
result.append((email_from,
|
result.append((email_from,
|
||||||
default_lang_class.new_mail_subject\
|
default_lang_class.new_mail_subject\
|
||||||
% (email_from),
|
% (email_from),
|
||||||
body))
|
body))
|
||||||
mail_index = _account.get_next_mail_index(mail_list)
|
|
||||||
elif action == MailAccount.DIGEST:
|
elif action == MailAccount.DIGEST:
|
||||||
body = ""
|
body = ""
|
||||||
new_mail_count = 0
|
new_mail_count = 0
|
||||||
mail_index = _account.get_next_mail_index(mail_list)
|
for mail_index in _account.get_next_mail_index(mail_list):
|
||||||
while mail_index is not None:
|
|
||||||
(tmp_body, from_email) = \
|
(tmp_body, from_email) = \
|
||||||
_account.get_mail_summary(mail_index)
|
_account.get_mail_summary(mail_index)
|
||||||
body += tmp_body
|
body += tmp_body
|
||||||
body += "\n----------------------------------\n"
|
body += "\n----------------------------------\n"
|
||||||
mail_index = _account.get_next_mail_index(mail_list)
|
|
||||||
new_mail_count += 1
|
new_mail_count += 1
|
||||||
if body != "":
|
if body != "":
|
||||||
result.append((None,
|
result.append((None,
|
||||||
@@ -152,7 +147,7 @@ class MailSender(HeadlineSender):
|
|||||||
def create_full_email_message(self, email_from, email_subject,
|
def create_full_email_message(self, email_from, email_subject,
|
||||||
email_body, to_account):
|
email_body, to_account):
|
||||||
"""
|
"""
|
||||||
Create a jabber message with email data and XEP-XXX addresses (TODO)
|
Create a jabber message with email data and XEP-0033 addresses
|
||||||
"""
|
"""
|
||||||
message = MessageSender.create_message(self, to_account,
|
message = MessageSender.create_message(self, to_account,
|
||||||
(email_subject, email_body))
|
(email_subject, email_body))
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ class MailAccount(PresenceAccount):
|
|||||||
self.default_lang_class = Lang.en
|
self.default_lang_class = Lang.en
|
||||||
|
|
||||||
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
|
||||||
"""
|
"""
|
||||||
def password_post_func(password, default_func, bare_from_jid):
|
def password_post_func(password, default_func, bare_from_jid):
|
||||||
if password is None or password == "":
|
if password is None or password == "":
|
||||||
@@ -239,6 +240,14 @@ class MailAccount(PresenceAccount):
|
|||||||
|
|
||||||
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
get_presence_actions_fields = classmethod(_get_presence_actions_fields)
|
||||||
|
|
||||||
|
def set_status(self, status):
|
||||||
|
"""Set current Jabber status"""
|
||||||
|
|
||||||
|
if status != account.OFFLINE and self._status == account.OFFLINE:
|
||||||
|
PresenceAccount.set_status(self, status)
|
||||||
|
self.first_check = True
|
||||||
|
self._status = status
|
||||||
|
|
||||||
def get_decoded_header(self, header, charset_hint=None):
|
def get_decoded_header(self, header, charset_hint=None):
|
||||||
decoded_header = email.Header.decode_header(header)
|
decoded_header = email.Header.decode_header(header)
|
||||||
decoded_header_str = u""
|
decoded_header_str = u""
|
||||||
@@ -461,10 +470,13 @@ class IMAPAccount(MailAccount):
|
|||||||
return u"Error while fetching mail " + str(index)
|
return u"Error while fetching mail " + str(index)
|
||||||
|
|
||||||
def get_next_mail_index(self, mail_list):
|
def get_next_mail_index(self, mail_list):
|
||||||
if self.is_mail_list_valid(mail_list):
|
"""
|
||||||
return mail_list.pop(0)
|
Mail indexes generator. Return mail_list elements and destroy them
|
||||||
else:
|
when returned.
|
||||||
return None
|
"""
|
||||||
|
while self.is_mail_list_valid(mail_list):
|
||||||
|
yield mail_list.pop(0)
|
||||||
|
return
|
||||||
|
|
||||||
def mark_all_as_read(self):
|
def mark_all_as_read(self):
|
||||||
self.get_new_mail_list()
|
self.get_new_mail_list()
|
||||||
@@ -629,16 +641,45 @@ class POP3Account(MailAccount):
|
|||||||
return u"Error while fetching mail " + str(index)
|
return u"Error while fetching mail " + str(index)
|
||||||
|
|
||||||
def get_next_mail_index(self, mail_list):
|
def get_next_mail_index(self, mail_list):
|
||||||
if self.is_mail_list_valid(mail_list):
|
"""
|
||||||
if self.nb_mail == self.lastmail:
|
Return next mail index to be read. mail_list is a generated list of
|
||||||
return None
|
mail indexes in the mailbox. If the mailbox has been check by another
|
||||||
|
client, self.nb_mail should be < to self.lastmail (last mail_list
|
||||||
|
index that has been returned), so self.lastmail is set to 0 to return
|
||||||
|
indexes from the begining of the mail_list array. If the mailbox has
|
||||||
|
not been checked by another client since last check from JMC, then
|
||||||
|
only new email indexes of mail_list should be returned. self.lastmail
|
||||||
|
sill contains old nb_mail value (it has stop at this value in the last
|
||||||
|
check) and self.nb_mail contains the new count of new emails:
|
||||||
|
ex:
|
||||||
|
- First check
|
||||||
|
[1, 2, 3, 4, 5, 6, 7]
|
||||||
|
^ ^
|
||||||
|
| |
|
||||||
|
self.lastmail self.nb_mail
|
||||||
|
- end of first check
|
||||||
|
[1, 2, 3, 4, 5, 6, 7]
|
||||||
|
^
|
||||||
|
|
|
||||||
|
self.nb_mail == self.lastmail
|
||||||
|
- second check (no check by another client)
|
||||||
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
||||||
|
^ ^
|
||||||
|
| |
|
||||||
|
self.lastmail self.nb_mail
|
||||||
|
Only emails indexes form 8 to 13 are returned
|
||||||
|
- a checking done by another client is dectected only if self.nb_mail
|
||||||
|
become < to self.lastmail. If the number of new emails is superior to
|
||||||
|
self.lastmail after another client has check the mailbox, emails
|
||||||
|
indexes from 0 to self.lastmail are not sent through JMC.
|
||||||
|
"""
|
||||||
|
while self.nb_mail != self.lastmail:
|
||||||
if self.nb_mail < self.lastmail:
|
if self.nb_mail < self.lastmail:
|
||||||
self.lastmail = 0
|
self.lastmail = 0
|
||||||
result = int(mail_list[self.lastmail])
|
result = int(mail_list[self.lastmail])
|
||||||
self.lastmail += 1
|
self.lastmail += 1
|
||||||
return result
|
yield result
|
||||||
else:
|
return
|
||||||
return None
|
|
||||||
|
|
||||||
def mark_all_as_read(self):
|
def mark_all_as_read(self):
|
||||||
self.get_new_mail_list()
|
self.get_new_mail_list()
|
||||||
|
|||||||
@@ -290,6 +290,77 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
|
|||||||
u"mymessage\n",
|
u"mymessage\n",
|
||||||
u"user@test.com")))
|
u"user@test.com")))
|
||||||
|
|
||||||
|
def test_get_next_mail_index_empty(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index with empty mail_list parameter.
|
||||||
|
"""
|
||||||
|
mail_list = []
|
||||||
|
self.pop3_account.nb_mail = 0
|
||||||
|
self.pop3_account.lastmail = 0
|
||||||
|
result = []
|
||||||
|
for elt in self.pop3_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
self.assertEquals(result, [])
|
||||||
|
|
||||||
|
def test_get_next_mail_index(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index first check.
|
||||||
|
"""
|
||||||
|
mail_list = [1, 2, 3, 4]
|
||||||
|
self.pop3_account.nb_mail = 4
|
||||||
|
self.pop3_account.lastmail = 0
|
||||||
|
result = []
|
||||||
|
for elt in self.pop3_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
self.assertEquals(result, [1, 2, 3, 4])
|
||||||
|
self.assertEquals(self.pop3_account.lastmail, 4)
|
||||||
|
|
||||||
|
def test_get_next_mail_index_second_check(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index second check (no parallel checking).
|
||||||
|
"""
|
||||||
|
mail_list = [1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
|
self.pop3_account.nb_mail = 8
|
||||||
|
self.pop3_account.lastmail = 4
|
||||||
|
result = []
|
||||||
|
for elt in self.pop3_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
self.assertEquals(result, [5, 6, 7, 8])
|
||||||
|
self.assertEquals(self.pop3_account.lastmail, 8)
|
||||||
|
|
||||||
|
def test_get_next_mail_index_second_check_parallel_check(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index second check (with parallel checking
|
||||||
|
but not more new emails than last index jmc stopped:
|
||||||
|
3 new emails after another client checked emails).
|
||||||
|
"""
|
||||||
|
mail_list = [1, 2, 3]
|
||||||
|
self.pop3_account.nb_mail = 3
|
||||||
|
self.pop3_account.lastmail = 4
|
||||||
|
result = []
|
||||||
|
for elt in self.pop3_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
self.assertEquals(result, [1, 2, 3])
|
||||||
|
self.assertEquals(self.pop3_account.lastmail, 3)
|
||||||
|
|
||||||
|
def test_get_next_mail_index_second_check_bug_parallel_check(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index second check (with parallel checking
|
||||||
|
but with more new emails than last index jmc stopped:
|
||||||
|
5 new emails after another client checked emails). Cannot make
|
||||||
|
the difference with one new email since last jmc email check!!
|
||||||
|
"""
|
||||||
|
mail_list = [1, 2, 3, 4, 5]
|
||||||
|
self.pop3_account.nb_mail = 5
|
||||||
|
self.pop3_account.lastmail = 4
|
||||||
|
result = []
|
||||||
|
for elt in self.pop3_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
# with no bug it should be:
|
||||||
|
# self.assertEquals(result, [1, 2, 3, 4, 5])
|
||||||
|
self.assertEquals(result, [5])
|
||||||
|
self.assertEquals(self.pop3_account.lastmail, 5)
|
||||||
|
|
||||||
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,
|
||||||
@@ -600,6 +671,31 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
call_func)
|
call_func)
|
||||||
test_func()
|
test_func()
|
||||||
|
|
||||||
|
def check_get_next_mail_index(self, mail_list):
|
||||||
|
"""
|
||||||
|
Common tests for get_next_mail_index method.
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
original_mail_list = [elt for elt in mail_list]
|
||||||
|
for elt in self.imap_account.get_next_mail_index(mail_list):
|
||||||
|
result.append(elt)
|
||||||
|
self.assertEquals(mail_list, [])
|
||||||
|
self.assertEquals(result, original_mail_list)
|
||||||
|
|
||||||
|
def test_get_next_mail_index_empty(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index with empty mail_list parameter.
|
||||||
|
"""
|
||||||
|
mail_list = []
|
||||||
|
self.check_get_next_mail_index(mail_list)
|
||||||
|
|
||||||
|
def test_get_next_mail_index(self):
|
||||||
|
"""
|
||||||
|
Test get_next_mail_index.
|
||||||
|
"""
|
||||||
|
mail_list = [1, 2, 3, 4]
|
||||||
|
self.check_get_next_mail_index(mail_list)
|
||||||
|
|
||||||
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,
|
||||||
|
|||||||
@@ -140,12 +140,11 @@ class XMLDummyServer(DummyServer):
|
|||||||
data = None
|
data = None
|
||||||
for idx in range(len(self.responses)):
|
for idx in range(len(self.responses)):
|
||||||
try:
|
try:
|
||||||
# TODO : this approximation is not clean
|
# This approximation is not clean
|
||||||
# received size is based on the expected size in self.queries
|
# received size is based on the expected size in self.queries
|
||||||
data = conn.recv(1024 + len(self.queries[idx]))
|
data = conn.recv(1024 + len(self.queries[idx]))
|
||||||
# print "receive : " + data
|
# print "receive : " + data
|
||||||
if data:
|
if data:
|
||||||
## TODO : without this log, test_set_register in test_component wait forever
|
|
||||||
#print "-----------RECEIVE1 " + data
|
#print "-----------RECEIVE1 " + data
|
||||||
r = self._reader.feed(data)
|
r = self._reader.feed(data)
|
||||||
except:
|
except:
|
||||||
@@ -153,7 +152,6 @@ class XMLDummyServer(DummyServer):
|
|||||||
print "".join (traceback.format_exception
|
print "".join (traceback.format_exception
|
||||||
(type, value, stack, 5))
|
(type, value, stack, 5))
|
||||||
raise
|
raise
|
||||||
# TODO verify got all data </stream>
|
|
||||||
if data:
|
if data:
|
||||||
self.real_queries.append(data)
|
self.real_queries.append(data)
|
||||||
# if response is a function apply it (it must return a string)
|
# if response is a function apply it (it must return a string)
|
||||||
|
|||||||
Reference in New Issue
Block a user