1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <modest-transport-account-decorator.h>
32 #include <modest-tny-account-store.h>
33 #include <modest-tny-account.h>
34 #include <modest-runtime.h>
35 #include <tny-simple-list.h>
36 #include <tny-iterator.h>
37 #include <tny-folder.h>
38 #include <modest-marshal.h>
39 #include <string.h> /* strcmp */
41 /* 'private'/'protected' functions */
42 static void modest_transport_account_decorator_class_init (ModestTransportAccountDecoratorClass *klass);
43 static void modest_transport_account_decorator_finalize (GObject *obj);
44 static void modest_transport_account_decorator_instance_init (GTypeInstance *instance, gpointer g_class);
45 static void modest_transport_account_decorator_send (TnyTransportAccount *self, TnyMsg *msg, GError **err);
46 static void modest_transport_account_decorator_cancel (TnyAccount *self);
50 /* /\* MY_SIGNAL_1, *\/ */
51 /* /\* MY_SIGNAL_2, *\/ */
55 /* typedef struct _ModestTransportAccountDecoratorPrivate ModestTransportAccountDecoratorPrivate; */
56 /* struct _ModestTransportAccountDecoratorPrivate { */
59 /* #define MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ */
60 /* MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR, \ */
61 /* ModestTransportAccountDecoratorPrivate)) */
64 static TnyCamelTransportAccountClass *parent_class = NULL;
66 /* uncomment the following if you have defined any signals */
67 /* static guint signals[LAST_SIGNAL] = {0}; */
70 * this thread actually tries to send all the mails in the outbox and keeps
71 * track of their state.
74 modest_transport_account_decorator_send (TnyTransportAccount *self, TnyMsg *msg, GError **err)
76 TnyTransportAccount *connection_specific_account = NULL;
77 /* ModestTransportAccountDecoratorPrivate *priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (self); */
78 ModestTnyAccountStore *store = modest_runtime_get_account_store ();
79 const gchar *account_name;
81 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (self));
83 connection_specific_account = TNY_TRANSPORT_ACCOUNT
84 (modest_tny_account_store_get_smtp_specific_transport_account_for_open_connection (store, account_name));
87 if (connection_specific_account) {
88 tny_transport_account_send (connection_specific_account, msg, err);
89 g_object_unref (connection_specific_account);
91 TNY_CAMEL_TRANSPORT_ACCOUNT_CLASS(parent_class)->send (self, msg, err);
96 modest_transport_account_decorator_cancel (TnyAccount *self)
98 TnyTransportAccount *conn_specific_account = NULL;
99 ModestTnyAccountStore *store = modest_runtime_get_account_store ();
100 const gchar *account_name;
102 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (self));
104 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (self);
106 conn_specific_account = (TnyTransportAccount *)
107 modest_tny_account_store_get_smtp_specific_transport_account_for_open_connection (store, account_name);
110 /* Cancel sending in the connection specific transport account */
111 if (conn_specific_account) {
112 tny_account_cancel (TNY_ACCOUNT (conn_specific_account));
113 g_object_unref (conn_specific_account);
116 /* Also cancel the transport account, we could not be sure
117 which one was used to send each email */
118 TNY_CAMEL_ACCOUNT_CLASS(parent_class)->cancel (self);
122 modest_transport_account_decorator_class_init (ModestTransportAccountDecoratorClass *klass)
124 GObjectClass *gobject_class;
125 TnyCamelTransportAccountClass *transport_class;
126 TnyCamelAccountClass *account_class;
128 gobject_class = (GObjectClass*) klass;
129 transport_class = (TnyCamelTransportAccountClass *) klass;
130 account_class = (TnyCamelAccountClass *) klass;
132 parent_class = g_type_class_peek_parent (klass);
133 gobject_class->finalize = modest_transport_account_decorator_finalize;
135 transport_class->send = modest_transport_account_decorator_send;
137 account_class->cancel = modest_transport_account_decorator_cancel;
138 /* g_type_class_add_private (gobject_class, sizeof(ModestTransportAccountDecoratorPrivate)); */
142 modest_transport_account_decorator_instance_init (GTypeInstance *instance, gpointer g_class)
144 /* ModestTransportAccountDecoratorPrivate *priv; */
146 /* priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (instance); */
150 modest_transport_account_decorator_finalize (GObject *obj)
152 /* ModestTransportAccountDecoratorPrivate *priv; */
154 /* priv = MODEST_TRANSPORT_ACCOUNT_DECORATOR_GET_PRIVATE (obj); */
156 G_OBJECT_CLASS(parent_class)->finalize (obj);
159 ModestTransportAccountDecorator*
160 modest_transport_account_decorator_new (void)
162 return g_object_new (MODEST_TYPE_TRANSPORT_ACCOUNT_DECORATOR, NULL);
166 modest_transport_account_decorator_get_type (void)
168 static GType my_type = 0;
171 static const GTypeInfo my_info = {
172 sizeof(ModestTransportAccountDecoratorClass),
173 NULL, /* base init */
174 NULL, /* base finalize */
175 (GClassInitFunc) modest_transport_account_decorator_class_init,
176 NULL, /* class finalize */
177 NULL, /* class data */
178 sizeof(ModestTransportAccountDecorator),
180 (GInstanceInitFunc) modest_transport_account_decorator_instance_init,
184 my_type = g_type_register_static (TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT,
185 "ModestTransportAccountDecorator",