first import
first import between version 0.1.3 and 0.2 darcs-hash:20051127110300-684f5-0ed50cd0e86df9195cec2c1df070fdf24a6faeb5.gz
This commit is contained in:
108
jabber/mailconnection_factory.py
Normal file
108
jabber/mailconnection_factory.py
Normal file
@@ -0,0 +1,108 @@
|
||||
##
|
||||
## mailconnection_factory.py
|
||||
## Login : <adro8400@claralinux>
|
||||
## Started on Fri May 20 10:41:46 2005 adro8400
|
||||
## $Id: mailconnection_factory.py,v 1.2 2005/09/18 20:24:07 dax Exp $
|
||||
##
|
||||
## Copyright (C) 2005 adro8400
|
||||
## 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
|
||||
##
|
||||
|
||||
from mailconnection import IMAPConnection, POP3Connection
|
||||
|
||||
""" Static method to return an empty MailConnection object of given type
|
||||
:Parameters:
|
||||
- 'type': type of connection to return : 'imap', 'imaps', 'pop3', 'pop3s'
|
||||
|
||||
:return: MailConnection of given type in parameter, None if unknown type
|
||||
|
||||
:returntype: 'MailConnection'"""
|
||||
def get_new_mail_connection(type):
|
||||
if type == "imap":
|
||||
return IMAPConnection()
|
||||
elif type == "imaps":
|
||||
return IMAPConnection(ssl = True)
|
||||
elif type == "pop3":
|
||||
return POP3Connection()
|
||||
elif type == "pop3s":
|
||||
return POP3Connection(ssl = True)
|
||||
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):
|
||||
arg_list = connection_string.split("#")
|
||||
# optionals values must be the at the beginning of the list to pop them
|
||||
# last
|
||||
arg_list.reverse()
|
||||
type = arg_list.pop()
|
||||
login = arg_list.pop()
|
||||
password = arg_list.pop()
|
||||
host = arg_list.pop()
|
||||
port = int(arg_list.pop())
|
||||
ffc_action = int(arg_list.pop())
|
||||
online_action = int(arg_list.pop())
|
||||
away_action = int(arg_list.pop())
|
||||
ea_action = int(arg_list.pop())
|
||||
offline_action = int(arg_list.pop())
|
||||
result = None
|
||||
if type == "imap":
|
||||
mailbox = arg_list.pop()
|
||||
result = IMAPConnection(login = login, \
|
||||
password = password, \
|
||||
host = host, \
|
||||
ssl = False, \
|
||||
port = port, \
|
||||
mailbox = mailbox)
|
||||
elif type == "imaps":
|
||||
mailbox = arg_list.pop()
|
||||
result = IMAPConnection(login = login, \
|
||||
password = password, \
|
||||
host = host, \
|
||||
port = port, \
|
||||
ssl = True, \
|
||||
mailbox = mailbox)
|
||||
elif type == "pop3":
|
||||
result = POP3Connection(login = login, \
|
||||
password = password, \
|
||||
host = host, \
|
||||
port = port, \
|
||||
ssl = False)
|
||||
elif type == "pop3s":
|
||||
result = POP3Connection(login = login, \
|
||||
password = password, \
|
||||
host = host, \
|
||||
port = port, \
|
||||
ssl = True)
|
||||
if result is None:
|
||||
raise Exception, "Connection type \"" + type + "\" unknown"
|
||||
result.ffc_action = ffc_action
|
||||
result.online_action = online_action
|
||||
result.away_action = away_action
|
||||
result.ea_action = ea_action
|
||||
result.offline_action = offline_action
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user