/*
* 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
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#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;
if (basetmp == NULL)
basetmp = "mimetmp";
basetmp = g_path_get_basename(basetmp);
- if (*basetmp == '\0') basetmp = g_strdup("mimetmp");
+ if (*basetmp == '\0')
+ basetmp = g_strdup("mimetmp");
base = conv_filename_from_utf8(basetmp);
+ g_free((gchar*)basetmp);
subst_for_shellsafe_filename(base);
}
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) {
value[0] = '\0';
value++;
+ while (value[0] == ' ')
+ value++;
g_strdown(attribute);
*tmp = '\0';
}
+ if (attribute) {
+ while (attribute[0] == ' ')
+ attribute++;
+ while (attribute[strlen(attribute)-1] == ' ')
+ attribute[strlen(attribute)-1] = '\0';
+ }
+ if (value) {
+ while (value[0] == ' ')
+ value++;
+ while (value[strlen(value)-1] == ' ')
+ value[strlen(value)-1] = '\0';
+ }
if (strrchr(attribute, '*') != NULL) {
gchar *tmpattr;