view python/test.py @ 195:320cfcba8058

add python module interface to the shared library for easy scripting. the shared library must never write to stdout or stderr. fix pst_attach_to_mem so the caller does not need to initialize the buffer pointer.
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Apr 2009 19:39:26 -0700
parents
children ffd1503a7530
line wrap: on
line source

import _libpst, sys

for i in range(1,len(sys.argv)):
    print "try file %s" % (sys.argv[i])
    pst = _libpst.pst(sys.argv[i])
    topf = pst.pst_getTopOfFolders()

    while (topf):
        #print "topf d_id is %d\n" % (topf.d_id)
        item = pst.pst_parse_item(topf, None)
        if (item):
            if (item.type == 1):
                em = item.email
                if (em):
                    if (em.messageid.str):
                        print "message id is |%s|" % (em.messageid.str)
                    subj = item.subject;
                    if (subj.str):
                        print "subject is %s" % (subj.str)
                    body = item.body
                    #if (body.str):
                    #    print "message body is %s" % (body.str)
                    att = item.attach
                    while (att):
                        attid   = att.i_id
                        print "attachment id %d" % (attid)
                        att1 = att.filename1
                        att2 = att.filename2
                        print "attachment file name %s %s" % (att1.str, att2.str)
                        attdata = pst.pst_attach_to_mem(att)
                        if (attdata):
                            print "data size %d" % (len(attdata))
                        att = att.next
        topf = pst.pst_getNextDptr(topf)
    print "done"