Probable Pywin32 (win32com.client) bug??

neblackcat neblackcat at yahoo.com.au
Thu Jul 15 10:47:40 EDT 2004


> Not very helpful, but... using the standard Python 2.3.4 and the most recent
> pywin32 on my Win2K box with Outlook 2000 and Exchanhge 5.5, I can traverse 
> folders via CDO without any crashes. I realise that this isn't in any way 
> conclusive but if you want to post some code, I'll happily run it against 
> my setup if possible to see what happens.

Ok thanks! I've attached the full code below.

Basically you just point it at a profile and it runs through
"containers" in the hierarchy (containers being infostores,
root-folder folders, and normal folders) building up the hierarchy
recursively.

Each container is loaded into an MAContainerCdo object along with its
direct sub-containers. The first one created is just a "Root"
container which only exists to represent the top of the hierachy (ie.
it doesnt represent any actual CDO object), but its initialisation
causes all of the container hierarchy to be recursively loaded.

It doesnt access any messages - just the actual folder objects. Once
the folder hierarchy is loaded, it just dumps out the folder names
(also recursively).

I'm using a test profile made in OL2003, which just has a local
Personal Message Store as I dont have an Exchange server, but I dont
imagine that matters.

The version below crashes on loop 21 every time I run it on my command
line, or loop 46 if I run it in the IDE (Komodo)!

If I comment-in the "good" lines (as commented in the following) - no
crashes!!

Thanks again...

---------------------------------------------------------------------

import win32com.client

#This script only reads/dumps the individual folders found in a
specified profile, but it
# might crash Python while doing it, so keep a backup of the relevant
PST files just in case!

# Set this to the Mapi/Outlook profile to use.
sMapiProfile = "Test2"

class MAContainerCdo:

  def __init__  (self, session, oParent=None, oCdoContainer=None):
    
    self.session       = session
    self.oParent       = oParent
    self.oChildren     = []
    self.oCdoContainer = oCdoContainer

    if self.oParent is None:
      self.nLevel     = 0
      self.sFullName  = 'Root'
    else:
      self.nLevel     = self.oParent.nLevel + 1
      self.sFullName  = self.oParent.sFullName + "/" +
self.oCdoContainer.Name
      
    # Get the children of this object into self.oChildren list:
    # - if its the root (level=0) then children are infostores,
    # - if its an infostore (level=1) then children are ths subfolders
of the infostore's root folder,
    # - if its a folder (level>1) then children are folder's
subfolders.
    
    if self.nLevel == 0:
      oc = self.session.InfoStores
    elif self.nLevel == 1:
      oc = self.oCdoContainer.RootFolder.Folders
    else:
      oc = self.oCdoContainer.Folders

    # THIS MAKES PYTHON CRASH (BUT NOT UNTIL LATER!)
    for o in oc:
      self.oChildren.append(MAContainerCdo(self.session, self, o))

    # THIS DOESNT (BUT IS FUNCTIONALLY IDENTICAL)!
    #if self.nLevel == 0:
    #  for o in oc:
    #    self.oChildren.append(MAContainerCdo(self.session, self, o))
    #else:
    #  o = oc.GetFirst()
    #  while o:
    #    self.oChildren.append(MAContainerCdo(self.session, self, o))
    #    o = oc.GetNext()
      

  def	Dump	(self):
    print "%-30s (%d children)" % (self.sFullName,
len(self.oChildren))
    for o in self.oChildren:
      o.Dump()
    
session = win32com.client.Dispatch('MAPI.Session')

for i in range(1,100):
    print "\nLoop " + str(i)
    session.Logon(sMapiProfile)
    ocRoot = MAContainerCdo(session)
    ocRoot.Dump ()
    session.Logoff()



More information about the Python-list mailing list