Fix bug #3246 ‘attachment open: "remember this" ignored if ~/.mailcap does not exist’
[claws.git] / src / common / utils.c
index 8382176a76e9d57f4249d5a3e068df2bb5e1ebb3..2e41793fc0935c40d54fe5519a1463e530320461 100644 (file)
@@ -926,6 +926,7 @@ gchar *strchr_with_skip_quote(const gchar *str, gint quote_chr, gint c)
 
 void extract_address(gchar *str)
 {
+       cm_return_if_fail(str != NULL);
        eliminate_address_comment(str);
        if (strchr_with_skip_quote(str, '"', '<'))
                extract_parenthesis_with_skip_quote(str, '"', '<', '>');
@@ -4804,13 +4805,25 @@ void mailcap_update_default(const gchar *type, const gchar *command)
        gboolean err = FALSE;
 
        if (!fp) {
-               g_free(path);
-               g_free(outpath);
-               return;
+               fp = g_fopen(path, "a");
+               if (!fp) {
+                       g_warning("failed to create file %s\n", path);
+                       g_free(path);
+                       g_free(outpath);
+                       return;
+               }
+               fp = g_freopen(path, "rb", fp);
+               if (!fp) {
+                       g_warning("failed to reopen file %s\n", path);
+                       g_free(path);
+                       g_free(outpath);
+                       return;
+               }
        }
 
        outfp = g_fopen(outpath, "wb");
        if (!outfp) {
+               g_warning("failed to create file %s\n", outpath);
                g_free(path);
                g_free(outpath);
                fclose(fp);