*
* 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
switch (mimeinfo->content) {
case MIMECONTENT_FILE:
if (mimeinfo->tmp)
- unlink(mimeinfo->data.filename);
+ g_unlink(mimeinfo->data.filename);
g_free(mimeinfo->data.filename);
break;
encoding == ENC_BINARY)
return TRUE;
- infp = fopen(mimeinfo->data.filename, "rb");
+ infp = g_fopen(mimeinfo->data.filename, "rb");
if (!infp) {
perror("fopen");
return FALSE;
stat(tmpfilename, &statbuf);
if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
- unlink(mimeinfo->data.filename);
+ g_unlink(mimeinfo->data.filename);
if (mimeinfo->data.filename != NULL)
g_free(mimeinfo->data.filename);
mimeinfo->data.filename = tmpfilename;
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 &&
}
if (mimeinfo->content == MIMECONTENT_FILE) {
- if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+ if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
g_warning("Can't open file %s\n", mimeinfo->data.filename);
return FALSE;
}
fclose(infp);
return FALSE;
}
- if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) {
+ if ((tmp_fp = g_fopen(tmp_file, "rb")) == NULL) {
FILE_OP_ERROR(tmp_file, "fopen");
- unlink(tmp_file);
+ g_unlink(tmp_file);
g_free(tmp_file);
fclose(infp);
return FALSE;
if (tmp_file) {
fclose(tmp_fp);
- unlink(tmp_file);
+ g_unlink(tmp_file);
g_free(tmp_file);
}
} else if (encoding == ENC_QUOTED_PRINTABLE) {
if (mimeinfo->content == MIMECONTENT_FILE) {
if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
- unlink(mimeinfo->data.filename);
+ g_unlink(mimeinfo->data.filename);
g_free(mimeinfo->data.filename);
} else if (mimeinfo->content == MIMECONTENT_MEM) {
if (mimeinfo->tmp && (mimeinfo->data.mem != NULL))
if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
return -1;
- if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+ if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return -1;
}
fclose(infp);
return -1;
}
- if ((outfp = fopen(outfile, "wb")) == NULL) {
+ if ((outfp = g_fopen(outfile, "wb")) == NULL) {
FILE_OP_ERROR(outfile, "fopen");
fclose(infp);
return -1;
fclose(infp);
if (fclose(outfp) == EOF) {
FILE_OP_ERROR(outfile, "fclose");
- unlink(outfile);
+ g_unlink(outfile);
return -1;
}
renderer_list = NULL;
rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
- f = fopen(rcpath, "rb");
+ f = g_fopen(rcpath, "rb");
g_free(rcpath);
if (f == NULL)
return NULL;
}
- tmpfp = fopen(tmpfile, "rb");
+ tmpfp = g_fopen(tmpfile, "rb");
if (tmpfp == NULL) {
g_free(tmpfile);
return NULL;
oldout = dup(1);
dup2(fileno(outfp), 1);
-
+
p = popen(renderer->renderer, "w");
if (p != NULL) {
size_t count;
fclose(tmpfp);
rewind(outfp);
- unlink(tmpfile);
+ g_unlink(tmpfile);
g_free(tmpfile);
return outfp;
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);
}
if (mime_type_list)
return mime_type_list;
- if ((fp = fopen("/usr/share/mime/globs", "rb")) == NULL) {
+ if ((fp = g_fopen("/usr/share/mime/globs", "rb")) == NULL) {
fp_is_glob_file = FALSE;
- if ((fp = fopen("/etc/mime.types", "rb")) == NULL) {
- if ((fp = fopen(SYSCONFDIR "/mime.types", "rb"))
+ if ((fp = g_fopen("/etc/mime.types", "rb")) == NULL) {
+ if ((fp = g_fopen(SYSCONFDIR "/mime.types", "rb"))
== NULL) {
FILE_OP_ERROR(SYSCONFDIR "/mime.types",
"fopen");
size_t total_len = 0;
gfloat octet_percentage;
- if ((fp = fopen(file, "rb")) == NULL) {
+ if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
return ENC_UNKNOWN;
}
procmime_decode_content(mimeinfo);
- fp = fopen(mimeinfo->data.filename, "rb");
+ fp = g_fopen(mimeinfo->data.filename, "rb");
if (fp == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return;
procmime_decode_content(mimeinfo);
- fp = fopen(mimeinfo->data.filename, "rb");
+ fp = g_fopen(mimeinfo->data.filename, "rb");
if (fp == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return;
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) {
g_return_val_if_fail(filename != NULL, NULL);
/* Open file */
- if ((fp = fopen(filename, "rb")) == NULL)
+ if ((fp = g_fopen(filename, "rb")) == NULL)
return NULL;
/* Skip queue header */
while (fgets(buf, sizeof(buf), fp) != 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");
/* write header */
switch (mimeinfo->content) {
case MIMECONTENT_FILE:
- if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+ if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return -1;
}
switch (mimeinfo->content) {
case MIMECONTENT_FILE:
- if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+ if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return -1;
}
if (G_NODE_IS_LEAF(mimeinfo->node)) {
switch (mimeinfo->content) {
case MIMECONTENT_FILE:
- if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+ if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return -1;
}
/* 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: