comparison src/readpst.c @ 46:b2a7f2e0926a

more fixes for 64 bit format
author carl
date Sat, 12 Jan 2008 15:20:53 -0800
parents b961bcdadd0e
children f66078abed38
comparison
equal deleted inserted replaced
45:b961bcdadd0e 46:b2a7f2e0926a
152 ff.skip_count++; 152 ff.skip_count++;
153 } 153 }
154 else { 154 else {
155 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id)); 155 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
156 156
157 item = _pst_parse_item(&pstfile, d_ptr); 157 item = pst_parse_item(&pstfile, d_ptr);
158 DEBUG_MAIN(("main: About to process item\n")); 158 DEBUG_MAIN(("main: About to process item\n"));
159 if (item && item->email && item->email->subject && item->email->subject->subj) { 159 if (item && item->email && item->email->subject && item->email->subject->subj) {
160 DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject)); 160 DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
161 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj)); 161 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
162 } 162 }
225 } else { 225 } else {
226 ff.skip_count++; 226 ff.skip_count++;
227 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", 227 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
228 item->type, item->ascii_type)); 228 item->type, item->ascii_type));
229 } 229 }
230 _pst_freeItem(item); 230 pst_freeItem(item);
231 } else { 231 } else {
232 ff.skip_count++; 232 ff.skip_count++;
233 DEBUG_MAIN(("main: A NULL item was seen\n")); 233 DEBUG_MAIN(("main: A NULL item was seen\n"));
234 } 234 }
235 d_ptr = d_ptr->next; 235 d_ptr = d_ptr->next;
332 fprintf(stderr, "Couldn't open file %s\n", fname ); 332 fprintf(stderr, "Couldn't open file %s\n", fname );
333 return 1; 333 return 1;
334 } 334 }
335 335
336 while (0 != ( l = fread( buf, 1, 1024, fp))) { 336 while (0 != ( l = fread( buf, 1, 1024, fp))) {
337 if (0 != _pst_decrypt( buf, l, PST_COMP_ENCRYPT)) 337 if (0 != pst_decrypt( buf, l, PST_COMP_ENCRYPT))
338 fprintf(stderr, "_pst_decrypt() failed (I'll try to continue)\n"); 338 fprintf(stderr, "pst_decrypt() failed (I'll try to continue)\n");
339 339
340 if (l != fwrite( buf, 1, l, stdout)) { 340 if (l != fwrite( buf, 1, l, stdout)) {
341 fprintf(stderr, "Couldn't output to stdout?\n"); 341 fprintf(stderr, "Couldn't output to stdout?\n");
342 return 1; 342 return 1;
343 } 343 }
360 } 360 }
361 361
362 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n"); 362 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
363 363
364 d_ptr = pstfile.d_head; // first record is main record 364 d_ptr = pstfile.d_head; // first record is main record
365 item = _pst_parse_item(&pstfile, d_ptr); 365 item = pst_parse_item(&pstfile, d_ptr);
366 if (!item || !item->message_store) { 366 if (!item || !item->message_store) {
367 DEBUG_RET(); 367 DEBUG_RET();
368 DIE(("main: Could not get root record\n")); 368 DIE(("main: Could not get root record\n"));
369 } 369 }
370 370
388 DEBUG_RET(); 388 DEBUG_RET();
389 DIE(("Top of folders record not found. Cannot continue\n")); 389 DIE(("Top of folders record not found. Cannot continue\n"));
390 } 390 }
391 391
392 process(item, d_ptr->child); // do the children of TOPF 392 process(item, d_ptr->child); // do the children of TOPF
393 _pst_freeItem(item); 393 pst_freeItem(item);
394 pst_close(&pstfile); 394 pst_close(&pstfile);
395 395
396 DEBUG_RET(); 396 DEBUG_RET();
397 return 0; 397 return 0;
398 } 398 }
568 return 0; 568 return 0;
569 } 569 }
570 570
571 571
572 char *mk_seperate_dir(char *dir) { 572 char *mk_seperate_dir(char *dir) {
573 DEBUG_ENT("mk_seperate_dir");
574
575 size_t dirsize = strlen(dir) + 10; 573 size_t dirsize = strlen(dir) + 10;
576 char dir_name[dirsize]; 574 char dir_name[dirsize];
577 int x = 0, y = 0; 575 int x = 0, y = 0;
578 576
577 DEBUG_ENT("mk_seperate_dir");
579 do { 578 do {
580 if (y == 0) 579 if (y == 0)
581 snprintf(dir_name, dirsize, "%s", dir); 580 snprintf(dir_name, dirsize, "%s", dir);
582 else 581 else
583 snprintf(dir_name, dirsize, "%s" SEP_MAIL_FILE_TEMPLATE, dir, y); // enough for 9 digits allocated above 582 snprintf(dir_name, dirsize, "%s" SEP_MAIL_FILE_TEMPLATE, dir, y); // enough for 9 digits allocated above
711 } 710 }
712 711
713 712
714 void write_separate_attachment(char f_name[], pst_item_attach* current_attach, int attach_num, pst_file* pst) 713 void write_separate_attachment(char f_name[], pst_item_attach* current_attach, int attach_num, pst_file* pst)
715 { 714 {
716 DEBUG_ENT("write_separate_attachment");
717 FILE *fp = NULL; 715 FILE *fp = NULL;
718 int x = 0; 716 int x = 0;
719 char *temp = NULL; 717 char *temp = NULL;
720 718
721 // If there is a long filename (filename2) use that, otherwise 719 // If there is a long filename (filename2) use that, otherwise
722 // use the 8.3 filename (filename1) 720 // use the 8.3 filename (filename1)
723 char *attach_filename = (current_attach->filename2) ? current_attach->filename2 721 char *attach_filename = (current_attach->filename2) ? current_attach->filename2
724 : current_attach->filename1; 722 : current_attach->filename1;
723 DEBUG_ENT("write_separate_attachment");
725 724
726 check_filename(f_name); 725 check_filename(f_name);
727 if (!attach_filename) { 726 if (!attach_filename) {
728 // generate our own (dummy) filename for the attachement 727 // generate our own (dummy) filename for the attachement
729 temp = xmalloc(strlen(f_name)+15); 728 temp = xmalloc(strlen(f_name)+15);
747 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); 746 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
748 } else { 747 } else {
749 if (current_attach->data) 748 if (current_attach->data)
750 fwrite(current_attach->data, 1, current_attach->size, fp); 749 fwrite(current_attach->data, 1, current_attach->size, fp);
751 else { 750 else {
752 pst_attach_to_file(pst, current_attach, fp); 751 (void)pst_attach_to_file(pst, current_attach, fp);
753 } 752 }
754 fclose(fp); 753 fclose(fp);
755 } 754 }
756 if (temp) free(temp); 755 if (temp) free(temp);
757 DEBUG_RET(); 756 DEBUG_RET();
758 } 757 }
759 758
760 759
761 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst) 760 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst)
762 { 761 {
762 char *enc = NULL; // base64 encoded attachment
763 DEBUG_ENT("write_inline_attachment"); 763 DEBUG_ENT("write_inline_attachment");
764 char *enc; // base64 encoded attachment
765 DEBUG_EMAIL(("Attachment Size is %i\n", current_attach->size)); 764 DEBUG_EMAIL(("Attachment Size is %i\n", current_attach->size));
766 DEBUG_EMAIL(("Attachment Pointer is %p\n", current_attach->data)); 765 DEBUG_EMAIL(("Attachment Pointer is %p\n", current_attach->data));
767 if (current_attach->data) { 766 if (current_attach->data) {
768 enc = base64_encode (current_attach->data, current_attach->size); 767 enc = base64_encode (current_attach->data, current_attach->size);
769 if (!enc) { 768 if (!enc) {
796 if (current_attach->data) { 795 if (current_attach->data) {
797 fwrite(enc, 1, strlen(enc), f_output); 796 fwrite(enc, 1, strlen(enc), f_output);
798 DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc))); 797 DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc)));
799 free(enc); // caught by valgrind 798 free(enc); // caught by valgrind
800 } else { 799 } else {
801 pst_attach_to_file_base64(pst, current_attach, f_output); 800 (void)pst_attach_to_file_base64(pst, current_attach, f_output);
802 } 801 }
803 fprintf(f_output, "\n\n"); 802 fprintf(f_output, "\n\n");
804 DEBUG_RET(); 803 DEBUG_RET();
805 } 804 }
806 805
807 806
808 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf) 807 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf)
809 { 808 {
810 DEBUG_ENT("write_normal_email");
811 char *boundary = NULL; // the boundary marker between multipart sections 809 char *boundary = NULL; // the boundary marker between multipart sections
812 int boundary_created = 0; // we have not (yet) created a new boundary 810 int boundary_created = 0; // we have not (yet) created a new boundary
813 char *temp = NULL; 811 char *temp = NULL;
814 int attach_num, base64_body = 0; 812 int attach_num, base64_body = 0;
815 time_t em_time; 813 time_t em_time;
816 char *c_time; 814 char *c_time;
817 pst_item_attach* current_attach; 815 pst_item_attach* current_attach;
816 DEBUG_ENT("write_normal_email");
818 817
819 // convert the sent date if it exists, or set it to a fixed date 818 // convert the sent date if it exists, or set it to a fixed date
820 if (item->email->sent_date) { 819 if (item->email->sent_date) {
821 em_time = fileTimeToUnixTime(item->email->sent_date, 0); 820 em_time = fileTimeToUnixTime(item->email->sent_date, 0);
822 c_time = ctime(&em_time); 821 c_time = ctime(&em_time);