sync with sylpheed 0.6.5cvs14
[claws.git] / src / template.c
index 1bc5ace..8072181 100644 (file)
@@ -49,25 +49,28 @@ static Template *template_load(gchar *filename)
 
        tmpl = g_new(Template, 1);
        tmpl->name = NULL;
+       tmpl->subject = NULL;
+       tmpl->value = NULL;
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                if (buf[0] == '\n')
                        break;
                else if (!g_strncasecmp(buf, "Name:", 5))
                        tmpl->name = g_strdup(g_strstrip(buf + 5));
+               else if (!g_strncasecmp(buf, "Subject:", 8))
+                       tmpl->subject = g_strdup(g_strstrip(buf + 8));
        }
 
        if (!tmpl->name) {
                g_warning("wrong template format\n");
-               g_free(tmpl);
+               template_free(tmpl);
                return NULL;
        }
 
        if ((bytes_read = fread(buf, 1, sizeof(buf), fp)) == 0) {
                if (ferror(fp)) {
                        FILE_OP_ERROR(filename, "fread");
-                       g_free(tmpl->name);
-                       g_free(tmpl);
+                       template_free(tmpl);
                        return NULL;
                }
        }
@@ -80,6 +83,7 @@ static Template *template_load(gchar *filename)
 void template_free(Template *tmpl)
 {
        g_free(tmpl->name);
+       g_free(tmpl->subject);
        g_free(tmpl->value);
        g_free(tmpl);
 }
@@ -186,6 +190,8 @@ void template_write_config(GSList *tmpl_list)
                debug_print(_("%s:%d writing template \"%s\" to %s\n"),
                            __FILE__, __LINE__, tmpl->name, filename);
                fprintf(fp, "Name: %s\n", tmpl->name);
+               if (tmpl->subject)
+                       fprintf(fp, "Subject: %s\n", tmpl->subject);
                fputs("\n", fp);
                fwrite(tmpl->value, sizeof(gchar) * strlen(tmpl->value), 1,
                       fp);