# 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 __PST_LIBPST_H
    00011 #define __PST_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_SCHEDULE    2
    00028 #define PST_TYPE_APPOINTMENT 8
    00029 #define PST_TYPE_CONTACT     9
    00030 #define PST_TYPE_JOURNAL    10
    00031 #define PST_TYPE_STICKYNOTE 11
    00032 #define PST_TYPE_TASK       12
    00033 #define PST_TYPE_OTHER      13
    00034 #define PST_TYPE_REPORT     14
    00035
    00036 // defines types of possible encryption
    00037 #define PST_NO_ENCRYPT   0
    00038 #define PST_COMP_ENCRYPT 1
    00039 #define PST_ENCRYPT      2
    00040
    00041 // defines different types of mappings
    00042 #define PST_MAP_ATTRIB (uint32_t)1
    00043 #define PST_MAP_HEADER (uint32_t)2
    00044
    00045 // define my custom email attributes.
    00046 #define PST_ATTRIB_HEADER -1
    00047
    00048 // defines types of free/busy values for appointment->showas
    00049 #define PST_FREEBUSY_FREE          0
    00050 #define PST_FREEBUSY_TENTATIVE     1
    00051 #define PST_FREEBUSY_BUSY          2
    00052 #define PST_FREEBUSY_OUT_OF_OFFICE 3
    00053
    00054 // defines labels for appointment->label
    00055 #define PST_APP_LABEL_NONE        0
    00056 #define PST_APP_LABEL_IMPORTANT   1
    00057 #define PST_APP_LABEL_BUSINESS    2
    00058 #define PST_APP_LABEL_PERSONAL    3
    00059 #define PST_APP_LABEL_VACATION    4
    00060 #define PST_APP_LABEL_MUST_ATTEND 5
    00061 #define PST_APP_LABEL_TRAVEL_REQ  6
    00062 #define PST_APP_LABEL_NEEDS_PREP  7
    00063 #define PST_APP_LABEL_BIRTHDAY    8
    00064 #define PST_APP_LABEL_ANNIVERSARY 9
    00065 #define PST_APP_LABEL_PHONE_CALL  10
    00066
    00067 // define type of recuring event
    00068 #define PST_APP_RECUR_NONE        0
    00069 #define PST_APP_RECUR_DAILY       1
    00070 #define PST_APP_RECUR_WEEKLY      2
    00071 #define PST_APP_RECUR_MONTHLY     3
    00072 #define PST_APP_RECUR_YEARLY      4
    00073
    00074 // define attachment types
    00075 #define PST_ATTACH_NONE             0
    00076 #define PST_ATTACH_BY_VALUE         1
    00077 #define PST_ATTACH_BY_REF           2
    00078 #define PST_ATTACH_BY_REF_RESOLV    3
    00079 #define PST_ATTACH_BY_REF_ONLY      4
    00080 #define PST_ATTACH_EMBEDDED         5
    00081 #define PST_ATTACH_OLE              6
    00082
    00083 // define flags
    00084 #define PST_FLAG_READ           0x01
    00085 #define PST_FLAG_UNMODIFIED     0x02
    00086 #define PST_FLAG_SUBMIT         0x04
    00087 #define PST_FLAG_UNSENT         0x08
    00088 #define PST_FLAG_HAS_ATTACHMENT 0x10
    00089 #define PST_FLAG_FROM_ME        0x20
    00090 #define PST_FLAG_ASSOCIATED     0x40
    00091 #define PST_FLAG_RESEND         0x80
    00092 #define PST_FLAG_RN_PENDING     0x100
    00093 #define PST_FLAG_NRN_PENDING    0x200
    00094
    00095
    00096 typedef struct pst_entryid {
    00097     int32_t u1;
    00098     char entryid[16];
    00099     uint32_t id;
    00100 } pst_entryid;
    00101
    00102
    00103 typedef struct pst_index_ll {
    00104     uint64_t i_id;
    00105     uint64_t offset;
    00106     uint64_t size;
    00107     int64_t  u1;
    00108     struct pst_index_ll *next;
    00109 } pst_index_ll;
    00110
    00111
    00112 typedef struct pst_id2_tree {
    00113     uint64_t            id2;
    00114     pst_index_ll        *id;
    00115     struct pst_id2_tree *child;
    00116     struct pst_id2_tree *next;
    00117 } pst_id2_tree;
    00118
    00119
    00120 typedef struct pst_desc_tree {
    00121     uint64_t              d_id;
    00122     uint64_t              parent_d_id;
    00123     pst_index_ll         *desc;
    00124     pst_index_ll         *assoc_tree;
    00125     int32_t               no_child;
    00126     struct pst_desc_tree *prev;
    00127     struct pst_desc_tree *next;
    00128     struct pst_desc_tree *parent;
    00129     struct pst_desc_tree *child;
    00130     struct pst_desc_tree *child_tail;
    00131 } pst_desc_tree;
    00132
    00133
    00138 typedef struct pst_string {
    00141     int     is_utf8;
    00142     char   *str;
    00143 } pst_string;
    00144
    00145
    00147 typedef struct pst_binary {
    00148     size_t  size;
    00149     char   *data;
    00150 } pst_binary;
    00151
    00152
    00155 typedef struct pst_item_email {
    00157     FILETIME   *arrival_date;
    00162     int         autoforward;
    00164     pst_string  cc_address;
    00166     pst_string  bcc_address;
    00168     pst_binary  conversation_index;
    00172     int         conversion_prohibited;
    00176     int         delete_after_submit;
    00180     int         delivery_report;
    00182     pst_binary  encrypted_body;
    00184     pst_binary  encrypted_htmlbody;
    00186     pst_string  header;
    00188     pst_string  htmlbody;
    00193     int32_t     importance;
    00195     pst_string  in_reply_to;
    00199     int         message_cc_me;
    00203     int         message_recip_me;
    00207     int         message_to_me;
    00209     pst_string  messageid;
    00215     int32_t     original_sensitivity;
    00217     pst_string  original_bcc;
    00219     pst_string  original_cc;
    00221     pst_string  original_to;
    00223     pst_string  outlook_recipient;
    00225     pst_string  outlook_recipient_name;
    00227     pst_string  outlook_recipient2;
    00229     pst_string  outlook_sender;
    00231     pst_string  outlook_sender_name;
    00233     pst_string  outlook_sender2;
    00239     int32_t     priority;
    00241     pst_string  processed_subject;
    00245     int         read_receipt;
    00247     pst_string  recip_access;
    00249     pst_string  recip_address;
    00251     pst_string  recip2_access;
    00253     pst_string  recip2_address;
    00257     int         reply_requested;
    00259     pst_string  reply_to;
    00261     pst_string  return_path_address;
    00265     int32_t     rtf_body_char_count;
    00267     int32_t     rtf_body_crc;
    00271     pst_string  rtf_body_tag;
    00275     pst_binary  rtf_compressed;
    00283     int         rtf_in_sync;
    00286     int32_t     rtf_ws_prefix_count;
    00289     int32_t     rtf_ws_trailing_count;
    00291     pst_string  sender_access;
    00293     pst_string  sender_address;
    00295     pst_string  sender2_access;
    00297     pst_string  sender2_address;
    00303     int32_t     sensitivity;
    00305     FILETIME    *sent_date;
    00307     pst_entryid *sentmail_folder;
    00309     pst_string  sentto_address;
    00311     pst_string  report_text;
    00313     FILETIME   *report_time;
    00315     int32_t     ndr_reason_code;
    00317     int32_t     ndr_diag_code;
    00319     pst_string  supplementary_info;
    00321     int32_t     ndr_status_code;
    00322
    00323     // elements added for .msg processing
    00325     pst_string  outlook_received_name1;
    00327     pst_string  outlook_sender_name2;
    00329     pst_string  outlook_normalized_subject;
    00331     pst_string  outlook_search_key;
    00332 } pst_item_email;
    00333
    00334
    00337 typedef struct pst_item_folder {
    00339     int32_t  item_count;
    00341     int32_t  unseen_item_count;
    00345     int32_t  assoc_count;
    00350     int      subfolder;
    00351 } pst_item_folder;
    00352
    00353
    00356 typedef struct pst_item_message_store {
    00358     pst_entryid *top_of_personal_folder;
    00360     pst_entryid *default_outbox_folder;
    00362     pst_entryid *deleted_items_folder;
    00364     pst_entryid *sent_items_folder;
    00366     pst_entryid *user_views_folder;
    00368     pst_entryid *common_view_folder;
    00370     pst_entryid *search_root_folder;
    00372     pst_entryid *top_of_folder;
    00383     int32_t valid_mask;
    00385     int32_t pwd_chksum;
    00386 } pst_item_message_store;
    00387
    00388
    00391 typedef struct pst_item_contact {
    00393     pst_string  account_name;
    00395     pst_string  address1;
    00397     pst_string  address1a;
    00399     pst_string  address1_desc;
    00401     pst_string  address1_transport;
    00403     pst_string  address2;
    00405     pst_string  address2a;
    00407     pst_string  address2_desc;
    00409     pst_string  address2_transport;
    00411     pst_string  address3;
    00413     pst_string  address3a;
    00415     pst_string  address3_desc;
    00417     pst_string  address3_transport;
    00419     pst_string  assistant_name;
    00421     pst_string  assistant_phone;
    00423     pst_string  billing_information;
    00425     FILETIME   *birthday;
    00427     pst_string  business_address;
    00429     pst_string  business_city;
    00431     pst_string  business_country;
    00433     pst_string  business_fax;
    00435     pst_string  business_homepage;
    00437     pst_string  business_phone;
    00439     pst_string  business_phone2;
    00441     pst_string  business_po_box;
    00443     pst_string  business_postal_code;
    00445     pst_string  business_state;
    00447     pst_string  business_street;
    00449     pst_string  callback_phone;
    00451     pst_string  car_phone;
    00453     pst_string  company_main_phone;
    00455     pst_string  company_name;
    00457     pst_string  computer_name;
    00459     pst_string  customer_id;
    00461     pst_string  def_postal_address;
    00463     pst_string  department;
    00465     pst_string  display_name_prefix;
    00467     pst_string  first_name;
    00469     pst_string  followup;
    00471     pst_string  free_busy_address;
    00473     pst_string  ftp_site;
    00475     pst_string  fullname;
    00480     int16_t     gender;
    00482     pst_string  gov_id;
    00484     pst_string  hobbies;
    00486     pst_string  home_address;
    00488     pst_string  home_city;
    00490     pst_string  home_country;
    00492     pst_string  home_fax;
    00494     pst_string  home_phone;
    00496     pst_string  home_phone2;
    00498     pst_string  home_po_box;
    00500     pst_string  home_postal_code;
    00502     pst_string  home_state;
    00504     pst_string  home_street;
    00506     pst_string  initials;
    00508     pst_string  isdn_phone;
    00510     pst_string  job_title;
    00512     pst_string  keyword;
    00514     pst_string  language;
    00516     pst_string  location;
    00520     int         mail_permission;
    00522     pst_string  manager_name;
    00524     pst_string  middle_name;
    00526     pst_string  mileage;
    00528     pst_string  mobile_phone;
    00530     pst_string  nickname;
    00532     pst_string  office_loc;
    00534     pst_string  common_name;
    00536     pst_string  org_id;
    00538     pst_string  other_address;
    00540     pst_string  other_city;
    00542     pst_string  other_country;
    00544     pst_string  other_phone;
    00546     pst_string  other_po_box;
    00548     pst_string  other_postal_code;
    00550     pst_string  other_state;
    00552     pst_string  other_street;
    00554     pst_string  pager_phone;
    00556     pst_string  personal_homepage;
    00558     pst_string  pref_name;
    00560     pst_string  primary_fax;
    00562     pst_string  primary_phone;
    00564     pst_string  profession;
    00566     pst_string  radio_phone;
    00570     int         rich_text;
    00572     pst_string  spouse_name;
    00574     pst_string  suffix;
    00576     pst_string  surname;
    00578     pst_string  telex;
    00580     pst_string  transmittable_display_name;
    00582     pst_string  ttytdd_phone;
    00584     FILETIME   *wedding_anniversary;
    00586     pst_string  work_address_street;
    00588     pst_string  work_address_city;
    00590     pst_string  work_address_state;
    00592     pst_string  work_address_postalcode;
    00594     pst_string  work_address_country;
    00596     pst_string  work_address_postofficebox;
    00597 } pst_item_contact;
    00598
    00599
    00602 typedef struct pst_item_attach {
    00604     pst_string      filename1;
    00606     pst_string      filename2;
    00608     pst_string      mimetype;
    00610     pst_binary      data;
    00612     uint64_t        id2_val;
    00614     uint64_t        i_id;
    00616     pst_id2_tree    *id2_head;
    00625     int32_t         method;
    00627     int32_t         position;
    00629     int32_t         sequence;
    00630     struct pst_item_attach *next;
    00631 } pst_item_attach;
    00632
    00633
    00635 typedef struct pst_item_extra_field {
    00636     char   *field_name;
    00637     char   *value;
    00638     struct pst_item_extra_field *next;
    00639 } pst_item_extra_field;
    00640
    00641
    00644 typedef struct pst_item_journal {
    00646     FILETIME   *start;
    00648     FILETIME   *end;
    00650     pst_string  type;
    00652     pst_string  description;
    00653 } pst_item_journal;
    00654
    00655
    00659 typedef struct pst_recurrence {
    00661     uint32_t    signature;
    00666     uint32_t    type;
    00673     uint32_t    sub_type;
    00675     uint32_t    parm1;
    00676     uint32_t    parm2;
    00677     uint32_t    parm3;
    00678     uint32_t    parm4;
    00679     uint32_t    parm5;
    00685     uint32_t    termination;
    00687     uint32_t    interval;
    00689     uint32_t    bydaymask;
    00691     uint32_t    dayofmonth;
    00693     uint32_t    monthofyear;
    00695     uint32_t    position;
    00697     uint32_t    count;
    00698     // there is more data, including the termination date,
    00699     // but we can get that from other mapi elements.
    00700 } pst_recurrence;
    00701
    00702
    00705 typedef struct pst_item_appointment {
    00707     FILETIME   *start;
    00709     FILETIME   *end;
    00711     pst_string  location;
    00715     int         alarm;
    00717     FILETIME   *reminder;
    00719     int32_t     alarm_minutes;
    00721     pst_string  alarm_filename;
    00723     pst_string  timezonestring;
    00729     int32_t     showas;
    00742     int32_t     label;
    00746     int         all_day;
    00750     int         is_recurring;
    00757     int32_t     recurrence_type;
    00759     pst_string  recurrence_description;
    00761     pst_binary  recurrence_data;
    00763     FILETIME   *recurrence_start;
    00765     FILETIME   *recurrence_end;
    00766 } pst_item_appointment;
    00767
    00768
    00772 typedef struct pst_item {
    00774     struct pst_file        *pf;
    00776     uint64_t               block_id;
    00778     pst_item_email         *email;
    00780     pst_item_folder        *folder;
    00782     pst_item_contact       *contact;
    00784     pst_item_attach        *attach;
    00786     pst_item_message_store *message_store;
    00788     pst_item_extra_field   *extra_fields;
    00790     pst_item_journal       *journal;
    00792     pst_item_appointment   *appointment;
    00803     int         type;
    00805     char       *ascii_type;
    00817     int32_t     flags;
    00819     pst_string  file_as;
    00821     pst_string  comment;
    00823     pst_string  body_charset;
    00825     pst_string  body;
    00827     pst_string  subject;
    00829     int32_t     internet_cpid;
    00831     int32_t     message_codepage;
    00833     int32_t     message_size;
    00835     pst_string  outlook_version;
    00837     pst_binary  record_key;
    00839     pst_binary  predecessor_change;
    00843     int         response_requested;
    00845     FILETIME   *create_date;
    00847     FILETIME   *modify_date;
    00851     int         private_member;
    00852 } pst_item;
    00853
    00854
    00863 typedef struct pst_x_attrib_ll {
    00867     uint32_t mytype;
    00869     uint32_t map;
    00871     void     *data;
    00873     struct pst_x_attrib_ll *next;
    00874 } pst_x_attrib_ll;
    00875
    00876
    00878 typedef struct pst_block_recorder {
    00879     struct pst_block_recorder  *next;
    00880     int64_t                     offset;
    00881     size_t                      size;
    00882     int                         readcount;
    00883 } pst_block_recorder;
    00884
    00885
    00886 typedef struct pst_file {
    00888     FILE*   fp;
    00890     char*   cwd;
    00892     char*   fname;
    00894     char*   charset;
    00896     pst_index_ll *i_head, *i_tail;
    00898     pst_desc_tree  *d_head, *d_tail;
    00900     pst_x_attrib_ll *x_head;
    00904     pst_block_recorder *block_head;
    00905
    00908     int do_read64;
    00910     uint64_t index1;
    00912     uint64_t index1_back;
    00914     uint64_t index2;
    00916     uint64_t index2_back;
    00918     uint64_t size;
    00922     unsigned char encryption;
    00928     unsigned char ind_type;
    00929 } pst_file;
    00930
    00931
    00939 int             pst_open(pst_file *pf, const char *name, const char *charset);
    00940
    00941
    00946 int             pst_reopen(pst_file *pf);
    00947
    00948
    00954 int             pst_load_index (pst_file *pf);
    00955
    00956
    00961 int             pst_load_extended_attributes(pst_file *pf);
    00962
    00963
    00967 int             pst_close(pst_file *pf);
    00968
    00969
    00975 pst_desc_tree*  pst_getTopOfFolders(pst_file *pf, const pst_item *root);
    00976
    00977
    00984 pst_binary      pst_attach_to_mem(pst_file *pf, pst_item_attach *attach);
    00985
    00986
    00992 size_t          pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
    00993
    00994
    01000 size_t          pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
    01001
    01002
    01007 pst_desc_tree*  pst_getNextDptr(pst_desc_tree* d);
    01008
    01009
    01017 pst_item*       pst_parse_item (pst_file *pf, pst_desc_tree *d_ptr, pst_id2_tree *m_head);
    01018
    01019
    01023 void            pst_freeItem(pst_item *item);
    01024
    01025
    01031 pst_index_ll*   pst_getID(pst_file* pf, uint64_t i_id);
    01032
    01033
    01041 size_t          pst_ff_getIDblock_dec(pst_file *pf, uint64_t i_id, char **buf);
    01042
    01043
    01051 size_t          pst_fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream);
    01052
    01053
    01062 char*           pst_rfc2426_escape(char* str, char** result, size_t* resultlen);
    01063
    01064
    01072 char*           pst_rfc2425_datetime_format(const FILETIME* ft, int buflen, char* result);
    01073
    01074
    01081 char*           pst_rfc2445_datetime_format(const FILETIME* ft, int buflen, char* result);
    01082
    01083
    01089 char*           pst_rfc2445_datetime_format_now(int buflen, char* result);
    01090
    01091
    01099 const char*     pst_default_charset(pst_item *item, int buflen, char* result);
    01100
    01101
    01105 void            pst_rfc2231(pst_string *str);
    01106
    01107
    01113 void            pst_rfc2047(pst_item *item, pst_string *str, int needs_quote);
    01114
    01115
    01120 void            pst_convert_utf8_null(pst_item *item, pst_string *str);
    01121
    01122
    01127 void            pst_convert_utf8(pst_item *item, pst_string *str);
    01128
    01129
    01134 pst_recurrence* pst_convert_recurrence(pst_item_appointment* appt);
    01135
    01136
    01140 void            pst_free_recurrence(pst_recurrence* r);
    01141
    01142
    01143
    01144 // switch from maximal packing back to default packing
    01145 // undo the packing from the beginning of this file
    01146 #ifdef _MSC_VER
    01147     #pragma pack(pop)
    01148 #endif
    01149 #if defined(__GNUC__) || defined (__SUNPRO_C) || defined(__SUNPRO_CC)
    01150     #pragma pack()
    01151 #endif
    01152
    01153
    01154
    01155 #endif