[Spambayes-checkins] spambayes/Outlook2000 addin.py, 1.60, 1.61 config.py, 1.9, 1.10 filter.py, 1.23, 1.24 msgstore.py, 1.46, 1.47

Mark Hammond mhammond at users.sourceforge.net
Mon Jun 16 20:04:13 EDT 2003


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

Modified Files:
	addin.py config.py filter.py msgstore.py 
Log Message:
2 new [General] options - delete_as_spam_message_state and 
recover_from_spam_message_state.  These specify if the message "Read" flag
should be changed on messages either "deleted from spam" or "recovered from
spam".  If "None", no change is made (as previously).  May also be "Read"
or "Unread", and the state is changed accordingly.


Index: addin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/addin.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** addin.py	16 Jun 2003 05:00:22 -0000	1.60
--- addin.py	17 Jun 2003 02:04:10 -0000	1.61
***************
*** 310,313 ****
--- 310,318 ----
      new_msg.HTMLBody = "<HTML><BODY>" + body + "</BODY></HTML>"
      # Attach the source message to it
+     # Using the original message has the side-effect of marking the original
+     # as unread.  Tried to make a copy, but the copy then refused to delete
+     # itself.
+     # And the "UnRead" property of the message is not reflected in the object
+     # model (we need to "refresh" the message).  Oh well.
      new_msg.Attachments.Add(item, constants.olByValue,
                              DisplayName="Original Message")
***************
*** 360,363 ****
--- 365,369 ----
              return
          import train
+         new_msg_state = self.manager.config.general.delete_as_spam_message_state
          for msgstore_message in msgstore_messages:
              # Must train before moving, else we lose the message!
***************
*** 368,371 ****
--- 374,388 ----
              else:
                  print "already was trained as spam"
+             # Do the new message state if necessary.
+             try:
+                 if new_msg_state == "Read":
+                     msgstore_message.SetReadState(True)
+                 elif new_msg_state == "Unread":
+                     msgstore_message.SetReadState(False)
+                 else:
+                     if new_msg_state not in ["", "None", None]:
+                         print "*** Bad new_msg_state value: %r" % (new_msg_state,)
+             except pythoncom.com_error:
+                 print "*** Failed to set the message state to '%s' for message '%s'" % (new_msg_state, subject)
              # Now move it.
              msgstore_message.MoveTo(spam_folder)
***************
*** 399,402 ****
--- 416,420 ----
          inbox_folder = msgstore.GetFolder(
                      app.Session.GetDefaultFolder(constants.olFolderInbox))
+         new_msg_state = self.manager.config.general.recover_from_spam_message_state
          import train
          for msgstore_message in msgstore_messages:
***************
*** 417,420 ****
--- 435,449 ----
              else:
                  print "already was trained as ham"
+             # Do the new message state if necessary.
+             try:
+                 if new_msg_state == "Read":
+                     msgstore_message.SetReadState(True)
+                 elif new_msg_state == "Unread":
+                     msgstore_message.SetReadState(False)
+                 else:
+                     if new_msg_state not in ["", "None", None]:
+                         print "*** Bad new_msg_state value: %r" % (new_msg_state,)
+             except pythoncom.com_error:
+                 print "*** Failed to set the message state to '%s' for message '%s'" % (new_msg_state, subject)
              # Now move it.
              msgstore_message.MoveTo(restore_folder)

Index: config.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/config.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** config.py	16 Jun 2003 05:00:23 -0000	1.9
--- config.py	17 Jun 2003 02:04:11 -0000	1.10
***************
*** 23,26 ****
--- 23,27 ----
  FIELD_NAME = r"[a-zA-Z0-9 ]+"
  FILTER_ACTION = "Untouched", "Moved", "Copied"
+ MSG_READ_STATE = "None", "Read", "Unread"
  
  from spambayes.OptionsClass import OptionsClass, Option
***************
*** 92,95 ****
--- 93,104 ----
          """""",
          PATH, RESTORE),
+     ("delete_as_spam_message_state", "How the 'read' flag on a message is modified", "None",
+         """When the 'Delete as Spam' function is used, the message 'read' flag can
+            also be set.""",
+            MSG_READ_STATE, RESTORE),
+     ("recover_from_spam_message_state", "How the 'read' flag on a message is modified", "None",
+         """When the 'Recover from Spam' function is used, the message 'read' flag can
+            also be set.""",
+            MSG_READ_STATE, RESTORE),
      ),
      "Training" : (

Index: filter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/filter.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** filter.py	16 Jun 2003 05:00:23 -0000	1.23
--- filter.py	17 Jun 2003 02:04:11 -0000	1.24
***************
*** 91,95 ****
              break
          progress.tick()
!         if only_unread and not message.unread or \
             only_unseen and message.GetField(field_name) is not None:
              continue
--- 91,95 ----
              break
          progress.tick()
!         if only_unread and message.GetReadState() or \
             only_unseen and message.GetField(field_name) is not None:
              continue

Index: msgstore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** msgstore.py	16 Jun 2003 05:00:23 -0000	1.46
--- msgstore.py	17 Jun 2003 02:04:11 -0000	1.47
***************
*** 52,56 ****
  class MsgStoreMsg:
      def __init__(self):
!         self.unread = False
      def GetEmailPackageObject(self):
          # Return a "read-only" Python email package object
--- 52,56 ----
  class MsgStoreMsg:
      def __init__(self):
!         pass
      def GetEmailPackageObject(self):
          # Return a "read-only" Python email package object
***************
*** 94,97 ****
--- 94,102 ----
  MYPR_BODY_HTML_W = 0x1013001f # ditto
  
+ CLEAR_READ_FLAG = 0x00000004
+ CLEAR_RN_PENDING = 0x00000020
+ CLEAR_NRN_PENDING = 0x00000040
+ SUPPRESS_RECEIPT = 0x1
+ 
  USE_DEFERRED_ERRORS = mapi.MAPI_DEFERRED_ERRORS # or set to zero to see what changes <wink>
  
***************
*** 470,485 ****
          # Thus, searchkey is the only reliable long-lived message key.
          self.searchkey = searchkey
!         self.flags = flags
!         self.unread = flags & MSGFLAG_READ == 0
          self.dirty = False
  
      def __repr__(self):
!         if self.unread:
!             urs = "read"
!         else:
!             urs = "unread"
!         return "<%s, '%s' (%s) id=%s/%s>" % (self.__class__.__name__,
                                       self.GetSubject(),
-                                      urs,
                                       mapi.HexFromBin(self.id[0]),
                                       mapi.HexFromBin(self.id[1]))
--- 475,484 ----
          # Thus, searchkey is the only reliable long-lived message key.
          self.searchkey = searchkey
!         self.flags = flags #  flags are unreliable - they change!
          self.dirty = False
  
      def __repr__(self):
!         return "<%s, '%s' id=%s/%s>" % (self.__class__.__name__,
                                       self.GetSubject(),
                                       mapi.HexFromBin(self.id[0]),
                                       mapi.HexFromBin(self.id[1]))
***************
*** 772,775 ****
--- 771,793 ----
              return None
          return val
+ 
+     def GetReadState(self):
+         val = self.GetField(PR_MESSAGE_FLAGS)
+         return (val&MSGFLAG_READ) != 0
+ 
+     def SetReadState(self, is_read):
+         self._EnsureObject()
+         # always try and clear any pending delivery reports of read/unread
+         if is_read:
+             self.mapi_object.SetReadFlag(USE_DEFERRED_ERRORS|SUPPRESS_RECEIPT)
+         else:
+             self.mapi_object.SetReadFlag(USE_DEFERRED_ERRORS|CLEAR_READ_FLAG)
+         if __debug__:
+             if self.GetReadState() != is_read:
+                 print "MAPI SetReadState appears to have failed to change the message state"
+                 print "Requested set to %s but the MAPI field after was %r" % \
+                       (is_read, self.GetField(PR_MESSAGE_FLAGS))
+ 
+     # unsent may also be useful - MSGFLAG_UNSENT bit in PR_MESSAGE_FLAGS .
  
      def Save(self):





More information about the Spambayes-checkins mailing list