[Spambayes-checkins] spambayes/Outlook2000/dialogs FilterDialog.py,1.8,1.9 FolderSelector.py,1.6,1.7 TrainingDialog.py,1.7,1.8

Mark Hammond mhammond@users.sourceforge.net
Sat Nov 2 12:28:41 2002


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

Modified Files:
	FilterDialog.py FolderSelector.py TrainingDialog.py 
Log Message:
Another nice patch from Piers Haken - use the Outlook object model for the
folder dialog.  I have no idea why this is necessary for Exchange server,
but it seems OK, and is trivial to revert.

I'm certain that Exchange Server can be navigated via Ext MAPI, but I'm
happy this at least gets more people going.

Note after applying this, the Folder dialog may not automatically 
pre-select the folders you had selected (but they are still working)
- however, once you have re-selected, it does re-remember.

(It seems Outlook has done something funky with the entry IDs, and made 
them binary comparable, whereas MAPI and CDO ones are not.  Whatever)


Index: FilterDialog.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/FilterDialog.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** FilterDialog.py	1 Nov 2002 02:03:46 -0000	1.8
--- FilterDialog.py	2 Nov 2002 12:28:38 -0000	1.9
***************
*** 194,198 ****
                  ids = [ids]
              single_select = not ids_are_list
!             d = FolderSelector.FolderSelector(self.mgr.message_store.session, ids, checkbox_state=None, single_select=single_select)
              if d.DoModal()==win32con.IDOK:
                  new_ids, include_sub = d.GetSelectedIDs()
--- 194,199 ----
                  ids = [ids]
              single_select = not ids_are_list
! #            d = FolderSelector.FolderSelector(self.mgr.message_store.session, ids, checkbox_state=None, single_select=single_select)
!             d = FolderSelector.FolderSelector(self.mgr.outlook.Session, ids, checkbox_state=None, single_select=single_select)
              if d.DoModal()==win32con.IDOK:
                  new_ids, include_sub = d.GetSelectedIDs()

Index: FolderSelector.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/FolderSelector.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FolderSelector.py	1 Nov 2002 05:47:59 -0000	1.6
--- FolderSelector.py	2 Nov 2002 12:28:38 -0000	1.7
***************
*** 22,25 ****
--- 22,35 ----
              c.dump(level+1)
  
+ # Oh, lord help us.
+ # We started with a CDO version - but CDO sucks for lots of reasons I
+ # wont even start to mention.
+ # So we moved to an Extended MAPI version with is nice and fast - screams
+ # along!  Except it doesn't work in all cases with Exchange (which 
+ # strikes Mark as extremely strange given that the Extended MAPI Python
+ # bindings were developed against an Exchange Server - but Mark doesn't
+ # have an Exchange server handy these days, and really doesn't give a
+ # rat's arse <wink>
+ # So finally we have an Outlook object model version!
  #########################################################################
  ## CDO version of a folder walker.
***************
*** 90,93 ****
--- 100,118 ----
      return root
  
+ ## <sob> - An Outlook object model version
+ def _BuildFolderTreeOutlook(session, parent):
+     children = []
+     for i in range (parent.Folders.Count):
+         folder = parent.Folders [i+1]
+         spec = FolderSpec ((folder.StoreID, folder.EntryID), folder.Name.encode("mbcs", "replace"))
+         if folder.Folders != None:
+             spec.children = _BuildFolderTreeOutlook (session, folder)
+         children.append(spec)
+     return children
+ 
+ def BuildFolderTreeOutlook(session):
+     root = FolderSpec(None, "root")
+     root.children = _BuildFolderTreeOutlook(session, session)
+     return root
  
  #########################################################################
***************
*** 141,146 ****
          if type(id2) != type(()):
              id2 = default_store_id, id2
!         return self.mapi.CompareEntryIDs(mapi.BinFromHex(id1[0]), mapi.BinFromHex(id2[0])) and \
!                self.mapi.CompareEntryIDs(mapi.BinFromHex(id1[1]), mapi.BinFromHex(id2[1]))
  
      def InIDs(self, id, ids):
--- 166,172 ----
          if type(id2) != type(()):
              id2 = default_store_id, id2
!         return id1 == id2
! #        return self.mapi.CompareEntryIDs(mapi.BinFromHex(id1[0]), mapi.BinFromHex(id2[0])) and \
! #               self.mapi.CompareEntryIDs(mapi.BinFromHex(id1[1]), mapi.BinFromHex(id2[1]))
  
      def InIDs(self, id, ids):
***************
*** 251,260 ****
              self.GetDlgItem(IDC_BUTTON_CLEARALL).ShowWindow(win32con.SW_HIDE)
  
!         if hasattr(self.mapi, "_oleobj_"): # Dispatch COM object
!             # CDO
!             tree = BuildFolderTreeCDO(self.mapi)
!         else:
!             # Extended MAPI.
!             tree = BuildFolderTreeMAPI(self.mapi)
          self._InsertSubFolders(0, tree)
          self.selected_ids = [] # wipe this out while we are alive.
--- 277,287 ----
              self.GetDlgItem(IDC_BUTTON_CLEARALL).ShowWindow(win32con.SW_HIDE)
  
!         tree = BuildFolderTreeOutlook(self.mapi)
! #        if hasattr(self.mapi, "_oleobj_"): # Dispatch COM object
! #            # CDO
! #            tree = BuildFolderTreeCDO(self.mapi)
! #        else:
! #            # Extended MAPI.
! #            tree = BuildFolderTreeMAPI(self.mapi)            
          self._InsertSubFolders(0, tree)
          self.selected_ids = [] # wipe this out while we are alive.
***************
*** 353,356 ****
      print d.GetSelectedIDs()
  
  if __name__=='__main__':
!     TestWithMAPI()
--- 380,391 ----
      print d.GetSelectedIDs()
  
+ def TestWithOutlook():
+     from win32com.client import Dispatch
+     outlook = Dispatch("Outlook.Application")
+     d=FolderSelector(outlook.Session, None, single_select = False)
+     d.DoModal()
+     print d.GetSelectedIDs()
+ 
+ 
  if __name__=='__main__':
!     TestWithOutlook()

Index: TrainingDialog.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/dialogs/TrainingDialog.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** TrainingDialog.py	1 Nov 2002 02:03:52 -0000	1.7
--- TrainingDialog.py	2 Nov 2002 12:28:38 -0000	1.8
***************
*** 105,109 ****
                  sub_attr = "ham_include_sub"
              include_sub = getattr(self.config, sub_attr)
!             d = FolderSelector.FolderSelector(self.mgr.message_store.session, l, checkbox_state=include_sub)
              if d.DoModal()==win32con.IDOK:
                  l[:], include_sub = d.GetSelectedIDs()[:]
--- 105,110 ----
                  sub_attr = "ham_include_sub"
              include_sub = getattr(self.config, sub_attr)
! #            d = FolderSelector.FolderSelector(self.mgr.message_store.session, l, checkbox_state=include_sub)
!             d = FolderSelector.FolderSelector(self.mgr.outlook.Session, l, checkbox_state=include_sub)
              if d.DoModal()==win32con.IDOK:
                  l[:], include_sub = d.GetSelectedIDs()[:]