+typedef struct
+{
+ TpAccount *new_account;
+ TpAccount *old_account;
+ gboolean enabled;
+} UoaMigrationData;
+
+static UoaMigrationData *
+uoa_migration_data_new (TpAccount *account)
+{
+ UoaMigrationData *data;
+
+ data = g_slice_new0 (UoaMigrationData);
+ data->old_account = g_object_ref (account);
+ data->enabled = tp_account_is_enabled (account);
+
+ return data;
+}
+
+static void
+uoa_migration_data_free (UoaMigrationData *data)
+{
+ g_clear_object (&data->new_account);
+ g_clear_object (&data->old_account);
+ g_slice_free (UoaMigrationData, data);
+}
+
+static void
+uoa_migration_done (UoaMigrationData *data)
+{
+ tp_account_remove_async (data->old_account, NULL, NULL);
+ tp_account_set_enabled_async (data->new_account, data->enabled, NULL, NULL);
+}
+
+static void
+uoa_set_account_password_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ UoaMigrationData *data = user_data;
+ GError *error = NULL;
+
+ if (!empathy_keyring_set_account_password_finish (data->new_account, result,
+ &error))
+ {
+ DEBUG ("Error setting old account's password on the new one: %s\n",
+ error->message);
+ g_clear_error (&error);
+ }
+
+ uoa_migration_done (data);
+}
+
+static void
+uoa_get_account_password_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ UoaMigrationData *data = user_data;
+ const gchar *password;
+ GError *error = NULL;
+
+ password = empathy_keyring_get_account_password_finish (data->old_account,
+ result, &error);
+ if (password == NULL)
+ {
+ DEBUG ("Error getting old account's password: %s\n", error->message);
+ g_clear_error (&error);
+
+ uoa_migration_done (data);
+ }
+ else
+ {
+ empathy_keyring_set_account_password_async (data->new_account, password,
+ TRUE, uoa_set_account_password_cb, data);
+ }
+}
+