add Reply-To to template config
authorPaul <paul@claws-mail.org>
Wed, 3 Sep 2014 10:49:17 +0000 (11:49 +0100)
committerPaul <paul@claws-mail.org>
Wed, 3 Sep 2014 10:49:17 +0000 (11:49 +0100)
src/common/template.c
src/common/template.h
src/compose.c
src/prefs_template.c

index b49b7d934381ad8425a4f25b215a55b3849f63bc..683f26362185456563f85d8438cc4fd641c1a3a2 100644 (file)
@@ -51,7 +51,8 @@ static Template *template_load(gchar *filename)
        tmpl->from = NULL;
        tmpl->to = NULL;
        tmpl->cc = NULL;        
-       tmpl->bcc = NULL;       
+       tmpl->bcc = NULL;
+       tmpl->replyto = NULL;
        tmpl->value = NULL;
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -67,6 +68,8 @@ static Template *template_load(gchar *filename)
                        tmpl->cc = g_strdup(g_strstrip(buf + 3));
                else if (!g_ascii_strncasecmp(buf, "Bcc:", 4))
                        tmpl->bcc = g_strdup(g_strstrip(buf + 4));                                              
+               else if (!g_ascii_strncasecmp(buf, "Reply-To:", 9))
+                       tmpl->replyto = g_strdup(g_strstrip(buf + 9));                                          
                else if (!g_ascii_strncasecmp(buf, "Subject:", 8))
                        tmpl->subject = g_strdup(g_strstrip(buf + 8));
        }
@@ -101,6 +104,7 @@ void template_free(Template *tmpl)
        g_free(tmpl->to);
        g_free(tmpl->cc);
        g_free(tmpl->bcc);              
+       g_free(tmpl->replyto);          
        g_free(tmpl->value);
        g_free(tmpl);
 }
@@ -269,6 +273,8 @@ static void template_write_config(GSList *tmpl_list)
                        TRY(fprintf(fp, "Cc: %s\n", tmpl->cc) > 0);
                if (tmpl->bcc && *tmpl->bcc != '\0')
                        TRY(fprintf(fp, "Bcc: %s\n", tmpl->bcc) > 0);
+               if (tmpl->replyto && *tmpl->replyto != '\0')
+                       TRY(fprintf(fp, "Reply-To: %s\n", tmpl->replyto) > 0);
 
                TRY(fputs("\n", fp) != EOF);
 
index c74e4cfa58f2e1fd8a3a5969e813b6537915fc78..2a37806629252de1e1352ec4e12ef5b9ea37428c 100644 (file)
@@ -32,7 +32,8 @@ struct _Template {
        gchar *from;
        gchar *to;
        gchar *cc;
-       gchar *bcc;             
+       gchar *bcc;
+       gchar *replyto;
        gchar *value;
 };
 
index d41d221aff4062395fc89a4b7d104b22bff765fd..c3ea943de32ff3716a0296dbec3e1f2b75ce3ef0 100644 (file)
@@ -8659,6 +8659,24 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                }
        }
 
+       if (tmpl->replyto && *tmpl->replyto != '\0') {
+#ifdef USE_ENCHANT
+               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->replyto);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL) {
+                       alertpanel_error(_("Template Reply-To format error."));
+               } else {
+                       compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
+               }
+       }
+
        /* process the subject */
        if (tmpl->subject && *tmpl->subject != '\0') {
 #ifdef USE_ENCHANT
index 68173cbd70dfb9df77392bd8161dd1600d6c8519..bafd768af7e6b0688628071c841f303e3df25767 100644 (file)
@@ -62,6 +62,7 @@ static struct Templates {
        GtkWidget *entry_to;
        GtkWidget *entry_cc;    
        GtkWidget *entry_bcc;
+       GtkWidget *entry_replyto;
        GtkWidget *text_value;
 } templates;
 
@@ -82,6 +83,7 @@ static struct
        {"To",          &templates.entry_to,            TRUE,   NULL},
        {"Cc",          &templates.entry_cc,            TRUE,   NULL},
        {"Bcc",         &templates.entry_bcc,           TRUE,   NULL},
+       {"Reply-To",    &templates.entry_replyto,       TRUE,   NULL},
        {"Subject",     &templates.entry_subject,       FALSE,  NULL},
        {NULL,          NULL,                           FALSE,  NULL}
 };
@@ -158,7 +160,7 @@ static void prefs_template_window_create(void)
        GtkWidget *scrolled_window;
        GtkWidget   *vpaned;
        GtkWidget     *vbox1;
-       GtkWidget       *table; /* including : entry_[name|from|to|cc|bcc|subject] */
+       GtkWidget       *table; /* including : entry_[name|from|to|cc|bcc|replyto|subject] */
        GtkWidget       *scroll2;
        GtkWidget         *text_value;
        GtkWidget     *vbox2;
@@ -451,6 +453,7 @@ static void prefs_template_reset_dialog(void)
        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), "");                 
+       gtk_entry_set_text(GTK_ENTRY(templates.entry_replyto), "");                     
        gtk_entry_set_text(GTK_ENTRY(templates.entry_subject), "");
        
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(templates.text_value));
@@ -657,6 +660,9 @@ static GSList *prefs_template_get_list(void)
                        ntmpl->bcc     = tmpl->bcc && *(tmpl->bcc)
                                         ? g_strdup(tmpl->bcc)
                                         : NULL;        
+                       ntmpl->replyto = tmpl->replyto && *(tmpl->replyto)
+                                        ? g_strdup(tmpl->replyto)
+                                        : NULL;        
                        ntmpl->value   = tmpl->value && *(tmpl->value)
                                         ? g_strdup(tmpl->value)
                                         : NULL;
@@ -734,7 +740,8 @@ static gboolean prefs_template_list_view_set_row(gint row)
        gchar *from;
        gchar *to;
        gchar *cc;
-       gchar *bcc;     
+       gchar *bcc;
+       gchar *replyto;
        gchar *value;
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
@@ -770,6 +777,8 @@ static gboolean prefs_template_list_view_set_row(gint row)
                                    0, -1);
        bcc = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_bcc),
                                    0, -1);
+       replyto = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_replyto),
+                                   0, -1);
        subject = gtk_editable_get_chars(GTK_EDITABLE(templates.entry_subject),
                                         0, -1);
 
@@ -789,6 +798,10 @@ static gboolean prefs_template_list_view_set_row(gint row)
                g_free(bcc);
                bcc = NULL;
        }
+       if (replyto && *replyto == '\0') {
+               g_free(replyto);
+               replyto = NULL;
+       }
        if (subject && *subject == '\0') {
                g_free(subject);
                subject = NULL;
@@ -818,6 +831,12 @@ static gboolean prefs_template_list_view_set_row(gint row)
                g_free(value);
                return FALSE;
        }
+       if (!prefs_template_string_is_valid(replyto, NULL, TRUE, TRUE)) {
+               alertpanel_error(_("The \"Replyt-To\" field of the template contains an invalid email address."));      
+               g_free(replyto);
+               g_free(value);
+               return FALSE;
+       }
        if (!prefs_template_string_is_valid(subject, NULL, TRUE, FALSE)) {
                alertpanel_error(_("The \"Subject\" field of the template is invalid."));       
                g_free(subject);
@@ -833,6 +852,7 @@ static gboolean prefs_template_list_view_set_row(gint row)
        tmpl->to = to;
        tmpl->cc = cc;
        tmpl->bcc = bcc;        
+       tmpl->replyto = replyto;        
        tmpl->value = value;
 
        prefs_template_list_view_insert_template(templates.list_view,
@@ -1252,6 +1272,7 @@ static void prefs_template_select_row(GtkTreeView *list_view, GtkTreePath *path)
        tmpl_def.to = "";
        tmpl_def.cc = "";
        tmpl_def.bcc = "";      
+       tmpl_def.replyto = "";  
        tmpl_def.value = "";
 
        gtk_tree_model_get(model, &titer, TEMPL_DATA, &tmpl, -1);
@@ -1267,6 +1288,8 @@ static void prefs_template_select_row(GtkTreeView *list_view, GtkTreePath *path)
                           tmpl->cc ? tmpl->cc : "");
        gtk_entry_set_text(GTK_ENTRY(templates.entry_bcc),
                           tmpl->bcc ? tmpl->bcc : "");                 
+       gtk_entry_set_text(GTK_ENTRY(templates.entry_replyto),
+                          tmpl->replyto ? tmpl->replyto : "");                 
        gtk_entry_set_text(GTK_ENTRY(templates.entry_subject),
                           tmpl->subject ? tmpl->subject : "");