comparison libpst.h @ 0:6b1b602514db libpst_0_5

Initial revision
author carl
date Fri, 09 Jul 2004 07:26:16 -0700
parents
children 43e8802f08c5 2b58cf15aaf7
comparison
equal deleted inserted replaced
-1:000000000000 0:6b1b602514db
1 /***
2 * libpst.h
3 * Part of LibPST project
4 * Written by David Smith
5 * dave.s@earthcorp.com
6 */
7 // LibPST - Library for Accessing Outlook .pst files
8 // Dave Smith - davesmith@users.sourceforge.net
9
10 #ifndef LIBPST_H
11 #define LIBPST_H
12
13 #ifndef _MSC_VER
14
15 #ifndef FILETIME_DEFINED
16 #define FILETIME_DEFINED
17 //Win32 Filetime struct - copied from WINE
18 typedef struct {
19 u_int32_t dwLowDateTime;
20 u_int32_t dwHighDateTime;
21 } FILETIME;
22 #endif //ifndef FILETIME_DEFINED
23 #endif //ifndef _MSC_VER
24
25 // define the INT32_MAX here cause it isn't normally defined
26 #ifndef INT32_MAX
27 # define INT32_MAX INT_MAX
28 #endif
29
30 // According to Jan Wolter, sys/param.h is the most portable source of endian
31 // information on UNIX systems. see http://www.unixpapa.com/incnote/byteorder.html
32 #include <sys/param.h>
33
34 #if BYTE_ORDER == BIG_ENDIAN
35 # define LE64_CPU(x) \
36 x = ((((x) & 0xff00000000000000) >> 56) | \
37 (((x) & 0x00ff000000000000) >> 40) | \
38 (((x) & 0x0000ff0000000000) >> 24) | \
39 (((x) & 0x000000ff00000000) >> 8 ) | \
40 (((x) & 0x00000000ff000000) << 8 ) | \
41 (((x) & 0x0000000000ff0000) << 24) | \
42 (((x) & 0x000000000000ff00) << 40) | \
43 (((x) & 0x00000000000000ff) << 56));
44 # define LE32_CPU(x) \
45 x = ((((x) & 0xff000000) >> 24) | \
46 (((x) & 0x00ff0000) >> 8 ) | \
47 (((x) & 0x0000ff00) << 8 ) | \
48 (((x) & 0x000000ff) << 24));
49 # define LE16_CPU(x) \
50 x = ((((x) & 0xff00) >> 8) | \
51 (((x) & 0x00ff) << 8));
52 #elif BYTE_ORDER == LITTLE_ENDIAN
53 # define LE64_CPU(x) {}
54 # define LE32_CPU(x) {}
55 # define LE16_CPU(x) {}
56 #else
57 # error "Byte order not supported by this library"
58 #endif // BYTE_ORDER
59
60
61 #ifdef _MSC_VER
62 #include "windows.h"
63 #define int32_t int
64 #define u_int32_t unsigned int
65 #define int16_t short int
66 #define u_int16_t unsigned short int
67 #endif // _MSC_VER
68
69
70 #define PST_VERSION "0.5"
71
72 #define PST_TYPE_NOTE 1
73 #define PST_TYPE_APPOINTMENT 8
74 #define PST_TYPE_CONTACT 9
75 #define PST_TYPE_JOURNAL 10
76 #define PST_TYPE_STICKYNOTE 11
77 #define PST_TYPE_TASK 12
78 #define PST_TYPE_OTHER 13
79 #define PST_TYPE_REPORT 14
80
81 // defines whether decryption is done on this bit of data
82 #define PST_NO_ENC 0
83 #define PST_ENC 1
84
85 // defines types of possible encryption
86 #define PST_NO_ENCRYPT 0
87 #define PST_COMP_ENCRYPT 1
88 #define PST_ENCRYPT 2
89
90 // defines different types of mappings
91 #define PST_MAP_ATTRIB 1
92 #define PST_MAP_HEADER 2
93
94 // define my custom email attributes.
95 #define PST_ATTRIB_HEADER -1
96
97 // defines types of free/busy values for appointment->showas
98 #define PST_FREEBUSY_FREE 0
99 #define PST_FREEBUSY_TENTATIVE 1
100 #define PST_FREEBUSY_BUSY 2
101 #define PST_FREEBUSY_OUT_OF_OFFICE 3
102
103 // defines labels for appointment->label
104 #define PST_APP_LABEL_NONE 0 // None
105 #define PST_APP_LABEL_IMPORTANT 1 // Important
106 #define PST_APP_LABEL_BUSINESS 2 // Business
107 #define PST_APP_LABEL_PERSONAL 3 // Personal
108 #define PST_APP_LABEL_VACATION 4 // Vacation
109 #define PST_APP_LABEL_MUST_ATTEND 5 // Must Attend
110 #define PST_APP_LABEL_TRAVEL_REQ 6 // Travel Required
111 #define PST_APP_LABEL_NEEDS_PREP 7 // Needs Preparation
112 #define PST_APP_LABEL_BIRTHDAY 8 // Birthday
113 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary
114 #define PST_APP_LABEL_PHONE_CALL 10// Phone Call
115
116 typedef struct _pst_misc_6_struct {
117 int32_t i1;
118 int32_t i2;
119 int32_t i3;
120 int32_t i4;
121 int32_t i5;
122 int32_t i6;
123 } pst_misc_6;
124
125 typedef struct _pst_entryid_struct {
126 int32_t u1;
127 char entryid[16];
128 int32_t id;
129 } pst_entryid;
130
131 typedef struct _pst_desc_struct {
132 u_int32_t d_id;
133 u_int32_t desc_id;
134 u_int32_t list_id;
135 u_int32_t parent_id;
136 } pst_desc;
137
138 typedef struct _pst_index_struct{
139 u_int32_t id;
140 int32_t offset;
141 u_int16_t size;
142 int16_t u1;
143 } pst_index;
144
145 typedef struct _pst_index_tree {
146 u_int32_t id;
147 int32_t offset;
148 size_t size;
149 int32_t u1;
150 struct _pst_index_tree * next;
151 } pst_index_ll;
152
153 typedef struct _pst_index2_tree {
154 int32_t id2;
155 pst_index_ll *id;
156 struct _pst_index2_tree * next;
157 } pst_index2_ll;
158
159 typedef struct _pst_desc_tree {
160 u_int32_t id;
161 pst_index_ll * list_index;
162 pst_index_ll * desc;
163 int32_t no_child;
164 struct _pst_desc_tree * prev;
165 struct _pst_desc_tree * next;
166 struct _pst_desc_tree * parent;
167 struct _pst_desc_tree * child;
168 struct _pst_desc_tree * child_tail;
169 } pst_desc_ll;
170
171 typedef struct _pst_item_email_subject {
172 int32_t off1;
173 int32_t off2;
174 char *subj;
175 } pst_item_email_subject;
176
177 typedef struct _pst_item_email {
178 FILETIME *arrival_date;
179 int32_t autoforward; // 1 = true, 0 = not set, -1 = false
180 char *body;
181 char *cc_address;
182 char *common_name;
183 int32_t conv_index;
184 int32_t conversion_prohib;
185 int32_t delete_after_submit; // 1 = true, 0 = false
186 int32_t delivery_report; // 1 = true, 0 = false
187 char *encrypted_body;
188 int32_t encrypted_body_size;
189 char *encrypted_htmlbody;
190 int32_t encrypted_htmlbody_size;
191 int32_t flag;
192 char *header;
193 char *htmlbody;
194 int32_t importance;
195 char *in_reply_to;
196 int32_t message_cc_me; // 1 = true, 0 = false
197 int32_t message_recip_me; // 1 = true, 0 = false
198 int32_t message_to_me; // 1 = true, 0 = false
199 char *messageid;
200 int32_t orig_sensitivity;
201 char *outlook_recipient;
202 char *outlook_recipient2;
203 char *outlook_sender;
204 char *outlook_sender_name;
205 char *outlook_sender2;
206 int32_t priority;
207 char *proc_subject;
208 int32_t read_receipt;
209 char *recip_access;
210 char *recip_address;
211 char *recip2_access;
212 char *recip2_address;
213 int32_t reply_requested;
214 char *reply_to;
215 char *return_path_address;
216 int32_t rtf_body_char_count;
217 int32_t rtf_body_crc;
218 char *rtf_body_tag;
219 char *rtf_compressed;
220 int32_t rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false
221 int32_t rtf_ws_prefix_count;
222 int32_t rtf_ws_trailing_count;
223 char *sender_access;
224 char *sender_address;
225 char *sender2_access;
226 char *sender2_address;
227 int32_t sensitivity;
228 FILETIME *sent_date;
229 pst_entryid *sentmail_folder;
230 char *sentto_address;
231 pst_item_email_subject *subject;
232 } pst_item_email;
233
234 typedef struct _pst_item_folder {
235 int32_t email_count;
236 int32_t unseen_email_count;
237 int32_t assoc_count;
238 char subfolder;
239 } pst_item_folder;
240
241 typedef struct _pst_item_message_store {
242 pst_entryid *deleted_items_folder;
243 pst_entryid *search_root_folder;
244 pst_entryid *top_of_personal_folder;
245 pst_entryid *top_of_folder;
246 int32_t valid_mask; // what folders the message store contains
247 int32_t pwd_chksum;
248 } pst_item_message_store;
249
250 typedef struct _pst_item_contact {
251 char *access_method;
252 char *account_name;
253 char *address1;
254 char *address1_desc;
255 char *address1_transport;
256 char *address2;
257 char *address2_desc;
258 char *address2_transport;
259 char *address3;
260 char *address3_desc;
261 char *address3_transport;
262 char *assistant_name;
263 char *assistant_phone;
264 char *billing_information;
265 FILETIME *birthday;
266 char *business_address;
267 char *business_city;
268 char *business_country;
269 char *business_fax;
270 char *business_homepage;
271 char *business_phone;
272 char *business_phone2;
273 char *business_po_box;
274 char *business_postal_code;
275 char *business_state;
276 char *business_street;
277 char *callback_phone;
278 char *car_phone;
279 char *company_main_phone;
280 char *company_name;
281 char *computer_name;
282 char *customer_id;
283 char *def_postal_address;
284 char *department;
285 char *display_name_prefix;
286 char *first_name;
287 char *followup;
288 char *free_busy_address;
289 char *ftp_site;
290 char *fullname;
291 int32_t gender;
292 char *gov_id;
293 char *hobbies;
294 char *home_address;
295 char *home_city;
296 char *home_country;
297 char *home_fax;
298 char *home_phone;
299 char *home_phone2;
300 char *home_po_box;
301 char *home_postal_code;
302 char *home_state;
303 char *home_street;
304 char *initials;
305 char *isdn_phone;
306 char *job_title;
307 char *keyword;
308 char *language;
309 char *location;
310 int32_t mail_permission;
311 char *manager_name;
312 char *middle_name;
313 char *mileage;
314 char *mobile_phone;
315 char *nickname;
316 char *office_loc;
317 char *org_id;
318 char *other_address;
319 char *other_city;
320 char *other_country;
321 char *other_phone;
322 char *other_po_box;
323 char *other_postal_code;
324 char *other_state;
325 char *other_street;
326 char *pager_phone;
327 char *personal_homepage;
328 char *pref_name;
329 char *primary_fax;
330 char *primary_phone;
331 char *profession;
332 char *radio_phone;
333 int32_t rich_text;
334 char *spouse_name;
335 char *suffix;
336 char *surname;
337 char *telex;
338 char *transmittable_display_name;
339 char *ttytdd_phone;
340 FILETIME *wedding_anniversary;
341 } pst_item_contact;
342
343 typedef struct _pst_item_attach {
344 char *filename1;
345 char *filename2;
346 char *mimetype;
347 char *data;
348 size_t size;
349 int32_t id2_val;
350 int32_t id_val; // calculated from id2_val during creation of record
351 int32_t method;
352 int32_t position;
353 int32_t sequence;
354 struct _pst_item_attach *next;
355 } pst_item_attach;
356
357 typedef struct _pst_item_extra_field {
358 char *field_name;
359 char *value;
360 struct _pst_item_extra_field *next;
361 } pst_item_extra_field;
362
363 typedef struct _pst_item_journal {
364 FILETIME *end;
365 FILETIME *start;
366 char *type;
367 } pst_item_journal;
368
369 typedef struct _pst_item_appointment {
370 FILETIME *end;
371 char *location;
372 FILETIME *reminder;
373 FILETIME *start;
374 char *timezonestring;
375 int32_t showas;
376 int32_t label;
377 } pst_item_appointment;
378
379 typedef struct _pst_item {
380 struct _pst_item_email *email; // data reffering to email
381 struct _pst_item_folder *folder; // data reffering to folder
382 struct _pst_item_contact *contact; // data reffering to contact
383 struct _pst_item_attach *attach; // linked list of attachments
384 struct _pst_item_attach *current_attach; // pointer to current attachment
385 struct _pst_item_message_store * message_store; // data referring to the message store
386 struct _pst_item_extra_field *extra_fields; // linked list of extra headers and such
387 struct _pst_item_journal *journal; // data reffering to a journal entry
388 struct _pst_item_appointment *appointment; // data reffering to a calendar entry
389 int32_t type;
390 char *ascii_type;
391 char *file_as;
392 char *comment;
393 int32_t message_size;
394 char *outlook_version;
395 char *record_key; // probably 16 bytes long.
396 size_t record_key_size;
397 int32_t response_requested;
398 FILETIME *create_date;
399 FILETIME *modify_date;
400 int32_t private;
401 } pst_item;
402
403 typedef struct _pst_x_attrib_ll {
404 int32_t type;
405 int32_t mytype;
406 int32_t map;
407 void *data;
408 struct _pst_x_attrib_ll *next;
409 } pst_x_attrib_ll;
410
411 typedef struct _pst_file {
412 pst_index_ll *i_head, *i_tail;
413 pst_index2_ll *i2_head;
414 pst_desc_ll *d_head, *d_tail;
415 pst_x_attrib_ll *x_head;
416 int32_t index1;
417 int32_t index1_count;
418 int32_t index2;
419 int32_t index2_count;
420 FILE * fp;
421 size_t size;
422 unsigned char index1_depth;
423 unsigned char index2_depth;
424 unsigned char encryption;
425 unsigned char id_depth_ok;
426 unsigned char desc_depth_ok;
427 unsigned char ind_type;
428 } pst_file;
429
430 typedef struct _pst_block_offset {
431 int16_t from;
432 int16_t to;
433 } pst_block_offset;
434
435 struct _pst_num_item {
436 int32_t id;
437 unsigned char *data;
438 int32_t type;
439 size_t size;
440 char *extra;
441 };
442
443 typedef struct _pst_num_array {
444 int32_t count_item;
445 int32_t count_array;
446 struct _pst_num_item ** items;
447 struct _pst_num_array *next;
448 } pst_num_array;
449
450 struct holder {
451 unsigned char **buf;
452 FILE * fp;
453 int32_t base64;
454 char base64_extra_chars[3];
455 int32_t base64_extra;
456 };
457
458 // prototypes
459 int32_t pst_open(pst_file *pf, char *name, char *mode);
460 int32_t pst_close(pst_file *pf);
461 pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root);
462 int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b);
463 int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
464 int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
465 int32_t pst_load_index (pst_file *pf);
466 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d);
467 int32_t pst_load_extended_attributes(pst_file *pf);
468
469 int32_t _pst_build_id_ptr(pst_file *pf, int32_t offset, int32_t depth, int32_t start_val, int32_t end_val);
470 int32_t _pst_build_desc_ptr (pst_file *pf, int32_t offset, int32_t depth, int32_t *high_id,
471 int32_t start_id, int32_t end_val);
472 pst_item* _pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
473 void * _pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
474 pst_num_array * _pst_parse_block(pst_file *pf, u_int32_t block_id, pst_index2_ll *i2_head);
475 int32_t _pst_process(pst_num_array *list, pst_item *item);
476 int32_t _pst_free_list(pst_num_array *list);
477 void _pst_freeItem(pst_item *item);
478 int32_t _pst_free_id2(pst_index2_ll * head);
479 int32_t _pst_free_id (pst_index_ll *head);
480 int32_t _pst_free_desc (pst_desc_ll *head);
481 int32_t _pst_free_xattrib(pst_x_attrib_ll *x);
482 int32_t _pst_getBlockOffset(char *buf, int32_t i_offset, int32_t offset, pst_block_offset *p);
483 pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
484 pst_index_ll * _pst_getID(pst_file* pf, u_int32_t id);
485 pst_index_ll * _pst_getID2(pst_index2_ll * ptr, u_int32_t id);
486 pst_desc_ll * _pst_getDptr(pst_file *pf, u_int32_t id);
487 size_t _pst_read_block_size(pst_file *pf, int32_t offset, size_t size, char ** buf, int32_t do_enc,
488 unsigned char is_index);
489 int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type);
490 int32_t _pst_getAtPos(FILE *fp, int32_t pos, void* buf, u_int32_t size);
491 int32_t _pst_get (FILE *fp, void *buf, u_int32_t size);
492 size_t _pst_ff_getIDblock_dec(pst_file *pf, u_int32_t id, unsigned char **b);
493 size_t _pst_ff_getIDblock(pst_file *pf, u_int32_t id, unsigned char** b);
494 size_t _pst_ff_getID2block(pst_file *pf, u_int32_t id2, pst_index2_ll *id2_head, unsigned char** buf);
495 size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h);
496 size_t _pst_ff_compile_ID(pst_file *pf, u_int32_t id, struct holder *h, int32_t size);
497
498 int32_t pst_strincmp(char *a, char *b, int32_t x);
499 int32_t pst_stricmp(char *a, char *b);
500 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
501 char * _pst_wide_to_single(char *wt, int32_t size);
502 // DEBUG functions
503 int32_t _pst_printDptr(pst_file *pf);
504 int32_t _pst_printIDptr(pst_file* pf);
505 int32_t _pst_printID2ptr(pst_index2_ll *ptr);
506 void * xmalloc(size_t size);
507 #endif