Esempio n. 1
0
static void
mail_store_prepare_for_offline_thread (GSimpleAsyncResult *simple,
                                       CamelStore *store,
                                       GCancellable *cancellable)
{
	CamelService *service;
	gchar *service_name;
	GError *error = NULL;

	service = CAMEL_SERVICE (store);

	service_name = camel_service_get_name (service, TRUE);
	camel_operation_push_message (
		cancellable, _("Preparing account '%s' for offline"),
		service_name);
	g_free (service_name);

	if (CAMEL_IS_DISCO_STORE (store))
		camel_disco_store_prepare_for_offline (
			CAMEL_DISCO_STORE (store), cancellable, &error);

	else if (CAMEL_IS_OFFLINE_STORE (store))
		camel_offline_store_prepare_for_offline_sync (
			CAMEL_OFFLINE_STORE (store), cancellable, &error);

	if (error != NULL)
		g_simple_async_result_take_error (simple, error);

	camel_operation_pop_message (cancellable);
}
Esempio n. 2
0
static void
mail_store_go_offline_thread (GSimpleAsyncResult *simple,
                              CamelStore *store,
                              GCancellable *cancellable)
{
	CamelService *service;
	gchar *service_name;
	GError *error = NULL;

	service = CAMEL_SERVICE (store);

	service_name = camel_service_get_name (service, TRUE);
	camel_operation_push_message (
		cancellable, _("Disconnecting from '%s'"), service_name);
	g_free (service_name);

	if (CAMEL_IS_DISCO_STORE (store)) {
		CamelDiscoStore *disco_store;

		disco_store = CAMEL_DISCO_STORE (store);

		if (camel_disco_store_can_work_offline (disco_store))
			camel_disco_store_set_status (
				disco_store, CAMEL_DISCO_STORE_OFFLINE,
				cancellable, &error);
		else
			em_utils_disconnect_service_sync (service, TRUE, cancellable, &error);

	} else if (CAMEL_IS_OFFLINE_STORE (store)) {
		CamelOfflineStore *offline_store;

		offline_store = CAMEL_OFFLINE_STORE (store);

		camel_offline_store_set_online_sync (
			offline_store, FALSE, cancellable, &error);

	} else
		em_utils_disconnect_service_sync (service, TRUE, cancellable, &error);

	if (error != NULL)
		g_simple_async_result_take_error (simple, error);

	camel_operation_pop_message (cancellable);
}
CamelImapResponse *
imap_read_response (CamelImapStore *store, CamelException *ex)
{
	CamelImapResponse *response;
	CamelImapResponseType type;
	char *respbuf, *p;

	/* Get another lock so that when we reach the tagged
	 * response and camel_imap_command_response unlocks,
	 * we're still locked. This lock is owned by response
	 * and gets unlocked when response is freed.
	 */
	CAMEL_SERVICE_REC_LOCK (store, connect_lock);

	response = g_new0 (CamelImapResponse, 1);
	if (store->current_folder && camel_disco_store_status (CAMEL_DISCO_STORE (store)) != CAMEL_DISCO_STORE_RESYNCING) {
		response->folder = store->current_folder;
		camel_object_ref (CAMEL_OBJECT (response->folder));
	}

	response->untagged = g_ptr_array_new ();
	while ((type = camel_imap_command_response (store, &respbuf, ex))
	       == CAMEL_IMAP_RESPONSE_UNTAGGED)
		g_ptr_array_add (response->untagged, respbuf);

	if (type == CAMEL_IMAP_RESPONSE_ERROR) {
		camel_imap_response_free_without_processing (store, response);
		return NULL;
	}

	response->status = respbuf;

	/* Check for OK or continuation response. */
	if (*respbuf == '+')
		return response;
	p = strchr (respbuf, ' ');
	if (p && !g_ascii_strncasecmp (p, " OK", 3))
		return response;

	/* We should never get BAD, or anything else but +, OK, or NO
	 * for that matter.  Well, we could get BAD, treat as NO.
	 */
	if (!p || (g_ascii_strncasecmp(p, " NO", 3) != 0 && g_ascii_strncasecmp(p, " BAD", 4)) ) {
		g_warning ("Unexpected response from IMAP server: %s",
			   respbuf);
		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
				      _("Unexpected response from IMAP "
					"server: %s"), respbuf);
		camel_imap_response_free_without_processing (store, response);
		return NULL;
	}

	p += 3;
	if (!*p++)
		p = NULL;
	camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_INVALID,
			      _("IMAP command failed: %s"),
			      p ? p : _("Unknown error"));
	camel_imap_response_free_without_processing (store, response);
	return NULL;
}