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     uint64_t parent_id;
00192     pst_index_ll * list_index;
00193     pst_index_ll * desc;
00194     int32_t no_child;
00195     struct pst_desc_tree * prev;
00196     struct pst_desc_tree * next;
00197     struct pst_desc_tree * parent;
00198     struct pst_desc_tree * child;
00199     struct pst_desc_tree * child_tail;
00200 } pst_desc_ll;
00201 
00202 
00203 typedef struct pst_item_email_subject {
00204     int     off1;
00205     int     off2;
00206     char   *subj;
00207 } pst_item_email_subject;
00208 
00209 
00210 typedef struct pst_item_email {
00211     FILETIME *arrival_date;
00212     int       autoforward;            // 1 = true, 0 = not set, -1 = false
00213     char     *body;
00214     char     *cc_address;
00215     char     *bcc_address;
00216     char     *common_name;
00217     int32_t   conv_index;
00218     int       conversion_prohib;      // 1 = true, 0 = false
00219     int       delete_after_submit;    // 1 = true, 0 = false
00220     int       delivery_report;        // 1 = true, 0 = false
00221     char     *encrypted_body;
00222     size_t    encrypted_body_size;
00223     char     *encrypted_htmlbody;
00224     size_t    encrypted_htmlbody_size;
00225     int32_t   flag;
00226     char     *header;
00227     char     *htmlbody;
00228     int32_t   importance;
00229     char     *in_reply_to;
00230     int       message_cc_me;          // 1 = true, 0 = false
00231     int       message_recip_me;       // 1 = true, 0 = false
00232     int       message_to_me;          // 1 = true, 0 = false
00233     char     *messageid;
00234     int32_t   orig_sensitivity;
00235     char     *original_bcc;
00236     char     *original_cc;
00237     char     *original_to;
00238     char     *outlook_recipient;
00239     char     *outlook_recipient_name;
00240     char     *outlook_recipient2;
00241     char     *outlook_sender;
00242     char     *outlook_sender_name;
00243     char     *outlook_sender2;
00244     int32_t   priority;
00245     char     *proc_subject;
00246     int       read_receipt;           // 1 = true, 0 = false
00247     char     *recip_access;
00248     char     *recip_address;
00249     char     *recip2_access;
00250     char     *recip2_address;
00251     int       reply_requested;        // 1 = true, 0 = false
00252     char     *reply_to;
00253     char     *return_path_address;
00254     int32_t   rtf_body_char_count;
00255     int32_t   rtf_body_crc;
00256     char     *rtf_body_tag;
00257     char     *rtf_compressed;
00258     uint32_t  rtf_compressed_size;
00259     int       rtf_in_sync;            // 1 = true, 0 = doesn't exist, -1 = false
00260     int32_t   rtf_ws_prefix_count;
00261     int32_t   rtf_ws_trailing_count;
00262     char     *sender_access;
00263     char     *sender_address;
00264     char     *sender2_access;
00265     char     *sender2_address;
00266     int32_t   sensitivity;
00267     FILETIME *sent_date;
00268     pst_entryid *sentmail_folder;
00269     char        *sentto_address;
00270     pst_item_email_subject *subject;
00271 } pst_item_email;
00272 
00273 
00274 typedef struct pst_item_folder {
00275     int32_t  email_count;
00276     int32_t  unseen_email_count;
00277     int32_t  assoc_count;
00278     int      subfolder;               // 1 = true, 0 = false
00279 } pst_item_folder;
00280 
00281 
00282 typedef struct pst_item_message_store {
00283     pst_entryid *top_of_personal_folder;        // 0x35e0
00284     pst_entryid *default_outbox_folder;         // 0x35e2
00285     pst_entryid *deleted_items_folder;          // 0x35e3
00286     pst_entryid *sent_items_folder;             // 0x35e4
00287     pst_entryid *user_views_folder;             // 0x35e5
00288     pst_entryid *common_view_folder;            // 0x35e6
00289     pst_entryid *search_root_folder;            // 0x35e7
00290     pst_entryid *top_of_folder;                 // 0x7c07
00291     int32_t valid_mask;                         // 0x35df  // what folders the message store contains
00292     int32_t pwd_chksum;                         // 0x76ff
00293 } pst_item_message_store;
00294 
00295 
00296 typedef struct pst_item_contact {
00297     char *access_method;
00298     char *account_name;
00299     char *address1;
00300     char *address1a;
00301     char *address1_desc;
00302     char *address1_transport;
00303     char *address2;
00304     char *address2a;
00305     char *address2_desc;
00306     char *address2_transport;
00307     char *address3;
00308     char *address3a;
00309     char *address3_desc;
00310     char *address3_transport;
00311     char *assistant_name;
00312     char *assistant_phone;
00313     char *billing_information;
00314     FILETIME *birthday;
00315     char *business_address;             // 0x801b
00316     char *business_city;
00317     char *business_country;
00318     char *business_fax;
00319     char *business_homepage;
00320     char *business_phone;
00321     char *business_phone2;
00322     char *business_po_box;
00323     char *business_postal_code;
00324     char *business_state;
00325     char *business_street;
00326     char *callback_phone;
00327     char *car_phone;
00328     char *company_main_phone;
00329     char *company_name;
00330     char *computer_name;
00331     char *customer_id;
00332     char *def_postal_address;
00333     char *department;
00334     char *display_name_prefix;
00335     char *first_name;
00336     char *followup;
00337     char *free_busy_address;
00338     char *ftp_site;
00339     char *fullname;
00340     int16_t  gender;
00341     char *gov_id;
00342     char *hobbies;
00343     char *home_address;                 // 0x801a
00344     char *home_city;
00345     char *home_country;
00346     char *home_fax;
00347     char *home_phone;
00348     char *home_phone2;
00349     char *home_po_box;
00350     char *home_postal_code;
00351     char *home_state;
00352     char *home_street;
00353     char *initials;
00354     char *isdn_phone;
00355     char *job_title;
00356     char *keyword;
00357     char *language;
00358     char *location;
00359     int   mail_permission;              // 1 = true, 0 = false
00360     char *manager_name;
00361     char *middle_name;
00362     char *mileage;
00363     char *mobile_phone;
00364     char *nickname;
00365     char *office_loc;
00366     char *org_id;
00367     char *other_address;                // 0x801c
00368     char *other_city;
00369     char *other_country;
00370     char *other_phone;
00371     char *other_po_box;
00372     char *other_postal_code;
00373     char *other_state;
00374     char *other_street;
00375     char *pager_phone;
00376     char *personal_homepage;
00377     char *pref_name;
00378     char *primary_fax;
00379     char *primary_phone;
00380     char *profession;
00381     char *radio_phone;
00382     int   rich_text;                    // 1 = true, 0 = false
00383     char *spouse_name;
00384     char *suffix;
00385     char *surname;
00386     char *telex;
00387     char *transmittable_display_name;
00388     char *ttytdd_phone;
00389     FILETIME *wedding_anniversary;
00390     char *work_address_street;          // 0x8045
00391     char *work_address_city;            // 0x8046
00392     char *work_address_state;           // 0x8047
00393     char *work_address_postalcode;      // 0x8048
00394     char *work_address_country;         // 0x8049
00395     char *work_address_postofficebox;   // 0x804a
00396 } pst_item_contact;
00397 
00398 
00399 typedef struct pst_item_attach {
00400     char *filename1;
00401     char *filename2;
00402     char *mimetype;
00403     char *data;
00404     size_t   size;
00405     uint64_t id2_val;
00406     uint64_t id_val; // calculated from id2_val during creation of record
00407     int32_t  method;
00408     int32_t  position;
00409     int32_t  sequence;
00410     struct pst_item_attach *next;
00411 } pst_item_attach;
00412 
00413 
00414 typedef struct pst_item_extra_field {
00415     char *field_name;
00416     char *value;
00417     struct pst_item_extra_field *next;
00418 } pst_item_extra_field;
00419 
00420 
00421 typedef struct pst_item_journal {
00422     FILETIME *end;
00423     FILETIME *start;
00424     char *type;
00425 } pst_item_journal;
00426 
00427 
00428 typedef struct pst_item_appointment {
00429     FILETIME *end;
00430     char     *location;
00431     int       alarm;                // 1 = true, 0 = false
00432     FILETIME *reminder;
00433     int32_t   alarm_minutes;
00434     char     *alarm_filename;
00435     FILETIME *start;
00436     char     *timezonestring;
00437     int32_t   showas;
00438     int32_t   label;
00439     int       all_day;              // 1 = true, 0 = false
00440     char     *recurrence;
00441     int32_t   recurrence_type;
00442     FILETIME *recurrence_start;
00443     FILETIME *recurrence_end;
00444 } pst_item_appointment;
00445 
00446 
00447 typedef struct pst_item {
00448     struct pst_item_email         *email;           // data reffering to email
00449     struct pst_item_folder        *folder;          // data reffering to folder
00450     struct pst_item_contact       *contact;         // data reffering to contact
00451     struct pst_item_attach        *attach;          // linked list of attachments
00452     struct pst_item_message_store *message_store;   // data referring to the message store
00453     struct pst_item_extra_field   *extra_fields;    // linked list of extra headers and such
00454     struct pst_item_journal       *journal;         // data reffering to a journal entry
00455     struct pst_item_appointment   *appointment;     // data reffering to a calendar entry
00456     int       type;
00457     char     *ascii_type;
00458     char     *file_as;
00459     char     *comment;
00460     int32_t   message_size;
00461     char     *outlook_version;
00462     char     *record_key; // probably 16 bytes long.
00463     size_t    record_key_size;
00464     int       response_requested;     // 1 = true, 0 = false
00465     FILETIME *create_date;
00466     FILETIME *modify_date;
00467     int       private_member;         // 1 = true, 0 = false
00468 } pst_item;
00469 
00470 
00471 typedef struct pst_x_attrib_ll {
00472     uint32_t type;
00473     uint32_t mytype;
00474     uint32_t map;
00475     void *data;
00476     struct pst_x_attrib_ll *next;
00477 } pst_x_attrib_ll;
00478 
00479 
00480 typedef struct pst_block_recorder {
00481     struct pst_block_recorder  *next;
00482     off_t                       offset;
00483     size_t                      size;
00484     int                         readcount;
00485 } pst_block_recorder;
00486 
00487 
00488 typedef struct pst_file {
00489     pst_index_ll *i_head, *i_tail;
00490     pst_desc_ll  *d_head, *d_tail;
00491     pst_x_attrib_ll *x_head;
00492     pst_block_recorder *block_head;
00493 
00494     //set this to 0 to read 32-bit pst files (pre Outlook 2003)
00495     //set this to 1 to read 64-bit pst files (Outlook 2003 and later)
00496     int do_read64;
00497 
00498     uint64_t index1;
00499     uint64_t index1_back;
00500     uint64_t index2;
00501     uint64_t index2_back;
00502     FILE * fp;                // file pointer to opened PST file
00503     uint64_t size;            // pst file size
00504     unsigned char encryption; // pst encryption setting
00505     unsigned char ind_type;   // pst index type
00506 } pst_file;
00507 
00508 
00509 typedef struct pst_block_offset {
00510     int16_t from;
00511     int16_t to;
00512 } pst_block_offset;
00513 
00514 
00515 typedef struct pst_block_offset_pointer {
00516     char *from;
00517     char *to;
00518     int   needfree;
00519 } pst_block_offset_pointer;
00520 
00521 
00522 typedef struct pst_num_item {
00523     uint32_t   id;      // not an id1 or id2, this is actually some sort of type code
00524     char      *data;
00525     uint32_t   type;
00526     size_t     size;
00527     char      *extra;
00528 } pst_num_item;
00529 
00530 
00531 typedef struct pst_num_array {
00532     int32_t count_item;
00533     int32_t orig_count;
00534     int32_t count_array;
00535     struct pst_num_item ** items;
00536     struct pst_num_array *next;
00537 } pst_num_array;
00538 
00539 
00540 typedef struct pst_holder {
00541     char  **buf;
00542     FILE   *fp;
00543     int     base64;
00544 } pst_holder;
00545 
00546 
00547 typedef struct pst_subblock {
00548     char    *buf;
00549     size_t   read_size;
00550     size_t   i_offset;
00551 } pst_subblock;
00552 
00553 
00554 typedef struct pst_subblocks {
00555     size_t          subblock_count;
00556     pst_subblock   *subs;
00557 } pst_subblocks;
00558 
00559 
00560 // prototypes
00561 int            pst_open(pst_file *pf, char *name);
00562 int            pst_close(pst_file *pf);
00563 pst_desc_ll *  pst_getTopOfFolders(pst_file *pf, pst_item *root);
00564 size_t         pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b);
00565 size_t         pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
00566 size_t         pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
00567 int            pst_load_index (pst_file *pf);
00568 pst_desc_ll*   pst_getNextDptr(pst_desc_ll* d);
00569 int            pst_load_extended_attributes(pst_file *pf);
00570 
00571 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);
00572 int            pst_build_desc_ptr(pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
00573 pst_item*      pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
00574 pst_item*      pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
00575 pst_num_array* pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head, pst_num_array *na_head);
00576 int            pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach);
00577 void           pst_free_list(pst_num_array *list);
00578 void           pst_freeItem(pst_item *item);
00579 void           pst_free_id2(pst_index2_ll * head);
00580 void           pst_free_id (pst_index_ll *head);
00581 void           pst_free_desc (pst_desc_ll *head);
00582 void           pst_free_xattrib(pst_x_attrib_ll *x);
00583 int            pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p);
00584 int            pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p);
00585 pst_index2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
00586 pst_index_ll*  pst_getID(pst_file* pf, uint64_t id);
00587 pst_index_ll*  pst_getID2(pst_index2_ll * ptr, uint64_t id);
00588 pst_desc_ll*   pst_getDptr(pst_file *pf, uint64_t id);
00589 size_t         pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf);
00590 int            pst_decrypt(uint64_t id, char *buf, size_t size, unsigned char type);
00591 uint64_t       pst_getIntAt(pst_file *pf, char *buf);
00592 uint64_t       pst_getIntAtPos(pst_file *pf, off_t pos);
00593 size_t         pst_getAtPos(pst_file *pf, off_t pos, void* buf, size_t size);
00594 size_t         pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **b);
00595 size_t         pst_ff_getIDblock(pst_file *pf, uint64_t id, char** b);
00596 size_t         pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf);
00597 size_t         pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h);
00598 size_t         pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size);
00599 
00600 int            pst_strincmp(char *a, char *b, size_t x);
00601 int            pst_stricmp(char *a, char *b);
00602 size_t         pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
00603 char *         pst_wide_to_single(char *wt, size_t size);
00604 
00605 char *         pst_rfc2426_escape(char *str);
00606 int            pst_chr_count(char *str, char x);
00607 char *         pst_rfc2425_datetime_format(FILETIME *ft);
00608 char *         pst_rfc2445_datetime_format(FILETIME *ft);
00609 
00610 void           pst_printDptr(pst_file *pf, pst_desc_ll *ptr);
00611 void           pst_printIDptr(pst_file* pf);
00612 void           pst_printID2ptr(pst_index2_ll *ptr);
00613 
00614 #endif // defined LIBPST_H

Generated on Thu Dec 11 11:58:49 2008 for 'LibPst' by  doxygen 1.3.9.1