0001 # TestExchange = Exchange Server Dump 0002 # Note that this code uses "CDO", which is unlikely to get the best choice. 0003 # You should use the Outlook object model, or 0004 # the win32com.mapi examples for a low-level interface. 0005 0006 from win32com.client import gencache, constants 0007 import pythoncom 0008 import os 0009 0010 ammodule = gencache.EnsureModule('{3FA7DEA7-6438-101B-ACC1-00AA00423326}', 0, 1, 1) 0011 0012 def GetDefaultProfileName(): 0013 import win32api, win32con 0014 try: 0015 key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles") 0016 try: 0017 return win32api.RegQueryValueEx(key, "DefaultProfile")[0] 0018 finally: 0019 key.Close() 0020 except win32api.error: 0021 return None 0022 0023 # 0024 # Recursive dump of folders. 0025 # 0026 def DumpFolder(folder, indent = 0): 0027 print " " * indent, folder.Name 0028 folders = folder.Folders 0029 folder = folders.GetFirst() 0030 while folder: 0031 DumpFolder(folder, indent+1) 0032 folder = folders.GetNext() 0033 0034 def DumpFolders(session): 0035 infostores = session.InfoStores 0036 print infostores 0037 print "There are %d infostores" % infostores.Count 0038 for i in range(infostores.Count): 0039 infostore = infostores[i+1] 0040 print "Infostore = ", infostore.Name 0041 try: 0042 folder = infostore.RootFolder 0043 except pythoncom.com_error, details: 0044 hr, msg, exc, arg = details 0045 # -2147221219 == MAPI_E_FAILONEPROVIDER - a single provider temporarily not available. 0046 if exc and exc[-1]==-2147221219: 0047 print "This info store is currently not available" 0048 continue 0049 DumpFolder(folder) 0050 0051 # Build a dictionary of property tags, so I can reverse look-up 0052 # 0053 PropTagsById={} 0054 for name, val in ammodule.constants.__dict__.items(): 0055 PropTagsById[val] = name 0056 0057 0058 def TestAddress(session): 0059 # entry = session.GetAddressEntry("Skip") 0060 # print entry 0061 pass 0062 0063 0064 def TestUser(session): 0065 ae = session.CurrentUser 0066 fields = ae.Fields 0067 print "User has %d fields" % fields.Count 0068 for f in range(len(fields)): 0069 field = fields[f+1] 0070 try: 0071 id = PropTagsById[field.ID] 0072 except KeyError: 0073 id = field.ID 0074 print "%s/%s=%s" % (field.Name, id, field.Value) 0075 0076 def test(): 0077 import win32com.client 0078 oldcwd = os.getcwd() 0079 session = win32com.client.Dispatch("MAPI.Session") 0080 try: 0081 session.Logon(GetDefaultProfileName()) 0082 except pythoncom.com_error, details: 0083 print "Could not log on to MAPI:", details 0084 return 0085 try: 0086 TestUser(session) 0087 TestAddress(session) 0088 DumpFolders(session) 0089 finally: 0090 session.Logoff() 0091 # It appears Exchange will change the cwd on us :( 0092 os.chdir(oldcwd) 0093 0094 if __name__=='__main__': 0095 from util import CheckClean 0096 test() 0097 CheckClean() 0098
Generated by PyXR 0.9.4