[Spambayes-checkins] spambayes/Outlook2000/sandbox mapi_driver.py,NONE,1.1 delete_outlook_field.py,1.4,1.5 dump_props.py,1.6,1.7

Mark Hammond mhammond@users.sourceforge.net
Sat Nov 23 02:57:49 2002


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

Modified Files:
	delete_outlook_field.py dump_props.py 
Added Files:
	mapi_driver.py 
Log Message:
Stop cloning the folder location code by creating a utility class.


--- NEW FILE: mapi_driver.py ---
from __future__ import generators
# Utilities for our sandbox

import pythoncom
from win32com.mapi import mapi, mapiutil
from win32com.mapi.mapitags import *

from win32com.client import Dispatch

class MAPIDriver:
    def __init__(self, read_only = False):
        mapi.MAPIInitialize(None)
        logonFlags = (mapi.MAPI_NO_MAIL |
                      mapi.MAPI_EXTENDED |
                      mapi.MAPI_USE_DEFAULT)
        self.session = mapi.MAPILogonEx(0, None, None, logonFlags)
        if read_only:
            self.mapi_flags = mapi.MAPI_DEFERRED_ERRORS
        else:
            self.mapi_flags = mapi.MAPI_DEFERRED_ERRORS | mapi.MAPI_BEST_ACCESS
        self.outlook = None

    def _GetMAPIFlags(self, mapi_flags = None):
        if mapi_flags is None:
            mapi_flags = self.mapi_flags
        return mapi_flags

    def GetOutlookFolder(self, item):
        if self.outlook is None:
            self.outlook = Dispatch("Outlook.Application")

        hr, props = item.GetProps((PR_ENTRYID,PR_STORE_ENTRYID), 0)
        (tag, eid), (tag, store_eid) = props
        eid = mapi.HexFromBin(eid)
        store_eid = mapi.HexFromBin(store_eid)
        return self.outlook.Session.GetFolderFromID(eid, store_eid)

    def GetMessageStores(self):
        tab = self.session.GetMsgStoresTable(0)
        rows = mapi.HrQueryAllRows(tab,
                                   (PR_ENTRYID, PR_DISPLAY_NAME_A, PR_DEFAULT_STORE),   # columns to retrieve
                                   None,     # all rows
                                   None,            # any sort order is fine
                                   0)               # any # of results is fine
        for row in rows:
            (eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row
            # Open the store.
            store = self.session.OpenMsgStore(
                                0,      # no parent window
                                eid,    # msg store to open
                                None,   # IID; accept default IMsgStore
                                # need write access to add score fields
                                mapi.MDB_WRITE |
                                    # we won't send or receive email
                                    mapi.MDB_NO_MAIL |
                                    mapi.MAPI_DEFERRED_ERRORS)
            yield store, name, def_store

    def _FindSubfolder(self, store, folder, find_name):
        find_name = find_name.lower()
        table = folder.GetHierarchyTable(0)
        rows = mapi.HrQueryAllRows(table, (PR_ENTRYID, PR_DISPLAY_NAME_A), None, None, 0)
        for (eid_tag, eid), (name_tag, name), in rows:
            if name.lower() == find_name:
                return store.OpenEntry(eid, None, mapi.MAPI_DEFERRED_ERRORS)
        return None

    def FindFolder(self, name):
        assert name
        names = [n.lower() for n in name.split("\\")]
        if names[0]:
            for store, name, is_default in self.GetMessageStores():
                if is_default:
                    store_name = name.lower()
                    break
            folder_names = names
        else:
            store_name = names[1]
            folder_names = names[2:]
        # Find the store with the name
        for store, name, is_default in self.GetMessageStores():
            if name.lower() == store_name:
                folder_store = store
                break
        else:
            raise ValueError, "The store '%s' can not be located" % (store_name,)

        hr, data = store.GetProps((PR_IPM_SUBTREE_ENTRYID,), 0)
        subtree_eid = data[0][1]
        folder = folder_store.OpenEntry(subtree_eid, None, mapi.MAPI_DEFERRED_ERRORS)

        for name in folder_names:
            folder = self._FindSubfolder(folder_store, folder, name)
            if folder is None:
                raise ValueError, "The subfolder '%s' can not be located" % (name,)
        return folder

    def GetAllItems(self, folder, mapi_flags = None):
        mapi_flags = self._GetMAPIFlags(mapi_flags)
        table = folder.GetContentsTable(0)
        table.SetColumns((PR_ENTRYID,PR_STORE_ENTRYID), 0)
        while 1:
            # Getting 70 at a time was the random number that gave best
            # perf for me ;)
            rows = table.QueryRows(70, 0)
            if len(rows) == 0:
                break
            for row in rows:
                (tag, eid), (tag, store_eid) = row
                store = self.session.OpenMsgStore(0, store_eid, None, mapi_flags)
                item = store.OpenEntry(eid, None, mapi_flags)
                yield item

    def GetItemsWithValue(self, folder, prop_tag, prop_val, mapi_flags = None):
        mapi_flags = self._GetMAPIFlags(mapi_flags)
        tab = folder.GetContentsTable(0)
        # Restriction for the table:  get rows where our prop values match
        restriction = (mapi.RES_CONTENT,   # a property restriction
                       (mapi.FL_SUBSTRING | mapi.FL_IGNORECASE | mapi.FL_LOOSE, # fuzz level
                        prop_tag,   # of the given prop
                        (prop_tag, prop_val))) # with given val
        rows = mapi.HrQueryAllRows(tab,
                                   (PR_ENTRYID, PR_STORE_ENTRYID),   # columns to retrieve
                                   restriction,     # only these rows
                                   None,            # any sort order is fine
                                   0)               # any # of results is fine
        for row in rows:
            (tag, eid),(tag, store_eid) = row
            store = self.session.OpenMsgStore(0, store_eid, None, mapi_flags)
            item = store.OpenEntry(eid, None, mapi_flags)
            yield item

    def DumpTopLevelFolders(self):
        print "Top-level folder names are:"
        for store, name, is_default in self.GetMessageStores():
            # Find the folder with the content.
            hr, data = store.GetProps((PR_IPM_SUBTREE_ENTRYID,), 0)
            subtree_eid = data[0][1]
            folder = store.OpenEntry(subtree_eid, None, mapi.MAPI_DEFERRED_ERRORS)
            # Now the top-level folders in the store.
            table = folder.GetHierarchyTable(0)
            rows = mapi.HrQueryAllRows(table, (PR_DISPLAY_NAME_A), None, None, 0)
            for (name_tag, folder_name), in rows:
                print " \\%s\\%s" % (name, folder_name)

    def GetFolderNameDoc(self):
        def_store_name = "<??unknown??>"
        for store, name, is_def in self.GetMessageStores():
            if is_def:
                def_store_name = name
        return """\
Folder name is a hierarchical 'path' name, using '\\'
as the path separator.  If the folder name begins with a
\\, it must be a fully-qualified name, including the message
store name. For example, as your default store is currently named
'%s', your Inbox can be specified either as:
  -f "Inbox"
or
  -f "\\%s\\Inbox"
""" % (def_store_name, def_store_name)


if __name__=='__main__':
    print "This is a utility script for the other scripts in this directory"

Index: delete_outlook_field.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/sandbox/delete_outlook_field.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** delete_outlook_field.py	14 Nov 2002 07:01:04 -0000	1.4
--- delete_outlook_field.py	23 Nov 2002 02:57:46 -0000	1.5
***************
*** 1,2 ****
--- 1,3 ----
+ from __future__ import generators
  # Do the best we can to completely obliterate a field from Outlook!
  
***************
*** 8,51 ****
  from win32com.mapi.mapitags import *
  
! mapi.MAPIInitialize(None)
! logonFlags = (mapi.MAPI_NO_MAIL |
!               mapi.MAPI_EXTENDED |
!               mapi.MAPI_USE_DEFAULT)
! session = mapi.MAPILogonEx(0, None, None, logonFlags)
! 
! def _FindDefaultMessageStore():
!     tab = session.GetMsgStoresTable(0)
!     # Restriction for the table:  get rows where PR_DEFAULT_STORE is true.
!     # There should be only one.
!     restriction = (mapi.RES_PROPERTY,   # a property restriction
!                    (mapi.RELOP_EQ,      # check for equality
!                     PR_DEFAULT_STORE,   # of the PR_DEFAULT_STORE prop
!                     (PR_DEFAULT_STORE, True))) # with True
!     rows = mapi.HrQueryAllRows(tab,
!                                (PR_ENTRYID,),   # columns to retrieve
!                                restriction,     # only these rows
!                                None,            # any sort order is fine
!                                0)               # any # of results is fine
!     # get first entry, a (property_tag, value) pair, for PR_ENTRYID
!     row = rows[0]
!     eid_tag, eid = row[0]
!     # Open the store.
!     return session.OpenMsgStore(
!                             0,      # no parent window
!                             eid,    # msg store to open
!                             None,   # IID; accept default IMsgStore
!                             # need write access to add score fields
!                             mapi.MDB_WRITE |
!                                 # we won't send or receive email
!                                 mapi.MDB_NO_MAIL |
!                                 mapi.MAPI_DEFERRED_ERRORS)
! 
! def _FindFolderEID(name):
!     from win32com.mapi import exchange
!     if not name.startswith("\\"):
!         name = "\\Top Of Personal Folders\\" + name
!     store = _FindDefaultMessageStore()
!     folder_eid = exchange.HrMAPIFindFolderEx(store, "\\", name)
!     return mapi.HexFromBin(folder_eid)
  
  def DeleteField_Outlook(folder, name):
--- 9,13 ----
  from win32com.mapi.mapitags import *
  
! import mapi_driver
  
  def DeleteField_Outlook(folder, name):
***************
*** 66,115 ****
      return num_outlook
  
! def DeleteField_MAPI(folder, name):
      # OK - now try and wipe the field using MAPI.
!     mapi_msgstore = _FindDefaultMessageStore()
!     mapi_folder = mapi_msgstore.OpenEntry(mapi.BinFromHex(folder.EntryID),
!                                           None,
!                                           mapi.MAPI_MODIFY | mapi.MAPI_DEFERRED_ERRORS)
! 
!     table = mapi_folder.GetContentsTable(0)
!     prop_ids = PR_ENTRYID,
!     table.SetColumns(prop_ids, 0)
!     propIds = mapi_folder.GetIDsFromNames(((mapi.PS_PUBLIC_STRINGS,name),), 0)
      num_mapi = 0
!     if PROP_TYPE(propIds[0])!=PT_ERROR:
!         assert propIds[0] == PROP_TAG( PT_UNSPECIFIED, PROP_ID(propIds[0]))
!         while 1:
!             # Getting 70 at a time was the random number that gave best
!             # perf for me ;)
!             rows = table.QueryRows(70, 0)
!             if len(rows) == 0:
!                 break
!             for row in rows:
!                 eid = row[0][1]
!                 item = mapi_msgstore.OpenEntry(eid, None, mapi.MAPI_MODIFY | mapi.MAPI_DEFERRED_ERRORS)
!                 # DeleteProps always says"success" - so check to see if it
!                 # actually exists just so we can count it.
!                 hr, vals = item.GetProps(propIds)
!                 if hr==0: # We actually have it
!                     hr, probs = item.DeleteProps(propIds)
!                     if  hr == 0:
!                         item.SaveChanges(mapi.MAPI_DEFERRED_ERRORS)
!                         num_mapi += 1
      return num_mapi
  
! def DeleteField_Folder(folder, name):
!     mapi_msgstore = _FindDefaultMessageStore()
!     mapi_folder = mapi_msgstore.OpenEntry(mapi.BinFromHex(folder.EntryID),
!                                           None,
!                                           mapi.MAPI_MODIFY | mapi.MAPI_DEFERRED_ERRORS)
!     propIds = mapi_folder.GetIDsFromNames(((mapi.PS_PUBLIC_STRINGS,name),), 0)
!     num_mapi = 0
      if PROP_TYPE(propIds[0])!=PT_ERROR:
!         hr, vals = mapi_folder.GetProps(propIds)
          if hr==0: # We actually have it
!             hr, probs = mapi_folder.DeleteProps(propIds)
              if  hr == 0:
!                 mapi_folder.SaveChanges(mapi.MAPI_DEFERRED_ERRORS)
                  return 1
      return 0
--- 28,58 ----
      return num_outlook
  
! def DeleteField_MAPI(driver, folder, name):
      # OK - now try and wipe the field using MAPI.
!     propIds = folder.GetIDsFromNames(((mapi.PS_PUBLIC_STRINGS,name),), 0)
!     if PROP_TYPE(propIds[0])==PT_ERROR:
!         print "No such field '%s' in folder" % (name,)
!         return 0
!     assert propIds[0] == PROP_TAG( PT_UNSPECIFIED, PROP_ID(propIds[0]))
      num_mapi = 0
!     for item in driver.GetAllItems(folder):
!         # DeleteProps always says"success" - so check to see if it
!         # actually exists just so we can count it.
!         hr, vals = item.GetProps(propIds)
!         if hr==0: # We actually have it
!             hr, probs = item.DeleteProps(propIds)
!             if  hr == 0:
!                 item.SaveChanges(mapi.MAPI_DEFERRED_ERRORS)
!                 num_mapi += 1
      return num_mapi
  
! def DeleteField_Folder(driver, folder, name):
!     propIds = folder.GetIDsFromNames(((mapi.PS_PUBLIC_STRINGS,name),), 0)
      if PROP_TYPE(propIds[0])!=PT_ERROR:
!         hr, vals = folder.GetProps(propIds)
          if hr==0: # We actually have it
!             hr, probs = folder.DeleteProps(propIds)
              if  hr == 0:
!                 folder.SaveChanges(mapi.MAPI_DEFERRED_ERRORS)
                  return 1
      return 0
***************
*** 145,182 ****
          entry = entries.GetNext()
  
! def usage():
      msg = """\
! Usage: %s [-f foldername] [-f foldername] [-d] [-s] [FieldName ...]
  -f - Run over the specified folders (default = Inbox)
  -d - Delete the named fields
  -s - Show message subject and field value for all messages with field
! If no options given, prints a summary of field names in the folders
! --no-outlook - Don't delete via the Outlook UserProperties API
! --no-mapi - Don't delete via the extended MAPI API
! --no-folder - Don't attempt to delete the field from the folder itself
  
! Folder name must be a hierarchical 'path' name, using '\\'
! as the path seperator.  If the folder name begins with a
! \\, it must be a fully-qualified name, including the message
! store name (eg, "Top of Public Folders").  If the path does not
! begin with a \\, it is assumed to be fully-qualifed from the root
! of the default message store
  
! Eg, 'python\\python-dev' will locate a python-dev subfolder in a python
! subfolder in your default store.
! """ % os.path.basename(sys.argv[0])
      print msg
  
  
  def main():
      import getopt
      try:
          opts, args = getopt.getopt(sys.argv[1:],
!                                    "dsf:",
                                     ["no-mapi", "no-outlook", "no-folder"])
      except getopt.error, e:
          print e
          print
!         usage()
          sys.exit(1)
      delete = show = False
--- 88,123 ----
          entry = entries.GetNext()
  
! def usage(driver):
!     folder_doc = driver.GetFolderNameDoc()
      msg = """\
! Usage: %s [-f foldername -f ...] [-d] [-s] [FieldName ...]
  -f - Run over the specified folders (default = Inbox)
  -d - Delete the named fields
+   --no-outlook - Don't delete via the Outlook UserProperties API
+   --no-mapi - Don't delete via the extended MAPI API
+   --no-folder - Don't attempt to delete the field from the folder itself
  -s - Show message subject and field value for all messages with field
! -n - Show top-level folder names and exit
  
! If no options are given, prints a summary of field names in the folders.
  
! %s
! Use the -n option to see all top-level folder names from all stores.""" \
!         % (os.path.basename(sys.argv[0]), folder_doc)
      print msg
  
  
  def main():
+     driver = mapi_driver.MAPIDriver()
+ 
      import getopt
      try:
          opts, args = getopt.getopt(sys.argv[1:],
!                                    "dnsf:",
                                     ["no-mapi", "no-outlook", "no-folder"])
      except getopt.error, e:
          print e
          print
!         usage(driver)
          sys.exit(1)
      delete = show = False
***************
*** 196,200 ****
          elif opt == "--no-folder":
              do_folder = False
! 
          else:
              print "Invalid arg"
--- 137,143 ----
          elif opt == "--no-folder":
              do_folder = False
!         elif opt == "-n":
!             driver.DumpTopLevelFolders()
!             sys.exit(1)
          else:
              print "Invalid arg"
***************
*** 203,230 ****
      if not folder_names:
          folder_names = ["Inbox"] # Assume this exists!
-     app = Dispatch("Outlook.Application")
      if not args:
          print "No args specified - dumping all unique UserProperty names,"
          print "and the count of messages they appear in"
      for folder_name in folder_names:
!         eid = _FindFolderEID(folder_name)
!         if eid is None:
!             print "*** Cant find folder", folder_name
              continue
!         folder = app.Session.GetFolderFromID(eid)
!         print "Processing folder", folder.Name.encode("mbcs", "replace")
          if not args:
!             CountFields(folder)
              continue
          for field_name in args:
              if show:
!                 ShowFields(folder, field_name)
              if delete:
                  print "Deleting field", field_name
                  if do_outlook:
!                     num = DeleteField_Outlook(folder, field_name)
                      print "Deleted", num, "field instances from Outlook"
                  if do_mapi:
!                     num = DeleteField_MAPI(folder, field_name)
                      print "Deleted", num, "field instances via MAPI"
                  if do_folder:
--- 146,177 ----
      if not folder_names:
          folder_names = ["Inbox"] # Assume this exists!
      if not args:
          print "No args specified - dumping all unique UserProperty names,"
          print "and the count of messages they appear in"
+     outlook = None
      for folder_name in folder_names:
!         try:
!             folder = driver.FindFolder(folder_name)
!         except ValueError, details:
!             print details
!             print "Ignoring folder '%s'" % (folder_name,)
              continue
!         print "Processing folder '%s'" % (folder_name,)
          if not args:
!             outlook_folder = driver.GetOutlookFolder(folder)
!             CountFields(outlook_folder)
              continue
          for field_name in args:
              if show:
!                 outlook_folder = driver.GetOutlookFolder(folder)
!                 ShowFields(outlook_folder, field_name)
              if delete:
                  print "Deleting field", field_name
                  if do_outlook:
!                     outlook_folder = driver.GetOutlookFolder(folder)
!                     num = DeleteField_Outlook(outlook_folder, field_name)
                      print "Deleted", num, "field instances from Outlook"
                  if do_mapi:
!                     num = DeleteField_MAPI(driver, folder, field_name)
                      print "Deleted", num, "field instances via MAPI"
                  if do_folder:

Index: dump_props.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/sandbox/dump_props.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** dump_props.py	20 Nov 2002 22:06:17 -0000	1.6
--- dump_props.py	23 Nov 2002 02:57:46 -0000	1.7
***************
*** 2,6 ****
  # Dump every property we can find for a MAPI item
  
- from win32com.client import Dispatch, constants
  import pythoncom
  import os, sys
--- 2,5 ----
***************
*** 9,77 ****
  from win32com.mapi.mapitags import *
  
! mapi.MAPIInitialize(None)
! logonFlags = (mapi.MAPI_NO_MAIL |
!               mapi.MAPI_EXTENDED |
!               mapi.MAPI_USE_DEFAULT)
! session = mapi.MAPILogonEx(0, None, None, logonFlags)
! 
! def GetMessageStores():
!     tab = session.GetMsgStoresTable(0)
!     rows = mapi.HrQueryAllRows(tab,
!                                (PR_ENTRYID, PR_DISPLAY_NAME_A, PR_DEFAULT_STORE),   # columns to retrieve
!                                None,     # all rows
!                                None,            # any sort order is fine
!                                0)               # any # of results is fine
!     for row in rows:
!         (eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row
!         # Open the store.
!         store = session.OpenMsgStore(
!                             0,      # no parent window
!                             eid,    # msg store to open
!                             None,   # IID; accept default IMsgStore
!                             # need write access to add score fields
!                             mapi.MDB_WRITE |
!                                 # we won't send or receive email
!                                 mapi.MDB_NO_MAIL |
!                                 mapi.MAPI_DEFERRED_ERRORS)
!         yield store, name, def_store
! 
! def _FindSubfolder(store, folder, find_name):
!     find_name = find_name.lower()
!     table = folder.GetHierarchyTable(0)
!     rows = mapi.HrQueryAllRows(table, (PR_ENTRYID, PR_DISPLAY_NAME_A), None, None, 0)
!     for (eid_tag, eid), (name_tag, name), in rows:
!         if name.lower() == find_name:
!             return store.OpenEntry(eid, None, mapi.MAPI_DEFERRED_ERRORS)
!     return None
! 
! def FindFolder(name):
!     assert name
!     names = [n.lower() for n in name.split("\\")]
!     if names[0]:
!         for store, name, is_default in GetMessageStores():
!             if is_default:
!                 store_name = name.lower()
!                 break
!         folder_names = names
!     else:
!         store_name = names[1]
!         folder_names = names[2:]
!     # Find the store with the name
!     for store, name, is_default in GetMessageStores():
!         if name.lower() == store_name:
!             folder_store = store
!             break
!     else:
!         raise ValueError, "The store '%s' can not be located" % (store_name,)
! 
!     hr, data = store.GetProps((PR_IPM_SUBTREE_ENTRYID,), 0)
!     subtree_eid = data[0][1]
!     folder = folder_store.OpenEntry(subtree_eid, None, mapi.MAPI_DEFERRED_ERRORS)
! 
!     for name in folder_names:
!         folder = _FindSubfolder(folder_store, folder, name)
!         if folder is None:
!             raise ValueError, "The subfolder '%s' can not be located" % (name,)
!     return folder_store, folder        
  
  # Also in new versions of mapituil
--- 8,12 ----
  from win32com.mapi.mapitags import *
  
! import mapi_driver
  
  # Also in new versions of mapituil
***************
*** 95,114 ****
      return ret
  
- def _FindItemsWithValue(folder, prop_tag, prop_val):
-     tab = folder.GetContentsTable(0)
-     # Restriction for the table:  get rows where our prop values match
-     restriction = (mapi.RES_CONTENT,   # a property restriction
-                    (mapi.FL_SUBSTRING | mapi.FL_IGNORECASE | mapi.FL_LOOSE, # fuzz level
-                     prop_tag,   # of the given prop
-                     (prop_tag, prop_val))) # with given val
-     rows = mapi.HrQueryAllRows(tab,
-                                (PR_ENTRYID,),   # columns to retrieve
-                                restriction,     # only these rows
-                                None,            # any sort order is fine
-                                0)               # any # of results is fine
-     # get entry IDs
-     return [row[0][1] for row in rows]
- 
- 
  def DumpItemProps(item, shorten):
      for prop_name, prop_val in GetAllProperties(item):
--- 30,33 ----
***************
*** 118,131 ****
          print "%-20s: %s" % (prop_name, prop_repr)
  
! def DumpProps(mapi_msgstore, mapi_folder, subject, include_attach, shorten):
      hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
      name = data[0][1]
!     eids = _FindItemsWithValue(mapi_folder, PR_SUBJECT_A, subject)
!     print "Folder '%s' has %d items matching '%s'" % (name, len(eids), subject)
!     for eid in eids:
!         print "Dumping item with ID", mapi.HexFromBin(eid)
!         item = mapi_msgstore.OpenEntry(eid,
!                                        None,
!                                        mapi.MAPI_DEFERRED_ERRORS)
          DumpItemProps(item, shorten)
          if include_attach:
--- 37,44 ----
          print "%-20s: %s" % (prop_name, prop_repr)
  
! def DumpProps(driver, mapi_folder, subject, include_attach, shorten):
      hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
      name = data[0][1]
!     for item in driver.GetItemsWithValue(mapi_folder, PR_SUBJECT_A, subject):
          DumpItemProps(item, shorten)
          if include_attach:
***************
*** 139,160 ****
                  DumpItemProps(attach, shorten)
  
! def DumpTopLevelFolders():
!     print "Top-level folder names are:"
!     for store, name, is_default in GetMessageStores():
!         # Find the folder with the content.
!         hr, data = store.GetProps((PR_IPM_SUBTREE_ENTRYID,), 0)
!         subtree_eid = data[0][1]
!         folder = store.OpenEntry(subtree_eid, None, mapi.MAPI_DEFERRED_ERRORS)
!         # Now the top-level folders in the store.
!         table = folder.GetHierarchyTable(0)
!         rows = mapi.HrQueryAllRows(table, (PR_DISPLAY_NAME_A), None, None, 0)
!         for (name_tag, folder_name), in rows:
!             print " \\%s\\%s" % (name, folder_name)
! 
! def usage():
!     def_store_name = "<??unknown??>"
!     for store, name, is_def in GetMessageStores():
!         if is_def:
!             def_store_name = name
      msg = """\
  Usage: %s [-f foldername] subject of the message
--- 52,57 ----
                  DumpItemProps(attach, shorten)
  
! def usage(driver):
!     folder_doc = driver.GetFolderNameDoc()
      msg = """\
  Usage: %s [-f foldername] subject of the message
***************
*** 167,184 ****
  matching is substring and ignore-case.
  
! Folder name must be a hierarchical 'path' name, using '\\'
! as the path seperator.  If the folder name begins with a
! \\, it must be a fully-qualified name, including the message
! store name. For example, your Inbox can be specified either as:
!   -f "Inbox"
! or
!   -f "\\%s\\Inbox"
! 
! Use the -n option to see all top-level folder names from all stores.
! """ % (os.path.basename(sys.argv[0]), def_store_name)
      print msg
  
- 
  def main():
      import getopt
      try:
--- 64,75 ----
  matching is substring and ignore-case.
  
! %s
! Use the -n option to see all top-level folder names from all stores.""" \
!     % (os.path.basename(sys.argv[0]),folder_doc)
      print msg
  
  def main():
+     driver = mapi_driver.MAPIDriver()
+ 
      import getopt
      try:
***************
*** 187,191 ****
          print e
          print
!         usage()
          sys.exit(1)
      folder_name = ""
--- 78,82 ----
          print e
          print
!         usage(driver)
          sys.exit(1)
      folder_name = ""
***************
*** 201,205 ****
              include_attach = True
          elif opt == "-n":
!             DumpTopLevelFolders()
              sys.exit(1)
          else:
--- 92,96 ----
              include_attach = True
          elif opt == "-n":
!             driver.DumpTopLevelFolders()
              sys.exit(1)
          else:
***************
*** 214,227 ****
          print "You must specify a subject"
          print
!         usage()
          sys.exit(1)
  
      try:
!         store, folder = FindFolder(folder_name)
      except ValueError, details:
          print details
          sys.exit(1)
  
!     DumpProps(store, folder, subject, include_attach, shorten)
  
  if __name__=='__main__':
--- 105,118 ----
          print "You must specify a subject"
          print
!         usage(driver)
          sys.exit(1)
  
      try:
!         folder = driver.FindFolder(folder_name)
      except ValueError, details:
          print details
          sys.exit(1)
  
!     DumpProps(driver, folder, subject, include_attach, shorten)
  
  if __name__=='__main__':





More information about the Spambayes-checkins mailing list