1
/* tinymail - Tiny Mail
2
* Copyright (C) 2006-2007 Antia Puentes Felpeto <apuentes@igalia.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with self library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
26
#include <tny-iterator.h>
27
#include <tny-simple-list.h>
28
#include <tny-account-store.h>
29
#include <tny-store-account.h>
30
#include <tny-folder.h>
31
#include <tny-folder-store.h>
32
#include <tny-folder-store-query.h>
34
#include <account-store.h>
36
static gchar *cachedir=NULL;
37
static gboolean online=FALSE;
38
static const gchar *src_name = NULL;
39
static TnyFolder *src_folder = NULL;
40
static gint recursion_level=0;
43
static const GOptionEntry options[] = {
44
{ "name", 'n', 0, G_OPTION_ARG_STRING, &src_name,
46
{ "cachedir", 'c', 0, G_OPTION_ARG_STRING, &cachedir,
47
"Cache directory", NULL },
48
{ "online", 'o', 0, G_OPTION_ARG_NONE, &online,
49
"Online or offline", NULL },
54
recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query)
57
TnyList *folders = tny_simple_list_new ();
59
tny_folder_store_get_folders (store, folders, query, NULL);
60
iter = tny_list_create_iterator (folders);
62
while (!tny_iterator_is_done (iter))
64
TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter);
66
const gchar *folder_name = NULL;
68
for (i=0; i<recursion_level; i++)
71
folder_name = tny_folder_get_name (TNY_FOLDER (folder));
72
g_print ("%s\n", folder_name);
74
if (!strcmp (folder_name, src_name))
75
src_folder = g_object_ref (folder);
78
recurse_folders (folder, query);
81
g_object_unref (G_OBJECT (folder));
83
tny_iterator_next (iter);
86
g_object_unref (G_OBJECT (iter));
87
g_object_unref (G_OBJECT (folders));
91
main (int argc, char **argv)
93
GOptionContext *context;
94
TnyAccountStore *account_store;
96
TnyStoreAccount *account;
105
context = g_option_context_new ("- The tinymail functional tester");
106
g_option_context_add_main_entries (context, options, "tinymail");
107
g_option_context_parse (context, &argc, &argv, NULL);
109
account_store = tny_test_account_store_new (online, cachedir);
112
g_print ("Using %s as cache directory\n", cachedir);
114
g_option_context_free (context);
115
accounts = tny_simple_list_new ();
117
tny_account_store_get_accounts (account_store, accounts,
118
TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
119
g_object_unref (G_OBJECT (account_store));
120
iter = tny_list_create_iterator (accounts);
121
account = (TnyStoreAccount*) tny_iterator_get_current (iter);
125
recurse_folders (TNY_FOLDER_STORE (account), NULL);
129
g_message ("Folder not found");
133
g_print ("Remove folder %s\n",
134
tny_folder_get_name (src_folder));
136
TnyFolderStore *folder_store = tny_folder_get_folder_store (src_folder);
138
if (!(folder_store)) {
139
g_message ("Folderstore not found");
143
tny_folder_store_remove_folder (folder_store, src_folder, &err);
144
g_object_unref (G_OBJECT (src_folder));
147
g_warning ("%s", err->message);
150
recurse_folders (TNY_FOLDER_STORE (account), NULL);
154
g_object_unref (G_OBJECT (account));
155
g_object_unref (G_OBJECT (iter));
156
g_object_unref (G_OBJECT (accounts));