Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

libpst.h

Go to the documentation of this file.
00001 /***
00002  * libpst.h
00003  * Part of LibPST project
00004  * Written by David Smith
00005  *            dave.s@earthcorp.com
00006  */
00007 // LibPST - Library for Accessing Outlook .pst files
00008 // Dave Smith - davesmith@users.sourceforge.net
00009 
00010 #ifndef LIBPST_H
00011 #define LIBPST_H
00012 
00013 #ifndef  _MSC_VER
00014     #include <stdint.h>
00015     #include <inttypes.h>
00016     #ifndef FILETIME_DEFINED
00017         #define FILETIME_DEFINED
00018         //Win32 Filetime struct - copied from WINE
00019         typedef struct {
00020           uint32_t dwLowDateTime;
00021           uint32_t dwHighDateTime;
00022         } FILETIME;
00023     #endif
00024 #endif
00025 
00026 // According to Jan Wolter, sys/param.h is the most portable source of endian
00027 // information on UNIX systems. see http://www.unixpapa.com/incnote/byteorder.html
00028 #ifdef _MSC_VER
00029   #define BYTE_ORDER LITTLE_ENDIAN
00030 #else
00031   #include <sys/param.h>
00032 #endif // defined _MSC_VER
00033 
00034 #if BYTE_ORDER == BIG_ENDIAN
00035 #  define LE64_CPU(x) \
00036   x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00037        (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00038        (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00039        (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00040        (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00041        (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00042        (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00043        (((x) & UINT64_C(0x00000000000000ff)) << 56));
00044 #  define LE32_CPU(x) \
00045   x = ((((x) & 0xff000000) >> 24) | \
00046        (((x) & 0x00ff0000) >> 8 ) | \
00047        (((x) & 0x0000ff00) << 8 ) | \
00048        (((x) & 0x000000ff) << 24));
00049 #  define LE16_CPU(x) \
00050   x = ((((x) & 0xff00) >> 8) | \
00051        (((x) & 0x00ff) << 8));
00052 #elif BYTE_ORDER == LITTLE_ENDIAN
00053 #  define LE64_CPU(x) {}
00054 #  define LE32_CPU(x) {}
00055 #  define LE16_CPU(x) {}
00056 #else
00057 #  error "Byte order not supported by this library"
00058 #endif // BYTE_ORDER
00059 
00060 
00061 #define PST_TYPE_NOTE        1
00062 #define PST_TYPE_APPOINTMENT 8
00063 #define PST_TYPE_CONTACT     9
00064 #define PST_TYPE_JOURNAL    10
00065 #define PST_TYPE_STICKYNOTE 11
00066 #define PST_TYPE_TASK       12
00067 #define PST_TYPE_OTHER      13
00068 #define PST_TYPE_REPORT     14
00069 
00070 // defines whether decryption is done on this bit of data
00071 #define PST_NO_ENC 0
00072 #define PST_ENC    1
00073 
00074 // defines types of possible encryption
00075 #define PST_NO_ENCRYPT   0
00076 #define PST_COMP_ENCRYPT 1
00077 #define PST_ENCRYPT      2
00078 
00079 // defines different types of mappings
00080 #define PST_MAP_ATTRIB (uint32_t)1
00081 #define PST_MAP_HEADER (uint32_t)2
00082 
00083 // define my custom email attributes.
00084 #define PST_ATTRIB_HEADER -1
00085 
00086 // defines types of free/busy values for appointment->showas
00087 #define PST_FREEBUSY_FREE 0
00088 #define PST_FREEBUSY_TENTATIVE 1
00089 #define PST_FREEBUSY_BUSY 2
00090 #define PST_FREEBUSY_OUT_OF_OFFICE 3
00091 
00092 // defines labels for appointment->label
00093 #define PST_APP_LABEL_NONE        0 // None
00094 #define PST_APP_LABEL_IMPORTANT   1 // Important
00095 #define PST_APP_LABEL_BUSINESS    2 // Business
00096 #define PST_APP_LABEL_PERSONAL    3 // Personal
00097 #define PST_APP_LABEL_VACATION    4 // Vacation
00098 #define PST_APP_LABEL_MUST_ATTEND 5 // Must Attend
00099 #define PST_APP_LABEL_TRAVEL_REQ  6 // Travel Required
00100 #define PST_APP_LABEL_NEEDS_PREP  7 // Needs Preparation
00101 #define PST_APP_LABEL_BIRTHDAY    8 // Birthday
00102 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary
00103 #define PST_APP_LABEL_PHONE_CALL  10// Phone Call
00104 
00105 // define type of reccuring event
00106 #define PST_APP_RECUR_NONE        0
00107 #define PST_APP_RECUR_DAILY       1
00108 #define PST_APP_RECUR_WEEKLY      2
00109 #define PST_APP_RECUR_MONTHLY     3
00110 #define PST_APP_RECUR_YEARLY      4
00111 
00112 
00113 typedef struct pst_misc_6_struct {
00114     int32_t i1;
00115     int32_t i2;
00116     int32_t i3;
00117     int32_t i4;
00118     int32_t i5;
00119     int32_t i6;
00120 } pst_misc_6;
00121 
00122 
00123 typedef struct pst_entryid_struct {
00124     int32_t u1;
00125     char entryid[16];
00126     uint32_t id;
00127 } pst_entryid;
00128 
00129 
00130 typedef struct pst_desc_struct32 {
00131     uint32_t d_id;
00132     uint32_t desc_id;
00133     uint32_t list_id;
00134     uint32_t parent_id;
00135 } pst_desc32;
00136 
00137 
00138 typedef struct pst_desc_structn {
00139     uint64_t d_id;
00140     uint64_t desc_id;
00141     uint64_t list_id;
00142     uint32_t parent_id;  // not 64 bit ??
00143     uint32_t u1;         // padding
00144 } pst_descn;
00145 
00146 
00147 typedef struct pst_index_struct32 {
00148     uint32_t id;
00149     uint32_t offset;
00150     uint16_t size;
00151     int16_t  u1;
00152 } pst_index32;
00153 
00154 
00155 typedef struct pst_index_struct {
00156     uint64_t id;
00157     uint64_t offset;
00158     uint16_t size;
00159     int16_t  u0;
00160     int32_t  u1;
00161 } pst_index;
00162 
00163 
00164 typedef struct pst_index_tree32 {
00165     uint32_t id;
00166     uint32_t offset;
00167     uint32_t size;
00168     int32_t  u1;
00169     struct pst_index_tree * next;
00170 } pst_index_ll32;
00171 
00172 
00173 typedef struct pst_index_tree {
00174     uint64_t id;
00175     uint64_t offset;
00176     uint64_t size;
00177     int64_t  u1;
00178     struct pst_index_tree * next;
00179 } pst_index_ll;
00180 
00181 
00182 typedef struct pst_index2_tree {
00183     uint64_t id2;
00184     pst_index_ll *id;
00185     struct pst_index2_tree * next;
00186 } pst_index2_ll;
00187 
00188 
00189 typedef struct pst_desc_tree {
00190     uint64_t id;
00191     pst_index_ll * list_index;
00192     pst_index_ll * desc;
00193     int32_t no_child;
00194     struct pst_desc_tree * prev;
00195     struct pst_desc_tree * next;
00196     struct pst_desc_tree * parent;
00197     struct pst_desc_tree * child;
00198     struct pst_desc_tree * child_tail;
00199 } pst_desc_ll;
00200 
00201 
00202 typedef struct pst_item_email_subject {
00203     int     off1;
00204     int     off2;
00205     char   *subj;
00206 } pst_item_email_subject;
00207 
00208 
00209 typedef struct pst_item_email {
00210     FILETIME *arrival_date;
00211     int       autoforward;            // 1 = true, 0 = not set, -1 = false
00212     char     *body;
00213     char     *cc_address;
00214     char     *bcc_address;
00215     char     *common_name;
00216     int32_t   conv_index;
00217     int       conversion_prohib;      // 1 = true, 0 = false
00218     int       delete_after_submit;    // 1 = true, 0 = false
00219     int       delivery_report;        // 1 = true, 0 = false
00220     char     *encrypted_body;
00221     size_t    encrypted_body_size;
00222     char     *encrypted_htmlbody;
00223     size_t    encrypted_htmlbody_size;
00224     int32_t   flag;
00225     char     *header;
00226     char     *htmlbody;
00227     int32_t   importance;
00228     char     *in_reply_to;
00229     int       message_cc_me;          // 1 = true, 0 = false
00230     int       message_recip_me;       // 1 = true, 0 = false
00231     int       message_to_me;          // 1 = true, 0 = false
00232     char     *messageid;
00233     int32_t   orig_sensitivity;
00234     char     *original_bcc;
00235     char     *original_cc;
00236     char     *original_to;
00237     char     *outlook_recipient;
00238     char     *outlook_recipient_name;
00239     char     *outlook_recipient2;
00240     char     *outlook_sender;
00241     char     *outlook_sender_name;
00242     char     *outlook_sender2;
00243     int32_t   priority;
00244     char     *proc_subject;
00245     int       read_receipt;           // 1 = true, 0 = false
00246     char     *recip_access;
00247     char     *recip_address;
00248     char     *recip2_access;
00249     char     *recip2_address;
00250     int       reply_requested;        // 1 = true, 0 = false
00251     char     *reply_to;
00252     char     *return_path_address;
00253     int32_t   rtf_body_char_count;
00254     int32_t   rtf_body_crc;
00255     char     *rtf_body_tag;
00256     char     *rtf_compressed;
00257     uint32_t  rtf_compressed_size;
00258     int       rtf_in_sync;            // 1 = true, 0 = doesn't exist, -1 = false
00259     int32_t   rtf_ws_prefix_count;
00260     int32_t   rtf_ws_trailing_count;
00261     char     *sender_access;
00262     char     *sender_address;
00263     char     *sender2_access;
00264     char     *sender2_address;
00265     int32_t   sensitivity;
00266     FILETIME *sent_date;
00267     pst_entryid *sentmail_folder;
00268     char        *sentto_address;
00269     pst_item_email_subject *subject;
00270 } pst_item_email;
00271 
00272 
00273 typedef struct pst_item_folder {
00274     int32_t  email_count;
00275     int32_t  unseen_email_count;
00276     int32_t  assoc_count;
00277     int      subfolder;               // 1 = true, 0 = false
00278 } pst_item_folder;
00279 
00280 
00281 typedef struct pst_item_message_store {
00282     pst_entryid *top_of_personal_folder;        // 0x35e0
00283     pst_entryid *default_outbox_folder;         // 0x35e2
00284     pst_entryid *deleted_items_folder;          // 0x35e3
00285     pst_entryid *sent_items_folder;             // 0x35e4
00286     pst_entryid *user_views_folder;             // 0x35e5
00287     pst_entryid *common_view_folder;            // 0x35e6
00288     pst_entryid *search_root_folder;            // 0x35e7
00289     pst_entryid *top_of_folder;                 // 0x7c07
00290     int32_t valid_mask;                         // 0x35df  // what folders the message store contains
00291     int32_t pwd_chksum;                         // 0x76ff
00292 } pst_item_message_store;
00293 
00294 
00295 typedef struct pst_item_contact {
00296     char *access_method;
00297     char *account_name;
00298     char *address1;
00299     char *address1a;
00300     char *address1_desc;
00301     char *address1_transport;
00302     char *address2;
00303     char *address2a;
00304     char *address2_desc;
00305     char *address2_transport;
00306     char *address3;
00307     char *address3a;
00308     char *address3_desc;
00309     char *address3_transport;
00310     char *assistant_name;
00311     char *assistant_phone;
00312     char *billing_information;
00313     FILETIME *birthday;
00314     char *business_address;             // 0x801b
00315     char *business_city;
00316     char *business_country;
00317     char *business_fax;
00318     char *business_homepage;
00319     char *business_phone;
00320     char *business_phone2;
00321     char *business_po_box;
00322     char *business_postal_code;
00323     char *business_state;
00324     char *business_street;
00325     char *callback_phone;
00326     char *car_phone;
00327     char *company_main_phone;
00328     char *company_name;
00329     char *computer_name;
00330     char *customer_id;
00331     char *def_postal_address;
00332     char *department;
00333     char *display_name_prefix;
00334     char *first_name;
00335     char *followup;
00336     char *free_busy_address;
00337     char *ftp_site;
00338     char *fullname;
00339     int16_t  gender;
00340     char *gov_id;
00341     char *hobbies;
00342     char *home_address;                 // 0x801a
00343     char *home_city;
00344     char *home_country;
00345     char *home_fax;
00346     char *home_phone;
00347     char *home_phone2;
00348     char *home_po_box;
00349     char *home_postal_code;
00350     char *home_state;
00351     char *home_street;
00352     char *initials;
00353     char *isdn_phone;
00354     char *job_title;
00355     char *keyword;
00356     char *language;
00357     char *location;
00358     int   mail_permission;              // 1 = true, 0 = false
00359     char *manager_name;
00360     char *middle_name;
00361     char *mileage;
00362     char *mobile_phone;
00363     char *nickname;
00364     char *office_loc;
00365     char *org_id;
00366     char *other_address;                // 0x801c
00367     char *other_city;
00368     char *other_country;
00369     char *other_phone;
00370     char *other_po_box;
00371     char *other_postal_code;
00372     char *other_state;
00373     char *other_street;
00374     char *pager_phone;
00375     char *personal_homepage;
00376     char *pref_name;
00377     char *primary_fax;
00378     char *primary_phone;
00379     char *profession;
00380     char *radio_phone;
00381     int   rich_text;                    // 1 = true, 0 = false
00382     char *spouse_name;
00383     char *suffix;
00384     char *surname;
00385     char *telex;
00386     char *transmittable_display_name;
00387     char *ttytdd_phone;
00388     FILETIME *wedding_anniversary;
00389     char *work_address_street;          // 0x8045
00390     char *work_address_city;            // 0x8046
00391     char *work_address_state;           // 0x8047
00392     char *work_address_postalcode;      // 0x8048
00393     char *work_address_country;         // 0x8049
00394     char *work_address_postofficebox;   // 0x804a
00395 } pst_item_contact;
00396 
00397 
00398 typedef struct pst_item_attach {
00399     char *filename1;
00400     char *filename2;
00401     char *mimetype;
00402     char *data;
00403     size_t   size;
00404     uint64_t id2_val;
00405     uint64_t id_val; // calculated from id2_val during creation of record
00406     int32_t  method;
00407     int32_t  position;
00408     int32_t  sequence;
00409     struct pst_item_attach *next;
00410 } pst_item_attach;
00411 
00412 
00413 typedef struct pst_item_extra_field {
00414     char *field_name;
00415     char *value;
00416     struct pst_item_extra_field *next;
00417 } pst_item_extra_field;
00418 
00419 
00420 typedef struct pst_item_journal {
00421     FILETIME *end;
00422     FILETIME *start;
00423     char *type;
00424 } pst_item_journal;
00425 
00426 
00427 typedef struct pst_item_appointment {
00428     FILETIME *end;
00429     char     *location;
00430     int       alarm;                // 1 = true, 0 = false
00431     FILETIME *reminder;
00432     int32_t   alarm_minutes;
00433     char     *alarm_filename;
00434     FILETIME *start;
00435     char     *timezonestring;
00436     int32_t   showas;
00437     int32_t   label;
00438     int       all_day;              // 1 = true, 0 = false
00439     char     *recurrence;
00440     int32_t   recurrence_type;
00441     FILETIME *recurrence_start;
00442     FILETIME *recurrence_end;
00443 } pst_item_appointment;
00444 
00445 
00446 typedef struct pst_item {
00447     struct pst_item_email         *email;           // data reffering to email
00448     struct pst_item_folder        *folder;          // data reffering to folder
00449     struct pst_item_contact       *contact;         // data reffering to contact
00450     struct pst_item_attach        *attach;          // linked list of attachments
00451     struct pst_item_message_store *message_store;   // data referring to the message store
00452     struct pst_item_extra_field   *extra_fields;    // linked list of extra headers and such
00453     struct pst_item_journal       *journal;         // data reffering to a journal entry
00454     struct pst_item_appointment   *appointment;     // data reffering to a calendar entry
00455     int       type;
00456     char     *ascii_type;
00457     char     *file_as;
00458     char     *comment;
00459     int32_t   message_size;
00460     char     *outlook_version;
00461     char     *record_key; // probably 16 bytes long.
00462     size_t    record_key_size;
00463     int       response_requested;     // 1 = true, 0 = false
00464     FILETIME *create_date;
00465     FILETIME *modify_date;
00466     int       private_member;         // 1 = true, 0 = false
00467 } pst_item;
00468 
00469 
00470 typedef struct pst_x_attrib_ll {
00471     uint32_t type;
00472     uint32_t mytype;
00473     uint32_t map;
00474     void *data;
00475     struct pst_x_attrib_ll *next;
00476 } pst_x_attrib_ll;
00477 
00478 
00479 typedef struct pst_block_recorder {
00480     struct pst_block_recorder  *next;
00481     off_t                       offset;
00482     size_t                      size;
00483     int                         readcount;
00484 } pst_block_recorder;
00485 
00486 
00487 typedef struct pst_file {
00488     pst_index_ll *i_head, *i_tail;
00489     pst_desc_ll  *d_head, *d_tail;
00490     pst_x_attrib_ll *x_head;
00491     pst_block_recorder *block_head;
00492 
00493     //set this to 0 to read 32-bit pst files (pre Outlook 2003)
00494     //set this to 1 to read 64-bit pst files (Outlook 2003 and later)
00495     int do_read64;
00496 
00497     uint64_t index1;
00498     uint64_t index1_back;
00499     uint64_t index2;
00500     uint64_t index2_back;
00501     FILE * fp;                // file pointer to opened PST file
00502     uint64_t size;            // pst file size
00503     unsigned char encryption; // pst encryption setting
00504     unsigned char ind_type;   // pst index type
00505 } pst_file;
00506 
00507 
00508 typedef struct pst_block_offset {
00509     int16_t from;
00510     int16_t to;
00511 } pst_block_offset;
00512 
00513 
00514 typedef struct pst_block_offset_pointer {
00515     char *from;
00516     char *to;
00517     int   needfree;
00518 } pst_block_offset_pointer;
00519 
00520 
00521 typedef struct pst_num_item {
00522     uint32_t   id;      // not an id1 or id2, this is actually some sort of type code
00523     char      *data;
00524     uint32_t   type;
00525     size_t     size;
00526     char      *extra;
00527 } pst_num_item;
00528 
00529 
00530 typedef struct pst_num_array {
00531     int32_t count_item;
00532     int32_t orig_count;
00533     int32_t count_array;
00534     struct pst_num_item ** items;
00535     struct pst_num_array *next;
00536 } pst_num_array;
00537 
00538 
00539 typedef struct pst_holder {
00540     char **buf;
00541     FILE *    fp;
00542     int       base64;
00543     char      base64_extra_chars[3];
00544     uint32_t  base64_extra;
00545 } pst_holder;
00546 
00547 
00548 typedef struct pst_subblock {
00549     char    *buf;
00550     size_t   read_size;
00551     size_t   i_offset;
00552 } pst_subblock;
00553 
00554 
00555 typedef struct pst_subblocks {
00556     size_t          subblock_count;
00557     pst_subblock   *subs;
00558 } pst_subblocks;
00559 
00560 
00561 // prototypes
00562 int            pst_open(pst_file *pf, char *name);
00563 int            pst_close(pst_file *pf);
00564 pst_desc_ll *  pst_getTopOfFolders(pst_file *pf, pst_item *root);
00565 size_t         pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b);
00566 size_t         pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
00567 size_t         pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
00568 int            pst_load_index (pst_file *pf);
00569 pst_desc_ll*   pst_getNextDptr(pst_desc_ll* d);
00570 int            pst_load_extended_attributes(pst_file *pf);
00571 
00572 int            pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
00573 int            pst_build_desc_ptr(pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val);
00574 pst_item*      pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
00575 pst_item*      pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
00576 pst_num_array* pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head, pst_num_array *na_head);
00577 int            pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach);
00578 void           pst_free_list(pst_num_array *list);
00579 void           pst_freeItem(pst_item *item);
00580 void           pst_free_id2(pst_index2_ll * head);
00581 void           pst_free_id (pst_index_ll *head);
00582 void           pst_free_desc (pst_desc_ll *head);
00583 void           pst_free_xattrib(pst_x_attrib_ll *x);
00584 int            pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p);
00585 int            pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p);
00586 pst_index2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
00587 pst_index_ll*  pst_getID(pst_file* pf, uint64_t id);
00588 pst_index_ll*  pst_getID2(pst_index2_ll * ptr, uint64_t id);
00589 pst_desc_ll*   pst_getDptr(pst_file *pf, uint64_t id);
00590 size_t         pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf);
00591 int            pst_decrypt(uint64_t id, char *buf, size_t size, unsigned char type);
00592 uint64_t       pst_getIntAt(pst_file *pf, char *buf);
00593 uint64_t       pst_getIntAtPos(pst_file *pf, off_t pos);
00594 size_t         pst_getAtPos(pst_file *pf, off_t pos, void* buf, size_t size);
00595 size_t         pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **b);
00596 size_t         pst_ff_getIDblock(pst_file *pf, uint64_t id, char** b);
00597 size_t         pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf);
00598 size_t         pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h);
00599 size_t         pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size);
00600 
00601 int            pst_strincmp(char *a, char *b, size_t x);
00602 int            pst_stricmp(char *a, char *b);
00603 size_t         pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
00604 char *         pst_wide_to_single(char *wt, size_t size);
00605 
00606 char *         pst_rfc2426_escape(char *str);
00607 int            pst_chr_count(char *str, char x);
00608 char *         pst_rfc2425_datetime_format(FILETIME *ft);
00609 char *         pst_rfc2445_datetime_format(FILETIME *ft);
00610 
00611 void           pst_printDptr(pst_file *pf, pst_desc_ll *ptr);
00612 void           pst_printIDptr(pst_file* pf);
00613 void           pst_printID2ptr(pst_index2_ll *ptr);
00614 
00615 #endif // defined LIBPST_H

Generated on Tue Aug 5 12:06:14 2008 for 'LibPst' by  doxygen 1.3.9.1