return IMAP_SUCCESS;
}
-gint imap_scan_subtree(Folder *folder, FolderItem *item, gboolean subs_only)
+GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean subs_only)
{
IMAPSession *session = imap_session_get(folder);
+ gchar *real_path;
+ gchar *wildcard_path;
+ gchar separator;
+ gchar wildcard[3];
+ clist * lep_list;
+ GSList *item_list = NULL, *cur;
+ GList *child_list = NULL;
+ int r;
+
if (!session)
- return -1;
- return imap_scan_tree_recursive(session, item, subs_only);
+ return NULL;
+
+ separator = imap_get_path_separator(session, IMAP_FOLDER(folder), item->path);
+
+ if (item->path) {
+ wildcard[0] = separator;
+ wildcard[1] = '%';
+ wildcard[2] = '\0';
+ real_path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path);
+ } else {
+ wildcard[0] = '%';
+ wildcard[1] = '\0';
+ real_path = g_strdup("");
+ }
+
+ Xstrcat_a(wildcard_path, real_path, wildcard,
+ {g_free(real_path); return NULL;});
+ lep_list = NULL;
+
+ if (subs_only)
+ r = imap_threaded_lsub(folder, "", wildcard_path, &lep_list);
+ else
+ r = imap_threaded_list(folder, "", wildcard_path, &lep_list);
+ if (r)
+ return NULL;
+
+ item_list = imap_list_from_lep(IMAP_FOLDER(folder),
+ lep_list, real_path, FALSE);
+ mailimap_list_result_free(lep_list);
+
+ for (cur = item_list; cur != NULL; cur = cur->next) {
+ FolderItem *cur_item = FOLDER_ITEM(cur->data);
+ child_list = g_list_prepend(child_list,
+ imap_get_real_path(session,
+ IMAP_FOLDER(folder), cur_item->path));
+ folder_item_destroy(cur_item);
+ }
+ child_list = g_list_reverse(child_list);
+ g_slist_free(item_list);
+ return child_list;
}
static gint imap_create_tree(Folder *folder)
return 0;
}
-gint imap_subscribe(Folder *folder, FolderItem *item, gboolean sub)
+gint imap_subscribe(Folder *folder, FolderItem *item, gchar *rpath, gboolean sub)
{
gchar *path;
- gint r;
+ gint r = -1;
IMAPSession *session;
debug_print("getting session...\n");
session = imap_session_get(folder);
- if (!session || !item->path) {
+ if (!session) {
return -1;
}
-
- path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path);
- if (!path)
- return -1;
- if (!strcmp(path, "INBOX") && sub == FALSE)
+ if (item && item->path) {
+ path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path);
+ if (!path)
+ return -1;
+ if (!strcmp(path, "INBOX") && sub == FALSE)
+ return -1;
+ debug_print("%ssubscribing %s\n", sub?"":"un", path);
+ r = imap_threaded_subscribe(folder, path, sub);
+ g_free(path);
+ } else if (rpath) {
+ r = imap_threaded_subscribe(folder, rpath, sub);
+ } else
return -1;
- debug_print("%ssubscribing %s\n", sub?"":"un", path);
- r = imap_threaded_subscribe(folder, path, sub);
- g_free(path);
return r;
}
free(dup_name);
continue;
}
-
if (!all && path_cmp(name, real_path) == 0) {
g_free(base);
free(dup_name);
return -1;
}
-gint imap_subscribe(Folder *folder, FolderItem *item, gboolean sub)
+gint imap_subscribe(Folder *folder, FolderItem *item, gchar *rpath, gboolean sub)
{
return -1;
}
-gint imap_scan_subtree(Folder *folder, FolderItem *item, gboolean subs_only)
+GList * imap_scan_subtree(Folder *folder, FolderItem *item, gboolean subs_only)
{
return -1;
}
gboolean action = GPOINTER_TO_INT(data);
if (item->path)
- imap_subscribe(item->folder, item, action);
+ imap_subscribe(item->folder, item, NULL, action);
return FALSE;
}
AUTORELEASE_STR(name, {g_free(name); return;});
if (action && item->folder->account->imap_subsonly) {
- alertpanel_notice(_("This folder is already subscribed to. To "
+ GList *child_list = imap_scan_subtree(item->folder, item, FALSE);
+ if (child_list) {
+ GList *cur;
+ int r = -1;
+ gchar *child_folder = input_dialog_combo(_("Subscribe"),
+ _("Choose a subfolder to subscribe to: "),
+ _("All of them"), child_list, TRUE);
+ if (child_folder && strcmp(child_folder, _("All of them"))) {
+ r = imap_subscribe(item->folder, NULL, child_folder, TRUE);
+ } else if (child_folder) {
+ for (cur = child_list; cur; cur = cur->next)
+ r = imap_subscribe(item->folder, NULL, (gchar *)cur->data, TRUE);
+ }
+ g_free(child_folder);
+ for (cur = child_list; cur; cur = cur->next)
+ g_free((gchar *)cur->data);
+ if (r == 0)
+ folderview_rescan_tree(item->folder, FALSE);
+ } else {
+ alertpanel_notice(_("This folder is already subscribed to and "
+ "has no subfolders. To "
"subscribe to other folders, you must first "
"disable \"Show subscribed folders only\".\n"
"\n"
"Alternatively, you can use \"Create new folder\" "
"to subscribe to a known folder."));
+ }
+ g_list_free(child_list);
return;
}
message = g_strdup_printf
g_node_traverse(item->node, G_PRE_ORDER,
G_TRAVERSE_ALL, -1, imap_gtk_subscribe_func, GINT_TO_POINTER(action));
} else {
- imap_subscribe(item->folder, item, action);
+ imap_subscribe(item->folder, item, NULL, action);
}
if (!action && item->folder->account->imap_subsonly)