Coverity fixes
[claws.git] / src / mh.c
index eb92dc6a79ebde21cf752bea8d61e5d14a112fa9..e7b988876fe35774afd3187fdcd0356eef3ed37f 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and 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
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -33,6 +34,7 @@
 #include <time.h>
 
 #include "folder.h"
+#include "folder_item_prefs.h"
 #include "mh.h"
 #include "procmsg.h"
 #include "procheader.h"
@@ -146,6 +148,7 @@ FolderClass *mh_get_class(void)
                mh_class.type = F_MH;
                mh_class.idstr = "mh";
                mh_class.uistr = "MH";
+               mh_class.supports_server_search = FALSE;
                
                /* Folder functions */
                mh_class.new_folder = mh_folder_new;
@@ -173,6 +176,7 @@ FolderClass *mh_get_class(void)
                mh_class.add_msgs = mh_add_msgs;
                mh_class.copy_msg = mh_copy_msg;
                mh_class.copy_msgs = mh_copy_msgs;
+               mh_class.search_msgs = folder_item_search_msgs_local;
                mh_class.remove_msg = mh_remove_msg;
                mh_class.remove_msgs = mh_remove_msgs;
                mh_class.remove_all_msg = mh_remove_all_msg;
@@ -463,7 +467,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
        FolderItem *src = NULL;
        gchar *srcfile;
        gchar *destfile;
-       gint filemode = 0;
        FolderItemPrefs *prefs;
        MsgInfo *msginfo = NULL;
        MsgInfoList *cur = NULL;
@@ -572,11 +575,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
                        if (chmod(destfile, prefs->folder_chmod) < 0)
                                FILE_OP_ERROR(destfile, "chmod");
-
-                       /* for mark file */
-                       filemode = prefs->folder_chmod;
-                       if (filemode & S_IRGRP) filemode |= S_IWGRP;
-                       if (filemode & S_IROTH) filemode |= S_IWOTH;
                }
                if (relation) {
                        if (g_hash_table_lookup(relation, msginfo) != NULL)
@@ -778,7 +776,7 @@ static gint mh_scan_tree(Folder *folder)
 
 static gint mh_create_tree(Folder *folder)
 {
-       gchar *rootpath;
+       gchar *rootpath, *f;
 
        cm_return_val_if_fail(folder != NULL, -1);
 
@@ -786,11 +784,42 @@ static gint mh_create_tree(Folder *folder)
        rootpath = LOCAL_FOLDER(folder)->rootpath;
        MAKE_DIR_IF_NOT_EXIST(rootpath);
        CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
-       MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
-       MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
-       MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
-       MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
-       MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
+
+       /* Create special directories as needed */
+       if (folder->inbox != NULL &&
+                       folder->inbox->path != NULL)
+               f = folder->inbox->path;
+       else
+               f = INBOX_DIR;
+       MAKE_DIR_IF_NOT_EXIST(f);
+
+       if (folder->outbox != NULL &&
+                       folder->outbox->path != NULL)
+               f = folder->outbox->path;
+       else
+               f = OUTBOX_DIR;
+       MAKE_DIR_IF_NOT_EXIST(f);
+
+       if (folder->draft != NULL &&
+                       folder->draft->path != NULL)
+               f = folder->draft->path;
+       else
+               f = DRAFT_DIR;
+       MAKE_DIR_IF_NOT_EXIST(f);
+
+       if (folder->queue != NULL &&
+                       folder->queue->path != NULL)
+               f = folder->queue->path;
+       else
+               f = QUEUE_DIR;
+       MAKE_DIR_IF_NOT_EXIST(f);
+
+       if (folder->trash != NULL &&
+                       folder->trash->path != NULL)
+               f = folder->trash->path;
+       else
+               f = TRASH_DIR;
+       MAKE_DIR_IF_NOT_EXIST(f);
 
        return 0;
 }
@@ -830,8 +859,8 @@ static gchar *mh_item_get_path(Folder *folder, FolderItem *item)
        if (!is_dir_exist(real_path) && is_dir_exist(path)) {
                /* mmh, older version did put utf8 filenames instead of
                 * the correct encoding */
-               g_rename(path, real_path);
-               folder_item_scan(item);
+               if (g_rename(path, real_path) == 0)
+                       folder_item_scan(item);
        }
 
        g_free(path);
@@ -1081,12 +1110,12 @@ static void mh_scan_tree_recursive(FolderItem *item)
                entry = mh_filename_from_utf8(utf8entry);
 
                if (
-#if !defined(G_OS_WIN32) && !defined(MAEMO) && defined(HAVE_DIRENT_D_TYPE)
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
                        d->d_type == DT_DIR ||
                        (d->d_type == DT_UNKNOWN &&
 #endif
                        g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
-#if !defined(G_OS_WIN32) && !defined(MAEMO) && defined(HAVE_DIRENT_D_TYPE)
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
                        )
 #endif
                   ) {
@@ -1325,8 +1354,10 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
                if (fclose(mh_sequences_new_fp) == EOF)
                        err = TRUE;
 
-               if (!err)
-                       g_rename(mh_sequences_new, mh_sequences_old);
+               if (!err) {
+                       if (g_rename(mh_sequences_new, mh_sequences_old) < 0)
+                               FILE_OP_ERROR(mh_sequences_new, "rename");
+               }
                g_free(sequence);
                procmsg_msg_list_free(msglist);
        }