+/*
+ * this is the extract of mime_decode which can be called if 'dont_decode' was set;
+ * to save the cpu intense process of decoding to the time when it realy wants the content.
+ * returns:
+ * - > 0 we decoded something, its on *decoded, you need to free it.
+ * - = 0 no need to decode stuff. *decoded will be NULL.
+ * - < 0 an error occured, either an unknown encoding, or alloc failed. no need to free.
+ */
+int mime_decode_now (char *part_start,
+ size_t length,
+ char *encoding,
+ char **decoded,
+ size_t *bytes_decoded)
+{
+ *bytes_decoded = 0;
+ *decoded = NULL;
+ /* Some encodings aren't really encodings */
+ if (!strcasecmp(encoding, "7bit"))
+ strcpy(encoding, "");
+ if (!strcasecmp(encoding, "8bit"))
+ strcpy(encoding, "");
+ if (!strcasecmp(encoding, "binary"))
+ strcpy(encoding, "");
+
+ /* If this part is not encoded, send as-is */
+ if (strlen(encoding) == 0) {
+ return 0;
+ }
+
+
+ /* Fail if we hit an unknown encoding. */
+ if ((strcasecmp(encoding, "base64"))
+ && (strcasecmp(encoding, "quoted-printable"))) {
+ return -1;
+ }
+
+ /*
+ * Allocate a buffer for the decoded data. The output buffer is slightly
+ * larger than the input buffer; this assumes that the decoded data
+ * will never be significantly larger than the encoded data. This is a
+ * safe assumption with base64, uuencode, and quoted-printable.
+ */
+ *decoded = malloc(length + 32768);
+ if (decoded == NULL) {
+ return -1;
+ }
+
+ if (!strcasecmp(encoding, "base64")) {
+ *bytes_decoded = CtdlDecodeBase64(*decoded, part_start, length);
+ return 1;
+ }
+ else if (!strcasecmp(encoding, "quoted-printable")) {
+ *bytes_decoded = CtdlDecodeQuotedPrintable(*decoded, part_start, length);
+ return 1;
+ }
+ return -1;
+}
+
+