[Spambayes-checkins] spambayes pop3proxy.py,1.54,1.55

Tony Meyer anadelonbrin at users.sourceforge.net
Wed Feb 26 20:13:34 EST 2003


Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv30319

Modified Files:
	pop3proxy.py 
Log Message:
Provides options to (a) add an id (as a header or in the body) to incoming mail, (b) strip such ids from incoming mail, (c) find (via the ui) a message based on id, (d) train messages by forwarding/bouncing them to a smtpproxy.

Index: pop3proxy.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/pop3proxy.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** pop3proxy.py	26 Feb 2003 00:11:38 -0000	1.54
--- pop3proxy.py	27 Feb 2003 04:13:31 -0000	1.55
***************
*** 23,26 ****
--- 23,27 ----
                        (default 8880; Browse http://localhost:8880/)
              -b      : Launch a web browser showing the user interface.
+             -s      : Start a SMTPProxy server for training use.
  
          All command line arguments and switches take their default
***************
*** 496,502 ****
                      state.numUnsure += 1
  
!             header = '%s: %s\r\n' % (options.hammie_header_name, disposition)
              headers, body = re.split(r'\n\r?\n', messageText, 1)
!             headers = headers + "\n" + header + "\r\n"
              
              if options.pop3proxy_notate_to \
--- 497,520 ----
                      state.numUnsure += 1
  
!             if options.pop3proxy_strip_incoming_mailids == True:
!                 s = re.compile(options.pop3proxy_mailid_header_name + ': [\d-]+[\\r]?[\\n]?')
!                 messageText = s.sub('', messageText)
! 
              headers, body = re.split(r'\n\r?\n', messageText, 1)
!             messageName = state.getNewMessageName()
!             if command == 'RETR' and not state.isTest \
!                 and options.pop3proxy_add_mailid_header == True:
!                 if options.pop3proxy_mailid_as_header == True:
!                     id_header = options.pop3proxy_mailid_header_name + ": " \
!                             + messageName + "\r\n"
!                 if options.pop3proxy_mailid_in_msgbody == True:
!                     body = body[:len(body)-3] + \
!                            options.pop3proxy_mailid_header_name + ": " \
!                             + messageName + "\r\n.\r\n"
!             else:
!                 id_header = options.hammie_header_name + "-ID: Test\r\n"
!                             
!             header = '%s: %s\r\n' % (options.hammie_header_name, disposition)
!             headers = headers + "\n" + header + id_header + "\r\n"
              
              if options.pop3proxy_notate_to \
***************
*** 519,523 ****
              if command == 'RETR' and not state.isTest:
                  # Write the message into the Unknown cache.
-                 messageName = state.getNewMessageName()
                  message = state.unknownCorpus.makeMessage(messageName)
                  message.setSubstance(messageText)
--- 537,540 ----
***************
*** 650,654 ****
                     self._buildClassifyBox() +
                     self._buildBox('Word query', 'query.gif',
!                                   self.html.wordQuery))
          self._writePreamble("Home")
          self.write(content)
--- 667,674 ----
                     self._buildClassifyBox() +
                     self._buildBox('Word query', 'query.gif',
!                                   self.html.wordQuery) +
!                    self._buildBox('Find message', 'query.gif',
!                                   self.html.findMessage)
!                    )
          self._writePreamble("Home")
          self.write(content)
***************
*** 877,888 ****
                      numDeferred += 1
                  if targetCorpus:
!                     try:
!                         targetCorpus.takeMessage(id, state.unknownCorpus)
!                         if numTrained == 0:
!                             self.write("<p><b>Training... ")
!                             self.flush()
!                         numTrained += 1
!                     except KeyError:
!                         pass  # Must be a reload.
  
          # Report on any training, and save the database if there was any.
--- 897,916 ----
                      numDeferred += 1
                  if targetCorpus:
!                     sourceCorpus = None
!                     if state.unknownCorpus.get(id) is not None:
!                         sourceCorpus = state.unknownCorpus
!                     elif state.hamCorpus.get(id) is not None:
!                         sourceCorpus = state.hamCorpus
!                     elif state.spamCorpus.get(id) is not None:
!                         sourceCorpus = state.spamCorpus
!                     if sourceCorpus is not None:
!                         try:
!                             targetCorpus.takeMessage(id, sourceCorpus)
!                             if numTrained == 0:
!                                 self.write("<p><b>Training... ")
!                                 self.flush()
!                             numTrained += 1
!                         except KeyError:
!                             pass  # Must be a reload.
  
          # Report on any training, and save the database if there was any.
***************
*** 895,898 ****
--- 923,929 ----
              self.write("<br>&nbsp;")
  
+         title = ""
+         keys = []
+         sourceCorpus = state.unknownCorpus
          # If any messages were deferred, show the same page again.
          if numDeferred > 0:
***************
*** 916,919 ****
--- 947,980 ----
              start = self._keyToTimestamp(params['prior'])
  
+         # Else if an id has been specified, just show that message
+         elif params.get('find') is not None:
+             key = params['find']
+             error = False
+             if key == "":
+                 error = True
+                 page = "<p>You must enter an id to find.</p>"
+             elif state.unknownCorpus.get(key) == None:
+                 # maybe this message has been moved to the spam
+                 # or ham corpus
+                 if state.hamCorpus.get(key) != None:
+                     sourceCorpus = state.hamCorpus
+                 elif state.spamCorpus.get(key) != None:
+                     sourceCorpus = state.spamCorpus
+                 else:
+                     error = True
+                     page = "<p>Could not find message with id '"
+                     page += key + "' - maybe it expired.</p>"
+             if error == True:
+                 title = "Did not find message"
+                 box = self._buildBox(title, 'status.gif', page)
+                 self.write(box)
+                 self.write(self._buildBox('Find message', 'query.gif',
+                                           self.html.findMessage))
+                 self._writePostamble()
+                 return
+             keys.append(params['find'])
+             prior = this = next = 0
+             title = "Found message"
+ 
          # Else show the most recent day's page, as decided by _buildReviewKeys.
          else:
***************
*** 921,925 ****
  
          # Build the lists of messages: spams, hams and unsure.
!         keys, date, prior, this, next = self._buildReviewKeys(start)
          keyedMessageInfo = {options.header_spam_string: [],
                              options.header_ham_string: [],
--- 982,987 ----
  
          # Build the lists of messages: spams, hams and unsure.
!         if len(keys) == 0:
!             keys, date, prior, this, next = self._buildReviewKeys(start)
          keyedMessageInfo = {options.header_spam_string: [],
                              options.header_ham_string: [],
***************
*** 928,932 ****
              # Parse the message, get the judgement header and build a message
              # info object for each message.
!             cachedMessage = state.unknownCorpus[key]
              message = mboxutils.get_message(cachedMessage.getSubstance())
              judgement = message[options.hammie_header_name]
--- 990,994 ----
              # Parse the message, get the judgement header and build a message
              # info object for each message.
!             cachedMessage = sourceCorpus[key]
              message = mboxutils.get_message(cachedMessage.getSubstance())
              judgement = message[options.hammie_header_name]
***************
*** 962,966 ****
  
              page.table += self.html.trainRow
!             title = "Untrained messages received on %s" % date
              box = self._buildBox(title, None, page)  # No icon, to save space.
          else:
--- 1024,1029 ----
  
              page.table += self.html.trainRow
!             if title == "":
!                 title = "Untrained messages received on %s" % date
              box = self._buildBox(title, None, page)  # No icon, to save space.
          else:
***************
*** 1003,1015 ****
  
      def onWordquery(self, word):
!         word = word.lower()
!         wordinfo = state.bayes._wordinfoget(word)
!         if wordinfo:
!             stats = self.html.wordStats.clone()
!             stats.spamcount = wordinfo.spamcount
!             stats.hamcount = wordinfo.hamcount
!             stats.spamprob = state.bayes.probability(wordinfo)
          else:
!             stats = "%r does not exist in the database." % cgi.escape(word)
  
          query = self.html.wordQuery.clone()
--- 1066,1081 ----
  
      def onWordquery(self, word):
!         if word == "":
!             stats = "You must enter a word."
          else:
!             word = word.lower()
!             wordinfo = state.bayes._wordinfoget(word)
!             if wordinfo:
!                 stats = self.html.wordStats.clone()
!                 stats.spamcount = wordinfo.spamcount
!                 stats.hamcount = wordinfo.hamcount
!                 stats.spamprob = state.bayes.probability(wordinfo)
!             else:
!                 stats = "%r does not exist in the database." % cgi.escape(word)
  
          query = self.html.wordQuery.clone()
***************
*** 1266,1270 ****
  
  
- 
  # ===================================================================
  # Test code.
--- 1332,1335 ----
***************
*** 1528,1532 ****
      # Read the arguments.
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'htbzpd:D:l:u:')
      except getopt.error, msg:
          print >>sys.stderr, str(msg) + '\n\n' + __doc__
--- 1593,1597 ----
      # Read the arguments.
      try:
!         opts, args = getopt.getopt(sys.argv[1:], 'htbzpsd:D:l:u:')
      except getopt.error, msg:
          print >>sys.stderr, str(msg) + '\n\n' + __doc__
***************
*** 1534,1537 ****
--- 1599,1603 ----
  
      runSelfTest = False
+     launchSMTPProxy = False
      for opt, arg in opts:
          if opt == '-h':
***************
*** 1543,1546 ****
--- 1609,1614 ----
          elif opt == '-b':
              state.launchUI = True
+         elif opt == '-s':
+             launchSMTPProxy = True
          elif opt == '-d':   # dbm file
              state.useDB = True
***************
*** 1563,1566 ****
--- 1631,1641 ----
      # Do whatever we've been asked to do...
      state.createWorkers()
+ 
+     if launchSMTPProxy:
+         from smtproxy import LoadServerInfo, CreateProxies
+         servers, proxyPorts = LoadServerInfo()
+         CreateProxies(servers, proxyPorts, state)
+         LoadServerInfo()
+     
      if runSelfTest:
          print "\nRunning self-test...\n"





More information about the Spambayes-checkins mailing list