gchar buf[BUFFSIZE];
gint bytes_read;
- debug_print(_("%s:%d loading template from %s\n"), __FILE__, __LINE__, filename);
-
- if ((fp = fopen(filename, "r")) == NULL) {
+ if ((fp = fopen(filename, "rb")) == NULL) {
FILE_OP_ERROR(filename, "fopen");
return NULL;
}
tmpl = g_new(Template, 1);
tmpl->name = NULL;
tmpl->subject = NULL;
+ tmpl->to = NULL;
tmpl->value = NULL;
while (fgets(buf, sizeof(buf), fp) != NULL) {
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))
+ tmpl->to = g_strdup(g_strstrip(buf + 3));
}
if (!tmpl->name) {
{
g_free(tmpl->name);
g_free(tmpl->subject);
+ g_free(tmpl->to);
g_free(tmpl->value);
g_free(tmpl);
}
GSList *tmpl_list = NULL;
path = get_template_dir();
- debug_print(_("%s:%d reading templates dir %s\n"), __FILE__, __LINE__, path);
+ debug_print("%s:%d reading templates dir %s\n",
+ __FILE__, __LINE__, path);
if (!is_dir_exist(path)) {
- if (mkdir(path, S_IRWXU) < 0) {
- FILE_OP_ERROR(path, "mkdir");
+ if (make_dir(path) < 0)
return NULL;
- }
}
if ((dp = opendir(path)) == NULL) {
if (*de->d_name == '.') continue;
filename = g_strconcat(path, G_DIR_SEPARATOR_S, de->d_name, NULL);
- debug_print(_("%s:%d found file %s\n"), __FILE__, __LINE__, filename);
if (stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) {
- debug_print(_("%s:%d %s is not an ordinary file\n"),
- __FILE__, __LINE__, filename);
+ debug_print("%s:%d %s is not an ordinary file\n",
+ __FILE__, __LINE__, filename);
continue;
}
FILE *fp;
gint tmpl_num;
+ debug_print("%s:%d writing templates\n", __FILE__, __LINE__);
+
path = get_template_dir();
if (!is_dir_exist(path)) {
if (is_file_exist(path)) {
- g_warning(_("file %s allready exists\n"), path);
+ g_warning(_("file %s already exists\n"), path);
return;
}
- if (mkdir(path, S_IRWXU) < 0) {
- FILE_OP_ERROR(path, "mkdir");
+ if (make_dir(path) < 0)
return;
- }
}
remove_all_files(path);
filename = g_strconcat(path, G_DIR_SEPARATOR_S,
itos(tmpl_num), NULL);
- if ((fp = fopen(filename, "w")) == NULL) {
+ if ((fp = fopen(filename, "wb")) == NULL) {
FILE_OP_ERROR(filename, "fopen");
g_free(filename);
g_free(path);
return;
}
- 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)
+ if (tmpl->subject && *tmpl->subject != '\0')
fprintf(fp, "Subject: %s\n", tmpl->subject);
+ if (tmpl->to && *tmpl->to != '\0')
+ fprintf(fp, "To: %s\n", tmpl->to);
fputs("\n", fp);
- fwrite(tmpl->value, sizeof(gchar) * strlen(tmpl->value), 1,
- fp);
+ fwrite(tmpl->value, sizeof(gchar) * strlen(tmpl->value), 1, fp);
fclose(fp);
}
}