Browse code

Save separate bounces in separate files

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

Nigel Horne authored on 2005/02/19 03:05:31
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Feb 18 18:04:30 GMT 2005 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Save separate bounces in separate files
4
+
1 5
 Thu Feb 17 19:28:46 GMT 2005 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/mbox.c:	Prescan some bounces before saving for full scanning
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.222  2005/02/18 18:00:55  nigelhorne
21
+ * Save separate bounces in separate files
22
+ *
20 23
  * Revision 1.221  2005/02/17 19:36:08  nigelhorne
21 24
  * Fix minor typo with bounce handlers
22 25
  *
... ...
@@ -651,7 +654,7 @@
651 651
  * Compilable under SCO; removed duplicate code with message.c
652 652
  *
653 653
  */
654
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.221 2005/02/17 19:36:08 nigelhorne Exp $";
654
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.222 2005/02/18 18:00:55 nigelhorne Exp $";
655 655
 
656 656
 #if HAVE_CONFIG_H
657 657
 #include "clamav-config.h"
... ...
@@ -2027,7 +2030,8 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2027 2027
 					if(boundaryStart(lineGetData(t_line->t_line), boundary))
2028 2028
 						break;
2029 2029
 					/*
2030
-					 * Found a uuencoded/binhex file before the first multipart
2030
+					 * Found a uuencoded/binhex file before
2031
+					 *	the first multipart
2031 2032
 					 * TODO: check yEnc
2032 2033
 					 */
2033 2034
 					if(uuencodeBegin(mainMessage) == t_line) {
... ...
@@ -2866,8 +2870,9 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2866 2866
 
2867 2867
 		for(t = aText; t; t = t->t_next) {
2868 2868
 			const line_t *l = t->t_line;
2869
-			const text *lookahead;
2869
+			const text *lookahead, *topofbounce;
2870 2870
 			const char *s;
2871
+			bool inheader;
2871 2872
 
2872 2873
 			if(l == NULL)
2873 2874
 				continue;
... ...
@@ -2937,16 +2942,49 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2937 2937
 				/* nothing here, move along please */
2938 2938
 				break;
2939 2939
 			}
2940
-			if((fb = fileblobCreate()) != NULL) {
2941
-				cli_dbgmsg("Save non mime part bounce message\n");
2942
-				fileblobSetFilename(fb, dir, "bounce");
2943
-				fileblobAddData(fb, (unsigned char *)"Received: by clamd (bounce)\n", 28);
2944
-
2945
-				fb = textToFileblob(t, fb);
2946
-
2947
-				fileblobDestroy(fb);
2940
+			if((fb = fileblobCreate()) == NULL)
2941
+				break;
2942
+			cli_dbgmsg("Save non mime part bounce message\n");
2943
+			fileblobSetFilename(fb, dir, "bounce");
2944
+			fileblobAddData(fb, (unsigned char *)"Received: by clamd (bounce)\n", 28);
2945
+
2946
+			inheader = TRUE;
2947
+			topofbounce = NULL;
2948
+			for(;;) {
2949
+				l = t->t_line;
2950
+
2951
+				if(l == NULL) {
2952
+					if(inheader) {
2953
+						inheader = FALSE;
2954
+						topofbounce = t;
2955
+					}
2956
+				} else {
2957
+					s = lineGetData(l);
2958
+					fileblobAddData(fb, (unsigned char *)s, strlen(s));
2959
+				}
2960
+				fileblobAddData(fb, (unsigned char *)"\n", 1);
2961
+				lookahead = t->t_next;
2962
+				if(lookahead == NULL)
2963
+					break;
2964
+				t = lookahead;
2965
+				l = t->t_line;
2966
+				if((!inheader) && l) {
2967
+					s = lineGetData(l);
2968
+					if(cli_filetype(s, strlen(s)) == CL_TYPE_MAIL) {
2969
+						cli_dbgmsg("Found the start of another bounce candidate\n");
2970
+						break;
2971
+					}
2972
+				}
2948 2973
 			}
2949
-			break;
2974
+
2975
+			fileblobDestroy(fb);
2976
+			if(topofbounce)
2977
+				t = topofbounce;
2978
+			/*
2979
+			 * Don't do this - it slows bugs.txt
2980
+			 */
2981
+			/*if(mainMessage)
2982
+				mainMessage->bounce = NULL;*/
2950 2983
 		}
2951 2984
 		textDestroy(aText);
2952 2985
 		aText = NULL;
... ...
@@ -3064,7 +3102,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
3064 3064
 				/*
3065 3065
 				 * Some bounces include the message
3066 3066
 				 * body without the headers.
3067
-				 * Unfortunately this generates a
3067
+				 * FIXME: Unfortunately this generates a
3068 3068
 				 * lot of false positives that a bounce
3069 3069
 				 * has been found when it hasn't.
3070 3070
 				 */
... ...
@@ -3135,6 +3173,12 @@ boundaryStart(const char *line, const char *boundary)
3135 3135
 
3136 3136
 	/*cli_dbgmsg("boundaryStart: line = '%s' boundary = '%s'\n", line, boundary);*/
3137 3137
 
3138
+	if((*line != '-') && (*line != '('))
3139
+		return 0;
3140
+
3141
+	if(strchr(line, '-') == NULL)
3142
+		return 0;
3143
+
3138 3144
 	if(strlen(line) <= sizeof(buf)) {
3139 3145
 		out = NULL;
3140 3146
 		ptr = rfc822comments(line, buf);