/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 2007-2009 The Claws Mail Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
TAGS_RC, NULL);
gchar tmp[255];
gint id;
- FILE *fp = fopen(file, "rb");
+ FILE *fp = g_fopen(file, "rb");
g_free(file);
fclose(fp);
return;
}
- while (fscanf(fp, "%d\t%254s\n", &id, tmp) == 2) {
- g_hash_table_insert(tags_table,
- GINT_TO_POINTER(id), g_strdup(tmp));
- g_hash_table_insert(tags_reverse_table,
- g_strdup(tmp), GINT_TO_POINTER(id));
+ while (fgets(tmp, sizeof(tmp), fp) != NULL) {
+ gchar *sep = strchr(tmp, '\t');
+ gchar *tag_name = sep?(sep+1):NULL;
+
+ if (!tag_name || !sep)
+ continue;
+ g_strstrip(tag_name);
+ *(sep) = '\0';
+ if (strcmp(tag_name, "NonJunk") &&
+ strcmp(tag_name, "NotJunk") &&
+ strcmp(tag_name, "NoJunk") &&
+ strcmp(tag_name, "$Forwarded") &&
+ strcmp(tag_name, "Junk")) {
+ id = atoi(tmp);
+ g_hash_table_insert(tags_table,
+ GINT_TO_POINTER(id), g_strdup(tag_name));
+ g_hash_table_insert(tags_reverse_table,
+ g_strdup(tag_name), GINT_TO_POINTER(id));
+ }
}
fclose(fp);
TAGS_RC, NULL);
TagWriteData data;
- FILE *fp = fopen(file, "wb");
+ FILE *fp = g_fopen(file, "wb");
if (!fp) {
- FILE_OP_ERROR(file, "fopen");
+ FILE_OP_ERROR(file, "g_fopen");
g_free(file);
g_free(file_new);
return;
}
if (data.error) {
+ fclose(fp);
g_free(file);
g_free(file_new);
return;
g_free(file_new);
return;
}
-
- if (g_rename(file, file_new) < 0) {
- FILE_OP_ERROR(file, "g_rename");
+
+ if (rename_force(file, file_new) < 0) {
+ FILE_OP_ERROR(file, "rename_force");
}
g_free(file);
if (g_hash_table_lookup(tags_reverse_table, tag))
return -1;
- tag_max_id++;
- g_hash_table_insert(tags_table, GINT_TO_POINTER(tag_max_id),
- g_strdup(tag));
- g_hash_table_insert(tags_reverse_table, g_strdup(tag),
- GINT_TO_POINTER(tag_max_id));
-
- return tag_max_id;
+ if (strcmp(tag, "NonJunk") &&
+ strcmp(tag, "NotJunk") &&
+ strcmp(tag, "NoJunk") &&
+ strcmp(tag, "$Forwarded") &&
+ strcmp(tag, "Junk")) {
+ tag_max_id++;
+ g_hash_table_insert(tags_table, GINT_TO_POINTER(tag_max_id),
+ g_strdup(tag));
+ g_hash_table_insert(tags_reverse_table, g_strdup(tag),
+ GINT_TO_POINTER(tag_max_id));
+
+ return tag_max_id;
+ } else {
+ return -1;
+ }
}
void tags_remove_tag(gint id)
g_hash_table_remove(tags_table, GINT_TO_POINTER(id));
}
+/* extern decl. to avoid including ../prefs_filtering.h */
+extern void prefs_filtering_rename_tag(const gchar *old_tag, const gchar *new_tag);
+
void tags_update_tag(gint id, const gchar *tag)
{
gchar *old_tag = g_hash_table_lookup(tags_table, GINT_TO_POINTER(id));
- if (old_tag) {
- g_hash_table_remove(tags_reverse_table, old_tag);
+ if (strcmp(tag, "NonJunk") &&
+ strcmp(tag, "NotJunk") &&
+ strcmp(tag, "NoJunk") &&
+ strcmp(tag, "$Forwarded") &&
+ strcmp(tag, "Junk")) {
+ if (old_tag) {
+ prefs_filtering_rename_tag(old_tag, tag);
+ g_hash_table_remove(tags_reverse_table, old_tag);
+ }
+
+ g_hash_table_replace(tags_table, GINT_TO_POINTER(id),
+ g_strdup(tag));
+ g_hash_table_insert(tags_reverse_table, g_strdup(tag),
+ GINT_TO_POINTER(id));
}
-
- g_hash_table_replace(tags_table, GINT_TO_POINTER(id),
- g_strdup(tag));
- g_hash_table_insert(tags_reverse_table, g_strdup(tag),
- GINT_TO_POINTER(id));
}
const gchar *tags_get_tag(gint id)
return data.list;
}
+guint tags_get_size(void)
+{
+ return g_hash_table_size(tags_table);
+}