Browse code

Reduce bounce false positives

git-svn: trunk@1946

Nigel Horne authored on 2006/05/03 00:21:59
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue May  2 16:21:06 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Reduce bounce false positives
4
+
1 5
 Mon May  1 22:22:28 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * clamconf/clamconf.c: fix typo spotted by NJH
... ...
@@ -20,7 +24,7 @@ Sun Apr 30 19:23:35 BST 2006 (njh)
20 20
 Tue Apr 25 18:48:23 BST 2006 (njh)
21 21
 ----------------------------------
22 22
   * libclamav/pst.c:	Apply patch from TK to use le??_to_host and to include
23
-  				clamav-config.h first
23
+				clamav-config.h first
24 24
 
25 25
 Mon Apr 24 22:19:34 BST 2006 (njh)
26 26
 ----------------------------------
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.292 2006/04/30 18:22:44 nigelhorne Exp $";
19
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.293 2006/05/02 15:19:24 nigelhorne Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -196,6 +196,7 @@ static	int	rfc1341(message *m, const char *dir);
196 196
 #endif
197 197
 static	bool	usefulHeader(int commandNumber, const char *cmd);
198 198
 static	char	*getline_from_mbox(char *buffer, size_t len, FILE *fin);
199
+static	bool	mailStart(const char *line);
199 200
 
200 201
 static	void	checkURLs(message *m, const char *dir);
201 202
 #ifdef	WITH_CURL
... ...
@@ -2666,9 +2667,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2666 2666
 			if(l == NULL)
2667 2667
 				continue;
2668 2668
 
2669
-			s = lineGetData(l);
2670
-
2671
-			if(cli_filetype(s, strlen(s)) != CL_TYPE_MAIL)
2669
+			if(!mailStart(lineGetData(l)))
2672 2670
 				continue;
2673 2671
 
2674 2672
 			/*
... ...
@@ -2758,8 +2757,8 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
2758 2758
 				l = t->t_line;
2759 2759
 				if((!inheader) && l) {
2760 2760
 					s = lineGetData(l);
2761
-					if(cli_filetype(s, strlen(s)) == CL_TYPE_MAIL) {
2762
-						cli_dbgmsg("Found the start of another bounce candidate\n");
2761
+					if(mailStart(s)) {
2762
+						cli_dbgmsg("Found the start of another bounce candidate (%s)\n", s);
2763 2763
 						break;
2764 2764
 					}
2765 2765
 				}
... ...
@@ -4221,3 +4220,36 @@ getline_from_mbox(char *buffer, size_t len, FILE *fin)
4221 4221
 
4222 4222
 	return ret;
4223 4223
 }
4224
+
4225
+static bool
4226
+mailStart(const char *line)
4227
+{
4228
+	if(line == NULL)
4229
+		return FALSE;
4230
+	if(*line == '\0')
4231
+		return FALSE;
4232
+	if((strncmp(line, "From ", 5) == 0) && !isalnum(line[5]))
4233
+		return FALSE;
4234
+	if((strncmp(line, ">From ", 6) == 0) && !isalnum(line[6]))
4235
+		return FALSE;
4236
+	if(cli_filetype(line, strlen(line)) != CL_TYPE_MAIL)
4237
+		return FALSE;
4238
+
4239
+	if((strncmp(line, "From ", 5) == 0) ||
4240
+	   (strncmp(line, ">From ", 6) == 0)) {
4241
+		int numSpaces = 0, numDigits = 0;
4242
+
4243
+		do
4244
+			if(*line == ' ')
4245
+				numSpaces++;
4246
+			else if(isdigit(*line))
4247
+				numDigits++;
4248
+		while(*++line != '\0');
4249
+
4250
+		if(numSpaces < 6)
4251
+			return FALSE;
4252
+		if(numDigits < 11)
4253
+			return FALSE;
4254
+	}
4255
+	return TRUE;
4256
+}
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: message.c,v 1.164 2006/04/09 19:59:27 kojm Exp $";
19
+static	char	const	rcsid[] = "$Id: message.c,v 1.165 2006/05/02 15:19:24 nigelhorne Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -637,7 +637,7 @@ messageFindArgument(const message *m, const char *variable)
637 637
 			while(isspace(*ptr))
638 638
 				ptr++;
639 639
 			if(*ptr != '=') {
640
-				cli_warnmsg("messageFindArgument: no '=' sign found in MIME header '%s'\n", variable);
640
+				cli_warnmsg("messageFindArgument: no '=' sign found in MIME header '%s' (%s)\n", variable, messageGetArgument(m, i));
641 641
 				return NULL;
642 642
 			}
643 643
 			if((*++ptr == '"') && (strchr(&ptr[1], '"') != NULL)) {