do not use description as attachment name
[claws.git] / src / mimeview.c
index 03d31a68f38084656d245254df6a1332762e8acb..3a65ed13148f2f8ce12726d5c9e2cbcbc5ebc5dc 100644 (file)
@@ -389,6 +389,20 @@ static gchar *get_part_name(MimeInfo *partinfo)
                return partinfo->name;
        else if (partinfo->filename)
                return partinfo->filename;
+       else if (partinfo->description)
+               return partinfo->description;
+       else
+               return "";
+}
+
+static gchar *get_part_description(MimeInfo *partinfo)
+{
+       if (partinfo->description)
+               return partinfo->description;
+       else if (partinfo->name)
+               return partinfo->name;
+       else if (partinfo->filename)
+               return partinfo->filename;
        else
                return "";
 }
@@ -404,7 +418,10 @@ static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
        str[COL_MIMETYPE] =
                partinfo->content_type ? partinfo->content_type : "";
        str[COL_SIZE] = to_human_readable(partinfo->size);
-       str[COL_NAME] = get_part_name(partinfo);
+       if (prefs_common.attach_desc)
+               str[COL_NAME] = get_part_description(partinfo);
+       else
+               str[COL_NAME] = get_part_name(partinfo);
 
        node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
                                     NULL, NULL, NULL, NULL,
@@ -810,37 +827,39 @@ static void mimeview_save_all(MimeView *mimeview)
        if (!dirname) return;
 
        /* return to first children */
+       if (!partinfo->parent->children) return;  /* multipart container? */
        attachment = partinfo->parent->children->next;
        /* for each attachment, extract it in the selected dir. */
-       while(attachment != NULL)
-       {
+       while (attachment != NULL) {
                static guint subst_cnt = 1;
                gchar *attachdir;
-               gchar *attachname = (attachment->filename)
-                       ? g_strdup(attachment->filename)
-                       : g_strdup_printf("noname.%d",subst_cnt++);
+               gchar *attachname = g_strdup(get_part_name(attachment));
+               AlertValue aval = G_ALERTDEFAULT;
+               gchar *res;
 
-               subst_chars(attachname, "/\\", G_DIR_SEPARATOR);
+               if (!attachname || !strlen(attachname))
+                       attachname = g_strdup_printf("noname.%d",subst_cnt++);
                subst_chars(attachname, ":?*&|<>\t\r\n", '_');
                g_snprintf(buf, sizeof(buf), "%s%s",
                           dirname,
                           (attachname[0] == G_DIR_SEPARATOR)
                           ? &attachname[1]
                           : attachname);
+               subst_chars(buf, "/\\", G_DIR_SEPARATOR);
                attachdir = g_dirname(buf);
                make_dir_hier(attachdir);
                g_free(attachdir);
-               g_free(attachname);
 
                if (is_file_exist(buf)) {
-                       AlertValue aval;
-
-                       aval = alertpanel(_("Overwrite"),
-                                         _("Overwrite existing file?"),
-                                         _("OK"), _("Cancel"), NULL);
-                       if (G_ALERTDEFAULT != aval) return;
+                       res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                             attachname);
+                       aval = alertpanel(_("Overwrite"), res, _("OK"), 
+                                         _("Cancel"), NULL);
+                       g_free(res);                                      
                }
-               if (procmime_get_part(buf, mimeview->file, attachment) < 0)
+               g_free(attachname);
+
+               if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, mimeview->file, attachment) < 0))
                        alertpanel_error(_("Can't save the part of multipart message."));
                attachment = attachment->next;
        }
@@ -873,6 +892,7 @@ static void mimeview_save_as(MimeView *mimeview)
        gchar *filename;
        gchar *defname = NULL;
        MimeInfo *partinfo;
+       gchar *res;
 
        if (!mimeview->opened) return;
        if (!mimeview->file) return;
@@ -892,10 +912,11 @@ static void mimeview_save_as(MimeView *mimeview)
        if (!filename) return;
        if (is_file_exist(filename)) {
                AlertValue aval;
-
-               aval = alertpanel(_("Overwrite"),
-                                 _("Overwrite existing file?"),
-                                 _("OK"), _("Cancel"), NULL);
+               res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                     filename);
+               aval = alertpanel(_("Overwrite"), res, _("OK"), 
+                                 _("Cancel"), NULL);
+               g_free(res);                                      
                if (G_ALERTDEFAULT != aval) return;
        }