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 (mkdir(dir, S_IRWXU) < 0) { \
797 FILE_OP_ERROR(dir, "mkdir"); \
800 if (chmod(dir, S_IRWXU) < 0) \
801 FILE_OP_ERROR(dir, "chmod"); \
805 gint mh_create_tree(Folder *folder)
809 g_return_val_if_fail(folder != NULL, -1);
811 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
812 rootpath = LOCAL_FOLDER(folder)->rootpath;
813 MAKE_DIR_IF_NOT_EXIST(rootpath);
814 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
815 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
816 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
817 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
818 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
819 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
824 #undef MAKE_DIR_IF_NOT_EXIST
826 FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
831 FolderItem *new_item;
833 g_return_val_if_fail(folder != NULL, NULL);
834 g_return_val_if_fail(parent != NULL, NULL);
835 g_return_val_if_fail(name != NULL, NULL);
837 path = folder_item_get_path(parent);
838 if (!is_dir_exist(path))
841 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
844 if (mkdir(fullpath, S_IRWXU) < 0) {
845 FILE_OP_ERROR(fullpath, "mkdir");
849 if (chmod(fullpath, S_IRWXU) < 0)
850 FILE_OP_ERROR(fullpath, "chmod");
855 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
858 path = g_strdup(name);
859 new_item = folder_item_new(name, path);
860 folder_item_append(parent, new_item);
866 gint mh_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
874 g_return_val_if_fail(folder != NULL, -1);
875 g_return_val_if_fail(item != NULL, -1);
876 g_return_val_if_fail(item->path != NULL, -1);
877 g_return_val_if_fail(name != NULL, -1);
879 oldpath = folder_item_get_path(item);
880 if (!is_dir_exist(oldpath))
881 make_dir_hier(oldpath);
883 dirname = g_dirname(oldpath);
884 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
887 if (rename(oldpath, newpath) < 0) {
888 FILE_OP_ERROR(oldpath, "rename");
897 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
898 dirname = g_dirname(item->path);
899 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
902 newpath = g_strdup(name);
905 item->name = g_strdup(name);
907 node = g_node_find(item->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
909 paths[0] = g_strdup(item->path);
911 g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
912 mh_rename_folder_func, paths);
919 gint mh_remove_folder(Folder *folder, FolderItem *item)
923 g_return_val_if_fail(folder != NULL, -1);
924 g_return_val_if_fail(item != NULL, -1);
925 g_return_val_if_fail(item->path != NULL, -1);
927 path = folder_item_get_path(item);
928 if (remove_dir_recursive(path) < 0) {
929 g_warning("can't remove directory `%s'\n", path);
935 folder_item_remove(item);
940 static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
946 GSList *newlist = NULL;
952 g_return_val_if_fail(item != NULL, NULL);
954 path = folder_item_get_path(item);
955 g_return_val_if_fail(path != NULL, NULL);
956 if (change_dir(path) < 0) {
962 if ((dp = opendir(".")) == NULL) {
963 FILE_OP_ERROR(item->path, "opendir");
967 debug_print(_("\tSearching uncached messages... "));
970 while ((d = readdir(dp)) != NULL) {
971 if ((num = to_number(d->d_name)) < 0) continue;
972 if (stat(d->d_name, &s) < 0) {
973 FILE_OP_ERROR(d->d_name, "stat");
976 if (!S_ISREG(s.st_mode)) continue;
978 msginfo = g_hash_table_lookup
979 (msg_table, GUINT_TO_POINTER(num));
982 /* not found in the cache (uncached message) */
983 msginfo = mh_parse_msg(d->d_name, item);
984 if (!msginfo) continue;
988 g_slist_append(NULL, msginfo);
990 last = g_slist_append(last, msginfo);
997 /* discard all previous cache */
998 while ((d = readdir(dp)) != NULL) {
999 if (to_number(d->d_name) < 0) continue;
1000 if (stat(d->d_name, &s) < 0) {
1001 FILE_OP_ERROR(d->d_name, "stat");
1004 if (!S_ISREG(s.st_mode)) continue;
1006 msginfo = mh_parse_msg(d->d_name, item);
1007 if (!msginfo) continue;
1010 last = newlist = g_slist_append(NULL, msginfo);
1012 last = g_slist_append(last, msginfo);
1022 debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
1024 debug_print(_("done.\n"));
1026 /* sort new messages in numerical order */
1028 debug_print(_("\tSorting uncached messages in numerical order... "));
1029 newlist = g_slist_sort
1030 (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
1031 debug_print(_("done.\n"));
1037 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
1043 flags.perm_flags = MSG_NEW|MSG_UNREAD;
1044 flags.tmp_flags = 0;
1046 g_return_val_if_fail(item != NULL, NULL);
1047 g_return_val_if_fail(file != NULL, NULL);
1049 if (item->stype == F_QUEUE) {
1050 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
1051 } else if (item->stype == F_DRAFT) {
1052 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
1055 msginfo = procheader_parse(file, flags, FALSE, FALSE);
1056 if (!msginfo) return NULL;
1058 msginfo->msgnum = atoi(file);
1059 msginfo->folder = item;
1061 if (stat(file, &s) < 0) {
1062 FILE_OP_ERROR(file, "stat");
1066 msginfo->size = s.st_size;
1067 msginfo->mtime = s.st_mtime;
1073 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
1078 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
1079 result = is_dir_exist(entry);
1086 * check whether PATH is a Maildir style mailbox.
1087 * This is the case if the 3 subdir: new, cur, tmp are existing.
1088 * This functon assumes that entry is an directory
1090 static gboolean mh_is_maildir(const gchar *path)
1092 return mh_is_maildir_one(path, "new") &&
1093 mh_is_maildir_one(path, "cur") &&
1094 mh_is_maildir_one(path, "tmp");
1097 static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
1105 g_return_if_fail(item != NULL);
1106 g_return_if_fail(item->folder != NULL);
1108 dp = opendir(item->path ? item->path : ".");
1110 FILE_OP_ERROR(item->path ? item->path : ".", "opendir");
1114 debug_print("scanning %s ...\n",
1115 item->path ? item->path
1116 : LOCAL_FOLDER(item->folder)->rootpath);
1117 if (item->folder->ui_func)
1118 item->folder->ui_func(item->folder, item,
1119 item->folder->ui_func_data);
1121 while ((d = readdir(dp)) != NULL) {
1122 if (d->d_name[0] == '.') continue;
1125 entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
1128 entry = g_strdup(d->d_name);
1130 if (stat(entry, &s) < 0) {
1131 FILE_OP_ERROR(entry, "stat");
1136 if (S_ISDIR(s.st_mode)) {
1137 FolderItem *new_item;
1139 if (mh_is_maildir(entry)) {
1144 new_item = folder_item_new(d->d_name, entry);
1145 folder_item_append(item, new_item);
1147 if (!strcmp(d->d_name, INBOX_DIR)) {
1148 new_item->stype = F_INBOX;
1149 item->folder->inbox = new_item;
1150 } else if (!strcmp(d->d_name, OUTBOX_DIR)) {
1151 new_item->stype = F_OUTBOX;
1152 item->folder->outbox = new_item;
1153 } else if (!strcmp(d->d_name, DRAFT_DIR)) {
1154 new_item->stype = F_DRAFT;
1155 item->folder->draft = new_item;
1156 } else if (!strcmp(d->d_name, QUEUE_DIR)) {
1157 new_item->stype = F_QUEUE;
1158 item->folder->queue = new_item;
1159 } else if (!strcmp(d->d_name, TRASH_DIR)) {
1160 new_item->stype = F_TRASH;
1161 item->folder->trash = new_item;
1164 folder_item_restore_persist_prefs(new_item, pptable);
1165 mh_scan_tree_recursive(new_item, pptable);
1166 } else if (to_number(d->d_name) != -1) n_msg++;
1174 gint new, unread, total, min, max;
1176 procmsg_get_mark_sum(item->path, &new, &unread, &total,
1178 if (n_msg > total) {
1179 new += n_msg - total;
1180 unread += n_msg - total;
1183 item->unread = unread;
1184 item->total = n_msg;
1188 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1190 FolderItem *item = node->data;
1191 gchar **paths = data;
1192 const gchar *oldpath = paths[0];
1193 const gchar *newpath = paths[1];
1195 gchar *new_itempath;
1198 oldpathlen = strlen(oldpath);
1199 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1200 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1204 base = item->path + oldpathlen;
1205 while (*base == G_DIR_SEPARATOR) base++;
1207 new_itempath = g_strdup(newpath);
1209 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1212 item->path = new_itempath;