[Spambayes] Using Spambayes w/ Eudora
Tony Lownds
tony at lownds.com
Mon Jan 13 23:06:10 EST 2003
At 5:54 PM +1100 1/14/03, Anthony Baxter wrote:
> >>> Tony Lownds wrote
>> The diff to pop3proxy.py is attached.
>
>Erm. The patch came through as a "application/mac-binhex40". Could
>you re-send with a more... standard... format?
>
>Ta
>
You mean there's something more standard than mac-binhex40?
:)
*** pop3proxy.py Mon Jan 13 14:59:22 2003
--- pop3proxy_peer.py Mon Jan 13 21:56:27 2003
***************
*** 157,164 ****
dispatchers created by a factory callable.
"""
! def __init__(self, port, factory, factoryArgs=(),
! socketMap=asyncore.socket_map):
asyncore.dispatcher.__init__(self, map=socketMap)
self.socketMap = socketMap
self.factory = factory
--- 157,164 ----
dispatchers created by a factory callable.
"""
! def __init__(self, port, factory, factoryArgs=(), listenAddress='',
! socketMap=asyncore.socket_map, ):
asyncore.dispatcher.__init__(self, map=socketMap)
self.socketMap = socketMap
self.factory = factory
***************
*** 168,175 ****
self.set_socket(s, socketMap)
self.set_reuse_addr()
if options.verbose:
! print "%s listening on port %d." %
(self.__class__.__name__, port)
! self.bind(('', port))
self.listen(5)
def handle_accept(self):
--- 168,175 ----
self.set_socket(s, socketMap)
self.set_reuse_addr()
if options.verbose:
! print "%s listening on %s port %d." %
(self.__class__.__name__, listenAddress, port)
! self.bind((listenAddress, port))
self.listen(5)
def handle_accept(self):
***************
*** 390,397 ****
def __init__(self, serverName, serverPort, proxyPort):
proxyArgs = (serverName, serverPort)
! Listener.__init__(self, proxyPort, BayesProxy, proxyArgs)
! print 'Listener on port %d is proxying %s:%d' % (proxyPort,
serverName, serverPort)
class BayesProxy(POP3ProxyBase):
--- 390,403 ----
def __init__(self, serverName, serverPort, proxyPort):
proxyArgs = (serverName, serverPort)
! bindAddress, bindPort = proxyPort
! Listener.__init__(
! self, bindPort, BayesProxy, proxyArgs,
! listenAddress=bindAddress
! )
! print 'Listener on port %s is proxying %s:%d' % (
! _addressPortStr(proxyPort), serverName, serverPort
! )
class BayesProxy(POP3ProxyBase):
***************
*** 1251,1257 ****
if options.pop3proxy_ports:
splitPorts = options.pop3proxy_ports.split(',')
! self.proxyPorts = map(int, map(string.strip, splitPorts))
if len(self.servers) != len(self.proxyPorts):
print "pop3proxy_servers & pop3proxy_ports are
different lengths!"
--- 1257,1263 ----
if options.pop3proxy_ports:
splitPorts = options.pop3proxy_ports.split(',')
! self.proxyPorts = map(_addressAndOrPort,
map(string.strip, splitPorts))
if len(self.servers) != len(self.proxyPorts):
print "pop3proxy_servers & pop3proxy_ports are
different lengths!"
***************
*** 1286,1292 ****
versions of the details, for display in the Status panel."""
serverStrings = ["%s:%s" % (s, p) for s, p in self.servers]
self.serversString = ', '.join(serverStrings)
! self.proxyPortsString = ', '.join(map(str, self.proxyPorts))
def createWorkers(self):
"""Using the options that were initialised in __init__ and then
--- 1292,1298 ----
versions of the details, for display in the Status panel."""
serverStrings = ["%s:%s" % (s, p) for s, p in self.servers]
self.serversString = ', '.join(serverStrings)
! self.proxyPortsString = ', '.join(map(_addressPortStr,
self.proxyPorts))
def createWorkers(self):
"""Using the options that were initialised in __init__ and then
***************
*** 1333,1340 ****
--- 1339,1364 ----
self.spamCorpus.addObserver(self.spamTrainer)
self.hamCorpus.addObserver(self.hamTrainer)
+ # helper functions
+
+ def _addressAndOrPort(s):
+ if ':' in s:
+ addr, port = s.split(':')
+ return addr, int(port)
+ else:
+ return '', int(s)
+
+ def _addressPortStr((addr, port)):
+ if not addr:
+ return str(port)
+ else:
+ return '%s:%d' % (addr, port)
+
+ # globals
+
state = State()
+ # main program
def main(servers, proxyPorts, uiPort, launchUI):
"""Runs the proxy forever or until a 'KILL' command is received or
***************
*** 1573,1579 ****
pop3Server.sendall("kill\r\n")
pop3Server.recv(100)
-
# ===================================================================
# __main__ driver.
# ===================================================================
--- 1597,1602 ----
***************
*** 1601,1607 ****
elif opt == '-p':
state.databaseFilename = arg
elif opt == '-l':
! state.proxyPorts = [int(arg)]
elif opt == '-u':
state.uiPort = int(arg)
elif opt == '-z':
--- 1624,1630 ----
elif opt == '-p':
state.databaseFilename = arg
elif opt == '-l':
! state.proxyPorts = [_addressAndOrPort(arg)]
elif opt == '-u':
state.uiPort = int(arg)
elif opt == '-z':
More information about the Spambayes
mailing list