package refactoring
- reorganize classes - make it run even when pysqlite2 is not installed - some tests to complete mailconnection_factory coverage darcs-hash:20060724214007-86b55-9b38308b8f645c2067c7b200f17532da62ec825c.gz
This commit is contained in:
21
run_test.py
21
run_test.py
@@ -1,6 +1,6 @@
|
|||||||
##
|
##
|
||||||
## run_test.py
|
## run_test.py
|
||||||
## Login : <david.rousselie@happycoders.org>
|
## Login : David Rousselie <dax@happycoders.org>
|
||||||
## Started on Wed May 18 13:33:03 2005 David Rousselie
|
## Started on Wed May 18 13:33:03 2005 David Rousselie
|
||||||
## $Id: run_test.py,v 1.2 2005/09/18 20:24:07 David Rousselie Exp $
|
## $Id: run_test.py,v 1.2 2005/09/18 20:24:07 David Rousselie Exp $
|
||||||
##
|
##
|
||||||
@@ -24,18 +24,21 @@ import coverage
|
|||||||
coverage.erase()
|
coverage.erase()
|
||||||
coverage.start()
|
coverage.start()
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
sys.path.append("src")
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
del sys.setdefaultencoding
|
del sys.setdefaultencoding
|
||||||
|
|
||||||
import tests
|
import tests
|
||||||
from tests.test_mailconnection import *
|
from tests.test_mailconnection import *
|
||||||
from tests.test_mailconnection_factory import *
|
from tests.test_mailconnection_factory import *
|
||||||
from tests.test_component import *
|
from tests.test_component import *
|
||||||
from tests.test_storage import *
|
from tests.test_storage import *
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import jabber
|
|
||||||
import logging
|
import logging
|
||||||
|
import jmc
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -81,10 +84,10 @@ if __name__ == '__main__':
|
|||||||
#test_support.run_suite(dbmstorage_suite)
|
#test_support.run_suite(dbmstorage_suite)
|
||||||
test_support.run_suite(jmc_suite)
|
test_support.run_suite(jmc_suite)
|
||||||
|
|
||||||
# coverage.stop()
|
coverage.stop()
|
||||||
# coverage.analysis(jabber.mailconnection_factory)
|
coverage.analysis(jmc.email.mailconnection_factory)
|
||||||
# coverage.analysis(jabber.mailconnection)
|
coverage.analysis(jmc.email.mailconnection)
|
||||||
# coverage.analysis(jabber.component)
|
coverage.analysis(jmc.jabber.component)
|
||||||
# coverage.analysis(jabber.x)
|
coverage.analysis(jmc.jabber.x)
|
||||||
# coverage.report([jabber.mailconnection_factory, jabber.mailconnection, \
|
coverage.report([jmc.email.mailconnection_factory, jmc.email.mailconnection, \
|
||||||
# jabber.component, jabber.x])
|
jmc.jabber.component, jmc.jabber.x])
|
||||||
|
|||||||
0
src/jmc/email/__init__.py
Normal file
0
src/jmc/email/__init__.py
Normal file
@@ -31,7 +31,7 @@ import poplib
|
|||||||
import imaplib
|
import imaplib
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from jabber.lang import Lang
|
from jmc.utils.lang import Lang
|
||||||
|
|
||||||
IMAP4_TIMEOUT = 10
|
IMAP4_TIMEOUT = 10
|
||||||
POP3_TIMEOUT = 10
|
POP3_TIMEOUT = 10
|
||||||
@@ -131,7 +131,7 @@ class MailConnection(object):
|
|||||||
""" Wrapper to mail connection and action.
|
""" Wrapper to mail connection and action.
|
||||||
Abstract class, do not represent real mail connection type"""
|
Abstract class, do not represent real mail connection type"""
|
||||||
|
|
||||||
_logger = logging.getLogger("jabber.MailConnection")
|
_logger = logging.getLogger("jmc.MailConnection")
|
||||||
|
|
||||||
def __init__(self, login = "", password = "", host = "", \
|
def __init__(self, login = "", password = "", host = "", \
|
||||||
port = 110, ssl = False):
|
port = 110, ssl = False):
|
||||||
@@ -327,7 +327,7 @@ class MailConnection(object):
|
|||||||
action = property(get_action)
|
action = property(get_action)
|
||||||
|
|
||||||
class IMAPConnection(MailConnection):
|
class IMAPConnection(MailConnection):
|
||||||
_logger = logging.getLogger("jabber.IMAPConnection")
|
_logger = logging.getLogger("jmc.IMAPConnection")
|
||||||
|
|
||||||
def __init__(self, login = "", password = "", host = "", \
|
def __init__(self, login = "", password = "", host = "", \
|
||||||
port = None, ssl = False, mailbox = "INBOX"):
|
port = None, ssl = False, mailbox = "INBOX"):
|
||||||
@@ -405,7 +405,7 @@ class IMAPConnection(MailConnection):
|
|||||||
type = property(get_type)
|
type = property(get_type)
|
||||||
|
|
||||||
class POP3Connection(MailConnection):
|
class POP3Connection(MailConnection):
|
||||||
_logger = logging.getLogger("jabber.POP3Connection")
|
_logger = logging.getLogger("jmc.POP3Connection")
|
||||||
|
|
||||||
def __init__(self, login = "", password = "", host = "", \
|
def __init__(self, login = "", password = "", host = "", \
|
||||||
port = None, ssl = False):
|
port = None, ssl = False):
|
||||||
@@ -20,17 +20,18 @@
|
|||||||
## 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
|
import jmc.email.mailconnection as mailconnection
|
||||||
from mailconnection import IMAPConnection, POP3Connection
|
from jmc.email.mailconnection import IMAPConnection, POP3Connection
|
||||||
|
|
||||||
""" Static method to return an empty MailConnection object of given type
|
def get_new_mail_connection(type):
|
||||||
:Parameters:
|
""" Static method to return an empty MailConnection object of given type
|
||||||
|
:Parameters:
|
||||||
- 'type': type of connection to return : 'imap', 'imaps', 'pop3', 'pop3s'
|
- 'type': type of connection to return : 'imap', 'imaps', 'pop3', 'pop3s'
|
||||||
|
|
||||||
:return: MailConnection of given type in parameter, None if unknown type
|
:return: MailConnection of given type in parameter, None if unknown type
|
||||||
|
|
||||||
:returntype: 'MailConnection'"""
|
:returntype: 'MailConnection'
|
||||||
def get_new_mail_connection(type):
|
"""
|
||||||
if type == "imap":
|
if type == "imap":
|
||||||
return IMAPConnection()
|
return IMAPConnection()
|
||||||
elif type == "imaps":
|
elif type == "imaps":
|
||||||
@@ -41,19 +42,20 @@ def get_new_mail_connection(type):
|
|||||||
return POP3Connection(ssl = True)
|
return POP3Connection(ssl = True)
|
||||||
raise Exception, "Connection type \"" + type + "\" unknown"
|
raise Exception, "Connection type \"" + type + "\" unknown"
|
||||||
|
|
||||||
""" Static methode to create a MailConnection object filled from string
|
|
||||||
|
|
||||||
:Parameters:
|
|
||||||
- 'connection_string': string containing MailConnection parameters separated
|
|
||||||
by '#'. ex: 'pop3#login#password#host#110#True'
|
|
||||||
|
|
||||||
:Types:
|
|
||||||
- 'connection_string': string
|
|
||||||
|
|
||||||
:return: MailConnection of given type found in string parameter
|
|
||||||
|
|
||||||
:returntype: 'MailConnection'"""
|
|
||||||
def str_to_mail_connection(connection_string):
|
def str_to_mail_connection(connection_string):
|
||||||
|
""" Static methode to create a MailConnection object filled from string
|
||||||
|
|
||||||
|
:Parameters:
|
||||||
|
- 'connection_string': string containing MailConnection parameters separated
|
||||||
|
by '#'. ex: 'pop3#login#password#host#110#chat_action#online_action#away_action#xa_action#dnd_action#offline_action#check_interval#liv_email_only(#Mailbox)'
|
||||||
|
|
||||||
|
:Types:
|
||||||
|
- 'connection_string': string
|
||||||
|
|
||||||
|
:return: MailConnection of given type found in string parameter
|
||||||
|
|
||||||
|
:returntype: 'MailConnection'
|
||||||
|
"""
|
||||||
arg_list = connection_string.split("#")
|
arg_list = connection_string.split("#")
|
||||||
# optionals values must be the at the beginning of the list to pop them
|
# optionals values must be the at the beginning of the list to pop them
|
||||||
# last
|
# last
|
||||||
@@ -76,6 +78,7 @@ def str_to_mail_connection(connection_string):
|
|||||||
offline_action = None
|
offline_action = None
|
||||||
interval = None
|
interval = None
|
||||||
live_email_only = False
|
live_email_only = False
|
||||||
|
result = None
|
||||||
if type[0:4] == "imap":
|
if type[0:4] == "imap":
|
||||||
if len(arg_list) == 9:
|
if len(arg_list) == 9:
|
||||||
chat_action = int(arg_list.pop())
|
chat_action = int(arg_list.pop())
|
||||||
@@ -100,7 +103,7 @@ def str_to_mail_connection(connection_string):
|
|||||||
ssl = (len(type) == 5), \
|
ssl = (len(type) == 5), \
|
||||||
port = port, \
|
port = port, \
|
||||||
mailbox = mailbox)
|
mailbox = mailbox)
|
||||||
else:
|
elif type[0:4] == "pop3":
|
||||||
if len(arg_list) == 8:
|
if len(arg_list) == 8:
|
||||||
chat_action = int(arg_list.pop())
|
chat_action = int(arg_list.pop())
|
||||||
online_action = int(arg_list.pop())
|
online_action = int(arg_list.pop())
|
||||||
0
src/jmc/jabber/__init__.py
Normal file
0
src/jmc/jabber/__init__.py
Normal file
@@ -32,11 +32,12 @@ import os
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import mailconnection
|
from jmc.email.mailconnection import *
|
||||||
from mailconnection import *
|
from jmc.jabber.x import *
|
||||||
from x import *
|
from jmc.utils.storage import *
|
||||||
from storage import *
|
from jmc.utils.lang import Lang
|
||||||
import mailconnection_factory
|
import jmc.email.mailconnection_factory
|
||||||
|
|
||||||
import pyxmpp.jabberd
|
import pyxmpp.jabberd
|
||||||
from pyxmpp.presence import Presence
|
from pyxmpp.presence import Presence
|
||||||
from pyxmpp.message import Message
|
from pyxmpp.message import Message
|
||||||
@@ -45,8 +46,6 @@ 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
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ class MailComponent(Component):
|
|||||||
port, \
|
port, \
|
||||||
disco_category = "gateway", \
|
disco_category = "gateway", \
|
||||||
disco_type = "headline")
|
disco_type = "headline")
|
||||||
self.__logger = logging.getLogger("jabber.Component")
|
self.__logger = logging.getLogger("jmc.jabber.Component")
|
||||||
self.__shutdown = 0
|
self.__shutdown = 0
|
||||||
self.__lang = Lang(default_lang)
|
self.__lang = Lang(default_lang)
|
||||||
self.__name = name
|
self.__name = name
|
||||||
@@ -30,9 +30,9 @@ reload(sys)
|
|||||||
sys.setdefaultencoding('utf-8')
|
sys.setdefaultencoding('utf-8')
|
||||||
del sys.setdefaultencoding
|
del sys.setdefaultencoding
|
||||||
|
|
||||||
from jabber import mailconnection
|
from jmc import mailconnection
|
||||||
from jabber.component import MailComponent, ComponentFatalError
|
from jmc.component import MailComponent, ComponentFatalError
|
||||||
from jabber.config import Config
|
from jmc.config import Config
|
||||||
|
|
||||||
def main(config_file = "jmc.xml", isDebug = 0):
|
def main(config_file = "jmc.xml", isDebug = 0):
|
||||||
try:
|
try:
|
||||||
@@ -87,5 +87,5 @@ if __name__ == "__main__":
|
|||||||
if (var_option & 2) == 2:
|
if (var_option & 2) == 2:
|
||||||
main(sys.argv[file_num], debug_level)
|
main(sys.argv[file_num], debug_level)
|
||||||
else:
|
else:
|
||||||
main("jmc.xml", debug_level)
|
main("/etc/jabber/jmc.xml", debug_level)
|
||||||
|
|
||||||
0
src/jmc/utils/__init__.py
Normal file
0
src/jmc/utils/__init__.py
Normal file
@@ -24,7 +24,7 @@ import libxml2
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from pyxmpp.jid import JID
|
from pyxmpp.jid import JID
|
||||||
from component import ComponentFatalError
|
from jmc.jabber.component import ComponentFatalError
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, config_file):
|
def __init__(self, config_file):
|
||||||
33
src/jmc/utils/release.py
Normal file
33
src/jmc/utils/release.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
##
|
||||||
|
## release.py
|
||||||
|
## Login : David Rousselie <dax@happycoders.org>
|
||||||
|
## Started on Mon Jul 24 22:37:00 2006 dax
|
||||||
|
## $Id$
|
||||||
|
##
|
||||||
|
## Copyright (C) 2006 dax
|
||||||
|
## 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
|
||||||
|
##
|
||||||
|
|
||||||
|
version = "0.2.2"
|
||||||
|
author = "David Rousselie"
|
||||||
|
email = "dax@happycoders.org"
|
||||||
|
license = "GPL"
|
||||||
|
long_description = """Jabber Mail Component
|
||||||
|
|
||||||
|
JMC is a jabber service to check email from POP3 and IMAP4 server and retrieve
|
||||||
|
them or just a notification of new emails. Jabber users can register multiple
|
||||||
|
email accounts.
|
||||||
|
|
||||||
|
"""
|
||||||
@@ -25,10 +25,10 @@ import re
|
|||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import anydbm
|
import anydbm
|
||||||
import mailconnection_factory
|
|
||||||
import logging
|
import logging
|
||||||
from UserDict import UserDict
|
from UserDict import UserDict
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
|
||||||
|
import jmc.email.mailconnection_factory as mailconnection_factory
|
||||||
|
|
||||||
|
|
||||||
class Storage(UserDict):
|
class Storage(UserDict):
|
||||||
@@ -106,7 +106,7 @@ class Storage(UserDict):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class DBMStorage(Storage):
|
class DBMStorage(Storage):
|
||||||
_logger = logging.getLogger("jabber.DBMStorage")
|
_logger = logging.getLogger("jmc.utils.DBMStorage")
|
||||||
|
|
||||||
def __init__(self, nb_pk_fields = 1, spool_dir = ".", db_file = None):
|
def __init__(self, nb_pk_fields = 1, spool_dir = ".", db_file = None):
|
||||||
# print "DBM INIT"
|
# print "DBM INIT"
|
||||||
@@ -166,127 +166,132 @@ class DBMStorage(Storage):
|
|||||||
Storage.__delitem__(self, pk_tuple)
|
Storage.__delitem__(self, pk_tuple)
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
|
# Do not fail if pysqlite is not installed
|
||||||
|
try:
|
||||||
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
|
|
||||||
class SQLiteStorage(Storage):
|
class SQLiteStorage(Storage):
|
||||||
_logger = logging.getLogger("jabber.SQLiteStorage")
|
_logger = logging.getLogger("jmc.utils.SQLiteStorage")
|
||||||
|
|
||||||
def __init__(self, nb_pk_fields = 1, spool_dir = ".", db_file = None):
|
def __init__(self, nb_pk_fields = 1, spool_dir = ".", db_file = None):
|
||||||
self.__connection = None
|
self.__connection = None
|
||||||
Storage.__init__(self, nb_pk_fields, spool_dir, db_file)
|
Storage.__init__(self, nb_pk_fields, spool_dir, db_file)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
SQLiteStorage._logger.debug("creating new Table")
|
SQLiteStorage._logger.debug("creating new Table")
|
||||||
cursor = self.__connection.cursor()
|
cursor = self.__connection.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
create table account(
|
create table account(
|
||||||
jid STRING,
|
jid STRING,
|
||||||
name STRING,
|
name STRING,
|
||||||
type STRING,
|
type STRING,
|
||||||
login STRING,
|
login STRING,
|
||||||
password STRING,
|
password STRING,
|
||||||
host STRING,
|
host STRING,
|
||||||
port INTEGER,
|
port INTEGER,
|
||||||
chat_action INTEGER,
|
chat_action INTEGER,
|
||||||
online_action INTEGER,
|
online_action INTEGER,
|
||||||
away_action INTEGER,
|
away_action INTEGER,
|
||||||
xa_action INTEGER,
|
xa_action INTEGER,
|
||||||
dnd_action INTEGER,
|
dnd_action INTEGER,
|
||||||
offline_action INTEGER,
|
offline_action INTEGER,
|
||||||
interval INTEGER,
|
interval INTEGER,
|
||||||
live_email_only BOOLEAN,
|
live_email_only BOOLEAN,
|
||||||
mailbox STRING,
|
mailbox STRING,
|
||||||
PRIMARY KEY(jid, name)
|
PRIMARY KEY(jid, name)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
self.__connection.commit()
|
self.__connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.__connection.close()
|
self.__connection.close()
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
if not os.path.exists(self.file):
|
if not os.path.exists(self.file):
|
||||||
self.__connection = sqlite.connect(self.file)
|
self.__connection = sqlite.connect(self.file)
|
||||||
self.create()
|
self.create()
|
||||||
else:
|
|
||||||
self.__connection = sqlite.connect(self.file)
|
|
||||||
cursor = self.__connection.cursor()
|
|
||||||
cursor.execute("""select * from account""")
|
|
||||||
result = {}
|
|
||||||
for row in cursor.fetchall():
|
|
||||||
# print "Creating new " + row[self.nb_pk_fields] + " connection."
|
|
||||||
account_type = row[self.nb_pk_fields]
|
|
||||||
account = result["#".join(row[0:self.nb_pk_fields])] = mailconnection_factory.get_new_mail_connection(account_type)
|
|
||||||
account.login = row[self.nb_pk_fields + 1]
|
|
||||||
account.password = row[self.nb_pk_fields + 2]
|
|
||||||
if account.password is None:
|
|
||||||
account.store_password = False
|
|
||||||
else:
|
else:
|
||||||
account.store_password = True
|
self.__connection = sqlite.connect(self.file)
|
||||||
account.host = row[self.nb_pk_fields + 3]
|
cursor = self.__connection.cursor()
|
||||||
account.port = int(row[self.nb_pk_fields + 4])
|
cursor.execute("""select * from account""")
|
||||||
account.chat_action = int(row[self.nb_pk_fields + 5])
|
result = {}
|
||||||
account.online_action = int(row[self.nb_pk_fields + 6])
|
for row in cursor.fetchall():
|
||||||
account.away_action = int(row[self.nb_pk_fields + 7])
|
# print "Creating new " + row[self.nb_pk_fields] + " connection."
|
||||||
account.xa_action = int(row[self.nb_pk_fields + 8])
|
account_type = row[self.nb_pk_fields]
|
||||||
account.dnd_action = int(row[self.nb_pk_fields + 9])
|
account = result["#".join(row[0:self.nb_pk_fields])] = mailconnection_factory.get_new_mail_connection(account_type)
|
||||||
account.offline_action = int(row[self.nb_pk_fields + 10])
|
account.login = row[self.nb_pk_fields + 1]
|
||||||
account.interval = int(row[self.nb_pk_fields + 11])
|
account.password = row[self.nb_pk_fields + 2]
|
||||||
account.live_email_only = (row[self.nb_pk_fields + 12] == 1)
|
if account.password is None:
|
||||||
if account_type[0:4] == "imap":
|
account.store_password = False
|
||||||
account.mailbox = row[self.nb_pk_fields + 13]
|
else:
|
||||||
# for field_index in range(self.nb_pk_fields + 1, len(row)):
|
account.store_password = True
|
||||||
# print "\tSetting " + str(cursor.description[field_index][0]) + \
|
account.host = row[self.nb_pk_fields + 3]
|
||||||
# " to " + str(row[field_index])
|
account.port = int(row[self.nb_pk_fields + 4])
|
||||||
# setattr(account,
|
account.chat_action = int(row[self.nb_pk_fields + 5])
|
||||||
# cursor.description[field_index][0],
|
account.online_action = int(row[self.nb_pk_fields + 6])
|
||||||
# row[field_index])
|
account.away_action = int(row[self.nb_pk_fields + 7])
|
||||||
cursor.close()
|
account.xa_action = int(row[self.nb_pk_fields + 8])
|
||||||
return result
|
account.dnd_action = int(row[self.nb_pk_fields + 9])
|
||||||
|
account.offline_action = int(row[self.nb_pk_fields + 10])
|
||||||
|
account.interval = int(row[self.nb_pk_fields + 11])
|
||||||
|
account.live_email_only = (row[self.nb_pk_fields + 12] == 1)
|
||||||
|
if account_type[0:4] == "imap":
|
||||||
|
account.mailbox = row[self.nb_pk_fields + 13]
|
||||||
|
# for field_index in range(self.nb_pk_fields + 1, len(row)):
|
||||||
|
# print "\tSetting " + str(cursor.description[field_index][0]) + \
|
||||||
|
# " to " + str(row[field_index])
|
||||||
|
# setattr(account,
|
||||||
|
# cursor.description[field_index][0],
|
||||||
|
# row[field_index])
|
||||||
|
cursor.close()
|
||||||
|
return result
|
||||||
|
|
||||||
def __setitem__(self, pk_tuple, obj):
|
def __setitem__(self, pk_tuple, obj):
|
||||||
Storage.__setitem__(self, pk_tuple, obj)
|
Storage.__setitem__(self, pk_tuple, obj)
|
||||||
cursor = self.__connection.cursor()
|
cursor = self.__connection.cursor()
|
||||||
mailbox = None
|
mailbox = None
|
||||||
password = None
|
password = None
|
||||||
if obj.type[0:4] == "imap":
|
if obj.type[0:4] == "imap":
|
||||||
mailbox = obj.mailbox
|
mailbox = obj.mailbox
|
||||||
if obj.store_password == True:
|
if obj.store_password == True:
|
||||||
password = obj.password
|
password = obj.password
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
insert or replace into account values
|
insert or replace into account values
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(pk_tuple[0],
|
(pk_tuple[0],
|
||||||
pk_tuple[1],
|
pk_tuple[1],
|
||||||
obj.type,
|
obj.type,
|
||||||
obj.login,
|
obj.login,
|
||||||
password,
|
password,
|
||||||
obj.host,
|
obj.host,
|
||||||
obj.port,
|
obj.port,
|
||||||
obj.chat_action,
|
obj.chat_action,
|
||||||
obj.online_action,
|
obj.online_action,
|
||||||
obj.away_action,
|
obj.away_action,
|
||||||
obj.xa_action,
|
obj.xa_action,
|
||||||
obj.dnd_action,
|
obj.dnd_action,
|
||||||
obj.offline_action,
|
obj.offline_action,
|
||||||
obj.interval,
|
obj.interval,
|
||||||
obj.live_email_only,
|
obj.live_email_only,
|
||||||
mailbox))
|
mailbox))
|
||||||
self.__connection.commit()
|
self.__connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
def __delitem__(self, pk_tuple):
|
def __delitem__(self, pk_tuple):
|
||||||
Storage.__delitem__(self, pk_tuple)
|
Storage.__delitem__(self, pk_tuple)
|
||||||
cursor = self.__connection.cursor()
|
cursor = self.__connection.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
delete from account where jid = ? and name = ?
|
delete from account where jid = ? and name = ?
|
||||||
""",
|
""",
|
||||||
(pk_tuple[0],
|
(pk_tuple[0],
|
||||||
pk_tuple[1]))
|
pk_tuple[1]))
|
||||||
self.__connection.commit()
|
self.__connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ import dummy_server
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from pyxmpp import xmlextra
|
from pyxmpp import xmlextra
|
||||||
from jabber.component import *
|
from jmc.jabber.component import *
|
||||||
from jabber.config import Config
|
from jmc.utils.config import Config
|
||||||
|
|
||||||
class TestStreamHandler(xmlextra.StreamHandler):
|
class TestStreamHandler(xmlextra.StreamHandler):
|
||||||
def __init__(self, expected_balises = []):
|
def __init__(self, expected_balises = []):
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from jabber.mailconnection import IMAPConnection, \
|
from jmc.email.mailconnection import IMAPConnection, \
|
||||||
POP3Connection, \
|
POP3Connection, \
|
||||||
MailConnection
|
MailConnection
|
||||||
import dummy_server
|
import dummy_server
|
||||||
|
|||||||
@@ -21,28 +21,49 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from jabber.mailconnection_factory import *
|
from jmc.email.mailconnection_factory import *
|
||||||
from jabber import mailconnection
|
from jmc.email.mailconnection import *
|
||||||
|
import jmc.email.mailconnection as mailconnection
|
||||||
|
|
||||||
class MailConnectionFactory_TestCase(unittest.TestCase):
|
class MailConnectionFactory_TestCase(unittest.TestCase):
|
||||||
def test_new_mail_connection_imap(self):
|
def test_new_mail_connection_imap(self):
|
||||||
mc = get_new_mail_connection("imap")
|
mc = get_new_mail_connection("imap")
|
||||||
# TODO
|
self.assertEquals(mc, IMAPConnection())
|
||||||
self.assertEquals(mc, mc)
|
|
||||||
|
|
||||||
def test_new_mail_connection_imaps(self):
|
def test_new_mail_connection_imaps(self):
|
||||||
mc = get_new_mail_connection("imaps")
|
mc = get_new_mail_connection("imaps")
|
||||||
self.assertEquals(mc, mc)
|
self.assertEquals(mc, IMAPConnection(ssl = True))
|
||||||
|
|
||||||
def test_new_mail_connection_pop3(self):
|
def test_new_mail_connection_pop3(self):
|
||||||
mc = get_new_mail_connection("pop3")
|
mc = get_new_mail_connection("pop3")
|
||||||
self.assertEquals(mc, mc)
|
self.assertEquals(mc, POP3Connection())
|
||||||
|
|
||||||
def test_new_mail_connection_pop3s(self):
|
def test_new_mail_connection_pop3s(self):
|
||||||
mc = get_new_mail_connection("pop3s")
|
mc = get_new_mail_connection("pop3s")
|
||||||
self.assertEquals(mc, mc)
|
self.assertEquals(mc, POP3Connection(ssl = True))
|
||||||
|
|
||||||
|
def test_new_mail_connection_unknown(self):
|
||||||
|
self.assertRaises(Exception, get_new_mail_connection, "unknown")
|
||||||
|
|
||||||
def test_str_to_mail_connection_imap_v01_v02(self):
|
def test_str_to_mail_connection_imap_v01_v02(self):
|
||||||
|
mc = str_to_mail_connection("imap#login#passwd#host#193#False#INBOX")
|
||||||
|
self.assertEquals(mc.get_type(), "imap")
|
||||||
|
self.assertEquals(mc.login, "login")
|
||||||
|
self.assertEquals(mc.password, "passwd")
|
||||||
|
self.assertEquals(mc.store_password, True)
|
||||||
|
self.assertEquals(mc.host, "host")
|
||||||
|
self.assertEquals(mc.port, 193)
|
||||||
|
self.assertEquals(mc.mailbox, "INBOX")
|
||||||
|
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)
|
||||||
|
self.assertEquals(mc.live_email_only, False)
|
||||||
|
|
||||||
|
def test_str_to_mail_connection_imap_v01_v02_retrieve(self):
|
||||||
mc = str_to_mail_connection("imap#login#passwd#host#193#True#INBOX")
|
mc = str_to_mail_connection("imap#login#passwd#host#193#True#INBOX")
|
||||||
self.assertEquals(mc.get_type(), "imap")
|
self.assertEquals(mc.get_type(), "imap")
|
||||||
self.assertEquals(mc.login, "login")
|
self.assertEquals(mc.login, "login")
|
||||||
@@ -77,6 +98,23 @@ class MailConnectionFactory_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(mc.interval, 5)
|
self.assertEquals(mc.interval, 5)
|
||||||
self.assertEquals(mc.live_email_only, False)
|
self.assertEquals(mc.live_email_only, False)
|
||||||
|
|
||||||
|
def test_str_to_mail_connection_pop3_v01_v02_retrieve(self):
|
||||||
|
mc = str_to_mail_connection("pop3#login#passwd#host#110#True")
|
||||||
|
self.assertEquals(mc.get_type(), "pop3")
|
||||||
|
self.assertEquals(mc.login, "login")
|
||||||
|
self.assertEquals(mc.password, "passwd")
|
||||||
|
self.assertEquals(mc.store_password, True)
|
||||||
|
self.assertEquals(mc.host, "host")
|
||||||
|
self.assertEquals(mc.port, 110)
|
||||||
|
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)
|
||||||
|
self.assertEquals(mc.live_email_only, False)
|
||||||
|
|
||||||
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#True#INBOX")
|
mc = str_to_mail_connection("imap#login#passwd#host#193#0#0#0#1#1#2#4#True#INBOX")
|
||||||
self.assertEquals(mc.get_type(), "imap")
|
self.assertEquals(mc.get_type(), "imap")
|
||||||
@@ -161,3 +199,6 @@ class MailConnectionFactory_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(mc.interval, 4)
|
self.assertEquals(mc.interval, 4)
|
||||||
self.assertEquals(mc.live_email_only, True)
|
self.assertEquals(mc.live_email_only, True)
|
||||||
|
|
||||||
|
def test_str_to_mail_connection_unknown(self):
|
||||||
|
self.assertRaises(Exception, str_to_mail_connection, ("unknown#login#passwd#host#995#0#0#0#1#1#2#4#True"))
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import dummy_server
|
import dummy_server
|
||||||
from jabber.storage import *
|
from jmc.utils.storage import *
|
||||||
from jabber import mailconnection
|
from jmc.email.mailconnection import *
|
||||||
from jabber.mailconnection import *
|
import jmc.email.mailconnection as mailconnection
|
||||||
|
|
||||||
class Storage_TestCase(unittest.TestCase):
|
class Storage_TestCase(unittest.TestCase):
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from jabber.x import *
|
from jmc.jabber.x import *
|
||||||
|
|
||||||
class X_TestCase(unittest.TestCase):
|
class X_TestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user