[Spambayes-checkins] spambayes/Outlook2000 msgstore.py,1.37,1.38

Mark Hammond mhammond at users.sourceforge.net
Thu Jan 23 04:17:37 EST 2003


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

Modified Files:
	msgstore.py 
Log Message:
A number of changes related to the folder selector dialog - code generally 
inspired by a couple of nice patches by Tony Meyer.  Should be no visible
changes, but under the covers:

* worked out we were using short-term EIDs for folders, causing the
exchange server to fail.  So we are back to a faster MAPI version.
Deleted the other variants - as I said in the comments, CVS is your
friend <wink>.  I was kind enough leave an indication of the last CVS 
revision with the old code though!

* Only build the folder structure as the folder is expanded.  Thus, the 
entire folder hierarchy is no longer walked when displaying the dialog.
This speeds up the code considerable for exchange server users, where the
public folder hierarchy is both huge, and never needed by SpamBayes.

* We generally use the msgstore, rather than hitting MAPI directly, 
abstracting away some ugly code.  Thus we are tied tighter to the 
spambayes manager object.

* Drop all concepts of "default store" - all folder/message IDs are 
expected to be a tuple of (store_id, item_id).  (This code was just
a hangover to prevent CVS users of spambayes from needing to redefine
all their folders when we first moved to the (store_id, item_id) scheme.



Index: msgstore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** msgstore.py	14 Jan 2003 05:38:20 -0000	1.37
--- msgstore.py	23 Jan 2003 12:17:35 -0000	1.38
***************
*** 42,45 ****
--- 42,48 ----
          self.name = "<folder>"
          self.count = 0
+     def GetParent(self):
+         # return a folder object with the parent, or None
+         raise NotImplementedError
      def GetMessageGenerator(self, folder):
          # Return a generator of MsgStoreMsg objects for the folder
***************
*** 172,180 ****
--- 175,188 ----
              item_id = mapi.BinFromHex(item_id)
              if store_id is None:
+                 # store_id=None was a "backwards compat" hack no longer
+                 # need - it can go once we are *sure* we dont need it ;)
+                 assert False, "We expect fully qualified IDs"
                  store_id = self.default_store_bin_eid
              else:
                  store_id = mapi.BinFromHex(store_id)
              return store_id, item_id
+         # See above - this branch can die (I think ;)
          assert type(item_id) in [type(''), type(u'')], "What kind of ID is '%r'?" % (item_id,)
+         assert False, "We expect fully qualified IDs"
          return self.default_store_bin_eid, mapi.BinFromHex(item_id)
  
***************
*** 216,221 ****
          folder = self._OpenEntry(folder_id)
          table = folder.GetContentsTable(0)
!         rc, props = folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
!         return MAPIMsgStoreFolder(self, folder_id, props[0][1],
                                    table.GetRowCount(0))
  
--- 224,231 ----
          folder = self._OpenEntry(folder_id)
          table = folder.GetContentsTable(0)
!         # Ensure we have a long-term ID.
!         rc, props = folder.GetProps( (PR_ENTRYID, PR_DISPLAY_NAME_A), 0)
!         folder_id = folder_id[0], props[0][1]
!         return MAPIMsgStoreFolder(self, folder_id, props[1][1],
                                    table.GetRowCount(0))
  
***************
*** 275,278 ****
--- 285,310 ----
          return mapi.HexFromBin(self.id[0]), mapi.HexFromBin(self.id[1])
  
+     def GetParent(self):
+         # return a folder object with the parent, or None
+         folder = self.msgstore._OpenEntry(self.id)
+         prop_ids = PR_PARENT_ENTRYID,
+         hr, data = folder.GetProps(prop_ids,0)
+         # Put parent ids together
+         parent_eid = data[0][1]
+         parent_id = self.id[0], parent_eid
+         if hr != 0 or \
+            self.msgstore.session.CompareEntryIDs(parent_eid, self.id[1]):
+             # No parent EID, or EID same as ours.
+             return None
+         parent = self.msgstore._OpenEntry(parent_id)
+         # Finally get the display name.
+         hr, data = folder.GetProps((PR_DISPLAY_NAME_A,), 0)
+         name = data[0][1]
+         count = parent.GetContentsTable(0).GetRowCount(0)
+         return MAPIMsgStoreFolder(self.msgstore, parent_id, name, count)
+ 
+     def OpenEntry(self, iid = None, flags = None):
+         return self.msgstore._OpenEntry(self.id, iid, flags)
+ 
      def GetOutlookItem(self):
          hex_item_id = mapi.HexFromBin(self.id[1])
***************
*** 281,285 ****
  
      def GetMessageGenerator(self):
!         folder = self.msgstore._OpenEntry(self.id)
          table = folder.GetContentsTable(0)
          # Limit ourselves to IPM.Note objects - ie, messages.
--- 313,317 ----
  
      def GetMessageGenerator(self):
!         folder = self.OpenEntry()
          table = folder.GetContentsTable(0)
          # Limit ourselves to IPM.Note objects - ie, messages.





More information about the Spambayes-checkins mailing list