[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/SMTP - SMTPServer.py:1.1.2.4 SMTPServerChannel.py:1.1.2.5
Stephan Richter
srichter@cbu.edu
Thu, 11 Apr 2002 00:32:42 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Server/SMTP
In directory cvs.zope.org:/tmp/cvs-serv25892/lib/python/Zope/Server/SMTP
Modified Files:
Tag: Zope3-Server-Branch
SMTPServer.py SMTPServerChannel.py
Log Message:
Wee, quiet a bit of changes, but they fix and finnish the stuff Shane did
earlier today.
- Removed a lot of old files and moved some to more appropriate places. The
removal of the Suthentication directory is probably the biggest one. I
also deleted all the other FileSystem types, like MSDOS and Unix, since
the FielSystem is not returning formatted lists anymore. Yipee!
- Fixed PublisherFTPServer, so it works with Shane's new Credentials
interfaces. Everything should be working fine again.
- Fixed the POP3 and SMTP code to work with the new model. It all works
really well. I hope that Gerson Kurz will take over this development
soon. I also contacted authors of other server protocols, and they might
join. Rich Salz is already writing a method for ZSI, so that we can
insert SOAP in the next days.
- Made most tests run again and updated them. I still have one error. I know
why it is caused, but I do not know how to correct. I know it is a test
environment problem though, not a code one.
=== Zope3/lib/python/Zope/Server/SMTP/SMTPServer.py 1.1.2.3 => 1.1.2.4 ===
from Zope.Server.ServerBase import ServerBase
-from Zope.Server.VFS.UnixFileSystem import UnixFileSystem
-from Zope.Server.Authentication.DictionaryAuthentication import \
- DictionaryAuthentication
+from Zope.Server.VFS.OSFileSystem import OSFileSystem
+from Zope.Server.VFS.IFilesystemAccess import IFilesystemAccess
class SMTPServer(ServerBase):
@@ -31,23 +30,27 @@
channel_class = SMTPServerChannel
SERVER_IDENT = 'Zope.Server.SMTPServer'
- storage = UnixFileSystem('/opt/ZopeMail')
- auth_source = DictionaryAuthentication({'foo': 'bar'})
config = SMTPConfigurations
- def __init__(self, ip, port, maildir, auth, *args, **kw):
+ def __init__(self, ip, port, maildir, *args, **kw):
- self.auth_source = auth
- self.maildir = UnixFileSystem(maildir)
+ assert IFilesystemAccess.isImplementedBy(maildir)
+ self.maildir = maildir
super(SMTPServer, self).__init__(ip, port, *args, **kw)
+
if __name__ == '__main__':
from Zope.Server.TaskThreads import ThreadedTaskDispatcher
+ from Zope.Server.VFS.OSFileSystem import OSFileSystem
+ from Zope.Server.VFS.TestFilesystemAccess import TestFilesystemAccess
+ td = ThreadedTaskDispatcher()
+ td.setThreadCount(4)
+ fs = OSFileSystem('/opt/ZopeMail')
+ maildir = TestFilesystemAccess(fs)
td = ThreadedTaskDispatcher()
td.setThreadCount(4)
- auth_source = DictionaryAuthentication({'foo': 'bar'})
- SMTPServer('', 25, '/var/mail', auth_source, task_dispatcher=td)
+ SMTPServer('', 25, maildir, task_dispatcher=td)
try:
while 1:
asyncore.poll(5)
=== Zope3/lib/python/Zope/Server/SMTP/SMTPServerChannel.py 1.1.2.4 => 1.1.2.5 ===
import fnmatch
import socket
+from cStringIO import StringIO
from Zope.Server.LineReceiver.LineServerChannel import LineServerChannel
+from Zope.Server.VFS.UsernamePassword import UsernamePassword
from SMTPStatusMessages import status_msgs
from ISMTPCommandHandler import ISMTPCommandHandler
@@ -101,6 +103,12 @@
data = data[n:]
+ def _getFilesystem(self):
+ """Open the filesystem using the current credentials."""
+ credentials = UsernamePassword('foo', 'bar')
+ return self.server.maildir.open(credentials)
+
+
############################################################
# Implementation methods for interface
# Zope.Server.SMTP.ISMTPCommandHandler
@@ -140,7 +148,6 @@
'See Zope.Server.SMTP.ISMTPCommandHandler.ISMTPCommandHandler'
self.reply('HELP')
-
def cmd_mail(self, args):
'See Zope.Server.SMTP.ISMTPCommandHandler.ISMTPCommandHandler'
args = args.split(':')
@@ -218,11 +225,10 @@
if receiver[0] == '<' or receiver[-1] == '>':
receiver = receiver[1:-1]
mailbox = receiver.split('@')[0]
- file = self.server.maildir.open(mailbox, 'a')
- file.write('From %s %s\n' %(self._from,
- time.strftime(self.datetime_format)))
- file.write(self._message+'\n\n')
- file.close()
+ data = 'From %s %s\n' %(self._from,
+ time.strftime(self.datetime_format))
+ data += self._message+'\n\n'
+ self._getFilesystem().writefile(mailbox, 'a', StringIO(data))
else:
# XXX: send mail to next server
pass
@@ -345,8 +351,7 @@
except:
username, domain = address, ''
-
- if self.server.auth_source.hasUser(username):
+ if self.server.maildir.hasUser(username):
return username, 1
elif self.config.LOCAL_DOMAIN_NAME == domain.lower():
return 'unknown', 1
@@ -384,7 +389,7 @@
except:
username, domain = address, ''
- if ( self.server.auth_source.hasUser(username) and
+ if ( self.server.maildir.hasUser(username) and
(domain.lower() == self.server.server_name or domain == '') ):
return 1