clean TODO comments

darcs-hash:20080310191927-86b55-89a714525eaf472ba9902a6c5064f81b85dd9900.gz
This commit is contained in:
David Rousselie
2008-03-10 20:19:27 +01:00
parent 7cd473ecaf
commit 3616e35abd
5 changed files with 157 additions and 28 deletions

View File

@@ -53,7 +53,6 @@ class MailCommandManager(JCLCommandManager):
# Delayed to JMC 0.3.1
def execute_retrieve_attachment_1(self, info_query, session_context,
command_node, lang_class):
# TODO : translate
self.__logger.debug("Executing command 'retrieve-attachment' step 1")
self.add_actions(command_node, [command.ACTION_NEXT])
bare_from_jid = info_query.get_from().bare()
@@ -62,8 +61,8 @@ class MailCommandManager(JCLCommandManager):
MailAccount)
if _account is not None:
result_form = Form(xmlnode_or_type="form",
title="TODO:TITLE",
instructions="TODO:INS")
title="TITLE",
instructions="INS")
field = result_form.add_field(name="attachments",
field_type="list-multi",
label="select attachments")
@@ -75,10 +74,10 @@ class MailCommandManager(JCLCommandManager):
result_form.as_xml(command_node)
return (result_form, [])
else:
# TODO Error
# ERROR
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,
command_node, lang_class):

View File

@@ -105,25 +105,20 @@ class MailFeeder(Feeder):
mail_list = _account.get_new_mail_list()
default_lang_class = _account.default_lang_class
if action == MailAccount.RETRIEVE:
# TODO : use generator (yield)
mail_index = _account.get_next_mail_index(mail_list)
while mail_index is not None:
for mail_index in _account.get_next_mail_index(mail_list):
(body, email_from) = _account.get_mail(mail_index)
result.append((email_from,
default_lang_class.new_mail_subject\
% (email_from),
body))
mail_index = _account.get_next_mail_index(mail_list)
elif action == MailAccount.DIGEST:
body = ""
new_mail_count = 0
mail_index = _account.get_next_mail_index(mail_list)
while mail_index is not None:
for mail_index in _account.get_next_mail_index(mail_list):
(tmp_body, from_email) = \
_account.get_mail_summary(mail_index)
body += tmp_body
body += "\n----------------------------------\n"
mail_index = _account.get_next_mail_index(mail_list)
new_mail_count += 1
if body != "":
result.append((None,
@@ -152,7 +147,7 @@ class MailSender(HeadlineSender):
def create_full_email_message(self, email_from, email_subject,
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,
(email_subject, email_body))

View File

@@ -179,7 +179,8 @@ class MailAccount(PresenceAccount):
self.default_lang_class = Lang.en
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):
if password is None or password == "":
@@ -239,6 +240,14 @@ class MailAccount(PresenceAccount):
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):
decoded_header = email.Header.decode_header(header)
decoded_header_str = u""
@@ -461,10 +470,13 @@ class IMAPAccount(MailAccount):
return u"Error while fetching mail " + str(index)
def get_next_mail_index(self, mail_list):
if self.is_mail_list_valid(mail_list):
return mail_list.pop(0)
else:
return None
"""
Mail indexes generator. Return mail_list elements and destroy them
when returned.
"""
while self.is_mail_list_valid(mail_list):
yield mail_list.pop(0)
return
def mark_all_as_read(self):
self.get_new_mail_list()
@@ -629,16 +641,45 @@ class POP3Account(MailAccount):
return u"Error while fetching mail " + str(index)
def get_next_mail_index(self, mail_list):
if self.is_mail_list_valid(mail_list):
if self.nb_mail == self.lastmail:
return None
"""
Return next mail index to be read. mail_list is a generated list of
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:
self.lastmail = 0
result = int(mail_list[self.lastmail])
self.lastmail += 1
return result
else:
return None
yield result
return
def mark_all_as_read(self):
self.get_new_mail_list()

View File

@@ -290,6 +290,77 @@ class POP3Account_TestCase(InheritableAccount_TestCase):
u"mymessage\n",
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):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User,
@@ -600,6 +671,31 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
call_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):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account, ExampleAccount, User,

View File

@@ -140,12 +140,11 @@ class XMLDummyServer(DummyServer):
data = None
for idx in range(len(self.responses)):
try:
# TODO : this approximation is not clean
# This approximation is not clean
# received size is based on the expected size in self.queries
data = conn.recv(1024 + len(self.queries[idx]))
# print "receive : " + data
if data:
## TODO : without this log, test_set_register in test_component wait forever
#print "-----------RECEIVE1 " + data
r = self._reader.feed(data)
except:
@@ -153,7 +152,6 @@ class XMLDummyServer(DummyServer):
print "".join (traceback.format_exception
(type, value, stack, 5))
raise
# TODO verify got all data </stream>
if data:
self.real_queries.append(data)
# if response is a function apply it (it must return a string)