Use selected text on reply/forward.
authorDarko Koruga <darko@users.sourceforge.net>
Thu, 7 Feb 2002 09:26:39 +0000 (09:26 +0000)
committerDarko Koruga <darko@users.sourceforge.net>
Thu, 7 Feb 2002 09:26:39 +0000 (09:26 +0000)
13 files changed:
ChangeLog.claws
configure.in
src/compose.c
src/compose.h
src/filtering.c
src/gtkutils.c
src/gtkutils.h
src/prefs_template.c
src/quote_fmt.h
src/quote_fmt_parse.y
src/summaryview.c
src/utils.c
src/utils.h

index df143d6..d19403e 100644 (file)
@@ -1,3 +1,16 @@
+2002-02-07 [darko]     0.7.0claws54
+
+       * src/compose.[ch]
+       * src/filtering.c
+       * src/gtkutils.[ch]
+       * src/prefs_template.c
+       * src/quote_fmt.h
+       * src/quote_fmt_parse.y
+       * src/summaryview.c
+       * src/utils.[ch]
+               When replying or forwarding an email don't quote the entire
+               mail body but use the part of the message text that is selected
+
 2002-02-06 [melvin]    0.7.0claws53
 
        * src/prefs_common.[ch]
index a4b6cb0..647440f 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws53
+EXTRA_VERSION=claws54
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 8e36fe7..5cd42c3 100644 (file)
@@ -172,7 +172,8 @@ static gchar *compose_parse_references              (const gchar    *ref,
 static gchar *compose_quote_fmt                        (Compose        *compose,
                                                 MsgInfo        *msginfo,
                                                 const gchar    *fmt,
-                                                const gchar    *qmark);
+                                                const gchar    *qmark,
+                                                const gchar    *seltext);
 
 static void compose_reply_set_entry            (Compose        *compose,
                                                 MsgInfo        *msginfo,
@@ -441,7 +442,8 @@ static void compose_attach_parts    (Compose        *compose,
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                                  gboolean to_all,
                                  gboolean ignore_replyto,
-                                 gboolean followup_and_reply_to);
+                                 gboolean followup_and_reply_to,
+                                 const gchar *seltext);
 
 void compose_headerentry_changed_cb       (GtkWidget          *entry,
                                            ComposeHeaderEntry *headerentry);
@@ -664,7 +666,7 @@ Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
                                   msginfo->subject);
        gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
 
-       compose_quote_fmt(c, msginfo, "%M", NULL);
+       compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
        gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
 
        ifactory = gtk_item_factory_from_widget(c->popupmenu);
@@ -797,22 +799,26 @@ Compose *compose_new_followup_and_replyto(PrefsAccount *account,
 */
 
 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
-                  gboolean ignore_replyto)
+                  gboolean ignore_replyto, const gchar *seltext)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
+       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
+                             seltext);
 }
 
 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
                                   gboolean to_all,
-                                  gboolean ignore_replyto)
+                                  gboolean ignore_replyto,
+                                  const gchar *seltext)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
+       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
+                             seltext);
 }
 
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                                  gboolean to_all,
                                  gboolean ignore_replyto,
-                                 gboolean followup_and_reply_to)
+                                 gboolean followup_and_reply_to,
+                                 const gchar *seltext)
 {
        Compose *compose;
        PrefsAccount *account;
@@ -919,7 +925,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
 
                quote_str = compose_quote_fmt(compose, msginfo,
                                              prefs_common.quotefmt,
-                                             qmark);
+                                             qmark, seltext);
        }
 
        if (prefs_common.auto_sig)
@@ -934,7 +940,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        gtk_stext_thaw(text);
        gtk_widget_grab_focus(compose->text);
 
-        if (prefs_common.auto_exteditor)
+       if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
 }
 
@@ -1160,7 +1166,7 @@ if (msginfo->var && *msginfo->var) { \
 }
 
 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
-                        gboolean as_attach)
+                        gboolean as_attach, const gchar *seltext)
 {
        Compose *compose;
        /*      PrefsAccount *account; */
@@ -1232,7 +1238,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                        qmark = "> ";
 
                quote_str = compose_quote_fmt(compose, msginfo,
-                                             prefs_common.fw_quotefmt, qmark);
+                                             prefs_common.fw_quotefmt, qmark,
+                                             seltext);
                compose_attach_parts(compose, msginfo);
        }
 
@@ -1702,7 +1709,8 @@ static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
 }
 
 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
-                               const gchar *fmt, const gchar *qmark)
+                               const gchar *fmt, const gchar *qmark,
+                               const gchar *seltext)
 {
        GtkSText *text = GTK_STEXT(compose->text);
        gchar *quote_str = NULL;
@@ -1711,7 +1719,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        gint len;
 
        if (qmark != NULL) {
-               quote_fmt_init(msginfo, NULL);
+               quote_fmt_init(msginfo, NULL, NULL);
                quote_fmt_scan_string(qmark);
                quote_fmt_parse();
 
@@ -1723,7 +1731,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        }
 
        if (fmt && *fmt != '\0') {
-               quote_fmt_init(msginfo, quote_str);
+               quote_fmt_init(msginfo, quote_str, seltext);
                quote_fmt_scan_string(fmt);
                quote_fmt_parse();
 
@@ -5028,7 +5036,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl)
 
                memset(&dummyinfo, 0, sizeof(MsgInfo));
                parsed_str = compose_quote_fmt(compose, &dummyinfo,
-                                              tmpl->value, NULL);
+                                              tmpl->value, NULL, NULL);
        } else {
                if (prefs_common.quotemark && *prefs_common.quotemark)
                        qmark = prefs_common.quotemark;
@@ -5036,7 +5044,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl)
                        qmark = "> ";
 
                parsed_str = compose_quote_fmt(compose, compose->replyinfo,
-                                              tmpl->value, qmark);
+                                              tmpl->value, qmark, NULL);
        }
 
        if (parsed_str && prefs_common.auto_sig)
index a9011b7..169a3e4 100644 (file)
@@ -219,14 +219,17 @@ Compose *compose_new_with_folderitem      (PrefsAccount   *account,
 void compose_followup_and_reply_to     (MsgInfo        *msginfo,
                                         gboolean        quote,
                                         gboolean        to_all,
-                                        gboolean        ignore_replyto);
+                                        gboolean        ignore_replyto,
+                                        const gchar    *seltext);
 void compose_reply                     (MsgInfo        *msginfo,
                                         gboolean        quote,
                                         gboolean        to_all,
-                                        gboolean        ignore_replyto);
+                                        gboolean        ignore_replyto,
+                                        const gchar    *seltext);
 Compose *compose_forward               (PrefsAccount *account,
                                         MsgInfo        *msginfo,
-                                        gboolean        as_attach);
+                                        gboolean        as_attach,
+                                        const gchar    *seltext);
 Compose *compose_forward_multiple      (PrefsAccount   *account, 
                                         GSList         *msginfo_list);
 Compose *compose_bounce                        (PrefsAccount   *account,
index a679a62..d3a2070 100644 (file)
@@ -193,7 +193,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
 
        case MATCHACTION_FORWARD:
                account = account_find_from_id(action->account_id);
-               compose = compose_forward(account, info, FALSE);
+               compose = compose_forward(account, info, FALSE, NULL);
                if (compose->account->protocol == A_NNTP)
                        compose_entry_append(compose, action->destination,
                                             COMPOSE_NEWSGROUPS);
@@ -213,7 +213,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
        case MATCHACTION_FORWARD_AS_ATTACHMENT:
 
                account = account_find_from_id(action->account_id);
-               compose = compose_forward(account, info, TRUE);
+               compose = compose_forward(account, info, TRUE, NULL);
                if (compose->account->protocol == A_NNTP)
                        compose_entry_append(compose, action->destination,
                                             COMPOSE_NEWSGROUPS);
index b7910bc..2aad297 100644 (file)
@@ -486,4 +486,24 @@ void gtkut_widget_set_composer_icon(GtkWidget *widget)
        gdk_window_set_icon(widget->window, NULL, xpm, bmp);    
 }
 
+const gchar *gtkut_get_selection(GtkWidget *widget)
+{
+       gchar *seltext = NULL;
+       guint start_pos, end_pos;
+       GtkEditable *editable = (GtkEditable *) widget;
+
+       if (editable->has_selection) {
+               if (editable->selection_start_pos < editable->selection_end_pos) {
+                       start_pos = editable->selection_start_pos;
+                       end_pos = editable->selection_end_pos;
+               }
+               else {
+                       start_pos = editable->selection_end_pos;
+                       end_pos = editable->selection_start_pos;
+               }
 
+               seltext = gtk_editable_get_chars(editable, start_pos, end_pos);
+       }
+
+       return seltext;
+}
index 0cc5c3a..994664d 100644 (file)
@@ -134,4 +134,5 @@ void gtkut_widget_init                      (void);
 void gtkut_widget_set_app_icon         (GtkWidget      *widget);
 void gtkut_widget_set_composer_icon    (GtkWidget      *widget);
 
+const gchar *gtkut_get_selection       (GtkWidget      *widget);
 #endif /* __GTKUTILS_H__ */
index 6e5d726..22c9868 100644 (file)
@@ -433,7 +433,7 @@ static gint prefs_template_clist_set_row(gint row)
                MsgInfo dummyinfo;
 
                memset(&dummyinfo, 0, sizeof(MsgInfo));
-               quote_fmt_init(&dummyinfo, NULL);
+               quote_fmt_init(&dummyinfo, NULL, NULL);
                quote_fmt_scan_string(value);
                quote_fmt_parse();
                parsed_buf = quote_fmt_get_buffer();
index cbeda39..0e18f43 100644 (file)
@@ -5,7 +5,7 @@
 #define quote_fmt_parse        quote_fmtparse
 
 gchar *quote_fmt_get_buffer(void);
-void quote_fmt_init(MsgInfo *info, gchar *my_quote_str);
+void quote_fmt_init(MsgInfo *info, gchar *my_quote_str, const gchar *seltext);
 gint quote_fmtparse(void);
 void quote_fmt_scan_string(const gchar *str);
 
index 42122f9..6125d33 100644 (file)
@@ -23,6 +23,7 @@ int yylex(void);
 
 static MsgInfo *msginfo = NULL;
 static gboolean *visible = NULL;
+static gchar *seltext = NULL;
 static gint maxsize = 0;
 static gint stacksize = 0;
 
@@ -93,10 +94,12 @@ gchar *quote_fmt_get_buffer(void)
                add_buffer(tmp); \
        }
 
-void quote_fmt_init(MsgInfo *info, gchar *my_quote_str)
+void quote_fmt_init(MsgInfo *info, gchar *my_quote_str,
+                   const gchar *selectiontext)
 {
        quote_str = my_quote_str;
        msginfo = info;
+       seltext = (gchar *) selectiontext;
        stacksize = 0;
        add_visibility(TRUE);
        if (buffer != NULL)
@@ -261,7 +264,10 @@ special:
        }
        | SHOW_MESSAGE
        {
-               if (msginfo->folder) {
+               if (seltext) {
+                       INSERT(seltext);
+               }
+               else if (msginfo->folder) {
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
@@ -279,12 +285,22 @@ special:
        }
        | SHOW_QUOTED_MESSAGE
        {
-               if (msginfo->folder) {
+               gchar *tmp_file = NULL;
+
+               if (seltext)
+                       tmp_file = write_buffer_to_file(seltext,
+                                                       strlen(seltext));
+
+               if (msginfo->folder || tmp_file) {
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (tmp_file)
+                               fp = fopen(tmp_file, "r");
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -296,15 +312,28 @@ special:
                                fclose(fp);
                        }
                }
+
+               if (tmp_file)
+                       unlink(tmp_file);
        }
        | SHOW_MESSAGE_NO_SIGNATURE
        {
+               gchar *tmp_file = NULL;
+
+               if (seltext)
+                       tmp_file = write_buffer_to_file(seltext,
+                                                       strlen(seltext));
+
                if (msginfo->folder) {
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (tmp_file)
+                               fp = fopen(tmp_file, "r");
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -316,15 +345,28 @@ special:
                                fclose(fp);
                        }
                }
+
+               if (tmp_file)
+                       unlink(tmp_file);
        }
        | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
        {
-               if (msginfo->folder) {
+               gchar *tmp_file = NULL;
+
+               if (seltext)
+                       tmp_file = write_buffer_to_file(seltext,
+                                                       strlen(seltext));
+
+               if (msginfo->folder || tmp_file) {
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (tmp_file)
+                               fp = fopen(tmp_file, "r");
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -338,6 +380,9 @@ special:
                                fclose(fp);
                        }
                }
+
+               if (tmp_file)
+                       unlink(tmp_file);
        }
        | SHOW_BACKSLASH
        {
index 550985a..6832c02 100644 (file)
@@ -3966,46 +3966,53 @@ void summary_reply(SummaryView *summaryview, ComposeMode mode)
        GtkWidget *widget;
        MsgInfo *msginfo;
        GList  *sel = GTK_CLIST(summaryview->ctree)->selection;
+       gchar *seltext = NULL;
 
        msginfo = gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
                                              summaryview->selected);
        if (!msginfo) return;
 
+       if (summaryview && summaryview->messageview  &&
+           summaryview->messageview->textview       &&
+           summaryview->messageview->textview->text)
+               seltext = (gchar *) gtkut_get_selection(
+                               summaryview->messageview->textview->text);
+
        switch (mode) {
        case COMPOSE_REPLY:
                compose_reply(msginfo, prefs_common.reply_with_quote,
-                             FALSE, FALSE);
+                             FALSE, FALSE, seltext);
                break;
        case COMPOSE_REPLY_WITH_QUOTE:
-               compose_reply(msginfo, TRUE, FALSE, FALSE);
+               compose_reply(msginfo, TRUE, FALSE, FALSE, seltext);
                break;
        case COMPOSE_REPLY_WITHOUT_QUOTE:
-               compose_reply(msginfo, FALSE, FALSE, FALSE);
+               compose_reply(msginfo, FALSE, FALSE, FALSE, seltext);
                break;
        case COMPOSE_REPLY_TO_SENDER:
                compose_reply(msginfo, prefs_common.reply_with_quote,
-                             FALSE, TRUE);
+                             FALSE, TRUE, seltext);
                break;
        case COMPOSE_FOLLOWUP_AND_REPLY_TO:
                compose_followup_and_reply_to(msginfo,
                                              prefs_common.reply_with_quote,
-                                             FALSE, TRUE);
+                                             FALSE, TRUE, seltext);
                break;
        case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
-               compose_reply(msginfo, TRUE, FALSE, TRUE);
+               compose_reply(msginfo, TRUE, FALSE, TRUE, seltext);
                break;
        case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
-               compose_reply(msginfo, FALSE, FALSE, TRUE);
+               compose_reply(msginfo, FALSE, FALSE, TRUE, seltext);
                break;
        case COMPOSE_REPLY_TO_ALL:
                compose_reply(msginfo, prefs_common.reply_with_quote,
-                             TRUE, TRUE);
+                             TRUE, TRUE, seltext);
                break;
        case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
-               compose_reply(msginfo, TRUE, TRUE, TRUE);
+               compose_reply(msginfo, TRUE, TRUE, TRUE, seltext);
                break;
        case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
-               compose_reply(msginfo, FALSE, TRUE, TRUE);
+               compose_reply(msginfo, FALSE, TRUE, TRUE, seltext);
                break;
        case COMPOSE_FORWARD:
                if (prefs_common.forward_as_attachment) {
@@ -4018,7 +4025,7 @@ void summary_reply(SummaryView *summaryview, ComposeMode mode)
                break;
        case COMPOSE_FORWARD_INLINE:
                if (!sel->next) {
-                       compose_forward(NULL, msginfo, FALSE);
+                       compose_forward(NULL, msginfo, FALSE, seltext);
                        break;
                }
                /* if (sel->next) FALL THROUGH */
@@ -4041,6 +4048,9 @@ void summary_reply(SummaryView *summaryview, ComposeMode mode)
        }
 
        summary_set_marks_selected(summaryview);
+
+       if (seltext)
+               g_free((gchar *) seltext);
 }
 
 /* color label */
index 8d7ce66..67df650 100644 (file)
@@ -1842,6 +1842,22 @@ FILE *my_tmpfile(void)
        return tmpfile();
 }
 
+gchar *write_buffer_to_file(const gchar *buf, guint bufsize)
+{
+       FILE *fp;
+       gchar *tmp_file = NULL;
+
+       tmp_file = get_tmp_file();
+       fp = fopen(tmp_file, "w");
+       if (fp) {
+               fwrite(buf, 1, bufsize, fp);
+               fclose(fp);
+       }
+       else tmp_file = NULL;
+
+       return tmp_file;
+}
+
 gint execute_async(gchar *const argv[])
 {
        pid_t pid;
index 04802f3..e8ce4ce 100644 (file)
@@ -313,6 +313,8 @@ gint move_file                      (const gchar    *src,
 gint change_file_mode_rw       (FILE           *fp,
                                 const gchar    *file);
 FILE *my_tmpfile               (void);
+gchar *write_buffer_to_file    (const gchar    *buf,
+                                guint           bufsize);
 
 #define is_file_exist(file)            file_exist(file, FALSE)
 #define is_file_or_fifo_exist(file)    file_exist(file, TRUE)