Browse code

FOLLOWURLS now compiled if libcurl is found

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

Nigel Horne authored on 2004/09/20 17:31:56
Showing 1 changed files
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.132  2004/09/20 08:31:56  nigelhorne
21
+ * FOLLOWURLS now compiled if libcurl is found
22
+ *
20 23
  * Revision 1.131  2004/09/18 14:59:25  nigelhorne
21 24
  * Code tidy
22 25
  *
... ...
@@ -381,7 +384,7 @@
381 381
  * Compilable under SCO; removed duplicate code with message.c
382 382
  *
383 383
  */
384
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.131 2004/09/18 14:59:25 nigelhorne Exp $";
384
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.132 2004/09/20 08:31:56 nigelhorne Exp $";
385 385
 
386 386
 #if HAVE_CONFIG_H
387 387
 #include "clamav-config.h"
... ...
@@ -459,10 +462,16 @@ typedef enum	{ FALSE = 0, TRUE = 1 } bool;
459 459
 
460 460
 #define	SAVE_TO_DISC	/* multipart/message are saved in a temporary file */
461 461
 
462
-/*#define	FOLLOWURLS	/*
462
+/*
463
+ * Code does exist to run FOLLORURLS on systems without libcurl, however that
464
+ * is not recommended so it is not compiled by default
465
+ */
466
+#ifdef	WITH_CURL
467
+#define	FOLLOWURLS	/*
463 468
 			 * If an email contains URLs, check them - helps to
464 469
 			 * find Dialer.gen-45
465 470
 			 */
471
+#endif
466 472
 
467 473
 #ifdef	FOLLOWURLS
468 474
 
... ...
@@ -2101,14 +2110,20 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2101 2101
 	cli_dbgmsg("parseMimeHeader: cmd='%s', arg='%s'\n", cmd, arg);
2102 2102
 
2103 2103
 	ptr = rfc822comments(cmd);
2104
-	commandNumber = tableFind(rfc821Table, ptr);
2105
-	free(ptr);
2104
+	if(ptr) {
2105
+		commandNumber = tableFind(rfc821Table, ptr);
2106
+		free(ptr);
2107
+	} else
2108
+		commandNumber = tableFind(rfc821Table, cmd);
2106 2109
 
2107 2110
 	copy = rfc822comments(arg);
2108
-	ptr = copy;
2111
+	if(copy == NULL)
2112
+		copy = strdup(arg);
2109 2113
 	if(copy == NULL)
2110 2114
 		return -1;
2111 2115
 
2116
+	ptr = copy;
2117
+
2112 2118
 	switch(commandNumber) {
2113 2119
 		case CONTENT_TYPE:
2114 2120
 			/*
... ...
@@ -2149,11 +2164,6 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2149 2149
 					messageSetMimeType(m, "application");
2150 2150
 					messageSetMimeSubtype(m, "octet-stream");
2151 2151
 				} else {
2152
-					char *s;
2153
-					char *mimeType;	/* LHS of the ; */
2154
-					size_t len;
2155
-
2156
-					s = mimeType = cli_strtok(copy, 0, ";");
2157 2152
 					/*
2158 2153
 					 * The content type could be in quotes:
2159 2154
 					 *	Content-Type: "multipart/mixed"
... ...
@@ -2161,12 +2171,16 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2161 2161
 					 *	the quotes, it doesn't handle
2162 2162
 					 *	them properly
2163 2163
 					 */
2164
-					while(isspace(*s))
2165
-						s++;
2166
-					if(s[0] == '\"')
2167
-						s++;
2164
+					while(isspace(*copy))
2165
+						copy++;
2166
+					if(copy[0] == '\"')
2167
+						copy++;
2168
+
2169
+					if(copy[0] != '/') {
2170
+						char *s;
2171
+						char *mimeType;	/* LHS of the ; */
2168 2172
 
2169
-					if(s[0] != '/')
2173
+						s = mimeType = cli_strtok(copy, 0, ";");
2170 2174
 						/*
2171 2175
 						 * Handle
2172 2176
 						 * Content-Type: foo/bar multipart/mixed
... ...
@@ -2187,16 +2201,19 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2187 2187
 							if(s == NULL)
2188 2188
 								break;
2189 2189
 							if(set) {
2190
-								len = strstrip(s) - 1;
2190
+								size_t len = strstrip(s) - 1;
2191 2191
 								if(s[len] == '\"') {
2192 2192
 									s[len] = '\0';
2193 2193
 									len = strstrip(s);
2194 2194
 								}
2195 2195
 								if(len) {
2196
-									char *t = cli_strtok(s, 0, " ");
2196
+									if(strchr(s, ' ')) {
2197
+										char *t = cli_strtok(s, 0, " ");
2197 2198
 
2198
-									messageSetMimeSubtype(m, t);
2199
-									free(t);
2199
+										messageSetMimeSubtype(m, t);
2200
+										free(t);
2201
+									} else
2202
+										messageSetMimeSubtype(m, s);
2200 2203
 								}
2201 2204
 							}
2202 2205
 
... ...
@@ -2207,7 +2224,8 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2207 2207
 							if(*s == '\0')
2208 2208
 								break;
2209 2209
 						}
2210
-					free(mimeType);
2210
+						free(mimeType);
2211
+					}
2211 2212
 				}
2212 2213
 
2213 2214
 				/*
... ...
@@ -2257,8 +2275,10 @@ saveTextPart(message *m, const char *dir)
2257 2257
 }
2258 2258
 
2259 2259
 /*
2260
- * Handle RFC822 comments in headers. Returns a malloc'd buffer that the
2261
- * caller must free, or NULL on error. See seciont 3.4.3 of RFC822
2260
+ * Handle RFC822 comments in headers.
2261
+ * Returns a buffer without the comments or NULL on error or if the input
2262
+ * has no comments. The caller must free the returned buffer
2263
+ * See secion 3.4.3 of RFC822
2262 2264
  * TODO: handle comments that go on to more than one line
2263 2265
  */
2264 2266
 static char *
... ...
@@ -2269,10 +2289,10 @@ rfc822comments(const char *in)
2269 2269
 	int backslash, inquote, commentlevel;
2270 2270
 
2271 2271
 	if(in == NULL)
2272
-		in = "";
2272
+		return NULL;
2273 2273
 
2274 2274
 	if(strchr(in, '(') == NULL)
2275
-		return strdup(in);
2275
+		return NULL;
2276 2276
 
2277 2277
 	out = cli_malloc(strlen(in) + 1);
2278 2278
 	if(out == NULL)