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 tree_id;
00099     uint32_t parent_d_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 tree_id;
00107     uint32_t parent_d_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 i_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 i_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_id2_tree {
00148     uint64_t id2;
00149     pst_index_ll *id;
00150     struct pst_id2_tree *child;
00151     struct pst_id2_tree *next;
00152 } pst_id2_ll;
00153 
00154 
00155 typedef struct pst_desc_tree {
00156     uint64_t              d_id;
00157     uint64_t              parent_d_id;
00158     pst_index_ll         *desc;
00159     pst_index_ll         *assoc_tree;
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_string {
00170     int     is_utf8;    // 1 = true, 0 = false
00171     char   *str;        // either utf8 or some sbcs
00172 } pst_string;
00173 
00174 
00175 typedef struct pst_binary {
00176     size_t  size;
00177     char   *data;
00178 } pst_binary;
00179 
00180 
00183 typedef struct pst_item_email {
00184     FILETIME   *arrival_date;
00186     int         autoforward;
00187     pst_string  cc_address;
00188     pst_string  bcc_address;
00189     pst_binary  conversation_index;
00191     int         conversion_prohibited;
00193     int         delete_after_submit;
00195     int         delivery_report;
00196     pst_binary  encrypted_body;
00197     pst_binary  encrypted_htmlbody;
00198     pst_string  header;
00199     pst_string  htmlbody;
00201     int32_t     importance;
00202     pst_string  in_reply_to;
00204     int         message_cc_me;
00206     int         message_recip_me;
00208     int         message_to_me;
00209     pst_string  messageid;
00211     int32_t     original_sensitivity;
00212     pst_string  original_bcc;
00213     pst_string  original_cc;
00214     pst_string  original_to;
00215     pst_string  outlook_recipient;
00216     pst_string  outlook_recipient_name;
00217     pst_string  outlook_recipient2;
00218     pst_string  outlook_sender;
00219     pst_string  outlook_sender_name;
00220     pst_string  outlook_sender2;
00222     int32_t     priority;
00223     pst_string  processed_subject;
00225     int         read_receipt;
00226     pst_string  recip_access;
00227     pst_string  recip_address;
00228     pst_string  recip2_access;
00229     pst_string  recip2_address;
00231     int         reply_requested;
00232     pst_string  reply_to;
00233     pst_string  return_path_address;
00234     int32_t     rtf_body_char_count;
00235     int32_t     rtf_body_crc;
00236     pst_string  rtf_body_tag;
00237     pst_binary  rtf_compressed;
00239     int         rtf_in_sync;
00240     int32_t     rtf_ws_prefix_count;
00241     int32_t     rtf_ws_trailing_count;
00242     pst_string  sender_access;
00243     pst_string  sender_address;
00244     pst_string  sender2_access;
00245     pst_string  sender2_address;
00247     int32_t     sensitivity;
00248     FILETIME    *sent_date;
00249     pst_entryid *sentmail_folder;
00250     pst_string  sentto_address;
00251     // delivery report fields
00252     pst_string  report_text;
00253     FILETIME   *report_time;
00254     int32_t     ndr_reason_code;
00255     int32_t     ndr_diag_code;
00256     pst_string  supplementary_info;
00257     int32_t     ndr_status_code;
00258 } pst_item_email;
00259 
00260 
00261 typedef struct pst_item_folder {
00262     int32_t  item_count;
00263     int32_t  unseen_item_count;
00264     int32_t  assoc_count;
00266     int      subfolder;
00267 } pst_item_folder;
00268 
00269 
00270 typedef struct pst_item_message_store {
00271     pst_entryid *top_of_personal_folder;        // 0x35e0
00272     pst_entryid *default_outbox_folder;         // 0x35e2
00273     pst_entryid *deleted_items_folder;          // 0x35e3
00274     pst_entryid *sent_items_folder;             // 0x35e4
00275     pst_entryid *user_views_folder;             // 0x35e5
00276     pst_entryid *common_view_folder;            // 0x35e6
00277     pst_entryid *search_root_folder;            // 0x35e7
00278     pst_entryid *top_of_folder;                 // 0x7c07
00289     int32_t valid_mask;                         // 0x35df
00290     int32_t pwd_chksum;                         // 0x76ff
00291 } pst_item_message_store;
00292 
00293 
00296 typedef struct pst_item_contact {
00297     pst_string  access_method;
00298     pst_string  account_name;
00299     pst_string  address1;
00300     pst_string  address1a;
00301     pst_string  address1_desc;
00302     pst_string  address1_transport;
00303     pst_string  address2;
00304     pst_string  address2a;
00305     pst_string  address2_desc;
00306     pst_string  address2_transport;
00307     pst_string  address3;
00308     pst_string  address3a;
00309     pst_string  address3_desc;
00310     pst_string  address3_transport;
00311     pst_string  assistant_name;
00312     pst_string  assistant_phone;
00313     pst_string  billing_information;
00314     FILETIME   *birthday;
00315     pst_string  business_address;               // 0x801b
00316     pst_string  business_city;
00317     pst_string  business_country;
00318     pst_string  business_fax;
00319     pst_string  business_homepage;
00320     pst_string  business_phone;
00321     pst_string  business_phone2;
00322     pst_string  business_po_box;
00323     pst_string  business_postal_code;
00324     pst_string  business_state;
00325     pst_string  business_street;
00326     pst_string  callback_phone;
00327     pst_string  car_phone;
00328     pst_string  company_main_phone;
00329     pst_string  company_name;
00330     pst_string  computer_name;
00331     pst_string  customer_id;
00332     pst_string  def_postal_address;
00333     pst_string  department;
00334     pst_string  display_name_prefix;
00335     pst_string  first_name;
00336     pst_string  followup;
00337     pst_string  free_busy_address;
00338     pst_string  ftp_site;
00339     pst_string  fullname;
00341     int16_t     gender;
00342     pst_string  gov_id;
00343     pst_string  hobbies;
00344     pst_string  home_address;                   // 0x801a
00345     pst_string  home_city;
00346     pst_string  home_country;
00347     pst_string  home_fax;
00348     pst_string  home_phone;
00349     pst_string  home_phone2;
00350     pst_string  home_po_box;
00351     pst_string  home_postal_code;
00352     pst_string  home_state;
00353     pst_string  home_street;
00354     pst_string  initials;
00355     pst_string  isdn_phone;
00356     pst_string  job_title;
00357     pst_string  keyword;
00358     pst_string  language;
00359     pst_string  location;
00361     int         mail_permission;
00362     pst_string  manager_name;
00363     pst_string  middle_name;
00364     pst_string  mileage;
00365     pst_string  mobile_phone;
00366     pst_string  nickname;
00367     pst_string  office_loc;
00368     pst_string  common_name;
00369     pst_string  org_id;
00370     pst_string  other_address;                  // 0x801c
00371     pst_string  other_city;
00372     pst_string  other_country;
00373     pst_string  other_phone;
00374     pst_string  other_po_box;
00375     pst_string  other_postal_code;
00376     pst_string  other_state;
00377     pst_string  other_street;
00378     pst_string  pager_phone;
00379     pst_string  personal_homepage;
00380     pst_string  pref_name;
00381     pst_string  primary_fax;
00382     pst_string  primary_phone;
00383     pst_string  profession;
00384     pst_string  radio_phone;
00386     int         rich_text;
00387     pst_string  spouse_name;
00388     pst_string  suffix;
00389     pst_string  surname;
00390     pst_string  telex;
00391     pst_string  transmittable_display_name;
00392     pst_string  ttytdd_phone;
00393     FILETIME   *wedding_anniversary;
00394     pst_string  work_address_street;            // 0x8045
00395     pst_string  work_address_city;              // 0x8046
00396     pst_string  work_address_state;             // 0x8047
00397     pst_string  work_address_postalcode;        // 0x8048
00398     pst_string  work_address_country;           // 0x8049
00399     pst_string  work_address_postofficebox;     // 0x804a
00400 } pst_item_contact;
00401 
00402 
00403 typedef struct pst_item_attach {
00404     pst_string  filename1;
00405     pst_string  filename2;
00406     pst_string  mimetype;
00407     pst_binary  data;
00408     uint64_t    id2_val;
00410     uint64_t    i_id;
00412     pst_id2_ll *id2_head;
00414     int32_t     method;
00415     int32_t     position;
00416     int32_t     sequence;
00417     struct pst_item_attach *next;
00418 } pst_item_attach;
00419 
00420 
00421 typedef struct pst_item_extra_field {
00422     char   *field_name;
00423     char   *value;
00424     struct pst_item_extra_field *next;
00425 } pst_item_extra_field;
00426 
00427 
00430 typedef struct pst_item_journal {
00431     FILETIME   *end;
00432     FILETIME   *start;
00433     pst_string  type;
00434     pst_string  description;
00435 } pst_item_journal;
00436 
00437 
00440 typedef struct pst_item_appointment {
00441     FILETIME   *end;
00442     pst_string  location;
00444     int         alarm;
00445     FILETIME   *reminder;
00446     int32_t     alarm_minutes;
00447     pst_string  alarm_filename;
00448     FILETIME   *start;
00449     pst_string  timezonestring;
00451     int32_t     showas;
00464     int32_t     label;
00466     int         all_day;
00468     pst_string  recurrence;
00470     int32_t     recurrence_type;
00471     FILETIME   *recurrence_start;
00472     FILETIME   *recurrence_end;
00473 } pst_item_appointment;
00474 
00475 
00476 typedef struct pst_item {
00477     struct pst_item_email         *email;           // data referring to email
00478     struct pst_item_folder        *folder;          // data referring to folder
00479     struct pst_item_contact       *contact;         // data referring to contact
00480     struct pst_item_attach        *attach;          // linked list of attachments
00481     struct pst_item_message_store *message_store;   // data referring to the message store
00482     struct pst_item_extra_field   *extra_fields;    // linked list of extra headers and such
00483     struct pst_item_journal       *journal;         // data referring to a journal entry
00484     struct pst_item_appointment   *appointment;     // data referring to a calendar entry
00485     int         type;
00486     char       *ascii_type;
00498     int32_t     flags;
00499     pst_string  file_as;
00500     pst_string  comment;
00502     pst_string  body_charset;
00504     pst_string  body;
00506     pst_string  subject;
00507     int32_t     internet_cpid;
00508     int32_t     message_codepage;
00509     int32_t     message_size;
00510     pst_string  outlook_version;
00511     pst_binary  record_key;
00512     pst_binary  predecessor_change;     // was formerly stored in record_key
00514     int         response_requested;
00515     FILETIME   *create_date;
00516     FILETIME   *modify_date;
00518     int         private_member;
00519 } pst_item;
00520 
00521 
00522 typedef struct pst_x_attrib_ll {
00523     uint32_t type;
00524     uint32_t mytype;
00525     uint32_t map;
00526     void *data;
00527     struct pst_x_attrib_ll *next;
00528 } pst_x_attrib_ll;
00529 
00530 
00531 typedef struct pst_block_recorder {
00532     struct pst_block_recorder  *next;
00533     int64_t                     offset;
00534     size_t                      size;
00535     int                         readcount;
00536 } pst_block_recorder;
00537 
00538 
00539 typedef struct pst_file {
00540     pst_index_ll *i_head, *i_tail;
00541     pst_desc_ll  *d_head, *d_tail;
00542     pst_x_attrib_ll *x_head;
00543     pst_block_recorder *block_head;
00544 
00545     int do_read64;              // 0 is 32-bit pst file, pre Outlook 2003;
00546                                 // 1 is 64-bit pst file, Outlook 2003 and later
00547     uint64_t index1;
00548     uint64_t index1_back;
00549     uint64_t index2;
00550     uint64_t index2_back;
00551     FILE * fp;                  // file pointer to opened PST file
00552     uint64_t size;              // pst file size
00553     unsigned char encryption;   // pst encryption setting
00554     unsigned char ind_type;     // pst index type
00555 } pst_file;
00556 
00557 
00558 typedef struct pst_block_offset {
00559     int16_t from;
00560     int16_t to;
00561 } pst_block_offset;
00562 
00563 
00564 typedef struct pst_block_offset_pointer {
00565     char *from;
00566     char *to;
00567     int   needfree;
00568 } pst_block_offset_pointer;
00569 
00570 
00571 typedef struct pst_mapi_element {
00572     uint32_t   mapi_id;
00573     char      *data;
00574     uint32_t   type;
00575     size_t     size;
00576     char      *extra;
00577 } pst_mapi_element;
00578 
00579 
00580 typedef struct pst_mapi_object {
00581     int32_t count_elements;     // count of active elements
00582     int32_t orig_count;         // originally allocated elements
00583     int32_t count_objects;      // number of mapi objects in the list
00584     struct pst_mapi_element **elements;
00585     struct pst_mapi_object *next;
00586 } pst_mapi_object;
00587 
00588 
00589 typedef struct pst_holder {
00590     char  **buf;
00591     FILE   *fp;
00592     int     base64;
00593 } pst_holder;
00594 
00595 
00596 typedef struct pst_subblock {
00597     char    *buf;
00598     size_t   read_size;
00599     size_t   i_offset;
00600 } pst_subblock;
00601 
00602 
00603 typedef struct pst_subblocks {
00604     size_t          subblock_count;
00605     pst_subblock   *subs;
00606 } pst_subblocks;
00607 
00608 
00609 // prototypes
00610 int            pst_open(pst_file *pf, char *name);
00611 int            pst_close(pst_file *pf);
00612 pst_desc_ll *  pst_getTopOfFolders(pst_file *pf, pst_item *root);
00613 size_t         pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b);
00614 size_t         pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
00615 size_t         pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
00616 int            pst_load_index (pst_file *pf);
00617 pst_desc_ll*   pst_getNextDptr(pst_desc_ll* d);
00618 int            pst_load_extended_attributes(pst_file *pf);
00619 
00620 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);
00621 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);
00622 pst_item*      pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
00623 pst_item*      pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr, pst_id2_ll *m_head);
00624 pst_mapi_object* pst_parse_block(pst_file *pf, uint64_t block_id, pst_id2_ll *i2_head);
00625 int            pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach);
00626 void           pst_free_list(pst_mapi_object *list);
00627 void           pst_freeItem(pst_item *item);
00628 void           pst_free_id2(pst_id2_ll * head);
00629 void           pst_free_id (pst_index_ll *head);
00630 void           pst_free_desc (pst_desc_ll *head);
00631 void           pst_free_xattrib(pst_x_attrib_ll *x);
00632 int            pst_getBlockOffsetPointer(pst_file *pf, pst_id2_ll *i2_head, pst_subblocks *subblocks, uint32_t offset, pst_block_offset_pointer *p);
00633 int            pst_getBlockOffset(char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p);
00634 pst_id2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list);
00635 pst_index_ll*  pst_getID(pst_file* pf, uint64_t i_id);
00636 pst_id2_ll* pst_getID2(pst_id2_ll * ptr, uint64_t id);
00637 pst_desc_ll*   pst_getDptr(pst_file *pf, uint64_t d_id);
00638 size_t         pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf);
00639 int            pst_decrypt(uint64_t id, char *buf, size_t size, unsigned char type);
00640 uint64_t       pst_getIntAt(pst_file *pf, char *buf);
00641 uint64_t       pst_getIntAtPos(pst_file *pf, int64_t pos);
00642 size_t         pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size);
00643 size_t         pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **b);
00644 size_t         pst_ff_getIDblock(pst_file *pf, uint64_t id, char** b);
00645 size_t         pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_ll *id2_head, char** buf);
00646 size_t         pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h);
00647 size_t         pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size);
00648 
00649 int            pst_strincmp(char *a, char *b, size_t x);
00650 int            pst_stricmp(char *a, char *b);
00651 size_t         pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
00652 char *         pst_wide_to_single(char *wt, size_t size);
00653 
00654 char *         pst_rfc2426_escape(char *str);
00655 int            pst_chr_count(char *str, char x);
00656 char *         pst_rfc2425_datetime_format(FILETIME *ft);
00657 char *         pst_rfc2445_datetime_format(FILETIME *ft);
00658 
00659 void           pst_printDptr(pst_file *pf, pst_desc_ll *ptr);
00660 void           pst_printIDptr(pst_file* pf);
00661 void           pst_printID2ptr(pst_id2_ll *ptr);
00662 
00663 const char*    pst_codepage(int cp);
00664 const char*    pst_default_charset(pst_item *item);
00665 void           pst_convert_utf8_null(pst_item *item, pst_string *str);
00666 void           pst_convert_utf8(pst_item *item, pst_string *str);
00667 
00668 
00669 // switch from maximal packing back to default packing
00670 // undo the packing from the beginning of this file
00671 #ifdef _MSC_VER
00672     #pragma pack(pop)
00673 #endif
00674 #if defined(__GNUC__) || defined (__SUNPRO_C) || defined(__SUNPRO_CC)
00675     #pragma pack()
00676 #endif
00677 
00678 
00679 
00680 #endif // defined LIBPST_H

Generated on Thu Mar 19 16:39:26 2009 for 'LibPst' by  doxygen 1.3.9.1