comparison src/pst2dii.cpp.in @ 202:2f38c4ce606f

remove readpstlog, switch to plain ascii debug log files
author Carl Byington <carl@five-ten-sg.com>
date Mon, 18 May 2009 15:55:05 -0700
parents 320cfcba8058
children 4a659f3138b7
comparison
equal deleted inserted replaced
201:3850a3b11745 202:2f38c4ce606f
178 char *attach_filename = (current_attach->filename2.str) ? current_attach->filename2.str 178 char *attach_filename = (current_attach->filename2.str) ? current_attach->filename2.str
179 : current_attach->filename1.str; 179 : current_attach->filename1.str;
180 DEBUG_ENT("write_separate_attachment"); 180 DEBUG_ENT("write_separate_attachment");
181 check_filename(fname); 181 check_filename(fname);
182 const char* f_name = fname.c_str(); 182 const char* f_name = fname.c_str();
183 DEBUG_EMAIL(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename)); 183 DEBUG_INFO(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename));
184 int len = strlen(output_directory) + 1 + strlen(f_name) + 15; 184 int len = strlen(output_directory) + 1 + strlen(f_name) + 15;
185 if (!attach_filename) { 185 if (!attach_filename) {
186 // generate our own (dummy) filename for the attachement 186 // generate our own (dummy) filename for the attachement
187 temp = (char*)pst_malloc(len); 187 temp = (char*)pst_malloc(len);
188 sprintf(temp, "%s/%s_attach%i", output_directory, f_name, attach_num); 188 sprintf(temp, "%s/%s_attach%i", output_directory, f_name, attach_num);
198 } while ((fp = fopen(temp, "r")) && ++x < 99999999); 198 } while ((fp = fopen(temp, "r")) && ++x < 99999999);
199 if (x > 99999999) { 199 if (x > 99999999) {
200 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp)); 200 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
201 } 201 }
202 } 202 }
203 DEBUG_EMAIL(("Saving attachment to %s\n", temp)); 203 DEBUG_INFO(("Saving attachment to %s\n", temp));
204 if (!(fp = fopen(temp, "wb"))) { 204 if (!(fp = fopen(temp, "wb"))) {
205 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); 205 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
206 } else { 206 } else {
207 (void)pst_attach_to_file(pst, current_attach, fp); 207 (void)pst_attach_to_file(pst, current_attach, fp);
208 fclose(fp); 208 fclose(fp);
446 // they can contain some email stuff too. We will cut off the header 446 // they can contain some email stuff too. We will cut off the header
447 // when we see a \n\n or \r\n\r\n 447 // when we see a \n\n or \r\n\r\n
448 removeCR(item->email->header.str); 448 removeCR(item->email->header.str);
449 char *temp = strstr(item->email->header.str, "\n\n"); 449 char *temp = strstr(item->email->header.str, "\n\n");
450 if (temp) { 450 if (temp) {
451 DEBUG_EMAIL(("Found body text in header\n")); 451 DEBUG_INFO(("Found body text in header\n"));
452 temp[1] = '\0'; // stop after first \n 452 temp[1] = '\0'; // stop after first \n
453 } 453 }
454 soh = skip_header_prologue(item->email->header.str); 454 soh = skip_header_prologue(item->email->header.str);
455 } 455 }
456 456
495 write_simple("SUBJECT", item->subject.str); 495 write_simple("SUBJECT", item->subject.str);
496 } 496 }
497 write_simple("MSGID", item->email->messageid.str); 497 write_simple("MSGID", item->email->messageid.str);
498 write_simple("READ", (item->flags & 1) ? "Y" : "N"); 498 write_simple("READ", (item->flags & 1) ? "Y" : "N");
499 499
500 DEBUG_EMAIL(("About to print Header\n")); 500 DEBUG_INFO(("About to print Header\n"));
501 fprintf(dii_file, "@HEADER\n"); 501 fprintf(dii_file, "@HEADER\n");
502 502
503 if (item && item->subject.str) { 503 if (item && item->subject.str) {
504 DEBUG_EMAIL(("item->subject = %s\n", item->subject.str)); 504 DEBUG_INFO(("item->subject = %s\n", item->subject.str));
505 } 505 }
506 506
507 if (soh) { 507 if (soh) {
508 // Now, write out the header... 508 // Now, write out the header...
509 print_pdf(soh); 509 print_pdf(soh);
545 } 545 }
546 snprintf(line, sizeof(line), "\n"); 546 snprintf(line, sizeof(line), "\n");
547 print_pdf_only(line, black); 547 print_pdf_only(line, black);
548 fprintf(dii_file, "@HEADER-END\n"); 548 fprintf(dii_file, "@HEADER-END\n");
549 549
550 DEBUG_EMAIL(("About to print Body\n")); 550 DEBUG_INFO(("About to print Body\n"));
551 fprintf(dii_file, "@EMAIL-BODY\n"); 551 fprintf(dii_file, "@EMAIL-BODY\n");
552 if (item->body.str) { 552 if (item->body.str) {
553 removeCR(item->body.str); 553 removeCR(item->body.str);
554 print_pdf(item->body.str); 554 print_pdf(item->body.str);
555 } else if (item->email->htmlbody.str) { 555 } else if (item->email->htmlbody.str) {
562 } 562 }
563 fprintf(dii_file, "@EMAIL-END\n"); 563 fprintf(dii_file, "@EMAIL-END\n");
564 564
565 int attach_num = 0; 565 int attach_num = 0;
566 for (pst_item_attach* current_attach = item->attach; current_attach; current_attach = current_attach->next) { 566 for (pst_item_attach* current_attach = item->attach; current_attach; current_attach = current_attach->next) {
567 DEBUG_EMAIL(("Attempting Attachment encoding\n")); 567 DEBUG_INFO(("Attempting Attachment encoding\n"));
568 if (!current_attach->data.data) { 568 if (!current_attach->data.data) {
569 DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->data.size)); 569 DEBUG_WARN(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->data.size));
570 } 570 }
571 string an = write_separate_attachment(f.name, current_attach, ++attach_num, pst); 571 string an = write_separate_attachment(f.name, current_attach, ++attach_num, pst);
572 fprintf(dii_file, "@EATTACH %s\n", an.c_str()); 572 fprintf(dii_file, "@EATTACH %s\n", an.c_str());
573 } 573 }
574 close_pdf(); 574 close_pdf();
611 //if this is a non-empty folder, we want to recurse into it 611 //if this is a non-empty folder, we want to recurse into it
612 fprintf(stderr, "entering folder %s\n", item->file_as.str); 612 fprintf(stderr, "entering folder %s\n", item->file_as.str);
613 process(item, &ff, d_ptr->child); 613 process(item, &ff, d_ptr->child);
614 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT || item->type == PST_TYPE_OTHER)) { 614 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT || item->type == PST_TYPE_OTHER)) {
615 ff.email_count++; 615 ff.email_count++;
616 DEBUG_MAIN(("main: Processing Email\n")); 616 DEBUG_INFO(("Processing Email\n"));
617 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT) && (ff.type != PST_TYPE_OTHER)) { 617 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT) && (ff.type != PST_TYPE_OTHER)) {
618 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n")); 618 DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
619 } 619 }
620 write_normal_email(ff, item, &pstfile); 620 write_normal_email(ff, item, &pstfile);
621 } 621 }
622 pst_freeItem(item); 622 pst_freeItem(item);
623 } else { 623 } else {
624 ff.skip_count++; 624 ff.skip_count++;
625 DEBUG_MAIN(("main: A NULL item was seen\n")); 625 DEBUG_INFO(("A NULL item was seen\n"));
626 } 626 }
627 } 627 }
628 d_ptr = d_ptr->next; 628 d_ptr = d_ptr->next;
629 } 629 }
630 close_enter_dir(ff); 630 close_enter_dir(ff);
689 689
690 #ifdef DEBUG_ALL 690 #ifdef DEBUG_ALL
691 // force a log file 691 // force a log file
692 if (!d_log) d_log = "pst2dii.log"; 692 if (!d_log) d_log = "pst2dii.log";
693 #endif 693 #endif
694 DEBUG_INIT(d_log); 694 DEBUG_INIT(d_log, NULL);
695 DEBUG_REGISTER_CLOSE();
696 DEBUG_ENT("main"); 695 DEBUG_ENT("main");
697 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n")); 696 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
698 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n")); 697 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
699 698
700 pst_load_extended_attributes(&pstfile); 699 pst_load_extended_attributes(&pstfile);
701 700
702 d_ptr = pstfile.d_head; // first record is main record 701 d_ptr = pstfile.d_head; // first record is main record
703 item = (pst_item*)pst_parse_item(&pstfile, d_ptr, NULL); 702 item = (pst_item*)pst_parse_item(&pstfile, d_ptr, NULL);
704 if (!item || !item->message_store) { 703 if (!item || !item->message_store) {
705 DEBUG_RET(); 704 DEBUG_RET();
706 DIE(("main: Could not get root record\n")); 705 DIE(("Could not get root record\n"));
707 } 706 }
708 707
709 d_ptr = pst_getTopOfFolders(&pstfile, item); 708 d_ptr = pst_getTopOfFolders(&pstfile, item);
710 if (!d_ptr) { 709 if (!d_ptr) {
711 DEBUG_RET(); 710 DEBUG_RET();