Make procmsg_msginfo_free() zero out pointers to freed memory.
[claws.git] / src / compose.c
index f57a0df34fb32c0293b788ac2c5cb0291a03cd8b..af64a8327c220c2d78638689d3b35ddf23b4965e 100644 (file)
@@ -61,7 +61,7 @@
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
 #else
        #include "addressbook-dbus.h"
@@ -1205,7 +1205,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                }
 
        }
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        if (attach_files) {
                GList *curr;
@@ -1826,7 +1826,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
 
                g_free(tmp);
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        textview = GTK_TEXT_VIEW(compose->text);
@@ -1885,7 +1885,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
                compose_attach_parts(compose, msginfo);
 
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        SIGNAL_BLOCK(textbuf);
@@ -3189,7 +3189,7 @@ error:
 ok:
        SIGNAL_UNBLOCK(buffer);
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        return buf;
 }
@@ -3778,7 +3778,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
 
                        ainfo->name = g_strdup_printf(_("Message: %s"), name);
 
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
                } else {
                        if (!g_ascii_strncasecmp(content_type, "text/", 5)) {
                                ainfo->charset = g_strdup(charset);
@@ -5214,7 +5214,7 @@ gint compose_send(Compose *compose)
                                if (tmp) {
                                        debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                        folder_item_remove_msg(folder, tmp->msgnum);
-                                       procmsg_msginfo_free(tmp);
+                                       procmsg_msginfo_free(&tmp);
                                } 
                        }
                }
@@ -5230,7 +5230,7 @@ gint compose_send(Compose *compose)
                        if (tmp) {
                                debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                folder_item_remove_msg(folder, tmp->msgnum);
-                               procmsg_msginfo_free(tmp);
+                               procmsg_msginfo_free(&tmp);
                        }
                }
                if (!discard_window) {
@@ -6494,11 +6494,22 @@ static gchar *compose_get_header(Compose *compose)
                
                g_string_append_printf(header, "From: %s <%s>\n",
                        qname, from_address);
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt) {
+                       compose_convert_header(compose, buf, sizeof(buf), from_name,
+                                              strlen("Disposition-Notification-To: "),
+                                              TRUE);
+                       g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, from_address);
+               }
                if (qname != name)
                        g_free(qname);
-       } else
+       } else {
                g_string_append_printf(header, "From: %s\n", from_address);
-       
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt)
+                       g_string_append_printf(header, "Disposition-Notification-To: %s\n", from_address);
+
+       }
        g_free(from_name);
        g_free(from_address);
 
@@ -6654,21 +6665,6 @@ static gchar *compose_get_header(Compose *compose)
                                     compose->priority);
        }
 
-       /* Request Return Receipt */
-       if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
-               if (compose->return_receipt) {
-                       if (compose->account->name
-                           && *compose->account->name) {
-                               compose_convert_header(compose, buf, sizeof(buf), 
-                                                      compose->account->name, 
-                                                      strlen("Disposition-Notification-To: "),
-                                                      TRUE);
-                               g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
-                       } else
-                               g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
-               }
-       }
-
        /* get special headers */
        for (list = compose->header_list; list; list = list->next) {
                ComposeHeaderEntry *headerentry;
@@ -6798,7 +6794,7 @@ static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_d
        if (*address != '\0') {
                gchar *name = procheader_get_fromname(address);
                extract_address(address);
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
                addressbook_add_contact(name, address, NULL, NULL);
 #else
                debug_print("%s: %s\n", name, address);
@@ -8082,7 +8078,7 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
                                prefs_common_translated_header_name("Newsgroups:"));
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_set_target_compose(compose);
 #endif 
        if (mode != COMPOSE_REDIRECT)
@@ -8619,7 +8615,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
 
                        parsed_str = compose_quote_fmt(compose, dummyinfo,
                                                           tmpl->value, qmark, tmp, FALSE, FALSE, err_msg);
-                       procmsg_msginfo_free( dummyinfo );
+                       procmsg_msginfo_free( &dummyinfo );
 
                        g_free( tmp );
                } 
@@ -8785,7 +8781,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                }
        }
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 }
 
 static void compose_destroy(Compose *compose)
@@ -8820,9 +8816,9 @@ static void compose_destroy(Compose *compose)
        hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST,
                        compose->folder_update_callback_id);
 
-       procmsg_msginfo_free(compose->targetinfo);
-       procmsg_msginfo_free(compose->replyinfo);
-       procmsg_msginfo_free(compose->fwdinfo);
+       procmsg_msginfo_free(&(compose->targetinfo));
+       procmsg_msginfo_free(&(compose->replyinfo));
+       procmsg_msginfo_free(&(compose->fwdinfo));
 
        g_free(compose->replyto);
        g_free(compose->cc);
@@ -8850,7 +8846,7 @@ static void compose_destroy(Compose *compose)
        g_free(compose->privacy_system);
        g_free(compose->encdata);
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
 #endif
@@ -9567,17 +9563,33 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
        return FALSE;
 }
 
+static char *ext_editor_menu_entries[] = {
+       "Menu/Message/Send",
+       "Menu/Message/SendLater",
+       "Menu/Message/InsertFile",
+       "Menu/Message/InsertSig",
+       "Menu/Message/ReplaceSig",
+       "Menu/Message/Save",
+       "Menu/Message/Print",
+       "Menu/Edit",
+#if USE_ENCHANT
+       "Menu/Spelling",
+#endif
+       "Menu/Tools/ShowRuler",
+       "Menu/Tools/Actions",
+       "Menu/Help",
+       NULL
+};
+
 static void compose_set_ext_editor_sensitive(Compose *compose,
                                             gboolean sensitive)
 {
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/Send", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/SendLater", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertFile", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/ReplaceSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapPara", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapAllLines", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/ExtEditor", sensitive);
+       int i;
+
+       for (i = 0; ext_editor_menu_entries[i]; ++i) {
+               cm_menu_set_sensitive_full(compose->ui_manager,
+                       ext_editor_menu_entries[i], sensitive);
+       }
 
        if (compose_get_ext_editor_uses_socket()) {
                if (sensitive) {
@@ -9932,6 +9944,12 @@ static void compose_send_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifdef G_OS_UNIX
+       if (compose->exteditor_tag != -1) {
+               debug_print("ignoring send: external editor still open\n");
+               return;
+       }
+#endif
        if (prefs_common.work_offline && 
            !inc_offline_should_override(TRUE,
                _("Claws Mail needs network access in order "
@@ -10126,7 +10144,7 @@ gboolean compose_draft (gpointer data, guint action)
                }
                if (tmpinfo) {
                        msgnum = tmpinfo->msgnum;
-                       procmsg_msginfo_free(tmpinfo);
+                       procmsg_msginfo_free(&tmpinfo);
                        debug_print("got draft msgnum %d from scanning\n", msgnum);
                } else {
                        debug_print("didn't get draft msgnum after scanning\n");
@@ -10184,7 +10202,7 @@ warn_err:
                if (action == COMPOSE_DRAFT_FOR_EXIT) {
                        compose_register_draft(newmsginfo);
                }
-               procmsg_msginfo_free(newmsginfo);
+               procmsg_msginfo_free(&newmsginfo);
        }
        
        folder_item_scan(draft);
@@ -10210,7 +10228,7 @@ warn_err:
                }
                g_free(path);
 
-               procmsg_msginfo_free(compose->targetinfo);
+               procmsg_msginfo_free(&(compose->targetinfo));
                compose->targetinfo = procmsg_msginfo_new();
                compose->targetinfo->msgnum = msgnum;
                compose->targetinfo->size = (goffset)s.st_size;
@@ -10473,7 +10491,7 @@ static void compose_address_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_open(compose);
 #else
        GError* error = NULL;
@@ -11854,7 +11872,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
 
        if (new_msglist) {
                compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
-               procmsg_msginfo_free(tmp_msginfo);
+               procmsg_msginfo_free(&tmp_msginfo);
                g_slist_free(new_msglist);
        } else
                compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);