git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@175 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/01/09 23:46:59... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Fri Jan 9 14:46:29 GMT 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav: Removed duplicated code in multipart handler in mbox.c |
|
4 |
+ |
|
1 | 5 |
Fri Jan 9 10:21:27 GMT 2004 (njh) |
2 | 6 |
---------------------------------- |
3 | 7 |
* libclamav: Locate uuencoded viruses hidden in text poritions of |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.27 2004/01/09 14:45:59 nigelhorne |
|
21 |
+ * Removed duplicated code in multipart handler |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.26 2004/01/09 10:20:54 nigelhorne |
21 | 24 |
* Locate uuencoded viruses hidden in text poritions of multipart/mixed mime messages |
22 | 25 |
* |
... | ... |
@@ -69,7 +72,7 @@ |
69 | 69 |
* Compilable under SCO; removed duplicate code with message.c |
70 | 70 |
* |
71 | 71 |
*/ |
72 |
-static char const rcsid[] = "$Id: mbox.c,v 1.26 2004/01/09 10:20:54 nigelhorne Exp $"; |
|
72 |
+static char const rcsid[] = "$Id: mbox.c,v 1.27 2004/01/09 14:45:59 nigelhorne Exp $"; |
|
73 | 73 |
|
74 | 74 |
#ifndef CL_DEBUG |
75 | 75 |
/*#define NDEBUG /* map CLAMAV debug onto standard */ |
... | ... |
@@ -162,6 +165,7 @@ static const struct tableinit { |
162 | 162 |
const char *key; |
163 | 163 |
int value; |
164 | 164 |
} rfc821headers[] = { |
165 |
+ /* TODO: make these regular expressions */ |
|
165 | 166 |
{ "Content-Type:", CONTENT_TYPE }, |
166 | 167 |
{ "Content-Transfer-Encoding:", CONTENT_TRANSFER_ENCODING }, |
167 | 168 |
{ "Content-Disposition:", CONTENT_DISPOSITION }, |
... | ... |
@@ -446,7 +450,6 @@ parseEmailHeaders(const message *m, const table_t *rfc821Table) |
446 | 446 |
static int /* success or fail */ |
447 | 447 |
parseEmailBody(message *mainMessage, blob **blobsIn, int nBlobs, text *textIn, const char *dir, table_t *rfc821Table, table_t *subtypeTable) |
448 | 448 |
{ |
449 |
- char *ptr; |
|
450 | 449 |
message *messages[MAXALTERNATIVE]; |
451 | 450 |
int inhead, inMimeHead, i, rc, htmltextPart, multiparts = 0; |
452 | 451 |
text *aText; |
... | ... |
@@ -581,7 +584,7 @@ parseEmailBody(message *mainMessage, blob **blobsIn, int nBlobs, text *textIn, c |
581 | 581 |
inMimeHead = continuationMarker(line); |
582 | 582 |
messageAddArgument(aMessage, line); |
583 | 583 |
} else if(inhead) { |
584 |
- char *copy, *arg; |
|
584 |
+ char *copy, *cmd; |
|
585 | 585 |
|
586 | 586 |
if(strlen(line) == 0) { |
587 | 587 |
inhead = 0; |
... | ... |
@@ -595,71 +598,47 @@ parseEmailBody(message *mainMessage, blob **blobsIn, int nBlobs, text *textIn, c |
595 | 595 |
if(!inMimeHead) |
596 | 596 |
if(t_line->t_next && ((t_line->t_next->t_text[0] == '\t') || (t_line->t_next->t_text[0] == ' '))) |
597 | 597 |
inMimeHead = TRUE; |
598 |
+ |
|
598 | 599 |
copy = strdup(line); |
599 |
- ptr = strtok_r(copy, " \t", &strptr); |
|
600 |
- |
|
601 |
- switch(tableFind(rfc821Table, ptr)) { |
|
602 |
- case CONTENT_TYPE: |
|
603 |
- cli_dbgmsg("insert content-type: parse line '%s'\n", line); |
|
604 |
- arg = strtok_r(NULL, "\r\n", &strptr); |
|
605 |
- if((arg == NULL) || (strchr(arg, '/') == NULL)) { |
|
606 |
- if(arg == NULL) |
|
607 |
- cli_warnmsg("Empty content-type received, assuming text/plain; charset=us-ascii\n", arg); |
|
608 |
- else |
|
609 |
- cli_warnmsg("Invalid content-type '%s' received, no subtype specified, assuming text/plain; charset=us-ascii\n", arg); |
|
610 |
- messageSetMimeType(aMessage, "text"); |
|
611 |
- messageSetMimeSubtype(aMessage, "plain"); |
|
612 |
- } else { |
|
613 |
- if(*arg == '/') { |
|
614 |
- cli_warnmsg("Content-type '/' received, assuming application/octet-stream\n"); |
|
615 |
- messageSetMimeType(aMessage, "application"); |
|
616 |
- messageSetMimeSubtype(aMessage, "octet-stream"); |
|
617 |
- ptr = strtok_r(arg, ";", &strptr); |
|
618 |
- } else { |
|
619 |
- messageSetMimeType(aMessage, strtok_r(arg, "/", &strptr)); |
|
620 |
- messageSetMimeSubtype(aMessage, strtok_r(NULL, ";", &strptr)); |
|
621 |
- } |
|
622 |
- if((ptr = strtok_r(NULL, "\r\n", &strptr)) != NULL) |
|
623 |
- messageAddArguments(aMessage, ptr); |
|
624 |
- } |
|
625 |
- break; |
|
626 |
- case CONTENT_TRANSFER_ENCODING: |
|
627 |
- ptr = strtok_r(NULL, "", &strptr); |
|
628 |
- if(ptr) { |
|
629 |
- messageSetEncoding(aMessage, ptr); |
|
630 |
- break; |
|
631 |
- } |
|
632 |
- /* |
|
633 |
- * Encoding type not found |
|
634 |
- */ |
|
635 |
- if(!inMimeHead) { |
|
636 |
- cli_warnmsg("Empty encoding type, assuming none"); |
|
637 |
- messageSetEncoding(aMessage, "7bit"); |
|
638 |
- break; |
|
639 |
- } |
|
640 |
- /* |
|
641 |
- * Handle the case |
|
642 |
- * when it flows over |
|
643 |
- * to the next line. |
|
644 |
- * |
|
645 |
- * Content-type: |
|
646 |
- * quoted-printable |
|
647 |
- */ |
|
648 |
- if(t_line->t_next) { |
|
649 |
- t_line = t_line->t_next; |
|
650 |
- messageSetEncoding(aMessage, t_line->t_text); |
|
651 | 600 |
|
652 |
- break; |
|
653 |
- } |
|
654 |
- cli_warnmsg("Empty encoding type, assuming none"); |
|
655 |
- messageSetEncoding(aMessage, "7bit"); |
|
601 |
+ cmd = strtok_r(copy, " \t", &strptr); |
|
656 | 602 |
|
657 |
- break; |
|
658 |
- case CONTENT_DISPOSITION: |
|
659 |
- messageSetDispositionType(aMessage, strtok_r(NULL, ";", &strptr)); |
|
660 |
- messageAddArgument(aMessage, strtok_r(NULL, "", &strptr)); |
|
661 |
- break; |
|
603 |
+ /* |
|
604 |
+ * TODO: duplication of code in |
|
605 |
+ * parseEmailHeaders |
|
606 |
+ */ |
|
607 |
+ if(*cmd) { |
|
608 |
+ char *arg = strtok_r(NULL, "", &strptr); |
|
609 |
+ |
|
610 |
+ if(arg) |
|
611 |
+ /* |
|
612 |
+ * Found a header such as |
|
613 |
+ * Content-Type: multipart/mixed; |
|
614 |
+ * set arg to be |
|
615 |
+ * "multipart/mixed" and cmd to |
|
616 |
+ * be "Content-Type:" |
|
617 |
+ */ |
|
618 |
+ parseMimeHeader(aMessage, cmd, rfc821Table, arg); |
|
619 |
+ else { |
|
620 |
+ /* |
|
621 |
+ * Handle the case where the |
|
622 |
+ * header does not have a space |
|
623 |
+ * after the ':', e.g. |
|
624 |
+ * Content-Type:multipart/mixed; |
|
625 |
+ */ |
|
626 |
+ arg = strchr(cmd, ':'); |
|
627 |
+ if(arg && (*++arg != '\0')) { |
|
628 |
+ char *p; |
|
629 |
+ |
|
630 |
+ cmd = strdup(cmd); |
|
631 |
+ p = strchr(cmd, ':'); |
|
632 |
+ *++p = '\0'; |
|
633 |
+ parseMimeHeader(aMessage, cmd, rfc821Table, arg); |
|
634 |
+ free(cmd); |
|
635 |
+ } |
|
636 |
+ } |
|
662 | 637 |
} |
638 |
+ |
|
663 | 639 |
free(copy); |
664 | 640 |
} else if(boundaryStart(line, boundary)) { |
665 | 641 |
inhead = 1; |