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:
David Rousselie
2006-02-06 14:37:41 +01:00
parent 8dc5a2aaa5
commit e5e80b2b0a
4 changed files with 71 additions and 44 deletions

View File

@@ -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,7 +687,8 @@ class MailComponent(Component):
if type[0:4] == "imap":
account.mailbox = mailbox
self.__storage[(base_from_jid, name)] = account
return 1
""" Handle presence availability """
@@ -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

View File

@@ -78,7 +78,9 @@ 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."
register_instructions = u"Entrer les paramètres de connexion"
@@ -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)"

View File

@@ -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)