| 1 |
1 |
/*
|
| 2 |
2 |
* LibSylph -- E-Mail client library
|
| 3 |
|
* Copyright (C) 1999-2007 Hiroyuki Yamamoto
|
|
3 |
* Copyright (C) 1999-2008 Hiroyuki Yamamoto
|
| 4 |
4 |
*
|
| 5 |
5 |
* This library is free software; you can redistribute it and/or
|
| 6 |
6 |
* modify it under the terms of the GNU Lesser General Public
|
| ... | ... | |
| 183 |
183 |
static GSList *imap_parse_list (IMAPSession *session,
|
| 184 |
184 |
const gchar *real_path,
|
| 185 |
185 |
gchar *separator);
|
|
186 |
static GSList *imap_add_inter_folders (GSList *item_list,
|
|
187 |
const gchar *root_path);
|
| 186 |
188 |
static GSList *imap_get_part_folder_list(GSList *item_list,
|
| 187 |
189 |
FolderItem *item);
|
| 188 |
190 |
|
| ... | ... | |
| 1917 |
1919 |
imap_cmd_gen_send(session, "LIST \"\" \"%s\"", wildcard_path);
|
| 1918 |
1920 |
|
| 1919 |
1921 |
item_list = imap_parse_list(session, real_path, NULL);
|
|
1922 |
item_list = imap_add_inter_folders(item_list, item->path);
|
| 1920 |
1923 |
g_free(real_path);
|
| 1921 |
1924 |
g_free(wildcard_path);
|
| 1922 |
1925 |
|
| ... | ... | |
| 2013 |
2016 |
return item_list;
|
| 2014 |
2017 |
}
|
| 2015 |
2018 |
|
|
2019 |
static GSList *imap_add_inter_folders(GSList *item_list, const gchar *root_path)
|
|
2020 |
{
|
|
2021 |
FolderItem *item;
|
|
2022 |
GSList *cur;
|
|
2023 |
GSList *add_list = NULL;
|
|
2024 |
GHashTable *exist;
|
|
2025 |
const gchar *p;
|
|
2026 |
gint root_path_len = 0;
|
|
2027 |
|
|
2028 |
if (root_path)
|
|
2029 |
root_path_len = strlen(root_path);
|
|
2030 |
|
|
2031 |
exist = g_hash_table_new(g_str_hash, g_str_equal);
|
|
2032 |
|
|
2033 |
for (cur = item_list; cur != NULL; cur = cur->next) {
|
|
2034 |
item = FOLDER_ITEM(cur->data);
|
|
2035 |
|
|
2036 |
if (root_path_len > 0 &&
|
|
2037 |
strncmp(root_path, item->path, root_path_len) != 0)
|
|
2038 |
continue;
|
|
2039 |
p = item->path + root_path_len;
|
|
2040 |
while (*p == '/') p++;
|
|
2041 |
if (*p == '\0') continue;
|
|
2042 |
g_hash_table_insert(exist, (gpointer)p, GINT_TO_POINTER(1));
|
|
2043 |
}
|
|
2044 |
|
|
2045 |
for (cur = item_list; cur != NULL; cur = cur->next) {
|
|
2046 |
const gchar *q, *r;
|
|
2047 |
gchar *parent, *full_parent;
|
|
2048 |
FolderItem *new_item;
|
|
2049 |
|
|
2050 |
item = FOLDER_ITEM(cur->data);
|
|
2051 |
|
|
2052 |
if (root_path_len > 0 &&
|
|
2053 |
strncmp(root_path, item->path, root_path_len) != 0)
|
|
2054 |
continue;
|
|
2055 |
p = item->path + root_path_len;
|
|
2056 |
while (*p == '/') p++;
|
|
2057 |
if (*p == '\0') continue;
|
|
2058 |
|
|
2059 |
q = p;
|
|
2060 |
while ((q = strchr(q, '/')) != NULL) {
|
|
2061 |
parent = g_strndup(p, q - p);
|
|
2062 |
if (!g_hash_table_lookup(exist, parent)) {
|
|
2063 |
if (root_path_len > 0)
|
|
2064 |
full_parent = g_strconcat
|
|
2065 |
(root_path, "/", parent, NULL);
|
|
2066 |
else
|
|
2067 |
full_parent = g_strdup(parent);
|
|
2068 |
new_item = folder_item_new(g_basename(parent),
|
|
2069 |
full_parent);
|
|
2070 |
new_item->no_select = TRUE;
|
|
2071 |
add_list = g_slist_prepend(add_list, new_item);
|
|
2072 |
r = new_item->path + root_path_len;
|
|
2073 |
while (*r == '/') r++;
|
|
2074 |
g_hash_table_insert(exist, (gpointer)r,
|
|
2075 |
GINT_TO_POINTER(1));
|
|
2076 |
debug_print("intermediate folder '%s' added\n",
|
|
2077 |
full_parent);
|
|
2078 |
g_free(full_parent);
|
|
2079 |
}
|
|
2080 |
g_free(parent);
|
|
2081 |
while (*q == '/') q++;
|
|
2082 |
}
|
|
2083 |
}
|
|
2084 |
|
|
2085 |
g_hash_table_destroy(exist);
|
|
2086 |
|
|
2087 |
add_list = g_slist_reverse(add_list);
|
|
2088 |
item_list = g_slist_concat(item_list, add_list);
|
|
2089 |
|
|
2090 |
return item_list;
|
|
2091 |
}
|
|
2092 |
|
| 2016 |
2093 |
static GSList *imap_get_part_folder_list(GSList *item_list, FolderItem *item)
|
| 2017 |
2094 |
{
|
| 2018 |
2095 |
FolderItem *cur_item;
|