Mercurial > libpst
annotate python/test.py @ 234:ed0cb66b23d4
better detection of dsn delivery reports
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 11 Sep 2009 12:46:36 -0700 |
parents | 268458c79e9b |
children | 1ddc61fd6189 |
rev | line source |
---|---|
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 import _libpst, sys |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
3 ft = _libpst.FILETIME() |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
4 ft.dwLowDateTime = 0 |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
5 ft.dwHighDateTime = 1 |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
6 |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
7 |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 for i in range(1,len(sys.argv)): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 print "try file %s" % (sys.argv[i]) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 pst = _libpst.pst(sys.argv[i]) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 topf = pst.pst_getTopOfFolders() |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
12 |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
13 print pst.pst_rfc2425_datetime_format(ft) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
14 print pst.pst_rfc2445_datetime_format(ft) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
15 |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 while (topf): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
17 #print "topf d_id is %d\n" % (topf.d_id) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
18 item = pst.pst_parse_item(topf, None) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
19 if (item): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
20 if (item.type == 1): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
21 em = item.email |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
22 if (em): |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
23 print "default charset %s" % (pst.pst_default_charset(item)) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
24 ft = em.arrival_date |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
25 if (ft): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
26 print "message arrived at %s" % (pst.pst_rfc2425_datetime_format(ft)) |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
27 if (em.messageid.str): |
204
268458c79e9b
more cleanup of the shared library interface, but still not fully thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
196
diff
changeset
|
28 print "message id is <%s>" % (em.messageid.str) |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
29 subj = item.subject; |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
30 if (subj and subj.str): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
31 was = subj.is_utf8; |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
32 pst.pst_convert_utf8(item, subj) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
33 now = subj.is_utf8; |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
34 if (was != now): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
35 print "subject was converted to utf8" |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
36 print "subject is %s" % (subj.str) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
37 body = item.body |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
38 #if (body.str): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
39 # print "message body is %s" % (body.str) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
40 att = item.attach |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
41 while (att): |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
42 attid = att.i_id |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
43 print "attachment id %d" % (attid) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
44 att1 = att.filename1 |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
45 att2 = att.filename2 |
204
268458c79e9b
more cleanup of the shared library interface, but still not fully thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
196
diff
changeset
|
46 print "attachment file name short '%s' long '%s'" % (att1.str, att2.str) |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
47 if (0): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
48 attdata = pst.pst_attach_to_mem(att) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
49 if (attdata): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
50 print "data size %d" % (len(attdata)) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
51 if (0): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
52 f = pst.ppst_open_file(att2.str, 'w') |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
53 if (f): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
54 si = pst.pst_attach_to_file_base64(att, f) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
55 pst.ppst_close_file(f) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
56 print "wrote %d bytes in %s" % (si, att2.str) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
57 if (1): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
58 f = pst.ppst_open_file(att2.str, 'w') |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
59 if (f): |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
60 si = pst.pst_attach_to_file(att, f) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
61 pst.ppst_close_file(f) |
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
62 print "wrote %d bytes in %s" % (si, att2.str) |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
63 att = att.next |
196
ffd1503a7530
build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
64 pst.pst_freeItem(item) |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
65 topf = pst.pst_getNextDptr(topf) |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
66 print "done" |
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
67 |