libpst

changeset 365:e4c414ff8fa2

allow first internet header to be wrapped
author Carl Byington <carl@five-ten-sg.com>
date Tue, 30 Aug 2016 15:04:12 -0700
parents 9c6f93aca0db
children 67a3ee227495
files src/readpst.c
diffstat 1 files changed, 26 insertions(+), 19 deletions(-) [+]
line diff
     1.1 --- a/src/readpst.c	Mon Aug 29 10:22:54 2016 -0700
     1.2 +++ b/src/readpst.c	Tue Aug 30 15:04:12 2016 -0700
     1.3 @@ -1214,6 +1214,17 @@
     1.4  }
     1.5  
     1.6  
     1.7 +int  header_match(char *header, char*field) {
     1.8 +    int n = strlen(field);
     1.9 +    if (strncasecmp(header, field, n) == 0) return 1;   // tag:{space}
    1.10 +    if ((field[n-1] == ' ') && (strncasecmp(header, field, n-1) == 0)) {
    1.11 +        char *crlftab = "\r\n\t";
    1.12 +        DEBUG_INFO(("Possible wrapped header = %s\n", header));
    1.13 +        if (strncasecmp(header+n-1, crlftab, 3) == 0) return 1; // tag:{cr}{lf}{tab}
    1.14 +    }
    1.15 +    return 0;
    1.16 +}
    1.17 +
    1.18  int  valid_headers(char *header)
    1.19  {
    1.20      // headers are sometimes really bogus - they seem to be fragments of the
    1.21 @@ -1222,26 +1233,22 @@
    1.22      // there are surely others. the problem is - given an arbitrary character
    1.23      // string, is it a valid (or even reasonable) set of rfc822 headers?
    1.24      if (header) {
    1.25 -        if ((strncasecmp(header, "Content-Type: ",                  14) == 0) ||
    1.26 -            (strncasecmp(header, "Date: ",                           6) == 0) ||
    1.27 -            (strncasecmp(header, "From: ",                           6) == 0) ||
    1.28 -            (strncasecmp(header, "MIME-Version: ",                  14) == 0) ||
    1.29 -            (strncasecmp(header, "Microsoft Mail Internet Headers", 31) == 0) ||
    1.30 -            (strncasecmp(header, "Received: ",                      10) == 0) ||
    1.31 -            (strncasecmp(header, "Return-Path: ",                   13) == 0) ||
    1.32 -            (strncasecmp(header, "Subject: ",                        9) == 0) ||
    1.33 -            (strncasecmp(header, "To: ",                             4) == 0) ||
    1.34 -            (strncasecmp(header, "X-ASG-Debug-ID: ",                16) == 0) ||
    1.35 -            (strncasecmp(header, "X-Barracuda-URL: ",               17) == 0) ||
    1.36 -            (strncasecmp(header, "X-x: ",                            5) == 0)) {
    1.37 -            return 1;                                 
    1.38 +        if (header_match(header, "Content-Type: "                 )) return 1;
    1.39 +        if (header_match(header, "Date: "                         )) return 1;
    1.40 +        if (header_match(header, "From: "                         )) return 1;
    1.41 +        if (header_match(header, "MIME-Version: "                 )) return 1;
    1.42 +        if (header_match(header, "Microsoft Mail Internet Headers")) return 1;
    1.43 +        if (header_match(header, "Received: "                     )) return 1;
    1.44 +        if (header_match(header, "Return-Path: "                  )) return 1;
    1.45 +        if (header_match(header, "Subject: "                      )) return 1;
    1.46 +        if (header_match(header, "To: "                           )) return 1;
    1.47 +        if (header_match(header, "X-ASG-Debug-ID: "               )) return 1;
    1.48 +        if (header_match(header, "X-Barracuda-URL: "              )) return 1;
    1.49 +        if (header_match(header, "X-x: "                          )) return 1;
    1.50 +        if (strlen(header) > 2) {
    1.51 +            DEBUG_INFO(("Ignore bogus headers = %s\n", header));
    1.52          }
    1.53 -        else {
    1.54 -            if (strlen(header) > 2) {
    1.55 -                DEBUG_INFO(("Ignore bogus headers = %s\n", header));
    1.56 -            }
    1.57 -            return 0;
    1.58 -        }
    1.59 +        return 0;
    1.60      }
    1.61      else return 0;
    1.62  }