Commit 0be9b1f8 authored by Matthew Barnes's avatar Matthew Barnes Committed by Rodrigo Moya
Browse files

Adapt to CamelService changes.

parent 7b71f8f1
......@@ -1084,6 +1084,8 @@ composer_build_message (EMsgComposer *composer,
"X-Priority", "1");
if (account != NULL) {
gchar *transport_uid;
/* X-Evolution-Account */
camel_medium_set_header (
CAMEL_MEDIUM (context->message),
......@@ -1095,9 +1097,12 @@ composer_build_message (EMsgComposer *composer,
"X-Evolution-Fcc", account->sent_folder_uri);
/* X-Evolution-Transport */
transport_uid = g_strconcat (
account->uid, "-transport", NULL);
camel_medium_set_header (
CAMEL_MEDIUM (context->message),
"X-Evolution-Transport", account->transport->url);
"X-Evolution-Transport", transport_uid);
g_free (transport_uid);
/* Organization */
if (account->id->organization != NULL) {
......
......@@ -324,9 +324,9 @@ e_get_any_enabled_account (void)
* the global #EAccountList that has transport information, or finally %NULL
* if no transport information could be found.
*
* Returns: an #EAccountService with transport info, or %NULL
* Returns: an #EAccount with transport info, or %NULL
**/
EAccountService *
EAccount *
e_get_default_transport (void)
{
EAccountList *account_list;
......@@ -335,7 +335,7 @@ e_get_default_transport (void)
account = e_get_default_account ();
if (account_has_transport_url (account))
return account->transport;
return account;
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
......@@ -345,7 +345,7 @@ e_get_default_transport (void)
account = (EAccount *) e_iterator_get (iterator);
if (account_has_transport_url (account)) {
g_object_unref (iterator);
return account->transport;
return account;
}
e_iterator_next (iterator);
}
......@@ -385,12 +385,15 @@ e_get_subscribable_accounts (CamelSession *session)
account = (EAccount *) e_iterator_get (iterator);
if (account->enabled) {
CamelService *service;
const gchar *url;
url = e_account_get_string (
account, E_ACCOUNT_SOURCE_URL);
store = (CamelStore *) camel_session_get_service (
session, url, CAMEL_PROVIDER_STORE, NULL);
service = camel_session_get_service (
session, account->uid);
if (CAMEL_IS_STORE (service))
store = CAMEL_STORE (service);
}
e_iterator_next (iterator);
......
......@@ -32,8 +32,7 @@ EAccount * e_get_account_by_uid (const gchar *uid);
EAccount * e_get_account_by_source_url (const gchar *source_url);
EAccount * e_get_account_by_transport_url (const gchar *transport_url);
EAccount * e_get_any_enabled_account (void);
EAccountService *
e_get_default_transport (void);
EAccount * e_get_default_transport (void);
GList * e_get_subscribable_accounts (CamelSession *session);
G_END_DECLS
......
......@@ -68,8 +68,8 @@ e_mail_local_init (EMailSession *session,
g_free (temp);
temp = camel_url_to_string (url, 0);
service = camel_session_get_service (
CAMEL_SESSION (session), temp,
service = camel_session_add_service (
CAMEL_SESSION (session), "local", temp,
CAMEL_PROVIDER_STORE, &local_error);
g_free (temp);
......@@ -90,10 +90,12 @@ e_mail_local_init (EMailSession *session,
/* FIXME camel_store_get_folder() may block. */
default_local_folders[ii].folder_uri = folder_uri;
if (!strcmp (display_name, "Inbox"))
default_local_folders[ii].folder = camel_store_get_inbox_folder_sync (
default_local_folders[ii].folder =
camel_store_get_inbox_folder_sync (
CAMEL_STORE (service), NULL, NULL);
else
default_local_folders[ii].folder = camel_store_get_folder_sync (
default_local_folders[ii].folder =
camel_store_get_folder_sync (
CAMEL_STORE (service), display_name,
CAMEL_STORE_FOLDER_CREATE, NULL, NULL);
}
......
......@@ -94,8 +94,6 @@ GType em_migrate_session_get_type (void);
G_DEFINE_TYPE (EMMigrateSession, em_migrate_session, CAMEL_TYPE_SESSION)
static CamelSession *em_migrate_session_new (const gchar *path);
static void
em_migrate_session_class_init (EMMigrateSessionClass *class)
{
......@@ -106,15 +104,12 @@ em_migrate_session_init (EMMigrateSession *session)
{
}
static CamelSession *
em_migrate_session_new (const gchar *path)
static EMMigrateSession *
em_migrate_session_new (const gchar *user_data_dir)
{
CamelSession *session;
session = g_object_new (EM_TYPE_MIGRATE_SESSION, NULL);
camel_session_construct (session, path);
return session;
return g_object_new (
EM_TYPE_MIGRATE_SESSION,
"user-data-dir", user_data_dir, NULL);
}
static GtkWidget *window;
......@@ -601,7 +596,9 @@ setup_local_store (EShellBackend *shell_backend,
camel_url_set_path (url, tmp);
g_free (tmp);
tmp = camel_url_to_string (url, 0);
store = (CamelStore *)camel_session_get_service (CAMEL_SESSION (session), tmp, CAMEL_PROVIDER_STORE, NULL);
store = (CamelStore *) camel_session_add_service (
CAMEL_SESSION (session), "local", tmp,
CAMEL_PROVIDER_STORE, NULL);
g_free (tmp);
return store;
......@@ -655,7 +652,7 @@ migrate_to_db (EShellBackend *shell_backend)
iter = e_list_get_iterator ((EList *) accounts);
len = e_list_length ((EList *) accounts);
session = (EMMigrateSession *) em_migrate_session_new (data_dir);
session = em_migrate_session_new (data_dir);
camel_session_set_online ((CamelSession *) session, FALSE);
em_migrate_setup_progress_dialog (
_("Migrating Folders"),
......@@ -697,21 +694,16 @@ migrate_to_db (EShellBackend *shell_backend)
while (e_iterator_is_valid (iter)) {
EAccount *account = (EAccount *) e_iterator_get (iter);
EAccountService *service;
const gchar *name;
service = account->source;
name = account->name;
em_migrate_set_progress ( (double)i/(len+1));
if (account->enabled
&& service->url != NULL && service->url[0]
&& strncmp (service->url, "mbox:", 5) != 0) {
e_mail_store_add_by_uri (
mail_session, service->url, name);
store = e_mail_store_add_by_account (
mail_session, account);
store = (CamelStore *) camel_session_get_service (
CAMEL_SESSION (session), service->url,
CAMEL_PROVIDER_STORE, NULL);
info = camel_store_get_folder_info_sync (
store, NULL,
CAMEL_STORE_FOLDER_INFO_RECURSIVE |
......@@ -870,7 +862,8 @@ migrate_stores (struct MigrateStore *ms)
}
static gboolean
migrate_mbox_to_maildir (EShellBackend *shell_backend, EMMigrateSession *session)
migrate_mbox_to_maildir (EShellBackend *shell_backend,
EMMigrateSession *session)
{
CamelService *mbox_service, *maildir_service;
CamelStore *mbox_store, *maildir_store;
......@@ -886,8 +879,8 @@ migrate_mbox_to_maildir (EShellBackend *shell_backend, EMMigrateSession *session
g_free (temp);
temp = camel_url_to_string (url, 0);
mbox_service = camel_session_get_service (
CAMEL_SESSION (session), temp,
mbox_service = camel_session_add_service (
CAMEL_SESSION (session), "local_mbox", temp,
CAMEL_PROVIDER_STORE, NULL);
g_free (temp);
camel_url_free (url);
......@@ -899,8 +892,8 @@ migrate_mbox_to_maildir (EShellBackend *shell_backend, EMMigrateSession *session
g_free (temp);
temp = camel_url_to_string (url, 0);
maildir_service = camel_session_get_service (
CAMEL_SESSION (session), temp,
maildir_service = camel_session_add_service (
CAMEL_SESSION (session), "local", temp,
CAMEL_PROVIDER_STORE, NULL);
g_free (temp);
camel_url_free (url);
......@@ -917,9 +910,6 @@ migrate_mbox_to_maildir (EShellBackend *shell_backend, EMMigrateSession *session
while (!ms.complete)
g_main_context_iteration (NULL, TRUE);
g_object_unref (mbox_store);
g_object_unref (maildir_store);
return TRUE;
}
......@@ -947,7 +937,8 @@ exit:
}
static gboolean
create_mbox_account (EShellBackend *shell_backend, EMMigrateSession *session)
create_mbox_account (EShellBackend *shell_backend,
EMMigrateSession *session)
{
EMailBackend *mail_backend;
EMailSession *mail_session;
......@@ -967,6 +958,9 @@ create_mbox_account (EShellBackend *shell_backend, EMMigrateSession *session)
account = e_account_new ();
account->enabled = TRUE;
g_free (account->uid);
account->uid = g_strdup ("local_mbox");
url = camel_url_new ("mbox:", NULL);
temp = g_build_filename (data_dir, "local_mbox", NULL);
camel_url_set_path (url, temp);
......@@ -1005,7 +999,7 @@ create_mbox_account (EShellBackend *shell_backend, EMMigrateSession *session)
g_free (folder_uri);
e_account_list_add (accounts, account);
e_mail_store_add_by_uri (mail_session, uri, name);
e_mail_store_add_by_account (mail_session, account);
e_account_list_save (accounts);
exit:
......@@ -1042,7 +1036,7 @@ migrate_local_store (EShellBackend *shell_backend)
if (!g_file_test (local_store, G_FILE_TEST_EXISTS))
g_mkdir_with_parents (local_store, 0700);
session = (EMMigrateSession *) em_migrate_session_new (data_dir);
session = em_migrate_session_new (data_dir);
camel_session_set_online (CAMEL_SESSION (session), FALSE);
migrate_mbox_to_maildir (shell_backend, session);
......
......@@ -51,9 +51,8 @@ struct _AsyncContext {
GPtrArray *post_to_uris;
gchar *folder_uri;
gchar *destination;
gchar *message_uid;
gchar *transport_uri;
gchar *transport_uid;
gchar *sent_folder_uri;
};
......@@ -93,9 +92,8 @@ async_context_free (AsyncContext *context)
}
g_free (context->folder_uri);
g_free (context->destination);
g_free (context->message_uid);
g_free (context->transport_uri);
g_free (context->transport_uid);
g_free (context->sent_folder_uri);
g_slice_free (AsyncContext, context);
......@@ -401,36 +399,30 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
/* Send the message to all recipients. */
if (camel_address_length (context->recipients) > 0) {
CamelTransport *transport;
CamelProvider *provider;
CamelService *service;
/* XXX This API does not allow for cancellation. */
transport = camel_session_get_transport (
CAMEL_SESSION (session),
context->transport_uri, &error);
service = camel_session_get_service (
CAMEL_SESSION (session), context->transport_uid);
if (error != NULL) {
g_warn_if_fail (transport == NULL);
g_return_if_fail (CAMEL_IS_TRANSPORT (service));
/* XXX This API does not allow for cancellation. */
if (!camel_service_connect_sync (service, &error)) {
g_simple_async_result_set_from_error (simple, error);
g_error_free (error);
return;
}
g_return_if_fail (CAMEL_IS_TRANSPORT (transport));
service = CAMEL_SERVICE (transport);
provider = camel_service_get_provider (service);
if (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER)
copy_to_sent = FALSE;
camel_transport_send_to_sync (
transport, context->message,
context->from, context->recipients,
cancellable, &error);
g_object_unref (transport);
CAMEL_TRANSPORT (service),
context->message, context->from,
context->recipients, cancellable, &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
......@@ -622,7 +614,6 @@ exit:
void
e_mail_session_send_to (EMailSession *session,
CamelMimeMessage *message,
const gchar *destination,
gint io_priority,
GCancellable *cancellable,
CamelFilterGetFolderFunc get_folder_func,
......@@ -642,7 +633,7 @@ e_mail_session_send_to (EMailSession *session,
struct _camel_header_raw *header;
const gchar *string;
const gchar *resent_from;
gchar *transport_uri = NULL;
gchar *transport_uid = NULL;
gchar *sent_folder_uri = NULL;
GError *error = NULL;
......@@ -668,7 +659,12 @@ e_mail_session_send_to (EMailSession *session,
if (account != NULL) {
if (account->transport != NULL) {
transport_uri = g_strdup (account->transport->url);
/* XXX Transport UIDs are kludgy right now. We
* use the EAccount's regular UID and tack on
* "-transport". Will be better soon. */
transport_uid = g_strconcat (
account->uid, "-transport", NULL);
/* to reprompt password on sending if needed */
account->transport->get_password_canceled = FALSE;
......@@ -677,16 +673,13 @@ e_mail_session_send_to (EMailSession *session,
}
string = camel_header_raw_find (&xev, "X-Evolution-Transport", NULL);
if (transport_uri == NULL && string != NULL)
transport_uri = g_strstrip (g_strdup (string));
if (transport_uid == NULL && string != NULL)
transport_uid = g_strstrip (g_strdup (string));
string = camel_header_raw_find (&xev, "X-Evolution-Fcc", NULL);
if (sent_folder_uri == NULL && string != NULL)
sent_folder_uri = g_strstrip (g_strdup (string));
if (transport_uri == NULL)
transport_uri = g_strdup (destination);
post_to_uris = g_ptr_array_new ();
for (header = xev; header != NULL; header = header->next) {
gchar *folder_uri;
......@@ -751,7 +744,6 @@ e_mail_session_send_to (EMailSession *session,
context = g_slice_new0 (AsyncContext);
context->message = g_object_ref (message);
context->destination = g_strdup (destination);
context->io_priority = io_priority;
context->from = from;
context->recipients = recipients;
......@@ -759,7 +751,7 @@ e_mail_session_send_to (EMailSession *session,
context->info = info;
context->xev = xev;
context->post_to_uris = post_to_uris;
context->transport_uri = transport_uri;
context->transport_uid = transport_uid;
context->sent_folder_uri = sent_folder_uri;
if (G_IS_CANCELLABLE (cancellable))
......@@ -841,7 +833,7 @@ e_mail_session_unsubscribe_folder_sync (EMailSession *session,
GError **error)
{
CamelURL *url;
CamelStore *store;
CamelService *service;
CamelProvider *provider;
const gchar *message;
const gchar *path = NULL;
......@@ -853,16 +845,21 @@ e_mail_session_unsubscribe_folder_sync (EMailSession *session,
message = _("Unsubscribing from folder '%s'");
camel_operation_push_message (cancellable, message, folder_uri);
store = camel_session_get_store (
CAMEL_SESSION (session), folder_uri, error);
if (store == NULL)
goto exit;
url = camel_url_new (folder_uri, error);
if (url == NULL)
goto exit;
provider = camel_service_get_provider (CAMEL_SERVICE (store));
service = camel_session_get_service_by_url (
CAMEL_SESSION (session), url);
if (!CAMEL_IS_STORE (service))
goto exit;
/* FIXME This should take our GCancellable. */
if (!camel_service_connect_sync (service, error))
goto exit;
provider = camel_service_get_provider (service);
if (provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
path = url->fragment;
......@@ -872,7 +869,7 @@ e_mail_session_unsubscribe_folder_sync (EMailSession *session,
g_return_val_if_fail (path != NULL, FALSE);
success = camel_store_unsubscribe_folder_sync (
store, path, cancellable, error);
CAMEL_STORE (service), path, cancellable, error);
camel_url_free (url);
......
......@@ -66,7 +66,6 @@ gboolean e_mail_session_handle_source_headers_finish
GError **error);
void e_mail_session_send_to (EMailSession *session,
CamelMimeMessage *message,
const gchar *destination,
gint io_priority,
GCancellable *cancellable,
CamelFilterGetFolderFunc get_folder_func,
......
......@@ -79,6 +79,7 @@ struct _EMailSessionPrivate {
struct _AsyncContext {
/* arguments */
CamelStoreGetFolderFlags flags;
gchar *uid;
gchar *uri;
/* results */
......@@ -486,6 +487,7 @@ async_context_free (AsyncContext *context)
if (context->folder != NULL)
g_object_unref (context->folder);
g_free (context->uid);
g_free (context->uri);
g_slice_free (AsyncContext, context);
......@@ -608,7 +610,7 @@ mail_session_get_password (CamelSession *session,
url = camel_url_to_string (service_url, CAMEL_URL_HIDE_ALL);
}
if (!strcmp(item, "popb4smtp_uri")) {
if (!strcmp(item, "popb4smtp_uid")) {
/* not 100% mt safe, but should be ok */
if (url
&& (account = e_get_account_by_transport_url (url)))
......@@ -1010,10 +1012,6 @@ e_mail_session_init (EMailSession *session)
/* Initialize the EAccount setup. */
e_account_writable (NULL, E_ACCOUNT_SOURCE_SAVE_PASSWD);
camel_session_construct (
CAMEL_SESSION (session),
mail_session_get_data_dir ());
client = gconf_client_get_default ();
gconf_client_add_dir (
......@@ -1038,7 +1036,13 @@ e_mail_session_init (EMailSession *session)
EMailSession *
e_mail_session_new (void)
{
return g_object_new (E_TYPE_MAIL_SESSION, NULL);
const gchar *user_data_dir;
user_data_dir = mail_session_get_data_dir ();
return g_object_new (
E_TYPE_MAIL_SESSION,
"user-data-dir", user_data_dir, NULL);
}
MailFolderCache *
......@@ -1060,7 +1064,7 @@ mail_session_get_inbox_thread (GSimpleAsyncResult *simple,
context = g_simple_async_result_get_op_res_gpointer (simple);
context->folder = e_mail_session_get_inbox_sync (
session, context->uri, cancellable, &error);
session, context->uid, cancellable, &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
......@@ -1070,32 +1074,31 @@ mail_session_get_inbox_thread (GSimpleAsyncResult *simple,
CamelFolder *
e_mail_session_get_inbox_sync (EMailSession *session,
const gchar *service_uri,
const gchar *service_uid,
GCancellable *cancellable,
GError **error)
{
CamelStore *store;
CamelFolder *folder;
CamelService *service;
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (service_uri != NULL, NULL);
g_return_val_if_fail (service_uid != NULL, NULL);
store = camel_session_get_store (
CAMEL_SESSION (session), service_uri, error);
service = camel_session_get_service (
CAMEL_SESSION (session), service_uid);
if (store == NULL)
if (!CAMEL_IS_STORE (service))
return NULL;
folder = camel_store_get_inbox_folder_sync (store, cancellable, error);
g_object_unref (store);
if (!camel_service_connect_sync (service, error))
return NULL;
return folder;
return camel_store_get_inbox_folder_sync (
CAMEL_STORE (service), cancellable, error);
}
void
e_mail_session_get_inbox (EMailSession *session,
const gchar *service_uri,
const gchar *service_uid,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -1105,10 +1108,10 @@ e_mail_session_get_inbox (EMailSession *session,
AsyncContext *context;
g_return_if_fail (E_IS_MAIL_SESSION (session));
g_return_if_fail (service_uri != NULL);
g_return_if_fail (service_uid != NULL);
context = g_slice_new0 (AsyncContext);
context->uri = g_strdup (service_uri);
context->uid = g_strdup (service_uid);
simple = g_simple_async_result_new (
G_OBJECT (session), callback,
......@@ -1160,7 +1163,7 @@ mail_session_get_trash_thread (GSimpleAsyncResult *simple,
context = g_simple_async_result_get_op_res_gpointer (simple);
context->folder = e_mail_session_get_trash_sync (
session, context->uri, cancellable, &error);
session, context->uid, cancellable, &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
......@@ -1170,32 +1173,31 @@ mail_session_get_trash_thread (GSimpleAsyncResult *simple,
CamelFolder *
e_mail_session_get_trash_sync (EMailSession *session,
const gchar *service_uri,
const gchar *service_uid,
GCancellable *cancellable,
GError **error)
{
CamelStore *store;
CamelFolder *folder;
CamelService *service;
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (service_uri != NULL, NULL);
g_return_val_if_fail (service_uid != NULL, NULL);
store = camel_session_get_store (
CAMEL_SESSION (session), service_uri, error);
service = camel_session_get_service (
CAMEL_SESSION (session), service_uid);
if (store == NULL)
if (!CAMEL_IS_STORE (service))
return NULL;
folder = camel_store_get_trash_folder_sync (store, cancellable, error);
g_object_unref (store);
if (!camel_service_connect_sync (service, error))
return NULL;
return folder;
return camel_store_get_trash_folder_sync (
CAMEL_STORE (service), cancellable, error);
}
void
e_mail_session_get_trash (EMailSession *session,
const gchar *service_uri,
const gchar *service_uid,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -1205,10 +1207,10 @@ e_mail_session_get_trash (EMailSession *session,
AsyncContext *context;
g_return_if_fail (E_IS_MAIL_SESSION (session));
g_return_if_fail (service_uri != NULL);
g_return_if_fail (service_uid != NULL);
context = g_slice_new0 (AsyncContext);
context->uri = g_strdup (service_uri);
context->uid = g_strdup (service_uid);
simple = g_simple_async_result_new (
G_OBJECT (session), callback,
......@@ -1277,7 +1279,7 @@ e_mail_session_uri_to_folder_sync (EMailSession *session,
GError **error)
{
CamelURL *url;
CamelStore *store;
CamelService *service;
CamelFolder *folder = NULL;