comparison src/readpst.c @ 139:1b3922080ca8

add forensic headers to capture some other data of interest; switch back to quoted From separator line
author Carl Byington <carl@five-ten-sg.com>
date Sun, 08 Feb 2009 20:20:34 -0800
parents fc11b1d1ad34
children fd4297884319
comparison
equal deleted inserted replaced
138:4b8c2c8a5829 139:1b3922080ca8
917 int sender_known = 0; 917 int sender_known = 0;
918 char *temp = NULL; 918 char *temp = NULL;
919 int attach_num; 919 int attach_num;
920 time_t em_time; 920 time_t em_time;
921 char *c_time; 921 char *c_time;
922 int has_from, has_subject, has_to, has_cc, has_bcc, has_date; 922 int has_from, has_subject, has_to, has_cc, has_date;
923 has_from = has_subject = has_to = has_cc = has_bcc = has_date = 0; 923 has_from = has_subject = has_to = has_cc = has_date = 0;
924 DEBUG_ENT("write_normal_email"); 924 DEBUG_ENT("write_normal_email");
925 925
926 // setup default body character set 926 // setup default body character set
927 snprintf(body_charset, sizeof(body_charset), "%s", (item->email->body_charset) ? item->email->body_charset : "utf-8"); 927 snprintf(body_charset, sizeof(body_charset), "%s", (item->email->body_charset) ? item->email->body_charset : "utf-8");
928 928
968 header_has_field(item->email->header, "\nFrom: ", &has_from); 968 header_has_field(item->email->header, "\nFrom: ", &has_from);
969 header_has_field(item->email->header, "\nTo: ", &has_to); 969 header_has_field(item->email->header, "\nTo: ", &has_to);
970 header_has_field(item->email->header, "\nSubject: ", &has_subject); 970 header_has_field(item->email->header, "\nSubject: ", &has_subject);
971 header_has_field(item->email->header, "\nDate: ", &has_date); 971 header_has_field(item->email->header, "\nDate: ", &has_date);
972 header_has_field(item->email->header, "\nCC: ", &has_cc); 972 header_has_field(item->email->header, "\nCC: ", &has_cc);
973 header_has_field(item->email->header, "\nBCC: ", &has_bcc);
974 973
975 // look for charset in Content-Type header 974 // look for charset in Content-Type header
976 t = header_get_field(item->email->header, "\nContent-Type: "); 975 t = header_get_field(item->email->header, "\nContent-Type: ");
977 if (t) { 976 if (t) {
978 // assume charset= will be on the first line, rather than on a continuation line 977 // assume charset= will be on the first line, rather than on a continuation line
1022 header_strip_field(item->email->header, "\nMIME-Version: "); 1021 header_strip_field(item->email->header, "\nMIME-Version: ");
1023 header_strip_field(item->email->header, "\nContent-Type: "); 1022 header_strip_field(item->email->header, "\nContent-Type: ");
1024 header_strip_field(item->email->header, "\nContent-Transfer-Encoding: "); 1023 header_strip_field(item->email->header, "\nContent-Transfer-Encoding: ");
1025 header_strip_field(item->email->header, "\nContent-class: "); 1024 header_strip_field(item->email->header, "\nContent-class: ");
1026 header_strip_field(item->email->header, "\nX-MimeOLE: "); 1025 header_strip_field(item->email->header, "\nX-MimeOLE: ");
1027 header_strip_field(item->email->header, "\nBcc: "); 1026 header_strip_field(item->email->header, "\nBcc:");
1027 header_strip_field(item->email->header, "\nX-From_: ");
1028 } 1028 }
1029 1029
1030 DEBUG_EMAIL(("About to print Header\n")); 1030 DEBUG_EMAIL(("About to print Header\n"));
1031 1031
1032 if (item && item->email && item->email->subject && item->email->subject->subj) { 1032 if (item && item->email && item->email->subject && item->email->subject->subj) {
1033 DEBUG_EMAIL(("item->email->subject->subj = %s\n", item->email->subject->subj)); 1033 DEBUG_EMAIL(("item->email->subject->subj = %s\n", item->email->subject->subj));
1034 } 1034 }
1035 1035
1036 if (mode != MODE_SEPARATE) {
1037 // most modes need this separator line
1038 fprintf(f_output, "From \"%s\" %s\n", sender, c_time);
1039 }
1040
1036 if (item->email->header) { 1041 if (item->email->header) {
1037 int len; 1042 int len;
1038 char *soh = item->email->header; 1043 fprintf(f_output, "%s", item->email->header);
1039
1040 if (mode != MODE_SEPARATE) {
1041 // don't put rubbish in if we are doing separate
1042 if (strncmp(soh, "X-From_: ", 9) == 0 ) {
1043 fputs("From ", f_output);
1044 soh += 9;
1045 } else
1046 fprintf(f_output, "From %s %s\n", sender, c_time);
1047 }
1048
1049 // make sure the headers end with a \n 1044 // make sure the headers end with a \n
1050 fprintf(f_output, "%s", soh); 1045 len = strlen(item->email->header);
1051 len = strlen(soh); 1046 if (!len || (item->email->header[len-1] != '\n')) fprintf(f_output, "\n");
1052 if (!len || (soh[len-1] != '\n')) fprintf(f_output, "\n");
1053
1054 } else {
1055 //make up our own headers
1056 if (mode != MODE_SEPARATE) {
1057 // don't want this first line for this mode
1058 fprintf(f_output, "From %s %s\n", sender, c_time);
1059 }
1060 } 1047 }
1061 1048
1062 // create required header fields that are not already written 1049 // create required header fields that are not already written
1063 if (!has_from) { 1050 if (!has_from) {
1064 fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, sender); 1051 fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, sender);
1078 1065
1079 if (!has_cc && item->email->cc_address) { 1066 if (!has_cc && item->email->cc_address) {
1080 fprintf(f_output, "Cc: %s\n", item->email->cc_address); 1067 fprintf(f_output, "Cc: %s\n", item->email->cc_address);
1081 } 1068 }
1082 1069
1083 if (!has_bcc && item->email->bcc_address) {
1084 fprintf(f_output, "Bcc: %s\n", item->email->bcc_address);
1085 }
1086
1087 if (!has_date && item->email->sent_date) { 1070 if (!has_date && item->email->sent_date) {
1088 char c_time[C_TIME_SIZE]; 1071 char c_time[C_TIME_SIZE];
1089 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time)); 1072 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
1090 fprintf(f_output, "Date: %s\n", c_time); 1073 fprintf(f_output, "Date: %s\n", c_time);
1074 }
1075
1076 // add forensic headers to capture some .pst stuff that is not really
1077 // needed or used by mail clients
1078 if (item->email->sender_address && !strchr(item->email->sender_address, '@')) {
1079 fprintf(f_output, "X-libpst-forensic-sender: %s\n", item->email->sender_address);
1080 }
1081
1082 if (item->email->bcc_address) {
1083 fprintf(f_output, "X-libpst-forensic-bcc: %s\n", item->email->bcc_address);
1091 } 1084 }
1092 1085
1093 // add our own mime headers 1086 // add our own mime headers
1094 fprintf(f_output, "MIME-Version: 1.0\n"); 1087 fprintf(f_output, "MIME-Version: 1.0\n");
1095 if (item->attach || (item->email->rtf_compressed && save_rtf) 1088 if (item->attach || (item->email->rtf_compressed && save_rtf)