[Spambayes-checkins] spambayes pop3proxy.py,1.8,1.9

Richie Hindle richiehindle@users.sourceforge.net
Sat Nov 2 21:00:23 2002


Update of /cvsroot/spambayes/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv13701

Modified Files:
	pop3proxy.py 
Log Message:
Can now listen on the port of your choice (thanks to Tim Stone).
Now supports the 'Unsure' value for X-Hammie-Disposition.
Now less anal about correcting for the size of the added header.


Index: pop3proxy.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/pop3proxy.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pop3proxy.py	1 Nov 2002 09:14:47 -0000	1.8
--- pop3proxy.py	2 Nov 2002 21:00:21 -0000	1.9
***************
*** 12,18 ****
                   defaults to 110.
  
!         options (the same as hammie):
              -p FILE : use the named data file
              -d      : the file is a DBM file rather than a pickle
  
      pop3proxy -t
--- 12,19 ----
                   defaults to 110.
  
!         options:
              -p FILE : use the named data file
              -d      : the file is a DBM file rather than a pickle
+             -l port : listen on this port number (default 110)
  
      pop3proxy -t
***************
*** 39,44 ****
  from Options import options
  
  HEADER_FORMAT = '%s: %%s\r\n' % hammie.DISPHEADER
! HEADER_EXAMPLE = '%s: Yes\r\n' % hammie.DISPHEADER
  
  
--- 40,47 ----
  from Options import options
  
+ # HEADER_EXAMPLE is the longest possible header - the length of this one
+ # is added to the size of each message.
  HEADER_FORMAT = '%s: %%s\r\n' % hammie.DISPHEADER
! HEADER_EXAMPLE = '%s: Unsure\r\n' % hammie.DISPHEADER
  
  
***************
*** 58,61 ****
--- 61,65 ----
          self.set_socket(s, socketMap)
          self.set_reuse_addr()
+         print "Listening on port %d." % port
          self.bind(('', port))
          self.listen(5)
***************
*** 337,350 ****
              ok, message = response.split('\n', 1)
  
!             # Now find the spam disposition and add the header.  The
!             # trailing space in "No " ensures consistent lengths - this
!             # is required because POP3 commands like 'STAT' and 'LIST'
!             # need to be able to report the size of a message before
!             # it's been classified.
              prob = self.bayes.spamprob(tokenizer.tokenize(message))
!             if prob > options.spam_cutoff:
                  disposition = "Yes"
              else:
!                 disposition = "No "
              headers, body = re.split(r'\n\r?\n', response, 1)
              headers = headers + "\n" + HEADER_FORMAT % disposition + "\r\n"
--- 341,353 ----
              ok, message = response.split('\n', 1)
  
!             # Now find the spam disposition and add the header.
              prob = self.bayes.spamprob(tokenizer.tokenize(message))
!             if prob < options.ham_cutoff:
!                 disposition = "No"
!             elif prob > options.spam_cutoff:
                  disposition = "Yes"
              else:
!                 disposition = "Unsure"
!             
              headers, body = re.split(r'\n\r?\n', response, 1)
              headers = headers + "\n" + HEADER_FORMAT % disposition + "\r\n"
***************
*** 577,581 ****
      # Read the arguments.
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'htdp:')
      except getopt.error, msg:
          print >>sys.stderr, str(msg) + '\n\n' + __doc__
--- 580,584 ----
      # Read the arguments.
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'htdp:l:')
      except getopt.error, msg:
          print >>sys.stderr, str(msg) + '\n\n' + __doc__
***************
*** 583,586 ****
--- 586,590 ----
  
      pickleName = hammie.DEFAULTDB
+     proxyPort = 110
      useDB = False
      runTestServer = False
***************
*** 595,599 ****
          elif opt == '-p':
              pickleName = arg
! 
      # Do whatever we've been asked to do...
      if not opts and not args:
--- 599,605 ----
          elif opt == '-p':
              pickleName = arg
!         elif opt == '-l':
!             proxyPort = int(arg)
!             
      # Do whatever we've been asked to do...
      if not opts and not args:
***************
*** 609,617 ****
      elif len(args) == 1:
          # Named POP3 server, default port.
!         main(args[0], 110, 110, pickleName, useDB)
  
      elif len(args) == 2:
          # Named POP3 server, named port.
!         main(args[0], int(args[1]), 110, pickleName, useDB)
  
      else:
--- 615,623 ----
      elif len(args) == 1:
          # Named POP3 server, default port.
!         main(args[0], 110, proxyPort, pickleName, useDB)
  
      elif len(args) == 2:
          # Named POP3 server, named port.
!         main(args[0], int(args[1]), proxyPort, pickleName, useDB)
  
      else: