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

Generated on Thu Feb 26 13:40:07 2009 for 'LibPst' by  doxygen 1.3.9.1