v0.1 to v0.2 storage auto convertion
- convert automatically (while loading) registered.db v0.1 to v0.2 format darcs-hash:20060129152338-86b55-39ba1c1c7ecd5d053d2b4a578253335a2c0747d6.gz
This commit is contained in:
@@ -71,16 +71,15 @@ class MailComponent(Component):
|
|||||||
|
|
||||||
self.__interval = int(config.get_content("config/check_interval"))
|
self.__interval = int(config.get_content("config/check_interval"))
|
||||||
self.__config = config
|
self.__config = config
|
||||||
|
spool_dir = config.get_content("config/spooldir") + "/" + \
|
||||||
|
config.get_content("config/jabber/service")
|
||||||
try:
|
try:
|
||||||
self.__storage = globals()[config.get_content("config/storage") + "Storage"]()
|
self.__storage = globals()[config.get_content("config/storage") \
|
||||||
|
+ "Storage"](2, spool_dir = spool_dir)
|
||||||
except:
|
except:
|
||||||
print >>sys.stderr, "Cannot find " \
|
print >>sys.stderr, "Cannot find " \
|
||||||
+ config.get_content("config/storage") + "Storage class"
|
+ config.get_content("config/storage") + "Storage class"
|
||||||
exit(1)
|
exit(1)
|
||||||
self.__spool_dir = config.get_content("config/spooldir") + "/" + \
|
|
||||||
config.get_content("config/jabber/service")
|
|
||||||
self.__storage.spool_dir = self.__spool_dir
|
|
||||||
self.__storage.nb_pk_fields = 2
|
|
||||||
# dump registered accounts (save) every hour
|
# dump registered accounts (save) every hour
|
||||||
self.__count = 60
|
self.__count = 60
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##
|
##
|
||||||
|
|
||||||
|
import mailconnection
|
||||||
from mailconnection import IMAPConnection, POP3Connection
|
from mailconnection import IMAPConnection, POP3Connection
|
||||||
|
|
||||||
""" Static method to return an empty MailConnection object of given type
|
""" Static method to return an empty MailConnection object of given type
|
||||||
@@ -62,42 +63,57 @@ def str_to_mail_connection(connection_string):
|
|||||||
password = arg_list.pop()
|
password = arg_list.pop()
|
||||||
host = arg_list.pop()
|
host = arg_list.pop()
|
||||||
port = int(arg_list.pop())
|
port = int(arg_list.pop())
|
||||||
chat_action = int(arg_list.pop())
|
chat_action = None
|
||||||
online_action = int(arg_list.pop())
|
online_action = None
|
||||||
away_action = int(arg_list.pop())
|
away_action = None
|
||||||
xa_action = int(arg_list.pop())
|
xa_action = None
|
||||||
dnd_action = int(arg_list.pop())
|
dnd_action = None
|
||||||
offline_action = int(arg_list.pop())
|
offline_action = None
|
||||||
interval = int(arg_list.pop())
|
interval = None
|
||||||
result = None
|
if type[0:4] == "imap":
|
||||||
if type == "imap":
|
if len(arg_list) == 8:
|
||||||
|
chat_action = int(arg_list.pop())
|
||||||
|
online_action = int(arg_list.pop())
|
||||||
|
away_action = int(arg_list.pop())
|
||||||
|
xa_action = int(arg_list.pop())
|
||||||
|
dnd_action = int(arg_list.pop())
|
||||||
|
offline_action = int(arg_list.pop())
|
||||||
|
interval = int(arg_list.pop())
|
||||||
|
else:
|
||||||
|
retrieve = bool(arg_list.pop() == "True")
|
||||||
|
if retrieve:
|
||||||
|
chat_action = online_action = away_action = xa_action = dnd_action = mailconnection.RETRIEVE
|
||||||
|
else:
|
||||||
|
chat_action = online_action = away_action = xa_action = dnd_action = mailconnection.DIGEST
|
||||||
|
offline_action = mailconnection.DO_NOTHING
|
||||||
mailbox = arg_list.pop()
|
mailbox = arg_list.pop()
|
||||||
result = IMAPConnection(login = login, \
|
result = IMAPConnection(login = login, \
|
||||||
password = password, \
|
password = password, \
|
||||||
host = host, \
|
host = host, \
|
||||||
ssl = False, \
|
ssl = (len(type) == 5), \
|
||||||
port = port, \
|
port = port, \
|
||||||
mailbox = mailbox)
|
mailbox = mailbox)
|
||||||
elif type == "imaps":
|
else:
|
||||||
mailbox = arg_list.pop()
|
if len(arg_list) == 7:
|
||||||
result = IMAPConnection(login = login, \
|
chat_action = int(arg_list.pop())
|
||||||
password = password, \
|
online_action = int(arg_list.pop())
|
||||||
host = host, \
|
away_action = int(arg_list.pop())
|
||||||
port = port, \
|
xa_action = int(arg_list.pop())
|
||||||
ssl = True, \
|
dnd_action = int(arg_list.pop())
|
||||||
mailbox = mailbox)
|
offline_action = int(arg_list.pop())
|
||||||
elif type == "pop3":
|
interval = int(arg_list.pop())
|
||||||
|
else:
|
||||||
|
retrieve = bool(arg_list.pop() == "True")
|
||||||
|
if retrieve:
|
||||||
|
chat_action = online_action = away_action = xa_action = dnd_action = mailconnection.RETRIEVE
|
||||||
|
else:
|
||||||
|
chat_action = online_action = away_action = xa_action = dnd_action = mailconnection.DIGEST
|
||||||
|
offline_action = mailconnection.DO_NOTHING
|
||||||
result = POP3Connection(login = login, \
|
result = POP3Connection(login = login, \
|
||||||
password = password, \
|
password = password, \
|
||||||
host = host, \
|
host = host, \
|
||||||
port = port, \
|
port = port, \
|
||||||
ssl = False)
|
ssl = (len(type) == 5))
|
||||||
elif type == "pop3s":
|
|
||||||
result = POP3Connection(login = login, \
|
|
||||||
password = password, \
|
|
||||||
host = host, \
|
|
||||||
port = port, \
|
|
||||||
ssl = True)
|
|
||||||
if result is None:
|
if result is None:
|
||||||
raise Exception, "Connection type \"" + type + "\" unknown"
|
raise Exception, "Connection type \"" + type + "\" unknown"
|
||||||
result.chat_action = chat_action
|
result.chat_action = chat_action
|
||||||
@@ -106,7 +122,8 @@ def str_to_mail_connection(connection_string):
|
|||||||
result.xa_action = xa_action
|
result.xa_action = xa_action
|
||||||
result.dnd_action = dnd_action
|
result.dnd_action = dnd_action
|
||||||
result.offline_action = offline_action
|
result.offline_action = offline_action
|
||||||
result.interval = interval
|
if interval is not None:
|
||||||
|
result.interval = interval
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class Storage(UserDict):
|
|||||||
return self._spool_dir
|
return self._spool_dir
|
||||||
|
|
||||||
def set_spool_dir(self, spool_dir):
|
def set_spool_dir(self, spool_dir):
|
||||||
|
print "setting spool dir to " + spool_dir
|
||||||
self._spool_dir = spool_dir
|
self._spool_dir = spool_dir
|
||||||
if not os.path.isdir(self._spool_dir):
|
if not os.path.isdir(self._spool_dir):
|
||||||
os.makedirs(self._spool_dir)
|
os.makedirs(self._spool_dir)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ if __name__ == '__main__':
|
|||||||
component2_suite, \
|
component2_suite, \
|
||||||
storage_suite, \
|
storage_suite, \
|
||||||
dbmstorage_suite))
|
dbmstorage_suite))
|
||||||
test_support.run_suite(mail_connection_suite)
|
test_support.run_suite(mc_factory_suite)
|
||||||
|
|
||||||
# coverage.stop()
|
# coverage.stop()
|
||||||
# coverage.analysis(jabber.mailconnection_factory)
|
# coverage.analysis(jabber.mailconnection_factory)
|
||||||
|
|||||||
@@ -41,6 +41,37 @@ class MailConnectionFactory_TestCase(unittest.TestCase):
|
|||||||
mc = get_new_mail_connection("pop3s")
|
mc = get_new_mail_connection("pop3s")
|
||||||
self.assertEquals(mc, mc)
|
self.assertEquals(mc, mc)
|
||||||
|
|
||||||
|
def test_str_to_mail_connection_imap_v01_v02(self):
|
||||||
|
mc = str_to_mail_connection("imap#login#passwd#host#193#True#INBOX")
|
||||||
|
self.assertEquals(mc.get_type(), "imap")
|
||||||
|
self.assertEquals(mc.login, "login")
|
||||||
|
self.assertEquals(mc.password, "passwd")
|
||||||
|
self.assertEquals(mc.host, "host")
|
||||||
|
self.assertEquals(mc.port, 193)
|
||||||
|
self.assertEquals(mc.mailbox, "INBOX")
|
||||||
|
self.assertEquals(mc.chat_action, mailconnection.RETRIEVE)
|
||||||
|
self.assertEquals(mc.online_action, mailconnection.RETRIEVE)
|
||||||
|
self.assertEquals(mc.away_action, mailconnection.RETRIEVE)
|
||||||
|
self.assertEquals(mc.xa_action, mailconnection.RETRIEVE)
|
||||||
|
self.assertEquals(mc.dnd_action, mailconnection.RETRIEVE)
|
||||||
|
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||||
|
self.assertEquals(mc.interval, 5)
|
||||||
|
|
||||||
|
def test_str_to_mail_connection_pop3_v01_v02(self):
|
||||||
|
mc = str_to_mail_connection("pop3#login#passwd#host#110#False")
|
||||||
|
self.assertEquals(mc.get_type(), "pop3")
|
||||||
|
self.assertEquals(mc.login, "login")
|
||||||
|
self.assertEquals(mc.password, "passwd")
|
||||||
|
self.assertEquals(mc.host, "host")
|
||||||
|
self.assertEquals(mc.port, 110)
|
||||||
|
self.assertEquals(mc.chat_action, mailconnection.DIGEST)
|
||||||
|
self.assertEquals(mc.online_action, mailconnection.DIGEST)
|
||||||
|
self.assertEquals(mc.away_action, mailconnection.DIGEST)
|
||||||
|
self.assertEquals(mc.xa_action, mailconnection.DIGEST)
|
||||||
|
self.assertEquals(mc.dnd_action, mailconnection.DIGEST)
|
||||||
|
self.assertEquals(mc.offline_action, mailconnection.DO_NOTHING)
|
||||||
|
self.assertEquals(mc.interval, 5)
|
||||||
|
|
||||||
def test_str_to_mail_connection_imap(self):
|
def test_str_to_mail_connection_imap(self):
|
||||||
mc = str_to_mail_connection("imap#login#passwd#host#193#0#0#0#1#1#2#4#INBOX")
|
mc = str_to_mail_connection("imap#login#passwd#host#193#0#0#0#1#1#2#4#INBOX")
|
||||||
self.assertEquals(mc.get_type(), "imap")
|
self.assertEquals(mc.get_type(), "imap")
|
||||||
|
|||||||
Reference in New Issue
Block a user