Multilang support

darcs-hash:20060128174218-86b55-4a70de917515e6938b764351be56a81991a5f95b.gz
This commit is contained in:
David Rousselie
2006-01-28 18:42:18 +01:00
parent ccde3a2bc9
commit 8fdd9d3be4
5 changed files with 358 additions and 295 deletions

33
TODO
View File

@@ -1,5 +1,3 @@
* Make real documentation
* i18n support in the same way as ejabberd and * i18n support in the same way as ejabberd and
PyMSNt, PyICQ-t and PyAIM-t: using xml:lang, but have an option in PyMSNt, PyICQ-t and PyAIM-t: using xml:lang, but have an option in
the config to set the default language to show, when the client do the config to set the default language to show, when the client do
@@ -7,38 +5,17 @@
* Database backend (default SQLLite) * Database backend (default SQLLite)
* Checkbox and radio button options in the forms to set when and how * Support for attachements with size limit and file format limit
you like to get the messages (in offline, online, free for chat, (e.g. only png, jpeg,... but no exe, bat,...).
away,... presence).
So:
Online: <radio button for notifications> <radio button for retrieving
mails> <checkbox for digest (all new mails in 1 message)>
Away: <radio button for notifications> <radio button for retrieving
mails> <checkbox for digest (all new mails in 1 message)>
Free for Chat: <radio button for notifications> <radio button for
retrieving mails> <checkbox for digest (all new mails in 1
message)>
Extended Away: <radio button for notifications> <radio button for
retrieving mails> <checkbox for digest (all new mails in 1
message)>
Offline: <radio button for notifications> <radio button for
retrieving mails> <checkbox for digest (all new mails in 1
message)>
* Dropdown menu in the forms with configurable time-intervals. E.g., * make JMC run on windows
users can choose betwoon 1 minute, 2 minutes, 5 minutes, 15
minutes, 30 minutes, 60 minutes, 1 day. The admin can configure in * Make real documentation
the configuration file of jmc which options are available.
* Support for Ad Hoc Commands (see PyMSNt cvs, avatar * Support for Ad Hoc Commands (see PyMSNt cvs, avatar
branch). Interesting for statistics. branch). Interesting for statistics.
* Support for attachements with size limit and file format limit
(e.g. only png, jpeg,... but no exe, bat,...).
* Support for epoll, kpoll and kqueu (see PyMSNt cvs, avatar branch * Support for epoll, kpoll and kqueu (see PyMSNt cvs, avatar branch
code). code).
* make JMC run on windows

View File

@@ -1,3 +1,4 @@
# -*- coding: UTF-8 -*-
## ##
## component.py ## component.py
## Login : David Rousselie <dax@happycoders.org> ## Login : David Rousselie <dax@happycoders.org>
@@ -43,6 +44,8 @@ from pyxmpp.jid import JID
from pyxmpp.jabber.disco import DiscoItems, DiscoItem, DiscoInfo, DiscoIdentity from pyxmpp.jabber.disco import DiscoItems, DiscoItem, DiscoInfo, DiscoIdentity
from pyxmpp.jabberd.component import Component from pyxmpp.jabberd.component import Component
from jabber.lang import Lang
class ComponentFatalError(RuntimeError): class ComponentFatalError(RuntimeError):
pass pass
@@ -57,6 +60,7 @@ class MailComponent(Component):
disco_type = "headline") disco_type = "headline")
self.__logger = logging.getLogger("jabber.Component") self.__logger = logging.getLogger("jabber.Component")
self.__shutdown = 0 self.__shutdown = 0
self.__default_lang = config.get_content("config/jabber/language")
# TODO : delete signals not known by Windows # TODO : delete signals not known by Windows
signal.signal(signal.SIGINT, self.signal_handler) signal.signal(signal.SIGINT, self.signal_handler)
@@ -77,8 +81,6 @@ class MailComponent(Component):
config.get_content("config/jabber/service") config.get_content("config/jabber/service")
self.__storage.spool_dir = self.__spool_dir self.__storage.spool_dir = self.__spool_dir
self.__storage.nb_pk_fields = 2 self.__storage.nb_pk_fields = 2
self.__reg_form = None
self.__reg_form_init = None
# dump registered accounts (save) every hour # dump registered accounts (save) every hour
self.__count = 60 self.__count = 60
self.running = False self.running = False
@@ -86,37 +88,46 @@ class MailComponent(Component):
def __del__(self): def __del__(self):
logging.shutdown() logging.shutdown()
""" Register Form creator """ def get_lang(self, node):
def get_reg_form(self): lang = node.getLang()
if self.__reg_form == None: if lang is None:
self.__reg_form = X() self.__logger.debug("Using default lang " + self.__default_lang)
self.__reg_form.xmlns = "jabber:x:data" lang = self.__default_lang
self.__reg_form.title = "Jabber Mail connection registration" return lang
self.__reg_form.instructions = "Enter anything below"
self.__reg_form.type = "form"
self.__reg_form.add_field(type = "text-single", \ def get_lang_class(self, lang):
label = "Connection name", \ return getattr(Lang, lang)
""" Register Form creator """
def get_reg_form(self, lang_class):
reg_form = X()
reg_form.xmlns = "jabber:x:data"
reg_form.title = lang_class.register_title
reg_form.instructions = lang_class.register_instructions
reg_form.type = "form"
reg_form.add_field(type = "text-single", \
label = lang_class.account_name, \
var = "name") var = "name")
self.__reg_form.add_field(type = "text-single", \ reg_form.add_field(type = "text-single", \
label = "Login", \ label = lang_class.account_login, \
var = "login") var = "login")
self.__reg_form.add_field(type = "text-private", \ reg_form.add_field(type = "text-private", \
label = "Password", \ label = lang_class.account_password, \
var = "password") var = "password")
self.__reg_form.add_field(type = "text-single", \ reg_form.add_field(type = "text-single", \
label = "Host", \ label = lang_class.account_host, \
var = "host") var = "host")
self.__reg_form.add_field(type = "text-single", \ reg_form.add_field(type = "text-single", \
label = "Port", \ label = lang_class.account_port, \
var = "port") var = "port")
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Mailbox type", \ label = lang_class.account_type, \
var = "type") var = "type")
field.add_option(label = "POP3", \ field.add_option(label = "POP3", \
value = "pop3") value = "pop3")
@@ -127,125 +138,124 @@ class MailComponent(Component):
field.add_option(label = "IMAPS", \ field.add_option(label = "IMAPS", \
value = "imaps") value = "imaps")
self.__reg_form.add_field(type = "text-single", \ reg_form.add_field(type = "text-single", \
label = "Mailbox (IMAP)", \ label = lang_class.account_mailbox, \
var = "mailbox", \ var = "mailbox", \
value = "INBOX") value = "INBOX")
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Free For Chat'", \ label = lang_class.account_ffc_action, \
var = "chat_action", \ var = "chat_action", \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Online'", \ label = lang_class.account_online_action, \
var = "online_action", \ var = "online_action", \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Away'", \ label = lang_class.account_away_action, \
var = "away_action", \ var = "away_action", \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Not Available'", \ label = lang_class.account_xa_action, \
var = "xa_action", \ var = "xa_action", \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Do not Disturb'", \ label = lang_class.account_dnd_action, \
var = "dnd_action", \ var = "dnd_action", \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form.add_field(type = "list-single", \ field = reg_form.add_field(type = "list-single", \
label = "Action when state is 'Offline'", \ label = lang_class.account_offline_action, \
var = "offline_action", \ var = "offline_action", \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
# default interval in config file # default interval in config file
self.__reg_form.add_field(type = "text-single", \ reg_form.add_field(type = "text-single", \
label = "Mail check interval (in minutes)", \ label = lang_class.account_check_interval, \
var = "interval", \ var = "interval", \
value = "5") value = "5")
return self.__reg_form return reg_form
""" Register Form modifier for existing accounts """ """ Register Form modifier for existing accounts """
def get_reg_form_init(self, jid, name): def get_reg_form_init(self, lang_class, jid, name):
if not self.__storage.has_key((jid, name)): if not self.__storage.has_key((jid, name)):
return None return None
account = self.__storage[(jid, name)] account = self.__storage[(jid, name)]
if self.__reg_form_init == None: reg_form_init = X()
self.__reg_form_init = X() reg_form_init.xmlns = "jabber:x:data"
self.__reg_form_init.xmlns = "jabber:x:data" reg_form_init.title = lang_class.update_title
self.__reg_form_init.title = "Jabber mail connection Modifier" reg_form_init.instructions = lang_class.update_instructions + \
self.__reg_form_init.instructions = "Modifier for connection " + \
name name
self.__reg_form_init.type = "form" reg_form_init.type = "form"
self.__reg_form_init.add_field(type = "fixed", \ reg_form_init.add_field(type = "fixed", \
label = "Connection name", \ label = lang_class.account_name, \
var = "name", \ var = "name", \
value = name) value = name)
self.__reg_form_init.add_field(type = "text-single", \ reg_form_init.add_field(type = "text-single", \
label = "Login", \ label = lang_class.account_login, \
var = "login", \ var = "login", \
value = account.login) value = account.login)
self.__reg_form_init.add_field(type = "text-private", \ reg_form_init.add_field(type = "text-private", \
label = "Password", \ label = lang_class.account_password, \
var = "password", \ var = "password", \
value = account.password) value = account.password)
self.__reg_form_init.add_field(type = "text-single", \ reg_form_init.add_field(type = "text-single", \
label = "Host", \ label = lang_class.account_host, \
var = "host", \ var = "host", \
value = account.host) value = account.host)
self.__reg_form_init.add_field(type = "text-single", \ reg_form_init.add_field(type = "text-single", \
label = "Port", \ label = lang_class.account_port, \
var = "port", \ var = "port", \
value = str(account.port)) value = unicode(account.port))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Mailbox type", \ label = lang_class.account_type, \
var = "type", \ var = "type", \
value = account.get_type()) value = account.get_type())
field.add_option(label = "POP3", \ field.add_option(label = "POP3", \
@@ -257,100 +267,87 @@ class MailComponent(Component):
field.add_option(label = "IMAPS", \ field.add_option(label = "IMAPS", \
value = "imaps") value = "imaps")
self.__reg_form_init.add_field(type = "text-single", \ reg_form_init.add_field(type = "text-single", \
label = "Mailbox (IMAP)", \ label = lang_class.account_mailbox, \
var = "mailbox") var = "mailbox")
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Free For Chat'", \ label = lang_class.account_ffc_action, \
var = "chat_action", \ var = "chat_action", \
value = str(account.chat_action)) value = str(account.chat_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Online'", \ label = lang_class.account_online_action, \
var = "online_action", \ var = "online_action", \
value = str(account.online_action)) value = str(account.online_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Away'", \ label = lang_class.account_away_action, \
var = "away_action", \ var = "away_action", \
value = str(account.away_action)) value = str(account.away_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Not Available'", \ label = lang_class.account_xa_action, \
var = "xa_action", \ var = "xa_action", \
value = str(account.xa_action)) value = str(account.xa_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Do not Disturb'", \ label = lang_class.account_dnd_action, \
var = "dnd_action", \ var = "dnd_action", \
value = str(account.dnd_action)) value = str(account.dnd_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
field = self.__reg_form_init.add_field(type = "list-single", \ field = reg_form_init.add_field(type = "list-single", \
label = "Action when state is 'Offline'", \ label = lang_class.account_offline_action, \
var = "offline_action", \ var = "offline_action", \
value = str(account.offline_action)) value = str(account.offline_action))
field.add_option(label = "Do nothing", \ field.add_option(label = lang_class.action_nothing, \
value = str(mailconnection.DO_NOTHING)) value = str(mailconnection.DO_NOTHING))
field.add_option(label = "Send mail digest", \ field.add_option(label = lang_class.action_digest, \
value = str(mailconnection.DIGEST)) value = str(mailconnection.DIGEST))
field.add_option(label = "Retrieve mail", \ field.add_option(label = lang_class.action_retrieve, \
value = str(mailconnection.RETRIEVE)) value = str(mailconnection.RETRIEVE))
self.__reg_form_init.add_field(type = "text-single", \ reg_form_init.add_field(type = "text-single", \
label = "Mail check interval (in minutes)", \ label = lang_class.account_check_interval, \
var = "interval", \ var = "interval", \
value = str(account.interval)) value = str(account.interval))
else:
self.__reg_form_init.fields["login"].value = account.login
self.__reg_form_init.fields["password"].value = account.password
self.__reg_form_init.fields["host"].value = account.host
self.__reg_form_init.fields["port"].value = str(account.port)
self.__reg_form_init.fields["type"].value = account.get_type()
self.__reg_form_init.fields["chat_action"].value = str(account.chat_action)
self.__reg_form_init.fields["online_action"].value = str(account.online_action)
self.__reg_form_init.fields["away_action"].value = str(account.away_action)
self.__reg_form_init.fields["xa_action"].value = str(account.xa_action)
self.__reg_form_init.fields["dnd_action"].value = str(account.dnd_action)
self.__reg_form_init.fields["offline_action"].value = str(account.offline_action)
self.__reg_form_init.fields["interval"].value = str(account.interval)
if account.get_type()[0:4] == "imap": if account.get_type()[0:4] == "imap":
self.__reg_form_init.fields["mailbox"].value = account.mailbox reg_form_init.fields["mailbox"].value = account.mailbox
else: else:
self.__reg_form_init.fields["mailbox"].value = "INBOX" reg_form_init.fields["mailbox"].value = u"INBOX"
return self.__reg_form_init return reg_form_init
""" Looping method """ """ Looping method """
def run(self, timeout): def run(self, timeout):
@@ -475,12 +472,13 @@ class MailComponent(Component):
""" Discovery get nested nodes handler """ """ Discovery get nested nodes handler """
def disco_get_items(self, node, iq): def disco_get_items(self, node, iq):
self.__logger.debug("DISCO_GET_ITEMS") self.__logger.debug("DISCO_GET_ITEMS")
lang_class = self.get_lang_class(self.get_lang(iq.get_node()))
base_from_jid = unicode(iq.get_from().bare()) base_from_jid = unicode(iq.get_from().bare())
di = DiscoItems() di = DiscoItems()
if not node: if not node:
for name in self.__storage.keys((base_from_jid,)): for name in self.__storage.keys((base_from_jid,)):
account = self.__storage[(base_from_jid, name)] account = self.__storage[(base_from_jid, name)]
str_name = account.get_type() + " connection " + name str_name = account.get_type() + lang_class.connection + name
if account.get_type()[0:4] == "imap": if account.get_type()[0:4] == "imap":
str_name += " (" + account.mailbox + ")" str_name += " (" + account.mailbox + ")"
DiscoItem(di, JID(name + "@" + unicode(self.jid)), \ DiscoItem(di, JID(name + "@" + unicode(self.jid)), \
@@ -500,20 +498,24 @@ class MailComponent(Component):
""" Send back register form to user """ """ Send back register form to user """
def get_register(self, iq): def get_register(self, iq):
self.__logger.debug("GET_REGISTER") self.__logger.debug("GET_REGISTER")
lang_class = self.get_lang_class(self.get_lang(iq.get_node()))
base_from_jid = unicode(iq.get_from().bare()) base_from_jid = unicode(iq.get_from().bare())
to = iq.get_to() to = iq.get_to()
iq = iq.make_result_response() iq = iq.make_result_response()
q = iq.new_query("jabber:iq:register") q = iq.new_query("jabber:iq:register")
if to and to != self.jid: if to and to != self.jid:
self.get_reg_form_init(base_from_jid, to.node).attach_xml(q) self.get_reg_form_init(lang_class,
base_from_jid,
to.node).attach_xml(q)
else: else:
self.get_reg_form().attach_xml(q) self.get_reg_form(lang_class).attach_xml(q)
self.stream.send(iq) self.stream.send(iq)
return 1 return 1
""" Handle user registration response """ """ Handle user registration response """
def set_register(self, iq): def set_register(self, iq):
self.__logger.debug("SET_REGISTER") self.__logger.debug("SET_REGISTER")
lang_class = self.get_lang_class(self.get_lang(iq.get_node()))
to = iq.get_to() to = iq.get_to()
from_jid = iq.get_from() from_jid = iq.get_from()
base_from_jid = unicode(from_jid.bare()) base_from_jid = unicode(from_jid.bare())
@@ -633,15 +635,13 @@ class MailComponent(Component):
if self.__storage.has_key((base_from_jid, name)): if self.__storage.has_key((base_from_jid, name)):
m = Message(from_jid = self.jid, to_jid = from_jid, \ m = Message(from_jid = self.jid, to_jid = from_jid, \
stanza_type = "message", \ stanza_type = "message", \
body = u"Updated %s connection '%s': Registered with "\ body = lang_class.update_account_message \
"username '%s' and password '%s' on '%s'" \
% (type, name, login, password, socket)) % (type, name, login, password, socket))
self.stream.send(m) self.stream.send(m)
else: else:
m = Message(from_jid = self.jid, to_jid = from_jid, \ m = Message(from_jid = self.jid, to_jid = from_jid, \
stanza_type = "message", \ stanza_type = "message", \
body = u"New %s connection '%s': Registered with " \ body = lang_class.new_account_message \
"username '%s' and password '%s' on '%s'" \
% (type, name, login, password, socket)) % (type, name, login, password, socket))
self.stream.send(m) self.stream.send(m)
p = Presence(from_jid = name + "@" + unicode(self.jid), \ p = Presence(from_jid = name + "@" + unicode(self.jid), \
@@ -836,6 +836,7 @@ class MailComponent(Component):
self.stream.send(mesg) self.stream.send(mesg)
account.disconnect() account.disconnect()
except Exception,e: except Exception,e:
# TODO : Send error message to the user
self.__logger.debug("Error while checking mail : %s" \ self.__logger.debug("Error while checking mail : %s" \
% (e)) % (e))

82
jabber/lang.py Normal file
View File

@@ -0,0 +1,82 @@
##
## lang.py
## Login : David Rousselie <david.rousselie@happycoders.org>
## Started on Sat Jan 28 16:37:11 2006 David Rousselie
## $Id$
##
## Copyright (C) 2006 David Rousselie
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
class Lang:
class en:
register_title = u"Jabber Mail connection registration"
register_instructions = u"Enter connection parameters"
account_name = u"Connection name"
account_login = u"Login"
account_password = u"Password"
account_host = u"Host"
account_port = u"Port"
account_type = u"Mail serveur type"
account_mailbox = u"Mailbox path (IMAP)"
account_ffc_action = u"Action when state is 'Free For Chat'"
account_online_action = u"Action when state is 'Online'"
account_away_action = u"Action when state is 'Away'"
account_xa_action = u"Action when state is 'Not Available'"
account_dnd_action = u"Action when state is 'Do not Disturb'"
account_offline_action = u"Action when state is 'Offline'"
account_check_interval = u"Mail check interval (in minutes)"
action_nothing = u"Do nothing"
action_retrieve = u"Retrieve mail"
action_digest = u"Send mail digest"
update_title = u"Jabber mail connection update"
update_instructions = u"Modifying connection "
connection = u" connection "
update_account_message = u"Updated %s connection '%s': Registered with "\
"username '%s' and password '%s' on '%s'"
new_account_message = u"New %s connection '%s': Registered with " \
"username '%s' and password '%s' on '%s'"
class fr:
register_title = u"Enregistrement d'une nouvelle connexion à un serveur email."
register_instructions = u"Entrer les paramètres de connexion"
# TODO
account_name = u"Connection name"
account_login = u"Login"
account_password = u"Password"
account_host = u"Host"
account_port = u"Port"
account_type = u"Mail serveur type"
account_mailbox = u"Mailbox path (IMAP)"
account_ffc_action = u"Action when state is 'Free For Chat'"
account_online_action = u"Action when state is 'Online'"
account_away_action = u"Action when state is 'Away'"
account_xa_action = u"Action when state is 'Not Available'"
account_dnd_action = u"Action when state is 'Do not Disturb'"
account_offline_action = u"Action when state is 'Offline'"
account_check_interval = u"Mail check interval (in minutes)"
action_nothing = u"Do nothing"
action_retrieve = u"Retrieve mail"
action_digest = u"Send mail digest"
update_title = u"Jabber mail connection update"
update_instructions = u"Modifying connection "
connection = u" connection "
update_account_message = u"Updated %s connection '%s': Registered with "\
"username '%s' and password '%s' on '%s'"
new_account_message = u"New %s connection '%s': Registered with " \
"username '%s' and password '%s' on '%s'"

3
jmc.py
View File

@@ -31,6 +31,9 @@ from jabber.config import Config
def main(config_file = "jmc.xml", isDebug = 0): def main(config_file = "jmc.xml", isDebug = 0):
try: try:
reload(sys)
sys.setdefaultencoding('utf-8')
del sys.setdefaultencoding
logger = logging.getLogger() logger = logging.getLogger()
logger.addHandler(logging.StreamHandler()) logger.addHandler(logging.StreamHandler())
if isDebug > 0: if isDebug > 0:

View File

@@ -5,7 +5,7 @@
<secret>secret</secret> <secret>secret</secret>
<service>jmc.localhost</service> <service>jmc.localhost</service>
<connectsleep>5</connectsleep> <connectsleep>5</connectsleep>
<language>fr</language> <language>en</language>
<vCard> <vCard>
<FN>Jabber Mail Component</FN> <FN>Jabber Mail Component</FN>
<DESC>A Jabber mail server component</DESC> <DESC>A Jabber mail server component</DESC>