home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2741 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.4 KB  |  126 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from win32com.client import gencache, constants
  5. import pythoncom
  6. import os
  7. ammodule = None
  8.  
  9. def GetDefaultProfileName():
  10.     import win32api
  11.     import win32con
  12.     
  13.     try:
  14.         key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles')
  15.         
  16.         try:
  17.             return win32api.RegQueryValueEx(key, 'DefaultProfile')[0]
  18.         finally:
  19.             key.Close()
  20.  
  21.     except win32api.error:
  22.         return None
  23.  
  24.  
  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.  
  34.  
  35. def DumpFolders(session):
  36.     
  37.     try:
  38.         infostores = session.InfoStores
  39.     except AttributeError:
  40.         store = session.DefaultStore
  41.         folder = store.GetRootFolder()
  42.         DumpFolder(folder)
  43.         return None
  44.  
  45.     print infostores
  46.     print 'There are %d infostores' % infostores.Count
  47.     for i in range(infostores.Count):
  48.         infostore = infostores[i + 1]
  49.         print 'Infostore = ', infostore.Name
  50.         
  51.         try:
  52.             folder = infostore.RootFolder
  53.         except pythoncom.com_error:
  54.             details = None
  55.             (hr, msg, exc, arg) = details
  56.             if exc and exc[-1] == -2147221219:
  57.                 print 'This info store is currently not available'
  58.                 continue
  59.             
  60.         except:
  61.             exc[-1] == -2147221219
  62.  
  63.         DumpFolder(folder)
  64.     
  65.  
  66. PropTagsById = { }
  67. if ammodule:
  68.     for name, val in ammodule.constants.__dict__.items():
  69.         PropTagsById[val] = name
  70.     
  71.  
  72.  
  73. def TestAddress(session):
  74.     pass
  75.  
  76.  
  77. def TestUser(session):
  78.     ae = session.CurrentUser
  79.     fields = getattr(ae, 'Fields', [])
  80.     print 'User has %d fields' % len(fields)
  81.     for f in range(len(fields)):
  82.         field = fields[f + 1]
  83.         
  84.         try:
  85.             id = PropTagsById[field.ID]
  86.         except KeyError:
  87.             id = field.ID
  88.  
  89.         print '%s/%s=%s' % (field.Name, id, field.Value)
  90.     
  91.  
  92.  
  93. def test():
  94.     import win32com.client as win32com
  95.     oldcwd = os.getcwd()
  96.     
  97.     try:
  98.         session = gencache.EnsureDispatch('MAPI.Session')
  99.         
  100.         try:
  101.             session.Logon(GetDefaultProfileName())
  102.         except pythoncom.com_error:
  103.             details = None
  104.             print 'Could not log on to MAPI:', details
  105.             return None
  106.  
  107.     except pythoncom.error:
  108.         app = gencache.EnsureDispatch('Outlook.Application')
  109.         session = app.Session
  110.  
  111.     
  112.     try:
  113.         TestUser(session)
  114.         TestAddress(session)
  115.         DumpFolders(session)
  116.     finally:
  117.         session.Logoff()
  118.         os.chdir(oldcwd)
  119.  
  120.  
  121. if __name__ == '__main__':
  122.     from util import CheckClean
  123.     test()
  124.     CheckClean()
  125.  
  126.