Browse code

Better handling of multipart/multipart messages

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

Nigel Horne authored on 2004/03/31 07:46:44
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Mar 30 23:57:33 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Better handling of multipart within multipart messages
4
+
1 5
 Tue Mar 30 23:18:49 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * clamav-milter: adapt Makefile to new directory structure
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.61  2004/03/30 22:45:13  nigelhorne
21
+ * Better handling of multipart/multipart messages
22
+ *
20 23
  * Revision 1.60  2004/03/29 09:22:03  nigelhorne
21 24
  * Tidy up code and reduce shuffling of data
22 25
  *
... ...
@@ -171,7 +174,7 @@
171 171
  * Compilable under SCO; removed duplicate code with message.c
172 172
  *
173 173
  */
174
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.60 2004/03/29 09:22:03 nigelhorne Exp $";
174
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.61 2004/03/30 22:45:13 nigelhorne Exp $";
175 175
 
176 176
 #if HAVE_CONFIG_H
177 177
 #include "clamav-config.h"
... ...
@@ -316,7 +319,9 @@ static	const	struct tableinit {
316 316
  * TODO: when signal handling is added, need to remove temp files when a
317 317
  * signal is received
318 318
  * TODO: add option to scan in memory not via temp files, perhaps with a
319
- * named pipe or memory mapped file?
319
+ * named pipe or memory mapped file, though this won't work on big e-mails
320
+ * containing many levels of encapsulated messages - it'd just take too much
321
+ * RAM
320 322
  * TODO: if debug is enabled, catch a segfault and dump the current e-mail
321 323
  * in it's entirety, then call abort()
322 324
  * TODO: parse .msg format files
... ...
@@ -515,8 +520,7 @@ parseEmailHeaders(const message *m, const table_t *rfc821Table)
515 515
 static int
516 516
 parseEmailHeader(message *m, const char *line, const table_t *rfc821Table)
517 517
 {
518
-	char *copy = strdup(line);
519
-	char *cmd;
518
+	char *copy, *cmd;
520 519
 	int ret = -1;
521 520
 #ifdef CL_THREAD_SAFE
522 521
 	char *strptr;
... ...
@@ -524,6 +528,11 @@ parseEmailHeader(message *m, const char *line, const table_t *rfc821Table)
524 524
 
525 525
 	cli_dbgmsg("parseEmailHeader '%s'\n", line);
526 526
 
527
+	if(strchr(line, ':') == NULL)
528
+		return -1;
529
+
530
+	copy = strdup(line);
531
+
527 532
 	cmd = strtok_r(copy, ":", &strptr);
528 533
 
529 534
 	if(cmd && *cmd) {
... ...
@@ -1030,14 +1039,19 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1030 1030
 						if(aMessage) {
1031 1031
 							body = parseEmailHeaders(aMessage, rfc821Table);
1032 1032
 							if(body) {
1033
-								t = messageToText(body);
1033
+								assert(aMessage == messages[i]);
1034
+								messageDestroy(messages[i]);
1035
+								messages[i] = NULL;
1034 1036
 
1035
-								rc = parseEmailBody(body, blobs, nBlobs, t, dir, rfc821Table, subtypeTable);
1036
-								cli_dbgmsg("Finished recursion\n");
1037
-								textDestroy(t);
1038 1037
 								if(mainMessage && (mainMessage != messageIn))
1039 1038
 									messageDestroy(mainMessage);
1040 1039
 
1040
+								t = messageToText(body);
1041
+								rc = parseEmailBody(body, blobs, nBlobs, t, dir, rfc821Table, subtypeTable);
1042
+								textDestroy(t);
1043
+
1044
+								cli_dbgmsg("Finished recursion\n");
1045
+
1041 1046
 								mainMessage = body;
1042 1047
 							}
1043 1048
 						} else {
... ...
@@ -1213,46 +1227,6 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1213 1213
 			}
1214 1214
 			if((strcasecmp(mimeSubtype, "rfc822") == 0) ||
1215 1215
 			   (strcasecmp(mimeSubtype, "delivery-status") == 0)) {
1216
-#if	0
1217
-				/*
1218
-				 * Found a message encapsulated within
1219
-				 * another message
1220
-				 *
1221
-				 * Thomas Lamy <Thomas.Lamy@in-online.net>:
1222
-				 * ensure t is correctly freed
1223
-				 */
1224
-				text *t, *msgText = messageToText(mainMessage);
1225
-				message *m, *body;
1226
-
1227
-				t = msgText;
1228
-				assert(t != NULL);
1229
-
1230
-				m = messageCreate();
1231
-				assert(m != NULL);
1232
-
1233
-				do {
1234
-					/*char *buffer = strdup(t->t_text);
1235
-
1236
-					cli_chomp(buffer);
1237
-					messageAddLine(m, buffer);
1238
-					free(buffer);*/
1239
-					messageAddLine(m, t->t_text);
1240
-				} while((t = t->t_next) != NULL);
1241
-
1242
-				textDestroy(msgText);
1243
-
1244
-				body = parseEmailHeaders(m, rfc821Table);
1245
-
1246
-				messageDestroy(m);
1247
-				m = body;
1248
-
1249
-				messageClean(m);
1250
-
1251
-				if(messageGetBody(m))
1252
-					rc = parseEmailBody(m, NULL, 0, NULL, dir, rfc821Table, subtypeTable);
1253
-
1254
-				messageDestroy(m);
1255
-#else
1256 1216
 				message *m = parseEmailHeaders(mainMessage, rfc821Table);
1257 1217
 				if(m) {
1258 1218
 					cli_dbgmsg("Decode rfc822");
... ...
@@ -1264,8 +1238,6 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1264 1264
 
1265 1265
 					messageDestroy(m);
1266 1266
 				}
1267
-#endif
1268
-
1269 1267
 				break;
1270 1268
 			} else if(strcasecmp(mimeSubtype, "partial") == 0)
1271 1269
 				/* TODO */