comparison src/readpst.c @ 129:fc11b1d1ad34

fix initial from header in mbox format. start moving to PST_LE_GET* rather than LE*_CPU macros so we can eventually remove the pragma packing.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 05 Feb 2009 12:09:04 -0800
parents 23a36ac0514d
children 1b3922080ca8
comparison
equal deleted inserted replaced
128:7f747c8c9d02 129:fc11b1d1ad34
2 * readpst.c 2 * readpst.c
3 * Part of the LibPST project 3 * Part of the LibPST project
4 * Written by David Smith 4 * Written by David Smith
5 * dave.s@earthcorp.com 5 * dave.s@earthcorp.com
6 */ 6 */
7 #include "common.h"
8 #include "libpst.h"
9 #include "timeconv.h"
10 #include "libstrfunc.h"
11 #include "vbuf.h"
12 7
13 #include "define.h" 8 #include "define.h"
14 #include "lzfu.h" 9 #include "lzfu.h"
15 10
16 #define OUTPUT_TEMPLATE "%s" 11 #define OUTPUT_TEMPLATE "%s"
916 911
917 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf) 912 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf)
918 { 913 {
919 char boundary[60]; 914 char boundary[60];
920 char body_charset[60]; 915 char body_charset[60];
916 char sender[60];
917 int sender_known = 0;
921 char *temp = NULL; 918 char *temp = NULL;
922 int attach_num; 919 int attach_num;
923 time_t em_time; 920 time_t em_time;
924 char *c_time; 921 char *c_time;
925 int has_from, has_subject, has_to, has_cc, has_bcc, has_date; 922 int has_from, has_subject, has_to, has_cc, has_bcc, has_date;
926 has_from = has_subject = has_to = has_cc = has_bcc = has_date = 0; 923 has_from = has_subject = has_to = has_cc = has_bcc = has_date = 0;
927 DEBUG_ENT("write_normal_email"); 924 DEBUG_ENT("write_normal_email");
928 925
929 // setup default body character set 926 // setup default body character set
930 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
929 // setup default sender
930 if (item->email->sender_address && strchr(item->email->sender_address, '@')) {
931 temp = item->email->sender_address;
932 sender_known = 1;
933 }
934 else {
935 temp = "MAILER-DAEMON";
936 }
937 snprintf(sender, sizeof(sender), "%s", temp);
931 938
932 // convert the sent date if it exists, or set it to a fixed date 939 // convert the sent date if it exists, or set it to a fixed date
933 if (item->email->sent_date) { 940 if (item->email->sent_date) {
934 em_time = fileTimeToUnixTime(item->email->sent_date, 0); 941 em_time = fileTimeToUnixTime(item->email->sent_date, 0);
935 c_time = ctime(&em_time); 942 c_time = ctime(&em_time);
990 *e = save; 997 *e = save;
991 DEBUG_EMAIL(("body charset %s from headers\n", body_charset)); 998 DEBUG_EMAIL(("body charset %s from headers\n", body_charset));
992 } 999 }
993 } 1000 }
994 1001
1002 // derive a proper sender email address
1003 if (!sender_known) {
1004 t = header_get_field(item->email->header, "\nFrom: ");
1005 if (t) {
1006 // assume address is on the first line, rather than on a continuation line
1007 t++;
1008 char *n = strchr(t, '\n');
1009 char *s = strchr(t, '<');
1010 char *e = strchr(t, '>');
1011 if (s && e && n && (s < e) && (e < n)) {
1012 char save = *e;
1013 *e = '\0';
1014 snprintf(sender, sizeof(sender), "%s", s+1);
1015 *e = save;
1016 }
1017 }
1018 }
1019
995 // Strip out the mime headers and some others that we don't want to emit 1020 // Strip out the mime headers and some others that we don't want to emit
996 header_strip_field(item->email->header, "\nMicrosoft Mail Internet Headers"); 1021 header_strip_field(item->email->header, "\nMicrosoft Mail Internet Headers");
997 header_strip_field(item->email->header, "\nMIME-Version: "); 1022 header_strip_field(item->email->header, "\nMIME-Version: ");
998 header_strip_field(item->email->header, "\nContent-Type: "); 1023 header_strip_field(item->email->header, "\nContent-Type: ");
999 header_strip_field(item->email->header, "\nContent-Transfer-Encoding: "); 1024 header_strip_field(item->email->header, "\nContent-Transfer-Encoding: ");
1016 // don't put rubbish in if we are doing separate 1041 // don't put rubbish in if we are doing separate
1017 if (strncmp(soh, "X-From_: ", 9) == 0 ) { 1042 if (strncmp(soh, "X-From_: ", 9) == 0 ) {
1018 fputs("From ", f_output); 1043 fputs("From ", f_output);
1019 soh += 9; 1044 soh += 9;
1020 } else 1045 } else
1021 fprintf(f_output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time); 1046 fprintf(f_output, "From %s %s\n", sender, c_time);
1022 } 1047 }
1023 1048
1024 // make sure the headers end with a \n 1049 // make sure the headers end with a \n
1025 fprintf(f_output, "%s", soh); 1050 fprintf(f_output, "%s", soh);
1026 len = strlen(soh); 1051 len = strlen(soh);
1028 1053
1029 } else { 1054 } else {
1030 //make up our own headers 1055 //make up our own headers
1031 if (mode != MODE_SEPARATE) { 1056 if (mode != MODE_SEPARATE) {
1032 // don't want this first line for this mode 1057 // don't want this first line for this mode
1033 if (item->email->outlook_sender_name) { 1058 fprintf(f_output, "From %s %s\n", sender, c_time);
1034 temp = item->email->outlook_sender_name;
1035 } else {
1036 temp = "(readpst_null)";
1037 }
1038 fprintf(f_output, "From \"%s\" %s\n", temp, c_time);
1039 } 1059 }
1040 } 1060 }
1041 1061
1042 // create required header fields that are not already written 1062 // create required header fields that are not already written
1043 if (!has_from) { 1063 if (!has_from) {
1044 temp = item->email->outlook_sender; 1064 fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, sender);
1045 if (!temp) temp = "";
1046 fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
1047 } 1065 }
1048 1066
1049 if (!has_subject) { 1067 if (!has_subject) {
1050 if (item->email->subject && item->email->subject->subj) { 1068 if (item->email->subject && item->email->subject->subj) {
1051 fprintf(f_output, "Subject: %s\n", item->email->subject->subj); 1069 fprintf(f_output, "Subject: %s\n", item->email->subject->subj);