#include "imap_gtk.h"
#include "inc.h"
#include "xml.h"
+#include "alertpanel.h"
#ifdef HAVE_LIBETPAN
#include "inputdialog.h"
#include "log.h"
#include "remotefolder.h"
-#include "alertpanel.h"
#include "claws.h"
#include "statusbar.h"
#include "msgcache.h"
g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, imap_reset_uid_lists_func, NULL);
}
-int imap_get_capabilities(IMAPSession *session)
+static int imap_get_capabilities(IMAPSession *session)
{
struct mailimap_capability_data *capabilities = NULL;
clistiter *cur;
return MAILIMAP_NO_ERROR;
}
-gboolean imap_has_capability(IMAPSession *session, const gchar *cap)
+static gboolean imap_has_capability(IMAPSession *session, const gchar *cap)
{
GSList *cur;
for (cur = session->capability; cur; cur = cur->next) {
g_relation_destroy(uid_mapping);
imap_lep_set_free(seq_list);
unlock_session();
+ statusbar_pop_all();
return -1;
}
}
return IMAP_SUCCESS;
}
-gint imap_scan_subtree(Folder *folder, FolderItem *item, gboolean subs_only)
+GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean unsubs_only, gboolean recursive)
{
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, *tmplist = NULL;
+ GSList *sub_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 (unsubs_only)
+ statusbar_print_all(_("Looking for unsubscribed folders in %s..."),
+ item->path?item->path:item->name);
+ else
+ statusbar_print_all(_("Looking for subfolders of %s..."),
+ item->path?item->path:item->name);
+
+ r = imap_threaded_list(folder, "", wildcard_path, &lep_list);
+ if (r) {
+ statusbar_pop_all();
+ 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);
+ if (recursive) {
+ tmplist = imap_scan_subtree(folder, cur_item,
+ unsubs_only, recursive);
+ if (tmplist)
+ child_list = g_list_concat(child_list, tmplist);
+ }
+ 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);
+
+ if (unsubs_only) {
+ r = imap_threaded_lsub(folder, "", wildcard_path, &lep_list);
+ if (r) {
+ statusbar_pop_all();
+ return NULL;
+ }
+ sub_list = imap_list_from_lep(IMAP_FOLDER(folder),
+ lep_list, real_path, FALSE);
+ mailimap_list_result_free(lep_list);
+
+ for (cur = sub_list; cur != NULL; cur = cur->next) {
+ FolderItem *cur_item = FOLDER_ITEM(cur->data);
+ GList *oldlitem = NULL;
+ gchar *tmp = imap_get_real_path(session,
+ IMAP_FOLDER(folder), cur_item->path);
+ folder_item_destroy(cur_item);
+ oldlitem = g_list_find_custom(
+ child_list, tmp, (GCompareFunc)strcmp2);
+ if (oldlitem) {
+ child_list = g_list_remove_link(child_list, oldlitem);
+ g_free(oldlitem->data);
+ g_list_free(oldlitem);
+ }
+ g_free(tmp);
+ }
+ }
+
+ statusbar_pop_all();
+
+ 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 unsubs_only, gboolean recursive)
{
- return -1;
+ return NULL;
}
#endif