0.9.4claws68
[claws.git] / src / compose.c
index 4d8c21a8f840cb96f6db96bf17d9ce0ec048e2e2..b8d99c5d1b5f7a2c7928d9d8308ee71a34bc9646 100644 (file)
@@ -484,6 +484,7 @@ static void compose_check_forwards_go          (Compose *compose);
 #endif
 
 static gboolean compose_send_control_enter     (Compose        *compose);
+static gint compose_defer_auto_save_draft      (Compose        *compose);
 
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
@@ -708,6 +709,13 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        text = GTK_STEXT(compose->text);
        gtk_stext_freeze(text);
 
+#ifdef USE_ASPELL
+       if (item && item->prefs && item->prefs->enable_default_dictionary &&
+           compose->gtkaspell) 
+               gtkaspell_change_dict(compose->gtkaspell, 
+                   item->prefs->default_dictionary);
+#endif
+
        if (account->auto_sig)
                compose_insert_sig(compose, FALSE);
        gtk_editable_set_position(GTK_EDITABLE(text), 0);
@@ -958,6 +966,15 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        text = GTK_STEXT(compose->text);
        gtk_stext_freeze(text);
 
+#ifdef USE_ASPELL
+       if (msginfo->folder && msginfo->folder->prefs && 
+           msginfo->folder->prefs && 
+           msginfo->folder->prefs->enable_default_dictionary &&
+           compose->gtkaspell)
+               gtkaspell_change_dict(compose->gtkaspell, 
+                   msginfo->folder->prefs->default_dictionary);
+#endif
+
        if (quote) {
                gchar *qmark;
 
@@ -1038,9 +1055,17 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose->fwdinfo = procmsg_msginfo_copy(msginfo);
 
        if (msginfo->subject && *msginfo->subject) {
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
-               gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
-                                     msginfo->subject);
+               gchar *buf, *buf2, *p;
+
+               buf = p = g_strdup(msginfo->subject);
+               p += subject_get_prefix_length(p);
+               memmove(buf, p, strlen(p) + 1);
+
+               buf2 = g_strdup_printf("Fw: %s", buf);
+               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
+               
+               g_free(buf);
+               g_free(buf2);
        }
 
        text = GTK_STEXT(compose->text);
@@ -1278,7 +1303,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        g_return_val_if_fail(msginfo != NULL, NULL);
 
        if (!account)
-               account = cur_account;
+               account = account_get_reply_account(msginfo,
+                                       prefs_common.reply_account_autosel);
        g_return_val_if_fail(account != NULL, NULL);
 
        compose = compose_create(account, COMPOSE_REDIRECT);
@@ -1791,7 +1817,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                gchar *buf, *buf2, *p;
 
                buf = p = g_strdup(msginfo->subject);
-               p += subject_get_reply_prefix_length(p);
+               p += subject_get_prefix_length(p);
                memmove(buf, p, strlen(p) + 1);
 
                buf2 = g_strdup_printf("Re: %s", buf);
@@ -1893,6 +1919,7 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
 {
        GtkSText *text = GTK_STEXT(compose->text);
        gint cur_pos;
+       gint len;
 
        g_return_if_fail(compose->account != NULL);
 
@@ -1900,9 +1927,11 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
 
        gtk_stext_freeze(text);
 
+       len = gtk_stext_get_length(text);
+       gtk_stext_set_point(text, len);
+
        if (replace && compose->sig_str) {
                gint pos;
-               gint len;
 
                if (compose->sig_str[0] == '\0')
                        pos = -1;
@@ -1914,16 +1943,9 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
                        if (len >= 0) {
                                gtk_stext_set_point(text, pos);
                                gtk_stext_forward_delete(text, len);
-                       } else {
-                               len = gtk_stext_get_length(text);
-                               gtk_stext_set_point(text, len);
                        }
-               } else {
-                       len = gtk_stext_get_length(text);
-                       gtk_stext_set_point(text, len);
                }
-       } else
-               gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
+       }
 
        g_free(compose->sig_str);
        compose->sig_str = compose_get_signature_str(compose);
@@ -1971,13 +1993,14 @@ static gchar *compose_get_signature_str(Compose *compose)
                g_free(tmp);
        }
 
-       if (compose->account->sig_sep) {
-               sig_str = g_strconcat(compose->account->sig_sep, "\n", sig_body,
+       if (compose->account->sig_sep)
+               sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
                                      NULL);
-               g_free(sig_body);
-       } else
-               sig_str = sig_body;
+       else
+               sig_str = g_strconcat("\n\n", sig_body, NULL);
 
+       g_free(sig_body);
+       
        return sig_str;
 }
 
@@ -2894,7 +2917,7 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
        activate_gnupg_mode(compose, account);          
 #endif /* USE_GPGME */
 
-       if (!init)
+       if (!init && compose->mode != COMPOSE_REDIRECT)
                compose_insert_sig(compose, TRUE);
 }
 
@@ -2990,6 +3013,8 @@ gint compose_send(Compose *compose)
        g_free(msgpath);
 
        folder_item_remove_msg(folder, msgnum);
+       
+       folder_item_scan(folder);
 
        return val;
 }
@@ -3673,6 +3698,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        GSList *cur;
        gchar buf[BUFFSIZE];
        gint num;
+       MsgFlags flag = {0, 0};
         static gboolean lock = FALSE;
        PrefsAccount *mailac = NULL, *newsac = NULL;
        
@@ -3861,7 +3887,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                return -1;
        }
        folder_item_scan(queue);
-       if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
+       if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
                g_warning("can't queue the message\n");
                unlink(tmp);
                g_free(tmp);
@@ -4261,16 +4287,16 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
        /* MIME */
        fprintf(fp, "Mime-Version: 1.0\n");
        if (compose_use_attach(compose)) {
-               get_rfc822_date(buf, sizeof(buf));
-               subst_char(buf, ' ', '_');
-               subst_char(buf, ',', '_');
-               compose->boundary = g_strdup_printf("Multipart_%s_%08x",
-                                                   buf, (guint)compose);
+               compose->boundary = generate_mime_boundary();
                fprintf(fp,
                        "Content-Type: multipart/mixed;\n"
                        " boundary=\"%s\"\n", compose->boundary);
        } else {
                fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
+#if USE_GPGME
+               if (compose->use_signing && !compose->gnupg_mode)
+                       fprintf(fp, "Content-Disposition: inline\n");
+#endif
                fprintf(fp, "Content-Transfer-Encoding: %s\n",
                        procmime_get_encoding_str(encoding));
        }
@@ -4323,6 +4349,11 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                headerentry = ((ComposeHeaderEntry *)list->data);
                
                tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
+               if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
+                       g_free(tmp);
+                       continue;
+               }
+
                if (!strstr(tmp, ":")) {
                        headername_wcolon = g_strconcat(tmp, ":", NULL);
                        headername = g_strdup(tmp);
@@ -4333,6 +4364,8 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                g_free(tmp);
                
                headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
+               subst_char(headervalue, '\r', ' ');
+               subst_char(headervalue, '\n', ' ');
                string = std_headers;
                while (*string != NULL) {
                        headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
@@ -4344,8 +4377,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
                                
                g_free(headername);
-               g_free(headername_wcolon);
-               
+               g_free(headername_wcolon);              
        }
 
        /* separator between header and body */
@@ -4365,6 +4397,8 @@ static void compose_convert_header(gchar *dest, gint len, gchar *src,
        if (len < 1) return;
 
        g_strchomp(src);
+       subst_char(src, '\n', ' ');
+       subst_char(src, '\r', ' ');
 
        conv_encode_header(dest, len, src, header_len, addr_field);
 }
@@ -5127,7 +5161,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                                        "/Spelling/Spelling Configuration");
                                gtkaspell_populate_submenu(gtkaspell, menuitem);
                                menu_set_sensitive(ifactory, "/Spelling", TRUE);
-                               }
+                       }
                }
        }
 #endif
@@ -6202,7 +6236,9 @@ static void compose_allow_user_actions (Compose *compose, gboolean allow)
        toolbar_comp_set_sensitive(compose, allow);
        menu_set_sensitive(ifactory, "/File", allow);
        menu_set_sensitive(ifactory, "/Edit", allow);
+#if USE_ASPELL
        menu_set_sensitive(ifactory, "/Spelling", allow);
+#endif 
        menu_set_sensitive(ifactory, "/Message", allow);
        menu_set_sensitive(ifactory, "/Tools", allow);
        menu_set_sensitive(ifactory, "/Help", allow);
@@ -6249,6 +6285,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
        FolderItem *draft;
        gchar *tmp;
        gint msgnum;
+       MsgFlags flag = {0, 0};
        static gboolean lock = FALSE;
        MsgInfo *newmsginfo;
        
@@ -6268,7 +6305,8 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                return;
        }
 
-       if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
+       folder_item_scan(draft);
+       if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
                unlink(tmp);
                g_free(tmp);
                lock = FALSE;
@@ -6288,6 +6326,8 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                procmsg_msginfo_free(newmsginfo);
        }
        
+       folder_item_scan(draft);
+       
        lock = FALSE;
 
        /* 0: quit editing  1: keep editing  2: keep editing (autosave) */
@@ -7006,10 +7046,15 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
                                           compose);
        gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
 
-       
        if (prefs_common.autosave && 
            gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
-               compose_draft_cb((gpointer)compose, 2, NULL);
+               gtk_timeout_add(500, (GtkFunction) compose_defer_auto_save_draft, compose);
+}
+
+static gint compose_defer_auto_save_draft(Compose *compose)
+{
+       compose_draft_cb((gpointer)compose, 2, NULL);
+       return FALSE;
 }
 
 static gboolean compose_send_control_enter(Compose *compose)