CLI: Add a --insert option to --compose, allowing to insert files.
[claws.git] / src / compose.c
index 21e690ae13ebea2e5c8e7fe345823870e768efab..5aad2778780b0a04b1cb35418bdad97ba2b0643b 100644 (file)
@@ -1084,6 +1084,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        else
                                gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(tmp);
                }
@@ -1177,6 +1178,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
                        compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(subject);
                        g_free(tmp);
@@ -1224,7 +1226,10 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                for (curr = attach_files ; curr != NULL ; curr = curr->next) {
                        ainfo = (AttachInfo *) curr->data;
-                       compose_attach_append(compose, ainfo->file, ainfo->file,
+                       if (ainfo->insert)
+                               compose_insert_file(compose, ainfo->file);
+                       else
+                               compose_attach_append(compose, ainfo->file, ainfo->file,
                                        ainfo->content_type, ainfo->charset);
                }
        }
@@ -1652,6 +1657,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                else
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
 
                g_free(tmp);
        }
@@ -1834,6 +1840,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                else
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
 
                g_free(tmp);
                procmsg_msginfo_free(&full_msginfo);
@@ -2025,6 +2032,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                        else
                                gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(tmp);
                }
@@ -3125,6 +3133,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                quote_fmt_parse();
 
                buf = quote_fmt_get_buffer();
+
                if (buf == NULL)
                        alertpanel_error(_("The \"Quotation mark\" of the template is invalid."));
                else
@@ -3158,11 +3167,14 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                }
 
                buf = quote_fmt_get_buffer();
+
                if (buf == NULL) {
                        gint line = quote_fmt_get_line();
                        alertpanel_error(err_msg, line);
+
                        goto error;
                }
+
        } else
                buf = "";
 
@@ -5160,6 +5172,7 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                                               GTK_STOCK_CANCEL, button_label, NULL, TRUE, NULL,
                                               ALERT_QUESTION, G_ALERTDEFAULT);
                        g_free(message);
+                       g_free(button_label);
                        if (aval & G_ALERTDISABLE) {
                                aval &= ~G_ALERTDISABLE;
                                prefs_common.warn_empty_subj = FALSE;
@@ -5183,9 +5196,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
                        g_strstrip(header);
                        g_strstrip(entry);
-                       if ((entry[0] != '\0')
-                       &&      (strcmp(header, prefs_common_translated_header_name("To:"))
-                       ||  strcmp(header, prefs_common_translated_header_name("Cc:")))) {
+                       if ((entry[0] != '\0') &&
+                           (!strcmp(header, prefs_common_translated_header_name("To:")) ||
+                            !strcmp(header, prefs_common_translated_header_name("Cc:")))) {
                                cnt++;
                        }
                        g_free(header);
@@ -5670,6 +5683,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                if (*chars != '\n') {
                        gtk_text_buffer_insert(buffer, &end, "\n", 1);
                }
+               g_free(chars);
        }
 
        /* get all composed text */
@@ -8829,6 +8843,8 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        compose_template_apply_fields(compose, tmpl);
        compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
        quote_fmt_reset_vartable();
+       quote_fmtlex_destroy();
+
        compose_changed_cb(NULL, compose);
 
 #ifdef USE_ENCHANT
@@ -8882,6 +8898,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->to && *tmpl->to != '\0') {
@@ -8900,6 +8919,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_TO, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->cc && *tmpl->cc != '\0') {
@@ -8918,6 +8940,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_CC, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->bcc && *tmpl->bcc != '\0') {
@@ -8936,6 +8961,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_BCC, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->replyto && *tmpl->replyto != '\0') {
@@ -8954,6 +8982,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        /* process the subject */
@@ -8973,6 +9004,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        procmsg_msginfo_free( &dummyinfo );
@@ -11677,6 +11711,8 @@ static gboolean compose_headerentry_button_clicked_cb (GtkWidget *button,
                                         ComposeHeaderEntry *headerentry)
 {
        gtk_entry_set_text(GTK_ENTRY(headerentry->entry), "");
+       gtk_widget_modify_base(GTK_WIDGET(headerentry->entry), GTK_STATE_NORMAL, NULL);
+       gtk_widget_modify_text(GTK_WIDGET(headerentry->entry), GTK_STATE_NORMAL, NULL);
        return FALSE;
 }