Mercurial > libpst
diff 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 |
line wrap: on
line diff
--- a/src/readpst.c Thu Feb 05 09:22:22 2009 -0800 +++ b/src/readpst.c Thu Feb 05 12:09:04 2009 -0800 @@ -4,11 +4,6 @@ * Written by David Smith * dave.s@earthcorp.com */ -#include "common.h" -#include "libpst.h" -#include "timeconv.h" -#include "libstrfunc.h" -#include "vbuf.h" #include "define.h" #include "lzfu.h" @@ -918,6 +913,8 @@ { char boundary[60]; char body_charset[60]; + char sender[60]; + int sender_known = 0; char *temp = NULL; int attach_num; time_t em_time; @@ -929,6 +926,16 @@ // setup default body character set snprintf(body_charset, sizeof(body_charset), "%s", (item->email->body_charset) ? item->email->body_charset : "utf-8"); + // setup default sender + if (item->email->sender_address && strchr(item->email->sender_address, '@')) { + temp = item->email->sender_address; + sender_known = 1; + } + else { + temp = "MAILER-DAEMON"; + } + snprintf(sender, sizeof(sender), "%s", temp); + // convert the sent date if it exists, or set it to a fixed date if (item->email->sent_date) { em_time = fileTimeToUnixTime(item->email->sent_date, 0); @@ -992,6 +999,24 @@ } } + // derive a proper sender email address + if (!sender_known) { + t = header_get_field(item->email->header, "\nFrom: "); + if (t) { + // assume address is on the first line, rather than on a continuation line + t++; + char *n = strchr(t, '\n'); + char *s = strchr(t, '<'); + char *e = strchr(t, '>'); + if (s && e && n && (s < e) && (e < n)) { + char save = *e; + *e = '\0'; + snprintf(sender, sizeof(sender), "%s", s+1); + *e = save; + } + } + } + // Strip out the mime headers and some others that we don't want to emit header_strip_field(item->email->header, "\nMicrosoft Mail Internet Headers"); header_strip_field(item->email->header, "\nMIME-Version: "); @@ -1018,7 +1043,7 @@ fputs("From ", f_output); soh += 9; } else - fprintf(f_output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time); + fprintf(f_output, "From %s %s\n", sender, c_time); } // make sure the headers end with a \n @@ -1030,20 +1055,13 @@ //make up our own headers if (mode != MODE_SEPARATE) { // don't want this first line for this mode - if (item->email->outlook_sender_name) { - temp = item->email->outlook_sender_name; - } else { - temp = "(readpst_null)"; - } - fprintf(f_output, "From \"%s\" %s\n", temp, c_time); + fprintf(f_output, "From %s %s\n", sender, c_time); } } // create required header fields that are not already written if (!has_from) { - temp = item->email->outlook_sender; - if (!temp) temp = ""; - fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp); + fprintf(f_output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, sender); } if (!has_subject) {