Global and per-folder templates can now override the From name (this
authorTristan Chabredier <wwp@claws-mail.org>
Thu, 6 Mar 2008 12:44:22 +0000 (12:44 +0000)
committerTristan Chabredier <wwp@claws-mail.org>
Thu, 6 Mar 2008 12:44:22 +0000 (12:44 +0000)
doesn't change the account being used), satisfying bug #1456.
Examples:
 "My other name" <%account_email> (just changes the name)
 my.faked.email@address.org (overrides the address too)

src/common/template.c
src/common/template.h
src/compose.c
src/folder_item_prefs.c
src/folder_item_prefs.h
src/prefs_account.c
src/prefs_folder_item.c
src/prefs_quote.c
src/prefs_template.c
src/quote_fmt.c
src/quote_fmt.h

index 2a5a673..029f455 100644 (file)
@@ -48,6 +48,7 @@ static Template *template_load(gchar *filename)
        tmpl->load_filename = g_strdup(filename);;
        tmpl->name = NULL;
        tmpl->subject = NULL;
+       tmpl->from = NULL;
        tmpl->to = NULL;
        tmpl->cc = NULL;        
        tmpl->bcc = NULL;       
@@ -58,6 +59,8 @@ static Template *template_load(gchar *filename)
                        break;
                else if (!g_ascii_strncasecmp(buf, "Name:", 5))
                        tmpl->name = g_strdup(g_strstrip(buf + 5));
+               else if (!g_ascii_strncasecmp(buf, "From:", 5))
+                       tmpl->from = g_strdup(g_strstrip(buf + 5));
                else if (!g_ascii_strncasecmp(buf, "To:", 3))
                        tmpl->to = g_strdup(g_strstrip(buf + 3));
                else if (!g_ascii_strncasecmp(buf, "Cc:", 3))
@@ -244,6 +247,8 @@ static void template_write_config(GSList *tmpl_list)
                TRY(fprintf(fp, "Name: %s\n", tmpl->name) > 0);
                if (tmpl->subject && *tmpl->subject != '\0')
                        TRY(fprintf(fp, "Subject: %s\n", tmpl->subject) > 0);
+               if (tmpl->from && *tmpl->from != '\0')
+                       TRY(fprintf(fp, "From: %s\n", tmpl->from) > 0);
                if (tmpl->to && *tmpl->to != '\0')
                        TRY(fprintf(fp, "To: %s\n", tmpl->to) > 0);
                if (tmpl->cc && *tmpl->cc != '\0')
index 458c170..5806af4 100644 (file)
@@ -29,6 +29,7 @@ struct _Template {
        gchar *load_filename;
        gchar *name;
        gchar *subject;
+       gchar *from;
        gchar *to;
        gchar *cc;
        gchar *bcc;             
index 5400ac5..d14f8d8 100644 (file)
@@ -1006,6 +1006,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        const gchar *body_format = NULL;
        gchar *mailto_from = NULL;
        PrefsAccount *mailto_account = NULL;
+       MsgInfo* dummyinfo = NULL;
 
        /* check if mailto defines a from */
        if (mailto && *mailto != '\0') {
@@ -1033,7 +1034,40 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        if (mailto_from) {
                gtk_entry_set_text(GTK_ENTRY(compose->from_name), mailto_from);
                g_free(mailto_from);
-       }
+       } else
+               /* override from name according to folder properties */
+               if (item && item->prefs &&
+                       item->prefs->compose_with_format &&
+                       item->prefs->compose_override_from_format &&
+                       *item->prefs->compose_override_from_format != '\0') {
+
+                       gchar *tmp = NULL;
+                       gchar *buf = NULL;
+
+                       dummyinfo = compose_msginfo_new_from_compose(compose);
+
+                       /* decode \-escape sequences in the internal representation of the quote format */
+                       tmp = malloc(strlen(item->prefs->compose_override_from_format)+1);
+                       pref_get_unescaped_pref(tmp, item->prefs->compose_override_from_format);
+
+#ifdef USE_ASPELL
+                       quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE,
+                                       compose->gtkaspell);
+#else
+                       quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+                       quote_fmt_scan_string(tmp);
+                       quote_fmt_parse();
+
+                       buf = quote_fmt_get_buffer();
+                       if (buf == NULL)
+                               alertpanel_error(_("New message From format error."));
+                       else
+                               gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+                       quote_fmt_reset_vartable();
+
+                       g_free(tmp);
+               }
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
@@ -1094,7 +1128,6 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        }
 
        if (subject_format || body_format) {
-               MsgInfo* dummyinfo = NULL;
 
                if ( subject_format
                         && *subject_format != '\0' )
@@ -1103,7 +1136,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        gchar *tmp = NULL;
                        gchar *buf = NULL;
 
-                       dummyinfo = compose_msginfo_new_from_compose(compose);
+                       if (!dummyinfo)
+                               dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        /* decode \-escape sequences in the internal representation of the quote format */
                        tmp = malloc(strlen(subject_format)+1);
@@ -1139,7 +1173,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        GtkTextIter start, end;
                        gchar *tmp = NULL;
 
-                       if ( dummyinfo == NULL )
+                       if (!dummyinfo)
                                dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        text = GTK_TEXT_VIEW(compose->text);
@@ -1158,8 +1192,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        g_free(tmp);
                }
 
-               procmsg_msginfo_free( dummyinfo );
        }
+       procmsg_msginfo_free( dummyinfo );
 
        if (attach_files) {
                gint i;
@@ -1505,6 +1539,38 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
 
+       /* override from name according to folder properties */
+       if (msginfo->folder && msginfo->folder->prefs &&
+               msginfo->folder->prefs->reply_with_format &&
+               msginfo->folder->prefs->reply_override_from_format &&
+               *msginfo->folder->prefs->reply_override_from_format != '\0') {
+
+               gchar *tmp = NULL;
+               gchar *buf = NULL;
+
+               /* decode \-escape sequences in the internal representation of the quote format */
+               tmp = malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
+               pref_get_unescaped_pref(tmp, msginfo->folder->prefs->reply_override_from_format);
+
+#ifdef USE_ASPELL
+               quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmp);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL)
+                       alertpanel_error(_("Message reply From format error."));
+               else
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               quote_fmt_reset_vartable();
+
+               g_free(tmp);
+       }
+
        textview = (GTK_TEXT_VIEW(compose->text));
        textbuf = gtk_text_view_get_buffer(textview);
        compose_create_tags(textview, compose);
@@ -1629,6 +1695,45 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                g_free(buf2);
        }
 
+       /* override from name according to folder properties */
+       if (msginfo->folder && msginfo->folder->prefs &&
+               msginfo->folder->prefs->forward_with_format &&
+               msginfo->folder->prefs->forward_override_from_format &&
+               *msginfo->folder->prefs->forward_override_from_format != '\0') {
+
+               gchar *tmp = NULL;
+               gchar *buf = NULL;
+               MsgInfo *full_msginfo = NULL;
+
+               if (!as_attach)
+                       full_msginfo = procmsg_msginfo_get_full_info(msginfo);
+               if (!full_msginfo)
+                       full_msginfo = procmsg_msginfo_copy(msginfo);
+
+               /* decode \-escape sequences in the internal representation of the quote format */
+               tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+               pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
+
+#ifdef USE_ASPELL
+               quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmp);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL)
+                       alertpanel_error(_("Message forward From format error."));
+               else
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               quote_fmt_reset_vartable();
+
+               g_free(tmp);
+               procmsg_msginfo_free(full_msginfo);
+       }
+
        textview = GTK_TEXT_VIEW(compose->text);
        textbuf = gtk_text_view_get_buffer(textview);
        compose_create_tags(textview, compose);
@@ -1767,6 +1872,42 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        compose->updating = TRUE;
 
+       /* override from name according to folder properties */
+       if (msginfo_list->data) {
+               MsgInfo *msginfo = msginfo_list->data;
+
+               if (msginfo->folder && msginfo->folder->prefs &&
+                       msginfo->folder->prefs->forward_with_format &&
+                       msginfo->folder->prefs->forward_override_from_format &&
+                       *msginfo->folder->prefs->forward_override_from_format != '\0') {
+
+                       gchar *tmp = NULL;
+                       gchar *buf = NULL;
+
+                       /* decode \-escape sequences in the internal representation of the quote format */
+                       tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+                       pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
+
+#ifdef USE_ASPELL
+                       quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                                       compose->gtkaspell);
+#else
+                       quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+                       quote_fmt_scan_string(tmp);
+                       quote_fmt_parse();
+
+                       buf = quote_fmt_get_buffer();
+                       if (buf == NULL)
+                               alertpanel_error(_("Message forward From format error."));
+                       else
+                               gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+                       quote_fmt_reset_vartable();
+
+                       g_free(tmp);
+               }
+       }
+
        textview = GTK_TEXT_VIEW(compose->text);
        textbuf = gtk_text_view_get_buffer(textview);
        compose_create_tags(textview, compose);
@@ -7528,6 +7669,24 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                msginfo = dummyinfo;
        }
 
+       if (tmpl->from && *tmpl->from != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmpl->from);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL) {
+                       alertpanel_error(_("Template From format error."));
+               } else {
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               }
+       }
+
        if (tmpl->to && *tmpl->to != '\0') {
 #ifdef USE_ASPELL
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
index a6c0726..63844f3 100644 (file)
@@ -83,18 +83,24 @@ static PrefParam param[] = {
 
        {"compose_with_format", "FALSE", &tmp_prefs.compose_with_format, P_BOOL,
         NULL, NULL, NULL},
+       {"compose_override_from_format", NULL, &tmp_prefs.compose_override_from_format, P_STRING,
+        NULL, NULL, NULL},
        {"compose_subject_format", NULL, &tmp_prefs.compose_subject_format, P_STRING,
         NULL, NULL, NULL},
        {"compose_body_format", NULL, &tmp_prefs.compose_body_format, P_STRING,
         NULL, NULL, NULL},
        {"reply_with_format", "FALSE", &tmp_prefs.reply_with_format, P_BOOL,
         NULL, NULL, NULL},
+       {"reply_override_from_format", NULL, &tmp_prefs.reply_override_from_format, P_STRING,
+        NULL, NULL, NULL},
        {"reply_quotemark", NULL, &tmp_prefs.reply_quotemark, P_STRING,
         NULL, NULL, NULL},
        {"reply_body_format", NULL, &tmp_prefs.reply_body_format, P_STRING,
         NULL, NULL, NULL},
        {"forward_with_format", "FALSE", &tmp_prefs.forward_with_format, P_BOOL,
         NULL, NULL, NULL},
+       {"forward_override_from_format", NULL, &tmp_prefs.forward_override_from_format, P_STRING,
+        NULL, NULL, NULL},
        {"forward_quotemark", NULL, &tmp_prefs.forward_quotemark, P_STRING,
         NULL, NULL, NULL},
        {"forward_body_format", NULL, &tmp_prefs.forward_body_format, P_STRING,
index 73b3ecd..f07f259 100644 (file)
@@ -60,13 +60,16 @@ struct _FolderItemPrefs {
        guint color;
 
        gboolean compose_with_format;
+       gchar *compose_override_from_format;
        gchar *compose_subject_format;
        gchar *compose_body_format;
        gboolean reply_with_format;
        gchar *reply_quotemark;
+       gchar *reply_override_from_format;
        gchar *reply_body_format;
        gboolean forward_with_format;
        gchar *forward_quotemark;
+       gchar *forward_override_from_format;
        gchar *forward_body_format;
 };
 
index ae19907..fab1b1a 100644 (file)
@@ -2051,6 +2051,7 @@ static void templates_create_widget_func(PrefsPage * _page,
                                window,
                                vbox2,
                                &page->checkbtn_compose_with_format,
+                               NULL,
                                &page->compose_subject_format,
                                &page->compose_body_format,
                                FALSE);
@@ -2065,6 +2066,7 @@ static void templates_create_widget_func(PrefsPage * _page,
                                window,
                                vbox2,
                                &page->checkbtn_reply_with_format,
+                               NULL,
                                &page->reply_quotemark,
                                &page->reply_body_format,
                                FALSE);
@@ -2079,6 +2081,7 @@ static void templates_create_widget_func(PrefsPage * _page,
                                window,
                                vbox2,
                                &page->checkbtn_forward_with_format,
+                               NULL,
                                &page->forward_quotemark,
                                &page->forward_body_format,
                                FALSE);
@@ -2920,12 +2923,15 @@ static void templates_save_func(PrefsPage *_page)
                return;
 
        quotefmt_check_new_msg_formats(tmp_ac_prefs.compose_with_format,
+                                                                       NULL,
                                                                        tmp_ac_prefs.compose_subject_format,
                                                                        tmp_ac_prefs.compose_body_format);
        quotefmt_check_reply_formats(tmp_ac_prefs.reply_with_format,
+                                                                       NULL,
                                                                        tmp_ac_prefs.reply_quotemark,
                                                                        tmp_ac_prefs.reply_body_format);
        quotefmt_check_forward_formats(tmp_ac_prefs.forward_with_format,
+                                                                       NULL,
                                                                        tmp_ac_prefs.forward_quotemark,
                                                                        tmp_ac_prefs.forward_body_format);
        if (prefs_templates_apply() >= 0)
index 2e29a91..b833e14 100644 (file)
@@ -150,13 +150,16 @@ struct _FolderItemTemplatesPage
        GtkWidget *window;
        GtkWidget *table;
        GtkWidget *checkbtn_compose_with_format;
+       GtkWidget *compose_override_from_format;
        GtkWidget *compose_subject_format;
        GtkWidget *compose_body_format;
        GtkWidget *checkbtn_reply_with_format;
        GtkWidget *reply_quotemark;
+       GtkWidget *reply_override_from_format;
        GtkWidget *reply_body_format;
        GtkWidget *checkbtn_forward_with_format;
        GtkWidget *forward_quotemark;
+       GtkWidget *forward_override_from_format;
        GtkWidget *forward_body_format;
 
        /* apply to sub folders */
@@ -1177,6 +1180,7 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
                                window,
                                vbox,
                                &page->checkbtn_compose_with_format,
+                               &page->compose_override_from_format,
                                &page->compose_subject_format,
                                &page->compose_body_format,
                                FALSE);
@@ -1195,6 +1199,7 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
                                window,
                                vbox,
                                &page->checkbtn_reply_with_format,
+                               &page->reply_override_from_format,
                                &page->reply_quotemark,
                                &page->reply_body_format,
                                FALSE);
@@ -1213,6 +1218,7 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
                                window,
                                vbox,
                                &page->checkbtn_forward_with_format,
+                               &page->forward_override_from_format,
                                &page->forward_quotemark,
                                &page->forward_body_format,
                                FALSE);
@@ -1227,6 +1233,8 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
                        item->prefs->compose_with_format);
+       pref_set_entry_from_pref(GTK_ENTRY(page->compose_override_from_format),
+                       item->prefs->compose_override_from_format);
        pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
                        item->prefs->compose_subject_format);
        pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
@@ -1236,6 +1244,8 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
                        item->prefs->reply_with_format);
        pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
                        item->prefs->reply_quotemark);
+       pref_set_entry_from_pref(GTK_ENTRY(page->reply_override_from_format),
+                       item->prefs->reply_override_from_format);
        pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
                        item->prefs->reply_body_format);
 
@@ -1243,6 +1253,8 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
                        item->prefs->forward_with_format);
        pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
                        item->prefs->forward_quotemark);
+       pref_set_entry_from_pref(GTK_ENTRY(page->forward_override_from_format),
+                       item->prefs->forward_override_from_format);
        pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
                        item->prefs->forward_body_format);
 
@@ -1285,11 +1297,14 @@ static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesP
        if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
                prefs->compose_with_format =
                        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
+               prefs->compose_override_from_format = pref_get_pref_from_entry(
+                               GTK_ENTRY(page->compose_override_from_format));
                prefs->compose_subject_format = pref_get_pref_from_entry(
                                GTK_ENTRY(page->compose_subject_format));
                prefs->compose_body_format = pref_get_pref_from_textview(
                                GTK_TEXT_VIEW(page->compose_body_format));
                quotefmt_check_new_msg_formats(prefs->compose_with_format,
+                                                                               prefs->compose_override_from_format,
                                                                                prefs->compose_subject_format,
                                                                                prefs->compose_body_format);
        }
@@ -1299,9 +1314,12 @@ static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesP
                        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
                prefs->reply_quotemark = gtk_editable_get_chars(
                                GTK_EDITABLE(page->reply_quotemark), 0, -1);
+               prefs->reply_override_from_format = pref_get_pref_from_entry(
+                               GTK_ENTRY(page->reply_override_from_format));
                prefs->reply_body_format = pref_get_pref_from_textview(
                                GTK_TEXT_VIEW(page->reply_body_format));
                quotefmt_check_reply_formats(prefs->reply_with_format,
+                                                                               prefs->reply_override_from_format,
                                                                                prefs->reply_quotemark,
                                                                                prefs->reply_body_format);
        }
@@ -1311,9 +1329,12 @@ static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesP
                        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
                prefs->forward_quotemark = gtk_editable_get_chars(
                                GTK_EDITABLE(page->forward_quotemark), 0, -1);
+               prefs->forward_override_from_format = pref_get_pref_from_entry(
+                               GTK_ENTRY(page->forward_override_from_format));
                prefs->forward_body_format = pref_get_pref_from_textview(
                                GTK_TEXT_VIEW(page->forward_body_format));
                quotefmt_check_forward_formats(prefs->forward_with_format,
+                                                                               prefs->forward_override_from_format,
                                                                                prefs->forward_quotemark,
                                                                                prefs->forward_body_format);
        }
index 998316c..0900c0b 100644 (file)
@@ -84,6 +84,7 @@ static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window,
                                window,
                                vbox2,
                                &prefs_quote->checkbtn_compose_with_format,
+                               NULL,
                                &prefs_quote->entry_subject,
                                &prefs_quote->text_format,
                                FALSE);
@@ -98,6 +99,7 @@ static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window,
                                window,
                                vbox2,
                                NULL,
+                               NULL,
                                &prefs_quote->entry_quotemark,
                                &prefs_quote->text_quotefmt,
                                FALSE);
@@ -112,6 +114,7 @@ static void prefs_quote_create_widget(PrefsPage *_page, GtkWindow *window,
                                window,
                                vbox2,
                                NULL,
+                               NULL,
                                &prefs_quote->entry_fw_quotemark,
                                &prefs_quote->text_fw_quotefmt,
                                FALSE);
@@ -164,20 +167,27 @@ static void prefs_quote_save(PrefsPage *_page)
        prefs_common.compose_body_format = pref_get_pref_from_textview(
                        GTK_TEXT_VIEW(page->text_format));
        quotefmt_check_new_msg_formats(prefs_common.compose_with_format,
-                                                                       prefs_common.compose_subject_format,
-                                                                       prefs_common.compose_body_format);
+                                                                  NULL,
+                                                                  prefs_common.compose_subject_format,
+                                                                  prefs_common.compose_body_format);
 
        prefs_common.quotemark = gtk_editable_get_chars(
                        GTK_EDITABLE(page->entry_quotemark), 0, -1);
        prefs_common.quotefmt = pref_get_pref_from_textview(
                        GTK_TEXT_VIEW(page->text_quotefmt));
-       quotefmt_check_reply_formats(TRUE, prefs_common.quotemark, prefs_common.quotefmt);
+       quotefmt_check_reply_formats(TRUE,
+                                                                NULL,
+                                                                prefs_common.quotemark,
+                                                                prefs_common.quotefmt);
 
        prefs_common.fw_quotemark = gtk_editable_get_chars(
                        GTK_EDITABLE(page->entry_fw_quotemark), 0, -1);
        prefs_common.fw_quotefmt = pref_get_pref_from_textview(
                        GTK_TEXT_VIEW(page->text_fw_quotefmt));
-       quotefmt_check_forward_formats(TRUE, prefs_common.fw_quotemark, prefs_common.fw_quotefmt);
+       quotefmt_check_forward_formats(TRUE,
+                                                                  NULL,
+                                                                  prefs_common.fw_quotemark,
+                                                                  prefs_common.fw_quotefmt);
 }
 
 static void prefs_quote_destroy_widget(PrefsPage *_page)
index 4190312..240a63f 100644 (file)
@@ -57,6 +57,7 @@ static struct Templates {
        GtkWidget *list_view;
        GtkWidget *entry_name;
        GtkWidget *entry_subject;
+       GtkWidget *entry_from;
        GtkWidget *entry_to;
        GtkWidget *entry_cc;    
        GtkWidget *entry_bcc;
@@ -132,7 +133,7 @@ static void prefs_template_window_create(void)
        GtkWidget *scrolled_window;
        GtkWidget   *vpaned;
        GtkWidget     *vbox1;
-       GtkWidget       *table; /* including : entry_[name|to|cc|bcc|subject] */
+       GtkWidget       *table; /* including : entry_[name|from|to|cc|bcc|subject] */
        GtkWidget       *scroll2;
        GtkWidget         *text_value;
        GtkWidget     *vbox2;
@@ -209,6 +210,8 @@ static void prefs_template_window_create(void)
        } tab[] = {
                {_("Name"),     &templates.entry_name,          FALSE,
                        _("This name is used as the Menu item")},
+               {_("From"),     &templates.entry_from,          TRUE,
+                       _("Override composing account's From header. This doesn't change the composing account.")},
                {_("To"),       &templates.entry_to,            TRUE,   NULL},
                {_("Cc"),       &templates.entry_cc,            TRUE,   NULL},
                {_("Bcc"),      &templates.entry_bcc,           TRUE,   NULL},
@@ -441,6 +444,7 @@ static void prefs_template_reset_dialog(void)
        GtkTextBuffer *buffer;
 
        gtk_entry_set_text(GTK_ENTRY(templates.entry_name), "");
+       gtk_entry_set_text(GTK_ENTRY(templates.entry_from), "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_to), "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_cc), "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_bcc), "");                 
@@ -588,6 +592,9 @@ static GSList *prefs_template_get_list(void)
                        ntmpl->subject = tmpl->subject && *(tmpl->subject) 
                                         ? g_strdup(tmpl->subject) 
                                         : NULL;
+                       ntmpl->from    = tmpl->from && *(tmpl->from)
+                                        ? g_strdup(tmpl->from)
+                                        : NULL;
                        ntmpl->to      = tmpl->to && *(tmpl->to)
                                         ? g_strdup(tmpl->to)
                                         : NULL;
@@ -639,6 +646,7 @@ static gboolean prefs_template_list_view_set_row(gint row)
        Template *tmpl;
        gchar *name;
        gchar *subject;
+       gchar *from;
        gchar *to;
        gchar *cc;
        gchar *bcc;     
@@ -672,6 +680,8 @@ static gboolean prefs_template_list_view_set_row(gint row)
                g_free(value);
                return FALSE;
        }
+       from = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_from),
+                                   0, -1);
        to = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_to),
                                    0, -1);
        cc = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_cc),
@@ -681,6 +691,10 @@ static gboolean prefs_template_list_view_set_row(gint row)
        subject = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_subject),
                                         0, -1);
 
+       if (from && *from == '\0') {
+               g_free(from);
+               from = NULL;
+       }
        if (to && *to == '\0') {
                g_free(to);
                to = NULL;
@@ -698,6 +712,12 @@ static gboolean prefs_template_list_view_set_row(gint row)
                subject = NULL;
        }
 
+       if (!prefs_template_string_is_valid(to, NULL, FALSE)) {
+               alertpanel_error(_("Template From format error."));
+               g_free(from);
+               g_free(value);
+               return FALSE;
+       }
        if (!prefs_template_string_is_valid(to, NULL, FALSE)) {
                alertpanel_error(_("Template To format error."));
                g_free(to);
@@ -727,6 +747,7 @@ static gboolean prefs_template_list_view_set_row(gint row)
        tmpl->load_filename = NULL;
        tmpl->name = name;
        tmpl->subject = subject;
+       tmpl->from = from;
        tmpl->to = to;
        tmpl->cc = cc;
        tmpl->bcc = bcc;        
@@ -1132,6 +1153,7 @@ static void prefs_template_select_row(GtkTreeView *list_view, GtkTreePath *path)
 
        tmpl_def.name = _("Template");
        tmpl_def.subject = "";
+       tmpl_def.from = "";
        tmpl_def.to = "";
        tmpl_def.cc = "";
        tmpl_def.bcc = "";      
@@ -1142,6 +1164,8 @@ static void prefs_template_select_row(GtkTreeView *list_view, GtkTreePath *path)
                tmpl = &tmpl_def;
 
        gtk_entry_set_text(GTK_ENTRY(templates.entry_name), tmpl->name);
+       gtk_entry_set_text(GTK_ENTRY(templates.entry_from),
+                          tmpl->from ? tmpl->from : "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_to),
                           tmpl->to ? tmpl->to : "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_cc),
index 48b00a4..1e82a40 100644 (file)
@@ -117,6 +117,7 @@ void quote_fmt_quote_description(GtkWidget *widget, GtkWidget *pref_window)
 void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_compose_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_subject_format,
                                                GtkWidget **edit_body_format,
                                                gboolean add_info_button)
@@ -124,6 +125,9 @@ void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
        GtkWidget *checkbtn_use_format = NULL;
        GtkWidget *vbox_format;
        GtkWidget *hbox_format;
+       GtkWidget *hbox2_format;
+       GtkWidget *label_from;
+       GtkWidget *entry_from;
        GtkWidget *label_subject;
        GtkWidget *entry_subject;
        GtkWidget *scrolledwin_format;
@@ -147,6 +151,25 @@ void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
        gtk_container_add(GTK_CONTAINER (parent_box), vbox_format);
        gtk_container_set_border_width (GTK_CONTAINER (vbox_format), 8);
 
+       if (override_from_format) {
+               hbox2_format = gtk_hbox_new (FALSE, 8);
+               gtk_widget_show (hbox2_format);
+               gtk_box_pack_start (GTK_BOX (vbox_format), hbox2_format, FALSE, FALSE, 0);
+
+               label_from = gtk_label_new (_("From"));
+               gtk_widget_show (label_from);
+               gtk_box_pack_start (GTK_BOX (hbox2_format), label_from, FALSE, FALSE, 0);
+
+               entry_from = gtk_entry_new ();
+               gtk_widget_show (entry_from);
+               gtk_box_pack_start (GTK_BOX (hbox2_format), entry_from, TRUE, TRUE, 0);
+               gtk_widget_set_size_request (entry_from, 100, -1);
+
+               gtk_tooltips_set_tip(gtk_tooltips_new(), entry_from,
+                               _("Override From header. This doesn't change the account used to compose the new message."),
+                               NULL);
+       }
+
        hbox_format = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox_format);
        gtk_box_pack_start (GTK_BOX (vbox_format), hbox_format, FALSE, FALSE, 0);
@@ -188,6 +211,8 @@ void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
 
        if (checkbtn_compose_with_format) {
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_subject);
+               if (override_from_format)
+                       SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_subject);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_format);
        }
@@ -197,6 +222,8 @@ void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
 
        if (checkbtn_compose_with_format)
                *checkbtn_compose_with_format = checkbtn_use_format;
+       if (override_from_format)
+               *override_from_format = entry_from;
        *edit_subject_format = entry_subject;
        *edit_body_format = text_format;
 }
@@ -204,6 +231,7 @@ void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
 void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_reply_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_reply_quotemark,
                                                GtkWidget **edit_reply_format,
                                                gboolean add_info_button)
@@ -212,8 +240,11 @@ void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
        GtkWidget *vbox_quote;
        GtkWidget *hbox1;
        GtkWidget *hbox2;
+       GtkWidget *hbox3;
        GtkWidget *label_quotemark;
        GtkWidget *entry_quotemark;
+       GtkWidget *label_from;
+       GtkWidget *entry_from;
        GtkWidget *scrolledwin_quotefmt;
        GtkWidget *text_quotefmt;
 
@@ -235,6 +266,25 @@ void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
        gtk_container_add(GTK_CONTAINER (parent_box), vbox_quote);
        gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
 
+       if (override_from_format) {
+               hbox3 = gtk_hbox_new (FALSE, 8);
+               gtk_widget_show (hbox3);
+               gtk_box_pack_start (GTK_BOX (vbox_quote), hbox3, FALSE, FALSE, 0);
+
+               label_from = gtk_label_new (_("From"));
+               gtk_widget_show (label_from);
+               gtk_box_pack_start (GTK_BOX (hbox3), label_from, FALSE, FALSE, 0);
+
+               entry_from = gtk_entry_new ();
+               gtk_widget_show (entry_from);
+               gtk_box_pack_start (GTK_BOX (hbox3), entry_from, TRUE, TRUE, 0);
+               gtk_widget_set_size_request (entry_from, 100, -1);
+
+               gtk_tooltips_set_tip(gtk_tooltips_new(), entry_from,
+                               _("Override From header. This doesn't change the account used to reply."),
+                               NULL);
+       }
+
        hbox1 = gtk_hbox_new (FALSE, 32);
        gtk_widget_show (hbox1);
        gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
@@ -281,6 +331,8 @@ void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
        if (checkbtn_reply_with_format) {
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_quotemark);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_quotemark);
+               if (override_from_format)
+                       SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_quotefmt);
        }
 
@@ -290,12 +342,15 @@ void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
        if (checkbtn_reply_with_format)
                *checkbtn_reply_with_format = checkbtn_use_format;
        *edit_reply_quotemark = entry_quotemark;
+       if (override_from_format)
+               *override_from_format = entry_from;
        *edit_reply_format = text_quotefmt;
 }
 
 void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_forward_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_fw_quotemark,
                                                GtkWidget **edit_fw_format,
                                                gboolean add_info_button)
@@ -304,8 +359,11 @@ void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
        GtkWidget *vbox_quote;
        GtkWidget *hbox1;
        GtkWidget *hbox2;
+       GtkWidget *hbox3;
        GtkWidget *label_quotemark;
        GtkWidget *entry_fw_quotemark;
+       GtkWidget *label_from;
+       GtkWidget *entry_from;
        GtkWidget *scrolledwin_quotefmt;
        GtkWidget *text_fw_quotefmt;
 
@@ -327,6 +385,25 @@ void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
        gtk_container_add(GTK_CONTAINER (parent_box), vbox_quote);
        gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8);
 
+       if (override_from_format) {
+               hbox3 = gtk_hbox_new (FALSE, 8);
+               gtk_widget_show (hbox3);
+               gtk_box_pack_start (GTK_BOX (vbox_quote), hbox3, FALSE, FALSE, 0);
+
+               label_from = gtk_label_new (_("From"));
+               gtk_widget_show (label_from);
+               gtk_box_pack_start (GTK_BOX (hbox3), label_from, FALSE, FALSE, 0);
+
+               entry_from = gtk_entry_new ();
+               gtk_widget_show (entry_from);
+               gtk_box_pack_start (GTK_BOX (hbox3), entry_from, TRUE, TRUE, 0);
+               gtk_widget_set_size_request (entry_from, 100, -1);
+
+               gtk_tooltips_set_tip(gtk_tooltips_new(), entry_from,
+                               _("Override From header. This doesn't change the account used to forward."),
+                               NULL);
+       }
+
        hbox1 = gtk_hbox_new (FALSE, 32);
        gtk_widget_show (hbox1);
        gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0);
@@ -375,6 +452,8 @@ void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
        if (checkbtn_forward_with_format) {
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_quotemark);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_fw_quotemark);
+               if (override_from_format)
+                       SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from);
                SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_fw_quotefmt);
        }
 
@@ -384,6 +463,8 @@ void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
        if (checkbtn_forward_with_format)
                *checkbtn_forward_with_format = checkbtn_use_format;
        *edit_fw_quotemark = entry_fw_quotemark;
+       if (override_from_format)
+               *override_from_format = entry_from;
        *edit_fw_format = text_fw_quotefmt;
 }
 
@@ -411,12 +492,16 @@ void quotefmt_add_info_button(GtkWindow *parent_window, GtkWidget *parent_box)
 
 
 void quotefmt_check_new_msg_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *subject_fmt,
                                                                        gchar *body_fmt)
 {
        if (use_format) {
                gint line;
 
+               if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, FALSE))
+                       alertpanel_error(_("New message From format error."));
+
                if (!prefs_template_string_is_valid(subject_fmt, NULL, FALSE))
                        alertpanel_error(_("New message subject format error."));
 
@@ -427,6 +512,7 @@ void quotefmt_check_new_msg_formats(gboolean use_format,
 }
 
 void quotefmt_check_reply_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *quotation_mark,
                                                                        gchar *body_fmt)
 {
@@ -436,6 +522,9 @@ void quotefmt_check_reply_formats(gboolean use_format,
                if (!prefs_template_string_is_valid(quotation_mark, NULL, FALSE))
                        alertpanel_error(_("Message reply quotation mark format error."));
 
+               if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, FALSE))
+                       alertpanel_error(_("Message reply From format error."));
+
                if (!prefs_template_string_is_valid(body_fmt, &line, TRUE)) {
                        alertpanel_error(_("Message reply format error at line %d."), line);
                }
@@ -443,6 +532,7 @@ void quotefmt_check_reply_formats(gboolean use_format,
 }
 
 void quotefmt_check_forward_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *quotation_mark,
                                                                        gchar *body_fmt)
 {
@@ -452,7 +542,9 @@ void quotefmt_check_forward_formats(gboolean use_format,
                if (!prefs_template_string_is_valid(quotation_mark, NULL, FALSE))
                        alertpanel_error(_("Message forward quotation mark format error."));
 
-fprintf(stderr, "\n%s\n", body_fmt);
+               if (override_from_fmt && !prefs_template_string_is_valid(override_from_fmt, NULL, FALSE))
+                       alertpanel_error(_("Message forward From format error."));
+
                if (!prefs_template_string_is_valid(body_fmt, &line, TRUE)) {
                        alertpanel_error(_("Message forward format error at line %d."), line);
                }
index aa1067a..880a0de 100644 (file)
@@ -33,30 +33,36 @@ gint quote_fmt_get_cursor_pos(void);
 void quotefmt_create_new_msg_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_compose_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_subject_format,
                                                GtkWidget **edit_body_format,
                                                gboolean add_info_button);
 void quotefmt_create_reply_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_reply_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_reply_quotemark,
                                                GtkWidget **edit_reply_format,
                                                gboolean add_info_button);
 void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window,
                                                GtkWidget *parent_box,
                                                GtkWidget **checkbtn_forward_with_format,
+                                               GtkWidget **override_from_format,
                                                GtkWidget **edit_fw_quotemark,
                                                GtkWidget **edit_fw_format,
                                                gboolean add_info_button);
 void quotefmt_add_info_button(GtkWindow *parent_window, GtkWidget *parent_box);
 
 void quotefmt_check_new_msg_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *subject_fmt,
                                                                        gchar *body_fmt);
 void quotefmt_check_reply_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *quotation_mark,
                                                                        gchar *body_fmt);
 void quotefmt_check_forward_formats(gboolean use_format,
+                                                                       gchar *override_from_fmt,
                                                                        gchar *quotation_mark,
                                                                        gchar *body_fmt);