Make procmsg_msginfo_free() zero out pointers to freed memory.
[claws.git] / src / action.c
index cc26bdfe32a84ed5aeec0f5a6ce5fbb3ae9be945..e78bf477b93db3d8d9b398a62f7a2d13cae8f53b 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto & The Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
+ *
  */
 
 #ifdef HAVE_CONFIG_H
@@ -386,8 +386,9 @@ static gboolean parse_append_filename(GString *cmd, MsgInfo *msginfo)
        }
 
        p = filename;
+       g_string_append(cmd, "\"");
 #ifdef G_OS_UNIX
-       while ((q = strpbrk(p, "$\"`'\\ \t*?[]&|;<>()!#~")) != NULL) {
+       while ((q = strpbrk(p, "$\"`\\~")) != NULL) {
                escape_ch[1] = *q;
                *q = '\0';
                g_string_append(cmd, p);
@@ -397,10 +398,9 @@ static gboolean parse_append_filename(GString *cmd, MsgInfo *msginfo)
 
        g_string_append(cmd, p);
 #else
-       g_string_append(cmd, "\"");
        g_string_append(cmd, filename);
-       g_string_append(cmd, "\"");
 #endif
+       g_string_append(cmd, "\"");
        g_free(filename);
 
        return TRUE;
@@ -434,7 +434,7 @@ static gboolean parse_append_msgpart(GString *cmd, MsgInfo *msginfo,
        g_free(filename);
 
        if (ret < 0) {
-               alertpanel_error(_("Can't get part of multipart message: %s"), strerror(-ret));
+               alertpanel_error(_("Can't get part of multipart message: %s"), g_strerror(-ret));
                g_free(part_filename);
                return FALSE;
        }
@@ -759,7 +759,7 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
                                gint body_pos, MimeInfo *partinfo,
                                void (*callback)(void *data), void *data)
 {
-       GSList *children_list = NULL;
+       GSList *children_list = NULL, *cur = NULL;
        gint is_ok  = TRUE;
        gint msg_list_len;
        Children *children;
@@ -850,9 +850,19 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
            ((action_type & ACTION_SINGLE) == 0 || msg_list_len == 1))
                children->open_in = 1;
 
-       if (action_type & ACTION_SINGLE) {
-               GSList *cur;
+       /* Pre-fetch bodies, makes it easier on IMAP (see bug #3011) */
+       for (cur = msg_list; cur; cur = cur->next) {
+               gchar *dummy;
+               msginfo = (MsgInfo *)cur->data;
+
+               dummy = procmsg_get_message_file((MsgInfo *)cur->data);
+               if (dummy)
+                       g_free(dummy);
+               else
+                       is_ok = FALSE;
+       }
 
+       if (is_ok && (action_type & ACTION_SINGLE)) {
                for (cur = msg_list; cur && is_ok == TRUE; cur = cur->next) {
                        msginfo = (MsgInfo *)cur->data;
                        if (!msginfo) {
@@ -877,7 +887,7 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
                        }
                        g_free(cmd);
                }
-       } else {
+       } else if (is_ok) {
                cmd = parse_action_cmd(action, NULL, msg_list, partinfo,
                                       user_str, user_hidden_str, sel_str);
                if (cmd) {
@@ -925,7 +935,7 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                             Children *children)
 {
        gint chld_in, chld_out, chld_err;
-       gchar **argv, *ret_str;
+       gchar **argv, *ret_str, *trim_cmd;
        GPid pid;
        ChildInfo *child_info;
        gint follow_child;
@@ -940,11 +950,23 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
        ret_str = g_locale_from_utf8(cmd, strlen(cmd),
                                     &by_read, &by_written,
                                     NULL);
-       if (ret_str && by_written)
-               argv = strsplit_with_quote(ret_str, " ", 0);
-       else
-               argv = strsplit_with_quote(cmd, " ", 0);
+       if (!ret_str || !by_written)
+               ret_str = g_strdup(cmd);
+
+       trim_cmd = ret_str;
+
+       while (g_ascii_isspace(trim_cmd[0]))
+               trim_cmd++;
 
+#ifdef G_OS_UNIX
+       argv = g_new0(gchar *, 4);
+       argv[0] = g_strdup("/bin/sh");
+       argv[1] = g_strdup("-c");
+       argv[2] = g_strdup(trim_cmd);
+       argv[3] = 0;
+#else
+       argv = strsplit_with_quote(trim_cmd, " ", 0);
+#endif
        g_free(ret_str);
 
        if (follow_child) {
@@ -965,8 +987,9 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
        if (!result) {
                alertpanel_error(_("Could not fork to execute the following "
                                "command:\n%s\n%s"),
-                                cmd, error->message);
-               g_free(error);
+                                cmd, error ? error->message : _("Unknown error"));
+               if (error)
+                       g_error_free(error);
                return NULL;
        }
 
@@ -1020,7 +1043,7 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                        r = close(chld_in);
                child_info->chld_in = -1; /* No more input */
                if (r != 0)
-                       debug_print("%s(%d)", strerror(errno), errno);
+                       debug_print("%s(%d)", g_strerror(errno), errno);
        }
 
        return child_info;
@@ -1314,11 +1337,6 @@ static void create_io_dialog(Children *children)
                gtk_box_pack_start(GTK_BOX(input_hbox), entry, TRUE, TRUE, 0);
                if (children->action_type & ACTION_USER_HIDDEN_IN) {
                        gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
-#ifdef MAEMO
-                       hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry), 
-                               HILDON_GTK_INPUT_MODE_FULL | 
-                               HILDON_GTK_INPUT_MODE_INVISIBLE);
-#endif
                }
                gtk_widget_show(entry);
 
@@ -1427,7 +1445,7 @@ static void catch_status(GPid pid, gint status, gpointer data)
                                modified_something = TRUE;
                                last_item = nmi->folder;
                        }
-                       procmsg_msginfo_free (nmi);
+                       procmsg_msginfo_free (&nmi);
                        if (summaryview && summaryview->displayed &&
                            summaryview->folder_item == msginfo->folder &&
                            summary_get_msgnum(summaryview, summaryview->displayed) == msginfo->msgnum)
@@ -1492,7 +1510,7 @@ static void catch_input(gpointer data, gint source, GIOCondition cond)
        r = close(child_info->chld_in);
        child_info->chld_in = -1;
        if (r != 0)
-               debug_print("%s(%d)", strerror(errno), errno);
+               debug_print("%s(%d)", g_strerror(errno), errno);
        child_info->chld_in = -1;
        debug_print("Input to grand child sent.\n");
 }