evolution-3.6.4/libemail-engine/e-mail-store-utils.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-store-utils.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-store-utils.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-store-utils.c
  3  *
  4  * This program 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) version 3.
  8  *
  9  * This program 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.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include "e-mail-utils.h"
 24 
 25 #include "e-mail-store-utils.h"
 26 
 27 #include <glib/gi18n-lib.h>
 28 
 29 typedef struct _AsyncContext AsyncContext;
 30 
 31 struct _AsyncContext {
 32 	gchar *full_name;
 33 };
 34 
 35 static void
 36 async_context_free (AsyncContext *context)
 37 {
 38 	g_free (context->full_name);
 39 
 40 	g_slice_free (AsyncContext, context);
 41 }
 42 
 43 static void
 44 mail_store_create_folder_thread (GSimpleAsyncResult *simple,
 45                                  GObject *object,
 46                                  GCancellable *cancellable)
 47 {
 48 	AsyncContext *context;
 49 	GError *error = NULL;
 50 
 51 	context = g_simple_async_result_get_op_res_gpointer (simple);
 52 
 53 	e_mail_store_create_folder_sync (
 54 		CAMEL_STORE (object), context->full_name,
 55 		cancellable, &error);
 56 
 57 	if (error != NULL)
 58 		g_simple_async_result_take_error (simple, error);
 59 }
 60 
 61 gboolean
 62 e_mail_store_create_folder_sync (CamelStore *store,
 63                                  const gchar *full_name,
 64                                  GCancellable *cancellable,
 65                                  GError **error)
 66 {
 67 	CamelFolderInfo *folder_info;
 68 	gchar *copied_full_name;
 69 	gchar *display_name;
 70 	const gchar *parent;
 71 	gboolean success = TRUE;
 72 
 73 	g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
 74 	g_return_val_if_fail (full_name != NULL, FALSE);
 75 
 76 	copied_full_name = g_strdup (full_name);
 77 	display_name = strrchr (copied_full_name, '/');
 78 	if (display_name == NULL) {
 79 		display_name = copied_full_name;
 80 		parent = "";
 81 	} else {
 82 		*display_name++ = '\0';
 83 		parent = copied_full_name;
 84 	}
 85 
 86 	folder_info = camel_store_create_folder_sync (
 87 		store, parent, display_name, cancellable, error);
 88 
 89 	g_free (copied_full_name);
 90 
 91 	if (folder_info == NULL)
 92 		return FALSE;
 93 
 94 	if (CAMEL_IS_SUBSCRIBABLE (store))
 95 		success = camel_subscribable_subscribe_folder_sync (
 96 			CAMEL_SUBSCRIBABLE (store),
 97 			full_name, cancellable, error);
 98 
 99 	camel_store_free_folder_info (store, folder_info);
100 
101 	return success;
102 }
103 
104 void
105 e_mail_store_create_folder (CamelStore *store,
106                             const gchar *full_name,
107                             gint io_priority,
108                             GCancellable *cancellable,
109                             GAsyncReadyCallback callback,
110                             gpointer user_data)
111 {
112 	GSimpleAsyncResult *simple;
113 	AsyncContext *context;
114 
115 	g_return_if_fail (CAMEL_IS_STORE (store));
116 	g_return_if_fail (full_name != NULL);
117 
118 	context = g_slice_new0 (AsyncContext);
119 	context->full_name = g_strdup (full_name);
120 
121 	simple = g_simple_async_result_new (
122 		G_OBJECT (store), callback, user_data,
123 		e_mail_store_create_folder);
124 
125 	g_simple_async_result_set_check_cancellable (simple, cancellable);
126 
127 	g_simple_async_result_set_op_res_gpointer (
128 		simple, context, (GDestroyNotify) async_context_free);
129 
130 	g_simple_async_result_run_in_thread (
131 		simple, mail_store_create_folder_thread,
132 		io_priority, cancellable);
133 
134 	g_object_unref (simple);
135 }
136 
137 gboolean
138 e_mail_store_create_folder_finish (CamelStore *store,
139                                    GAsyncResult *result,
140                                    GError **error)
141 {
142 	GSimpleAsyncResult *simple;
143 
144 	g_return_val_if_fail (
145 		g_simple_async_result_is_valid (
146 		result, G_OBJECT (store),
147 		e_mail_store_create_folder), FALSE);
148 
149 	simple = G_SIMPLE_ASYNC_RESULT (result);
150 
151 	/* Assume success unless a GError is set. */
152 	return !g_simple_async_result_propagate_error (simple, error);
153 }
154 
155 static void
156 mail_store_go_offline_thread (GSimpleAsyncResult *simple,
157                               CamelStore *store,
158                               GCancellable *cancellable)
159 {
160 	CamelService *service;
161 	const gchar *display_name;
162 	GError *error = NULL;
163 
164 	service = CAMEL_SERVICE (store);
165 
166 	display_name = camel_service_get_display_name (service);
167 	if (display_name == NULL || *display_name == '\0')
168 		display_name = G_OBJECT_TYPE_NAME (service);
169 
170 	camel_operation_push_message (
171 		cancellable, _("Disconnecting from '%s'"), display_name);
172 
173 	if (CAMEL_IS_DISCO_STORE (store)) {
174 		CamelDiscoStore *disco_store;
175 
176 		disco_store = CAMEL_DISCO_STORE (store);
177 
178 		if (camel_disco_store_can_work_offline (disco_store))
179 			camel_disco_store_set_status (
180 				disco_store, CAMEL_DISCO_STORE_OFFLINE,
181 				cancellable, &error);
182 		else
183 			camel_service_disconnect_sync (
184 				service, TRUE, cancellable, &error);
185 
186 	} else if (CAMEL_IS_OFFLINE_STORE (store)) {
187 		CamelOfflineStore *offline_store;
188 
189 		offline_store = CAMEL_OFFLINE_STORE (store);
190 
191 		camel_offline_store_set_online_sync (
192 			offline_store, FALSE, cancellable, &error);
193 
194 	} else {
195 		camel_service_disconnect_sync (
196 			service, TRUE, cancellable, &error);
197 	}
198 
199 	if (error != NULL)
200 		g_simple_async_result_take_error (simple, error);
201 
202 	camel_operation_pop_message (cancellable);
203 }
204 
205 void
206 e_mail_store_go_offline (CamelStore *store,
207                          gint io_priority,
208                          GCancellable *cancellable,
209                          GAsyncReadyCallback callback,
210                          gpointer user_data)
211 {
212 	GSimpleAsyncResult *simple;
213 
214 	g_return_if_fail (CAMEL_IS_STORE (store));
215 
216 	simple = g_simple_async_result_new (
217 		G_OBJECT (store), callback,
218 		user_data, e_mail_store_go_offline);
219 
220 	g_simple_async_result_set_check_cancellable (simple, cancellable);
221 
222 	g_simple_async_result_run_in_thread (
223 		simple, (GSimpleAsyncThreadFunc)
224 		mail_store_go_offline_thread,
225 		io_priority, cancellable);
226 
227 	g_object_unref (simple);
228 }
229 
230 gboolean
231 e_mail_store_go_offline_finish (CamelStore *store,
232                                 GAsyncResult *result,
233                                 GError **error)
234 {
235 	GSimpleAsyncResult *simple;
236 
237 	g_return_val_if_fail (
238 		g_simple_async_result_is_valid (
239 		result, G_OBJECT (store), e_mail_store_go_offline), FALSE);
240 
241 	simple = G_SIMPLE_ASYNC_RESULT (result);
242 
243 	/* Assume success unless a GError is set. */
244 	return !g_simple_async_result_propagate_error (simple, error);
245 }
246 
247 static void
248 mail_store_go_online_thread (GSimpleAsyncResult *simple,
249                              CamelStore *store,
250                              GCancellable *cancellable)
251 {
252 	CamelService *service;
253 	const gchar *display_name;
254 	GError *error = NULL;
255 
256 	service = CAMEL_SERVICE (store);
257 
258 	display_name = camel_service_get_display_name (service);
259 	if (display_name == NULL || *display_name == '\0')
260 		display_name = G_OBJECT_TYPE_NAME (service);
261 
262 	camel_operation_push_message (
263 		cancellable, _("Reconnecting to '%s'"), display_name);
264 
265 	if (CAMEL_IS_DISCO_STORE (store))
266 		camel_disco_store_set_status (
267 			CAMEL_DISCO_STORE (store),
268 			CAMEL_DISCO_STORE_ONLINE,
269 			cancellable, &error);
270 
271 	else if (CAMEL_IS_OFFLINE_STORE (store))
272 		camel_offline_store_set_online_sync (
273 			CAMEL_OFFLINE_STORE (store),
274 			TRUE, cancellable, &error);
275 
276 	if (error != NULL)
277 		g_simple_async_result_take_error (simple, error);
278 
279 	camel_operation_pop_message (cancellable);
280 }
281 
282 void
283 e_mail_store_go_online (CamelStore *store,
284                         gint io_priority,
285                         GCancellable *cancellable,
286                         GAsyncReadyCallback callback,
287                         gpointer user_data)
288 {
289 	GSimpleAsyncResult *simple;
290 
291 	g_return_if_fail (CAMEL_IS_STORE (store));
292 
293 	simple = g_simple_async_result_new (
294 		G_OBJECT (store), callback,
295 		user_data, e_mail_store_go_online);
296 
297 	g_simple_async_result_set_check_cancellable (simple, cancellable);
298 
299 	g_simple_async_result_run_in_thread (
300 		simple, (GSimpleAsyncThreadFunc)
301 		mail_store_go_online_thread,
302 		io_priority, cancellable);
303 
304 	g_object_unref (simple);
305 }
306 
307 gboolean
308 e_mail_store_go_online_finish (CamelStore *store,
309                                GAsyncResult *result,
310                                GError **error)
311 {
312 	GSimpleAsyncResult *simple;
313 
314 	g_return_val_if_fail (
315 		g_simple_async_result_is_valid (
316 		result, G_OBJECT (store), e_mail_store_go_online), FALSE);
317 
318 	simple = G_SIMPLE_ASYNC_RESULT (result);
319 
320 	/* Assume success unless a GError is set. */
321 	return !g_simple_async_result_propagate_error (simple, error);
322 }
323 
324 static void
325 mail_store_prepare_for_offline_thread (GSimpleAsyncResult *simple,
326                                        CamelStore *store,
327                                        GCancellable *cancellable)
328 {
329 	CamelService *service;
330 	const gchar *display_name;
331 	GError *error = NULL;
332 
333 	service = CAMEL_SERVICE (store);
334 
335 	display_name = camel_service_get_display_name (service);
336 	if (display_name == NULL || *display_name == '\0')
337 		display_name = G_OBJECT_TYPE_NAME (service);
338 
339 	camel_operation_push_message (
340 		cancellable, _("Preparing account '%s' for offline"),
341 		display_name);
342 
343 	if (CAMEL_IS_DISCO_STORE (store))
344 		camel_disco_store_prepare_for_offline (
345 			CAMEL_DISCO_STORE (store), cancellable, &error);
346 
347 	else if (CAMEL_IS_OFFLINE_STORE (store))
348 		camel_offline_store_prepare_for_offline_sync (
349 			CAMEL_OFFLINE_STORE (store), cancellable, &error);
350 
351 	if (error != NULL)
352 		g_simple_async_result_take_error (simple, error);
353 
354 	camel_operation_pop_message (cancellable);
355 }
356 
357 void
358 e_mail_store_prepare_for_offline (CamelStore *store,
359                                   gint io_priority,
360                                   GCancellable *cancellable,
361                                   GAsyncReadyCallback callback,
362                                   gpointer user_data)
363 {
364 	GSimpleAsyncResult *simple;
365 
366 	g_return_if_fail (CAMEL_IS_STORE (store));
367 
368 	simple = g_simple_async_result_new (
369 		G_OBJECT (store), callback, user_data,
370 		e_mail_store_prepare_for_offline);
371 
372 	g_simple_async_result_set_check_cancellable (simple, cancellable);
373 
374 	g_simple_async_result_run_in_thread (
375 		simple, (GSimpleAsyncThreadFunc)
376 		mail_store_prepare_for_offline_thread,
377 		io_priority, cancellable);
378 
379 	g_object_unref (simple);
380 }
381 
382 gboolean
383 e_mail_store_prepare_for_offline_finish (CamelStore *store,
384                                          GAsyncResult *result,
385                                          GError **error)
386 {
387 	GSimpleAsyncResult *simple;
388 
389 	g_return_val_if_fail (
390 		g_simple_async_result_is_valid (
391 		result, G_OBJECT (store),
392 		e_mail_store_prepare_for_offline), FALSE);
393 
394 	simple = G_SIMPLE_ASYNC_RESULT (result);
395 
396 	/* Assume success unless a GError is set. */
397 	return !g_simple_async_result_propagate_error (simple, error);
398 }