win32com: Accessing MAPIOBJECT

Rudy Schockaert rudy.schockaert at pandora.be
Thu Mar 13 15:54:38 EST 2003


> I've been tinkering with win32com in the hopes of being able to convert
> some of the mail in some of my Outlook folders into a mbox for use with
> SpamBayes. I've figured out how to access them messages, but they seem to
> only have the interfaces that Outlook itself needs: Body, Subject, etc,
and
> not the full headers for example.

That's why you better access the messages with CDO.

The information I think you are referring to is held in the
PR_TRANSPORT_MESSAGE_HEADERS (0x007D001E) property of the message. In CDO
you can easily obtain that property via the Fields property of the message.
I modified your original example in one that uses CDO instead. I tested it
and it works ;-)

By default CDO isn't included when you install Outlook, so it's possible
that you'll have to add Collaboration Data Objects form the Outlook Options.

from win32com.client import Dispatch
import pythoncom

def ol_walk(Folders, depth = 0):

    for fnum in range(Folders.Count):
        msgs = Folders[fnum+1].Messages

        spacer = " " * (5 * depth)
        dash = "-" * depth

        print "%sFolder: %s Number of Messages: %d" % \
            (dash, Folders[fnum+1].Name, msgs.Count)

        if msgs.Count:
            for mnum in range(msgs.Count):
                try:
                    print "%s Subject: %s" % \
                        (spacer, msgs[mnum+1].Subject.encode())
                except UnicodeError, msg:
                    print "%s Unicode Error: %s" % (spacer, msg)
                try:
                    print "%s    Transportheaders : %s" % \
                     (spacer, msgs[mnum+1].Fields[0x007D001F].Value)
                except :
                    print "%s    No Transportheaders" % spacer

        ol_walk(Folders.Item(fnum+1).Folders, depth + 1)

cdo = Dispatch("MAPI.Session")
cdo.logon
for i in range(cdo.InfoStores.Count):
    if cdo.InfoStores[i + 1].Name[:7] == 'Mailbox':
     ol_walk(cdo.InfoStores[i + 1].RootFolder.Folders)








More information about the Python-list mailing list