annotate python/test.py @ 196:ffd1503a7530

build proper python rpm subpackage
author Carl Byington <carl@five-ten-sg.com>
date Wed, 22 Apr 2009 13:52:18 -0700
parents 320cfcba8058
children 268458c79e9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 print _libpst.__dict__
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
4 exit
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
5
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
6 ft = _libpst.FILETIME()
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
7 ft.dwLowDateTime = 0
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
8 ft.dwHighDateTime = 1
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
9
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
10
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 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
12 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
13 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
14 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
15
196
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
16 print pst.pst_rfc2425_datetime_format(ft)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
17 print pst.pst_rfc2445_datetime_format(ft)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
18
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 while (topf):
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 #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
21 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
22 if (item):
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 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
24 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
25 if (em):
196
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
26 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
27 ft = em.arrival_date
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
28 if (ft):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
29 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
30 if (em.messageid.str):
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 print "message id is |%s|" % (em.messageid.str)
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 subj = item.subject;
196
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
33 if (subj and subj.str):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
34 was = subj.is_utf8;
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
35 pst.pst_convert_utf8(item, subj)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
36 now = subj.is_utf8;
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
37 if (was != now):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
38 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
39 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
40 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
41 #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
42 # 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
43 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
44 while (att):
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 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
46 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
47 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
48 att2 = att.filename2
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 print "attachment file name %s %s" % (att1.str, att2.str)
196
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
50 if (0):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
51 attdata = pst.pst_attach_to_mem(att)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
52 if (attdata):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
53 print "data size %d" % (len(attdata))
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
54 if (0):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
55 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
56 if (f):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
57 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
58 pst.ppst_close_file(f)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
59 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
60 if (1):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
61 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
62 if (f):
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
63 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
64 pst.ppst_close_file(f)
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
65 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
66 att = att.next
196
ffd1503a7530 build proper python rpm subpackage
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
67 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
68 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
69 print "done"
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70