Tidy up multipart handling

git-svn: trunk@723
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 058ccefea5
commit f12d249838
  1. 4
      clamav-devel/ChangeLog
  2. 57
      clamav-devel/libclamav/mbox.c
  3. 15
      clamav-devel/libclamav/message.c

@ -1,3 +1,7 @@
Wed Aug 4 19:59:54 BST 2004 (njh)
----------------------------------
* libclamav: Improved the decoding of multipart messages and MIME headers
Wed Aug 4 20:01:26 CEST 2004 (tk)
----------------------------------
* libclamav: fix compilation error with Sun's compiler (reported by

@ -17,6 +17,9 @@
*
* Change History:
* $Log: mbox.c,v $
* Revision 1.91 2004/08/04 18:59:19 nigelhorne
* Tidy up multipart handling
*
* Revision 1.90 2004/07/26 17:02:56 nigelhorne
* Fix crash when debugging on SPARC
*
@ -258,7 +261,7 @@
* Compilable under SCO; removed duplicate code with message.c
*
*/
static char const rcsid[] = "$Id: mbox.c,v 1.90 2004/07/26 17:02:56 nigelhorne Exp $";
static char const rcsid[] = "$Id: mbox.c,v 1.91 2004/08/04 18:59:19 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -601,7 +604,6 @@ cli_mbox(const char *dir, int desc)
static message *
parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
{
bool inContinuationHeader = FALSE; /* state machine: ugh */
bool inHeader = TRUE;
text *t;
message *ret;
@ -640,13 +642,7 @@ parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
* a continuation of the previous entry.
*/
if(inHeader && buffer &&
((buffer[0] == '\t') || (buffer[0] == ' ')))
inContinuationHeader = TRUE;
if(inContinuationHeader) {
if(!continuationMarker(buffer))
inContinuationHeader = FALSE; /* no more args */
((buffer[0] == '\t') || (buffer[0] == ' '))) {
/*
* Add all the arguments on the line
*/
@ -664,11 +660,11 @@ parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
*/
if(buffer == NULL) {
cli_dbgmsg("End of header information\n");
inContinuationHeader = inHeader = FALSE;
} else if(parseEmailHeader(ret, buffer, rfc821Table) == CONTENT_TYPE)
inContinuationHeader = continuationMarker(buffer);
if(buffer)
inHeader = FALSE;
} else {
(void)parseEmailHeader(ret, buffer, rfc821Table);
free(buffer);
}
} else {
/*cli_dbgmsg("Add line to body '%s'\n", buffer);*/
if(messageAddLine(ret, buffer, 0) < 0)
@ -731,8 +727,7 @@ parseEmailHeader(message *m, const char *line, const table_t *rfc821Table)
* This function parses the body of mainMessage and saves its attachments in dir
*
* mainMessage is the buffer to be parsed, it contains an e-mail's body, without
* any headers. First
* time of calling it'll be
* any headers. First time of calling it'll be
* the whole message. Later it'll be parts of a multipart message
* textIn is the plain text message being built up so far
* blobsIn contains the array of attachments found so far
@ -876,10 +871,8 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
message **m;
m = cli_realloc(messages, ((multiparts + 1) * sizeof(message *)));
if(m == NULL) {
multiparts--;
if(m == NULL)
break;
}
messages = m;
aMessage = messages[multiparts] = messageCreate();
@ -1164,7 +1157,9 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
bool addAttachment = FALSE;
bool addToText = FALSE;
const char *dtype;
#if 0
message *body;
#endif
aMessage = messages[i];
@ -1320,6 +1315,7 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
* be an attachment
*/
cli_dbgmsg("Found multipart inside multipart\n");
#if 0
if(aMessage) {
body = parseEmailHeaders(aMessage, rfc821Table, TRUE);
if(body) {
@ -1339,6 +1335,18 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
mainMessage = body;
}
#else
if(aMessage) {
/*
* The headers were parsed when reading in the
* whole multipart section
*/
rc = parseEmailBody(aMessage, blobs, nBlobs, aText, dir, rfc821Table, subtypeTable);
cli_dbgmsg("Finished recursion\n");
assert(aMessage == messages[i]);
messageDestroy(messages[i]);
messages[i] = NULL;
#endif
} else {
rc = parseEmailBody(NULL, blobs, nBlobs, NULL, dir, rfc821Table, subtypeTable);
if(mainMessage && (mainMessage != messageIn))
@ -1598,6 +1606,11 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
}
}
if(aText && (textIn == NULL)) {
textDestroy(aText);
aText = NULL;
}
cli_dbgmsg("%d attachments found\n", nBlobs);
if(nBlobs == 0) {
@ -1719,6 +1732,9 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
if(saveIt) {
cli_dbgmsg("Saving text part to scan\n");
/*
* TODO: May be better to save aText
*/
saveTextPart(mainMessage, dir);
}
}
@ -1739,9 +1755,6 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
}
}
if(aText && (textIn == NULL))
textDestroy(aText);
/* Already done */
if(blobs && (blobsIn == NULL))
blobArrayDestroy(blobs, nBlobs);
@ -1980,7 +1993,7 @@ continuationMarker(const char *line)
static int
parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg)
{
int type = tableFind(rfc821Table, cmd);
const int type = tableFind(rfc821Table, cmd);
#ifdef CL_THREAD_SAFE
char *strptr;
#endif

@ -17,6 +17,9 @@
*
* Change History:
* $Log: message.c,v $
* Revision 1.69 2004/08/04 18:59:19 nigelhorne
* Tidy up multipart handling
*
* Revision 1.68 2004/07/30 11:50:39 nigelhorne
* Code tidy
*
@ -201,7 +204,7 @@
* uuencodebegin() no longer static
*
*/
static char const rcsid[] = "$Id: message.c,v 1.68 2004/07/30 11:50:39 nigelhorne Exp $";
static char const rcsid[] = "$Id: message.c,v 1.69 2004/08/04 18:59:19 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -658,12 +661,22 @@ messageAddArguments(message *m, const char *s)
*ptr = '\0';
#if 0
field = cli_malloc(strlen(key) + strlen(data) + 2);
if(field)
sprintf(field, "%s=%s", key, data);
free((char *)key);
free(data);
#else
field = cli_realloc((char *)key, strlen(key) + strlen(data) + 2);
if(field) {
strcat(field, "=");
strcat(field, data);
} else
free((char *)key);
free(data);
#endif
} else {
size_t len;

Loading…
Cancel
Save