[Spambayes-checkins] spambayes/Outlook2000 addin.py,1.17,1.18 manager.py,1.23,1.24 msgstore.py,1.6,1.7 rule.py,1.5,1.6

Tim Peters tim_one@users.sourceforge.net
Fri, 25 Oct 2002 10:47:39 -0700


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

Modified Files:
	addin.py manager.py msgstore.py rule.py 
Log Message:
Attempting to switch the scores from floats in 0.-1. to ints in 0-100.

YOU MAY NEED TO CHANGE YOUR FILTER RULES ACCORDINGLY.

The Rule dialog appears to have gotten partly broken before this --
referenced a _GetFolder method that doesn't exist.  Repaired that.

PROBLEM:  While the Rule dialog seems to work fine now, trying to write
a score to the SpamProb (Hammie, whatever) custom field doesn't appear
to do anything anymore.  But I didn't touch that part of the code, so
I'm baffled.  Perhaps it has to do with that the *type* changed from
double to int, and that _MapiTypeMap can't tell the difference between
an int and a bool before Python 2.3 (I'm using 2.2)?  But commenting
out the PT_BOOLEAN entry there didn't make any difference for me, so I
doubt that's it.


Index: addin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/addin.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** addin.py	25 Oct 2002 06:58:20 -0000	1.17
--- addin.py	25 Oct 2002 17:47:36 -0000	1.18
***************
*** 129,135 ****
  
      msgstore_message = mgr.message_store.GetMessage(item.EntryID)
!     prob, clues = mgr.score(msgstore_message, evidence=True)
      new_msg = app.CreateItem(0)
!     body = ["<h2>Spam Score: %g</h2><br>" % prob]
      push = body.append
      # Format the clues.
--- 129,135 ----
  
      msgstore_message = mgr.message_store.GetMessage(item.EntryID)
!     score, clues = mgr.score(msgstore_message, evidence=True, scale=False)
      new_msg = app.CreateItem(0)
!     body = ["<h2>Spam Score: %g</h2><br>" % score]
      push = body.append
      # Format the clues.

Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** manager.py	25 Oct 2002 15:20:25 -0000	1.23
--- manager.py	25 Oct 2002 17:47:36 -0000	1.24
***************
*** 179,188 ****
              self.message_store = None
  
!     def score(self, msg, evidence=False):
          email = msg.GetEmailPackageObject()
!         # As Tim suggested in email, score should move to range(100)
!         # This is probably a good place to do it - anyone who wants the real
!         # float value can look at the "clues"
!         return self.bayes.spamprob(bayes_tokenize(email), evidence)
  
  _mgr = None
--- 179,212 ----
              self.message_store = None
  
!     def score(self, msg, evidence=False, scale=True):
!         """Score a msg.
! 
!         If optional arg evidence is specified and true, the result is a
!         two-tuple
! 
!             score, clues
! 
!         where clues is a list of the (word, spamprob(word)) pairs that
!         went into determining the score.  Else just the score is returned.
! 
!         If optional arg scale is specified and false, the score is a float
!         in 0.0 (ham) thru 1.0 (spam).  Else (the default), the score is
!         scaled into an integer from 0 (ham) thru 100 (spam).
!         """
! 
          email = msg.GetEmailPackageObject()
!         result = self.bayes.spamprob(bayes_tokenize(email), evidence)
!         if not scale:
!             return result
!         # For sister-friendliness, multiply score by 100 and round to an int.
!         if evidence:
!             score, the_evidence = result
!         else:
!             score = result
!         score = int(round(score * 100.0))
!         if evidence:
!             return score, the_evidence
!         else:
!             return score
  
  _mgr = None

Index: msgstore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** msgstore.py	25 Oct 2002 04:40:42 -0000	1.6
--- msgstore.py	25 Oct 2002 17:47:36 -0000	1.7
***************
*** 296,299 ****
--- 296,301 ----
      def SetField(self, prop, val):
          self._EnsureObject()
+         print "after ensure object"
+         print type(prop), prop, type(0)
          if type(prop)!=type(0):
              props = ( (mapi.PS_PUBLIC_STRINGS, prop), )

Index: rule.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/rule.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** rule.py	24 Oct 2002 13:06:39 -0000	1.5
--- rule.py	25 Oct 2002 17:47:36 -0000	1.6
***************
*** 7,12 ****
          self.name = "New Rule"
          self.enabled = True
!         self.min = 0.0
!         self.max = 0.9
          self.action = "None"
          self.flag_message = True
--- 7,12 ----
          self.name = "New Rule"
          self.enabled = True
!         self.min = 30
!         self.max = 80
          self.action = "None"
          self.flag_message = True
***************
*** 27,39 ****
              if not self.folder_id:
                  return "You must specify a folder for 'Move' or 'Copy'"
!             if self._GetFolder(mgr) is None:
                  return "Can not locate the destination folder"
          if self.write_field and not self.write_field_name:
              return "You must specify the field name to create"
  
!     def Act(self, mgr, msg, prob):
          if mgr.verbose > 1:
!             print "Rule '%s': %.2f->%.2f (%.2f) (%s)" % (self.name, self.min, self.max, prob, repr(msg))
!         if prob < self.min or prob > self.max:
              return False
  
--- 27,40 ----
              if not self.folder_id:
                  return "You must specify a folder for 'Move' or 'Copy'"
!             if mgr.message_store.GetFolder(self.folder_id) is None:
                  return "Can not locate the destination folder"
          if self.write_field and not self.write_field_name:
              return "You must specify the field name to create"
  
!     def Act(self, mgr, msg, score):
          if mgr.verbose > 1:
!             print "Rule '%s': %d->%d (%d) (%s)" % (
!                   self.name, self.min, self.max, score, repr(msg))
!         if score < self.min or score > self.max:
              return False
  
***************
*** 44,48 ****
  
          if self.write_field:
!             msg.SetField(self.write_field_name, prob)
              msg.Save()
  
--- 45,49 ----
  
          if self.write_field:
!             msg.SetField(self.write_field_name, score)
              msg.Save()