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