remove unnecessary cm_return_val_if_fail()
[claws.git] / src / folder.c
index 48a8d32ceeec45ad25243993589eb60c304a57b9..3982e858f08b58ffa4436311af085144495cefbb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * 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
 #include "main.h"
 #include "msgcache.h"
 #include "privacy.h"
+#include "prefs_common.h"
+#include "prefs_migration.h"
+#include "file-utils.h"
 
 /* Dependecies to be removed ?! */
-#include "prefs_common.h"
 #include "prefs_account.h"
 
 /* Define possible missing constants for Windows. */
@@ -377,8 +379,11 @@ FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path
        item->no_sub = FALSE;
        item->no_select = FALSE;
        item->collapsed = FALSE;
-       item->thread_collapsed = FALSE;
-       item->threaded  = TRUE;
+       item->thread_collapsed = prefs_common.folder_default_thread_collapsed;
+       item->threaded  = prefs_common.folder_default_thread;
+       item->hide_read_threads = prefs_common.folder_default_hide_read_threads;
+       item->hide_read_msgs = prefs_common.folder_default_hide_read_msgs;
+       item->hide_del_msgs = prefs_common.folder_default_hide_del_msgs;
        item->ret_rcpt  = FALSE;
        item->opened    = FALSE;
        item->node = g_node_new(item);
@@ -830,6 +835,8 @@ gint folder_read_list(void)
        GNode *node, *cur;
        XMLNode *xmlnode;
        gchar *path;
+       GList *list;
+       gint config_version = -1;
 
        path = folder_get_list_path();
        if (!is_file_exist(path)) return -1;
@@ -837,7 +844,7 @@ gint folder_read_list(void)
        if (!node) return -1;
 
        xmlnode = node->data;
-       if (strcmp2(xmlnode->tag->tag, "folderlist") != 0) {
+       if (g_strcmp0(xmlnode->tag->tag, "folderlist") != 0) {
                g_warning("wrong folder list");
                xml_free_tree(node);
                return -1;
@@ -856,7 +863,23 @@ gint folder_read_list(void)
                cur = cur->next;
        }
 
+       for (list = xmlnode->tag->attr; list != NULL; list = list->next) {
+               XMLAttr *attr = list->data;
+
+               if (!attr || !attr->name || !attr->value) continue;
+               if (!strcmp(attr->name, "config_version")) {
+                       config_version = atoi(attr->value);
+                       debug_print("Found folderlist config_version %d\n", config_version);
+               }
+       }
+
        xml_free_tree(node);
+
+       if (prefs_update_config_version_folderlist(config_version) < 0) {
+               debug_print("Folderlist configuration file version upgrade failed\n");
+               return -2;
+       }
+
        if (folder_list || folder_unloaded_list)
                return 0;
        else
@@ -883,6 +906,8 @@ void folder_write_list(void)
                return;         
        }
        tag = xml_tag_new("folderlist");
+       xml_tag_add_attr(tag, xml_attr_new_int("config_version",
+                               CLAWS_CONFIG_VERSION));
 
        xmlnode = xml_node_new(tag, NULL);
 
@@ -1255,7 +1280,7 @@ Folder *folder_find_from_name(const gchar *name, FolderClass *klass)
        for (list = folder_list; list != NULL; list = list->next) {
                folder = list->data;
                if (folder->klass == klass && 
-                   strcmp2(name, folder->name) == 0)
+                   g_strcmp0(name, folder->name) == 0)
                        return folder;
        }
 
@@ -1341,7 +1366,7 @@ FolderItem *folder_find_child_item_by_name(FolderItem *item, const gchar *name)
 
        for (node = item->node->children; node != NULL; node = node->next) {
                child = FOLDER_ITEM(node->data);
-               if (strcmp2(child->name, name) == 0) {
+               if (g_strcmp0(child->name, name) == 0) {
                        return child;
                }
        }
@@ -1567,23 +1592,23 @@ gchar *folder_item_get_name(FolderItem *item)
 
        switch (item->stype) {
        case F_INBOX:
-               name = g_strdup(!strcmp2(item->name, INBOX_DIR) ? _("Inbox") :
+               name = g_strdup(!g_strcmp0(item->name, INBOX_DIR) ? _("Inbox") :
                                item->name);
                break;
        case F_OUTBOX:
-               name = g_strdup(!strcmp2(item->name, OUTBOX_DIR) ? _("Sent") :
+               name = g_strdup(!g_strcmp0(item->name, OUTBOX_DIR) ? _("Sent") :
                                item->name);
                break;
        case F_QUEUE:
-               name = g_strdup(!strcmp2(item->name, QUEUE_DIR) ? _("Queue") :
+               name = g_strdup(!g_strcmp0(item->name, QUEUE_DIR) ? _("Queue") :
                                item->name);
                break;
        case F_TRASH:
-               name = g_strdup(!strcmp2(item->name, TRASH_DIR) ? _("Trash") :
+               name = g_strdup(!g_strcmp0(item->name, TRASH_DIR) ? _("Trash") :
                                item->name);
                break;
        case F_DRAFT:
-               name = g_strdup(!strcmp2(item->name, DRAFT_DIR) ? _("Drafts") :
+               name = g_strdup(!g_strcmp0(item->name, DRAFT_DIR) ? _("Drafts") :
                                item->name);
                break;
        default:
@@ -1599,7 +1624,7 @@ gchar *folder_item_get_name(FolderItem *item)
                        name = g_strconcat(item->name, " (", item->folder->klass->uistr, ")", NULL);
                } else {
                        if (FOLDER_CLASS(item->folder) == news_get_class() &&
-                           item->path && !strcmp2(item->name, item->path))
+                           item->path && !g_strcmp0(item->name, item->path))
                                name = get_abbrev_newsgroup_name
                                        (item->path,
                                         prefs_common.ng_abbrev_len);
@@ -2347,10 +2372,12 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
        if (newmsg_list != NULL) {
                GSList *elem, *to_filter = NULL;
                gboolean do_filter = (filtering == TRUE) &&
-                                       (item->stype == F_INBOX) &&
-                                       (item->folder->account != NULL) && 
-                                       (item->folder->account->filter_on_recv);
-               
+                       (item->folder->account != NULL) &&
+                       (item->folder->account->filter_on_recv) &&
+                       ((item->stype == F_INBOX) ||
+                        ((item->stype == F_NORMAL) &&
+                         (FOLDER_TYPE(item->folder) == F_NEWS)));
+
                for (elem = newmsg_list; elem != NULL; elem = g_slist_next(elem)) {
                        MsgInfo *msginfo = (MsgInfo *) elem->data;
 
@@ -2969,12 +2996,12 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
        gint msgnum = 0;
        gchar buf[BUFFSIZE];
 
-       if ((fp = g_fopen(file, "rb")) == NULL)
+       if ((fp = claws_fopen(file, "rb")) == NULL)
                return 0;
 
        if ((folder_has_parent_of_type(dest, F_QUEUE)) || 
            (folder_has_parent_of_type(dest, F_DRAFT)))
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                        /* new way */
                        if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
                                strlen("X-Claws-End-Special-Headers:"))) ||
@@ -3008,7 +3035,7 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
        
        g_free(hentry[0].body);
        hentry[0].body = NULL;
-       fclose(fp);
+       claws_fclose(fp);
 
        return msgnum;
 }
@@ -3453,7 +3480,7 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
                for (; cur; cur = cur->next) {
                        Compose *compose = NULL;
                        FolderItem *queue = dest;
-                       int val = 0;
+                       ComposeQueueResult val = COMPOSE_QUEUE_SUCCESS;
                        
                        msginfo = (MsgInfo *)cur->data;
                        compose = compose_reedit(msginfo, TRUE);
@@ -3463,12 +3490,12 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
                        }
                        val = compose_queue(compose, NULL, &queue, NULL,
                                        FALSE);
-                       if (val < 0) {
+                       if (val != COMPOSE_QUEUE_SUCCESS) {
                                queue_err = TRUE;
                        } else if (remove_source) {
                                folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
                        }
-                       if (val == 0)
+                       if (val == COMPOSE_QUEUE_SUCCESS)
                                compose_close(compose);
                }
                return queue_err ? -1:0;
@@ -3961,7 +3988,6 @@ static gchar *folder_item_get_cache_file(FolderItem *item)
        gchar *old_file;
 
        cm_return_val_if_fail(item != NULL, NULL);
-       cm_return_val_if_fail(item->path != NULL, NULL);
 
        path = folder_item_get_path(item);
        cm_return_val_if_fail(path != NULL, NULL);
@@ -4048,7 +4074,7 @@ static gpointer xml_to_folder_item(gpointer nodedata, gpointer data)
        cm_return_val_if_fail(xmlnode != NULL, NULL);
        cm_return_val_if_fail(folder != NULL, NULL);
 
-       if (strcmp2(xmlnode->tag->tag, "folderitem") != 0) {
+       if (g_strcmp0(xmlnode->tag->tag, "folderitem") != 0) {
                g_warning("tag name != \"folderitem\"");
                return NULL;
        }
@@ -4096,7 +4122,7 @@ static Folder *folder_get_from_xml(GNode *node)
        cm_return_val_if_fail(node->data != NULL, NULL);
 
        xmlnode = node->data;
-       if (strcmp2(xmlnode->tag->tag, "folder") != 0) {
+       if (g_strcmp0(xmlnode->tag->tag, "folder") != 0) {
                g_warning("tag name != \"folder\"");
                return NULL;
        }
@@ -4420,8 +4446,9 @@ void folder_item_apply_processing(FolderItem *item)
 
        processing_list = item->prefs->processing;
 
-       if (!pre_global_processing && !processing_list
-       &&  !post_global_processing)
+       if (!processing_enabled(pre_global_processing) &&
+           !processing_enabled(processing_list) &&
+           !processing_enabled(post_global_processing))
                return;
 
        debug_print("processing %s\n", item->name);