Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testExchange.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # TestExchange = Exchange Server Dump
  2. # Note that this code uses "CDO", which is unlikely to get the best choice.
  3. # You should use the Outlook object model, or
  4. # the win32com.mapi examples for a low-level interface.
  5. import os
  6. import pythoncom
  7. from win32com.client import constants, gencache
  8. ammodule = None # was the generated module!
  9. def GetDefaultProfileName():
  10. import win32api
  11. import win32con
  12. try:
  13. key = win32api.RegOpenKey(
  14. win32con.HKEY_CURRENT_USER,
  15. "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles",
  16. )
  17. try:
  18. return win32api.RegQueryValueEx(key, "DefaultProfile")[0]
  19. finally:
  20. key.Close()
  21. except win32api.error:
  22. return None
  23. #
  24. # Recursive dump of folders.
  25. #
  26. def DumpFolder(folder, indent=0):
  27. print(" " * indent, folder.Name)
  28. folders = folder.Folders
  29. folder = folders.GetFirst()
  30. while folder:
  31. DumpFolder(folder, indent + 1)
  32. folder = folders.GetNext()
  33. def DumpFolders(session):
  34. try:
  35. infostores = session.InfoStores
  36. except AttributeError:
  37. # later outlook?
  38. store = session.DefaultStore
  39. folder = store.GetRootFolder()
  40. DumpFolder(folder)
  41. return
  42. print(infostores)
  43. print("There are %d infostores" % infostores.Count)
  44. for i in range(infostores.Count):
  45. infostore = infostores[i + 1]
  46. print("Infostore = ", infostore.Name)
  47. try:
  48. folder = infostore.RootFolder
  49. except pythoncom.com_error as details:
  50. hr, msg, exc, arg = details
  51. # -2147221219 == MAPI_E_FAILONEPROVIDER - a single provider temporarily not available.
  52. if exc and exc[-1] == -2147221219:
  53. print("This info store is currently not available")
  54. continue
  55. DumpFolder(folder)
  56. # Build a dictionary of property tags, so I can reverse look-up
  57. #
  58. PropTagsById = {}
  59. if ammodule:
  60. for name, val in ammodule.constants.__dict__.items():
  61. PropTagsById[val] = name
  62. def TestAddress(session):
  63. # entry = session.GetAddressEntry("Skip")
  64. # print entry
  65. pass
  66. def TestUser(session):
  67. ae = session.CurrentUser
  68. fields = getattr(ae, "Fields", [])
  69. print("User has %d fields" % len(fields))
  70. for f in range(len(fields)):
  71. field = fields[f + 1]
  72. try:
  73. id = PropTagsById[field.ID]
  74. except KeyError:
  75. id = field.ID
  76. print("%s/%s=%s" % (field.Name, id, field.Value))
  77. def test():
  78. import win32com.client
  79. oldcwd = os.getcwd()
  80. try:
  81. session = gencache.EnsureDispatch("MAPI.Session")
  82. try:
  83. session.Logon(GetDefaultProfileName())
  84. except pythoncom.com_error as details:
  85. print("Could not log on to MAPI:", details)
  86. return
  87. except pythoncom.error:
  88. # no mapi.session - let's try outlook
  89. app = gencache.EnsureDispatch("Outlook.Application")
  90. session = app.Session
  91. try:
  92. TestUser(session)
  93. TestAddress(session)
  94. DumpFolders(session)
  95. finally:
  96. session.Logoff()
  97. # It appears Exchange will change the cwd on us :(
  98. os.chdir(oldcwd)
  99. if __name__ == "__main__":
  100. from .util import CheckClean
  101. test()
  102. CheckClean()