… | |
… | |
55 | #include <uudeview.h> |
55 | #include <uudeview.h> |
56 | #include <uuint.h> |
56 | #include <uuint.h> |
57 | #include <fptools.h> |
57 | #include <fptools.h> |
58 | #include <uustring.h> |
58 | #include <uustring.h> |
59 | |
59 | |
60 | char * uuscan_id = "$Id: uuscan.c,v 1.16 2009/08/24 06:15:00 root Exp $"; |
60 | char * uuscan_id = "$Id: uuscan.c,v 1.17 2009/08/28 23:25:18 root Exp $"; |
61 | |
61 | |
62 | /* |
62 | /* |
63 | * Header fields we recognize as such. See RFC822. We add "From ", |
63 | * Header fields we recognize as such. See RFC822. We add "From ", |
64 | * the usual marker for a beginning of a new message, and a couple |
64 | * the usual marker for a beginning of a new message, and a couple |
65 | * of usual MDA, News and MIME headers. |
65 | * of usual MDA, News and MIME headers. |
66 | * We make a distinction of MIME headers as we need the difference |
66 | * We make a distinction of MIME headers as we need the difference |
67 | * to scan the bodies from partial multipart messages. |
67 | * to scan the bodies from partial multipart messages. |
68 | */ |
68 | */ |
69 | |
69 | |
|
|
70 | #define LSTR(s) { sizeof (s) - 1, s } |
|
|
71 | |
|
|
72 | struct lstr { |
|
|
73 | int len; |
|
|
74 | const char *str; |
|
|
75 | }; |
|
|
76 | |
|
|
77 | #define MAX_KNOWNHEADERLEN 28 /* max. length of a known header */ |
|
|
78 | |
70 | static char *knownmsgheaders[] = { |
79 | static struct lstr knownheaders[] = { |
71 | "From ", "Return-Path:", "Received:", "Reply-To:", |
80 | /* "From " handled in IsKnownHeader */ |
|
|
81 | |
|
|
82 | /* knownmsgheaders */ |
|
|
83 | LSTR ("Return-Path"), LSTR ("Received"), LSTR ("Reply-To"), |
72 | "From:", "Sender:", "Resent-Reply-To:", "Resent-From:", |
84 | LSTR ("From"), LSTR ("Sender"), LSTR ("Resent-Reply-To"), LSTR ("Resent-From"), |
73 | "Resent-Sender:", "Date:", "Resent-Date:", "To:", |
85 | LSTR ("Resent-Sender"), LSTR ("Date"), LSTR ("Resent-Date"), LSTR ("To"), |
74 | "Resent-To:", "Cc:", "Bcc:", "Resent-bcc:", |
86 | LSTR ("Resent-To"), LSTR ("Cc"), LSTR ("Bcc"), LSTR ("Resent-bcc"), |
75 | "Message-ID:", "Resent-Message-Id:", "In-Reply-To:", |
87 | LSTR ("Message-ID"), LSTR ("Resent-Message-Id"), LSTR ("In-Reply-To"), |
76 | "References:", "Keywords:", "Subject:", "Comments:", |
88 | LSTR ("References"), LSTR ("Keywords"), LSTR ("Subject"), LSTR ("Comments"), |
77 | |
89 | |
78 | "Delivery-Date:", "Posted-Date:", "Received-Date:", |
90 | LSTR ("Delivery-Date"), LSTR ("Posted-Date"), LSTR ("Received-Date"), |
79 | "Precedence:", |
91 | LSTR ("Precedence"), |
80 | |
92 | |
81 | "Path:", "Newsgroups:", "Organization:", "Lines:", |
93 | LSTR ("Path"), LSTR ("Newsgroups"), LSTR ("Organization"), LSTR ("Lines"), |
82 | "NNTP-Posting-Host:", |
94 | LSTR ("NNTP-Posting-Host"), |
83 | NULL |
|
|
84 | }; |
|
|
85 | |
95 | |
86 | static char *knownmimeheaders[] = { |
96 | /* knownminehaders */ |
87 | "Mime-Version:", "Content-Transfer-Encoding:", |
97 | LSTR ("Mime-Version"), LSTR ("Content-Transfer-Encoding"), |
88 | "Content-Type:", "Content-Disposition:", |
98 | LSTR ("Content-Type"), LSTR ("Content-Disposition"), |
89 | "Content-Description:", "Content-Length:", |
99 | LSTR ("Content-Description"), LSTR ("Content-Length") |
90 | NULL |
|
|
91 | }; |
100 | }; |
92 | |
101 | |
93 | /* |
102 | /* |
94 | * for MIME (plaintext) parts without filename |
103 | * for MIME (plaintext) parts without filename |
95 | */ |
104 | */ |
… | |
… | |
525 | */ |
534 | */ |
526 | |
535 | |
527 | static int |
536 | static int |
528 | IsKnownHeader (char *line) |
537 | IsKnownHeader (char *line) |
529 | { |
538 | { |
530 | char **iter = knownmsgheaders; |
539 | const char *sep; |
|
|
540 | int len, i; |
|
|
541 | |
|
|
542 | /* "From " handled specially */ |
|
|
543 | /* we assume the buffer is at least 5 bytes long */ |
|
|
544 | if (line [4] == ' ' && line [1] == 'r' && line [2] == 'o' && line [3] == 'm' |
|
|
545 | && (line [0] == 'f' || line [0] == 'F')) |
|
|
546 | return 1; |
|
|
547 | |
|
|
548 | sep = memchr (line, ':', MAX_KNOWNHEADERLEN); |
531 | |
549 | |
532 | /* fast reject, the majority of calls are simple rejects */ |
550 | /* fast reject, the majority of calls are simple rejects */ |
533 | if (!strchr (line, ':')) |
551 | if (!sep) |
534 | return 0; |
552 | return 0; |
535 | |
553 | |
536 | while (iter && *iter) { |
554 | len = sep - line; /* length of part before ':' */ |
537 | if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
555 | |
|
|
556 | for (i = 0; i < sizeof (knownheaders) / sizeof (knownheaders [0]); ++i) |
|
|
557 | if (len == knownheaders [i].len && _FP_strnicmp (line, knownheaders [i].str, len) == 0) |
538 | return 1; |
558 | return 1; |
539 | iter++; |
|
|
540 | } |
|
|
541 | |
|
|
542 | iter = knownmimeheaders; |
|
|
543 | |
|
|
544 | while (iter && *iter) { |
|
|
545 | if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
|
|
546 | return 2; |
|
|
547 | iter++; |
|
|
548 | } |
|
|
549 | |
559 | |
550 | return 0; |
560 | return 0; |
551 | } |
561 | } |
552 | |
562 | |
553 | /* |
563 | /* |