2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n.h>
37 # include <sys/time.h>
43 #include "procheader.h"
47 /* Define possible missing constants for Windows. */
60 static void mh_folder_init (Folder *folder,
64 static Folder *mh_folder_new (const gchar *name,
66 static void mh_folder_destroy (Folder *folder);
67 static gchar *mh_fetch_msg (Folder *folder,
70 static MsgInfo *mh_get_msginfo (Folder *folder,
73 static gint mh_add_msg (Folder *folder,
77 static gint mh_add_msgs (Folder *folder,
81 static gint mh_copy_msg (Folder *folder,
84 static gint mh_copy_msgs (Folder *folder,
88 static gint mh_remove_msg (Folder *folder,
91 static gint mh_remove_all_msg (Folder *folder,
93 static gboolean mh_is_msg_changed (Folder *folder,
97 static gint mh_get_num_list (Folder *folder,
100 gboolean *old_uids_valid);
101 static gint mh_scan_tree (Folder *folder);
103 static gint mh_create_tree (Folder *folder);
104 static FolderItem *mh_create_folder (Folder *folder,
107 static gint mh_rename_folder (Folder *folder,
110 static gint mh_remove_folder (Folder *folder,
113 static gchar *mh_get_new_msg_filename (FolderItem *dest);
115 static MsgInfo *mh_parse_msg (const gchar *file,
117 static void mh_remove_missing_folder_items (Folder *folder);
118 static gchar *mh_filename_from_utf8 (const gchar *path);
119 static gchar *mh_filename_to_utf8 (const gchar *path);
120 static void mh_scan_tree_recursive (FolderItem *item);
122 static gboolean mh_rename_folder_func (GNode *node,
124 static gchar *mh_item_get_path (Folder *folder,
127 static gboolean mh_scan_required (Folder *folder,
130 static FolderClass mh_class;
132 FolderClass *mh_get_class(void)
134 if (mh_class.idstr == NULL) {
135 mh_class.type = F_MH;
136 mh_class.idstr = "mh";
137 mh_class.uistr = "MH";
139 /* Folder functions */
140 mh_class.new_folder = mh_folder_new;
141 mh_class.destroy_folder = mh_folder_destroy;
142 mh_class.set_xml = folder_local_set_xml;
143 mh_class.get_xml = folder_local_get_xml;
144 mh_class.scan_tree = mh_scan_tree;
145 mh_class.create_tree = mh_create_tree;
147 /* FolderItem functions */
148 mh_class.item_get_path = mh_item_get_path;
149 mh_class.create_folder = mh_create_folder;
150 mh_class.rename_folder = mh_rename_folder;
151 mh_class.remove_folder = mh_remove_folder;
152 mh_class.get_num_list = mh_get_num_list;
153 mh_class.scan_required = mh_scan_required;
155 /* Message functions */
156 mh_class.get_msginfo = mh_get_msginfo;
157 mh_class.fetch_msg = mh_fetch_msg;
158 mh_class.add_msg = mh_add_msg;
159 mh_class.add_msgs = mh_add_msgs;
160 mh_class.copy_msg = mh_copy_msg;
161 mh_class.copy_msgs = mh_copy_msgs;
162 mh_class.remove_msg = mh_remove_msg;
163 mh_class.remove_all_msg = mh_remove_all_msg;
164 mh_class.is_msg_changed = mh_is_msg_changed;
170 static Folder *mh_folder_new(const gchar *name, const gchar *path)
174 folder = (Folder *)g_new0(MHFolder, 1);
175 folder->klass = &mh_class;
176 mh_folder_init(folder, name, path);
181 static void mh_folder_destroy(Folder *folder)
183 folder_local_folder_destroy(LOCAL_FOLDER(folder));
186 static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
188 folder_local_folder_init(folder, name, path);
192 gboolean mh_scan_required(Folder *folder, FolderItem *item)
197 path = folder_item_get_path(item);
198 g_return_val_if_fail(path != NULL, FALSE);
200 if (stat(path, &s) < 0) {
201 FILE_OP_ERROR(path, "stat");
206 if ((s.st_mtime > item->mtime) &&
207 (s.st_mtime - 3600 != item->mtime)) {
208 debug_print("MH scan required, folder updated: %s (%ld > %ld)\n",
210 (long int) s.st_mtime,
211 (long int) item->mtime);
216 debug_print("MH scan not required: %s (%ld <= %ld)\n",
218 (long int) s.st_mtime,
219 (long int) item->mtime);
224 void mh_get_last_num(Folder *folder, FolderItem *item)
232 g_return_if_fail(item != NULL);
234 debug_print("mh_get_last_num(): Scanning %s ...\n", item->path);
236 path = folder_item_get_path(item);
237 g_return_if_fail(path != NULL);
238 if (change_dir(path) < 0) {
244 if ((dp = opendir(".")) == NULL) {
245 FILE_OP_ERROR(item->path, "opendir");
249 while ((d = readdir(dp)) != NULL) {
250 if ((num = to_number(d->d_name)) > 0 &&
251 dirent_is_regular_file(d)) {
258 debug_print("Last number in dir %s = %d\n", item->path, max);
259 item->last_num = max;
262 gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *old_uids_valid)
268 gint num, nummsgs = 0;
270 g_return_val_if_fail(item != NULL, -1);
272 debug_print("mh_get_num_list(): Scanning %s ...\n", item->path);
274 *old_uids_valid = TRUE;
276 path = folder_item_get_path(item);
277 g_return_val_if_fail(path != NULL, -1);
278 if (change_dir(path) < 0) {
284 if ((dp = opendir(".")) == NULL) {
285 FILE_OP_ERROR(item->path, "opendir");
289 while ((d = readdir(dp)) != NULL) {
290 if ((num = to_number(d->d_name)) > 0) {
291 *list = g_slist_prepend(*list, GINT_TO_POINTER(num));
297 item->mtime = time(NULL);
301 static gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
306 g_return_val_if_fail(item != NULL, NULL);
307 g_return_val_if_fail(num > 0, NULL);
309 path = folder_item_get_path(item);
310 file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
312 if (!is_file_exist(file)) {
321 static MsgInfo *mh_get_msginfo(Folder *folder, FolderItem *item, gint num)
326 g_return_val_if_fail(item != NULL, NULL);
327 g_return_val_if_fail(num > 0, NULL);
329 file = mh_fetch_msg(folder, item, num);
330 if (!file) return NULL;
332 msginfo = mh_parse_msg(file, item);
334 msginfo->msgnum = num;
341 static gchar *mh_get_new_msg_filename(FolderItem *dest)
346 destpath = folder_item_get_path(dest);
347 g_return_val_if_fail(destpath != NULL, NULL);
349 if (!is_dir_exist(destpath))
350 make_dir_hier(destpath);
353 destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
355 if (is_file_entry_exist(destfile)) {
367 static gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file, MsgFlags *flags)
371 MsgFileInfo fileinfo;
373 g_return_val_if_fail(file != NULL, -1);
375 fileinfo.msginfo = NULL;
376 fileinfo.file = (gchar *)file;
377 fileinfo.flags = flags;
378 file_list.data = &fileinfo;
379 file_list.next = NULL;
381 ret = mh_add_msgs(folder, dest, &file_list, NULL);
385 static gint mh_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
390 MsgFileInfo *fileinfo;
392 g_return_val_if_fail(dest != NULL, -1);
393 g_return_val_if_fail(file_list != NULL, -1);
395 if (dest->last_num < 0) {
396 mh_get_last_num(folder, dest);
397 if (dest->last_num < 0) return -1;
400 for (cur = file_list; cur != NULL; cur = cur->next) {
401 fileinfo = (MsgFileInfo *)cur->data;
403 destfile = mh_get_new_msg_filename(dest);
404 if (destfile == NULL) return -1;
407 if (link(fileinfo->file, destfile) < 0) {
409 if (copy_file(fileinfo->file, destfile, TRUE) < 0) {
410 g_warning(_("can't copy message %s to %s\n"),
411 fileinfo->file, destfile);
419 if (relation != NULL)
420 g_relation_insert(relation, fileinfo, GINT_TO_POINTER(dest->last_num + 1));
425 return dest->last_num;
428 static gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
432 g_return_val_if_fail(msginfo != NULL, -1);
434 msglist.data = msginfo;
437 return mh_copy_msgs(folder, dest, &msglist, NULL);
440 static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
443 gboolean dest_need_scan = FALSE;
447 FolderItemPrefs *prefs;
448 MsgInfo *msginfo = NULL;
449 gboolean remove_special_headers = FALSE;
450 MsgInfoList *cur = NULL;
451 g_return_val_if_fail(dest != NULL, -1);
452 g_return_val_if_fail(msglist != NULL, -1);
454 msginfo = (MsgInfo *)msglist->data;
456 g_return_val_if_fail(msginfo != NULL, -1);
458 if (msginfo->folder == dest) {
459 g_warning("the src folder is identical to the dest.\n");
463 if (dest->last_num < 0) {
464 mh_get_last_num(folder, dest);
465 if (dest->last_num < 0) return -1;
468 if ((MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
469 && !folder_has_parent_of_type(dest, F_QUEUE)
470 && !folder_has_parent_of_type(dest, F_DRAFT)) {
471 /* as every msginfo comes from the same folder, it is supposed they
472 * will either match the preceding condition either all or none.
474 remove_special_headers = TRUE;
475 } else if (!(MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
476 && (folder_has_parent_of_type(dest, F_QUEUE)
477 || folder_has_parent_of_type(dest, F_DRAFT))) {
483 for (cur = msglist; cur; cur = cur->next) {
484 msginfo = (MsgInfo *)cur->data;
487 srcfile = procmsg_get_message_file(msginfo);
488 destfile = mh_get_new_msg_filename(dest);
494 debug_print("Copying message %s%c%d to %s ...\n",
495 msginfo->folder->path, G_DIR_SEPARATOR,
496 msginfo->msgnum, dest->path);
499 if (remove_special_headers) {
500 if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
505 } else if (copy_file(srcfile, destfile, TRUE) < 0) {
506 FILE_OP_ERROR(srcfile, "copy");
511 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
512 if (chmod(destfile, prefs->folder_chmod) < 0)
513 FILE_OP_ERROR(destfile, "chmod");
516 filemode = prefs->folder_chmod;
517 if (filemode & S_IRGRP) filemode |= S_IWGRP;
518 if (filemode & S_IROTH) filemode |= S_IWOTH;
521 g_relation_insert(relation, msginfo, GINT_TO_POINTER(dest->last_num+1));
527 dest_need_scan = mh_scan_required(dest->folder, dest);
529 dest->mtime = time(NULL);
531 return dest->last_num;
534 static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
536 gboolean need_scan = FALSE;
539 g_return_val_if_fail(item != NULL, -1);
541 file = mh_fetch_msg(folder, item, num);
542 g_return_val_if_fail(file != NULL, -1);
544 need_scan = mh_scan_required(folder, item);
546 if (g_unlink(file) < 0) {
547 FILE_OP_ERROR(file, "unlink");
553 item->mtime = time(NULL);
559 static gint mh_remove_all_msg(Folder *folder, FolderItem *item)
564 g_return_val_if_fail(item != NULL, -1);
566 path = folder_item_get_path(item);
567 g_return_val_if_fail(path != NULL, -1);
568 val = remove_all_numbered_files(path);
574 static gboolean mh_is_msg_changed(Folder *folder, FolderItem *item,
579 if (g_stat(itos(msginfo->msgnum), &s) < 0 ||
580 msginfo->size != s.st_size || (
581 (msginfo->mtime - s.st_mtime != 0) &&
582 (msginfo->mtime - s.st_mtime != 3600) &&
583 (msginfo->mtime - s.st_mtime != -3600)))
589 static gint mh_scan_tree(Folder *folder)
594 g_return_val_if_fail(folder != NULL, -1);
597 item = folder_item_new(folder, folder->name, NULL);
598 item->folder = folder;
599 folder->node = item->node = g_node_new(item);
601 item = FOLDER_ITEM(folder->node->data);
603 rootpath = folder_item_get_path(item);
604 if (change_dir(rootpath) < 0) {
610 mh_create_tree(folder);
611 mh_remove_missing_folder_items(folder);
612 mh_scan_tree_recursive(item);
617 #define MAKE_DIR_IF_NOT_EXIST(dir) \
619 if (!is_dir_exist(dir)) { \
620 if (is_file_exist(dir)) { \
621 g_warning("File `%s' already exists.\n" \
622 "Can't create folder.", dir); \
625 if (make_dir(dir) < 0) \
630 static gint mh_create_tree(Folder *folder)
634 g_return_val_if_fail(folder != NULL, -1);
636 CHDIR_RETURN_VAL_IF_FAIL(get_mail_base_dir(), -1);
637 rootpath = LOCAL_FOLDER(folder)->rootpath;
638 MAKE_DIR_IF_NOT_EXIST(rootpath);
639 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
640 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
641 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
642 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
643 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
644 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
649 #undef MAKE_DIR_IF_NOT_EXIST
651 static gchar *mh_item_get_path(Folder *folder, FolderItem *item)
653 gchar *folder_path, *path;
655 g_return_val_if_fail(folder != NULL, NULL);
656 g_return_val_if_fail(item != NULL, NULL);
658 folder_path = g_strdup(LOCAL_FOLDER(folder)->rootpath);
659 g_return_val_if_fail(folder_path != NULL, NULL);
661 /* FIXME: [W32] The code below does not correctly merge
662 relative filenames; there should be a function to handle
664 if ( !is_relative_filename (folder_path) ) {
666 path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
669 path = g_strdup(folder_path);
672 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
673 folder_path, G_DIR_SEPARATOR_S,
676 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
680 real_path = mh_filename_from_utf8(path);
681 if (!is_dir_exist(real_path) && is_dir_exist(path)) {
682 /* mmh, older version did put utf8 filenames instead of
683 * the correct encoding */
684 rename(path, real_path);
685 folder_item_scan(item);
692 static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
695 gchar *path, *real_name;
697 FolderItem *new_item;
698 gchar *mh_sequences_filename;
699 FILE *mh_sequences_file;
701 g_return_val_if_fail(folder != NULL, NULL);
702 g_return_val_if_fail(parent != NULL, NULL);
703 g_return_val_if_fail(name != NULL, NULL);
705 path = folder_item_get_path(parent);
706 if (!is_dir_exist(path))
707 if (make_dir_hier(path) != 0)
710 real_name = mh_filename_from_utf8(name);
711 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, real_name, NULL);
715 if (make_dir(fullpath) < 0) {
723 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
726 path = g_strdup(name);
727 new_item = folder_item_new(folder, name, path);
728 folder_item_append(parent, new_item);
732 path = folder_item_get_path(new_item);
733 mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
734 ".mh_sequences", NULL);
735 if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
736 fclose(mh_sequences_file);
738 g_free(mh_sequences_filename);
744 static gint mh_rename_folder(Folder *folder, FolderItem *item,
750 gchar *newpath, *utf8newpath;
753 g_return_val_if_fail(folder != NULL, -1);
754 g_return_val_if_fail(item != NULL, -1);
755 g_return_val_if_fail(item->path != NULL, -1);
756 g_return_val_if_fail(name != NULL, -1);
758 oldpath = folder_item_get_path(item);
759 if (!is_dir_exist(oldpath))
760 make_dir_hier(oldpath);
762 dirname = g_path_get_dirname(oldpath);
763 real_name = mh_filename_from_utf8(name);
764 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
767 if (g_rename(oldpath, newpath) < 0) {
768 FILE_OP_ERROR(oldpath, "rename");
777 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
778 dirname = g_path_get_dirname(item->path);
779 utf8newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S,
783 utf8newpath = g_strdup(name);
786 item->name = g_strdup(name);
788 paths[0] = g_strdup(item->path);
789 paths[1] = utf8newpath;
790 g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
791 mh_rename_folder_func, paths);
798 static gint mh_remove_folder(Folder *folder, FolderItem *item)
802 g_return_val_if_fail(folder != NULL, -1);
803 g_return_val_if_fail(item != NULL, -1);
804 g_return_val_if_fail(item->path != NULL, -1);
806 path = folder_item_get_path(item);
807 if (remove_dir_recursive(path) < 0) {
808 g_warning("can't remove directory `%s'\n", path);
814 folder_item_remove(item);
818 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
823 g_return_val_if_fail(item != NULL, NULL);
824 g_return_val_if_fail(file != NULL, NULL);
826 flags.perm_flags = MSG_NEW|MSG_UNREAD;
829 if (folder_has_parent_of_type(item, F_QUEUE)) {
830 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
831 } else if (folder_has_parent_of_type(item, F_DRAFT)) {
832 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
835 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
836 if (!msginfo) return NULL;
838 msginfo->msgnum = atoi(file);
839 msginfo->folder = item;
845 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
850 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
851 result = is_dir_exist(entry);
858 * check whether PATH is a Maildir style mailbox.
859 * This is the case if the 3 subdir: new, cur, tmp are existing.
860 * This functon assumes that entry is an directory
862 static gboolean mh_is_maildir(const gchar *path)
864 return mh_is_maildir_one(path, "new") &&
865 mh_is_maildir_one(path, "cur") &&
866 mh_is_maildir_one(path, "tmp");
870 static gboolean mh_remove_missing_folder_items_func(GNode *node, gpointer data)
875 g_return_val_if_fail(node->data != NULL, FALSE);
877 if (G_NODE_IS_ROOT(node))
880 item = FOLDER_ITEM(node->data);
882 path = folder_item_get_path(item);
883 if (!is_dir_exist(path)) {
884 debug_print("folder '%s' not found. removing...\n", path);
885 folder_item_remove(item);
892 static void mh_remove_missing_folder_items(Folder *folder)
894 g_return_if_fail(folder != NULL);
896 debug_print("searching missing folders...\n");
898 g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
899 mh_remove_missing_folder_items_func, folder);
902 static void mh_scan_tree_recursive(FolderItem *item)
911 const gchar *dir_name;
913 gchar *real_path, *entry, *utf8entry, *utf8name;
916 g_return_if_fail(item != NULL);
917 g_return_if_fail(item->folder != NULL);
919 folder = item->folder;
921 real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
923 dir = g_dir_open(real_path, 0, NULL);
925 g_warning("failed to open directory: %s\n", real_path);
930 dp = opendir(real_path);
932 FILE_OP_ERROR(real_path, "opendir");
938 debug_print("scanning %s ...\n",
939 item->path ? item->path
940 : LOCAL_FOLDER(item->folder)->rootpath);
942 folder->ui_func(folder, item, folder->ui_func_data);
945 while ((dir_name = g_dir_read_name(dir)) != NULL) {
947 while ((d = readdir(dp)) != NULL) {
948 dir_name = d->d_name;
950 if (dir_name[0] == '.') continue;
952 utf8name = mh_filename_to_utf8(dir_name);
954 utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
957 utf8entry = g_strdup(utf8name);
958 entry = mh_filename_from_utf8(utf8entry);
961 #if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
962 d->d_type == DT_DIR ||
963 (d->d_type == DT_UNKNOWN &&
965 g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
966 #if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
970 FolderItem *new_item = NULL;
974 if (mh_is_maildir(entry)) {
983 for (node = node->children; node != NULL; node = node->next) {
984 FolderItem *cur_item = FOLDER_ITEM(node->data);
985 if (!strcmp2(cur_item->path, entry)) {
991 debug_print("new folder '%s' found.\n", entry);
992 new_item = folder_item_new(folder, utf8name, utf8entry);
993 folder_item_append(item, new_item);
997 if (!folder->inbox &&
998 !strcmp(dir_name, INBOX_DIR)) {
999 new_item->stype = F_INBOX;
1000 folder->inbox = new_item;
1001 } else if (!folder->outbox &&
1002 !strcmp(dir_name, OUTBOX_DIR)) {
1003 new_item->stype = F_OUTBOX;
1004 folder->outbox = new_item;
1005 } else if (!folder->draft &&
1006 !strcmp(dir_name, DRAFT_DIR)) {
1007 new_item->stype = F_DRAFT;
1008 folder->draft = new_item;
1009 } else if (!folder->queue &&
1010 !strcmp(dir_name, QUEUE_DIR)) {
1011 new_item->stype = F_QUEUE;
1012 folder->queue = new_item;
1013 } else if (!folder->trash &&
1014 !strcmp(dir_name, TRASH_DIR)) {
1015 new_item->stype = F_TRASH;
1016 folder->trash = new_item;
1020 mh_scan_tree_recursive(new_item);
1021 } else if (to_number(dir_name) > 0) n_msg++;
1034 item->mtime = time(NULL);
1038 gint new, unread, total, min, max;
1040 procmsg_get_mark_sum(item->path, &new, &unread, &total,
1042 if (n_msg > total) {
1043 new += n_msg - total;
1044 unread += n_msg - total;
1047 item->unread = unread;
1048 item->total = n_msg;
1053 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1055 FolderItem *item = node->data;
1056 gchar **paths = data;
1057 const gchar *oldpath = paths[0];
1058 const gchar *newpath = paths[1];
1060 gchar *new_itempath;
1063 oldpathlen = strlen(oldpath);
1064 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1065 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1069 base = item->path + oldpathlen;
1070 while (*base == G_DIR_SEPARATOR) base++;
1072 new_itempath = g_strdup(newpath);
1074 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1077 item->path = new_itempath;
1082 static gchar *mh_filename_from_utf8(const gchar *path)
1084 gchar *real_path = g_filename_from_utf8(path, -1, NULL, NULL, NULL);
1087 g_warning("mh_filename_from_utf8: faild to convert character set\n");
1088 real_path = g_strdup(path);
1094 static gchar *mh_filename_to_utf8(const gchar *path)
1096 gchar *utf8path = g_filename_to_utf8(path, -1, NULL, NULL, NULL);
1098 g_warning("mh_filename_to_utf8: faild to convert character set\n");
1099 utf8path = g_strdup(path);