2009-12-29 [colin] 3.7.3cvs46
[claws.git] / src / compose.c
index 18950822f9454ce511978e9215d9d91c64e3fea9..b6f3dcbdb5ae8d6bcb4c2f6c513a80c830cbdd6f 100644 (file)
@@ -1115,6 +1115,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        g_free(subject);
                        g_free(tmp);
+                       mfield = SUBJECT_FIELD_PRESENT;
                }
 
                if ( body_format
@@ -1143,9 +1144,10 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        g_free(tmp);
 #ifdef USE_ENCHANT
-                       if (compose->gtkaspell->check_while_typing)
+                       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
+                       mfield = BODY_FIELD_PRESENT;
                }
 
        }
@@ -1176,16 +1178,24 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        /* Place cursor according to provided input (mfield) */
        switch (mfield) { 
                case NO_FIELD_PRESENT:
-                       gtk_widget_grab_focus(compose->header_last->entry);
+                       if (compose->header_last)
+                               gtk_widget_grab_focus(compose->header_last->entry);
                        break;
                case TO_FIELD_PRESENT:
-                       buf = g_strdup("");
-                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);     
+                       buf = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
+                       if (buf) {
+                               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
+                               g_free(buf);
+                       }
                        gtk_widget_grab_focus(compose->subject_entry);
                        break;
                case SUBJECT_FIELD_PRESENT:
                        textview = GTK_TEXT_VIEW(compose->text);
+                       if (!textview)
+                               break;
                        textbuf = gtk_text_view_get_buffer(textview);
+                       if (!textbuf)
+                               break;
                        mark = gtk_text_buffer_get_insert(textbuf);
                        gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
                        gtk_text_buffer_insert(textbuf, &iter, "", -1);
@@ -1212,6 +1222,9 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        compose->modified = FALSE;
        compose_set_title(compose);
+
+  hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1606,7 +1619,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                quote_fmt_reset_vartable();
 #ifdef USE_ENCHANT
-               if (compose->gtkaspell->check_while_typing)
+               if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                        gtkaspell_highlight_all(compose->gtkaspell);
 #endif
        }
@@ -1649,6 +1662,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
        END_TIMING();
+
        return compose;
 }
 
@@ -1802,7 +1816,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                procmsg_msginfo_free(full_msginfo);
 #ifdef USE_ENCHANT
-               if (compose->gtkaspell->check_while_typing)
+               if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                        gtkaspell_highlight_all(compose->gtkaspell);
 #endif
        }
@@ -1848,6 +1862,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1994,6 +2010,8 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2100,7 +2118,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        }
 
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
-           folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
+           folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
+           folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
                gchar queueheader_buf[BUFFSIZE];
                gint id, param;
 
@@ -2237,7 +2256,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        compose_extract_original_charset(compose);
 
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
-           folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
+           folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
+           folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
                gchar queueheader_buf[BUFFSIZE];
 
                /* Set message save folder */
@@ -2322,6 +2342,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        
        compose->sig_str = account_get_signature_str(compose->account);
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2427,6 +2449,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -3039,6 +3063,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        GSList *cur;
        gchar *from = NULL;
        gchar *replyto = NULL;
+       gchar *ac_email = NULL;
 
        gboolean reply_to_ml = FALSE;
        gboolean default_reply_to = FALSE;
@@ -3201,13 +3226,27 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        cc_list = address_list_append_with_comments(cc_list, msginfo->to);
        cc_list = address_list_append_with_comments(cc_list, compose->cc);
 
+       ac_email = g_utf8_strdown(compose->account->address, -1);
+
        if (cc_list) {
-               for (cur = cc_list; cur != NULL; cur = cur->next)
-                       compose_entry_append(compose, (gchar *)cur->data,
-                                            COMPOSE_CC, PREF_NONE);
+               for (cur = cc_list; cur != NULL; cur = cur->next) {
+                       gchar *addr = g_utf8_strdown(cur->data, -1);
+                       extract_address(addr);
+               
+                       if (strcmp(ac_email, addr))
+                               compose_entry_append(compose, (gchar *)cur->data,
+                                                    COMPOSE_CC, PREF_NONE);
+                       else
+                               debug_print("Cc address same as compose account's, ignoring\n");
+
+                       g_free(addr);
+               }
+               
                slist_free_strings(cc_list);
                g_slist_free(cc_list);
        }
+       
+       g_free(ac_email);
 }
 
 #define SET_ENTRY(entry, str) \
@@ -4603,20 +4642,12 @@ compose_current_mail_account(void)
 static void compose_select_account(Compose *compose, PrefsAccount *account,
                                   gboolean init)
 {
-       gchar *from = NULL, *email, *header;
+       gchar *from = NULL, *header;
        ComposeHeaderEntry *header_entry;
 
        cm_return_if_fail(account != NULL);
 
-       email = g_utf8_strdown(compose->account->address, -1);
-       g_hash_table_remove(compose->email_hashtable, email);
-       g_free(email);
-
        compose->account = account;
-       g_hash_table_insert(compose->email_hashtable,
-                           g_utf8_strdown(account->address, -1),
-                           GUINT_TO_POINTER(1)); 
-
        if (account->name && *account->name) {
                gchar *buf;
                QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
@@ -6525,12 +6556,14 @@ static void compose_add_header_entry(Compose *compose, const gchar *header,
 {
        ComposeHeaderEntry *last_header = compose->header_last;
        gchar *tmp = g_strdup(text), *email;
+       gboolean replyto_hdr = g_str_has_suffix(header, "-To:");
        
        extract_address(tmp);
        email = g_utf8_strdown(tmp, -1);
        
-       if (!(!strcmp(header, "To:") && !strcasecmp(compose->account->address, email))
-           && g_hash_table_lookup(compose->email_hashtable, email) != NULL) {
+       if (replyto_hdr == FALSE &&
+           g_hash_table_lookup(compose->email_hashtable, email) != NULL)
+       {
                debug_print("Ignoring duplicate address - %s %s, pref_type: %d\n",
                                header, text, (gint) pref_type);
                g_free(email);
@@ -6542,8 +6575,12 @@ static void compose_add_header_entry(Compose *compose, const gchar *header,
        gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
        last_header->type = pref_type;
 
-       g_hash_table_insert(compose->email_hashtable, email,
-                               GUINT_TO_POINTER(1));
+       if (replyto_hdr == FALSE)
+               g_hash_table_insert(compose->email_hashtable, email,
+                                   GUINT_TO_POINTER(1));
+       else
+               g_free(email);
+       
        g_free(tmp);
 }
 
@@ -6902,7 +6939,8 @@ static void compose_dict_changed(void *data)
 {
        Compose *compose = (Compose *) data;
 
-       if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
+       if(compose->gtkaspell && 
+                  compose->gtkaspell->recheck_when_changing_dict == FALSE)
                return;
 
        gtkaspell_highlight_all(compose->gtkaspell);
@@ -7515,7 +7553,7 @@ static Compose *compose_create(PrefsAccount *account,
                        }
                }
        }
-        compose->gtkaspell = gtkaspell;
+    compose->gtkaspell = gtkaspell;
        compose_spell_menu_changed(compose);
        claws_spell_entry_set_gtkaspell(CLAWS_SPELL_ENTRY(subject_entry), gtkaspell);
 #endif
@@ -8101,7 +8139,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        compose_changed_cb(NULL, compose);
 
 #ifdef USE_ENCHANT
-       if (compose->gtkaspell->check_while_typing)
+       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -8238,6 +8276,8 @@ static void compose_destroy(Compose *compose)
        slist_free_strings(compose->header_list);
        g_slist_free(compose->header_list);
 
+       compose->header_list = compose->newsgroup_list = compose->to_list = NULL;
+
        g_hash_table_destroy(compose->email_hashtable);
 
        procmsg_msginfo_free(compose->targetinfo);
@@ -9598,7 +9638,8 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
        }
 
 #ifdef USE_ENCHANT     
-       if (files_inserted > 0 && compose->gtkaspell->check_while_typing)
+       if (files_inserted > 0 && compose->gtkaspell && 
+                   compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9882,7 +9923,8 @@ static void compose_paste_cb(GtkAction *action, gpointer data)
 
 #ifdef USE_ENCHANT
        if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9931,7 +9973,8 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data)
 
 #ifdef USE_ENCHANT
        if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9953,7 +9996,8 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
 
 #ifdef USE_ENCHANT
        if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+           compose->gtkaspell &&
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -11029,6 +11073,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
        }
        g_free(s_system);
        g_free(body);
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
 }
 
 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,