changeset 277:86078d0c2e9c

ignore internet headers that don't seem to be real rfc822 headers
author Carl Byington <carl@five-ten-sg.com>
date Sun, 22 May 2011 15:06:08 -0700
parents bbbd455c0490
children 06e723720db0
files src/libpst.c src/readpst.c
diffstat 2 files changed, 18 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/libpst.c	Sun May 22 13:19:49 2011 -0700
+++ b/src/libpst.c	Sun May 22 15:06:08 2011 -0700
@@ -2372,15 +2372,6 @@
                     break;
                 case 0x007D: // PR_TRANSPORT_MESSAGE_HEADERS Internet Header
                     LIST_COPY_EMAIL_STR("Internet Header", item->email->header);
-                    if (item->email->header.str && item->email->header.str[0] == '\r') {
-                        // broken outlook internet headers
-                        const char* fix = "Received: header broken by outlook fixup by libpst";
-                        char *str = pst_malloc(strlen(fix) + strlen(item->email->header.str) + 1);
-                        strcpy(str, fix);
-                        strcat(str, item->email->header.str);
-                        free(item->email->header.str);
-                        item->email->header.str = str;
-                    }
                     break;
                 case 0x0C04: // PR_NDR_REASON_CODE
                     LIST_COPY_EMAIL_INT32("NDR reason code", item->email->ndr_reason_code);
--- a/src/readpst.c	Sun May 22 13:19:49 2011 -0700
+++ b/src/readpst.c	Sun May 22 15:06:08 2011 -0700
@@ -45,6 +45,7 @@
 void      write_separate_attachment(char f_name[], pst_item_attach* attach, int attach_num, pst_file* pst);
 void      write_embedded_message(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pf, char** extra_mime_headers);
 void      write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst);
+int       valid_headers(char *header);
 void      header_has_field(char *header, char *field, int *flag);
 void      header_get_subfield(char *field, const char *subfield, char *body_subfield, size_t size_subfield);
 char*     header_get_field(char *header, char *field);
@@ -1084,6 +1085,20 @@
 }
 
 
+int  valid_headers(char *header)
+{
+    // headers are sometimes really bogus - they seem to be fragments of the
+    // message body, so we only use them if they seem to be real rfc822 headers.
+    if ((strncasecmp(header, "Return-Path: ", 13) == 0) ||
+        (strncasecmp(header, "Received: ",    10) == 0) ||
+        (strncasecmp(header, "From: ",         6) == 0)) {
+    }
+    else {
+        DEBUG_INFO(("Ignore bogus headers = \n%s\n", header));
+    }
+}
+
+
 void header_has_field(char *header, char *field, int *flag)
 {
     DEBUG_ENT("header_has_field");
@@ -1358,21 +1373,9 @@
     DEBUG_ENT("write_normal_email");
 
     pst_convert_utf8_null(item, &item->email->header);
-    headers = (item->email->header.str) ? item->email->header.str : *extra_mime_headers;
-    if (*extra_mime_headers && item->email->header.str) {
-        // we have both extra mime headers from the outer message,  and also our own set of headers
-        // normally we would use the headers on our current (inner) message, but those
-        // headers are sometimes really bogus - they seem to be fragments of the message body. So
-        // we only use them if they seem to be actual smtp rfc822 headers.
-        if ((strncasecmp(headers, "Return-Path: ", 13) == 0) ||
-            (strncasecmp(headers, "Received: ",    10) == 0) ||
-            (strncasecmp(headers, "From: ",         6) == 0)) {
-        }
-        else {
-            DEBUG_INFO(("Ignore bogus inner headers = \n%s\n", headers));
-            headers = *extra_mime_headers;
-        }
-    }
+    headers = valid_headers(item->email->header.str) ? item->email->header.str :
+              valid_headers(*extra_mime_headers)     ? *extra_mime_headers     :
+              NULL;
 
     // setup default body character set and report type
     strncpy(body_charset, pst_default_charset(item, sizeof(buffer_charset), buffer_charset), sizeof(body_charset));