/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto & The Sylpheed-Claws Team
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto & The Sylpheed-Claws 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
#include <glib/gi18n.h>
#include <stdio.h>
#include <string.h>
-#include <locale.h>
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
outfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename);
if (!outfp) {
perror("tmpfile");
+ fclose(infp);
return FALSE;
}
tmp_file = TRUE;
if (!tmpfp) {
perror("tmpfile");
if (tmp_file) fclose(outfp);
+ fclose(infp);
return FALSE;
}
}
dup2(oldout, 1);
/* CodeConverter seems to have no effect here */
} else if (mimeinfo->type == MIMETYPE_TEXT && !g_ascii_strcasecmp(mimeinfo->subtype, "html")) {
- HTMLParser *parser;
+ SC_HTMLParser *parser;
CodeConverter *conv;
conv = conv_code_converter_new(src_codeset);
- parser = html_parser_new(tmpfp, conv);
- while ((str = html_parse(parser)) != NULL) {
+ parser = sc_html_parser_new(tmpfp, conv);
+ while ((str = sc_html_parse(parser)) != NULL) {
fputs(str, outfp);
}
- html_parser_destroy(parser);
+ sc_html_parser_destroy(parser);
conv_code_converter_destroy(conv);
} else if (mimeinfo->type == MIMETYPE_TEXT && !g_ascii_strcasecmp(mimeinfo->subtype, "enriched")) {
ERTFParser *parser;
return ENC_8BIT;
}
-EncodingType procmime_get_encoding_for_text_file(const gchar *file)
+EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *has_binary)
{
FILE *fp;
guchar buf[BUFFSIZE];
size_t octet_chars = 0;
size_t total_len = 0;
gfloat octet_percentage;
+ gboolean force_b64 = FALSE;
if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
for (p = buf, i = 0; i < len; ++p, ++i) {
if (*p & 0x80)
++octet_chars;
+ if (*p == '\0') {
+ force_b64 = TRUE;
+ *has_binary = TRUE;
+ }
}
total_len += len;
}
"8bit chars: %d / %d (%f%%)\n", octet_chars, total_len,
100.0 * octet_percentage);
- if (octet_percentage > 0.20) {
+ if (octet_percentage > 0.20 || force_b64) {
debug_print("using BASE64\n");
return ENC_BASE64;
} else if (octet_chars > 0) {