comparison src/libpst.c @ 195:320cfcba8058

add python module interface to the shared library for easy scripting. the shared library must never write to stdout or stderr. fix pst_attach_to_mem so the caller does not need to initialize the buffer pointer.
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Apr 2009 19:39:26 -0700
parents cf3df962f1e5
children 7c60d6d1c681
comparison
equal deleted inserted replaced
194:885b47107036 195:320cfcba8058
282 static int pst_strincmp(char *a, char *b, size_t x); 282 static int pst_strincmp(char *a, char *b, size_t x);
283 static char* pst_wide_to_single(char *wt, size_t size); 283 static char* pst_wide_to_single(char *wt, size_t size);
284 284
285 285
286 286
287 int pst_open(pst_file *pf, char *name) { 287 int pst_open(pst_file *pf, const char *name) {
288 int32_t sig; 288 int32_t sig;
289 289
290 pst_unicode_init(); 290 pst_unicode_init();
291 291
292 DEBUG_ENT("pst_open"); 292 DEBUG_ENT("pst_open");
305 } 305 }
306 306
307 // Check pst file magic 307 // Check pst file magic
308 if (pst_getAtPos(pf, 0, &sig, sizeof(sig)) != sizeof(sig)) { 308 if (pst_getAtPos(pf, 0, &sig, sizeof(sig)) != sizeof(sig)) {
309 (void)fclose(pf->fp); 309 (void)fclose(pf->fp);
310 WARN(("cannot read signature from PST file. Closing on error\n")); 310 DEBUG_WARN(("cannot read signature from PST file. Closing with error\n"));
311 DEBUG_RET(); 311 DEBUG_RET();
312 return -1; 312 return -1;
313 } 313 }
314 LE32_CPU(sig); 314 LE32_CPU(sig);
315 DEBUG_INFO(("sig = %X\n", sig)); 315 DEBUG_INFO(("sig = %X\n", sig));
316 if (sig != (int32_t)PST_SIGNATURE) { 316 if (sig != (int32_t)PST_SIGNATURE) {
317 (void)fclose(pf->fp); 317 (void)fclose(pf->fp);
318 WARN(("not a PST file that I know. Closing with error\n")); 318 DEBUG_WARN(("not a PST file that I know. Closing with error\n"));
319 DEBUG_RET(); 319 DEBUG_RET();
320 return -1; 320 return -1;
321 } 321 }
322 322
323 // read index type 323 // read index type
332 case INDEX_TYPE64A : 332 case INDEX_TYPE64A :
333 pf->do_read64 = 1; 333 pf->do_read64 = 1;
334 break; 334 break;
335 default: 335 default:
336 (void)fclose(pf->fp); 336 (void)fclose(pf->fp);
337 WARN(("unknown .pst format, possibly newer than Outlook 2003 PST file?\n")); 337 DEBUG_WARN(("unknown .pst format, possibly newer than Outlook 2003 PST file?\n"));
338 DEBUG_RET(); 338 DEBUG_RET();
339 return -1; 339 return -1;
340 } 340 }
341 341
342 // read encryption setting 342 // read encryption setting
358 358
359 359
360 int pst_close(pst_file *pf) { 360 int pst_close(pst_file *pf) {
361 DEBUG_ENT("pst_close"); 361 DEBUG_ENT("pst_close");
362 if (!pf->fp) { 362 if (!pf->fp) {
363 WARN(("cannot close NULL fp\n"));
364 DEBUG_RET(); 363 DEBUG_RET();
365 return -1; 364 return 0;
366 } 365 }
367 if (fclose(pf->fp)) { 366 if (fclose(pf->fp)) {
368 WARN(("fclose returned non-zero value\n")); 367 DEBUG_WARN(("fclose returned non-zero value\n"));
369 DEBUG_RET(); 368 DEBUG_RET();
370 return -1; 369 return -1;
371 } 370 }
372 // we must free the id linklist and the desc tree 371 // we must free the id linklist and the desc tree
373 pst_free_id (pf->i_head); 372 pst_free_id (pf->i_head);
485 me->next = deep_copy(head->next); 484 me->next = deep_copy(head->next);
486 return me; 485 return me;
487 } 486 }
488 487
489 488
490 pst_desc_tree* pst_getTopOfFolders(pst_file *pf, pst_item *root) { 489 pst_desc_tree* pst_getTopOfFolders(pst_file *pf, const pst_item *root) {
491 pst_desc_tree *topnode; 490 pst_desc_tree *topnode;
492 uint32_t topid; 491 uint32_t topid;
493 DEBUG_ENT("pst_getTopOfFolders"); 492 DEBUG_ENT("pst_getTopOfFolders");
494 if (!root || !root->message_store) { 493 if (!root || !root->message_store) {
495 DEBUG_INDEX(("There isn't a top of folder record here.\n")); 494 DEBUG_INDEX(("There isn't a top of folder record here.\n"));
521 520
522 size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b) { 521 size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, char **b) {
523 pst_index_ll *ptr; 522 pst_index_ll *ptr;
524 pst_holder h = {b, NULL, 0}; 523 pst_holder h = {b, NULL, 0};
525 size_t size = 0; 524 size_t size = 0;
525 *b = NULL;
526 DEBUG_ENT("pst_attach_to_mem"); 526 DEBUG_ENT("pst_attach_to_mem");
527 if (attach->i_id != (uint64_t)-1) { 527 if ((!attach->data.data) && (attach->i_id != (uint64_t)-1)) {
528 ptr = pst_getID(pf, attach->i_id); 528 ptr = pst_getID(pf, attach->i_id);
529 if (ptr) { 529 if (ptr) {
530 size = pst_ff_getID2data(pf, ptr, &h); 530 size = pst_ff_getID2data(pf, ptr, &h);
531 } else { 531 } else {
532 DEBUG_WARN(("Couldn't find ID pointer. Cannot handle attachment\n")); 532 DEBUG_WARN(("Couldn't find ID pointer. Cannot handle attachment\n"));
533 } 533 *b = NULL;
534 attach->data.size = size; 534 }
535 } else { 535 } else {
536 size = attach->data.size; 536 size = attach->data.size;
537 *b = attach->data.data; 537 *b = attach->data.data;
538 attach->data.data = NULL; // prevent pst_free_item() from trying to free this
539 attach->data.size = 0; // since we have given that buffer to the caller
538 } 540 }
539 DEBUG_RET(); 541 DEBUG_RET();
540 return size; 542 return size;
541 } 543 }
542 544
544 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) { 546 size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) {
545 pst_index_ll *ptr; 547 pst_index_ll *ptr;
546 pst_holder h = {NULL, fp, 0}; 548 pst_holder h = {NULL, fp, 0};
547 size_t size = 0; 549 size_t size = 0;
548 DEBUG_ENT("pst_attach_to_file"); 550 DEBUG_ENT("pst_attach_to_file");
549 if (attach->i_id != (uint64_t)-1) { 551 if ((!attach->data.data) && (attach->i_id != (uint64_t)-1)) {
550 ptr = pst_getID(pf, attach->i_id); 552 ptr = pst_getID(pf, attach->i_id);
551 if (ptr) { 553 if (ptr) {
552 size = pst_ff_getID2data(pf, ptr, &h); 554 size = pst_ff_getID2data(pf, ptr, &h);
553 } else { 555 } else {
554 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n")); 556 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n"));
555 } 557 }
556 attach->data.size = size;
557 } else { 558 } else {
558 // save the attachment to the file
559 size = attach->data.size; 559 size = attach->data.size;
560 (void)pst_fwrite(attach->data.data, (size_t)1, size, fp); 560 if (attach->data.data && size) {
561 // save the attachment to the file
562 (void)pst_fwrite(attach->data.data, (size_t)1, size, fp);
563 }
561 } 564 }
562 DEBUG_RET(); 565 DEBUG_RET();
563 return size; 566 return size;
564 } 567 }
565 568
567 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) { 570 size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) {
568 pst_index_ll *ptr; 571 pst_index_ll *ptr;
569 pst_holder h = {NULL, fp, 1}; 572 pst_holder h = {NULL, fp, 1};
570 size_t size = 0; 573 size_t size = 0;
571 DEBUG_ENT("pst_attach_to_file_base64"); 574 DEBUG_ENT("pst_attach_to_file_base64");
572 if (attach->i_id != (uint64_t)-1) { 575 if ((!attach->data.data) && (attach->i_id != (uint64_t)-1)) {
573 ptr = pst_getID(pf, attach->i_id); 576 ptr = pst_getID(pf, attach->i_id);
574 if (ptr) { 577 if (ptr) {
575 size = pst_ff_getID2data(pf, ptr, &h); 578 size = pst_ff_getID2data(pf, ptr, &h);
576 } else { 579 } else {
577 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to Base64\n")); 580 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to Base64\n"));
578 } 581 }
579 attach->data.size = size;
580 } else { 582 } else {
581 // encode the attachment to the file
582 size = attach->data.size; 583 size = attach->data.size;
583 char *c = pst_base64_encode(attach->data.data, size); 584 if (attach->data.data && size) {
584 if (c) { 585 // encode the attachment to the file
585 (void)pst_fwrite(c, (size_t)1, strlen(c), fp); 586 char *c = pst_base64_encode(attach->data.data, size);
586 free(c); // caught by valgrind 587 if (c) {
588 (void)pst_fwrite(c, (size_t)1, strlen(c), fp);
589 free(c); // caught by valgrind
590 }
587 } 591 }
588 } 592 }
589 DEBUG_RET(); 593 DEBUG_RET();
590 return size; 594 return size;
591 } 595 }
593 597
594 int pst_load_index (pst_file *pf) { 598 int pst_load_index (pst_file *pf) {
595 int x; 599 int x;
596 DEBUG_ENT("pst_load_index"); 600 DEBUG_ENT("pst_load_index");
597 if (!pf) { 601 if (!pf) {
598 WARN(("Cannot load index for a NULL pst_file\n")); 602 DEBUG_WARN(("Cannot load index for a NULL pst_file\n"));
599 DEBUG_RET(); 603 DEBUG_RET();
600 return -1; 604 return -1;
601 } 605 }
602 606
603 x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX); 607 x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX);
1423 uint8_t slot; 1427 uint8_t slot;
1424 } table2_rec; //for type 2 (0x7CEC) blocks 1428 } table2_rec; //for type 2 (0x7CEC) blocks
1425 1429
1426 DEBUG_ENT("pst_parse_block"); 1430 DEBUG_ENT("pst_parse_block");
1427 if ((read_size = pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) { 1431 if ((read_size = pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) {
1428 WARN(("Error reading block id %#"PRIx64"\n", block_id)); 1432 DEBUG_WARN(("Error reading block id %#"PRIx64"\n", block_id));
1429 if (buf) free (buf); 1433 if (buf) free (buf);
1430 DEBUG_RET(); 1434 DEBUG_RET();
1431 return NULL; 1435 return NULL;
1432 } 1436 }
1433 1437
1494 LE16_CPU(table_rec.ref_type); 1498 LE16_CPU(table_rec.ref_type);
1495 LE32_CPU(table_rec.value); 1499 LE32_CPU(table_rec.value);
1496 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); 1500 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
1497 1501
1498 if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) { 1502 if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) {
1499 WARN(("Unknown second block constant - %#hx %#hx for id %#"PRIx64"\n", table_rec.type, table_rec.ref_type, block_id)); 1503 DEBUG_WARN(("Unknown second block constant - %#hx %#hx for id %#"PRIx64"\n", table_rec.type, table_rec.ref_type, block_id));
1500 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1504 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1501 DEBUG_RET(); 1505 DEBUG_RET();
1502 return NULL; 1506 return NULL;
1503 } 1507 }
1504 1508
1535 LE16_CPU(seven_c_blk.u8); 1539 LE16_CPU(seven_c_blk.u8);
1536 1540
1537 list_start = fr_ptr + sizeof(seven_c_blk); // the list of item numbers start after this record 1541 list_start = fr_ptr + sizeof(seven_c_blk); // the list of item numbers start after this record
1538 1542
1539 if (seven_c_blk.seven_c != 0x7C) { // this would mean it isn't a 7C block! 1543 if (seven_c_blk.seven_c != 0x7C) { // this would mean it isn't a 7C block!
1540 WARN(("Error. There isn't a 7C where I want to see 7C!\n")); 1544 DEBUG_WARN(("Error. There isn't a 7C where I want to see 7C!\n"));
1541 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1545 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1542 DEBUG_RET(); 1546 DEBUG_RET();
1543 return NULL; 1547 return NULL;
1544 } 1548 }
1545 1549
1557 LE16_CPU(table_rec.ref_type); 1561 LE16_CPU(table_rec.ref_type);
1558 LE32_CPU(table_rec.value); 1562 LE32_CPU(table_rec.value);
1559 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); 1563 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
1560 1564
1561 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record 1565 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record
1562 WARN(("Unknown second block constant - %#hx for id %#"PRIx64"\n", table_rec.type, block_id)); 1566 DEBUG_WARN(("Unknown second block constant - %#hx for id %#"PRIx64"\n", table_rec.type, block_id));
1563 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1567 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1564 DEBUG_RET(); 1568 DEBUG_RET();
1565 return NULL; 1569 return NULL;
1566 } 1570 }
1567 1571
1583 } 1587 }
1584 ind2_ptr = block_offset6.from; 1588 ind2_ptr = block_offset6.from;
1585 ind2_end = block_offset6.to; 1589 ind2_end = block_offset6.to;
1586 } 1590 }
1587 else { 1591 else {
1588 WARN(("ERROR: Unknown block constant - %#hx for id %#"PRIx64"\n", block_hdr.type, block_id)); 1592 DEBUG_WARN(("ERROR: Unknown block constant - %#hx for id %#"PRIx64"\n", block_hdr.type, block_id));
1589 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1593 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1590 DEBUG_RET(); 1594 DEBUG_RET();
1591 return NULL; 1595 return NULL;
1592 } 1596 }
1593 1597
1644 DEBUG_WARN (("Trying to read outside buffer, buffer size %#x, offset %#x, data size %#x\n", 1648 DEBUG_WARN (("Trying to read outside buffer, buffer size %#x, offset %#x, data size %#x\n",
1645 read_size, ind2_end-ind2_ptr+table2_rec.ind2_off, table2_rec.size)); 1649 read_size, ind2_end-ind2_ptr+table2_rec.ind2_off, table2_rec.size));
1646 } 1650 }
1647 fr_ptr += sizeof(table2_rec); 1651 fr_ptr += sizeof(table2_rec);
1648 } else { 1652 } else {
1649 WARN(("Missing code for block_type %i\n", block_type)); 1653 DEBUG_WARN(("Missing code for block_type %i\n", block_type));
1650 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1654 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1651 pst_free_list(mo_head); 1655 pst_free_list(mo_head);
1652 DEBUG_RET(); 1656 DEBUG_RET();
1653 return NULL; 1657 return NULL;
1654 } 1658 }
1784 pst_vbappend(utf16buf, "\0\0", (size_t)2); 1788 pst_vbappend(utf16buf, "\0\0", (size_t)2);
1785 DEBUG_INDEX(("Iconv in:\n")); 1789 DEBUG_INDEX(("Iconv in:\n"));
1786 DEBUG_HEXDUMPC(utf16buf->b, utf16buf->dlen, 0x10); 1790 DEBUG_HEXDUMPC(utf16buf->b, utf16buf->dlen, 0x10);
1787 rc = pst_vb_utf16to8(utf8buf, utf16buf->b, utf16buf->dlen); 1791 rc = pst_vb_utf16to8(utf8buf, utf16buf->b, utf16buf->dlen);
1788 if (rc == (size_t)-1) { 1792 if (rc == (size_t)-1) {
1789 DEBUG_EMAIL(("Failed to convert utf-16 to utf-8\n")); 1793 DEBUG_WARN(("Failed to convert utf-16 to utf-8\n"));
1790 } 1794 }
1791 else { 1795 else {
1792 free(mo_ptr->elements[x]->data); 1796 free(mo_ptr->elements[x]->data);
1793 mo_ptr->elements[x]->size = utf8buf->dlen; 1797 mo_ptr->elements[x]->size = utf8buf->dlen;
1794 mo_ptr->elements[x]->data = pst_malloc(utf8buf->dlen); 1798 mo_ptr->elements[x]->data = pst_malloc(utf8buf->dlen);
1797 DEBUG_INDEX(("Iconv out:\n")); 1801 DEBUG_INDEX(("Iconv out:\n"));
1798 DEBUG_HEXDUMPC(mo_ptr->elements[x]->data, mo_ptr->elements[x]->size, 0x10); 1802 DEBUG_HEXDUMPC(mo_ptr->elements[x]->data, mo_ptr->elements[x]->size, 0x10);
1799 } 1803 }
1800 if (mo_ptr->elements[x]->type == 0) mo_ptr->elements[x]->type = table_rec.ref_type; 1804 if (mo_ptr->elements[x]->type == 0) mo_ptr->elements[x]->type = table_rec.ref_type;
1801 } else { 1805 } else {
1802 WARN(("ERROR Unknown ref_type %#hx\n", table_rec.ref_type)); 1806 DEBUG_WARN(("ERROR Unknown ref_type %#hx\n", table_rec.ref_type));
1803 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1807 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1804 pst_free_list(mo_head); 1808 pst_free_list(mo_head);
1805 DEBUG_RET(); 1809 DEBUG_RET();
1806 return NULL; 1810 return NULL;
1807 } 1811 }
1841 (list->elements[x]->type == 0x1e) || \ 1845 (list->elements[x]->type == 0x1e) || \
1842 (list->elements[x]->type == 0x102)) { \ 1846 (list->elements[x]->type == 0x102)) { \
1843 LIST_COPY(targ, (char*)) \ 1847 LIST_COPY(targ, (char*)) \
1844 } \ 1848 } \
1845 else { \ 1849 else { \
1846 DEBUG_EMAIL(("src not 0x1e or 0x1f or 0x102 for string dst\n")); \ 1850 DEBUG_WARN(("src not 0x1e or 0x1f or 0x102 for string dst\n")); \
1847 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 1851 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
1848 SAFE_FREE(targ); \ 1852 SAFE_FREE(targ); \
1849 targ = NULL; \ 1853 targ = NULL; \
1850 } \ 1854 } \
1851 } 1855 }
1852 1856
1853 #define LIST_COPY_BOOL(label, targ) { \ 1857 #define LIST_COPY_BOOL(label, targ) { \
1854 if (list->elements[x]->type != 0x0b) { \ 1858 if (list->elements[x]->type != 0x0b) { \
1855 DEBUG_EMAIL(("src not 0x0b for boolean dst\n")); \ 1859 DEBUG_WARN(("src not 0x0b for boolean dst\n")); \
1856 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 1860 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
1857 } \ 1861 } \
1858 if (*(int16_t*)list->elements[x]->data) { \ 1862 if (*(int16_t*)list->elements[x]->data) { \
1859 DEBUG_EMAIL((label" - True\n")); \ 1863 DEBUG_EMAIL((label" - True\n")); \
1860 targ = 1; \ 1864 targ = 1; \
1879 LIST_COPY_BOOL(label, targ) \ 1883 LIST_COPY_BOOL(label, targ) \
1880 } 1884 }
1881 1885
1882 #define LIST_COPY_INT16_N(targ) { \ 1886 #define LIST_COPY_INT16_N(targ) { \
1883 if (list->elements[x]->type != 0x02) { \ 1887 if (list->elements[x]->type != 0x02) { \
1884 DEBUG_EMAIL(("src not 0x02 for int16 dst\n")); \ 1888 DEBUG_WARN(("src not 0x02 for int16 dst\n")); \
1885 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 1889 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
1886 } \ 1890 } \
1887 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ 1891 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \
1888 LE16_CPU(targ); \ 1892 LE16_CPU(targ); \
1889 } 1893 }
1893 DEBUG_EMAIL((label" - %i %#x\n", (int)targ, (int)targ)); \ 1897 DEBUG_EMAIL((label" - %i %#x\n", (int)targ, (int)targ)); \
1894 } 1898 }
1895 1899
1896 #define LIST_COPY_INT32_N(targ) { \ 1900 #define LIST_COPY_INT32_N(targ) { \
1897 if (list->elements[x]->type != 0x03) { \ 1901 if (list->elements[x]->type != 0x03) { \
1898 DEBUG_EMAIL(("src not 0x03 for int32 dst\n")); \ 1902 DEBUG_WARN(("src not 0x03 for int32 dst\n")); \
1899 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 1903 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
1900 } \ 1904 } \
1901 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ 1905 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \
1902 LE32_CPU(targ); \ 1906 LE32_CPU(targ); \
1903 } 1907 }
2009 } 2013 }
2010 2014
2011 // malloc space and copy the item filetime 2015 // malloc space and copy the item filetime
2012 #define LIST_COPY_TIME(label, targ) { \ 2016 #define LIST_COPY_TIME(label, targ) { \
2013 if (list->elements[x]->type != 0x40) { \ 2017 if (list->elements[x]->type != 0x40) { \
2014 DEBUG_EMAIL(("src not 0x40 for filetime dst\n")); \ 2018 DEBUG_WARN(("src not 0x40 for filetime dst\n")); \
2015 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 2019 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
2016 } \ 2020 } \
2017 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \ 2021 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \
2018 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \ 2022 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \
2019 LE32_CPU(targ->dwLowDateTime); \ 2023 LE32_CPU(targ->dwLowDateTime); \
2058 MALLOC_EMAIL(item); \ 2062 MALLOC_EMAIL(item); \
2059 LIST_COPY_BIN(targ); \ 2063 LIST_COPY_BIN(targ); \
2060 DEBUG_EMAIL((label"\n")); \ 2064 DEBUG_EMAIL((label"\n")); \
2061 } 2065 }
2062 2066
2063 #define NULL_CHECK(x) { if (!x) { DEBUG_EMAIL(("NULL_CHECK: Null Found\n")); break;} } 2067 #define NULL_CHECK(x) { if (!x) { DEBUG_WARN(("NULL_CHECK: Null Found\n")); break;} }
2064 2068
2065 2069
2066 /** 2070 /**
2067 * process the list of MAPI objects produced from parse_block() 2071 * process the list of MAPI objects produced from parse_block()
2068 * 2072 *
2118 } 2122 }
2119 } 2123 }
2120 } 2124 }
2121 } 2125 }
2122 else { 2126 else {
2123 DEBUG_EMAIL(("What does this mean? Internet header %s value\n", list->elements[x]->extra)); 2127 DEBUG_WARN(("What does this mean? Internet header %s value\n", list->elements[x]->extra));
2124 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 2128 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
2125 free(ef); // caught by valgrind 2129 free(ef); // caught by valgrind
2126 } 2130 }
2127 } 2131 }
2128 break; 2132 break;
2130 if (list->elements[x]->type == 0x0b) { 2134 if (list->elements[x]->type == 0x0b) {
2131 // If set to true, the sender allows this email to be autoforwarded 2135 // If set to true, the sender allows this email to be autoforwarded
2132 LIST_COPY_EMAIL_BOOL("AutoForward allowed", item->email->autoforward); 2136 LIST_COPY_EMAIL_BOOL("AutoForward allowed", item->email->autoforward);
2133 if (!item->email->autoforward) item->email->autoforward = -1; 2137 if (!item->email->autoforward) item->email->autoforward = -1;
2134 } else { 2138 } else {
2135 DEBUG_EMAIL(("What does this mean?\n")); 2139 DEBUG_WARN(("What does this mean?\n"));
2136 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 2140 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
2137 } 2141 }
2138 break; 2142 break;
2139 case 0x0003: // Extended Attributes table 2143 case 0x0003: // Extended Attributes table
2140 DEBUG_EMAIL(("Extended Attributes Table - NOT PROCESSED\n")); 2144 DEBUG_EMAIL(("Extended Attributes Table - NOT PROCESSED\n"));
2171 else 2175 else
2172 item->type = PST_TYPE_OTHER; 2176 item->type = PST_TYPE_OTHER;
2173 DEBUG_EMAIL(("Message class %s [%"PRIi32"] \n", item->ascii_type, item->type)); 2177 DEBUG_EMAIL(("Message class %s [%"PRIi32"] \n", item->ascii_type, item->type));
2174 } 2178 }
2175 else { 2179 else {
2176 DEBUG_EMAIL(("What does this mean?\n")); 2180 DEBUG_WARN(("What does this mean?\n"));
2177 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 2181 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
2178 } 2182 }
2179 break; 2183 break;
2180 case 0x0023: // PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED 2184 case 0x0023: // PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED
2181 if (list->elements[x]->type == 0x0b) { 2185 if (list->elements[x]->type == 0x0b) {
2182 // set if the sender wants a delivery report from all recipients 2186 // set if the sender wants a delivery report from all recipients
2183 LIST_COPY_EMAIL_BOOL("Global Delivery Report", item->email->delivery_report); 2187 LIST_COPY_EMAIL_BOOL("Global Delivery Report", item->email->delivery_report);
2184 } 2188 }
2185 else { 2189 else {
2186 DEBUG_EMAIL(("What does this mean?\n")); 2190 DEBUG_WARN(("What does this mean?\n"));
2187 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 2191 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
2188 } 2192 }
2189 break; 2193 break;
2190 case 0x0026: // PR_PRIORITY 2194 case 0x0026: // PR_PRIORITY
2191 LIST_COPY_EMAIL_ENUM("Priority", item->email->priority, 1, 3, "NonUrgent", "Normal", "Urgent"); 2195 LIST_COPY_EMAIL_ENUM("Priority", item->email->priority, 1, 3, "NonUrgent", "Normal", "Urgent");
2225 break; 2229 break;
2226 case 0x003B: // PR_SENT_REPRESENTING_SEARCH_KEY Sender address 1 2230 case 0x003B: // PR_SENT_REPRESENTING_SEARCH_KEY Sender address 1
2227 LIST_COPY_EMAIL_STR("Sent on behalf of address 1", item->email->outlook_sender); 2231 LIST_COPY_EMAIL_STR("Sent on behalf of address 1", item->email->outlook_sender);
2228 break; 2232 break;
2229 case 0x003F: // PR_RECEIVED_BY_ENTRYID Structure containing Recipient 2233 case 0x003F: // PR_RECEIVED_BY_ENTRYID Structure containing Recipient
2230 DEBUG_EMAIL(("Recipient Structure 1 -- NOT HANDLED\n")); 2234 DEBUG_EMAIL(("Recipient Structure 1 -- NOT PROCESSED\n"));
2231 break; 2235 break;
2232 case 0x0040: // PR_RECEIVED_BY_NAME Name of Recipient Structure 2236 case 0x0040: // PR_RECEIVED_BY_NAME Name of Recipient Structure
2233 DEBUG_EMAIL(("Received By Name 1 -- NOT HANDLED\n")); 2237 DEBUG_EMAIL(("Received By Name 1 -- NOT PROCESSED\n"));
2234 break; 2238 break;
2235 case 0x0041: // PR_SENT_REPRESENTING_ENTRYID Structure containing Sender 2239 case 0x0041: // PR_SENT_REPRESENTING_ENTRYID Structure containing Sender
2236 DEBUG_EMAIL(("Sent on behalf of Structure 1 -- NOT HANDLED\n")); 2240 DEBUG_EMAIL(("Sent on behalf of Structure 1 -- NOT PROCESSED\n"));
2237 break; 2241 break;
2238 case 0x0042: // PR_SENT_REPRESENTING_NAME 2242 case 0x0042: // PR_SENT_REPRESENTING_NAME
2239 LIST_COPY_EMAIL_STR("Sent on behalf of", item->email->outlook_sender_name); 2243 LIST_COPY_EMAIL_STR("Sent on behalf of", item->email->outlook_sender_name);
2240 break; 2244 break;
2241 case 0x0043: // PR_RCVD_REPRESENTING_ENTRYID Recipient Structure 2 2245 case 0x0043: // PR_RCVD_REPRESENTING_ENTRYID Recipient Structure 2
2242 DEBUG_EMAIL(("Received on behalf of Structure -- NOT HANDLED\n")); 2246 DEBUG_EMAIL(("Received on behalf of Structure -- NOT PROCESSED\n"));
2243 break; 2247 break;
2244 case 0x0044: // PR_RCVD_REPRESENTING_NAME 2248 case 0x0044: // PR_RCVD_REPRESENTING_NAME
2245 LIST_COPY_EMAIL_STR("Received on behalf of", item->email->outlook_recipient_name); 2249 LIST_COPY_EMAIL_STR("Received on behalf of", item->email->outlook_recipient_name);
2246 break; 2250 break;
2247 case 0x004F: // PR_REPLY_RECIPIENT_ENTRIES Reply-To Structure 2251 case 0x004F: // PR_REPLY_RECIPIENT_ENTRIES Reply-To Structure
2248 DEBUG_EMAIL(("Reply-To Structure -- NOT HANDLED\n")); 2252 DEBUG_EMAIL(("Reply-To Structure -- NOT PROCESSED\n"));
2249 break; 2253 break;
2250 case 0x0050: // PR_REPLY_RECIPIENT_NAMES Name of Reply-To Structure 2254 case 0x0050: // PR_REPLY_RECIPIENT_NAMES Name of Reply-To Structure
2251 LIST_COPY_EMAIL_STR("Reply-To", item->email->reply_to); 2255 LIST_COPY_EMAIL_STR("Reply-To", item->email->reply_to);
2252 break; 2256 break;
2253 case 0x0051: // PR_RECEIVED_BY_SEARCH_KEY Recipient Address 1 2257 case 0x0051: // PR_RECEIVED_BY_SEARCH_KEY Recipient Address 1
2312 break; 2316 break;
2313 case 0x0C05: // PR_NDR_DIAG_CODE 2317 case 0x0C05: // PR_NDR_DIAG_CODE
2314 LIST_COPY_EMAIL_INT32("NDR diag code", item->email->ndr_diag_code); 2318 LIST_COPY_EMAIL_INT32("NDR diag code", item->email->ndr_diag_code);
2315 break; 2319 break;
2316 case 0x0C06: // PR_NON_RECEIPT_NOTIFICATION_REQUESTED 2320 case 0x0C06: // PR_NON_RECEIPT_NOTIFICATION_REQUESTED
2317 DEBUG_EMAIL(("Non-Receipt Notification Requested - (ignored) - ")); 2321 DEBUG_EMAIL(("Non-Receipt Notification Requested -- NOT PROCESSED\n"));
2318 break; 2322 break;
2319 case 0x0C17: // PR_REPLY_REQUESTED 2323 case 0x0C17: // PR_REPLY_REQUESTED
2320 LIST_COPY_EMAIL_BOOL("Reply Requested", item->email->reply_requested); 2324 LIST_COPY_EMAIL_BOOL("Reply Requested", item->email->reply_requested);
2321 break; 2325 break;
2322 case 0x0C19: // PR_SENDER_ENTRYID Sender Structure 2 2326 case 0x0C19: // PR_SENDER_ENTRYID Sender Structure 2
2323 DEBUG_EMAIL(("Sender Structure 2 -- NOT HANDLED\n")); 2327 DEBUG_EMAIL(("Sender Structure 2 -- NOT PROCESSED\n"));
2324 break; 2328 break;
2325 case 0x0C1A: // PR_SENDER_NAME Name of Sender Structure 2 2329 case 0x0C1A: // PR_SENDER_NAME Name of Sender Structure 2
2326 DEBUG_EMAIL(("Name of Sender Structure 2 -- NOT HANDLED\n")); 2330 DEBUG_EMAIL(("Name of Sender Structure 2 -- NOT PROCESSED\n"));
2327 break; 2331 break;
2328 case 0x0C1B: // PR_SUPPLEMENTARY_INFO 2332 case 0x0C1B: // PR_SUPPLEMENTARY_INFO
2329 LIST_COPY_EMAIL_STR("Supplementary info", item->email->supplementary_info); 2333 LIST_COPY_EMAIL_STR("Supplementary info", item->email->supplementary_info);
2330 break; 2334 break;
2331 case 0x0C1D: // PR_SENDER_SEARCH_KEY Name of Sender Address 2 2335 case 0x0C1D: // PR_SENDER_SEARCH_KEY Name of Sender Address 2
2441 break; 2445 break;
2442 case 0x3008: // PR_LAST_MODIFICATION_TIME Date 5 - Modify Date 2446 case 0x3008: // PR_LAST_MODIFICATION_TIME Date 5 - Modify Date
2443 LIST_COPY_TIME("Date 5 (Modify Date)", item->modify_date); 2447 LIST_COPY_TIME("Date 5 (Modify Date)", item->modify_date);
2444 break; 2448 break;
2445 case 0x300B: // PR_SEARCH_KEY Record Header 2 2449 case 0x300B: // PR_SEARCH_KEY Record Header 2
2446 DEBUG_EMAIL(("Record Search 2 -- NOT HANDLED\n")); 2450 DEBUG_EMAIL(("Record Search 2 -- NOT PROCESSED\n"));
2447 break; 2451 break;
2448 case 0x35DF: // PR_VALID_FOLDER_MASK 2452 case 0x35DF: // PR_VALID_FOLDER_MASK
2449 LIST_COPY_STORE_INT32("Valid Folder Mask", item->message_store->valid_mask); 2453 LIST_COPY_STORE_INT32("Valid Folder Mask", item->message_store->valid_mask);
2450 break; 2454 break;
2451 case 0x35E0: // PR_IPM_SUBTREE_ENTRYID Top of Personal Folder Record 2455 case 0x35E0: // PR_IPM_SUBTREE_ENTRYID Top of Personal Folder Record
2646 break; 2650 break;
2647 case 0x3A21: // PR_PAGER_TELEPHONE_NUMBER 2651 case 0x3A21: // PR_PAGER_TELEPHONE_NUMBER
2648 LIST_COPY_CONTACT_STR("Pager Phone Number", item->contact->pager_phone); 2652 LIST_COPY_CONTACT_STR("Pager Phone Number", item->contact->pager_phone);
2649 break; 2653 break;
2650 case 0x3A22: // PR_USER_CERTIFICATE 2654 case 0x3A22: // PR_USER_CERTIFICATE
2651 DEBUG_EMAIL(("User Certificate - NOT PROCESSED")); 2655 DEBUG_EMAIL(("User Certificate - NOT PROCESSED\n"));
2652 break; 2656 break;
2653 case 0x3A23: // PR_PRIMARY_FAX_NUMBER 2657 case 0x3A23: // PR_PRIMARY_FAX_NUMBER
2654 LIST_COPY_CONTACT_STR("Primary Fax Number", item->contact->primary_fax); 2658 LIST_COPY_CONTACT_STR("Primary Fax Number", item->contact->primary_fax);
2655 break; 2659 break;
2656 case 0x3A24: // PR_BUSINESS_FAX_NUMBER 2660 case 0x3A24: // PR_BUSINESS_FAX_NUMBER
2806 memcpy(&(tempid), list->elements[x]->data, sizeof(tempid)); 2810 memcpy(&(tempid), list->elements[x]->data, sizeof(tempid));
2807 LE32_CPU(tempid); 2811 LE32_CPU(tempid);
2808 attach->id2_val = tempid; 2812 attach->id2_val = tempid;
2809 DEBUG_EMAIL(("%#"PRIx64"\n", attach->id2_val)); 2813 DEBUG_EMAIL(("%#"PRIx64"\n", attach->id2_val));
2810 } else { 2814 } else {
2811 DEBUG_EMAIL(("NOT AN ATTACHMENT: %#x\n", list->elements[x]->mapi_id)); 2815 DEBUG_WARN(("NOT AN ATTACHMENT: %#x\n", list->elements[x]->mapi_id));
2812 } 2816 }
2813 break; 2817 break;
2814 case 0x67FF: // Extra Property Identifier (Password CheckSum) 2818 case 0x67FF: // Extra Property Identifier (Password CheckSum)
2815 LIST_COPY_STORE_INT32("Password checksum", item->message_store->pwd_chksum); 2819 LIST_COPY_STORE_INT32("Password checksum", item->message_store->pwd_chksum);
2816 break; 2820 break;
2984 case 0x8712: // Journal Type Description 2988 case 0x8712: // Journal Type Description
2985 LIST_COPY_JOURNAL_STR("Journal description", item->journal->description); 2989 LIST_COPY_JOURNAL_STR("Journal description", item->journal->description);
2986 break; 2990 break;
2987 default: 2991 default:
2988 if (list->elements[x]->type == (uint32_t)0x0002) { 2992 if (list->elements[x]->type == (uint32_t)0x0002) {
2989 DEBUG_EMAIL(("Unknown type %#x 16bit int = %hi\n", list->elements[x]->mapi_id, 2993 DEBUG_WARN(("Unknown type %#x 16bit int = %hi\n", list->elements[x]->mapi_id,
2990 *(int16_t*)list->elements[x]->data)); 2994 *(int16_t*)list->elements[x]->data));
2991 2995
2992 } else if (list->elements[x]->type == (uint32_t)0x0003) { 2996 } else if (list->elements[x]->type == (uint32_t)0x0003) {
2993 DEBUG_EMAIL(("Unknown type %#x 32bit int = %i\n", list->elements[x]->mapi_id, 2997 DEBUG_WARN(("Unknown type %#x 32bit int = %i\n", list->elements[x]->mapi_id,
2994 *(int32_t*)list->elements[x]->data)); 2998 *(int32_t*)list->elements[x]->data));
2995 2999
2996 } else if (list->elements[x]->type == (uint32_t)0x0004) { 3000 } else if (list->elements[x]->type == (uint32_t)0x0004) {
2997 DEBUG_EMAIL(("Unknown type %#x 4-byte floating [size = %#x]\n", list->elements[x]->mapi_id, 3001 DEBUG_WARN(("Unknown type %#x 4-byte floating [size = %#x]\n", list->elements[x]->mapi_id,
2998 list->elements[x]->size)); 3002 list->elements[x]->size));
2999 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3003 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3000 3004
3001 } else if (list->elements[x]->type == (uint32_t)0x0005) { 3005 } else if (list->elements[x]->type == (uint32_t)0x0005) {
3002 DEBUG_EMAIL(("Unknown type %#x double floating [size = %#x]\n", list->elements[x]->mapi_id, 3006 DEBUG_WARN(("Unknown type %#x double floating [size = %#x]\n", list->elements[x]->mapi_id,
3003 list->elements[x]->size)); 3007 list->elements[x]->size));
3004 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3008 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3005 3009
3006 } else if (list->elements[x]->type == (uint32_t)0x0006) { 3010 } else if (list->elements[x]->type == (uint32_t)0x0006) {
3007 DEBUG_EMAIL(("Unknown type %#x signed 64bit int = %"PRIi64"\n", list->elements[x]->mapi_id, 3011 DEBUG_WARN(("Unknown type %#x signed 64bit int = %"PRIi64"\n", list->elements[x]->mapi_id,
3008 *(int64_t*)list->elements[x]->data)); 3012 *(int64_t*)list->elements[x]->data));
3009 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3013 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3010 3014
3011 } else if (list->elements[x]->type == (uint32_t)0x0007) { 3015 } else if (list->elements[x]->type == (uint32_t)0x0007) {
3012 DEBUG_EMAIL(("Unknown type %#x application time [size = %#x]\n", list->elements[x]->mapi_id, 3016 DEBUG_WARN(("Unknown type %#x application time [size = %#x]\n", list->elements[x]->mapi_id,
3013 list->elements[x]->size)); 3017 list->elements[x]->size));
3014 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3018 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3015 3019
3016 } else if (list->elements[x]->type == (uint32_t)0x000a) { 3020 } else if (list->elements[x]->type == (uint32_t)0x000a) {
3017 DEBUG_EMAIL(("Unknown type %#x 32bit error value = %i\n", list->elements[x]->mapi_id, 3021 DEBUG_WARN(("Unknown type %#x 32bit error value = %i\n", list->elements[x]->mapi_id,
3018 *(int32_t*)list->elements[x]->data)); 3022 *(int32_t*)list->elements[x]->data));
3019 3023
3020 } else if (list->elements[x]->type == (uint32_t)0x000b) { 3024 } else if (list->elements[x]->type == (uint32_t)0x000b) {
3021 DEBUG_EMAIL(("Unknown type %#x 16bit boolean = %s [%hi]\n", list->elements[x]->mapi_id, 3025 DEBUG_WARN(("Unknown type %#x 16bit boolean = %s [%hi]\n", list->elements[x]->mapi_id,
3022 (*((int16_t*)list->elements[x]->data)!=0?"True":"False"), 3026 (*((int16_t*)list->elements[x]->data)!=0?"True":"False"),
3023 *((int16_t*)list->elements[x]->data))); 3027 *((int16_t*)list->elements[x]->data)));
3024 3028
3025 } else if (list->elements[x]->type == (uint32_t)0x000d) { 3029 } else if (list->elements[x]->type == (uint32_t)0x000d) {
3026 DEBUG_EMAIL(("Unknown type %#x Embedded object [size = %#x]\n", list->elements[x]->mapi_id, 3030 DEBUG_WARN(("Unknown type %#x Embedded object [size = %#x]\n", list->elements[x]->mapi_id,
3027 list->elements[x]->size)); 3031 list->elements[x]->size));
3028 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3032 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3029 3033
3030 } else if (list->elements[x]->type == (uint32_t)0x0014) { 3034 } else if (list->elements[x]->type == (uint32_t)0x0014) {
3031 DEBUG_EMAIL(("Unknown type %#x signed 64bit int = %"PRIi64"\n", list->elements[x]->mapi_id, 3035 DEBUG_WARN(("Unknown type %#x signed 64bit int = %"PRIi64"\n", list->elements[x]->mapi_id,
3032 *(int64_t*)list->elements[x]->data)); 3036 *(int64_t*)list->elements[x]->data));
3033 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3037 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3034 3038
3035 } else if (list->elements[x]->type == (uint32_t)0x001e) { 3039 } else if (list->elements[x]->type == (uint32_t)0x001e) {
3036 DEBUG_EMAIL(("Unknown type %#x String Data = \"%s\"\n", list->elements[x]->mapi_id, 3040 DEBUG_WARN(("Unknown type %#x String Data = \"%s\"\n", list->elements[x]->mapi_id,
3037 list->elements[x]->data)); 3041 list->elements[x]->data));
3038 3042
3039 } else if (list->elements[x]->type == (uint32_t)0x001f) { 3043 } else if (list->elements[x]->type == (uint32_t)0x001f) {
3040 DEBUG_EMAIL(("Unknown type %#x Unicode String Data [size = %#x]\n", list->elements[x]->mapi_id, 3044 DEBUG_WARN(("Unknown type %#x Unicode String Data [size = %#x]\n", list->elements[x]->mapi_id,
3041 list->elements[x]->size)); 3045 list->elements[x]->size));
3042 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3046 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3043 3047
3044 } else if (list->elements[x]->type == (uint32_t)0x0040) { 3048 } else if (list->elements[x]->type == (uint32_t)0x0040) {
3045 DEBUG_EMAIL(("Unknown type %#x Date = \"%s\"\n", list->elements[x]->mapi_id, 3049 DEBUG_WARN(("Unknown type %#x Date = \"%s\"\n", list->elements[x]->mapi_id,
3046 pst_fileTimeToAscii((FILETIME*)list->elements[x]->data))); 3050 pst_fileTimeToAscii((FILETIME*)list->elements[x]->data)));
3047 3051
3048 } else if (list->elements[x]->type == (uint32_t)0x0048) { 3052 } else if (list->elements[x]->type == (uint32_t)0x0048) {
3049 DEBUG_EMAIL(("Unknown type %#x OLE GUID [size = %#x]\n", list->elements[x]->mapi_id, 3053 DEBUG_WARN(("Unknown type %#x OLE GUID [size = %#x]\n", list->elements[x]->mapi_id,
3050 list->elements[x]->size)); 3054 list->elements[x]->size));
3051 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3055 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3052 3056
3053 } else if (list->elements[x]->type == (uint32_t)0x0102) { 3057 } else if (list->elements[x]->type == (uint32_t)0x0102) {
3054 DEBUG_EMAIL(("Unknown type %#x Binary Data [size = %#x]\n", list->elements[x]->mapi_id, 3058 DEBUG_WARN(("Unknown type %#x Binary Data [size = %#x]\n", list->elements[x]->mapi_id,
3055 list->elements[x]->size)); 3059 list->elements[x]->size));
3056 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3060 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3057 3061
3058 } else if (list->elements[x]->type == (uint32_t)0x1003) { 3062 } else if (list->elements[x]->type == (uint32_t)0x1003) {
3059 DEBUG_EMAIL(("Unknown type %#x Array of 32 bit values [size = %#x]\n", list->elements[x]->mapi_id, 3063 DEBUG_WARN(("Unknown type %#x Array of 32 bit values [size = %#x]\n", list->elements[x]->mapi_id,
3060 list->elements[x]->size)); 3064 list->elements[x]->size));
3061 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3065 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3062 3066
3063 } else if (list->elements[x]->type == (uint32_t)0x1014) { 3067 } else if (list->elements[x]->type == (uint32_t)0x1014) {
3064 DEBUG_EMAIL(("Unknown type %#x Array of 64 bit values [siize = %#x]\n", list->elements[x]->mapi_id, 3068 DEBUG_WARN(("Unknown type %#x Array of 64 bit values [siize = %#x]\n", list->elements[x]->mapi_id,
3065 list->elements[x]->size)); 3069 list->elements[x]->size));
3066 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3070 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3067 3071
3068 } else if (list->elements[x]->type == (uint32_t)0x101e) { 3072 } else if (list->elements[x]->type == (uint32_t)0x101e) {
3069 DEBUG_EMAIL(("Unknown type %#x Array of Strings [size = %#x]\n", list->elements[x]->mapi_id, 3073 DEBUG_WARN(("Unknown type %#x Array of Strings [size = %#x]\n", list->elements[x]->mapi_id,
3070 list->elements[x]->size)); 3074 list->elements[x]->size));
3071 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3075 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3072 3076
3073 } else if (list->elements[x]->type == (uint32_t)0x101f) { 3077 } else if (list->elements[x]->type == (uint32_t)0x101f) {
3074 DEBUG_EMAIL(("Unknown type %#x Array of Unicode Strings [size = %#x]\n", list->elements[x]->mapi_id, 3078 DEBUG_WARN(("Unknown type %#x Array of Unicode Strings [size = %#x]\n", list->elements[x]->mapi_id,
3075 list->elements[x]->size)); 3079 list->elements[x]->size));
3076 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3080 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3077 3081
3078 } else if (list->elements[x]->type == (uint32_t)0x1102) { 3082 } else if (list->elements[x]->type == (uint32_t)0x1102) {
3079 DEBUG_EMAIL(("Unknown type %#x Array of binary data blobs [size = %#x]\n", list->elements[x]->mapi_id, 3083 DEBUG_WARN(("Unknown type %#x Array of binary data blobs [size = %#x]\n", list->elements[x]->mapi_id,
3080 list->elements[x]->size)); 3084 list->elements[x]->size));
3081 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3085 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3082 3086
3083 } else { 3087 } else {
3084 DEBUG_EMAIL(("Unknown type %#x Not Printable [%#x]\n", list->elements[x]->mapi_id, 3088 DEBUG_WARN(("Unknown type %#x Not Printable [%#x]\n", list->elements[x]->mapi_id,
3085 list->elements[x]->type)); 3089 list->elements[x]->type));
3086 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); 3090 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);
3087 } 3091 }
3088 3092
3089 if (list->elements[x]->data) { 3093 if (list->elements[x]->data) {
3195 pst_id2_tree *i2_ptr = NULL; 3199 pst_id2_tree *i2_ptr = NULL;
3196 DEBUG_ENT("pst_build_id2"); 3200 DEBUG_ENT("pst_build_id2");
3197 3201
3198 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) { 3202 if (pst_read_block_size(pf, list->offset, list->size, &buf) < list->size) {
3199 //an error occured in block read 3203 //an error occured in block read
3200 WARN(("block read error occured. offset = %#"PRIx64", size = %#"PRIx64"\n", list->offset, list->size)); 3204 DEBUG_WARN(("block read error occured. offset = %#"PRIx64", size = %#"PRIx64"\n", list->offset, list->size));
3201 if (buf) free(buf); 3205 if (buf) free(buf);
3202 DEBUG_RET(); 3206 DEBUG_RET();
3203 return NULL; 3207 return NULL;
3204 } 3208 }
3205 DEBUG_HEXDUMPC(buf, list->size, 16); 3209 DEBUG_HEXDUMPC(buf, list->size, 16);
3207 memcpy(&block_head, buf, sizeof(block_head)); 3211 memcpy(&block_head, buf, sizeof(block_head));
3208 LE16_CPU(block_head.type); 3212 LE16_CPU(block_head.type);
3209 LE16_CPU(block_head.count); 3213 LE16_CPU(block_head.count);
3210 3214
3211 if (block_head.type != (uint16_t)0x0002) { // some sort of constant? 3215 if (block_head.type != (uint16_t)0x0002) { // some sort of constant?
3212 WARN(("Unknown constant [%#hx] at start of id2 values [offset %#"PRIx64"].\n", block_head.type, list->offset)); 3216 DEBUG_WARN(("Unknown constant [%#hx] at start of id2 values [offset %#"PRIx64"].\n", block_head.type, list->offset));
3213 if (buf) free(buf); 3217 if (buf) free(buf);
3214 DEBUG_RET(); 3218 DEBUG_RET();
3215 return NULL; 3219 return NULL;
3216 } 3220 }
3217 3221
3738 x++; 3742 x++;
3739 salt++; 3743 salt++;
3740 } 3744 }
3741 3745
3742 } else { 3746 } else {
3743 WARN(("Unknown encryption: %i. Cannot decrypt\n", type)); 3747 DEBUG_WARN(("Unknown encryption: %i. Cannot decrypt\n", type));
3744 DEBUG_RET(); 3748 DEBUG_RET();
3745 return -1; 3749 return -1;
3746 } 3750 }
3747 DEBUG_RET(); 3751 DEBUG_RET();
3748 return 0; 3752 return 0;
4157 } 4161 }
4158 return r; 4162 return r;
4159 } 4163 }
4160 4164
4161 4165
4162 char *pst_rfc2425_datetime_format(FILETIME *ft) { 4166 char *pst_rfc2425_datetime_format(const FILETIME *ft) {
4163 static char buffer[30]; 4167 static char buffer[30];
4164 struct tm *stm = NULL; 4168 struct tm *stm = NULL;
4165 DEBUG_ENT("rfc2425_datetime_format"); 4169 DEBUG_ENT("rfc2425_datetime_format");
4166 stm = pst_fileTimeToStructTM(ft); 4170 stm = pst_fileTimeToStructTM(ft);
4167 if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", stm)==0) { 4171 if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
4170 DEBUG_RET(); 4174 DEBUG_RET();
4171 return buffer; 4175 return buffer;
4172 } 4176 }
4173 4177
4174 4178
4175 char *pst_rfc2445_datetime_format(FILETIME *ft) { 4179 char *pst_rfc2445_datetime_format(const FILETIME *ft) {
4176 static char buffer[30]; 4180 static char buffer[30];
4177 struct tm *stm = NULL; 4181 struct tm *stm = NULL;
4178 DEBUG_ENT("rfc2445_datetime_format"); 4182 DEBUG_ENT("rfc2445_datetime_format");
4179 stm = pst_fileTimeToStructTM(ft); 4183 stm = pst_fileTimeToStructTM(ft);
4180 if (strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", stm)==0) { 4184 if (strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", stm)==0) {
4271 DEBUG_ENT("pst_convert_utf8"); 4275 DEBUG_ENT("pst_convert_utf8");
4272 pst_vbuf *newer = pst_vballoc(2); 4276 pst_vbuf *newer = pst_vballoc(2);
4273 size_t rc = pst_vb_8bit2utf8(newer, str->str, strlen(str->str) + 1, charset); 4277 size_t rc = pst_vb_8bit2utf8(newer, str->str, strlen(str->str) + 1, charset);
4274 if (rc == (size_t)-1) { 4278 if (rc == (size_t)-1) {
4275 free(newer->b); 4279 free(newer->b);
4276 DEBUG_EMAIL(("Failed to convert %s to utf-8 - %s\n", charset, str->str)); 4280 DEBUG_WARN(("Failed to convert %s to utf-8 - %s\n", charset, str->str));
4277 } 4281 }
4278 else { 4282 else {
4279 free(str->str); 4283 free(str->str);
4280 str->str = newer->b; 4284 str->str = newer->b;
4281 str->is_utf8 = 1; 4285 str->is_utf8 = 1;