home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32com_test_testExchange.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  2.0 KB  |  84 lines

  1. # TestExchange = Exchange Server Dump
  2.  
  3. from win32com.client import gencache, constants
  4. import pythoncom
  5.  
  6. ammodule = gencache.EnsureModule('{3FA7DEA7-6438-101B-ACC1-00AA00423326}', 0, 1, 1)
  7.  
  8. def GetDefaultProfileName():
  9.     import win32api, win32con
  10.     try:
  11.         key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles")
  12.         try:
  13.             return win32api.RegQueryValueEx(key, "DefaultProfile")[0]
  14.         finally:
  15.             key.Close()
  16.     except win32api.error:
  17.         return None
  18.  
  19. #
  20. # Recursive dump of folders.
  21. #
  22. def DumpFolder(folder, indent = 0):
  23.     print " " * indent, folder.Name
  24.     folders = folder.Folders
  25.     folder = folders.GetFirst()
  26.     while folder:
  27.         DumpFolder(folder, indent+1)
  28.         folder = folders.GetNext()
  29.  
  30. def DumpFolders(session):
  31.     infostores = session.InfoStores
  32.     print infostores
  33.     print "There are %d infostores" % infostores.Count
  34.     for i in range(infostores.Count):
  35.         infostore = infostores[i+1]
  36.         print "Infostore = ", infostore.Name
  37.         folder = infostore.RootFolder
  38.         DumpFolder(folder)
  39.  
  40. # Build a dictionary of property tags, so I can reverse look-up
  41. #
  42. PropTagsById={}
  43. for name, val in ammodule.constants.__dict__.items():
  44.     PropTagsById[val] = name
  45.  
  46.  
  47. def TestAddress(session):
  48. #    entry = session.GetAddressEntry("Skip")
  49. #    print entry
  50.     pass
  51.  
  52.  
  53. def TestUser(session):
  54.     ae = session.CurrentUser
  55.     fields = ae.Fields
  56.     print "User has %d fields" % fields.Count
  57.     for f in range(len(fields)):
  58.         field = fields[f+1]
  59.         try:
  60.             id = PropTagsById[field.ID]
  61.         except KeyError:
  62.             id = field.ID
  63.         print "%s/%s=%s" % (field.Name, id, field.Value)
  64.             
  65. def test():
  66.     import win32com.client
  67.     session = win32com.client.Dispatch("MAPI.Session")
  68.     try:
  69.         session.Logon(GetDefaultProfileName())
  70.     except pythoncom.com_error, details:
  71.         print "Could not log on to MAPI:", details
  72.         return
  73.     try:
  74.         TestUser(session)
  75.         TestAddress(session)
  76.         DumpFolders(session)
  77.     finally:
  78.         session.Logoff
  79.  
  80. if __name__=='__main__':
  81.     from util import CheckClean
  82.     test()
  83.     CheckClean()
  84.