[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/POP3 - POP3MessageList.py:1.1.2.2 POP3Server.py:1.1.2.4 POP3ServerChannel.py:1.1.2.4
Stephan Richter
srichter@cbu.edu
Thu, 11 Apr 2002 00:32:41 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Server/POP3
In directory cvs.zope.org:/tmp/cvs-serv25892/lib/python/Zope/Server/POP3
Modified Files:
Tag: Zope3-Server-Branch
POP3MessageList.py POP3Server.py POP3ServerChannel.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/POP3/POP3MessageList.py 1.1.2.1 => 1.1.2.2 ===
import mailbox
import os
+from cStringIO import StringIO
from IPOP3MessageList import IPOP3MessageList
from POP3Message import POP3Message
@@ -45,7 +46,8 @@
maildrop = self.maildrop
else:
self.maildrop = maildrop
- md_file = self.maildir.open(maildrop, 'r')
+ md_file = StringIO()
+ self.maildir.readfile(maildrop, 'r', md_file)
self._mb = mailbox.UnixMailbox(md_file)
msg = self._mb.next()
self._messagelist = []
@@ -60,11 +62,9 @@
for msg in self.getMessages():
mb_str += msg.getEntireMessage()
self._mb.fp.close()
- file = self.maildir.open(self.maildrop, 'w')
- file.write(mb_str)
- file.close()
-
+ self.maildir.writefile(self.maildrop, 'w', StringIO(mb_str))
+
def exists(self, index):
'See Zope.Server.POP3.IPOP3MessageList.IPOP3MessageList'
if index > 0 and index <= len(self._messagelist):
=== Zope3/lib/python/Zope/Server/POP3/POP3Server.py 1.1.2.3 => 1.1.2.4 ===
$Id$
"""
+import asyncore
from POP3ServerChannel import POP3ServerChannel
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 POP3Server(ServerBase):
@@ -30,29 +30,30 @@
SERVER_IDENT = 'Zope.Server.POP3Server'
- def __init__(self, ip, port, maildir, auth, task_dispatcher=None,
- adj=None, start=1, hit_log=None, verbose=0):
-
- self.auth_source = auth
- self.maildir = UnixFileSystem(maildir)
-
- super(POP3Server, self).__init__(ip, port, task_dispatcher,
- adj, start, hit_log, verbose)
+ def __init__(self, ip, port, maildir, *args, **kw):
+
+ assert IFilesystemAccess.isImplementedBy(maildir)
+ self.maildir = maildir
+
+ super(POP3Server, self).__init__(ip, port, *args, **kw)
if __name__ == '__main__':
-
- import asyncore
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)
- auth_source = DictionaryAuthentication({'foo': 'bar'})
- POP3Server('', 110, '/var/mail', auth_source, task_dispatcher=td)
+ fs = OSFileSystem('/opt/ZopeMail')
+ maildir = TestFilesystemAccess(fs)
+ td = ThreadedTaskDispatcher()
+ td.setThreadCount(4)
+ POP3Server('', 110, maildir, task_dispatcher=td)
try:
while 1:
asyncore.poll(5)
- # print 'active channels:', POP3ServerChannel.active_channels
+ print 'active channels:', POP3ServerChannel.active_channels
except KeyboardInterrupt:
print 'shutting down...'
td.shutdown()
+
=== Zope3/lib/python/Zope/Server/POP3/POP3ServerChannel.py 1.1.2.3 => 1.1.2.4 ===
import time
import md5
+from cStringIO import StringIO
from Zope.Server.LineReceiver.LineServerChannel import LineServerChannel
+from Zope.Server.VFS.UsernamePassword import UsernamePassword
from POP3StatusMessages import status_msgs
from POP3MessageList import POP3MessageList
@@ -67,7 +69,7 @@
super(POP3ServerChannel, self).__init__(server, conn, addr, adj)
self.username = ''
- self.password = ''
+ self.credentials = None
self.messagelist = None
self.secret = "<%d.%d.%s@%s.%s>" %( os.getpid(), thread.get_ident(),
@@ -77,6 +79,11 @@
self.reply('OK_GREETING', self.secret)
+ def _getFilesystem(self):
+ """Open the filesystem using the current credentials."""
+ return self.server.maildir.open(self.credentials)
+
+
############################################################
# Implementation methods for interface
# Zope.Server.POP3.IPOP3CommandHandler
@@ -91,20 +98,20 @@
return self.reply('ERR_CMD_UNKNOWN')
# Get the username and check whether the user exists
- auth = self.server.auth_source
self.username, hash = args.split()
- if not auth.hasUser(self.username):
+ if not self.server.maildir.hasUser(self.username):
return self.reply('ERR_LOGIN_MISMATCH')
# See whether we got the right MD5 hash
- self.password = auth.getPassword(self.username)
- expected = md5.new(self.secret + self.password).hexdigest()
+ password = self.server.maildir.getPassword(self.username)
+ expected = md5.new(self.secret + password).hexdigest()
if expected != hash:
return self.reply('ERR_LOGIN_MISMATCH')
-
+
+ self.authenticated = 1
+ self.credentials = UsernamePassword(self.username, password)
self.openMessageList()
self.reply('OK_LOGIN')
- self.authenticated = 1
def cmd_capa(self, args):
@@ -164,7 +171,7 @@
def cmd_pass(self, args):
'See Zope.Server.POP3.IPOP3CommandHandler.IPOP3CommandHandler'
- self.password = args
+ password = args
if self.authenticated:
return self.reply('ERR_INV_STATE')
@@ -173,15 +180,17 @@
if not self.username:
return self.reply('ERR_NO_USER')
- auth = self.server.auth_source
- self.authenticated, message = auth.authenticate(self.username,
- self.password)
- if self.authenticated:
- self.openMessageList()
- self.reply('OK_LOGIN')
- else:
+ credentials = UsernamePassword(self.username, password)
+ try:
+ self.server.maildir.authenticate(credentials)
+ except:
self.reply('ERR_LOGIN_MISMATCH')
self.close()
+ else:
+ self.credentials = credentials
+ self.authenticated = 1
+ self.openMessageList()
+ self.reply('OK_LOGIN')
def cmd_quit(self, args):
@@ -281,7 +290,7 @@
if self.authenticated:
return self.reply('ERR_INV_STATE')
- if self.server.auth_source.hasUser(args):
+ if self.server.maildir.hasUser(args):
self.username = args
self.reply('OK_USER', args)
else:
@@ -292,7 +301,7 @@
def openMessageList(self):
- self.messagelist = self.message_list_factory(self.server.maildir)
+ self.messagelist = self.message_list_factory(self._getFilesystem())
self.messagelist.open(self.username)