/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto & The Claws Mail Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
{
gchar *filename;
MimeInfo *mimeinfo;
- START_TIMING("");
- filename = procmsg_get_message_file_path(msginfo);
+
+ filename = procmsg_get_message_file_path(msginfo);
if (!filename || !is_file_exist(filename)) {
g_free(filename);
return NULL;
mimeinfo = procmime_scan_queue_file(filename);
g_free(filename);
- END_TIMING();
return mimeinfo;
}
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);
}
return 0;
}
-static FILE *procmime_get_text_content(MimeInfo *mimeinfo)
+FILE *procmime_get_text_content(MimeInfo *mimeinfo)
{
FILE *tmpfp, *outfp;
const gchar *src_codeset;
? 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;
return outfp;
}
+FILE *procmime_get_binary_content(MimeInfo *mimeinfo)
+{
+ FILE *outfp;
+ gchar *tmpfile;
+
+ cm_return_val_if_fail(mimeinfo != NULL, NULL);
+
+ if (!procmime_decode_content(mimeinfo))
+ return NULL;
+
+ tmpfile = procmime_get_tmp_file_name(mimeinfo);
+ if (tmpfile == NULL)
+ return NULL;
+
+ if (procmime_get_part(tmpfile, mimeinfo) < 0) {
+ g_free(tmpfile);
+ return NULL;
+ }
+
+ outfp = g_fopen(tmpfile, "rb");
+ if (outfp == NULL) {
+ g_unlink(tmpfile);
+ g_free(tmpfile);
+ return NULL;
+ }
+
+ g_unlink(tmpfile);
+ g_free(tmpfile);
+
+ return outfp;
+}
+
/* search the first text part of (multipart) MIME message,
decode, convert it and output to outfp. */
FILE *procmime_get_first_text_content(MsgInfo *msginfo)
FILE *outfp = NULL;
MimeInfo *mimeinfo, *partinfo;
gboolean empty_ok = FALSE, short_scan = TRUE;
- START_TIMING("");
- cm_return_val_if_fail(msginfo != NULL, NULL);
+
+ cm_return_val_if_fail(msginfo != NULL, NULL);
/* first we try to short-scan (for speed), refusing empty parts */
scan_again:
goto scan_again;
}
procmime_mimeinfo_free_all(mimeinfo);
- END_TIMING();
return outfp;
}
return result;
}
-static gboolean procmime_find_string_part(MimeInfo *mimeinfo, const gchar *filename,
- const gchar *str, StrFindFunc find_func)
-{
- FILE *outfp;
- gchar buf[BUFFSIZE];
-
- cm_return_val_if_fail(mimeinfo != NULL, FALSE);
- cm_return_val_if_fail(mimeinfo->type == MIMETYPE_TEXT, FALSE);
- cm_return_val_if_fail(str != NULL, FALSE);
- cm_return_val_if_fail(find_func != NULL, FALSE);
-
- outfp = procmime_get_text_content(mimeinfo);
-
- if (!outfp)
- return FALSE;
-
- while (fgets(buf, sizeof(buf), outfp) != NULL) {
- strretchomp(buf);
- if (find_func(buf, str)) {
- fclose(outfp);
- return TRUE;
- }
- }
-
- fclose(outfp);
-
- return FALSE;
-}
-
-gboolean procmime_find_string(MsgInfo *msginfo, const gchar *str,
- StrFindFunc find_func)
-{
- MimeInfo *mimeinfo;
- MimeInfo *partinfo;
- gchar *filename;
- gboolean found = FALSE;
-
- cm_return_val_if_fail(msginfo != NULL, FALSE);
- cm_return_val_if_fail(str != NULL, FALSE);
- cm_return_val_if_fail(find_func != NULL, FALSE);
-
- filename = procmsg_get_message_file(msginfo);
- if (!filename) return FALSE;
- mimeinfo = procmime_scan_message(msginfo);
-
- for (partinfo = mimeinfo; partinfo != NULL;
- partinfo = procmime_mimeinfo_next(partinfo)) {
- if (partinfo->type == MIMETYPE_TEXT) {
- if (procmime_find_string_part
- (partinfo, filename, str, find_func) == TRUE) {
- found = TRUE;
- break;
- }
- }
- }
-
- procmime_mimeinfo_free_all(mimeinfo);
- g_free(filename);
-
- return found;
-}
-
gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo)
{
static guint32 id = 0;
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;
}
} else {
procheader_get_header_fields(fp, hentry);
}
+
+ fclose(fp);
- if (!hentry[0].body || !hentry[1].body) {
+ if (!hentry[0].body || !hentry[1].body) {
debug_print("MsgId %s, Disp %s\n",
hentry[0].body ? hentry[0].body:"(nil)",
hentry[1].body ? hentry[1].body:"(nil)");
#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; \
} \
dstpos++;
}
*dstpos = '\0';
+ if (value[0] == '"')
+ extract_quote(value, '"');
} else {
if (value[0] == '"')
extract_quote(value, '"');
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);