static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent, const gchar *name) { gchar *path, *real_name; gchar *fullpath; FolderItem *new_item; gchar *mh_sequences_filename; FILE *mh_sequences_file; cm_return_val_if_fail(folder != NULL, NULL); cm_return_val_if_fail(parent != NULL, NULL); cm_return_val_if_fail(name != NULL, NULL); path = folder_item_get_path(parent); if (!is_dir_exist(path)) if (make_dir_hier(path) != 0) return NULL; real_name = mh_filename_from_utf8(name); fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, real_name, NULL); g_free(real_name); g_free(path); if (make_dir(fullpath) < 0) { g_free(fullpath); return NULL; } g_free(fullpath); if (parent->path) path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name, NULL); else path = g_strdup(name); new_item = folder_item_new(folder, name, path); folder_item_append(parent, new_item); g_free(path); path = folder_item_get_path(new_item); mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S, ".mh_sequences", NULL); if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) { fclose(mh_sequences_file); } g_free(mh_sequences_filename); g_free(path); return new_item; }
static void mh_scan_tree_recursive(FolderItem *item) { Folder *folder; GDir *dir; const gchar *dir_name; gchar *real_path, *entry, *utf8entry, *utf8name; gint n_msg = 0; GError *error = NULL; cm_return_if_fail(item != NULL); cm_return_if_fail(item->folder != NULL); folder = item->folder; real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup("."); dir = g_dir_open(real_path, 0, &error); if (!dir) { g_warning("failed to open directory '%s': %s (%d)", real_path, error->message, error->code); g_error_free(error); g_free(real_path); return; } g_free(real_path); debug_print("scanning %s ...\n", item->path ? item->path : LOCAL_FOLDER(item->folder)->rootpath); if (folder->ui_func) folder->ui_func(folder, item, folder->ui_func_data); while ((dir_name = g_dir_read_name(dir)) != NULL) { if (dir_name[0] == '.') continue; utf8name = mh_filename_to_utf8(dir_name); if (item->path) utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S, utf8name, NULL); else utf8entry = g_strdup(utf8name); entry = mh_filename_from_utf8(utf8entry); if (g_file_test(entry, G_FILE_TEST_IS_DIR)) { FolderItem *new_item = NULL; GNode *node; node = item->node; for (node = node->children; node != NULL; node = node->next) { FolderItem *cur_item = FOLDER_ITEM(node->data); gchar *curpath = mh_filename_from_utf8(cur_item->path); if (!strcmp2(curpath, entry)) { new_item = cur_item; g_free(curpath); break; } g_free(curpath); } if (!new_item) { debug_print("new folder '%s' found.\n", entry); new_item = folder_item_new(folder, utf8name, utf8entry); folder_item_append(item, new_item); } if (!item->path) { if (!folder->inbox && !strcmp(dir_name, INBOX_DIR)) { new_item->stype = F_INBOX; folder->inbox = new_item; } else if (!folder->outbox && !strcmp(dir_name, OUTBOX_DIR)) { new_item->stype = F_OUTBOX; folder->outbox = new_item; } else if (!folder->draft && !strcmp(dir_name, DRAFT_DIR)) { new_item->stype = F_DRAFT; folder->draft = new_item; } else if (!folder->queue && !strcmp(dir_name, QUEUE_DIR)) { new_item->stype = F_QUEUE; folder->queue = new_item; } else if (!folder->trash && !strcmp(dir_name, TRASH_DIR)) { new_item->stype = F_TRASH; folder->trash = new_item; } } mh_scan_tree_recursive(new_item); } else if (to_number(dir_name) > 0) n_msg++; g_free(entry); g_free(utf8entry); g_free(utf8name); } g_dir_close(dir); mh_set_mtime(folder, item); }
static void mh_scan_tree_recursive(FolderItem *item) { Folder *folder; #ifdef G_OS_WIN32 GDir *dir; #else DIR *dp; struct dirent *d; #endif const gchar *dir_name; struct stat s; gchar *real_path, *entry, *utf8entry, *utf8name; gint n_msg = 0; cm_return_if_fail(item != NULL); cm_return_if_fail(item->folder != NULL); folder = item->folder; real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup("."); #ifdef G_OS_WIN32 dir = g_dir_open(real_path, 0, NULL); if (!dir) { g_warning("failed to open directory: %s\n", real_path); g_free(real_path); return; } #else dp = opendir(real_path); if (!dp) { FILE_OP_ERROR(real_path, "opendir"); return; } #endif g_free(real_path); debug_print("scanning %s ...\n", item->path ? item->path : LOCAL_FOLDER(item->folder)->rootpath); if (folder->ui_func) folder->ui_func(folder, item, folder->ui_func_data); #ifdef G_OS_WIN32 while ((dir_name = g_dir_read_name(dir)) != NULL) { #else while ((d = readdir(dp)) != NULL) { dir_name = d->d_name; #endif if (dir_name[0] == '.') continue; utf8name = mh_filename_to_utf8(dir_name); if (item->path) utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S, utf8name, NULL); else utf8entry = g_strdup(utf8name); entry = mh_filename_from_utf8(utf8entry); if ( #if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE) d->d_type == DT_DIR || (d->d_type == DT_UNKNOWN && #endif g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode) #if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE) ) #endif ) { FolderItem *new_item = NULL; GNode *node; node = item->node; for (node = node->children; node != NULL; node = node->next) { FolderItem *cur_item = FOLDER_ITEM(node->data); gchar *curpath = mh_filename_from_utf8(cur_item->path); if (!strcmp2(curpath, entry)) { new_item = cur_item; g_free(curpath); break; } g_free(curpath); } if (!new_item) { debug_print("new folder '%s' found.\n", entry); new_item = folder_item_new(folder, utf8name, utf8entry); folder_item_append(item, new_item); } if (!item->path) { if (!folder->inbox && !strcmp(dir_name, INBOX_DIR)) { new_item->stype = F_INBOX; folder->inbox = new_item; } else if (!folder->outbox && !strcmp(dir_name, OUTBOX_DIR)) { new_item->stype = F_OUTBOX; folder->outbox = new_item; } else if (!folder->draft && !strcmp(dir_name, DRAFT_DIR)) { new_item->stype = F_DRAFT; folder->draft = new_item; } else if (!folder->queue && !strcmp(dir_name, QUEUE_DIR)) { new_item->stype = F_QUEUE; folder->queue = new_item; } else if (!folder->trash && !strcmp(dir_name, TRASH_DIR)) { new_item->stype = F_TRASH; folder->trash = new_item; } } mh_scan_tree_recursive(new_item); } else if (to_number(dir_name) > 0) n_msg++; g_free(entry); g_free(utf8entry); g_free(utf8name); } #ifdef G_OS_WIN32 g_dir_close(dir); #else closedir(dp); #endif mh_set_mtime(folder, item); } static gboolean mh_rename_folder_func(GNode *node, gpointer data) { FolderItem *item = node->data; gchar **paths = data; const gchar *oldpath = paths[0]; const gchar *newpath = paths[1]; gchar *base; gchar *new_itempath; gint oldpathlen; oldpathlen = strlen(oldpath); if (strncmp(oldpath, item->path, oldpathlen) != 0) { g_warning("path doesn't match: %s, %s\n", oldpath, item->path); return TRUE; } base = item->path + oldpathlen; while (*base == G_DIR_SEPARATOR) base++; if (*base == '\0') new_itempath = g_strdup(newpath); else new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base, NULL); g_free(item->path); item->path = new_itempath; return FALSE; }
static void subscribe_newsgroup_cb(GtkAction *action, gpointer data) { FolderView *folderview = (FolderView *)data; Folder *folder; FolderItem *item; FolderItem *rootitem; FolderItem *newitem; GSList *new_subscr; GSList *cur; GNode *gnode; MainWindow *mainwin = mainwindow_get_mainwindow(); if ((item = folderview_get_selected_item(folderview)) == NULL) return; if (mainwin->lock_count || news_folder_locked(item->folder)) return; folder = item->folder; cm_return_if_fail(folder != NULL); cm_return_if_fail(FOLDER_TYPE(folder) == F_NEWS); cm_return_if_fail(folder->account != NULL); if ((rootitem = folder_item_parent(item)) == NULL) rootitem = item; new_subscr = grouplist_dialog(folder); /* remove unsubscribed newsgroups */ for (gnode = folder->node->children; gnode != NULL; ) { GNode *next = gnode->next; item = FOLDER_ITEM(gnode->data); if (g_slist_find_custom(new_subscr, item->path, (GCompareFunc)g_ascii_strcasecmp) != NULL) { gnode = next; continue; } if (folderview_get_opened_item(folderview) == item) { summary_clear_all(folderview->summaryview); folderview_close_opened(folderview, TRUE); } folderview_remove_item(folderview, item); folder_item_remove(item); gnode = next; } folderview_freeze(folderview); /* add subscribed newsgroups */ for (cur = new_subscr; cur != NULL; cur = cur->next) { gchar *name = (gchar *)cur->data; FolderUpdateData hookdata; if (news_find_child_item(rootitem, name) != NULL) continue; newitem = folder_item_new(folder, name, name); folder_item_append(rootitem, newitem); hookdata.folder = newitem->folder; hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDERITEM; hookdata.item = newitem; hookdata.item2 = NULL; hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata); } folderview_thaw(folderview); slist_free_strings_full(new_subscr); folder_write_list(); }