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");
121 mtime = MAX(s.st_mtime, s.st_ctime);
122 if (item->mtime == mtime) {
123 debug_print("Folder is not modified.\n");
130 if (use_cache && !scan_new) {
131 mlist = procmsg_read_cache(item, FALSE);
133 mlist = mh_get_uncached_msgs(NULL, item);
134 } else if (use_cache) {
137 mlist = procmsg_read_cache(item, TRUE);
138 msg_table = procmsg_msg_hash_table_create(mlist);
140 newlist = mh_get_uncached_msgs(msg_table, item);
142 g_hash_table_destroy(msg_table);
144 mlist = g_slist_concat(mlist, newlist);
146 mlist = mh_get_uncached_msgs(NULL, item);
148 procmsg_set_flags(mlist, item);
151 gettimeofday(&tv_after, NULL);
153 timersub(&tv_after, &tv_before, &tv_result);
154 g_print("mh_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
155 item->path, tv_result.tv_sec, tv_result.tv_usec);
161 gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
166 g_return_val_if_fail(item != NULL, NULL);
167 g_return_val_if_fail(num > 0 && num <= item->last_num, NULL);
169 path = folder_item_get_path(item);
170 file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
172 if (!is_file_exist(file)) {
180 gchar *mh_get_newmsg_filename(FolderItem *dest)
184 gboolean found = FALSE;
186 destpath = folder_item_get_path(dest);
187 g_return_val_if_fail(destpath != NULL, NULL);
188 if (!is_dir_exist(destpath))
189 make_dir_hier(destpath);
192 destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
194 if(is_file_exist(destfile)) {
206 gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
207 gboolean remove_source)
211 g_return_val_if_fail(dest != NULL, -1);
212 g_return_val_if_fail(file != NULL, -1);
214 if (dest->last_num < 0) {
215 mh_scan_folder(folder, dest);
216 if (dest->last_num < 0) return -1;
219 destfile = mh_get_newmsg_filename(dest);
220 if(!destfile) return -1;
222 if (link(file, destfile) < 0) {
223 if (copy_file(file, destfile) < 0) {
224 g_warning(_("can't copy message %s to %s\n"),
232 if (unlink(file) < 0)
233 FILE_OP_ERROR(file, "unlink");
238 return dest->last_num;
241 gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
248 PrefsFolderItem *prefs;
250 g_return_val_if_fail(dest != NULL, -1);
251 g_return_val_if_fail(msginfo != NULL, -1);
253 if (msginfo->folder == dest) {
254 g_warning(_("the src folder is identical to the dest.\n"));
258 if (dest->last_num < 0) {
259 mh_scan_folder(folder, dest);
260 if (dest->last_num < 0) return -1;
265 destdir = folder_item_get_path(dest);
266 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
267 g_warning(_("Can't open mark file.\n"));
269 debug_print(_("Moving message %s%c%d to %s ...\n"),
270 msginfo->folder->path, G_DIR_SEPARATOR,
271 msginfo->msgnum, dest->path);
272 srcfile = procmsg_get_message_file_path(msginfo);
274 destfile = mh_get_newmsg_filename(dest);
275 if(!destfile) return -1;
279 if (move_file(srcfile, destfile) < 0) {
286 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
287 if (chmod(destfile, prefs->folder_chmod) < 0)
288 FILE_OP_ERROR(destfile, "chmod");
291 filemode = prefs->folder_chmod;
292 if (filemode & S_IRGRP) filemode |= S_IWGRP;
293 if (filemode & S_IROTH) filemode |= S_IWOTH;
303 newmsginfo.msgnum = dest->last_num;
304 newmsginfo.flags = msginfo->flags;
305 if (dest->stype == F_OUTBOX ||
306 dest->stype == F_QUEUE ||
307 dest->stype == F_DRAFT ||
308 dest->stype == F_TRASH)
309 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
310 MSG_NEW|MSG_UNREAD|MSG_DELETED);
312 procmsg_write_flags(&newmsginfo, fp);
316 fchmod(fileno(fp), filemode);
320 markfile = folder_item_get_mark_file(dest);
322 chmod(markfile, filemode);
331 return dest->last_num;
334 gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
342 PrefsFolderItem *prefs;
344 g_return_val_if_fail(dest != NULL, -1);
345 g_return_val_if_fail(msglist != NULL, -1);
347 if (dest->last_num < 0) {
348 mh_scan_folder(folder, dest);
349 if (dest->last_num < 0) return -1;
354 destdir = folder_item_get_path(dest);
355 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
356 g_warning(_("Can't open mark file.\n"));
358 for (cur = msglist; cur != NULL; cur = cur->next) {
359 msginfo = (MsgInfo *)cur->data;
361 if (msginfo->folder == dest) {
362 g_warning(_("the src folder is identical to the dest.\n"));
365 debug_print(_("Moving message %s%c%d to %s ...\n"),
366 msginfo->folder->path, G_DIR_SEPARATOR,
367 msginfo->msgnum, dest->path);
369 srcfile = procmsg_get_message_file_path(msginfo);
370 destfile = mh_get_newmsg_filename(dest);
371 if(!destfile) return -1;
373 if (move_file(srcfile, destfile) < 0) {
386 newmsginfo.msgnum = dest->last_num;
387 newmsginfo.flags = msginfo->flags;
388 if (dest->stype == F_OUTBOX ||
389 dest->stype == F_QUEUE ||
390 dest->stype == F_DRAFT ||
391 dest->stype == F_TRASH)
394 MSG_NEW|MSG_UNREAD|MSG_DELETED);
396 procmsg_write_flags(&newmsginfo, fp);
403 return dest->last_num;
406 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
413 PrefsFolderItem *prefs;
415 g_return_val_if_fail(dest != NULL, -1);
416 g_return_val_if_fail(msginfo != NULL, -1);
418 if (msginfo->folder == dest) {
419 g_warning(_("the src folder is identical to the dest.\n"));
423 if (dest->last_num < 0) {
424 mh_scan_folder(folder, dest);
425 if (dest->last_num < 0) return -1;
430 destdir = folder_item_get_path(dest);
431 if (!is_dir_exist(destdir))
432 make_dir_hier(destdir);
434 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
435 g_warning(_("Can't open mark file.\n"));
437 debug_print(_("Copying message %s%c%d to %s ...\n"),
438 msginfo->folder->path, G_DIR_SEPARATOR,
439 msginfo->msgnum, dest->path);
440 srcfile = procmsg_get_message_file_path(msginfo);
441 destfile = mh_get_newmsg_filename(dest);
452 if (copy_file(srcfile, destfile) < 0) {
453 FILE_OP_ERROR(srcfile, "copy");
460 if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
461 if (chmod(destfile, prefs->folder_chmod) < 0)
462 FILE_OP_ERROR(destfile, "chmod");
465 filemode = prefs->folder_chmod;
466 if (filemode & S_IRGRP) filemode |= S_IWGRP;
467 if (filemode & S_IROTH) filemode |= S_IWOTH;
477 newmsginfo.msgnum = dest->last_num;
478 newmsginfo.flags = msginfo->flags;
479 if (dest->stype == F_OUTBOX ||
480 dest->stype == F_QUEUE ||
481 dest->stype == F_DRAFT ||
482 dest->stype == F_TRASH)
483 MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
484 MSG_NEW|MSG_UNREAD|MSG_DELETED);
485 procmsg_write_flags(&newmsginfo, fp);
489 fchmod(fileno(fp), filemode);
493 markfile = folder_item_get_mark_file(dest);
495 chmod(markfile, filemode);
504 return dest->last_num;
508 gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
516 src_folder = msginfo->folder->folder;
518 g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
520 filename = src_folder->fetch_msg(src_folder,
523 if (filename == NULL)
526 num = folder->add_msg(folder, dest, filename, FALSE);
528 destdir = folder_item_get_path(dest);
529 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
530 g_warning(_("Can't open mark file.\n"));
535 newmsginfo.msgnum = dest->last_num;
536 newmsginfo.flags = msginfo->flags;
537 if (dest->stype == F_OUTBOX ||
538 dest->stype == F_QUEUE ||
539 dest->stype == F_DRAFT ||
540 dest->stype == F_TRASH)
541 MSG_UNSET_FLAGS(newmsginfo.flags,
542 MSG_NEW|MSG_UNREAD|MSG_DELETED);
544 procmsg_write_flags(&newmsginfo, fp);
552 gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
561 g_return_val_if_fail(dest != NULL, -1);
562 g_return_val_if_fail(msglist != NULL, -1);
564 if (dest->last_num < 0) {
565 mh_scan_folder(folder, dest);
566 if (dest->last_num < 0) return -1;
569 destdir = folder_item_get_path(dest);
570 if (!is_dir_exist(destdir))
571 make_dir_hier(destdir);
573 if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
574 g_warning(_("Can't open mark file.\n"));
576 for (cur = msglist; cur != NULL; cur = cur->next) {
577 msginfo = (MsgInfo *)cur->data;
579 if (msginfo->folder == dest) {
580 g_warning(_("the src folder is identical to the dest.\n"));
583 debug_print(_("Copying message %s%c%d to %s ...\n"),
584 msginfo->folder->path, G_DIR_SEPARATOR,
585 msginfo->msgnum, dest->path);
587 srcfile = procmsg_get_message_file_path(msginfo);
588 destfile = mh_get_newmsg_filename(dest);
594 if (copy_file(srcfile, destfile) < 0) {
595 FILE_OP_ERROR(srcfile, "copy");
608 newmsginfo.msgnum = dest->last_num;
609 newmsginfo.flags = msginfo->flags;
610 if (dest->stype == F_OUTBOX ||
611 dest->stype == F_QUEUE ||
612 dest->stype == F_DRAFT ||
613 dest->stype == F_TRASH)
616 MSG_NEW|MSG_UNREAD|MSG_DELETED);
617 procmsg_write_flags(&newmsginfo, fp);
624 return dest->last_num;
627 gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
631 g_return_val_if_fail(item != NULL, -1);
633 file = mh_fetch_msg(folder, item, num);
634 g_return_val_if_fail(file != NULL, -1);
636 if (unlink(file) < 0) {
637 FILE_OP_ERROR(file, "unlink");
646 gint mh_remove_all_msg(Folder *folder, FolderItem *item)
651 g_return_val_if_fail(item != NULL, -1);
653 path = folder_item_get_path(item);
654 g_return_val_if_fail(path != NULL, -1);
655 val = remove_all_numbered_files(path);
661 gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, MsgInfo *msginfo)
665 if (stat(itos(msginfo->msgnum), &s) < 0 ||
666 msginfo->size != s.st_size ||
667 msginfo->mtime != s.st_mtime)
673 void mh_scan_folder(Folder *folder, FolderItem *item)
683 g_return_if_fail(item != NULL);
685 debug_print("mh_scan_folder(): Scanning %s ...\n", item->path);
687 path = folder_item_get_path(item);
688 g_return_if_fail(path != NULL);
689 if (change_dir(path) < 0) {
695 if ((dp = opendir(".")) == NULL) {
696 FILE_OP_ERROR(item->path, "opendir");
701 folder->ui_func(folder, item, folder->ui_func_data);
703 while ((d = readdir(dp)) != NULL) {
704 if ((num = to_number(d->d_name)) >= 0 &&
705 stat(d->d_name, &s) == 0 &&
706 S_ISREG(s.st_mode)) {
716 item->new = item->unread = item->total = 0;
718 gint new, unread, total;
720 procmsg_get_mark_sum(".", &new, &unread, &total);
722 new += n_msg - total;
723 unread += n_msg - total;
726 item->unread = unread;
730 debug_print(_("Last number in dir %s = %d\n"), item->path, max);
731 item->last_num = max;
734 void mh_scan_tree(Folder *folder)
740 g_return_if_fail(folder != NULL);
742 pptable = folder_persist_prefs_new(folder);
744 folder_tree_destroy(folder);
745 item = folder_item_new(folder->name, NULL);
746 item->folder = folder;
747 folder->node = g_node_new(item);
749 rootpath = folder_item_get_path(item);
750 if (change_dir(rootpath) < 0) {
756 mh_scan_tree_recursive(item, pptable);
758 folder_persist_prefs_free(pptable);
761 #define MAKE_DIR_IF_NOT_EXIST(dir) \
763 if (!is_dir_exist(dir)) { \
764 if (is_file_exist(dir)) { \
765 g_warning(_("File `%s' already exists.\n" \
766 "Can't create folder."), dir); \
769 if (mkdir(dir, S_IRWXU) < 0) { \
770 FILE_OP_ERROR(dir, "mkdir"); \
773 if (chmod(dir, S_IRWXU) < 0) \
774 FILE_OP_ERROR(dir, "chmod"); \
778 gint mh_create_tree(Folder *folder)
782 g_return_val_if_fail(folder != NULL, -1);
784 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
785 rootpath = LOCAL_FOLDER(folder)->rootpath;
786 MAKE_DIR_IF_NOT_EXIST(rootpath);
787 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
788 MAKE_DIR_IF_NOT_EXIST(INBOX_DIR);
789 MAKE_DIR_IF_NOT_EXIST(OUTBOX_DIR);
790 MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR);
791 MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR);
792 MAKE_DIR_IF_NOT_EXIST(TRASH_DIR);
797 #undef MAKE_DIR_IF_NOT_EXIST
799 FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
804 FolderItem *new_item;
806 g_return_val_if_fail(folder != NULL, NULL);
807 g_return_val_if_fail(parent != NULL, NULL);
808 g_return_val_if_fail(name != NULL, NULL);
810 path = folder_item_get_path(parent);
811 if (!is_dir_exist(path))
814 fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
817 if (mkdir(fullpath, S_IRWXU) < 0) {
818 FILE_OP_ERROR(fullpath, "mkdir");
822 if (chmod(fullpath, S_IRWXU) < 0)
823 FILE_OP_ERROR(fullpath, "chmod");
828 path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
831 path = g_strdup(name);
832 new_item = folder_item_new(name, path);
833 folder_item_append(parent, new_item);
839 gint mh_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
847 g_return_val_if_fail(folder != NULL, -1);
848 g_return_val_if_fail(item != NULL, -1);
849 g_return_val_if_fail(item->path != NULL, -1);
850 g_return_val_if_fail(name != NULL, -1);
852 oldpath = folder_item_get_path(item);
853 if (!is_dir_exist(oldpath))
854 make_dir_hier(oldpath);
856 dirname = g_dirname(oldpath);
857 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
860 if (rename(oldpath, newpath) < 0) {
861 FILE_OP_ERROR(oldpath, "rename");
870 if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
871 dirname = g_dirname(item->path);
872 newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, name, NULL);
875 newpath = g_strdup(name);
878 item->name = g_strdup(name);
880 node = g_node_find(item->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL,
882 paths[0] = g_strdup(item->path);
884 g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
885 mh_rename_folder_func, paths);
892 gint mh_remove_folder(Folder *folder, FolderItem *item)
896 g_return_val_if_fail(folder != NULL, -1);
897 g_return_val_if_fail(item != NULL, -1);
898 g_return_val_if_fail(item->path != NULL, -1);
900 path = folder_item_get_path(item);
901 if (remove_dir_recursive(path) < 0) {
902 g_warning("can't remove directory `%s'\n", path);
908 folder_item_remove(item);
913 static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
919 GSList *newlist = NULL;
925 g_return_val_if_fail(item != NULL, NULL);
927 path = folder_item_get_path(item);
928 g_return_val_if_fail(path != NULL, NULL);
929 if (change_dir(path) < 0) {
935 if ((dp = opendir(".")) == NULL) {
936 FILE_OP_ERROR(item->path, "opendir");
940 debug_print(_("\tSearching uncached messages... "));
943 while ((d = readdir(dp)) != NULL) {
944 if ((num = to_number(d->d_name)) < 0) continue;
945 if (stat(d->d_name, &s) < 0) {
946 FILE_OP_ERROR(d->d_name, "stat");
949 if (!S_ISREG(s.st_mode)) continue;
951 msginfo = g_hash_table_lookup
952 (msg_table, GUINT_TO_POINTER(num));
955 /* not found in the cache (uncached message) */
956 msginfo = mh_parse_msg(d->d_name, item);
957 if (!msginfo) continue;
961 g_slist_append(NULL, msginfo);
963 last = g_slist_append(last, msginfo);
970 /* discard all previous cache */
971 while ((d = readdir(dp)) != NULL) {
972 if (to_number(d->d_name) < 0) continue;
973 if (stat(d->d_name, &s) < 0) {
974 FILE_OP_ERROR(d->d_name, "stat");
977 if (!S_ISREG(s.st_mode)) continue;
979 msginfo = mh_parse_msg(d->d_name, item);
980 if (!msginfo) continue;
983 last = newlist = g_slist_append(NULL, msginfo);
985 last = g_slist_append(last, msginfo);
995 debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
997 debug_print(_("done.\n"));
999 /* sort new messages in numerical order */
1001 debug_print(_("\tSorting uncached messages in numerical order... "));
1002 newlist = g_slist_sort
1003 (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
1004 debug_print(_("done.\n"));
1010 static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
1016 flags.perm_flags = MSG_NEW|MSG_UNREAD;
1017 flags.tmp_flags = 0;
1019 g_return_val_if_fail(item != NULL, NULL);
1020 g_return_val_if_fail(file != NULL, NULL);
1022 if (item->stype == F_QUEUE) {
1023 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
1024 } else if (item->stype == F_DRAFT) {
1025 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
1028 msginfo = procheader_parse(file, flags, FALSE, FALSE);
1029 if (!msginfo) return NULL;
1031 msginfo->msgnum = atoi(file);
1032 msginfo->folder = item;
1034 if (stat(file, &s) < 0) {
1035 FILE_OP_ERROR(file, "stat");
1039 msginfo->size = s.st_size;
1040 msginfo->mtime = s.st_mtime;
1046 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
1051 entry = g_strconcat(path, G_DIR_SEPARATOR_S, dir, NULL);
1052 result = is_dir_exist(entry);
1059 * check whether PATH is a Maildir style mailbox.
1060 * This is the case if the 3 subdir: new, cur, tmp are existing.
1061 * This functon assumes that entry is an directory
1063 static gboolean mh_is_maildir(const gchar *path)
1065 return mh_is_maildir_one(path, "new") &&
1066 mh_is_maildir_one(path, "cur") &&
1067 mh_is_maildir_one(path, "tmp");
1070 static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
1078 g_return_if_fail(item != NULL);
1079 g_return_if_fail(item->folder != NULL);
1081 dp = opendir(item->path ? item->path : ".");
1083 FILE_OP_ERROR(item->path ? item->path : ".", "opendir");
1087 debug_print("scanning %s ...\n",
1088 item->path ? item->path
1089 : LOCAL_FOLDER(item->folder)->rootpath);
1090 if (item->folder->ui_func)
1091 item->folder->ui_func(item->folder, item,
1092 item->folder->ui_func_data);
1094 while ((d = readdir(dp)) != NULL) {
1095 if (d->d_name[0] == '.') continue;
1098 entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
1101 entry = g_strdup(d->d_name);
1103 if (stat(entry, &s) < 0) {
1104 FILE_OP_ERROR(entry, "stat");
1109 if (S_ISDIR(s.st_mode)) {
1110 FolderItem *new_item;
1112 if (mh_is_maildir(entry)) {
1117 new_item = folder_item_new(d->d_name, entry);
1118 folder_item_append(item, new_item);
1120 if (!strcmp(d->d_name, "inbox")) {
1121 new_item->stype = F_INBOX;
1122 item->folder->inbox = new_item;
1123 } else if (!strcmp(d->d_name, "outbox")) {
1124 new_item->stype = F_OUTBOX;
1125 item->folder->outbox = new_item;
1126 } else if (!strcmp(d->d_name, "draft")) {
1127 new_item->stype = F_DRAFT;
1128 item->folder->draft = new_item;
1129 } else if (!strcmp(d->d_name, "queue")) {
1130 new_item->stype = F_QUEUE;
1131 item->folder->queue = new_item;
1132 } else if (!strcmp(d->d_name, "trash")) {
1133 new_item->stype = F_TRASH;
1134 item->folder->trash = new_item;
1137 folder_item_restore_persist_prefs(new_item, pptable);
1138 mh_scan_tree_recursive(new_item, pptable);
1139 } else if (to_number(d->d_name) != -1) n_msg++;
1147 gint new, unread, total;
1149 procmsg_get_mark_sum(item->path, &new, &unread, &total);
1150 if (n_msg > total) {
1151 new += n_msg - total;
1152 unread += n_msg - total;
1155 item->unread = unread;
1156 item->total = n_msg;
1160 static gboolean mh_rename_folder_func(GNode *node, gpointer data)
1162 FolderItem *item = node->data;
1163 gchar **paths = data;
1164 const gchar *oldpath = paths[0];
1165 const gchar *newpath = paths[1];
1167 gchar *new_itempath;
1170 oldpathlen = strlen(oldpath);
1171 if (strncmp(oldpath, item->path, oldpathlen) != 0) {
1172 g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
1176 base = item->path + oldpathlen;
1177 while (*base == G_DIR_SEPARATOR) base++;
1179 new_itempath = g_strdup(newpath);
1181 new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
1184 item->path = new_itempath;