void e_mail_store_remove_by_account (EMailBackend *backend, EAccount *account) { EMailSession *session; CamelService *service; CamelProvider *provider; const gchar *uid; g_return_if_fail (E_IS_MAIL_BACKEND (backend)); g_return_if_fail (E_IS_ACCOUNT (account)); uid = account->uid; session = e_mail_backend_get_session (backend); service = camel_session_get_service (CAMEL_SESSION (session), uid); g_return_if_fail (CAMEL_IS_STORE (service)); provider = camel_service_get_provider (service); g_return_if_fail (provider != NULL); if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) return; e_mail_store_remove (backend, CAMEL_STORE (service)); }
static CamelService * get_service_for_source (CamelSession *session, const gchar *src) { CamelService *service = NULL; /* Source strings are now CamelService UIDs. */ if (src != NULL) service = camel_session_get_service (session, src); /* For backward-compability, also handle CamelService URLs. */ if (service == NULL && src != NULL) { CamelURL *url; url = camel_url_new (src, NULL); if (service == NULL && url != NULL) service = camel_session_get_service_by_url ( session, url, CAMEL_PROVIDER_STORE); if (service == NULL && url != NULL) service = camel_session_get_service_by_url ( session, url, CAMEL_PROVIDER_TRANSPORT); if (url != NULL) camel_url_free (url); } return service; }
static void mc_setup_local_store(MailComponent *mc) { MailComponentPrivate *p = mc->priv; CamelURL *url; char *tmp; CamelException ex; int i; g_mutex_lock(p->lock); if (p->local_store != NULL) { g_mutex_unlock(p->lock); return; } camel_exception_init(&ex); url = camel_url_new("mbox:", NULL); tmp = g_build_filename (p->base_directory, "local", NULL); camel_url_set_path(url, tmp); g_free(tmp); tmp = camel_url_to_string(url, 0); p->local_store = (CamelStore *)camel_session_get_service(session, tmp, CAMEL_PROVIDER_STORE, &ex); g_free(tmp); if (p->local_store == NULL) goto fail; for (i=0;i<sizeof(mc_default_folders)/sizeof(mc_default_folders[0]);i++) { /* FIXME: should this uri be account relative? */ camel_url_set_fragment(url, mc_default_folders[i].name); mc_default_folders[i].uri = camel_url_to_string(url, 0); mc_default_folders[i].folder = camel_store_get_folder(p->local_store, mc_default_folders[i].name, CAMEL_STORE_FOLDER_CREATE, &ex); camel_exception_clear(&ex); } camel_url_free(url); g_mutex_unlock(p->lock); g_object_ref(mc); camel_object_ref(p->local_store); mail_async_event_emit(p->async_event, MAIL_ASYNC_GUI, (MailAsyncFunc)mc_add_local_store, p->local_store, _("On This Computer"), mc); return; fail: g_mutex_unlock(p->lock); g_warning("Could not setup local store/folder: %s", ex.desc); camel_url_free(url); camel_exception_clear(&ex); }
/** * camel_session_get_service_connected: * @session: a #CamelSession object * @url_string: a #CamelURL describing the service to get * @type: the provider type * @ex: a #CamelException * * This works like #camel_session_get_service, but also ensures that * the returned service will have been successfully connected (via * #camel_service_connect.) * * Returns the requested #CamelService, or %NULL **/ CamelService * camel_session_get_service_connected (CamelSession *session, const char *url_string, CamelProviderType type, CamelException *ex) { CamelService *svc; svc = camel_session_get_service (session, url_string, type, ex); if (svc == NULL) return NULL; if (svc->status != CAMEL_SERVICE_CONNECTED) { if (camel_service_connect (svc, ex) == FALSE) { camel_object_unref (svc); return NULL; } } return svc; }
CamelFolder * mail_tool_get_trash (const gchar *url, int connect, CamelException *ex) { CamelStore *store; CamelFolder *trash; if (connect) store = camel_session_get_store (session, url, ex); else store = (CamelStore *) camel_session_get_service (session, url, CAMEL_PROVIDER_STORE, ex); if (!store) return NULL; if (connect || ((CamelService *) store)->status == CAMEL_SERVICE_CONNECTED) trash = camel_store_get_trash (store, ex); else trash = NULL; camel_object_unref (store); return trash; }
static void mail_session_send_to_thread (GSimpleAsyncResult *simple, EMailSession *session, GCancellable *cancellable) { AsyncContext *context; CamelFolder *local_sent_folder; GString *error_messages; gboolean copy_to_sent = TRUE; guint ii; GError *error = NULL; context = g_simple_async_result_get_op_res_gpointer (simple); /* Send the message to all recipients. */ if (camel_address_length (context->recipients) > 0) { CamelProvider *provider; CamelService *service; gboolean did_connect = FALSE; service = camel_session_get_service ( CAMEL_SESSION (session), context->transport_uid); if (!CAMEL_IS_TRANSPORT (service)) { g_simple_async_result_set_error (simple, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_URL_INVALID, _("Cannot get transport for account '%s'"), context->transport_uid); return; } if (camel_service_get_connection_status (service) != CAMEL_SERVICE_CONNECTED) { did_connect = TRUE; /* XXX This API does not allow for cancellation. */ if (!em_utils_connect_service_sync (service, cancellable, &error)) { g_simple_async_result_take_error (simple, error); return; } } provider = camel_service_get_provider (service); if (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER) copy_to_sent = FALSE; camel_transport_send_to_sync ( CAMEL_TRANSPORT (service), context->message, context->from, context->recipients, cancellable, &error); if (did_connect) em_utils_disconnect_service_sync ( service, error == NULL, cancellable, error ? NULL : &error); if (error != NULL) { g_simple_async_result_take_error (simple, error); return; } } /* Post the message to requested folders. */ for (ii = 0; ii < context->post_to_uris->len; ii++) { CamelFolder *folder; const gchar *folder_uri; folder_uri = g_ptr_array_index (context->post_to_uris, ii); folder = e_mail_session_uri_to_folder_sync ( session, folder_uri, 0, cancellable, &error); if (error != NULL) { g_warn_if_fail (folder == NULL); g_simple_async_result_take_error (simple, error); return; } g_return_if_fail (CAMEL_IS_FOLDER (folder)); camel_folder_append_message_sync ( folder, context->message, context->info, NULL, cancellable, &error); g_object_unref (folder); if (error != NULL) { g_simple_async_result_take_error (simple, error); return; } } /*** Post Processing ***/ /* This accumulates error messages during post-processing. */ error_messages = g_string_sized_new (256); mail_tool_restore_xevolution_headers (context->message, context->xev); /* Run filters on the outgoing message. */ if (context->driver != NULL) { camel_filter_driver_filter_message ( context->driver, context->message, context->info, NULL, NULL, NULL, "", cancellable, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto exit; if (error != NULL) { g_string_append_printf ( error_messages, _("Failed to apply outgoing filters: %s"), error->message); g_clear_error (&error); } } if (!copy_to_sent) goto cleanup; /* Append the sent message to a Sent folder. */ local_sent_folder = e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_SENT); /* Try to extract a CamelFolder from the Sent folder URI. */ if (context->sent_folder_uri != NULL) { context->sent_folder = e_mail_session_uri_to_folder_sync ( session, context->sent_folder_uri, 0, cancellable, &error); if (error != NULL) { g_warn_if_fail (context->sent_folder == NULL); if (error_messages->len > 0) g_string_append (error_messages, "\n\n"); g_string_append_printf ( error_messages, _("Failed to append to %s: %s\n" "Appending to local 'Sent' folder instead."), context->sent_folder_uri, error->message); g_clear_error (&error); } } /* Fall back to the local Sent folder. */ if (context->sent_folder == NULL) context->sent_folder = g_object_ref (local_sent_folder); /* Append the message. */ camel_folder_append_message_sync ( context->sent_folder, context->message, context->info, NULL, cancellable, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto exit; if (error == NULL) goto cleanup; /* If appending to a remote Sent folder failed, * try appending to the local Sent folder. */ if (context->sent_folder != local_sent_folder) { const gchar *description; description = camel_folder_get_description ( context->sent_folder); if (error_messages->len > 0) g_string_append (error_messages, "\n\n"); g_string_append_printf ( error_messages, _("Failed to append to %s: %s\n" "Appending to local 'Sent' folder instead."), description, error->message); g_clear_error (&error); camel_folder_append_message_sync ( local_sent_folder, context->message, context->info, NULL, cancellable, &error); } if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto exit; /* We can't even append to the local Sent folder? * In that case just leave the message in Outbox. */ if (error != NULL) { if (error_messages->len > 0) g_string_append (error_messages, "\n\n"); g_string_append_printf ( error_messages, _("Failed to append to local 'Sent' folder: %s"), error->message); g_clear_error (&error); goto exit; } cleanup: /* The send operation was successful; ignore cleanup errors. */ /* Mark the draft message for deletion, if present. */ e_mail_session_handle_draft_headers_sync ( session, context->message, cancellable, &error); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } /* Set flags on the original source message, if present. * Source message refers to the message being forwarded * or replied to. */ e_mail_session_handle_source_headers_sync ( session, context->message, cancellable, &error); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } exit: /* If we were cancelled, disregard any other errors. */ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_simple_async_result_take_error (simple, error); /* Stuff the accumulated error messages in a GError. */ } else if (error_messages->len > 0) { g_simple_async_result_set_error ( simple, E_MAIL_ERROR, E_MAIL_ERROR_POST_PROCESSING, "%s", error_messages->str); } /* Synchronize the Sent folder. */ if (context->sent_folder != NULL) camel_folder_synchronize_sync ( context->sent_folder, FALSE, cancellable, NULL); g_string_free (error_messages, TRUE); }
CamelFolder * mail_tool_uri_to_folder (const char *uri, guint32 flags, CamelException *ex) { CamelURL *url; CamelStore *store = NULL; CamelFolder *folder = NULL; int offset = 0; char *curi = NULL; g_return_val_if_fail (uri != NULL, NULL); /* TODO: vtrash and vjunk are no longer used for these uri's */ if (!strncmp (uri, "vtrash:", 7)) offset = 7; else if (!strncmp (uri, "vjunk:", 6)) offset = 6; else if (!strncmp(uri, "email:", 6)) { /* FIXME?: the filter:get_folder callback should do this itself? */ curi = em_uri_to_camel(uri); if (uri == NULL) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Invalid folder: `%s'"), uri); return NULL; } uri = curi; } url = camel_url_new (uri + offset, ex); if (!url) { g_free(curi); return NULL; } store = (CamelStore *)camel_session_get_service(session, uri+offset, CAMEL_PROVIDER_STORE, ex); if (store) { const char *name; /* if we have a fragment, then the path is actually used by the store, so the fragment is the path to the folder instead */ if (url->fragment) { name = url->fragment; } else { if (url->path && *url->path) name = url->path + 1; else name = ""; } if (offset) { if (offset == 7) folder = camel_store_get_trash (store, ex); else if (offset == 6) folder = camel_store_get_junk (store, ex); } else folder = camel_store_get_folder (store, name, flags, ex); camel_object_unref (store); } if (folder) mail_note_folder (folder); camel_url_free (url); g_free(curi); return folder; }