1
/* tinymail - Tiny Mail
2
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
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.
21
#include <camel/camel-session.h>
24
#include <glib/gi18n-lib.h>
29
#include <tny-platform-factory.h>
32
#include <tny-account-store.h>
33
#include <tny-account.h>
34
#include <tny-camel-account.h>
36
#include <tny-store-account.h>
37
#include <tny-transport-account.h>
38
#include <tny-camel-store-account.h>
39
#include <tny-camel-transport-account.h>
40
#include <tny-device.h>
41
#include <tny-session-camel.h>
44
#include "account-store.h"
47
static GObjectClass *parent_class = NULL;
51
per_account_get_pass_func (TnyAccount *account, const gchar *prompt, gboolean *cancel)
53
if (strstr (tny_account_get_name (account), "SMTP"))
54
return g_strdup ("unittest");
56
return g_strdup ("tnytest");
60
per_account_forget_pass_func (TnyAccount *account)
62
g_print ("Invalid test account (password incorrect)\n");
68
tny_test_account_store_alert (TnyAccountStore *self, TnyAccount *account, TnyAlertType type, gboolean question, const GError *error)
75
tny_test_account_store_get_cache_dir (TnyAccountStore *self)
77
TnyTestAccountStore *me = (TnyTestAccountStore*) self;
79
if (me->cache_dir == NULL)
84
gchar *attempt = g_strdup_printf ("tinymail.%d", att);
85
gchar *str = g_build_filename (g_get_tmp_dir (), attempt, NULL);
87
dir = g_dir_open (str, 0, NULL);
95
} while (dir != NULL);
103
tny_test_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types)
105
TnyTestAccountStore *me = (TnyTestAccountStore *) self;
109
/* Dear visitor of the SVN-web. This is indeed a fully functional and
110
working IMAP account. This does not mean that you need to fuck it up */
112
if (types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS || types == TNY_ACCOUNT_STORE_BOTH)
114
account = TNY_ACCOUNT (tny_camel_store_account_new ());
116
tny_camel_account_set_session (TNY_CAMEL_ACCOUNT (account), me->session);
117
camel_session_set_online ((CamelSession*)me->session, me->force_online);
118
tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), me->force_online, NULL, NULL);
120
tny_account_set_proto (account, "imap");
121
tny_account_set_name (account, "imap1.tinymail.org");
122
tny_account_set_user (account, "tnytest");
123
tny_account_set_hostname (account, "imap1.tinymail.org");
124
tny_account_set_id (account, "tnytest@imap1.tinymail.org");
125
tny_account_set_forget_pass_func (account, per_account_forget_pass_func);
126
tny_account_set_pass_func (account, per_account_get_pass_func);
128
tny_list_prepend (list, (GObject*)account);
129
g_object_unref (G_OBJECT (account));
132
if (types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS || types == TNY_ACCOUNT_STORE_BOTH)
134
account = TNY_ACCOUNT (tny_camel_transport_account_new ());
136
tny_camel_account_set_session (TNY_CAMEL_ACCOUNT (account), me->session);
137
camel_session_set_online ((CamelSession*)me->session, me->force_online);
138
tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), me->force_online, NULL, NULL);
140
tny_account_set_proto (account, "something");
141
tny_account_set_name (account, "SMTP unit test account");
142
tny_account_set_id (account, "unique_smtp");
143
tny_account_set_url_string (account, "smtp://tinymailunittest;auth=PLAIN@mail.tinymail.org:2222/;use_ssl=wrapped");
145
tny_account_set_forget_pass_func (account, per_account_forget_pass_func);
146
tny_account_set_pass_func (account, per_account_get_pass_func);
148
tny_list_prepend (list, (GObject*)account);
149
g_object_unref (G_OBJECT (account));
152
if (me->force_online)
153
tny_device_force_online (me->device);
155
tny_device_force_offline (me->device);
163
tny_test_account_store_new (gboolean force_online, const gchar *cachedir)
165
TnyTestAccountStore *self = g_object_new (TNY_TYPE_TEST_ACCOUNT_STORE, NULL);
170
g_free (self->cache_dir);
171
self->cache_dir = g_strdup (cachedir);
174
self->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self));
176
self->force_online = force_online;
179
return TNY_ACCOUNT_STORE (self);
184
tny_test_account_store_instance_init (GTypeInstance *instance, gpointer g_class)
186
TnyTestAccountStore *self = (TnyTestAccountStore *)instance;
187
TnyPlatformFactory *platfact = tny_test_platform_factory_get_instance ();
189
self->device = tny_platform_factory_new_device (platfact);
190
g_object_unref (G_OBJECT (platfact));
197
tny_test_account_store_finalize (GObject *object)
199
TnyTestAccountStore *me = (TnyTestAccountStore*) object;
202
g_free (me->cache_dir);
204
g_object_unref (me->device);
206
(*parent_class->finalize) (object);
213
tny_test_account_store_class_init (TnyTestAccountStoreClass *class)
215
GObjectClass *object_class;
217
parent_class = g_type_class_peek_parent (class);
218
object_class = (GObjectClass*) class;
220
object_class->finalize = tny_test_account_store_finalize;
227
tny_test_account_store_get_device (TnyAccountStore *self)
229
TnyTestAccountStore *me = (TnyTestAccountStore*) self;
231
return g_object_ref (G_OBJECT (me->device));
236
tny_account_store_init (gpointer g, gpointer iface_data)
238
TnyAccountStoreIface *klass = (TnyAccountStoreIface *)g;
240
klass->get_accounts_func = tny_test_account_store_get_accounts;
241
klass->get_cache_dir_func = tny_test_account_store_get_cache_dir;
242
klass->alert_func = tny_test_account_store_alert;
243
klass->get_device_func = tny_test_account_store_get_device;
250
tny_test_account_store_get_type (void)
252
static GType type = 0;
254
if (G_UNLIKELY(type == 0))
256
static const GTypeInfo info =
258
sizeof (TnyTestAccountStoreClass),
259
NULL, /* base_init */
260
NULL, /* base_finalize */
261
(GClassInitFunc) tny_test_account_store_class_init, /* class_init */
262
NULL, /* class_finalize */
263
NULL, /* class_data */
264
sizeof (TnyTestAccountStore),
266
tny_test_account_store_instance_init /* instance_init */
269
static const GInterfaceInfo tny_account_store_info =
271
(GInterfaceInitFunc) tny_account_store_init, /* interface_init */
272
NULL, /* interface_finalize */
273
NULL /* interface_data */
276
type = g_type_register_static (G_TYPE_OBJECT,
277
"TnyTestAccountStore",
280
g_type_add_interface_static (type, TNY_TYPE_ACCOUNT_STORE,
281
&tny_account_store_info);