fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / plugins / att_remover / att_remover.c
index 0946bb12ccfbecc4a586e3fa1bcae5e12c794eb0..f98e0d8d1b3151b71bfb7e9f4103eaf21cda73bd 100644 (file)
@@ -66,7 +66,7 @@ static PrefParam prefs[] = {
         NULL, NULL},
         {"win_height", "-1", &AttRemoverData.win_height, P_INT, NULL, 
          NULL, NULL},
-        {0,0,0,0}
+        {0,0,0,0,0,0,0}
 };
 
 enum {
@@ -87,7 +87,7 @@ static MimeInfo *find_first_text_part(MimeInfo *partinfo)
 static gboolean key_pressed_cb(GtkWidget *widget, GdkEventKey *event,
                                AttRemover *attremover)
 {
-       if (event && event->keyval == GDK_Escape)
+       if (event && event->keyval == GDK_KEY_Escape)
                gtk_widget_destroy(attremover->window);
 
        return FALSE;
@@ -336,6 +336,7 @@ static void remove_attachments_dialog(AttRemover *attremover)
        gtk_container_set_border_width( GTK_CONTAINER(window), VBOX_BORDER);
        gtk_window_set_title(GTK_WINDOW(window), _("Remove attachments"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+       gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
 
        g_signal_connect(G_OBJECT(window), "delete_event",
@@ -418,13 +419,15 @@ static void remove_attachments(GSList *msglist)
        SummaryView *summaryview = mainwin->summaryview;
        GSList *cur;
        gint msgnum = -1;
+       gint stripped_msgs = 0;
+       gint total_msgs = 0;
        
        if (alertpanel_full(_("Destroy attachments"),
                   _("Do you really want to remove all attachments from "
                   "the selected messages?\n\n"
                  "The deleted data will be unrecoverable."), 
-                 GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL,
-                  FALSE, NULL, ALERT_QUESTION, G_ALERTALTERNATE) != G_ALERTALTERNATE)
+                 GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, ALERTFOCUS_SECOND,
+                  FALSE, NULL, ALERT_QUESTION) != G_ALERTALTERNATE)
                return;
 
        main_window_cursor_wait(summaryview->mainwin);
@@ -437,10 +440,12 @@ static void remove_attachments(GSList *msglist)
                MsgInfo *newmsg = NULL;
                MimeInfo *info = NULL;
                MimeInfo *partinfo = NULL;
+               MimeInfo *nextpartinfo = NULL;
 
                if (!msginfo)
                        continue;
-               
+               total_msgs++;                   /* count all processed messages */
+
                newmsg = procmsg_msginfo_copy(msginfo);
                info = procmime_scan_message(newmsg);
        
@@ -448,12 +453,27 @@ static void remove_attachments(GSList *msglist)
                        procmsg_msginfo_free(&newmsg);
                        continue;
                }
-               partinfo->node->next = NULL;
-               partinfo->node->children = NULL;
-               info->node->children->data = partinfo;
+               /* only strip attachments where there is at least one */
+               nextpartinfo = procmime_mimeinfo_next(partinfo);
+               if (nextpartinfo) {
+                       partinfo->node->next = NULL;
+                       partinfo->node->children = NULL;
+                       info->node->children->data = partinfo;
+
+                       msgnum = save_new_message(msginfo, newmsg, info, FALSE);
 
-               msgnum = save_new_message(msginfo, newmsg, info, FALSE);                
+                       stripped_msgs++;        /* count messages with removed attachment(s) */
+               }
        }
+       if (stripped_msgs == 0) {
+               alertpanel_notice(_("The selected messages don't have any attachments."));
+       } else {
+               if (stripped_msgs != total_msgs)
+                       alertpanel_notice(_("Attachments removed from %d of the %d selected messages."),
+                                                       stripped_msgs, total_msgs);
+               else
+                       alertpanel_notice(_("Attachments removed from all %d selected messages."), total_msgs);
+       }       
 
        inc_unlock();
        folder_item_update_thaw();
@@ -482,12 +502,10 @@ static void remove_attachments_ui(GtkAction *action, gpointer data)
                
                if (!partinfo) {
                        alertpanel_notice(_("This message doesn't have any attachments."));
-                       g_slist_free(msglist);
-                       return;
+               } else {
+                       AttRemoverData.msginfo = msglist->data;
+                       remove_attachments_dialog(&AttRemoverData);
                }
-               
-               AttRemoverData.msginfo = msglist->data;
-               remove_attachments_dialog(&AttRemoverData);
        } else
                remove_attachments(msglist);