2005-07-01 [colin] 1.9.12cvs8
[claws.git] / src / common / template.c
index 59bbb55b79f6da58022682f98d333769cda07ea5..031ddb3df959f9e4decbcd608126c61e7d017b7c 100644 (file)
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <ctype.h>
 
-#include "intl.h"
 #include "utils.h"
 #include "template.h"
+#include "../codeconv.h"
 
 static GSList *template_list;
 
@@ -55,16 +56,16 @@ static Template *template_load(gchar *filename)
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                if (buf[0] == '\n')
                        break;
-               else if (!g_strncasecmp(buf, "Name:", 5))
+               else if (!g_ascii_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));
-               else if (!g_strncasecmp(buf, "To:", 3))
+               else if (!g_ascii_strncasecmp(buf, "To:", 3))
                        tmpl->to = g_strdup(g_strstrip(buf + 3));
-               else if (!g_strncasecmp(buf, "Cc:", 3))
+               else if (!g_ascii_strncasecmp(buf, "Cc:", 3))
                        tmpl->cc = g_strdup(g_strstrip(buf + 3));
-               else if (!g_strncasecmp(buf, "Bcc:", 4))
+               else if (!g_ascii_strncasecmp(buf, "Bcc:", 4))
                        tmpl->bcc = g_strdup(g_strstrip(buf + 4));                                              
+               else if (!g_ascii_strncasecmp(buf, "Subject:", 8))
+                       tmpl->subject = g_strdup(g_strstrip(buf + 8));
        }
 
        if (!tmpl->name) {
@@ -111,7 +112,7 @@ void template_clear_config(GSList *tmpl_list)
 
 GSList *template_read_config(void)
 {
-       gchar *path;
+       const gchar *path;
        gchar *filename;
        DIR *dp;
        struct dirent *de;
@@ -136,7 +137,8 @@ GSList *template_read_config(void)
        while ((de = readdir(dp)) != NULL) {
                if (*de->d_name == '.') continue;
 
-               filename = g_strconcat(path, G_DIR_SEPARATOR_S, de->d_name, NULL);
+               filename = g_strconcat(path, G_DIR_SEPARATOR_S,
+                                      de->d_name, NULL);
 
                if (stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) {
                        debug_print("%s:%d %s is not an ordinary file\n",
@@ -147,6 +149,7 @@ GSList *template_read_config(void)
                tmpl = template_load(filename);
                if (tmpl)
                        tmpl_list = g_slist_append(tmpl_list, tmpl);
+
                g_free(filename);
        }
 
@@ -157,7 +160,7 @@ GSList *template_read_config(void)
 
 void template_write_config(GSList *tmpl_list)
 {
-       gchar *path;
+       const gchar *path;
        GSList *cur;
        Template *tmpl;
        FILE *fp;
@@ -169,7 +172,7 @@ void template_write_config(GSList *tmpl_list)
 
        if (!is_dir_exist(path)) {
                if (is_file_exist(path)) {
-                       g_warning(_("file %s already exists\n"), path);
+                       g_warning("file %s already exists\n", path);
                        return;
                }
                if (make_dir(path) < 0)
@@ -190,7 +193,6 @@ void template_write_config(GSList *tmpl_list)
                if ((fp = fopen(filename, "wb")) == NULL) {
                        FILE_OP_ERROR(filename, "fopen");
                        g_free(filename);
-                       g_free(path);
                        return;
                }
 
@@ -204,8 +206,13 @@ void template_write_config(GSList *tmpl_list)
                if (tmpl->bcc && *tmpl->bcc != '\0')
                        fprintf(fp, "Bcc: %s\n", tmpl->bcc);                                            
                fputs("\n", fp);
-               fwrite(tmpl->value, sizeof(gchar) * strlen(tmpl->value), 1, fp);
+               if (tmpl->value && *tmpl->value != '\0')
+                       fwrite(tmpl->value, sizeof(gchar), strlen(tmpl->value), fp);
+               else
+                       fwrite("", sizeof(gchar), 1, fp);
+
                fclose(fp);
+               g_free(filename);
        }
 }