comparison src/readpst.c @ 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
comparison
equal deleted inserted replaced
276:bbbd455c0490 277:86078d0c2e9c
43 char* my_stristr(char *haystack, char *needle); 43 char* my_stristr(char *haystack, char *needle);
44 void check_filename(char *fname); 44 void check_filename(char *fname);
45 void write_separate_attachment(char f_name[], pst_item_attach* attach, int attach_num, pst_file* pst); 45 void write_separate_attachment(char f_name[], pst_item_attach* attach, int attach_num, pst_file* pst);
46 void write_embedded_message(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pf, char** extra_mime_headers); 46 void write_embedded_message(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pf, char** extra_mime_headers);
47 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst); 47 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst);
48 int valid_headers(char *header);
48 void header_has_field(char *header, char *field, int *flag); 49 void header_has_field(char *header, char *field, int *flag);
49 void header_get_subfield(char *field, const char *subfield, char *body_subfield, size_t size_subfield); 50 void header_get_subfield(char *field, const char *subfield, char *body_subfield, size_t size_subfield);
50 char* header_get_field(char *header, char *field); 51 char* header_get_field(char *header, char *field);
51 char* header_end_field(char *field); 52 char* header_end_field(char *field);
52 void header_strip_field(char *header, char *field); 53 void header_strip_field(char *header, char *field);
1082 fprintf(f_output, "\n\n"); 1083 fprintf(f_output, "\n\n");
1083 DEBUG_RET(); 1084 DEBUG_RET();
1084 } 1085 }
1085 1086
1086 1087
1088 int valid_headers(char *header)
1089 {
1090 // headers are sometimes really bogus - they seem to be fragments of the
1091 // message body, so we only use them if they seem to be real rfc822 headers.
1092 if ((strncasecmp(header, "Return-Path: ", 13) == 0) ||
1093 (strncasecmp(header, "Received: ", 10) == 0) ||
1094 (strncasecmp(header, "From: ", 6) == 0)) {
1095 }
1096 else {
1097 DEBUG_INFO(("Ignore bogus headers = \n%s\n", header));
1098 }
1099 }
1100
1101
1087 void header_has_field(char *header, char *field, int *flag) 1102 void header_has_field(char *header, char *field, int *flag)
1088 { 1103 {
1089 DEBUG_ENT("header_has_field"); 1104 DEBUG_ENT("header_has_field");
1090 if (my_stristr(header, field) || (strncasecmp(header, field+1, strlen(field)-1) == 0)) { 1105 if (my_stristr(header, field) || (strncasecmp(header, field+1, strlen(field)-1) == 0)) {
1091 DEBUG_INFO(("header block has %s header\n", field+1)); 1106 DEBUG_INFO(("header block has %s header\n", field+1));
1356 int has_from, has_subject, has_to, has_cc, has_date, has_msgid; 1371 int has_from, has_subject, has_to, has_cc, has_date, has_msgid;
1357 has_from = has_subject = has_to = has_cc = has_date = has_msgid = 0; 1372 has_from = has_subject = has_to = has_cc = has_date = has_msgid = 0;
1358 DEBUG_ENT("write_normal_email"); 1373 DEBUG_ENT("write_normal_email");
1359 1374
1360 pst_convert_utf8_null(item, &item->email->header); 1375 pst_convert_utf8_null(item, &item->email->header);
1361 headers = (item->email->header.str) ? item->email->header.str : *extra_mime_headers; 1376 headers = valid_headers(item->email->header.str) ? item->email->header.str :
1362 if (*extra_mime_headers && item->email->header.str) { 1377 valid_headers(*extra_mime_headers) ? *extra_mime_headers :
1363 // we have both extra mime headers from the outer message, and also our own set of headers 1378 NULL;
1364 // normally we would use the headers on our current (inner) message, but those
1365 // headers are sometimes really bogus - they seem to be fragments of the message body. So
1366 // we only use them if they seem to be actual smtp rfc822 headers.
1367 if ((strncasecmp(headers, "Return-Path: ", 13) == 0) ||
1368 (strncasecmp(headers, "Received: ", 10) == 0) ||
1369 (strncasecmp(headers, "From: ", 6) == 0)) {
1370 }
1371 else {
1372 DEBUG_INFO(("Ignore bogus inner headers = \n%s\n", headers));
1373 headers = *extra_mime_headers;
1374 }
1375 }
1376 1379
1377 // setup default body character set and report type 1380 // setup default body character set and report type
1378 strncpy(body_charset, pst_default_charset(item, sizeof(buffer_charset), buffer_charset), sizeof(body_charset)); 1381 strncpy(body_charset, pst_default_charset(item, sizeof(buffer_charset), buffer_charset), sizeof(body_charset));
1379 body_charset[sizeof(body_charset)-1] = '\0'; 1382 body_charset[sizeof(body_charset)-1] = '\0';
1380 strncpy(body_report, "delivery-status", sizeof(body_report)); 1383 strncpy(body_report, "delivery-status", sizeof(body_report));