Browse code

Handle '8 bit' and plain/text

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1007 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/10/16 22:56:40
Showing 2 changed files
... ...
@@ -1,3 +1,9 @@
1
+Sat Oct 16 14:55:03 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/message.c:	Handle some broken email headers:
4
+		Content-Transfer-Encoding: 8 bit
5
+		Content-Type: plain/text
6
+
1 7
 Sat Oct 16 10:02:32 BST 2004 (njh)
2 8
 ----------------------------------
3 9
   * libclamav/mbox.c:	Improved handling for wraparound headers
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.101  2004/10/16 13:53:52  nigelhorne
21
+ * Handle '8 bit' and plain/text
22
+ *
20 23
  * Revision 1.100  2004/10/14 17:45:55  nigelhorne
21 24
  * Try to reclaim some memory if it becomes low when decoding
22 25
  *
... ...
@@ -297,7 +300,7 @@
297 297
  * uuencodebegin() no longer static
298 298
  *
299 299
  */
300
-static	char	const	rcsid[] = "$Id: message.c,v 1.100 2004/10/14 17:45:55 nigelhorne Exp $";
300
+static	char	const	rcsid[] = "$Id: message.c,v 1.101 2004/10/16 13:53:52 nigelhorne Exp $";
301 301
 
302 302
 #if HAVE_CONFIG_H
303 303
 #include "clamav-config.h"
... ...
@@ -367,16 +370,15 @@ static	void	messageDedup(message *m);
367 367
 static	const	struct	encoding_map {
368 368
 	const	char	*string;
369 369
 	encoding_type	type;
370
-} encoding_map[] = {
370
+} encoding_map[] = {	/* rfc1521 */
371 371
 	{	"7bit",			NOENCODING	},
372 372
 	{	"text/plain",		NOENCODING	},
373 373
 	{	"quoted-printable",	QUOTEDPRINTABLE	},	/* rfc1522 */
374 374
 	{	"base64",		BASE64		},	/* rfc2045 */
375 375
 	{	"8bit",			EIGHTBIT	},
376
-	{	"8 bit",		EIGHTBIT	},	/* incorrect */
376
+	{	"binary",		BINARY		},
377 377
 	{	"x-uuencode",		UUENCODE	},
378 378
 	{	"x-yencode",		YENCODE		},
379
-	{	"binary",		BINARY		},
380 379
 	{	NULL,			NOENCODING	}
381 380
 };
382 381
 
... ...
@@ -472,7 +474,7 @@ messageReset(message *m)
472 472
 }
473 473
 
474 474
 /*
475
- * Handle the Content-Type header
475
+ * Handle the Content-Type header. The syntax is in RFC1341.
476 476
  * Return success (1) or failure (0). Failure only happens when it's an
477 477
  * unknown type and we've already received a known type, or we've received an
478 478
  * empty type. If we receive an unknown type by itself we default to application
... ...
@@ -532,11 +534,17 @@ messageSetMimeType(message *mess, const char *type)
532 532
 	} else if(mess->mimeType == NOMIME) {
533 533
 		if(strncasecmp(type, "x-", 2) == 0)
534 534
 			mess->mimeType = MEXTENSION;
535
-		else {
535
+		else if(strcasecmp(type, "plain") != 0) {
536 536
 			/*
537 537
 			 * Based on a suggestion by James Stevens
538 538
 			 *	<James@kyzo.com>
539 539
 			 * Force scanning of strange messages
540
+			 *
541
+			 * Don't handle broken e-mail probably sending
542
+			 *	Content-Type: plain/text
543
+			 * instead of
544
+			 *	Content-Type: text/plain
545
+			 * as an attachment
540 546
 			 */
541 547
 			cli_warnmsg("Unknown MIME type: `%s' - set to Application\n", type);
542 548
 			mess->mimeType = APPLICATION;
... ...
@@ -924,6 +932,13 @@ messageSetEncoding(message *m, const char *enctype)
924 924
 		enctype++;
925 925
 
926 926
 	/*
927
+	 * broken:
928
+	 *	Content-Transfer-Encoding: 8 bit
929
+	 */
930
+	if(strcasecmp(enctype, "8 bit") == 0)
931
+		enctype = "8bit";
932
+
933
+	/*
927 934
 	 * Iterate through
928 935
 	 *	Content-Transfer-Encoding: base64 binary
929 936
 	 * cli_strtok's fieldno counts from 0
... ...
@@ -1529,7 +1544,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1529 1529
 			 * TODO: handle multipart yEnc encoded files
1530 1530
 			 */
1531 1531
 			t_line = yEncBegin(m);
1532
-			filename = lineGetData(t_line->t_line);
1532
+			filename = (char *)lineGetData(t_line->t_line);
1533 1533
 
1534 1534
 			if((filename = strstr(filename, " name=")) != NULL) {
1535 1535
 				filename = strdup(&filename[6]);
... ...
@@ -2309,7 +2324,7 @@ hex(char c)
2309 2309
 static unsigned char
2310 2310
 base64(char c)
2311 2311
 {
2312
-	const unsigned char ret = base64Table[c];
2312
+	const unsigned char ret = base64Table[(int)c];
2313 2313
 
2314 2314
 	if(ret == 255) {
2315 2315
 		cli_dbgmsg("Illegal character <%c> in base64 encoding\n", c);