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 gchar *mh_get_new_msg_filename (FolderItem *dest);
52 static GSList *mh_get_uncached_msgs (GHashTable *msg_table,
54 static MsgInfo *mh_parse_msg (const gchar *file,
56 static void mh_scan_tree_recursive (FolderItem *item,
59 static gboolean mh_rename_folder_func (GNode *node,
63 Folder *mh_folder_new(const gchar *name, const gchar *path)
67 folder = (Folder *)g_new0(MHFolder, 1);
68 mh_folder_init(folder, name, path);
73 void mh_folder_destroy(MHFolder *folder)
75 folder_local_folder_destroy(LOCAL_FOLDER(folder));
78 static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
80 folder_local_folder_init(folder, name, path);
84 folder->get_msg_list = mh_get_msg_list;
85 folder->fetch_msg = mh_fetch_msg;
86 folder->add_msg = mh_add_msg;
87 folder->move_msg = mh_move_msg;
88 folder->move_msgs_with_dest = mh_move_msgs_with_dest;
89 folder->copy_msg = mh_copy_msg;
90 folder->copy_msgs_with_dest = mh_copy_msgs_with_dest;
91 folder->remove_msg = mh_remove_msg;
92 folder->remove_all_msg = mh_remove_all_msg;
93 folder->is_msg_changed = mh_is_msg_changed;
94 folder->scan = mh_scan_folder;
95 folder->scan_tree = mh_scan_tree;
96 folder->create_tree = mh_create_tree;
97 folder->create_folder = mh_create_folder;
98 folder->rename_folder = mh_rename_folder;
99 folder->remove_folder = mh_remove_folder;
102 GSList *mh_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
105 GHashTable *msg_table;
108 gboolean scan_new = TRUE;
110 struct timeval tv_before, tv_after, tv_result;
112 gettimeofday(&tv_before, NULL);
115 g_return_val_if_fail(item != NULL, NULL);
117 path = folder_item_get_path(item);
118 if (stat(path, &s) < 0) {
119 FILE_OP_ERROR(path, "stat");
123 mtime = MAX(s.st_mtime, s.st_ctime);
124 if (item->mtime == mtime) {
125 debug_print("Folder is not modified.\n");
132 if (use_cache && !scan_new) {
133 mlist = procmsg_read_cache(item, FALSE);
135 mlist = mh_get_uncached_msgs(NULL, item);
136 } else if (use_cache) {
139 mlist = procmsg_read_cache(item, TRUE);
140 msg_table = procmsg_msg_hash_table_create(mlist);
142 newlist = mh_get_uncached_msgs(msg_table, item);
144 g_hash_table_destroy(msg_table);
146 mlist = g_slist_concat(mlist, newlist);
148 mlist = mh_get_uncached_msgs(NULL, item);
150 procmsg_set_flags(mlist, item);
153 gettimeofday(&tv_after, NULL);
155 timersub(&tv_after, &tv_before, &tv_result);
156 g_print("mh_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
157 item->path, tv_result.tv_sec, tv_result.tv_usec);
163 gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
168 g_return_val_if_fail(item != NULL, NULL);
169 g_return_val_if_fail(num > 0 && num <= item->last_num, NULL);
171 path = folder_item_get_path(item);
172 file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
174 if (!is_file_exist(file)) {
182 static gchar *mh_get_new_msg_filename(FolderItem *dest)
187 destpath = folder_item_get_path(dest);
188 g_return_val_if_fail(destpath != NULL, NULL);
190 if (!is_dir_exist(destpath))
191 make_dir_hier(destpath);
194 destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
196 if (is_file_entry_exist(destfile)) {
208 #define SET_DEST_MSG_FLAGS(fp, dest, msginfo) \
210 MsgInfo newmsginfo; \
212 newmsginfo.msgnum = dest->last_num; \
213 newmsginfo.flags = msginfo->flags; \
214 if (dest->stype == F_OUTBOX || \
215 dest->stype == F_QUEUE || \
216 dest->stype == F_DRAFT || \
217 dest->stype == F_TRASH) \
218 MSG_UNSET_PERM_FLAGS(newmsginfo.flags, \
219 MSG_NEW|MSG_UNREAD|MSG_DELETED); \
221 procmsg_write_flags(&newmsginfo, fp); \
224 gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
225 gboolean remove_source)
229 g_return_val_if_fail(dest != NULL, -1);
230 g_return_val_if_fail(file != NULL, -1);
232 if (dest->last_num < 0) {
233 mh_scan_folder(folder, dest);
234 if (dest->last_num < 0) return -1;
237 destfile = mh_get_new_msg_filename(dest);
238 g_return_val_if_fail(destfile != NULL, -1);
240 if (link(file, destfile) < 0) {
241 if (copy_file(file, destfile) < 0) {
242 g_warning(_("can't copy message %s to %s\n"),
250 if (unlink(file) < 0)
251 FILE_OP_ERROR(file, "unlink");
256 return dest->last_num;
259 static gint mh_do_move(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
266 PrefsFolderItem *prefs;
268 g_return_val_if_fail(dest != NULL, -1);
269 g_return_val_if_fail(msginfo != NULL, -1);
271 if (msginfo->folder == dest) {
272 g_warning(_("the src folder is identical to the dest.\n"));
276 if (dest->last_num < 0) {
277 mh_scan_folder(folder, dest);
278 if (dest->last_num < 0) return -1;
283 destfile = mh_get_new_msg_filename(dest);
284 g_return_val_if_fail(destfile != NULL, -1);
286 debug_print(_("Moving message %s%c%d to %s ...\n"),
287 msginfo->folder->path, G_DIR_SEPARATOR,
288 msginfo->msgnum, dest->path);
289 srcfile = procmsg_get_message_file(msginfo);
291 destfile = mh_get_new_msg_filename(dest);
292 if(!destfile) return -1;
294 srcfile = procmsg_get_message_file(msginfo);
296 if (move_file(srcfile, destfile) < 0) {
302 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
303 if (chmod(destfile, prefs->folder_chmod) < 0)
304 FILE_OP_ERROR(destfile, "chmod");
307 filemode = prefs->folder_chmod;
308 if (filemode & S_IRGRP) filemode |= S_IWGRP;
309 if (filemode & S_IROTH) filemode |= S_IWOTH;
316 destdir = folder_item_get_path(dest);
317 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
318 g_warning(_("Can't open mark file.\n"));
320 SET_DEST_MSG_FLAGS(fp, dest, msginfo);
323 fchmod(fileno(fp), filemode);
327 markfile = folder_item_get_mark_file(dest);
329 chmod(markfile, filemode);
339 return dest->last_num;
342 gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
347 g_return_val_if_fail(folder != NULL, -1);
348 g_return_val_if_fail(dest != NULL, -1);
349 g_return_val_if_fail(msginfo != NULL, -1);
350 g_return_val_if_fail(msginfo->folder != NULL, -1);
352 if (folder == msginfo->folder->folder)
353 return mh_do_move(folder, dest, msginfo);
355 srcfile = procmsg_get_message_file(msginfo);
356 if (!srcfile) return -1;
358 ret = mh_add_msg(folder, dest, srcfile, FALSE);
365 destdir = folder_item_get_path(dest);
366 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
367 g_warning(_("Can't open mark file.\n"));
369 SET_DEST_MSG_FLAGS(fp, dest, msginfo);
374 ret = folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
380 static gint mh_do_move_msgs_with_dest(Folder *folder, FolderItem *dest,
389 PrefsFolderItem *prefs;
391 g_return_val_if_fail(dest != NULL, -1);
392 g_return_val_if_fail(msglist != NULL, -1);
394 if (dest->last_num < 0) {
395 mh_scan_folder(folder, dest);
396 if (dest->last_num < 0) return -1;
401 destdir = folder_item_get_path(dest);
402 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
403 g_warning(_("Can't open mark file.\n"));
405 for (cur = msglist; cur != NULL; cur = cur->next) {
406 msginfo = (MsgInfo *)cur->data;
408 if (msginfo->folder == dest) {
409 g_warning(_("the src folder is identical to the dest.\n"));
412 debug_print(_("Moving message %s%c%d to %s ...\n"),
413 msginfo->folder->path, G_DIR_SEPARATOR,
414 msginfo->msgnum, dest->path);
416 destfile = mh_get_new_msg_filename(dest);
417 if (!destfile) break;
418 srcfile = procmsg_get_message_file(msginfo);
419 destfile = mh_get_new_msg_filename(dest);
420 if(!destfile) return -1;
422 if (move_file(srcfile, destfile) < 0) {
433 SET_DEST_MSG_FLAGS(fp, dest, msginfo);
440 return dest->last_num;
443 gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
449 msginfo = (MsgInfo *)msglist->data;
450 if (folder == msginfo->folder->folder)
451 return mh_do_move_msgs_with_dest(folder, dest, msglist);
453 for (cur = msglist; cur != NULL; cur = cur->next) {
454 msginfo = (MsgInfo *)cur->data;
455 ret = mh_move_msg(folder, dest, msginfo);
456 if (ret == -1) break;
462 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
469 PrefsFolderItem *prefs;
471 g_return_val_if_fail(dest != NULL, -1);
472 g_return_val_if_fail(msginfo != NULL, -1);
474 if (msginfo->folder == dest) {
475 g_warning(_("the src folder is identical to the dest.\n"));
479 if (dest->last_num < 0) {
480 mh_scan_folder(folder, dest);
481 if (dest->last_num < 0) return -1;
486 destfile = mh_get_new_msg_filename(dest);
487 g_return_val_if_fail(destfile != NULL, -1);
489 debug_print(_("Copying message %s%c%d to %s ...\n"),
490 msginfo->folder->path, G_DIR_SEPARATOR,
491 msginfo->msgnum, dest->path);
493 srcfile = procmsg_get_message_file(msginfo);
495 if (copy_file(srcfile, destfile) < 0) {
496 FILE_OP_ERROR(srcfile, "copy");
502 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
503 if (chmod(destfile, prefs->folder_chmod) < 0)
504 FILE_OP_ERROR(destfile, "chmod");
507 filemode = prefs->folder_chmod;
508 if (filemode & S_IRGRP) filemode |= S_IWGRP;
509 if (filemode & S_IROTH) filemode |= S_IWOTH;
516 destdir = folder_item_get_path(dest);
517 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
518 g_warning(_("Can't open mark file.\n"));
520 SET_DEST_MSG_FLAGS(fp, dest, msginfo);
524 fchmod(fileno(fp), filemode);
528 markfile = folder_item_get_mark_file(dest);
530 chmod(markfile, filemode);
540 return dest->last_num;
544 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
552 src_folder = msginfo->folder->folder;
554 g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
556 filename = src_folder->fetch_msg(src_folder,
559 if (filename == NULL)
562 num = folder->add_msg(folder, dest, filename, FALSE);
564 destdir = folder_item_get_path(dest);
569 newmsginfo.msgnum = dest->last_num;
570 newmsginfo.flags = msginfo->flags;
571 if (dest->stype == F_OUTBOX ||
572 dest->stype == F_QUEUE ||
573 dest->stype == F_DRAFT ||
574 dest->stype == F_TRASH)
575 MSG_UNSET_FLAGS(newmsginfo.flags,
576 MSG_NEW|MSG_UNREAD|MSG_DELETED);
578 procmsg_write_flags(&newmsginfo, fp);
586 gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
595 g_return_val_if_fail(dest != NULL, -1);
596 g_return_val_if_fail(msglist != NULL, -1);
598 if (dest->last_num < 0) {
599 mh_scan_folder(folder, dest);
600 if (dest->last_num < 0) return -1;
603 destdir = folder_item_get_path(dest);
604 if (!is_dir_exist(destdir))
605 make_dir_hier(destdir);
607 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
608 g_warning(_("Can't open mark file.\n"));
610 for (cur = msglist; cur != NULL; cur = cur->next) {
611 msginfo = (MsgInfo *)cur->data;
613 if (msginfo->folder == dest) {
614 g_warning(_("the src folder is identical to the dest.\n"));
617 debug_print(_("Copying message %s%c%d to %s ...\n"),
618 msginfo->folder->path, G_DIR_SEPARATOR,
619 msginfo->msgnum, dest->path);
621 destfile = mh_get_new_msg_filename(dest);
622 if (!destfile) break;
623 srcfile = procmsg_get_message_file(msginfo);
625 if (copy_file(srcfile, destfile) < 0) {
626 FILE_OP_ERROR(srcfile, "copy");
637 SET_DEST_MSG_FLAGS(fp, dest, msginfo);
644 return dest->last_num;
647 gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
651 g_return_val_if_fail(item != NULL, -1);
653 file = mh_fetch_msg(folder, item, num);
654 g_return_val_if_fail(file != NULL, -1);
656 if (unlink(file) < 0) {
657 FILE_OP_ERROR(file, "unlink");
666 gint mh_remove_all_msg(Folder *folder, FolderItem *item)
671 g_return_val_if_fail(item != NULL, -1);
673 path = folder_item_get_path(item);
674 g_return_val_if_fail(path != NULL, -1);
675 val = remove_all_numbered_files(path);
681 gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, MsgInfo *msginfo)
685 if (stat(itos(msginfo->msgnum), &s) < 0 ||
686 msginfo->size != s.st_size ||
687 msginfo->mtime != s.st_mtime)
693 gint mh_scan_folder(Folder *folder, FolderItem *item)
703 g_return_val_if_fail(item != NULL, -1);
705 debug_print("mh_scan_folder(): Scanning %s ...\n", item->path);
707 path = folder_item_get_path(item);
708 g_return_val_if_fail(path != NULL, -1);
709 if (change_dir(path) < 0) {
715 if ((dp = opendir(".")) == NULL) {
716 FILE_OP_ERROR(item->path, "opendir");
721 folder->ui_func(folder, item, folder->ui_func_data);
723 while ((d = readdir(dp)) != NULL) {
724 if ((num = to_number(d->d_name)) >= 0 &&
725 stat(d->d_name, &s) == 0 &&
726 S_ISREG(s.st_mode)) {
736 item->new = item->unread = item->total = 0;
738 gint new, unread, total, min, max;
740 procmsg_get_mark_sum(".", &new, &unread, &total, &min, &max, 0);
742 new += n_msg - total;
743 unread += n_msg - total;
746 item->unread = unread;
750 debug_print(_("Last number in dir %s = %d\n"), item->path, max);
751 item->last_num = max;
756 void mh_scan_tree(Folder *folder)
762 g_return_if_fail(folder != NULL);
764 pptable = folder_persist_prefs_new(folder);
766 prefs_scoring_clear();
767 prefs_filtering_clear();
768 folder_tree_destroy(folder);
769 item = folder_item_new(folder->name, NULL);
770 item->folder = folder;
771 folder->node = g_node_new(item);
773 rootpath = folder_item_get_path(item);
774 if (change_dir(rootpath) < 0) {
780 mh_create_tree(folder);
781 mh_scan_tree_recursive(item, pptable);
783 folder_persist_prefs_free(pptable);
785 prefs_matcher_read_config();
788 #define MAKE_DIR_IF_NOT_EXIST(dir) \
790 if (!is_dir_exist(dir)) { \
791 if (is_file_exist(dir)) { \
792 g_warning(_("File `%s' already exists.\n" \
793 "Can't create folder."), dir); \
796 if (make_dir(dir) < 0) \
801 gint mh_create_tree(Folder *folder)
805 g_return_val_if_fail(folder != NULL, -1);
807 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
808 rootpath = LOCAL_FOLDER(folder)->rootpath;
809 MAKE_DIR_IF_NOT_EXIST(rootpath);
810 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
811 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
812 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
813 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
814 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
815 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
820 #undef MAKE_DIR_IF_NOT_EXIST
822 FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
827 FolderItem *new_item;
829 g_return_val_if_fail(folder != NULL, NULL);
830 g_return_val_if_fail(parent != NULL, NULL);
831 g_return_val_if_fail(name != NULL, NULL);
833 path = folder_item_get_path(parent);
834 if (!is_dir_exist(path))
837 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
840 if (make_dir(fullpath) < 0) {
848 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
851 path = g_strdup(name);
852 new_item = folder_item_new(name, path);
853 folder_item_append(parent, new_item);
859 gint mh_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
867 g_return_val_if_fail(folder != NULL, -1);
868 g_return_val_if_fail(item != NULL, -1);
869 g_return_val_if_fail(item->path != NULL, -1);
870 g_return_val_if_fail(name != NULL, -1);
872 oldpath = folder_item_get_path(item);
873 if (!is_dir_exist(oldpath))
874 make_dir_hier(oldpath);
876 dirname = g_dirname(oldpath);
877 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
880 if (rename(oldpath, newpath) < 0) {
881 FILE_OP_ERROR(oldpath, "rename");
890 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
891 dirname = g_dirname(item->path);
892 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
895 newpath = g_strdup(name);
898 item->name = g_strdup(name);
900 node = g_node_find(item->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
902 paths[0] = g_strdup(item->path);
904 g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
905 mh_rename_folder_func, paths);
912 gint mh_remove_folder(Folder *folder, FolderItem *item)
916 g_return_val_if_fail(folder != NULL, -1);
917 g_return_val_if_fail(item != NULL, -1);
918 g_return_val_if_fail(item->path != NULL, -1);
920 path = folder_item_get_path(item);
921 if (remove_dir_recursive(path) < 0) {
922 g_warning("can't remove directory `%s'\n", path);
928 folder_item_remove(item);
933 static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
939 GSList *newlist = NULL;
945 g_return_val_if_fail(item != NULL, NULL);
947 path = folder_item_get_path(item);
948 g_return_val_if_fail(path != NULL, NULL);
949 if (change_dir(path) < 0) {
955 if ((dp = opendir(".")) == NULL) {
956 FILE_OP_ERROR(item->path, "opendir");
960 debug_print(_("\tSearching uncached messages... "));
963 while ((d = readdir(dp)) != NULL) {
964 if ((num = to_number(d->d_name)) < 0) continue;
965 if (stat(d->d_name, &s) < 0) {
966 FILE_OP_ERROR(d->d_name, "stat");
969 if (!S_ISREG(s.st_mode)) continue;
971 msginfo = g_hash_table_lookup
972 (msg_table, GUINT_TO_POINTER(num));
975 /* not found in the cache (uncached message) */
976 msginfo = mh_parse_msg(d->d_name, item);
977 if (!msginfo) continue;
981 g_slist_append(NULL, msginfo);
983 last = g_slist_append(last, msginfo);
990 /* discard all previous cache */
991 while ((d = readdir(dp)) != NULL) {
992 if (to_number(d->d_name) < 0) continue;
993 if (stat(d->d_name, &s) < 0) {
994 FILE_OP_ERROR(d->d_name, "stat");
997 if (!S_ISREG(s.st_mode)) continue;
999 msginfo = mh_parse_msg(d->d_name, item);
1000 if (!msginfo) continue;
1003 last = newlist = g_slist_append(NULL, msginfo);
1005 last = g_slist_append(last, msginfo);
1015 debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
1017 debug_print(_("done.\n"));
1019 /* sort new messages in numerical order */
1021 debug_print(_("\tSorting uncached messages in numerical order... "));
1022 newlist = g_slist_sort
1023 (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
1024 debug_print(_("done.\n"));
1030 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
1036 flags.perm_flags = MSG_NEW|MSG_UNREAD;
1037 flags.tmp_flags = 0;
1039 g_return_val_if_fail(item != NULL, NULL);
1040 g_return_val_if_fail(file != NULL, NULL);
1042 if (item->stype == F_QUEUE) {
1043 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
1044 } else if (item->stype == F_DRAFT) {
1045 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
1048 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
1049 if (!msginfo) return NULL;
1051 msginfo->msgnum = atoi(file);
1052 msginfo->folder = item;
1054 if (stat(file, &s) < 0) {
1055 FILE_OP_ERROR(file, "stat");
1059 msginfo->size = s.st_size;
1060 msginfo->mtime = s.st_mtime;
1066 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
1071 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
1072 result = is_dir_exist(entry);
1079 * check whether PATH is a Maildir style mailbox.
1080 * This is the case if the 3 subdir: new, cur, tmp are existing.
1081 * This functon assumes that entry is an directory
1083 static gboolean mh_is_maildir(const gchar *path)
1085 return mh_is_maildir_one(path, "new") &&
1086 mh_is_maildir_one(path, "cur") &&
1087 mh_is_maildir_one(path, "tmp");
1090 static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
1098 g_return_if_fail(item != NULL);
1099 g_return_if_fail(item->folder != NULL);
1101 dp = opendir(item->path ? item->path : ".");
1103 FILE_OP_ERROR(item->path ? item->path : ".", "opendir");
1107 debug_print("scanning %s ...\n",
1108 item->path ? item->path
1109 : LOCAL_FOLDER(item->folder)->rootpath);
1110 if (item->folder->ui_func)
1111 item->folder->ui_func(item->folder, item,
1112 item->folder->ui_func_data);
1114 while ((d = readdir(dp)) != NULL) {
1115 if (d->d_name[0] == '.') continue;
1118 entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
1121 entry = g_strdup(d->d_name);
1123 if (stat(entry, &s) < 0) {
1124 FILE_OP_ERROR(entry, "stat");
1129 if (S_ISDIR(s.st_mode)) {
1130 FolderItem *new_item;
1132 if (mh_is_maildir(entry)) {
1137 new_item = folder_item_new(d->d_name, entry);
1138 folder_item_append(item, new_item);
1140 if (!strcmp(d->d_name, INBOX_DIR)) {
1141 new_item->stype = F_INBOX;
1142 item->folder->inbox = new_item;
1143 } else if (!strcmp(d->d_name, OUTBOX_DIR)) {
1144 new_item->stype = F_OUTBOX;
1145 item->folder->outbox = new_item;
1146 } else if (!strcmp(d->d_name, DRAFT_DIR)) {
1147 new_item->stype = F_DRAFT;
1148 item->folder->draft = new_item;
1149 } else if (!strcmp(d->d_name, QUEUE_DIR)) {
1150 new_item->stype = F_QUEUE;
1151 item->folder->queue = new_item;
1152 } else if (!strcmp(d->d_name, TRASH_DIR)) {
1153 new_item->stype = F_TRASH;
1154 item->folder->trash = new_item;
1157 folder_item_restore_persist_prefs(new_item, pptable);
1158 mh_scan_tree_recursive(new_item, pptable);
1159 } else if (to_number(d->d_name) != -1) n_msg++;
1167 gint new, unread, total, min, max;
1169 procmsg_get_mark_sum(item->path, &new, &unread, &total,
1171 if (n_msg > total) {
1172 new += n_msg - total;
1173 unread += n_msg - total;
1176 item->unread = unread;
1177 item->total = n_msg;
1181 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1183 FolderItem *item = node->data;
1184 gchar **paths = data;
1185 const gchar *oldpath = paths[0];
1186 const gchar *newpath = paths[1];
1188 gchar *new_itempath;
1191 oldpathlen = strlen(oldpath);
1192 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1193 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1197 base = item->path + oldpathlen;
1198 while (*base == G_DIR_SEPARATOR) base++;
1200 new_itempath = g_strdup(newpath);
1202 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1205 item->path = new_itempath;