/*
* 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>
g_free(mimeinfo->subtype);
g_free(mimeinfo->description);
g_free(mimeinfo->id);
+ g_free(mimeinfo->location);
g_hash_table_foreach_remove(mimeinfo->typeparameters,
procmime_mimeinfo_parameters_destroy, NULL);
g_node_destroy(node);
}
-#if 0 /* UNUSED */
-MimeInfo *procmime_mimeinfo_insert(MimeInfo *parent, MimeInfo *mimeinfo)
-{
- MimeInfo *child = parent->children;
-
- if (!child)
- parent->children = mimeinfo;
- else {
- while (child->next != NULL)
- child = child->next;
-
- child->next = mimeinfo;
- }
-
- mimeinfo->parent = parent;
- mimeinfo->level = parent->level + 1;
-
- return mimeinfo;
-}
-
-void procmime_mimeinfo_replace(MimeInfo *old, MimeInfo *new)
-{
- MimeInfo *parent = old->parent;
- MimeInfo *child;
-
- g_return_if_fail(parent != NULL);
- g_return_if_fail(new->next == NULL);
-
- for (child = parent->children; child && child != old;
- child = child->next)
- ;
- if (!child) {
- g_warning("oops: parent can't find it's own child");
- return;
- }
- procmime_mimeinfo_free_all(old);
-
- if (child == parent->children) {
- new->next = parent->children->next;
- parent->children = new;
- } else {
- new->next = child->next;
- child = new;
- }
-}
-#endif
-
MimeInfo *procmime_mimeinfo_parent(MimeInfo *mimeinfo)
{
g_return_val_if_fail(mimeinfo != NULL, NULL);
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;
}
}
stat(tmpfilename, &statbuf);
if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
g_unlink(mimeinfo->data.filename);
- if (mimeinfo->data.filename != NULL)
- g_free(mimeinfo->data.filename);
+ g_free(mimeinfo->data.filename);
mimeinfo->data.filename = tmpfilename;
mimeinfo->tmp = TRUE;
mimeinfo->offset = 0;
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) {
return g_strdup_printf("%s/%s", type_str, subtype);
}
-int procmime_parse_mimepart(MimeInfo *parent,
+static int procmime_parse_mimepart(MimeInfo *parent,
gchar *content_type,
gchar *content_encoding,
gchar *content_description,
gchar *content_id,
gchar *content_disposition,
+ gchar *content_location,
const gchar *filename,
guint offset,
guint length);
NULL, TRUE},
{"Content-Disposition:",
NULL, TRUE},
+ {"Content-Location:",
+ NULL, TRUE},
{"MIME-Version:",
NULL, TRUE},
{NULL, NULL, FALSE}};
g_free(hentry[4].body);
hentry[4].body = tmp;
}
+ if (hentry[5].body != NULL) {
+ tmp = conv_unmime_header(hentry[5].body, NULL);
+ g_free(hentry[5].body);
+ hentry[5].body = tmp;
+ }
content_start = ftell(fp);
fclose(fp);
procmime_parse_mimepart(mimeinfo,
hentry[0].body, hentry[1].body,
hentry[2].body, hentry[3].body,
- hentry[4].body,
+ hentry[4].body, hentry[5].body,
mimeinfo->data.filename, content_start,
mimeinfo->length - (content_start - mimeinfo->offset));
NULL, TRUE},
{"Content-Disposition:",
NULL, TRUE},
+ {"Content-Location:",
+ NULL, TRUE},
{NULL, NULL, FALSE}};
gchar *p, *tmp;
gchar *boundary;
result = procmime_parse_mimepart(mimeinfo,
hentry[0].body, hentry[1].body,
hentry[2].body, hentry[3].body,
- hentry[4].body,
+ hentry[4].body, hentry[5].body,
mimeinfo->data.filename, lastoffset,
(ftell(fp) - strlen(buf)) - lastoffset - 1);
}
g_free(hentry[4].body);
hentry[4].body = tmp;
}
+ if (hentry[5].body != NULL) {
+ tmp = conv_unmime_header(hentry[5].body, NULL);
+ g_free(hentry[5].body);
+ hentry[5].body = tmp;
+ }
lastoffset = ftell(fp);
}
}
return;
}
-int procmime_parse_mimepart(MimeInfo *parent,
+static int procmime_parse_mimepart(MimeInfo *parent,
gchar *content_type,
gchar *content_encoding,
gchar *content_description,
gchar *content_id,
gchar *content_disposition,
+ gchar *content_location,
const gchar *filename,
guint offset,
guint length)
else
mimeinfo->id = NULL;
+ if (content_location != NULL)
+ mimeinfo->location = g_strdup(content_location);
+ else
+ mimeinfo->location = NULL;
+
if (content_disposition != NULL)
procmime_parse_content_disposition(content_disposition, mimeinfo);
else
if (mimeinfo->id != NULL)
fprintf(fp, "Content-ID: %s\n", mimeinfo->id);
+ if (mimeinfo->location != NULL)
+ fprintf(fp, "Content-Location: %s\n", mimeinfo->location);
+
if (mimeinfo->disposition != DISPOSITIONTYPE_UNKNOWN) {
ParametersData *pdata = g_new0(ParametersData, 1);
gchar *buf = NULL;
g_ascii_strncasecmp(buf, "Content-Transfer-Encoding:", 26) == 0 ||
g_ascii_strncasecmp(buf, "Content-Description:", 20) == 0 ||
g_ascii_strncasecmp(buf, "Content-ID:", 11) == 0 ||
+ g_ascii_strncasecmp(buf, "Content-Location:", 17) == 0 ||
g_ascii_strncasecmp(buf, "Content-Disposition:", 20) == 0) {
skip = TRUE;
continue;