changeset 125:23a36ac0514d

recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Feb 2009 15:01:47 -0800
parents cbf63dd3f109
children f01d6163acba
files ChangeLog regression/regression-tests.bash src/common.h src/debug.c src/libpst.c src/libpst.h src/readpst.c src/readpstlog.c
diffstat 8 files changed, 86 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Feb 03 11:00:16 2009 -0800
+++ b/ChangeLog	Tue Feb 03 15:01:47 2009 -0800
@@ -1,4 +1,4 @@
-LibPST 0.6.26 (2009-02-02)
+LibPST 0.6.26 (2009-02-03)
 ===============================
     * patch from Fridrich Strba for building on mingw and
       general cleanup of autoconf files
@@ -7,8 +7,6 @@
       libpst.so and the header files required to use it.
     * remove version.h since the version number is now in config.h
     * more const correctness issues regarding getopt()
-    * disable building pst2dii on cygwin, since the convert program
-      on the path is part of windows, not image magic.
     * consistent ordering of our include files. all system includes
       protected by ifdef HAVE_ from autoconf.
     * strip and regenerate all MIME headers to avoid duplicates.
@@ -20,7 +18,9 @@
       HAVE_ symbols. define.h is the only other file allowed to
       include system .h files. define.h is never installed; common.h
       is installed if we are building the shared library.
-
+    * recover dropped pragma pack line, use int64_t rather than off_t
+      to avoid forcing users of the shared library to enable large
+      file support.
 
 LibPST 0.6.25 (2009-01-16)
 ===============================
--- a/regression/regression-tests.bash	Tue Feb 03 11:00:16 2009 -0800
+++ b/regression/regression-tests.bash	Tue Feb 03 15:01:47 2009 -0800
@@ -23,6 +23,7 @@
     mkdir output$n
     #    ../src/readpst -cv -o output$n $fn >$ba.err 2>&1
     $val ../src/readpst -cv -o output$n -d dumper $fn >$ba.err 2>&1
+    #readpst -cv -o output$n -d dumper $fn >$ba.err 2>&1
          ../src/readpstlog -f I dumper >$ba.log
     #$val ../src/pst2ldif -d dumper -b 'o=ams-cc.com, c=US' -c 'newPerson' -o $fn >$ba.ldif.err 2>&1
     #$val ../src/pst2ldif -d dumper -b 'o=ams-cc.com, c=US' -c 'inetOrgPerson' $fn >$ba.ldif2.err 2>&1
@@ -33,7 +34,7 @@
 
 
 val="valgrind --leak-check=full"
-#val=''
+val=''
 
 pushd ..
 make || exit
--- a/src/common.h	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/common.h	Tue Feb 03 15:01:47 2009 -0800
@@ -29,6 +29,7 @@
 
 
 #ifndef _WIN32
+    #pragma pack(1)
     typedef uint32_t  DWORD;
     typedef uint16_t   WORD;
     typedef uint8_t    BYTE;
--- a/src/debug.c	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/debug.c	Tue Feb 03 15:01:47 2009 -0800
@@ -48,7 +48,7 @@
     if (col == -1) col = NUM_COL;
     fprintf(out, "\n");
     while (off < size) {
-        fprintf(out, "%06"PRIx64"\t:", (uint64_t)(off+delta));
+        fprintf(out, "%06"PRIx64"\t:", (int64_t)(off+delta));
         toff = off;
         while (count < col && off < size) {
             fprintf(out, "%02hhx ", (unsigned char)buf[off]);
@@ -251,19 +251,19 @@
     size_t size, ptr, funcname, filename, text, end;
     char *buf = NULL, rec_type;
     if (!debug_fp) return;  // no file
-    uint64_t index_pos = ftello(debug_fp);
-    uint64_t file_pos  = index_pos;
+    int64_t index_pos = ftello(debug_fp);
+    int64_t file_pos  = index_pos;
     // add 2. One for the pointer to the next index,
     // one for the count of this index
-    int index_size = ((curr_items+2) * sizeof(uint64_t));
-    uint64_t *index;
+    int index_size = ((curr_items+2) * sizeof(int64_t));
+    int64_t *index;
     int index_ptr = 0;
     struct pst_debug_file_rec_m mfile_rec;
     struct pst_debug_file_rec_l lfile_rec;
 
     if (curr_items == 0) return;    // no items to write.
 
-    index = (uint64_t*)xmalloc(index_size);
+    index = (int64_t*)xmalloc(index_size);
     memset(index, 0, index_size);   // valgrind, avoid writing uninitialized data
     file_pos += index_size;
     // write the index first, we will re-write it later, but
@@ -335,9 +335,9 @@
     struct pst_debug_file_rec_l lfile_rec;
     struct pst_debug_file_rec_m mfile_rec;
     unsigned char rec_type;
-    int index_size = 3 * sizeof(uint64_t);
-    uint64_t index[3];
-    uint64_t index_pos, file_pos;
+    int index_size = 3 * sizeof(int64_t);
+    int64_t index[3];
+    int64_t index_pos, file_pos;
     char zero = '\0';
     unsigned int end;
     if (!debug_fp) return;  // no file
@@ -397,8 +397,8 @@
 void pst_debug_write_hex(struct pst_debug_item *item, char *buf, size_t size, int col) {
     struct pst_debug_file_rec_l lfile_rec;
     unsigned char rec_type;
-    int index_size = 3 * sizeof(uint64_t);
-    uint64_t index_pos, file_pos, index[3];
+    int index_size = 3 * sizeof(int64_t);
+    int64_t index_pos, file_pos, index[3];
     char zero='\0';
     if (!debug_fp) return;  // no file
     index[0] = 1; // only one item in this index run
--- a/src/libpst.c	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/libpst.c	Tue Feb 03 15:01:47 2009 -0800
@@ -20,21 +20,21 @@
 #define INDEX_TYPE32A           0x0F    // unknown, but assumed to be similar for now
 #define INDEX_TYPE64            0x17
 #define INDEX_TYPE64A           0x15    // http://sourceforge.net/projects/libpff/
-#define INDEX_TYPE_OFFSET       (uint64_t)0x0A
-
-#define FILE_SIZE_POINTER32     (uint64_t)0xA8
-#define INDEX_POINTER32         (uint64_t)0xC4
-#define INDEX_BACK32            (uint64_t)0xC0
-#define SECOND_POINTER32        (uint64_t)0xBC
-#define SECOND_BACK32           (uint64_t)0xB8
-#define ENC_TYPE32              (uint64_t)0x1CD
-
-#define FILE_SIZE_POINTER64     (uint64_t)0xB8
-#define INDEX_POINTER64         (uint64_t)0xF0
-#define INDEX_BACK64            (uint64_t)0xE8
-#define SECOND_POINTER64        (uint64_t)0xE0
-#define SECOND_BACK64           (uint64_t)0xD8
-#define ENC_TYPE64              (uint64_t)0x201
+#define INDEX_TYPE_OFFSET       (int64_t)0x0A
+
+#define FILE_SIZE_POINTER32     (int64_t)0xA8
+#define INDEX_POINTER32         (int64_t)0xC4
+#define INDEX_BACK32            (int64_t)0xC0
+#define SECOND_POINTER32        (int64_t)0xBC
+#define SECOND_BACK32           (int64_t)0xB8
+#define ENC_TYPE32              (int64_t)0x1CD
+
+#define FILE_SIZE_POINTER64     (int64_t)0xB8
+#define INDEX_POINTER64         (int64_t)0xF0
+#define INDEX_BACK64            (int64_t)0xE8
+#define SECOND_POINTER64        (int64_t)0xE0
+#define SECOND_BACK64           (int64_t)0xD8
+#define ENC_TYPE64              (int64_t)0x201
 
 #define FILE_SIZE_POINTER ((pf->do_read64) ? FILE_SIZE_POINTER64 : FILE_SIZE_POINTER32)
 #define INDEX_POINTER     ((pf->do_read64) ? INDEX_POINTER64     : INDEX_POINTER32)
@@ -813,7 +813,7 @@
 }
 
 
-int pst_build_id_ptr(pst_file *pf, uint64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) {
+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) {
     struct pst_table_ptr_structn table, table2;
     pst_index_ll *i_ptr=NULL;
     pst_index index;
@@ -926,7 +926,7 @@
 }
 
 
-int pst_build_desc_ptr (pst_file *pf, uint64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) {
+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) {
     struct pst_table_ptr_structn table, table2;
     pst_descn desc_rec;
     int32_t item_count;
@@ -1091,8 +1091,9 @@
     list = NULL; //pst_process will free the items in the list
 
     if ((id_ptr = pst_getID2(id2_head, (uint64_t)0x671))) {
-        // attachments exist - so we will process them
+        // should not have any existing attachments anyway
         while (item->attach) {
+            DEBUG_EMAIL(("throw away existing attachment\n"));
             attach = item->attach->next;
             free(item->attach);
             item->attach = attach;
@@ -1101,10 +1102,8 @@
         DEBUG_EMAIL(("ATTACHMENT processing attachment\n"));
         if ((list = pst_parse_block(pf, id_ptr->id, id2_head, NULL)) == NULL) {
             DEBUG_WARN(("ERROR error processing main attachment record\n"));
-            //if (item) pst_freeItem(item);
             if (id2_head) pst_free_id2(id2_head);
             DEBUG_RET();
-            //return NULL;
             return item;
         }
         else {
@@ -4118,7 +4117,7 @@
                  is non-NULL, it will first be free()d
  * @return       size of block read into memory
  */
-size_t pst_read_block_size(pst_file *pf, uint64_t offset, size_t size, char **buf) {
+size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf) {
     size_t rsize;
     DEBUG_ENT("pst_read_block_size");
     DEBUG_READ(("Reading block from %#"PRIx64", %x bytes\n", offset, size));
@@ -4210,7 +4209,7 @@
 }
 
 
-uint64_t pst_getIntAtPos(pst_file *pf, uint64_t pos ) {
+uint64_t pst_getIntAtPos(pst_file *pf, int64_t pos ) {
     uint64_t buf64;
     uint32_t buf32;
     if (pf->do_read64) {
@@ -4235,7 +4234,7 @@
  * @return     actual read size, 0 if seek error
  */
 
-size_t pst_getAtPos(pst_file *pf, uint64_t pos, void* buf, size_t size) {
+size_t pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size) {
     size_t rc;
     DEBUG_ENT("pst_getAtPos");
 //  pst_block_recorder **t = &pf->block_head;
--- a/src/libpst.h	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/libpst.h	Tue Feb 03 15:01:47 2009 -0800
@@ -460,7 +460,7 @@
 
 typedef struct pst_block_recorder {
     struct pst_block_recorder  *next;
-    uint64_t                    offset;
+    int64_t                     offset;
     size_t                      size;
     int                         readcount;
 } pst_block_recorder;
@@ -549,8 +549,8 @@
 pst_desc_ll*   pst_getNextDptr(pst_desc_ll* d);
 int            pst_load_extended_attributes(pst_file *pf);
 
-int            pst_build_id_ptr(pst_file *pf, uint64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
-int            pst_build_desc_ptr(pst_file *pf, uint64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
+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);
+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);
 pst_item*      pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
 pst_item*      pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
 pst_num_array* pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head, pst_num_array *na_head);
@@ -567,11 +567,11 @@
 pst_index_ll*  pst_getID(pst_file* pf, uint64_t id);
 pst_index_ll*  pst_getID2(pst_index2_ll * ptr, uint64_t id);
 pst_desc_ll*   pst_getDptr(pst_file *pf, uint64_t id);
-size_t         pst_read_block_size(pst_file *pf, uint64_t offset, size_t size, char **buf);
+size_t         pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf);
 int            pst_decrypt(uint64_t id, char *buf, size_t size, unsigned char type);
 uint64_t       pst_getIntAt(pst_file *pf, char *buf);
-uint64_t       pst_getIntAtPos(pst_file *pf, uint64_t pos);
-size_t         pst_getAtPos(pst_file *pf, uint64_t pos, void* buf, size_t size);
+uint64_t       pst_getIntAtPos(pst_file *pf, int64_t pos);
+size_t         pst_getAtPos(pst_file *pf, int64_t pos, void* buf, size_t size);
 size_t         pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **b);
 size_t         pst_ff_getIDblock(pst_file *pf, uint64_t id, char** b);
 size_t         pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, char** buf);
--- a/src/readpst.c	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/readpst.c	Tue Feb 03 15:01:47 2009 -0800
@@ -922,7 +922,6 @@
     int attach_num;
     time_t em_time;
     char *c_time;
-    pst_item_attach* current_attach;
     int has_from, has_subject, has_to, has_cc, has_bcc, has_date;
     has_from = has_subject = has_to = has_cc = has_bcc = has_date = 0;
     DEBUG_ENT("write_normal_email");
@@ -1000,6 +999,7 @@
         header_strip_field(item->email->header, "\nContent-Transfer-Encoding: ");
         header_strip_field(item->email->header, "\nContent-class: ");
         header_strip_field(item->email->header, "\nX-MimeOLE: ");
+        header_strip_field(item->email->header, "\nBcc: ");
     }
 
     DEBUG_EMAIL(("About to print Header\n"));
@@ -1096,56 +1096,61 @@
     }
 
     if (item->email->rtf_compressed && save_rtf) {
+        pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
         DEBUG_EMAIL(("Adding RTF body as attachment\n"));
-        current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
-        memset(current_attach, 0, sizeof(pst_item_attach));
-        current_attach->next = item->attach;
-        item->attach = current_attach;
-        current_attach->data = lzfu_decompress(item->email->rtf_compressed, item->email->rtf_compressed_size, &current_attach->size);
-        current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
-        strcpy(current_attach->filename2, RTF_ATTACH_NAME);
-        current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
-        strcpy(current_attach->mimetype, RTF_ATTACH_TYPE);
+        memset(attach, 0, sizeof(pst_item_attach));
+        attach->next = item->attach;
+        item->attach = attach;
+        attach->data = lzfu_decompress(item->email->rtf_compressed, item->email->rtf_compressed_size, &attach->size);
+        attach->filename2 = strdup(RTF_ATTACH_NAME);
+        attach->mimetype  = strdup(RTF_ATTACH_TYPE);
     }
 
     if (item->email->encrypted_body || item->email->encrypted_htmlbody) {
         // if either the body or htmlbody is encrypted, add them as attachments
         if (item->email->encrypted_body) {
+            pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
             DEBUG_EMAIL(("Adding Encrypted Body as attachment\n"));
-            current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
-            memset(current_attach, 0, sizeof(pst_item_attach));
-            current_attach->next = item->attach;
-            item->attach = current_attach;
-            current_attach->data = item->email->encrypted_body;
-            current_attach->size = item->email->encrypted_body_size;
+            attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
+            memset(attach, 0, sizeof(pst_item_attach));
+            attach->next = item->attach;
+            item->attach = attach;
+            attach->data = item->email->encrypted_body;
+            attach->size = item->email->encrypted_body_size;
             item->email->encrypted_body = NULL;
         }
 
         if (item->email->encrypted_htmlbody) {
+            pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
             DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n"));
-            current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
-            memset(current_attach, 0, sizeof(pst_item_attach));
-            current_attach->next = item->attach;
-            item->attach = current_attach;
-            current_attach->data = item->email->encrypted_htmlbody;
-            current_attach->size = item->email->encrypted_htmlbody_size;
+            attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
+            memset(attach, 0, sizeof(pst_item_attach));
+            attach->next = item->attach;
+            item->attach = attach;
+            attach->data = item->email->encrypted_htmlbody;
+            attach->size = item->email->encrypted_htmlbody_size;
             item->email->encrypted_htmlbody = NULL;
         }
         write_email_body(f_output, "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
     }
 
     // other attachments
-    attach_num = 0;
-    for (current_attach = item->attach; current_attach; current_attach = current_attach->next) {
-        DEBUG_EMAIL(("Attempting Attachment encoding\n"));
-        if (!current_attach->data) {
-            DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->size));
+    {
+        pst_item_attach* attach;
+        attach_num = 0;
+        for (attach = item->attach; attach; attach = attach->next) {
+            DEBUG_EMAIL(("Attempting Attachment encoding\n"));
+            if (!attach->data) {
+                DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", attach->size));
+            }
+            if (mode == MODE_SEPARATE && !mode_MH)
+                write_separate_attachment(f_name, attach, ++attach_num, pst);
+            else
+                write_inline_attachment(f_output, attach, boundary, pst);
         }
-        if (mode == MODE_SEPARATE && !mode_MH)
-            write_separate_attachment(f_name, current_attach, ++attach_num, pst);
-        else
-            write_inline_attachment(f_output, current_attach, boundary, pst);
     }
+
+    // end of this mail message
     if (mode != MODE_SEPARATE) { /* do not add a boundary after the last attachment for mode_MH */
         DEBUG_EMAIL(("Writing buffer between emails\n"));
         fprintf(f_output, "\n--%s--\n", boundary);
--- a/src/readpstlog.c	Tue Feb 03 11:00:16 2009 -0800
+++ b/src/readpstlog.c	Tue Feb 03 15:01:47 2009 -0800
@@ -68,13 +68,13 @@
     buf = (char*) xmalloc(BUF_SIZE);
 
     while (!stop) {
-        uint64_t temp;
-        if (fread(&temp, sizeof(uint64_t), 1, fp)<=0) break;
+        int64_t temp;
+        if (fread(&temp, sizeof(int64_t), 1, fp)<=0) break;
         x = (int)temp;
         ptr = 0;
         if (x > 0) {
-            uint64_t i[x+1]; // plus 1 because we want to read the offset of the next index
-            if (get(i, sizeof(uint64_t), x+1, fp)==0) {
+            int64_t i[x+1]; // plus 1 because we want to read the offset of the next index
+            if (get(i, sizeof(int64_t), x+1, fp)==0) {
                 // we have reached the end of the debug file
                 printf("oh dear. we must now end\n");
                 break;