Added new command "Reply to author".
[claws.git] / src / summaryview.c
index 8712c2e9600283cc5cee00ff7a98912a65273c22..bbdd58e85c9ddc67145daf25ca633e3d81983b93 100644 (file)
@@ -72,7 +72,9 @@
 #include "filter.h"
 #include "folder.h"
 #include "addressbook.h"
+#include "addr_compl.h"
 #include "scoring.h"
+#include "prefs_folder_item.h"
 
 #include "pixmaps/dir-open.xpm"
 #include "pixmaps/mark.xpm"
@@ -318,6 +320,7 @@ static GtkItemFactoryEntry summary_popup_entries[] =
        {N_("/---"),                    NULL, NULL,             0, "<Separator>"},
        {N_("/_Reply"),                 NULL, summary_reply_cb, COMPOSE_REPLY, NULL},
        {N_("/Reply to a_ll"),          NULL, summary_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
+       {N_("/Reply to author"),        NULL, summary_reply_cb, COMPOSE_REPLY_TO_AUTHOR, NULL},
        {N_("/_Forward"),               NULL, summary_reply_cb, COMPOSE_FORWARD, NULL},
        {N_("/Forward as an a_ttachment"),
                                        NULL, summary_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
@@ -602,7 +605,8 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
 
        STATUSBAR_POP(summaryview->mainwin);
 
-       is_refresh = (item == summaryview->folder_item) ? TRUE : FALSE;
+       is_refresh = (!prefs_common.open_inbox_on_inc &&
+                     item == summaryview->folder_item) ? TRUE : FALSE;
        if (is_refresh) {
                prev_msgnum = summary_get_current_msgnum(summaryview);
                if (prev_msgnum < 1)
@@ -625,7 +629,8 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                        return FALSE;
        } else
 #endif
-               summary_write_cache(summaryview);
+               if (!is_refresh)
+                       summary_write_cache(summaryview);
 
        gtk_clist_freeze(GTK_CLIST(ctree));
 
@@ -834,13 +839,16 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
        sens = (selection == SUMMARY_SELECTED_MULTIPLE) ? FALSE : TRUE;
        menu_set_sensitive(ifactory, "/Reply",                    sens);
        menu_set_sensitive(ifactory, "/Reply to all",             sens);
+       menu_set_sensitive(ifactory, "/Reply to author",          sens);
        menu_set_sensitive(ifactory, "/Forward",                  sens);
        menu_set_sensitive(ifactory, "/Forward as an attachment", sens);
 
        menu_set_sensitive(ifactory, "/Open in new window", sens);
        menu_set_sensitive(ifactory, "/View source", sens);
        menu_set_sensitive(ifactory, "/Show all header", sens);
-       if (summaryview->folder_item->stype == F_DRAFT)
+       if ((summaryview->folder_item->stype == F_DRAFT) ||
+           (summaryview->folder_item->stype == F_OUTBOX) ||
+           (summaryview->folder_item->stype == F_QUEUE))
                menu_set_sensitive(ifactory, "/Reedit", sens);
 
        menu_set_sensitive(ifactory, "/Save as...", sens);
@@ -1321,6 +1329,9 @@ void summary_sort(SummaryView *summaryview, SummarySortType type)
        GtkCList *clist = GTK_CLIST(summaryview->ctree);
        GtkCListCompareFunc cmp_func;
 
+       if (!summaryview->folder_item)
+               return;
+
        switch (type) {
        case SORT_BY_NUMBER:
                cmp_func = (GtkCListCompareFunc)summary_cmp_by_num;
@@ -1382,9 +1393,13 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
 {
        GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
        MsgInfo *msginfo;
+       MsgInfo *parentinfo;
+       MsgInfo *cur_msginfo;
        GtkCTreeNode *node, *parent;
        gchar *text[N_SUMMARY_COLS];
        GHashTable *msgid_table;
+       GSList * cur;
+       GtkCTreeNode *cur_parent;
 
        if (!mlist) return;
 
@@ -1395,17 +1410,29 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
        msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
        summaryview->msgid_table = msgid_table;
 
-       if (prefs_common.enable_thread) {
+       if (prefs_common.use_addr_book)
+               start_address_completion();
+       
+       main_window_set_thread_option(summaryview->mainwin);
+
+       for (cur = mlist ; cur != NULL; cur = cur->next) {
+               msginfo = (MsgInfo *)cur->data;
+               msginfo->threadscore = msginfo->score;
+       }
+
+       /*      if (prefs_common.enable_thread) { */
+       if (summaryview->folder_item->prefs->enable_thread) {
                for (; mlist != NULL; mlist = mlist->next) {
                        msginfo = (MsgInfo *)mlist->data;
                        parent = NULL;
 
-                       summary_set_header(text, msginfo);
-
                        /* search parent node for threading */
-                       if (msginfo->inreplyto && *msginfo->inreplyto)
+                       if (msginfo->inreplyto && *msginfo->inreplyto) {
                                parent = g_hash_table_lookup
                                        (msgid_table, msginfo->inreplyto);
+                       }
+
+                       summary_set_header(text, msginfo);
 
                        node = gtk_ctree_insert_node
                                (ctree, parent, NULL, text, 2,
@@ -1420,6 +1447,33 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                            == NULL)
                                g_hash_table_insert(msgid_table,
                                                    msginfo->msgid, node);
+
+                       cur_parent = parent;
+                       cur_msginfo = msginfo;
+                       while (cur_parent != NULL) {
+                               parentinfo = gtk_ctree_node_get_row_data(ctree, cur_parent);
+
+                               if (!parentinfo)
+                                       break;
+                               
+                               if (parentinfo->threadscore <
+                                   cur_msginfo->threadscore) {
+                                       gchar * s;
+                                       parentinfo->threadscore =
+                                               cur_msginfo->threadscore;
+#if 0
+                                       s = itos(parentinfo->threadscore);
+                                       gtk_ctree_node_set_text(ctree, cur_parent, S_COL_SCORE, s);
+#endif
+                               }
+                               else break;
+                               
+                               cur_msginfo = parentinfo;
+                               if (cur_msginfo->inreplyto &&
+                                   *cur_msginfo->inreplyto) {
+                                       cur_parent = g_hash_table_lookup(msgid_table, cur_msginfo->inreplyto);
+                               }
+                       }
                }
 
                /* complete the thread */
@@ -1453,6 +1507,9 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                                           optimal_width);
        }
 
+       if (prefs_common.use_addr_book)
+               end_address_completion();
+
        debug_print(_("done.\n"));
        STATUSBAR_POP(summaryview->mainwin);
        if (debug_mode)
@@ -1536,6 +1593,7 @@ static void summary_set_header(gchar *text[], MsgInfo *msginfo)
 {
        static gchar date_modified[80];
        static gchar *to = NULL;
+       static gchar *from_name = NULL;
        static gchar col_number[11];
        static gchar col_score[11];
 
@@ -1544,7 +1602,11 @@ static void summary_set_header(gchar *text[], MsgInfo *msginfo)
        text[S_COL_MIME] = NULL;
        text[S_COL_NUMBER] = itos_buf(col_number, msginfo->msgnum);
        text[S_COL_SIZE]   = to_human_readable(msginfo->size);
+#if 0
+       text[S_COL_SCORE]  = itos_buf(col_score, msginfo->threadscore);
+#else
        text[S_COL_SCORE]  = itos_buf(col_score, msginfo->score);
+#endif
 
        if (msginfo->date_t) {
                procheader_date_get_localtime(date_modified,
@@ -1559,7 +1621,8 @@ static void summary_set_header(gchar *text[], MsgInfo *msginfo)
        text[S_COL_FROM] = msginfo->fromname ? msginfo->fromname :
                _("(No From)");
        if (prefs_common.swap_from && msginfo->from && msginfo->to &&
-           cur_account && cur_account->address) {
+           cur_account && cur_account->address &&
+           !MSG_IS_NEWS(msginfo->flags)) {
                gchar *from;
 
                Xalloca(from, strlen(msginfo->from) + 1, return);
@@ -1572,6 +1635,24 @@ static void summary_set_header(gchar *text[], MsgInfo *msginfo)
                }
        }
 
+       if ((text[S_COL_FROM] != to) && prefs_common.use_addr_book &&
+           msginfo->from) {
+               gint count;
+               gchar *from;
+  
+               Xalloca(from, strlen(msginfo->from) + 1, return);
+               strcpy(from, msginfo->from);
+               extract_address(from);
+               count = complete_address(from);
+               if (count > 1) {
+                       g_free(from_name);
+                       from = get_complete_address(1);
+                       from_name = procheader_get_fromname(from);
+                       g_free(from);
+                       text[S_COL_FROM] = from_name;
+               }
+       }
+
        text[S_COL_SUBJECT] = msginfo->subject ? msginfo->subject :
                _("(No Subject)");
 }
@@ -1678,7 +1759,9 @@ void summary_reedit(SummaryView *summaryview)
 
        if (!summaryview->selected) return;
        if (!summaryview->folder_item ||
-           summaryview->folder_item->stype != F_DRAFT) return;
+           (summaryview->folder_item->stype != F_DRAFT &&
+            summaryview->folder_item->stype != F_OUTBOX &&
+            summaryview->folder_item->stype != F_QUEUE)) return;
 
        msginfo = gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
                                              summaryview->selected);
@@ -2219,6 +2302,7 @@ void summary_print(SummaryView *summaryview)
            strchr(p + 2, '%')) {
                alertpanel_error(_("Print command line is invalid:\n`%s'"),
                                 cmdline);
+               g_free(cmdline);
                return;
        }
 
@@ -2227,6 +2311,8 @@ void summary_print(SummaryView *summaryview)
                        (ctree, GTK_CTREE_NODE(cur->data));
                if (msginfo) procmsg_print_message(msginfo, cmdline);
        }
+       
+       g_free(cmdline);
 }
 
 void summary_execute(SummaryView *summaryview)
@@ -2922,31 +3008,44 @@ static void summary_reply_cb(SummaryView *summaryview, guint action,
 
        switch ((ComposeReplyMode)action) {
        case COMPOSE_REPLY:
-               compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, FALSE);
                break;
        case COMPOSE_REPLY_WITH_QUOTE:
-               compose_reply(msginfo, TRUE, FALSE);
+               compose_reply(msginfo, TRUE, FALSE, FALSE);
                break;
        case COMPOSE_REPLY_WITHOUT_QUOTE:
-               compose_reply(msginfo, FALSE, FALSE);
+               compose_reply(msginfo, FALSE, FALSE, FALSE);
                break;
        case COMPOSE_REPLY_TO_ALL:
-               compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             TRUE, FALSE);
                break;
        case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
-               compose_reply(msginfo, TRUE, TRUE);
+               compose_reply(msginfo, TRUE, TRUE, FALSE);
                break;
        case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
-               compose_reply(msginfo, FALSE, TRUE);
+               compose_reply(msginfo, FALSE, TRUE, FALSE);
+               break;
+       case COMPOSE_REPLY_TO_AUTHOR:
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, TRUE);
+               break;
+       case COMPOSE_REPLY_TO_AUTHOR_WITH_QUOTE:
+               compose_reply(msginfo, TRUE, FALSE, TRUE);
+               break;
+       case COMPOSE_REPLY_TO_AUTHOR_WITHOUT_QUOTE:
+               compose_reply(msginfo, FALSE, FALSE, TRUE);
                break;
        case COMPOSE_FORWARD:
-               compose_forward(msginfo, FALSE);
+               compose_forward(NULL, msginfo, FALSE);
                break;
        case COMPOSE_FORWARD_AS_ATTACH:
-               compose_forward(msginfo, TRUE);
+               compose_forward(NULL, msginfo, TRUE);
                break;
        default:
-               compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, FALSE);
        }
 
        summary_set_marks_selected(summaryview);
@@ -3192,7 +3291,7 @@ static gint summary_cmp_by_score(GtkCList *clist,
 
        /* if score are equal, sort by date */
 
-       diff = msginfo1->score - msginfo2->score;
+       diff = msginfo1->threadscore - msginfo2->threadscore;
        if (diff != 0)
                return diff;
        else