*
* 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
gchar *tmpfilename;
struct stat statbuf;
+ if (mimeinfo->content == MIMECONTENT_EMPTY)
+ return TRUE;
+
if (mimeinfo->encoding_type != ENC_UNKNOWN &&
mimeinfo->encoding_type != ENC_BINARY &&
mimeinfo->encoding_type != ENC_7BIT &&
oldout = dup(1);
dup2(fileno(outfp), 1);
-
+
p = popen(renderer->renderer, "w");
if (p != NULL) {
size_t count;
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(basetmp);
subst_for_shellsafe_filename(base);
}
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;
gchar *charset, *lang, *oldvalue, *newvalue;
attribute = (gchar *) cur->data;
- if (!g_hash_table_lookup_extended(table, attribute, (gpointer *) &key, (gpointer *) &value))
+ if (!g_hash_table_lookup_extended(
+ table, attribute, (gpointer *)(gchar *) &key, (gpointer *)(gchar *) &value))
continue;
charset = value;
mimeinfo->type = MIMETYPE_TEXT;
mimeinfo->subtype = g_strdup("plain");
if (g_hash_table_lookup(mimeinfo->typeparameters,
- "charset") == NULL)
+ "charset") == NULL) {
g_hash_table_insert(mimeinfo->typeparameters,
- g_strdup("charset"),
- g_strdup("us-ascii"));
+ g_strdup("charset"),
+ g_strdup(
+ conv_get_locale_charset_str_no_utf8()));
+ }
} else {
gchar *type, *subtype, *params;
mimeinfo->type = MIMETYPE_TEXT;
mimeinfo->subtype = g_strdup("plain");
if (g_hash_table_lookup(mimeinfo->typeparameters,
- "charset") == NULL)
- g_hash_table_insert(mimeinfo->typeparameters, g_strdup("charset"), g_strdup("us-ascii"));
+ "charset") == NULL) {
+ g_hash_table_insert(mimeinfo->typeparameters,
+ g_strdup("charset"),
+ g_strdup(
+ conv_get_locale_charset_str_no_utf8()));
+ }
}
if (content_encoding != NULL) {
ENC_AS_TOKEN,
ENC_AS_QUOTED_STRING,
ENC_AS_EXTENDED,
+ ENC_TO_ASCII,
} EncodeAs;
typedef struct _ParametersData {
FILE *fp;
guint len;
+ guint ascii_only;
} ParametersData;
static void write_parameters(gpointer key, gpointer value, gpointer user_data)
{
gchar *param = key;
- gchar *val = value, *valpos;
+ gchar *val = value, *valpos, *tmp;
ParametersData *pdata = (ParametersData *)user_data;
GString *buf = g_string_new("");
EncodeAs encas = ENC_AS_TOKEN;
for (valpos = val; *valpos != 0; valpos++) {
- if (!IS_ASCII(*valpos)) {
+ if (!IS_ASCII(*valpos) || *valpos == '"') {
encas = ENC_AS_EXTENDED;
break;
}
case ';':
case ':':
case '\\':
- case '"':
+ case '\'':
case '/':
case '[':
case ']':
continue;
}
}
+
+ if (encas == ENC_AS_EXTENDED && pdata->ascii_only == TRUE)
+ encas = ENC_TO_ASCII;
switch (encas) {
case ENC_AS_TOKEN:
g_string_append_printf(buf, "%s=%s", param, val);
break;
+ case ENC_TO_ASCII:
+ tmp = g_strdup(val);
+ g_strcanon(tmp,
+ " ()<>@,';:\\/[]?=.0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz",
+ '_');
+ g_string_append_printf(buf, "%s=\"%s\"", param, tmp);
+ g_free(tmp);
+ break;
+
case ENC_AS_QUOTED_STRING:
g_string_append_printf(buf, "%s=\"%s\"", param, val);
break;
g_string_append_printf(buf, "%%%s", hexstr);
}
}
- break;
+ break;
}
if (buf->str && strlen(buf->str)) {
debug_print("procmime_write_mime_header\n");
pdata->fp = fp;
+ pdata->ascii_only = FALSE;
for (type_table = mime_type_table; type_table->str != NULL; type_table++)
if (mimeinfo->type == type_table->type) {
"Content-Type: %s/%s", type_table->str, mimeinfo->subtype);
fprintf(fp, "%s", buf);
pdata->len = strlen(buf);
+ pdata->ascii_only = TRUE;
g_free(buf);
break;
}
g_free(buf);
pdata->fp = fp;
+ pdata->ascii_only = FALSE;
+
g_hash_table_foreach(mimeinfo->dispositionparameters, write_parameters, pdata);
g_free(pdata);
fprintf(fp, "\n");
/* Call writer for mime type */
switch (mimeinfo->type) {
case MIMETYPE_MESSAGE:
- if (g_ascii_strcasecmp(mimeinfo->subtype, "rfc822") == 0)
+ if (g_ascii_strcasecmp(mimeinfo->subtype, "rfc822") == 0) {
return procmime_write_message_rfc822(mimeinfo, fp);
+ }
break;
case MIMETYPE_MULTIPART: