#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;
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) {
GSList *template_read_config(void)
{
- gchar *path;
+ const gchar *path;
gchar *filename;
DIR *dp;
struct dirent *de;
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",
tmpl = template_load(filename);
if (tmpl)
tmpl_list = g_slist_append(tmpl_list, tmpl);
+
g_free(filename);
}
void template_write_config(GSList *tmpl_list)
{
- gchar *path;
+ const gchar *path;
GSList *cur;
Template *tmpl;
FILE *fp;
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)
if ((fp = fopen(filename, "wb")) == NULL) {
FILE_OP_ERROR(filename, "fopen");
g_free(filename);
- g_free(path);
return;
}
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);
}
}