2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 # include <sys/time.h>
43 #include "procheader.h"
46 static GSList *mh_get_uncached_msgs (GHashTable *msg_table,
48 static MsgInfo *mh_parse_msg (const gchar *file,
50 static void mh_scan_tree_recursive (FolderItem *item);
52 static gboolean mh_rename_folder_func (GNode *node,
56 GSList *mh_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
59 GHashTable *msg_table;
62 gboolean scan_new = TRUE;
64 struct timeval tv_before, tv_after, tv_result;
66 gettimeofday(&tv_before, NULL);
69 g_return_val_if_fail(item != NULL, NULL);
71 path = folder_item_get_path(item);
72 if (stat(path, &s) < 0) {
73 FILE_OP_ERROR(path, "stat");
75 if (item->mtime == s.st_mtime) {
76 debug_print("Folder is not modified.\n");
79 item->mtime = s.st_mtime;
83 if (use_cache && !scan_new) {
84 mlist = procmsg_read_cache(item, FALSE);
86 mlist = mh_get_uncached_msgs(NULL, item);
87 } else if (use_cache) {
90 mlist = procmsg_read_cache(item, TRUE);
91 msg_table = procmsg_msg_hash_table_create(mlist);
93 newlist = mh_get_uncached_msgs(msg_table, item);
95 g_hash_table_destroy(msg_table);
97 mlist = g_slist_concat(mlist, newlist);
99 mlist = mh_get_uncached_msgs(NULL, item);
101 procmsg_set_flags(mlist, item);
104 gettimeofday(&tv_after, NULL);
106 timersub(&tv_after, &tv_before, &tv_result);
107 g_print("mh_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
108 item->path, tv_result.tv_sec, tv_result.tv_usec);
114 gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
119 g_return_val_if_fail(item != NULL, NULL);
120 g_return_val_if_fail(num > 0 && num <= item->last_num, NULL);
122 path = folder_item_get_path(item);
123 file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
125 if (!is_file_exist(file)) {
133 gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
134 gboolean remove_source)
139 g_return_val_if_fail(dest != NULL, -1);
140 g_return_val_if_fail(file != NULL, -1);
142 if (dest->last_num < 0) {
143 mh_scan_folder(folder, dest);
144 if (dest->last_num < 0) return -1;
147 destpath = folder_item_get_path(dest);
148 g_return_val_if_fail(destpath != NULL, -1);
149 if (!is_dir_exist(destpath))
150 make_dir_hier(destpath);
152 destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
155 if (link(file, destfile) < 0) {
156 if (copy_file(file, destfile) < 0) {
157 g_warning(_("can't copy message %s to %s\n"),
165 if (unlink(file) < 0)
166 FILE_OP_ERROR(file, "unlink");
171 return dest->last_num;
174 gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
181 PrefsFolderItem *prefs;
183 g_return_val_if_fail(dest != NULL, -1);
184 g_return_val_if_fail(msginfo != NULL, -1);
186 if (msginfo->folder == dest) {
187 g_warning(_("the src folder is identical to the dest.\n"));
191 if (dest->last_num < 0) {
192 mh_scan_folder(folder, dest);
193 if (dest->last_num < 0) return -1;
198 destdir = folder_item_get_path(dest);
199 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
200 g_warning(_("Can't open mark file.\n"));
202 debug_print(_("Moving message %s%c%d to %s ...\n"),
203 msginfo->folder->path, G_DIR_SEPARATOR,
204 msginfo->msgnum, dest->path);
205 srcfile = procmsg_get_message_file_path(msginfo);
206 destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
210 if (move_file(srcfile, destfile) < 0) {
217 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
218 if (chmod(destfile, prefs->folder_chmod) < 0)
219 FILE_OP_ERROR(destfile, "chmod");
222 filemode = prefs->folder_chmod;
223 if (filemode & S_IRGRP) filemode |= S_IWGRP;
224 if (filemode & S_IROTH) filemode |= S_IWOTH;
234 newmsginfo.msgnum = dest->last_num;
235 newmsginfo.flags = msginfo->flags;
236 if (dest->stype == F_OUTBOX ||
237 dest->stype == F_QUEUE ||
238 dest->stype == F_DRAFT ||
239 dest->stype == F_TRASH)
240 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
241 MSG_NEW|MSG_UNREAD|MSG_DELETED);
243 procmsg_write_flags(&newmsginfo, fp);
247 fchmod(fileno(fp), filemode);
251 markfile = folder_item_get_mark_file(dest);
253 chmod(markfile, filemode);
262 return dest->last_num;
265 gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
273 PrefsFolderItem *prefs;
275 g_return_val_if_fail(dest != NULL, -1);
276 g_return_val_if_fail(msglist != NULL, -1);
278 if (dest->last_num < 0) {
279 mh_scan_folder(folder, dest);
280 if (dest->last_num < 0) return -1;
285 destdir = folder_item_get_path(dest);
286 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
287 g_warning(_("Can't open mark file.\n"));
289 for (cur = msglist; cur != NULL; cur = cur->next) {
290 msginfo = (MsgInfo *)cur->data;
292 if (msginfo->folder == dest) {
293 g_warning(_("the src folder is identical to the dest.\n"));
296 debug_print(_("Moving message %s%c%d to %s ...\n"),
297 msginfo->folder->path, G_DIR_SEPARATOR,
298 msginfo->msgnum, dest->path);
300 srcfile = procmsg_get_message_file_path(msginfo);
301 destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
304 if (move_file(srcfile, destfile) < 0) {
317 newmsginfo.msgnum = dest->last_num;
318 newmsginfo.flags = msginfo->flags;
319 if (dest->stype == F_OUTBOX ||
320 dest->stype == F_QUEUE ||
321 dest->stype == F_DRAFT ||
322 dest->stype == F_TRASH)
325 MSG_NEW|MSG_UNREAD|MSG_DELETED);
327 procmsg_write_flags(&newmsginfo, fp);
334 return dest->last_num;
337 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
344 PrefsFolderItem *prefs;
346 g_return_val_if_fail(dest != NULL, -1);
347 g_return_val_if_fail(msginfo != NULL, -1);
349 if (msginfo->folder == dest) {
350 g_warning(_("the src folder is identical to the dest.\n"));
354 if (dest->last_num < 0) {
355 mh_scan_folder(folder, dest);
356 if (dest->last_num < 0) return -1;
361 destdir = folder_item_get_path(dest);
362 if (!is_dir_exist(destdir))
363 make_dir_hier(destdir);
365 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
366 g_warning(_("Can't open mark file.\n"));
368 debug_print(_("Copying message %s%c%d to %s ...\n"),
369 msginfo->folder->path, G_DIR_SEPARATOR,
370 msginfo->msgnum, dest->path);
371 srcfile = procmsg_get_message_file_path(msginfo);
372 destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
378 if (is_file_exist(destfile)) {
379 g_warning(_("%s already exists."), destfile);
386 if (copy_file(srcfile, destfile) < 0) {
387 FILE_OP_ERROR(srcfile, "copy");
394 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
395 if (chmod(destfile, prefs->folder_chmod) < 0)
396 FILE_OP_ERROR(destfile, "chmod");
399 filemode = prefs->folder_chmod;
400 if (filemode & S_IRGRP) filemode |= S_IWGRP;
401 if (filemode & S_IROTH) filemode |= S_IWOTH;
411 newmsginfo.msgnum = dest->last_num;
412 newmsginfo.flags = msginfo->flags;
413 if (dest->stype == F_OUTBOX ||
414 dest->stype == F_QUEUE ||
415 dest->stype == F_DRAFT ||
416 dest->stype == F_TRASH)
417 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
418 MSG_NEW|MSG_UNREAD|MSG_DELETED);
419 procmsg_write_flags(&newmsginfo, fp);
423 fchmod(fileno(fp), filemode);
427 markfile = folder_item_get_mark_file(dest);
429 chmod(markfile, filemode);
438 return dest->last_num;
442 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
450 src_folder = msginfo->folder->folder;
452 g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
454 filename = src_folder->fetch_msg(src_folder,
457 if (filename == NULL)
460 num = folder->add_msg(folder, dest, filename, FALSE);
462 destdir = folder_item_get_path(dest);
463 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
464 g_warning(_("Can't open mark file.\n"));
469 newmsginfo.msgnum = dest->last_num;
470 newmsginfo.flags = msginfo->flags;
471 if (dest->stype == F_OUTBOX ||
472 dest->stype == F_QUEUE ||
473 dest->stype == F_DRAFT ||
474 dest->stype == F_TRASH)
475 MSG_UNSET_FLAGS(newmsginfo.flags,
476 MSG_NEW|MSG_UNREAD|MSG_DELETED);
478 procmsg_write_flags(&newmsginfo, fp);
486 gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
495 g_return_val_if_fail(dest != NULL, -1);
496 g_return_val_if_fail(msglist != NULL, -1);
498 if (dest->last_num < 0) {
499 mh_scan_folder(folder, dest);
500 if (dest->last_num < 0) return -1;
503 destdir = folder_item_get_path(dest);
504 if (!is_dir_exist(destdir))
505 make_dir_hier(destdir);
507 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
508 g_warning(_("Can't open mark file.\n"));
510 for (cur = msglist; cur != NULL; cur = cur->next) {
511 msginfo = (MsgInfo *)cur->data;
513 if (msginfo->folder == dest) {
514 g_warning(_("the src folder is identical to the dest.\n"));
517 debug_print(_("Copying message %s%c%d to %s ...\n"),
518 msginfo->folder->path, G_DIR_SEPARATOR,
519 msginfo->msgnum, dest->path);
521 srcfile = procmsg_get_message_file_path(msginfo);
522 destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
525 if (is_file_exist(destfile)) {
526 g_warning(_("%s already exists."), destfile);
532 if (copy_file(srcfile, destfile) < 0) {
533 FILE_OP_ERROR(srcfile, "copy");
546 newmsginfo.msgnum = dest->last_num;
547 newmsginfo.flags = msginfo->flags;
548 if (dest->stype == F_OUTBOX ||
549 dest->stype == F_QUEUE ||
550 dest->stype == F_DRAFT ||
551 dest->stype == F_TRASH)
554 MSG_NEW|MSG_UNREAD|MSG_DELETED);
555 procmsg_write_flags(&newmsginfo, fp);
562 return dest->last_num;
565 gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
569 g_return_val_if_fail(item != NULL, -1);
571 file = mh_fetch_msg(folder, item, num);
572 g_return_val_if_fail(file != NULL, -1);
574 if (unlink(file) < 0) {
575 FILE_OP_ERROR(file, "unlink");
584 gint mh_remove_all_msg(Folder *folder, FolderItem *item)
589 g_return_val_if_fail(item != NULL, -1);
591 path = folder_item_get_path(item);
592 g_return_val_if_fail(path != NULL, -1);
593 val = remove_all_numbered_files(path);
599 gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, MsgInfo *msginfo)
603 if (stat(itos(msginfo->msgnum), &s) < 0 ||
604 msginfo->size != s.st_size ||
605 msginfo->mtime != s.st_mtime)
611 void mh_scan_folder(Folder *folder, FolderItem *item)
621 g_return_if_fail(item != NULL);
623 debug_print("mh_scan_folder(): Scanning %s ...\n", item->path);
625 path = folder_item_get_path(item);
626 g_return_if_fail(path != NULL);
627 if (change_dir(path) < 0) {
633 if ((dp = opendir(".")) == NULL) {
634 FILE_OP_ERROR(item->path, "opendir");
639 folder->ui_func(folder, item, folder->ui_func_data);
641 while ((d = readdir(dp)) != NULL) {
642 if ((num = to_number(d->d_name)) >= 0 &&
643 stat(d->d_name, &s) == 0 &&
644 S_ISREG(s.st_mode)) {
654 item->new = item->unread = item->total = 0;
656 gint new, unread, total;
658 procmsg_get_mark_sum(".", &new, &unread, &total);
660 new += n_msg - total;
661 unread += n_msg - total;
664 item->unread = unread;
668 debug_print(_("Last number in dir %s = %d\n"), item->path, max);
669 item->last_num = max;
672 void mh_scan_tree(Folder *folder)
677 g_return_if_fail(folder != NULL);
679 folder_tree_destroy(folder);
680 item = folder_item_new(folder->name, NULL);
681 item->folder = folder;
682 folder->node = g_node_new(item);
684 rootpath = folder_item_get_path(item);
685 if (change_dir(rootpath) < 0) {
691 mh_scan_tree_recursive(item);
694 #define MAKE_DIR_IF_NOT_EXIST(dir) \
696 if (!is_dir_exist(dir)) { \
697 if (is_file_exist(dir)) { \
698 g_warning(_("File `%s' already exists.\n" \
699 "Can't create folder."), dir); \
702 if (mkdir(dir, S_IRWXU) < 0) { \
703 FILE_OP_ERROR(dir, "mkdir"); \
706 if (chmod(dir, S_IRWXU) < 0) \
707 FILE_OP_ERROR(dir, "chmod"); \
711 gint mh_create_tree(Folder *folder)
715 g_return_val_if_fail(folder != NULL, -1);
717 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
718 rootpath = LOCAL_FOLDER(folder)->rootpath;
719 MAKE_DIR_IF_NOT_EXIST(rootpath);
720 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
721 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
722 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
723 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
724 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
725 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
730 #undef MAKE_DIR_IF_NOT_EXIST
732 FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
737 FolderItem *new_item;
739 g_return_val_if_fail(folder != NULL, NULL);
740 g_return_val_if_fail(parent != NULL, NULL);
741 g_return_val_if_fail(name != NULL, NULL);
743 path = folder_item_get_path(parent);
744 if (!is_dir_exist(path))
747 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
750 if (mkdir(fullpath, S_IRWXU) < 0) {
751 FILE_OP_ERROR(fullpath, "mkdir");
755 if (chmod(fullpath, S_IRWXU) < 0)
756 FILE_OP_ERROR(fullpath, "chmod");
761 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
764 path = g_strdup(name);
765 new_item = folder_item_new(name, path);
766 folder_item_append(parent, new_item);
772 gint mh_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
780 g_return_val_if_fail(folder != NULL, -1);
781 g_return_val_if_fail(item != NULL, -1);
782 g_return_val_if_fail(item->path != NULL, -1);
783 g_return_val_if_fail(name != NULL, -1);
785 oldpath = folder_item_get_path(item);
786 if (!is_dir_exist(oldpath))
787 make_dir_hier(oldpath);
789 dirname = g_dirname(oldpath);
790 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
793 if (rename(oldpath, newpath) < 0) {
794 FILE_OP_ERROR(oldpath, "rename");
803 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
804 dirname = g_dirname(item->path);
805 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
808 newpath = g_strdup(name);
811 item->name = g_strdup(name);
813 node = g_node_find(item->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
815 paths[0] = g_strdup(item->path);
817 g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
818 mh_rename_folder_func, paths);
825 gint mh_remove_folder(Folder *folder, FolderItem *item)
829 g_return_val_if_fail(folder != NULL, -1);
830 g_return_val_if_fail(item != NULL, -1);
831 g_return_val_if_fail(item->path != NULL, -1);
833 path = folder_item_get_path(item);
834 if (remove_dir_recursive(path) < 0) {
835 g_warning("can't remove directory `%s'\n", path);
841 folder_item_remove(item);
846 static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
852 GSList *newlist = NULL;
858 g_return_val_if_fail(item != NULL, NULL);
860 path = folder_item_get_path(item);
861 g_return_val_if_fail(path != NULL, NULL);
862 if (change_dir(path) < 0) {
868 if ((dp = opendir(".")) == NULL) {
869 FILE_OP_ERROR(item->path, "opendir");
873 debug_print(_("\tSearching uncached messages... "));
876 while ((d = readdir(dp)) != NULL) {
877 if ((num = to_number(d->d_name)) < 0) continue;
878 if (stat(d->d_name, &s) < 0) {
879 FILE_OP_ERROR(d->d_name, "stat");
882 if (!S_ISREG(s.st_mode)) continue;
884 msginfo = g_hash_table_lookup
885 (msg_table, GUINT_TO_POINTER(num));
888 /* not found in the cache (uncached message) */
889 msginfo = mh_parse_msg(d->d_name, item);
890 if (!msginfo) continue;
894 g_slist_append(NULL, msginfo);
896 last = g_slist_append(last, msginfo);
903 /* discard all previous cache */
904 while ((d = readdir(dp)) != NULL) {
905 if (to_number(d->d_name) < 0) continue;
906 if (stat(d->d_name, &s) < 0) {
907 FILE_OP_ERROR(d->d_name, "stat");
910 if (!S_ISREG(s.st_mode)) continue;
912 msginfo = mh_parse_msg(d->d_name, item);
913 if (!msginfo) continue;
916 last = newlist = g_slist_append(NULL, msginfo);
918 last = g_slist_append(last, msginfo);
928 debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
930 debug_print(_("done.\n"));
932 /* sort new messages in numerical order */
934 debug_print(_("\tSorting uncached messages in numerical order... "));
935 newlist = g_slist_sort
936 (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
937 debug_print(_("done.\n"));
943 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
949 flags.perm_flags = MSG_NEW|MSG_UNREAD;
952 g_return_val_if_fail(item != NULL, NULL);
953 g_return_val_if_fail(file != NULL, NULL);
955 if (item->stype == F_QUEUE) {
956 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
957 } else if (item->stype == F_DRAFT) {
958 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
961 msginfo = procheader_parse(file, flags, FALSE);
962 if (!msginfo) return NULL;
964 msginfo->msgnum = atoi(file);
965 msginfo->folder = item;
967 if (stat(file, &s) < 0) {
968 FILE_OP_ERROR(file, "stat");
972 msginfo->size = s.st_size;
973 msginfo->mtime = s.st_mtime;
979 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
984 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
985 result = is_dir_exist(entry);
992 * check whether PATH is a Maildir style mailbox.
993 * This is the case if the 3 subdir: new, cur, tmp are existing.
994 * This functon assumes that entry is an directory
996 static gboolean mh_is_maildir(const gchar *path)
998 return mh_is_maildir_one(path, "new") &&
999 mh_is_maildir_one(path, "cur") &&
1000 mh_is_maildir_one(path, "tmp");
1003 static void mh_scan_tree_recursive(FolderItem *item)
1011 g_return_if_fail(item != NULL);
1012 g_return_if_fail(item->folder != NULL);
1014 dp = opendir(item->path ? item->path : ".");
1016 FILE_OP_ERROR(item->path ? item->path : ".", "opendir");
1020 debug_print("scanning %s ...\n",
1021 item->path ? item->path
1022 : LOCAL_FOLDER(item->folder)->rootpath);
1023 if (item->folder->ui_func)
1024 item->folder->ui_func(item->folder, item,
1025 item->folder->ui_func_data);
1027 while ((d = readdir(dp)) != NULL) {
1028 if (d->d_name[0] == '.') continue;
1031 entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
1034 entry = g_strdup(d->d_name);
1036 if (stat(entry, &s) < 0) {
1037 FILE_OP_ERROR(entry, "stat");
1042 if (S_ISDIR(s.st_mode)) {
1043 FolderItem *new_item;
1045 if (mh_is_maildir(entry)) {
1050 new_item = folder_item_new(d->d_name, entry);
1051 folder_item_append(item, new_item);
1053 if (!strcmp(d->d_name, "inbox")) {
1054 new_item->stype = F_INBOX;
1055 item->folder->inbox = new_item;
1056 } else if (!strcmp(d->d_name, "outbox")) {
1057 new_item->stype = F_OUTBOX;
1058 item->folder->outbox = new_item;
1059 } else if (!strcmp(d->d_name, "draft")) {
1060 new_item->stype = F_DRAFT;
1061 item->folder->draft = new_item;
1062 } else if (!strcmp(d->d_name, "queue")) {
1063 new_item->stype = F_QUEUE;
1064 item->folder->queue = new_item;
1065 } else if (!strcmp(d->d_name, "trash")) {
1066 new_item->stype = F_TRASH;
1067 item->folder->trash = new_item;
1070 mh_scan_tree_recursive(new_item);
1071 } else if (to_number(d->d_name) != -1) n_msg++;
1079 gint new, unread, total;
1081 procmsg_get_mark_sum(item->path, &new, &unread, &total);
1082 if (n_msg > total) {
1083 new += n_msg - total;
1084 unread += n_msg - total;
1087 item->unread = unread;
1088 item->total = n_msg;
1092 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1094 FolderItem *item = node->data;
1095 gchar **paths = data;
1096 const gchar *oldpath = paths[0];
1097 const gchar *newpath = paths[1];
1099 gchar *new_itempath;
1102 oldpathlen = strlen(oldpath);
1103 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1104 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1108 base = item->path + oldpathlen;
1109 while (*base == G_DIR_SEPARATOR) base++;
1111 new_itempath = g_strdup(newpath);
1113 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1116 item->path = new_itempath;