comparison python/python-libpst.cpp @ 198:7c60d6d1c681

decode more recurrence mapi elements
author Carl Byington <carl@five-ten-sg.com>
date Tue, 12 May 2009 19:34:49 -0700
parents ffd1503a7530
children e3a46f66332b
comparison
equal deleted inserted replaced
197:07ceebd115ce 198:7c60d6d1c681
25 { 25 {
26 }; 26 };
27 27
28 class pst { 28 class pst {
29 public: 29 public:
30 pst(const string filename); 30 pst(const string filename);
31 virtual ~pst(); 31 virtual ~pst();
32 pst_desc_tree* pst_getTopOfFolders(); 32 pst_desc_tree* pst_getTopOfFolders();
33 ppst_binary pst_attach_to_mem(pst_item_attach *attach); 33 ppst_binary pst_attach_to_mem(pst_item_attach *attach);
34 size_t pst_attach_to_file(pst_item_attach *attach, FILE* fp); 34 size_t pst_attach_to_file(pst_item_attach *attach, FILE* fp);
35 size_t pst_attach_to_file_base64(pst_item_attach *attach, FILE* fp); 35 size_t pst_attach_to_file_base64(pst_item_attach *attach, FILE* fp);
36 pst_desc_tree* pst_getNextDptr(pst_desc_tree* d); 36 pst_desc_tree* pst_getNextDptr(pst_desc_tree* d);
37 pst_item* pst_parse_item(pst_desc_tree *d_ptr, pst_id2_tree *m_head); 37 pst_item* pst_parse_item(pst_desc_tree *d_ptr, pst_id2_tree *m_head);
38 void pst_freeItem(pst_item *item); 38 void pst_freeItem(pst_item *item);
39 pst_index_ll* pst_getID(uint64_t i_id); 39 pst_index_ll* pst_getID(uint64_t i_id);
40 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type); 40 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type);
41 size_t pst_ff_getIDblock_dec(uint64_t i_id, char **buf); 41 size_t pst_ff_getIDblock_dec(uint64_t i_id, char **buf);
42 size_t pst_ff_getIDblock(uint64_t i_id, char** buf); 42 size_t pst_ff_getIDblock(uint64_t i_id, char** buf);
43 string pst_rfc2426_escape(char *str); 43 string pst_rfc2426_escape(char *str);
44 string pst_rfc2425_datetime_format(const FILETIME *ft); 44 string pst_rfc2425_datetime_format(const FILETIME *ft);
45 string pst_rfc2445_datetime_format(const FILETIME *ft); 45 string pst_rfc2445_datetime_format(const FILETIME *ft);
46 string pst_default_charset(pst_item *item); 46 string pst_default_charset(pst_item *item);
47 void pst_convert_utf8_null(pst_item *item, pst_string *str); 47 void pst_convert_utf8_null(pst_item *item, pst_string *str);
48 void pst_convert_utf8(pst_item *item, pst_string *str); 48 void pst_convert_utf8(pst_item *item, pst_string *str);
49 pst_recurrence* pst_convert_recurrence(pst_item_appointment *appt);
50 void pst_free_recurrence(pst_recurrence* r);
49 51
50 /** helper for python access to fopen() */ 52 /** helper for python access to fopen() */
51 FILE* ppst_open_file(string filename, string mode); 53 FILE* ppst_open_file(string filename, string mode);
52 /** helper for python access to fclose() */ 54 /** helper for python access to fclose() */
53 int ppst_close_file(FILE* fp); 55 int ppst_close_file(FILE* fp);
77 pst::~pst() { 79 pst::~pst() {
78 if (root) pst_freeItem(root); 80 if (root) pst_freeItem(root);
79 if (is_open) ::pst_close(&pf); 81 if (is_open) ::pst_close(&pf);
80 } 82 }
81 83
82 pst_desc_tree* pst::pst_getTopOfFolders() { 84 pst_desc_tree* pst::pst_getTopOfFolders() {
83 return topf; 85 return topf;
84 } 86 }
85 87
86 ppst_binary pst::pst_attach_to_mem(pst_item_attach *attach) { 88 ppst_binary pst::pst_attach_to_mem(pst_item_attach *attach) {
89 pst_binary r = ::pst_attach_to_mem(&pf, attach);
87 ppst_binary rc; 90 ppst_binary rc;
88 rc.size = rc.size = ::pst_attach_to_mem(&pf, attach, &rc.data); 91 rc.size = r.size;
92 rc.data = r.data;
89 return rc; 93 return rc;
90 } 94 }
91 95
92 size_t pst::pst_attach_to_file(pst_item_attach *attach, FILE* fp) { 96 size_t pst::pst_attach_to_file(pst_item_attach *attach, FILE* fp) {
93 return ::pst_attach_to_file(&pf, attach, fp); 97 return ::pst_attach_to_file(&pf, attach, fp);
94 } 98 }
95 99
96 size_t pst::pst_attach_to_file_base64(pst_item_attach *attach, FILE* fp) { 100 size_t pst::pst_attach_to_file_base64(pst_item_attach *attach, FILE* fp) {
97 return ::pst_attach_to_file_base64(&pf, attach, fp); 101 return ::pst_attach_to_file_base64(&pf, attach, fp);
98 } 102 }
99 103
100 pst_desc_tree* pst::pst_getNextDptr(pst_desc_tree* d) { 104 pst_desc_tree* pst::pst_getNextDptr(pst_desc_tree* d) {
101 return ::pst_getNextDptr(d); 105 return ::pst_getNextDptr(d);
102 } 106 }
103 107
104 pst_item* pst::pst_parse_item (pst_desc_tree *d_ptr, pst_id2_tree *m_head) { 108 pst_item* pst::pst_parse_item (pst_desc_tree *d_ptr, pst_id2_tree *m_head) {
105 return ::pst_parse_item(&pf, d_ptr, m_head); 109 return ::pst_parse_item(&pf, d_ptr, m_head);
106 } 110 }
107 111
108 void pst::pst_freeItem(pst_item *item) { 112 void pst::pst_freeItem(pst_item *item) {
109 return ::pst_freeItem(item); 113 return ::pst_freeItem(item);
110 } 114 }
111 115
112 pst_index_ll* pst::pst_getID(uint64_t i_id) { 116 pst_index_ll* pst::pst_getID(uint64_t i_id) {
113 return ::pst_getID(&pf, i_id); 117 return ::pst_getID(&pf, i_id);
114 } 118 }
115 119
116 int pst::pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) { 120 int pst::pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) {
117 return ::pst_decrypt(i_id, buf, size, type); 121 return ::pst_decrypt(i_id, buf, size, type);
118 } 122 }
119 123
120 size_t pst::pst_ff_getIDblock_dec(uint64_t i_id, char **buf) { 124 size_t pst::pst_ff_getIDblock_dec(uint64_t i_id, char **buf) {
121 return ::pst_ff_getIDblock_dec(&pf, i_id, buf); 125 return ::pst_ff_getIDblock_dec(&pf, i_id, buf);
122 } 126 }
123 127
124 size_t pst::pst_ff_getIDblock(uint64_t i_id, char** buf) { 128 size_t pst::pst_ff_getIDblock(uint64_t i_id, char** buf) {
125 return ::pst_ff_getIDblock(&pf, i_id, buf); 129 return ::pst_ff_getIDblock(&pf, i_id, buf);
126 } 130 }
127 131
128 string pst::pst_rfc2426_escape(char *str) { 132 string pst::pst_rfc2426_escape(char *str) {
129 return ::pst_rfc2426_escape(str); 133 return ::pst_rfc2426_escape(str);
130 } 134 }
131 135
132 string pst::pst_rfc2425_datetime_format(const FILETIME *ft) { 136 string pst::pst_rfc2425_datetime_format(const FILETIME *ft) {
133 return ::pst_rfc2425_datetime_format((FILETIME *)ft); // cast away const is ok, since libpst did not modify it anyway, and the signature will change in more recent versions 137 return ::pst_rfc2425_datetime_format((FILETIME *)ft); // cast away const is ok, since libpst did not modify it anyway, and the signature will change in more recent versions
134 } 138 }
135 139
136 string pst::pst_rfc2445_datetime_format(const FILETIME *ft) { 140 string pst::pst_rfc2445_datetime_format(const FILETIME *ft) {
137 return ::pst_rfc2445_datetime_format((FILETIME *)ft); // cast away const is ok, since libpst did not modify it anyway, and the signature will change in more recent versions 141 return ::pst_rfc2445_datetime_format((FILETIME *)ft); // cast away const is ok, since libpst did not modify it anyway, and the signature will change in more recent versions
138 } 142 }
139 143
140 string pst::pst_default_charset(pst_item *item) { 144 string pst::pst_default_charset(pst_item *item) {
141 return ::pst_default_charset(item); 145 return ::pst_default_charset(item);
142 } 146 }
143 147
144 void pst::pst_convert_utf8_null(pst_item *item, pst_string *str) { 148 void pst::pst_convert_utf8_null(pst_item *item, pst_string *str) {
145 ::pst_convert_utf8_null(item, str); 149 ::pst_convert_utf8_null(item, str);
146 } 150 }
147 151
148 void pst::pst_convert_utf8(pst_item *item, pst_string *str) { 152 void pst::pst_convert_utf8(pst_item *item, pst_string *str) {
149 ::pst_convert_utf8(item, str); 153 ::pst_convert_utf8(item, str);
154 }
155
156 pst_recurrence* pst::pst_convert_recurrence(pst_item_appointment *appt)
157 {
158 return ::pst_convert_recurrence(appt);
159 }
160
161 void pst::pst_free_recurrence(pst_recurrence* r)
162 {
163 ::pst_free_recurrence(r);
150 } 164 }
151 165
152 FILE* pst::ppst_open_file(string filename, string mode) { 166 FILE* pst::ppst_open_file(string filename, string mode) {
153 return ::fopen(filename.c_str(), mode.c_str()); 167 return ::fopen(filename.c_str(), mode.c_str());
154 } 168 }
187 } 201 }
188 return NULL; 202 return NULL;
189 } 203 }
190 }; 204 };
191 205
206 struct make_python_pst_recurrence {
207 static PyObject* convert(pst_recurrence* const &s) {
208 if (s) return to_python_indirect<pst_recurrence*, detail::make_reference_holder>()(s);
209 return NULL;
210 }
211 };
212
192 struct make_python_pst_item_email { 213 struct make_python_pst_item_email {
193 static PyObject* convert(pst_item_email* const &s) { 214 static PyObject* convert(pst_item_email* const &s) {
194 if (s) return to_python_indirect<pst_item_email*, detail::make_reference_holder>()(s); 215 if (s) return to_python_indirect<pst_item_email*, detail::make_reference_holder>()(s);
195 return NULL; 216 return NULL;
196 } 217 }
229 //boost::python::docstring_options doc_options(); 250 //boost::python::docstring_options doc_options();
230 251
231 to_python_converter<pst_binary, make_python_pst_binary>(); 252 to_python_converter<pst_binary, make_python_pst_binary>();
232 to_python_converter<ppst_binary, make_python_ppst_binary>(); 253 to_python_converter<ppst_binary, make_python_ppst_binary>();
233 to_python_converter<char*, make_python_string>(); 254 to_python_converter<char*, make_python_string>();
255 to_python_converter<pst_recurrence*, make_python_pst_recurrence>();
234 to_python_converter<pst_item_email*, make_python_pst_item_email>(); 256 to_python_converter<pst_item_email*, make_python_pst_item_email>();
235 to_python_converter<pst_item_attach*, make_python_pst_item_attach>(); 257 to_python_converter<pst_item_attach*, make_python_pst_item_attach>();
236 to_python_converter<pst_desc_tree*, make_python_pst_desc_tree>(); 258 to_python_converter<pst_desc_tree*, make_python_pst_desc_tree>();
237 to_python_converter<pst_index_ll*, make_python_pst_index_ll>(); 259 to_python_converter<pst_index_ll*, make_python_pst_index_ll>();
238 to_python_converter<FILE*, make_python_FILE>(); 260 to_python_converter<FILE*, make_python_FILE>();
365 .def_readonly("valid_mask", &pst_item_message_store::valid_mask) 387 .def_readonly("valid_mask", &pst_item_message_store::valid_mask)
366 .def_readonly("pwd_chksum", &pst_item_message_store::pwd_chksum) 388 .def_readonly("pwd_chksum", &pst_item_message_store::pwd_chksum)
367 ; 389 ;
368 390
369 class_<pst_item_contact>("pst_item_contact") 391 class_<pst_item_contact>("pst_item_contact")
370 .def_readonly("access_method", &pst_item_contact::access_method)
371 .def_readonly("account_name", &pst_item_contact::account_name) 392 .def_readonly("account_name", &pst_item_contact::account_name)
372 .def_readonly("address1", &pst_item_contact::address1) 393 .def_readonly("address1", &pst_item_contact::address1)
373 .def_readonly("address1a", &pst_item_contact::address1a) 394 .def_readonly("address1a", &pst_item_contact::address1a)
374 .def_readonly("address1_desc", &pst_item_contact::address1_desc) 395 .def_readonly("address1_desc", &pst_item_contact::address1_desc)
375 .def_readonly("address1_transport", &pst_item_contact::address1_transport) 396 .def_readonly("address1_transport", &pst_item_contact::address1_transport)
488 .def_readonly("value", &pst_item_extra_field::value) 509 .def_readonly("value", &pst_item_extra_field::value)
489 .add_property("next", make_getter(&pst_item_extra_field::next, return_value_policy<reference_existing_object>())) 510 .add_property("next", make_getter(&pst_item_extra_field::next, return_value_policy<reference_existing_object>()))
490 ; 511 ;
491 512
492 class_<pst_item_journal>("pst_item_journal") 513 class_<pst_item_journal>("pst_item_journal")
514 .add_property("start", make_getter(&pst_item_journal::start, return_value_policy<reference_existing_object>()))
493 .add_property("end", make_getter(&pst_item_journal::end, return_value_policy<reference_existing_object>())) 515 .add_property("end", make_getter(&pst_item_journal::end, return_value_policy<reference_existing_object>()))
494 .add_property("start", make_getter(&pst_item_journal::start, return_value_policy<reference_existing_object>()))
495 .def_readonly("type", &pst_item_journal::type) 516 .def_readonly("type", &pst_item_journal::type)
496 .def_readonly("description", &pst_item_journal::description) 517 .def_readonly("description", &pst_item_journal::description)
497 ; 518 ;
498 519
520 class_<pst_recurrence>("pst_recurrence")
521 .def_readonly("signature", &pst_recurrence::signature)
522 .def_readonly("type", &pst_recurrence::type)
523 .def_readonly("sub_type", &pst_recurrence::sub_type)
524 .def_readonly("parm1", &pst_recurrence::parm1)
525 .def_readonly("parm2", &pst_recurrence::parm2)
526 .def_readonly("parm3", &pst_recurrence::parm3)
527 .def_readonly("parm4", &pst_recurrence::parm4)
528 .def_readonly("parm5", &pst_recurrence::parm5)
529 .def_readonly("termination", &pst_recurrence::termination)
530 .def_readonly("interval", &pst_recurrence::interval)
531 .def_readonly("count", &pst_recurrence::count)
532 ;
533
499 class_<pst_item_appointment>("pst_item_appointment") 534 class_<pst_item_appointment>("pst_item_appointment")
535 .add_property("start", make_getter(&pst_item_appointment::start, return_value_policy<reference_existing_object>()))
500 .add_property("end", make_getter(&pst_item_appointment::end, return_value_policy<reference_existing_object>())) 536 .add_property("end", make_getter(&pst_item_appointment::end, return_value_policy<reference_existing_object>()))
501 .def_readonly("location", &pst_item_appointment::location) 537 .def_readonly("location", &pst_item_appointment::location)
538 .def_readonly("alarm", &pst_item_appointment::alarm)
502 .add_property("reminder", make_getter(&pst_item_appointment::reminder, return_value_policy<reference_existing_object>())) 539 .add_property("reminder", make_getter(&pst_item_appointment::reminder, return_value_policy<reference_existing_object>()))
503 .def_readonly("alarm_minutes", &pst_item_appointment::alarm_minutes) 540 .def_readonly("alarm_minutes", &pst_item_appointment::alarm_minutes)
504 .def_readonly("alarm_filename", &pst_item_appointment::alarm_filename) 541 .def_readonly("alarm_filename", &pst_item_appointment::alarm_filename)
505 .add_property("start", make_getter(&pst_item_appointment::start, return_value_policy<reference_existing_object>()))
506 .def_readonly("timezonestring", &pst_item_appointment::timezonestring) 542 .def_readonly("timezonestring", &pst_item_appointment::timezonestring)
507 .def_readonly("showas", &pst_item_appointment::showas) 543 .def_readonly("showas", &pst_item_appointment::showas)
508 .def_readonly("label", &pst_item_appointment::label) 544 .def_readonly("label", &pst_item_appointment::label)
509 .def_readonly("all_day", &pst_item_appointment::all_day) 545 .def_readonly("all_day", &pst_item_appointment::all_day)
510 .def_readonly("recurrence", &pst_item_appointment::recurrence) 546 .def_readonly("is_recurring", &pst_item_appointment::is_recurring)
511 .def_readonly("recurrence_type", &pst_item_appointment::recurrence_type) 547 .def_readonly("recurrence_type", &pst_item_appointment::recurrence_type)
548 .def_readonly("recurrence_description", &pst_item_appointment::recurrence_description)
549 .def_readonly("recurrence_data", &pst_item_appointment::recurrence_data)
512 .add_property("recurrence_start", make_getter(&pst_item_appointment::recurrence_start, return_value_policy<reference_existing_object>())) 550 .add_property("recurrence_start", make_getter(&pst_item_appointment::recurrence_start, return_value_policy<reference_existing_object>()))
513 .add_property("recurrence_end", make_getter(&pst_item_appointment::recurrence_end, return_value_policy<reference_existing_object>())) 551 .add_property("recurrence_end", make_getter(&pst_item_appointment::recurrence_end, return_value_policy<reference_existing_object>()))
514 ; 552 ;
515 553
516 class_<pst_item>("pst_item") 554 class_<pst_item>("pst_item")