*
* This is the MIME parser for Citadel. Sometimes it actually works.
*
- * Copyright (c) 1998-2001 by Art Cancro
+ * Copyright (c) 1998-2002 by Art Cancro
* This code is distributed under the terms of the GNU General Public License.
*
*/
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
-#include <pthread.h>
#include "webcit.h"
-#include "mime_parser.h"
void extract_key(char *target, char *source, char *key)
char *decoded;
size_t bytes_decoded = 0;
+ fprintf(stderr, "mime_decode() called\n");
+
/* Some encodings aren't really encodings */
if (!strcasecmp(encoding, "7bit"))
strcpy(encoding, "");
}
return;
}
+
if ((strcasecmp(encoding, "base64"))
&& (strcasecmp(encoding, "quoted-printable"))) {
fprintf(stderr, "ERROR: unknown MIME encoding '%s'\n", encoding);
* Allocate a buffer for the decoded data. The output buffer is the
* same size as the input buffer; this assumes that the decoded data
* will never be larger than the encoded data. This is a safe
- * assumption with base64, uuencode, and quoted-printable. Just to
- * be safe, we still pad the buffer a bit.
+ * assumption with base64, uuencode, and quoted-printable.
*/
- decoded = malloc(length + 1024);
+ fprintf(stderr, "About to allocate %d bytes for decoded part\n",
+ length+2048);
+ decoded = malloc(length+2048);
if (decoded == NULL) {
fprintf(stderr, "ERROR: cannot allocate memory.\n");
return;
}
+ fprintf(stderr, "Got it!\n");
+ fprintf(stderr, "Decoding %s\n", encoding);
if (!strcasecmp(encoding, "base64")) {
bytes_decoded = decode_base64(decoded, part_start);
}
bytes_decoded = decode_quoted_printable(decoded,
part_start, length);
}
+ fprintf(stderr, "Bytes decoded: %d\n", bytes_decoded);
if (bytes_decoded > 0) if (CallBack != NULL) {
CallBack(name, filename, fixed_partnum(partnum),
free(decoded);
}
-
-
-
/*
* Break out the components of a multipart message
* (This function expects to be fed HEADERS + CONTENT)
/* Learn interesting things from the headers */
strcpy(header, "");
do {
- ptr = memreadline(ptr, buf, sizeof buf);
+ ptr = memreadline(ptr, buf, SIZ);
if (ptr >= content_end) {
goto end_parser;
}
extract_key(boundary, header, "boundary");
strcpy(header, "");
}
- if ((strlen(header) + strlen(buf) + 2) < sizeof(header))
+ if ((strlen(header) + strlen(buf) + 2) < SIZ)
strcat(header, buf);
} while ((strlen(buf) > 0) && (*ptr != 0));
userdata,
dont_decode);
}
- ptr = memreadline(ptr, buf, sizeof(buf));
+ ptr = memreadline(ptr, buf, SIZ);
part_start = ptr;
}
else {
-
-
-
-
/*
* Entry point for the MIME parser.
* (This function expects to be fed HEADERS + CONTENT)