[Spambayes-checkins] spambayes pop3proxy.py,1.10,1.11

Just van Rossum jvr@users.sourceforge.net
Thu Nov 7 22:27:05 2002


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

Modified Files:
	pop3proxy.py 
Log Message:
- added True/False for compatibilty with Python 2.2
- write out trained messages to files, to make it easier
  to rebuild the database



Index: pop3proxy.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/pop3proxy.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** pop3proxy.py	5 Nov 2002 22:18:56 -0000	1.10
--- pop3proxy.py	7 Nov 2002 22:27:02 -0000	1.11
***************
*** 28,31 ****
--- 28,34 ----
  For safety, and to help debugging, the whole POP3 conversation is
  written out to _pop3proxy.log for each run.
+ 
+ To make rebuilding the database easier, trained messages are appended
+ to _pop3proxyham.mbox and _pop3proxyspam.mbox.
  """
  
***************
*** 37,40 ****
--- 40,49 ----
  __credits__ = "Tim Peters, Neale Pickett, all the spambayes contributors."
  
+ try:
+     True, False
+ except NameError:
+     # Maintain compatibility with Python 2.2
+     True, False = 1, 0
+ 
  
  import sys, re, operator, errno, getopt, cPickle, cStringIO, time
***************
*** 609,614 ****
  
      def onUpload(self, params):
!         message = params.get('file') or params.get('text')            
          isSpam = (params['which'] == 'spam')
          self.bayes.learn(tokenizer.tokenize(message), isSpam, True)
          self.push("""<p>Trained on your message. Saving database...</p>""")
--- 618,634 ----
  
      def onUpload(self, params):
!         message = params.get('file') or params.get('text')
          isSpam = (params['which'] == 'spam')
+         # Append the message to a file, to make it easier to rebuild
+         # the database later.
+         message = message.replace('\r\n', '\n').replace('\r', '\n')
+         if isSpam:
+             f = open("_pop3proxyspam.mbox", "a")
+         else:
+             f = open("_pop3proxyham.mbox", "a")
+         f.write("From ???@???\n")  # fake From line (XXX good enough?)
+         f.write(message)
+         f.write("\n")
+         f.close()
          self.bayes.learn(tokenizer.tokenize(message), isSpam, True)
          self.push("""<p>Trained on your message. Saving database...</p>""")