FLUSH_LASTLINE();
} else if (encoding == ENC_BASE64) {
gchar outbuf[BUFFSIZE];
- gint len;
+ gint len, inlen, inread;
Base64Decoder *decoder;
gboolean got_error = FALSE;
gboolean uncanonicalize = FALSE;
FILE *tmpfp = outfp;
+ gboolean null_bytes = FALSE;
+ gboolean starting = TRUE;
if (mimeinfo->type == MIMETYPE_TEXT ||
mimeinfo->type == MIMETYPE_MESSAGE) {
}
decoder = base64_decoder_new();
- while ((ftell(infp) < readend) && (fgets(buf, sizeof(buf), infp) != NULL)) {
- len = base64_decoder_decode(decoder, buf, outbuf);
- if (len < 0 && !got_error) {
+ while ((inlen = MIN(readend - ftell(infp), sizeof(buf))) > 0 && !err) {
+ inread = fread(buf, 1, inlen, infp);
+ len = base64_decoder_decode(decoder, buf, outbuf, inread);
+ if (uncanonicalize == TRUE && strlen(outbuf) < len && starting) {
+ uncanonicalize = FALSE;
+ null_bytes = TRUE;
+ }
+ starting = FALSE;
+ if (((inread != inlen) || len < 0) && !got_error) {
g_warning("Bad BASE64 content.\n");
if (fwrite(_("[Error decoding BASE64]\n"),
sizeof(gchar),
} else if (len >= 0) {
/* print out the error message only once
* per block */
- if (fwrite(outbuf, sizeof(gchar), len, tmpfp) < len)
- err = TRUE;
+ if (null_bytes) {
+ /* we won't uncanonicalize, output to outfp directly */
+ if (fwrite(outbuf, sizeof(gchar), len, outfp) < len)
+ err = TRUE;
+ } else {
+ if (fwrite(outbuf, sizeof(gchar), len, tmpfp) < len)
+ err = TRUE;
+ }
got_error = FALSE;
}
}
while ((restlength > 0) && ((readlength = fread(buf, 1, restlength > BUFFSIZE ? BUFFSIZE : restlength, infp)) > 0)) {
if (fwrite(buf, 1, readlength, outfp) != readlength) {
saved_errno = errno;
+ fclose(infp);
fclose(outfp);
return -(saved_errno);
}
? forced_charset :
procmime_mimeinfo_get_parameter(mimeinfo, "charset");
+ /* use supersets transparently when possible */
if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_ISO_8859_1))
src_codeset = CS_WINDOWS_1252;
+ else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_X_GBK))
+ src_codeset = CS_GB18030;
+ else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_GBK))
+ src_codeset = CS_GB18030;
+ else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_GB2312))
+ src_codeset = CS_GB18030;
if (mimeinfo->type == MIMETYPE_TEXT && !g_ascii_strcasecmp(mimeinfo->subtype, "html")) {
SC_HTMLParser *parser;
fseek(fp, mimeinfo->offset, SEEK_SET);
procheader_get_header_fields(fp, hentry);
if (hentry[0].body != NULL) {
- tmp = conv_unmime_header(hentry[0].body, NULL);
+ tmp = conv_unmime_header(hentry[0].body, NULL, FALSE);
g_free(hentry[0].body);
hentry[0].body = tmp;
}
if (hentry[2].body != NULL) {
- tmp = conv_unmime_header(hentry[2].body, NULL);
+ tmp = conv_unmime_header(hentry[2].body, NULL, FALSE);
g_free(hentry[2].body);
hentry[2].body = tmp;
}
if (hentry[4].body != NULL) {
- tmp = conv_unmime_header(hentry[4].body, NULL);
+ tmp = conv_unmime_header(hentry[4].body, NULL, FALSE);
g_free(hentry[4].body);
hentry[4].body = tmp;
}
if (hentry[5].body != NULL) {
- tmp = conv_unmime_header(hentry[5].body, NULL);
+ tmp = conv_unmime_header(hentry[5].body, NULL, FALSE);
g_free(hentry[5].body);
hentry[5].body = tmp;
}
if (hentry[7].body != NULL) {
- tmp = conv_unmime_header(hentry[7].body, NULL);
+ tmp = conv_unmime_header(hentry[7].body, NULL, FALSE);
g_free(hentry[7].body);
hentry[7].body = tmp;
}
if (hentry[8].body != NULL) {
- tmp = conv_unmime_header(hentry[8].body, NULL);
+ tmp = conv_unmime_header(hentry[8].body, NULL, FALSE);
g_free(hentry[8].body);
hentry[8].body = tmp;
}
#define GET_HEADERS() { \
procheader_get_header_fields(fp, hentry); \
if (hentry[0].body != NULL) { \
- tmp = conv_unmime_header(hentry[0].body, NULL); \
+ tmp = conv_unmime_header(hentry[0].body, NULL, FALSE); \
g_free(hentry[0].body); \
hentry[0].body = tmp; \
} \
if (hentry[2].body != NULL) { \
- tmp = conv_unmime_header(hentry[2].body, NULL); \
+ tmp = conv_unmime_header(hentry[2].body, NULL, FALSE); \
g_free(hentry[2].body); \
hentry[2].body = tmp; \
} \
if (hentry[4].body != NULL) { \
- tmp = conv_unmime_header(hentry[4].body, NULL); \
+ tmp = conv_unmime_header(hentry[4].body, NULL, FALSE); \
g_free(hentry[4].body); \
hentry[4].body = tmp; \
} \
if (hentry[5].body != NULL) { \
- tmp = conv_unmime_header(hentry[5].body, NULL); \
+ tmp = conv_unmime_header(hentry[5].body, NULL, FALSE); \
g_free(hentry[5].body); \
hentry[5].body = tmp; \
} \
if (hentry[6].body != NULL) { \
- tmp = conv_unmime_header(hentry[6].body, NULL); \
+ tmp = conv_unmime_header(hentry[6].body, NULL, FALSE); \
g_free(hentry[6].body); \
hentry[6].body = tmp; \
} \
if (hentry[7].body != NULL) { \
- tmp = conv_unmime_header(hentry[7].body, NULL); \
+ tmp = conv_unmime_header(hentry[7].body, NULL, FALSE); \
g_free(hentry[7].body); \
hentry[7].body = tmp; \
} \
/* Create MimeInfo */
mimeinfo = procmime_mimeinfo_new();
mimeinfo->content = MIMECONTENT_FILE;
- mimeinfo->lax_parse = parent->lax_parse;
if (parent != NULL) {
if (g_node_depth(parent->node) > 32) {
g_string_append_printf(buf, "%%%s", hexstr);
}
}
- break;
+ break;
+#else
+ case ENC_AS_EXTENDED:
+ debug_print("Unhandled ENC_AS_EXTENDED.");
+ break;
#endif
case ENC_AS_ENCWORD:
len = MAX(strlen(val)*6, 512);