Message subject added
- Jabber messages now have a subject - Some bugs corrected : - password storage true by default - better exception handling - storage.__setitem__ called after account object complete darcs-hash:20060206133741-86b55-0a51e24fb65b16c1c942b088f7052ab88248b9ac.gz
This commit is contained in:
@@ -30,6 +30,7 @@ import sys
|
||||
import anydbm
|
||||
import os
|
||||
import time
|
||||
import traceback
|
||||
|
||||
import mailconnection
|
||||
from mailconnection import *
|
||||
@@ -112,7 +113,7 @@ class MailComponent(Component):
|
||||
reg_form.add_field(type = "boolean", \
|
||||
label = lang_class.account_password_store, \
|
||||
var = "store_password",
|
||||
value = "True")
|
||||
value = "1")
|
||||
|
||||
reg_form.add_field(type = "text-single", \
|
||||
label = lang_class.account_host, \
|
||||
@@ -647,6 +648,7 @@ class MailComponent(Component):
|
||||
else:
|
||||
socket = host
|
||||
if self.__storage.has_key((base_from_jid, name)):
|
||||
account = self.__storage[(base_from_jid, name)]
|
||||
m = Message(from_jid = self.jid, to_jid = from_jid, \
|
||||
stanza_type = "normal", \
|
||||
subject = lang_class.update_account_message_subject \
|
||||
@@ -655,6 +657,7 @@ class MailComponent(Component):
|
||||
% (login, password, socket))
|
||||
self.stream.send(m)
|
||||
else:
|
||||
account = mailconnection_factory.get_new_mail_connection(type)
|
||||
m = Message(from_jid = self.jid, to_jid = from_jid, \
|
||||
stanza_type = "normal", \
|
||||
subject = lang_class.new_account_message_subject \
|
||||
@@ -666,9 +669,6 @@ class MailComponent(Component):
|
||||
to_jid = base_from_jid, \
|
||||
stanza_type="subscribe")
|
||||
self.stream.send(p)
|
||||
|
||||
self.__storage[(base_from_jid, name)] = account = \
|
||||
mailconnection_factory.get_new_mail_connection(type)
|
||||
account.login = login
|
||||
account.password = password
|
||||
account.store_password = store_password
|
||||
@@ -687,6 +687,7 @@ class MailComponent(Component):
|
||||
|
||||
if type[0:4] == "imap":
|
||||
account.mailbox = mailbox
|
||||
self.__storage[(base_from_jid, name)] = account
|
||||
|
||||
return 1
|
||||
|
||||
@@ -857,26 +858,30 @@ class MailComponent(Component):
|
||||
account.lastmail = 0
|
||||
if action == mailconnection.RETRIEVE:
|
||||
while account.lastmail < num:
|
||||
body = account.get_mail(int(mail_list[account.lastmail]))
|
||||
(body, email_from) = account.get_mail(int(mail_list[account.lastmail]))
|
||||
mesg = Message(from_jid = name + "@" + \
|
||||
unicode(self.jid), \
|
||||
to_jid = jid, \
|
||||
stanza_type = "normal", \
|
||||
subject = account.default_lang_class.new_mail_subject % (email_from), \
|
||||
body = body)
|
||||
self.stream.send(mesg)
|
||||
account.lastmail += 1
|
||||
else:
|
||||
body = ""
|
||||
new_mail_count = 0
|
||||
while account.lastmail < num:
|
||||
body += \
|
||||
account.get_mail_summary(int(mail_list[account.lastmail])) \
|
||||
+ "\n----------------------------------\n"
|
||||
(tmp_body, from_email) = \
|
||||
account.get_mail_summary(int(mail_list[account.lastmail]))
|
||||
body += tmp_body + "\n----------------------------------\n"
|
||||
account.lastmail += 1
|
||||
new_mail_count += 1
|
||||
if body != "":
|
||||
mesg = Message(from_jid = name + "@" + \
|
||||
unicode(self.jid), \
|
||||
to_jid = jid, \
|
||||
stanza_type = "headline", \
|
||||
subject = account.default_lang_class.new_digest_subject % (new_mail_count), \
|
||||
body = body)
|
||||
self.stream.send(mesg)
|
||||
account.disconnect()
|
||||
@@ -891,8 +896,10 @@ class MailComponent(Component):
|
||||
body = account.default_lang_class.check_error_body \
|
||||
% (e))
|
||||
self.stream.send(msg)
|
||||
self.__logger.debug("Error while checking mail : %s" \
|
||||
% (e))
|
||||
type, value, stack = sys.exc_info()
|
||||
self.__logger.debug("Error while checking mail : %s\n%s" \
|
||||
% (e, "".join(traceback.format_exception
|
||||
(type, value, stack, 5))))
|
||||
|
||||
""" check mail handler """
|
||||
def check_all_mail(self):
|
||||
@@ -923,8 +930,10 @@ class MailComponent(Component):
|
||||
body = account.default_lang_class.check_error_body \
|
||||
% (e))
|
||||
self.stream.send(msg)
|
||||
self.__logger.debug("Error while checking mail : %s" \
|
||||
% (e))
|
||||
type, value, stack = sys.exc_info()
|
||||
self.__logger.debug("Error while first checking mail : %s\n%s" \
|
||||
% (e, "".join(traceback.format_exception
|
||||
(type, value, stack, 5))))
|
||||
account.lastcheck += 1
|
||||
if account.lastcheck == account.interval:
|
||||
account.lastcheck = 0
|
||||
|
||||
@@ -78,6 +78,8 @@ class Lang:
|
||||
password_saved_for_session = u"Password will be kept during your jabber session"
|
||||
check_error_subject = u"Error while checking emails."
|
||||
check_error_body = u"An error appears while checking emails :\n\t%s"
|
||||
new_mail_subject = u"New email from %s"
|
||||
new_digest_subject = u"%i new email(s)"
|
||||
|
||||
class fr:
|
||||
register_title = u"Enregistrement d'une nouvelle connexion à un serveur email."
|
||||
@@ -119,3 +121,5 @@ class Lang:
|
||||
check_error_subject = u"Erreur lors de la vérification des emails."
|
||||
check_error_body = u"Une erreur est survenue lors de la vérification " \
|
||||
"des emails :\n\t%s"
|
||||
new_mail_subject = u"Nouvel email de %s"
|
||||
new_digest_subject = u"%i nouveau(x) email(s)"
|
||||
|
||||
@@ -226,23 +226,26 @@ class MailConnection(object):
|
||||
def format_message(self, email_msg, include_body = True):
|
||||
from_decoded = email.Header.decode_header(email_msg["From"])
|
||||
charset_hint = None
|
||||
email_from = u""
|
||||
result = u"From : "
|
||||
for i in range(len(from_decoded)):
|
||||
if from_decoded[i][1]:
|
||||
charset_hint = from_decoded[i][1]
|
||||
result += unicode(from_decoded[i][0].decode(from_decoded[i][1]))
|
||||
email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1]))
|
||||
else:
|
||||
try:
|
||||
result += unicode(from_decoded[i][0])
|
||||
email_from += unicode(from_decoded[i][0])
|
||||
except Exception,e:
|
||||
try:
|
||||
result += unicode(from_decoded[i][0].decode("iso-8859-1"))
|
||||
email_from += unicode(from_decoded[i][0].decode("iso-8859-1"))
|
||||
except Exception, e:
|
||||
try:
|
||||
result += unicode(from_decoded[i][0].decode(default_encoding))
|
||||
email_from += unicode(from_decoded[i][0].decode(default_encoding))
|
||||
except Exception, e:
|
||||
print e
|
||||
result += "\n"
|
||||
type, value, stack = sys.exc_info()
|
||||
print >>sys.stderr, "".join(traceback.format_exception
|
||||
(type, value, stack, 5))
|
||||
result += email_from + u"\n"
|
||||
|
||||
subject_decoded = email.Header.decode_header(email_msg["Subject"])
|
||||
result += u"Subject : "
|
||||
@@ -279,7 +282,7 @@ class MailConnection(object):
|
||||
content_type = part.get_content_type()
|
||||
if action.has_key(content_type):
|
||||
result += action[content_type](part) + u'\n'
|
||||
return result
|
||||
return (result, email_from)
|
||||
|
||||
def format_message_summary(self, email_msg):
|
||||
return self.format_message(email_msg, False)
|
||||
|
||||
@@ -59,13 +59,15 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
test_format_message_summary_not_encoded = \
|
||||
make_test((False, False, True), \
|
||||
lambda self, email: self.connection.format_message_summary(email), \
|
||||
u"From : not encoded from\nSubject : not encoded subject\n\n")
|
||||
(u"From : not encoded from\nSubject : not encoded subject\n\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_summary_encoded = \
|
||||
make_test((True, False, True), \
|
||||
lambda self, email: self.connection.format_message_summary(email), \
|
||||
u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\n")
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\n", \
|
||||
u"encoded from (éàê)"))
|
||||
|
||||
test_format_message_summary_partial_encoded = \
|
||||
make_test((True, False, True), \
|
||||
@@ -77,35 +79,40 @@ class MailConnection_TestCase(unittest.TestCase):
|
||||
"\"" + str(email["From"]) \
|
||||
+ "\" not encoded part") or \
|
||||
self.connection.format_message_summary(email), \
|
||||
u"From : \"encoded from (éàê)\" not encoded part\nSubject " + \
|
||||
u": \"encoded subject (éàê)\" not encoded part\n\n")
|
||||
(u"From : \"encoded from (éàê)\" not encoded part\nSubject " + \
|
||||
u": \"encoded subject (éàê)\" not encoded part\n\n", \
|
||||
u"\"encoded from (éàê)\" not encoded part"))
|
||||
|
||||
test_format_message_single_not_encoded = \
|
||||
make_test((False, False, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded single part\n")
|
||||
(u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded single part\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_single_encoded = \
|
||||
make_test((True, False, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\nEncoded single part with 'iso-8859-15' charset" + \
|
||||
u" (éàê)\n")
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject " + \
|
||||
u"(éàê)\n\nEncoded single part with 'iso-8859-15' charset" + \
|
||||
u" (éàê)\n", \
|
||||
u"encoded from (éàê)"))
|
||||
|
||||
test_format_message_multi_not_encoded = \
|
||||
make_test((False, True, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded multipart1\nNot encoded multipart2\n")
|
||||
(u"From : not encoded from\nSubject : not encoded subject" + \
|
||||
u"\n\nNot encoded multipart1\nNot encoded multipart2\n", \
|
||||
u"not encoded from"))
|
||||
|
||||
test_format_message_multi_encoded = \
|
||||
make_test((True, True, True), \
|
||||
lambda self, email: self.connection.format_message(email), \
|
||||
u"From : encoded from (éàê)\nSubject : encoded subject (éà" + \
|
||||
u"ê)\n\nutf-8 multipart1 with no charset (éàê)" + \
|
||||
u"\nEncoded multipart2 with 'iso-8859-15' charset (éàê)\n" + \
|
||||
u"Encoded multipart3 with no charset (éàê)\n")
|
||||
(u"From : encoded from (éàê)\nSubject : encoded subject (éà" + \
|
||||
u"ê)\n\nutf-8 multipart1 with no charset (éàê)" + \
|
||||
u"\nEncoded multipart2 with 'iso-8859-15' charset (éàê)\n" + \
|
||||
u"Encoded multipart3 with no charset (éàê)\n", \
|
||||
u"encoded from (éàê)"))
|
||||
|
||||
|
||||
class POP3Connection_TestCase(unittest.TestCase):
|
||||
@@ -161,8 +168,9 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail_summary(1), \
|
||||
"From : user@test.com\n" + \
|
||||
"Subject : subject test\n\n"))
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n", \
|
||||
u"user@test.com")))
|
||||
|
||||
test_get_mail = \
|
||||
make_test(["+OK 10 octets\r\n" + \
|
||||
@@ -172,9 +180,10 @@ class POP3Connection_TestCase(unittest.TestCase):
|
||||
["RETR 1\r\n"], \
|
||||
lambda self: \
|
||||
self.assertEquals(self.pop3connection.get_mail(1), \
|
||||
"From : user@test.com\n" + \
|
||||
"Subject : subject test\n\n" + \
|
||||
"mymessage\n"))
|
||||
(u"From : user@test.com\n" + \
|
||||
u"Subject : subject test\n\n" + \
|
||||
u"mymessage\n", \
|
||||
u"user@test.com")))
|
||||
|
||||
|
||||
class IMAPConnection_TestCase(unittest.TestCase):
|
||||
@@ -245,7 +254,8 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
"^[^ ]* FETCH 1 \(RFC822\)", \
|
||||
"^[^ ]* STORE 1 FLAGS \(UNSEEN\)"], \
|
||||
lambda self: self.assertEquals(self.imap_connection.get_mail_summary(1), \
|
||||
"From : None\nSubject : None\n\n"))
|
||||
(u"From : None\nSubject : None\n\n", \
|
||||
u"None")))
|
||||
|
||||
test_get_mail = make_test([lambda data: "* 42 EXISTS\r\n* 1 RECENT\r\n* OK" +\
|
||||
" [UNSEEN 9]\r\n* FLAGS (\Deleted \Seen\*)\r\n*" +\
|
||||
@@ -261,5 +271,6 @@ class IMAPConnection_TestCase(unittest.TestCase):
|
||||
"^[^ ]* FETCH 1 \(RFC822\)", \
|
||||
"^[^ ]* STORE 1 FLAGS \(UNSEEN\)"], \
|
||||
lambda self: self.assertEquals(self.imap_connection.get_mail(1), \
|
||||
"From : None\nSubject : None\n\nbody text\r\n\n"))
|
||||
(u"From : None\nSubject : None\n\nbody text\r\n\n", \
|
||||
u"None")))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user