2010-01-03 [mir] 3.7.3cvs51
[claws.git] / src / compose.c
index c6bf249725a3a2327700da7b26f2a1ca1a638290..429e77c45086658b82cb160e985bd2a0983b3543 100644 (file)
@@ -1059,6 +1059,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
                } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
                        compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS, PREF_FOLDER);
+                       mfield = TO_FIELD_PRESENT;
                }
                /*
                 * CLAWS: just don't allow return receipt request, even if the user
@@ -1144,7 +1145,7 @@ 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;
@@ -1222,6 +1223,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;
 }
 
@@ -1616,7 +1620,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
        }
@@ -1659,6 +1663,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
        END_TIMING();
+
        return compose;
 }
 
@@ -1812,7 +1817,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
        }
@@ -1858,6 +1863,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -2004,6 +2011,8 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2110,7 +2119,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;
 
@@ -2247,7 +2257,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 */
@@ -2332,6 +2343,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;
 }
 
@@ -2437,6 +2450,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -3049,6 +3064,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;
@@ -3211,13 +3227,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) \
@@ -4613,20 +4643,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);
@@ -6535,12 +6557,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);
@@ -6552,8 +6576,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);
 }
 
@@ -6912,7 +6940,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);
@@ -7525,7 +7554,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
@@ -8111,7 +8140,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
 }
@@ -9610,7 +9639,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
 }
@@ -9894,7 +9924,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
 }
@@ -9943,7 +9974,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
 }
@@ -9965,7 +9997,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
 }
@@ -11041,6 +11074,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,