Browse code

Bounce messages are now table driven

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

Nigel Horne authored on 2004/02/05 20:24:54
Showing 2 changed files
... ...
@@ -1,8 +1,15 @@
1
+Thu Feb  5 11:25:56 GMT 2004 (njh)
2
+----------------------------------
3
+  * libclamav:	Bounce delimeters were found by a list of strcasecmps,
4
+  			now handled in a table which means it's easier to
5
+			add new examples as they are found
6
+
1 7
 Wed Feb  4 16:33:08 GMT 2004 (trog)
2 8
 -----------------------------------
3 9
   * libclamav: ole2_extract.c: Improve error handling
4 10
 
5 11
 Wed Feb  4 13:34:28 GMT 2004 (njh)
12
+---------------------------------
6 13
   * libclamav:	Binhex now removes repetitive characters before handling the
7 14
 			header (used to be the other way around)
8 15
 		Handle partial writes in mbox - and print when write fails
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.25  2004/02/05 11:23:07  nigelhorne
21
+ * Bounce messages are now table driven
22
+ *
20 23
  * Revision 1.24  2004/02/04 13:29:16  nigelhorne
21 24
  * Handle blobAddData of more than 128K
22 25
  *
... ...
@@ -69,7 +72,7 @@
69 69
  * uuencodebegin() no longer static
70 70
  *
71 71
  */
72
-static	char	const	rcsid[] = "$Id: message.c,v 1.24 2004/02/04 13:29:16 nigelhorne Exp $";
72
+static	char	const	rcsid[] = "$Id: message.c,v 1.25 2004/02/05 11:23:07 nigelhorne Exp $";
73 73
 
74 74
 #ifndef	CL_DEBUG
75 75
 /*#define	NDEBUG	/* map CLAMAV debug onto standard */
... ...
@@ -99,6 +102,7 @@ static	char	const	rcsid[] = "$Id: message.c,v 1.24 2004/02/04 13:29:16 nigelhorn
99 99
 #include "mbox.h"
100 100
 #include "blob.h"
101 101
 #include "text.h"
102
+#include "table.h"
102 103
 #include "strrcpy.h"
103 104
 #include "others.h"
104 105
 #include "str.h"
... ...
@@ -657,7 +661,7 @@ messageToBlob(const message *m)
657 657
 		unsigned long len, l, newlen = 0L;
658 658
 		char *filename;
659 659
 		unsigned char *ptr, *data;
660
-		int bytenumber = 0;
660
+		int bytenumber;
661 661
 		blob *tmp = blobCreate();
662 662
 
663 663
 		/*
... ...
@@ -683,10 +687,8 @@ messageToBlob(const message *m)
683 683
 		 *
684 684
 		 * See RFC1741
685 685
 		 */
686
-		while((t_line = t_line->t_next) != NULL) {
686
+		while((t_line = t_line->t_next) != NULL)
687 687
 			blobAddData(tmp, (unsigned char *)t_line->t_text, strlen(t_line->t_text));
688
-			blobAddData(tmp, (unsigned char *)"\n", 1);
689
-		}
690 688
 
691 689
 		data = blobGetData(tmp);
692 690
 
... ...
@@ -696,8 +698,6 @@ messageToBlob(const message *m)
696 696
 			blobDestroy(b);
697 697
 			return NULL;
698 698
 		}
699
-		len = blobGetDataSize(tmp);
700
-
701 699
 		if(data[0] != ':') {
702 700
 			/*
703 701
 			 * TODO: Need an example of this before I can be
... ...
@@ -709,6 +709,9 @@ messageToBlob(const message *m)
709 709
 			blobDestroy(b);
710 710
 			return NULL;
711 711
 		}
712
+
713
+		len = blobGetDataSize(tmp);
714
+
712 715
 		/*
713 716
 		 * FIXME: this is dirty code, modification of the contents
714 717
 		 * of a member of the blob object should be done through blob.c
... ...
@@ -719,6 +722,7 @@ messageToBlob(const message *m)
719 719
 
720 720
 		ptr = cli_malloc(len);
721 721
 		memcpy(ptr, data, len);
722
+		bytenumber = 0;
722 723
 
723 724
 		/*
724 725
 		 * ptr now contains the encoded (7bit) data - len bytes long
... ...
@@ -727,11 +731,12 @@ messageToBlob(const message *m)
727 727
 		for(l = 1; l < len; l++) {
728 728
 			unsigned char c = ptr[l];
729 729
 
730
-			if((c == '\n') || (c == '\r'))
731
-				continue;
732 730
 			if(c == ':')
733 731
 				break;
734 732
 
733
+			if((c == '\n') || (c == '\r'))
734
+				continue;
735
+
735 736
 			if((c < 0x20) || (c > 0x7f) || (hqxtbl[c] == 0xff)) {
736 737
 				cli_warnmsg("Invalid HQX7 character '%c' (0x%02x)\n", c, c);
737 738
 				break;
... ...
@@ -764,6 +769,7 @@ messageToBlob(const message *m)
764 764
 					break;
765 765
 			}
766 766
 		}
767
+
767 768
 		cli_dbgmsg("decoded HQX7 message (now %lu bytes)\n", newlen);
768 769
 
769 770
 		/*
... ...
@@ -1074,11 +1080,27 @@ const text *
1074 1074
 bounceBegin(const message *m)
1075 1075
 {
1076 1076
 	const text *t_line;
1077
+	static table_t *bounceMessages;
1078
+	const char *bounces[] = {
1079
+		"--- Below this line is a copy of the message.",
1080
+		"------ This is a copy of the message, including all the headers. ------",
1081
+		"=================================================================================",
1082
+		NULL
1083
+	};
1084
+
1085
+	if(bounceMessages == NULL) {
1086
+		const char **bounce;
1087
+
1088
+		bounceMessages = tableCreate();
1089
+
1090
+		for(bounce = bounces; *bounce; bounce++)
1091
+			if(tableInsert(bounceMessages, *bounce, 1) < 0)
1092
+				cli_warnmsg("Bounce messages starting with\n\t%s\nwon't be detected\n",
1093
+					*bounce);
1094
+	}
1077 1095
 
1078 1096
 	for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next)
1079
-		if((strcasecmp(t_line->t_text, "--- Below this line is a copy of the message.") == 0) ||
1080
-		   (strcmp(t_line->t_text, "=================================================================================") == 0) ||
1081
-		   (strcasecmp(t_line->t_text, "------ This is a copy of the message, including all the headers. ------") == 0))
1097
+		if(tableFind(bounceMessages, t_line->t_text) == 1)
1082 1098
 			return t_line;
1083 1099
 
1084 1100
 	return NULL;