[PyWebMail-Checkins] webmail/webmail/backends __init__.py, 1.5, 1.6 smtp.py, 1.3, 1.4
Status: Beta
Brought to you by:
dubnerm
From: Michael D. <du...@us...> - 2007-12-08 08:03:05
|
Update of /cvsroot/pywebmail/webmail/webmail/backends In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14030/backends Modified Files: __init__.py smtp.py Log Message: support outbox - message sending backends Index: smtp.py =================================================================== RCS file: /cvsroot/pywebmail/webmail/webmail/backends/smtp.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** smtp.py 2 Dec 2004 10:10:10 -0000 1.3 --- smtp.py 8 Dec 2007 08:03:08 -0000 1.4 *************** *** 1,7 **** ! import sys, thread, rfc822 try: from cStringIO import StringIO except: from StringIO import StringIO import webmail.utils.smtp from webmail.utils.backend_helpers import MessageInfoBase server = None --- 1,10 ---- ! import sys, logging, thread, rfc822, smtplib try: from cStringIO import StringIO except: from StringIO import StringIO import webmail.utils.smtp from webmail.utils.backend_helpers import MessageInfoBase + from webmail.utils.expr_helper import a2bool + + log = logging.getLogger('webmail.backends.smtp'); server = None *************** *** 9,13 **** global server if server is not None: return ! server = webmail.utils.smtp.SMTPServer(('',25)) thread.start_new_thread(server.loop, ()) --- 12,16 ---- global server if server is not None: return ! server = webmail.utils.smtp.SMTPServer(('127.0.0.1',25)) thread.start_new_thread(server.loop, ()) *************** *** 103,106 **** --- 106,162 ---- return folder + class SMTPTransport: + + def __init__(self, main_config, box_config): + self.email = box_config.get('from_email',None) + if self.email is None: + self.email = box_config['email'] + self.localhost = box_config.get('smtp_localhost',None) + self.debug = a2bool(box_config.get('smtp_debug','0')) + self.user = box_config.get('smtp_user') + self.auth = a2bool(box_config.get('smtp_auth','10'[not self.user])) + if self.auth and not self.user: + self.user = box_config.get('user') + if self.auth and not self.user: + self.user = box_config['email'] + if self.auth: + self.password = box_config.get('smtp_password') + if self.auth and not self.password: + self.password = box_config['password'] + host = box_config['out_server'] + port = None + try: + host,port = host.split(':',1) + port = int(port) + except: + pass + if box_config.has_key('port'): + port = int(box_config['port']) + self.host,self.port = host,port + + def send(self, msg): + headers = rfc822.Message(StringIO(msg)) + recipients = [] + l = headers.getaddrlist('to') + if l: recipients.extend(zip(*l)[1]) + l = headers.getaddrlist('cc') + if l: recipients.extend(zip(*l)[1]) + l = headers.getaddrlist('bcc') + if l: recipients.extend(zip(*l)[1]) + sender = headers.getaddr('from') + assert sender[0].lower() != self.email.lower(), "Sender sanity check failed" + smtp = smtplib.SMTP(local_hostname=self.localhost) + smtp.set_debuglevel(self.debug) + smtp.connect(self.host, self.port) + #code,data = smtp.helo() + #log.debug('SMTP outbox: HELO %s: %s %s', smtp.local_hostname, code, data) + code,data = smtp.ehlo() + log.debug('SMTP outbox: EHLO %s: %s %s', smtp.local_hostname, code, data) + if self.auth: + smtp.login(self.user, self.password) + smtp.sendmail(sender, recipients, msg) + smtp.quit() + + outbox_factory = SMTPTransport mailbox_factory = SMTPAccount Index: __init__.py =================================================================== RCS file: /cvsroot/pywebmail/webmail/webmail/backends/__init__.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** __init__.py 4 Aug 2007 10:34:19 -0000 1.5 --- __init__.py 8 Dec 2007 08:03:08 -0000 1.6 *************** *** 1,5 **** import sys ! def get_default_backend(mailbox_info): #if mailbox_info.has_key('file'): return 'file' # not yet supported if mailbox_info.has_key('server'): --- 1,5 ---- import sys ! def get_default_mailbox_backend(mailbox_info): #if mailbox_info.has_key('file'): return 'file' # not yet supported if mailbox_info.has_key('server'): *************** *** 22,25 **** --- 22,44 ---- return 'web' + get_default_backend = get_default_mailbox_backend + + def get_default_outbox_backend(mailbox_info): + return 'smtp' # nothing else implemented yet + if mailbox_info.has_key('out_server'): + return 'smtp' # imap not yet implemented + host = mailbox_info['out_server'] + port = None + try: + host,port = host.split(':',1) + port = int(port) + except: + pass + if mailbox_info.has_key('port'): + port = int(mailbox_info['port']) + #if port in (143, 993): return 'imap' # imap not yet supported + return 'smtp' + return 'web' + def get_backend_module(backend_name): backend_module = globals().get(backend_name) |