2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 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 void mh_folder_init (Folder *folder,
50 static GSList *mh_get_uncached_msgs (GHashTable *msg_table,
52 static MsgInfo *mh_parse_msg (const gchar *file,
54 static void mh_scan_tree_recursive (FolderItem *item,
57 static gboolean mh_rename_folder_func (GNode *node,
61 Folder *mh_folder_new(const gchar *name, const gchar *path)
65 folder = (Folder *)g_new0(MHFolder, 1);
66 mh_folder_init(folder, name, path);
71 void mh_folder_destroy(MHFolder *folder)
73 folder_local_folder_destroy(LOCAL_FOLDER(folder));
76 static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
78 folder_local_folder_init(folder, name, path);
82 folder->get_msg_list = mh_get_msg_list;
83 folder->fetch_msg = mh_fetch_msg;
84 folder->add_msg = mh_add_msg;
85 folder->move_msg = mh_move_msg;
86 folder->move_msgs_with_dest = mh_move_msgs_with_dest;
87 folder->copy_msg = mh_copy_msg;
88 folder->copy_msgs_with_dest = mh_copy_msgs_with_dest;
89 folder->remove_msg = mh_remove_msg;
90 folder->remove_all_msg = mh_remove_all_msg;
91 folder->is_msg_changed = mh_is_msg_changed;
92 folder->scan = mh_scan_folder;
93 folder->scan_tree = mh_scan_tree;
94 folder->create_tree = mh_create_tree;
95 folder->create_folder = mh_create_folder;
96 folder->rename_folder = mh_rename_folder;
97 folder->remove_folder = mh_remove_folder;
100 GSList *mh_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
103 GHashTable *msg_table;
106 gboolean scan_new = TRUE;
108 struct timeval tv_before, tv_after, tv_result;
110 gettimeofday(&tv_before, NULL);
113 g_return_val_if_fail(item != NULL, NULL);
115 path = folder_item_get_path(item);
116 if (stat(path, &s) < 0) {
117 FILE_OP_ERROR(path, "stat");
119 if (item->mtime == s.st_mtime) {
120 debug_print("Folder is not modified.\n");
123 item->mtime = s.st_mtime;
127 if (use_cache && !scan_new) {
128 mlist = procmsg_read_cache(item, FALSE);
130 mlist = mh_get_uncached_msgs(NULL, item);
131 } else if (use_cache) {
134 mlist = procmsg_read_cache(item, TRUE);
135 msg_table = procmsg_msg_hash_table_create(mlist);
137 newlist = mh_get_uncached_msgs(msg_table, item);
139 g_hash_table_destroy(msg_table);
141 mlist = g_slist_concat(mlist, newlist);
143 mlist = mh_get_uncached_msgs(NULL, item);
145 procmsg_set_flags(mlist, item);
148 gettimeofday(&tv_after, NULL);
150 timersub(&tv_after, &tv_before, &tv_result);
151 g_print("mh_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
152 item->path, tv_result.tv_sec, tv_result.tv_usec);
158 gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
163 g_return_val_if_fail(item != NULL, NULL);
164 g_return_val_if_fail(num > 0 && num <= item->last_num, NULL);
166 path = folder_item_get_path(item);
167 file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
169 if (!is_file_exist(file)) {
177 gchar *mh_get_newmsg_filename(FolderItem *dest)
181 gboolean found = FALSE;
183 destpath = folder_item_get_path(dest);
184 g_return_val_if_fail(destpath != NULL, NULL);
185 if (!is_dir_exist(destpath))
186 make_dir_hier(destpath);
189 destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
191 if(is_file_exist(destfile)) {
203 gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
204 gboolean remove_source)
208 g_return_val_if_fail(dest != NULL, -1);
209 g_return_val_if_fail(file != NULL, -1);
211 if (dest->last_num < 0) {
212 mh_scan_folder(folder, dest);
213 if (dest->last_num < 0) return -1;
216 destfile = mh_get_newmsg_filename(dest);
217 if(!destfile) return -1;
219 if (link(file, destfile) < 0) {
220 if (copy_file(file, destfile) < 0) {
221 g_warning(_("can't copy message %s to %s\n"),
229 if (unlink(file) < 0)
230 FILE_OP_ERROR(file, "unlink");
235 return dest->last_num;
238 gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
245 PrefsFolderItem *prefs;
247 g_return_val_if_fail(dest != NULL, -1);
248 g_return_val_if_fail(msginfo != NULL, -1);
250 if (msginfo->folder == dest) {
251 g_warning(_("the src folder is identical to the dest.\n"));
255 if (dest->last_num < 0) {
256 mh_scan_folder(folder, dest);
257 if (dest->last_num < 0) return -1;
262 destdir = folder_item_get_path(dest);
263 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
264 g_warning(_("Can't open mark file.\n"));
266 debug_print(_("Moving message %s%c%d to %s ...\n"),
267 msginfo->folder->path, G_DIR_SEPARATOR,
268 msginfo->msgnum, dest->path);
269 srcfile = procmsg_get_message_file_path(msginfo);
271 destfile = mh_get_newmsg_filename(dest);
272 if(!destfile) return -1;
276 if (move_file(srcfile, destfile) < 0) {
283 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
284 if (chmod(destfile, prefs->folder_chmod) < 0)
285 FILE_OP_ERROR(destfile, "chmod");
288 filemode = prefs->folder_chmod;
289 if (filemode & S_IRGRP) filemode |= S_IWGRP;
290 if (filemode & S_IROTH) filemode |= S_IWOTH;
300 newmsginfo.msgnum = dest->last_num;
301 newmsginfo.flags = msginfo->flags;
302 if (dest->stype == F_OUTBOX ||
303 dest->stype == F_QUEUE ||
304 dest->stype == F_DRAFT ||
305 dest->stype == F_TRASH)
306 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
307 MSG_NEW|MSG_UNREAD|MSG_DELETED);
309 procmsg_write_flags(&newmsginfo, fp);
313 fchmod(fileno(fp), filemode);
317 markfile = folder_item_get_mark_file(dest);
319 chmod(markfile, filemode);
328 return dest->last_num;
331 gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
339 PrefsFolderItem *prefs;
341 g_return_val_if_fail(dest != NULL, -1);
342 g_return_val_if_fail(msglist != NULL, -1);
344 if (dest->last_num < 0) {
345 mh_scan_folder(folder, dest);
346 if (dest->last_num < 0) return -1;
351 destdir = folder_item_get_path(dest);
352 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
353 g_warning(_("Can't open mark file.\n"));
355 for (cur = msglist; cur != NULL; cur = cur->next) {
356 msginfo = (MsgInfo *)cur->data;
358 if (msginfo->folder == dest) {
359 g_warning(_("the src folder is identical to the dest.\n"));
362 debug_print(_("Moving message %s%c%d to %s ...\n"),
363 msginfo->folder->path, G_DIR_SEPARATOR,
364 msginfo->msgnum, dest->path);
366 srcfile = procmsg_get_message_file_path(msginfo);
367 destfile = mh_get_newmsg_filename(dest);
368 if(!destfile) return -1;
370 if (move_file(srcfile, destfile) < 0) {
383 newmsginfo.msgnum = dest->last_num;
384 newmsginfo.flags = msginfo->flags;
385 if (dest->stype == F_OUTBOX ||
386 dest->stype == F_QUEUE ||
387 dest->stype == F_DRAFT ||
388 dest->stype == F_TRASH)
391 MSG_NEW|MSG_UNREAD|MSG_DELETED);
393 procmsg_write_flags(&newmsginfo, fp);
400 return dest->last_num;
403 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
410 PrefsFolderItem *prefs;
412 g_return_val_if_fail(dest != NULL, -1);
413 g_return_val_if_fail(msginfo != NULL, -1);
415 if (msginfo->folder == dest) {
416 g_warning(_("the src folder is identical to the dest.\n"));
420 if (dest->last_num < 0) {
421 mh_scan_folder(folder, dest);
422 if (dest->last_num < 0) return -1;
427 destdir = folder_item_get_path(dest);
428 if (!is_dir_exist(destdir))
429 make_dir_hier(destdir);
431 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
432 g_warning(_("Can't open mark file.\n"));
434 debug_print(_("Copying message %s%c%d to %s ...\n"),
435 msginfo->folder->path, G_DIR_SEPARATOR,
436 msginfo->msgnum, dest->path);
437 srcfile = procmsg_get_message_file_path(msginfo);
438 destfile = mh_get_newmsg_filename(dest);
449 if (copy_file(srcfile, destfile) < 0) {
450 FILE_OP_ERROR(srcfile, "copy");
457 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
458 if (chmod(destfile, prefs->folder_chmod) < 0)
459 FILE_OP_ERROR(destfile, "chmod");
462 filemode = prefs->folder_chmod;
463 if (filemode & S_IRGRP) filemode |= S_IWGRP;
464 if (filemode & S_IROTH) filemode |= S_IWOTH;
474 newmsginfo.msgnum = dest->last_num;
475 newmsginfo.flags = msginfo->flags;
476 if (dest->stype == F_OUTBOX ||
477 dest->stype == F_QUEUE ||
478 dest->stype == F_DRAFT ||
479 dest->stype == F_TRASH)
480 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
481 MSG_NEW|MSG_UNREAD|MSG_DELETED);
482 procmsg_write_flags(&newmsginfo, fp);
486 fchmod(fileno(fp), filemode);
490 markfile = folder_item_get_mark_file(dest);
492 chmod(markfile, filemode);
501 return dest->last_num;
505 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
513 src_folder = msginfo->folder->folder;
515 g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
517 filename = src_folder->fetch_msg(src_folder,
520 if (filename == NULL)
523 num = folder->add_msg(folder, dest, filename, FALSE);
525 destdir = folder_item_get_path(dest);
526 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
527 g_warning(_("Can't open mark file.\n"));
532 newmsginfo.msgnum = dest->last_num;
533 newmsginfo.flags = msginfo->flags;
534 if (dest->stype == F_OUTBOX ||
535 dest->stype == F_QUEUE ||
536 dest->stype == F_DRAFT ||
537 dest->stype == F_TRASH)
538 MSG_UNSET_FLAGS(newmsginfo.flags,
539 MSG_NEW|MSG_UNREAD|MSG_DELETED);
541 procmsg_write_flags(&newmsginfo, fp);
549 gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
558 g_return_val_if_fail(dest != NULL, -1);
559 g_return_val_if_fail(msglist != NULL, -1);
561 if (dest->last_num < 0) {
562 mh_scan_folder(folder, dest);
563 if (dest->last_num < 0) return -1;
566 destdir = folder_item_get_path(dest);
567 if (!is_dir_exist(destdir))
568 make_dir_hier(destdir);
570 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
571 g_warning(_("Can't open mark file.\n"));
573 for (cur = msglist; cur != NULL; cur = cur->next) {
574 msginfo = (MsgInfo *)cur->data;
576 if (msginfo->folder == dest) {
577 g_warning(_("the src folder is identical to the dest.\n"));
580 debug_print(_("Copying message %s%c%d to %s ...\n"),
581 msginfo->folder->path, G_DIR_SEPARATOR,
582 msginfo->msgnum, dest->path);
584 srcfile = procmsg_get_message_file_path(msginfo);
585 destfile = mh_get_newmsg_filename(dest);
591 if (copy_file(srcfile, destfile) < 0) {
592 FILE_OP_ERROR(srcfile, "copy");
605 newmsginfo.msgnum = dest->last_num;
606 newmsginfo.flags = msginfo->flags;
607 if (dest->stype == F_OUTBOX ||
608 dest->stype == F_QUEUE ||
609 dest->stype == F_DRAFT ||
610 dest->stype == F_TRASH)
613 MSG_NEW|MSG_UNREAD|MSG_DELETED);
614 procmsg_write_flags(&newmsginfo, fp);
621 return dest->last_num;
624 gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
628 g_return_val_if_fail(item != NULL, -1);
630 file = mh_fetch_msg(folder, item, num);
631 g_return_val_if_fail(file != NULL, -1);
633 if (unlink(file) < 0) {
634 FILE_OP_ERROR(file, "unlink");
643 gint mh_remove_all_msg(Folder *folder, FolderItem *item)
648 g_return_val_if_fail(item != NULL, -1);
650 path = folder_item_get_path(item);
651 g_return_val_if_fail(path != NULL, -1);
652 val = remove_all_numbered_files(path);
658 gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, MsgInfo *msginfo)
662 if (stat(itos(msginfo->msgnum), &s) < 0 ||
663 msginfo->size != s.st_size ||
664 msginfo->mtime != s.st_mtime)
670 void mh_scan_folder(Folder *folder, FolderItem *item)
680 g_return_if_fail(item != NULL);
682 debug_print("mh_scan_folder(): Scanning %s ...\n", item->path);
684 path = folder_item_get_path(item);
685 g_return_if_fail(path != NULL);
686 if (change_dir(path) < 0) {
692 if ((dp = opendir(".")) == NULL) {
693 FILE_OP_ERROR(item->path, "opendir");
698 folder->ui_func(folder, item, folder->ui_func_data);
700 while ((d = readdir(dp)) != NULL) {
701 if ((num = to_number(d->d_name)) >= 0 &&
702 stat(d->d_name, &s) == 0 &&
703 S_ISREG(s.st_mode)) {
713 item->new = item->unread = item->total = 0;
715 gint new, unread, total;
717 procmsg_get_mark_sum(".", &new, &unread, &total);
719 new += n_msg - total;
720 unread += n_msg - total;
723 item->unread = unread;
727 debug_print(_("Last number in dir %s = %d\n"), item->path, max);
728 item->last_num = max;
731 void mh_scan_tree(Folder *folder)
737 g_return_if_fail(folder != NULL);
739 pptable = folder_persist_prefs_new(folder);
741 folder_tree_destroy(folder);
742 item = folder_item_new(folder->name, NULL);
743 item->folder = folder;
744 folder->node = g_node_new(item);
746 rootpath = folder_item_get_path(item);
747 if (change_dir(rootpath) < 0) {
753 mh_scan_tree_recursive(item, pptable);
755 folder_persist_prefs_free(pptable);
758 #define MAKE_DIR_IF_NOT_EXIST(dir) \
760 if (!is_dir_exist(dir)) { \
761 if (is_file_exist(dir)) { \
762 g_warning(_("File `%s' already exists.\n" \
763 "Can't create folder."), dir); \
766 if (mkdir(dir, S_IRWXU) < 0) { \
767 FILE_OP_ERROR(dir, "mkdir"); \
770 if (chmod(dir, S_IRWXU) < 0) \
771 FILE_OP_ERROR(dir, "chmod"); \
775 gint mh_create_tree(Folder *folder)
779 g_return_val_if_fail(folder != NULL, -1);
781 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
782 rootpath = LOCAL_FOLDER(folder)->rootpath;
783 MAKE_DIR_IF_NOT_EXIST(rootpath);
784 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
785 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
786 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
787 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
788 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
789 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
794 #undef MAKE_DIR_IF_NOT_EXIST
796 FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
801 FolderItem *new_item;
803 g_return_val_if_fail(folder != NULL, NULL);
804 g_return_val_if_fail(parent != NULL, NULL);
805 g_return_val_if_fail(name != NULL, NULL);
807 path = folder_item_get_path(parent);
808 if (!is_dir_exist(path))
811 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
814 if (mkdir(fullpath, S_IRWXU) < 0) {
815 FILE_OP_ERROR(fullpath, "mkdir");
819 if (chmod(fullpath, S_IRWXU) < 0)
820 FILE_OP_ERROR(fullpath, "chmod");
825 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
828 path = g_strdup(name);
829 new_item = folder_item_new(name, path);
830 folder_item_append(parent, new_item);
836 gint mh_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
844 g_return_val_if_fail(folder != NULL, -1);
845 g_return_val_if_fail(item != NULL, -1);
846 g_return_val_if_fail(item->path != NULL, -1);
847 g_return_val_if_fail(name != NULL, -1);
849 oldpath = folder_item_get_path(item);
850 if (!is_dir_exist(oldpath))
851 make_dir_hier(oldpath);
853 dirname = g_dirname(oldpath);
854 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
857 if (rename(oldpath, newpath) < 0) {
858 FILE_OP_ERROR(oldpath, "rename");
867 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
868 dirname = g_dirname(item->path);
869 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
872 newpath = g_strdup(name);
875 item->name = g_strdup(name);
877 node = g_node_find(item->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
879 paths[0] = g_strdup(item->path);
881 g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
882 mh_rename_folder_func, paths);
889 gint mh_remove_folder(Folder *folder, FolderItem *item)
893 g_return_val_if_fail(folder != NULL, -1);
894 g_return_val_if_fail(item != NULL, -1);
895 g_return_val_if_fail(item->path != NULL, -1);
897 path = folder_item_get_path(item);
898 if (remove_dir_recursive(path) < 0) {
899 g_warning("can't remove directory `%s'\n", path);
905 folder_item_remove(item);
910 static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
916 GSList *newlist = NULL;
922 g_return_val_if_fail(item != NULL, NULL);
924 path = folder_item_get_path(item);
925 g_return_val_if_fail(path != NULL, NULL);
926 if (change_dir(path) < 0) {
932 if ((dp = opendir(".")) == NULL) {
933 FILE_OP_ERROR(item->path, "opendir");
937 debug_print(_("\tSearching uncached messages... "));
940 while ((d = readdir(dp)) != NULL) {
941 if ((num = to_number(d->d_name)) < 0) continue;
942 if (stat(d->d_name, &s) < 0) {
943 FILE_OP_ERROR(d->d_name, "stat");
946 if (!S_ISREG(s.st_mode)) continue;
948 msginfo = g_hash_table_lookup
949 (msg_table, GUINT_TO_POINTER(num));
952 /* not found in the cache (uncached message) */
953 msginfo = mh_parse_msg(d->d_name, item);
954 if (!msginfo) continue;
958 g_slist_append(NULL, msginfo);
960 last = g_slist_append(last, msginfo);
967 /* discard all previous cache */
968 while ((d = readdir(dp)) != NULL) {
969 if (to_number(d->d_name) < 0) continue;
970 if (stat(d->d_name, &s) < 0) {
971 FILE_OP_ERROR(d->d_name, "stat");
974 if (!S_ISREG(s.st_mode)) continue;
976 msginfo = mh_parse_msg(d->d_name, item);
977 if (!msginfo) continue;
980 last = newlist = g_slist_append(NULL, msginfo);
982 last = g_slist_append(last, msginfo);
992 debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
994 debug_print(_("done.\n"));
996 /* sort new messages in numerical order */
998 debug_print(_("\tSorting uncached messages in numerical order... "));
999 newlist = g_slist_sort
1000 (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
1001 debug_print(_("done.\n"));
1007 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
1013 flags.perm_flags = MSG_NEW|MSG_UNREAD;
1014 flags.tmp_flags = 0;
1016 g_return_val_if_fail(item != NULL, NULL);
1017 g_return_val_if_fail(file != NULL, NULL);
1019 if (item->stype == F_QUEUE) {
1020 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
1021 } else if (item->stype == F_DRAFT) {
1022 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
1025 msginfo = procheader_parse(file, flags, FALSE, FALSE);
1026 if (!msginfo) return NULL;
1028 msginfo->msgnum = atoi(file);
1029 msginfo->folder = item;
1031 if (stat(file, &s) < 0) {
1032 FILE_OP_ERROR(file, "stat");
1036 msginfo->size = s.st_size;
1037 msginfo->mtime = s.st_mtime;
1043 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
1048 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
1049 result = is_dir_exist(entry);
1056 * check whether PATH is a Maildir style mailbox.
1057 * This is the case if the 3 subdir: new, cur, tmp are existing.
1058 * This functon assumes that entry is an directory
1060 static gboolean mh_is_maildir(const gchar *path)
1062 return mh_is_maildir_one(path, "new") &&
1063 mh_is_maildir_one(path, "cur") &&
1064 mh_is_maildir_one(path, "tmp");
1067 static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
1075 g_return_if_fail(item != NULL);
1076 g_return_if_fail(item->folder != NULL);
1078 dp = opendir(item->path ? item->path : ".");
1080 FILE_OP_ERROR(item->path ? item->path : ".", "opendir");
1084 debug_print("scanning %s ...\n",
1085 item->path ? item->path
1086 : LOCAL_FOLDER(item->folder)->rootpath);
1087 if (item->folder->ui_func)
1088 item->folder->ui_func(item->folder, item,
1089 item->folder->ui_func_data);
1091 while ((d = readdir(dp)) != NULL) {
1092 if (d->d_name[0] == '.') continue;
1095 entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
1098 entry = g_strdup(d->d_name);
1100 if (stat(entry, &s) < 0) {
1101 FILE_OP_ERROR(entry, "stat");
1106 if (S_ISDIR(s.st_mode)) {
1107 FolderItem *new_item;
1109 if (mh_is_maildir(entry)) {
1114 new_item = folder_item_new(d->d_name, entry);
1115 folder_item_append(item, new_item);
1117 if (!strcmp(d->d_name, "inbox")) {
1118 new_item->stype = F_INBOX;
1119 item->folder->inbox = new_item;
1120 } else if (!strcmp(d->d_name, "outbox")) {
1121 new_item->stype = F_OUTBOX;
1122 item->folder->outbox = new_item;
1123 } else if (!strcmp(d->d_name, "draft")) {
1124 new_item->stype = F_DRAFT;
1125 item->folder->draft = new_item;
1126 } else if (!strcmp(d->d_name, "queue")) {
1127 new_item->stype = F_QUEUE;
1128 item->folder->queue = new_item;
1129 } else if (!strcmp(d->d_name, "trash")) {
1130 new_item->stype = F_TRASH;
1131 item->folder->trash = new_item;
1134 folder_item_restore_persist_prefs(new_item, pptable);
1135 mh_scan_tree_recursive(new_item, pptable);
1136 } else if (to_number(d->d_name) != -1) n_msg++;
1144 gint new, unread, total;
1146 procmsg_get_mark_sum(item->path, &new, &unread, &total);
1147 if (n_msg > total) {
1148 new += n_msg - total;
1149 unread += n_msg - total;
1152 item->unread = unread;
1153 item->total = n_msg;
1157 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1159 FolderItem *item = node->data;
1160 gchar **paths = data;
1161 const gchar *oldpath = paths[0];
1162 const gchar *newpath = paths[1];
1164 gchar *new_itempath;
1167 oldpathlen = strlen(oldpath);
1168 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1169 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1173 base = item->path + oldpathlen;
1174 while (*base == G_DIR_SEPARATOR) base++;
1176 new_itempath = g_strdup(newpath);
1178 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1181 item->path = new_itempath;