Commit ec170e47 authored by Matthew Barnes's avatar Matthew Barnes

Move more account utilities to e-account-utils.c.

parent e555c2bf
......@@ -32,7 +32,6 @@
#include <libedataserver/e-account-list.h>
#include "mail-view.h"
#include "e-util/e-config.h"
#include "mail/mail-config.h"
#include "mail/e-mail-session.h"
#include "mail-guess-servers.h"
......
......@@ -28,7 +28,6 @@
#include "mail-settings-view.h"
#include <libedataserver/e-account-list.h>
#include "mail-view.h"
#include "mail/mail-config.h"
#include <e-util/e-account-utils.h>
struct _MailSettingsViewPrivate {
......
......@@ -1284,7 +1284,7 @@ AC_SUBST(CERT_UI_LIBS)
dnl ************
dnl E_UTIL Flags
dnl ************
EVO_SET_COMPILE_FLAGS(E_UTIL, $LIBEDATASERVERUI camel-1.2 $mozilla_nspr, $MANUAL_NSPR_CFLAGS $MANUAL_NSPR_LIBS)
EVO_SET_COMPILE_FLAGS(E_UTIL, $LIBEDATASERVERUI camel-provider-1.2 $mozilla_nspr, $MANUAL_NSPR_CFLAGS $MANUAL_NSPR_LIBS)
AC_SUBST(E_UTIL_CFLAGS)
AC_SUBST(E_UTIL_LIBS)
......
......@@ -435,6 +435,10 @@ e_get_default_account
e_set_default_account
e_get_account_by_name
e_get_account_by_uid
e_get_account_by_source_url
e_get_account_by_transport_url
e_get_any_enabled_account
e_get_default_transport
</SECTION>
<SECTION>
......
......@@ -64,3 +64,39 @@ Mail Accounts
@Returns:
<!-- ##### FUNCTION e_get_account_by_source_url ##### -->
<para>
</para>
@source_url:
@Returns:
<!-- ##### FUNCTION e_get_account_by_transport_url ##### -->
<para>
</para>
@transport_url:
@Returns:
<!-- ##### FUNCTION e_get_any_enabled_account ##### -->
<para>
</para>
@void:
@Returns:
<!-- ##### FUNCTION e_get_default_transport ##### -->
<para>
</para>
@void:
@Returns:
......@@ -22,10 +22,31 @@
#include "e-account-utils.h"
#include <camel/camel.h>
#include <gconf/gconf-client.h>
static EAccountList *global_account_list;
static gboolean
account_has_source_url (EAccount *account)
{
return (account != NULL) &&
(account->enabled) &&
(account->source != NULL) &&
(account->source->url != NULL) &&
(account->source->url[0] != '\0');
}
static gboolean
account_has_transport_url (EAccount *account)
{
return (account != NULL) &&
(account->enabled) &&
(account->transport != NULL) &&
(account->transport->url != NULL) &&
(account->transport->url[0] != '\0');
}
/**
* e_get_account_list:
*
......@@ -138,6 +159,122 @@ e_get_account_by_uid (const gchar *uid)
return (EAccount *) account;
}
/**
* e_get_account_by_source_url:
* @source_url: a source URL
*
* Returns the #EAccount with the given source URL, or %NULL if no such
* account exists.
*
* Returns: an #EAccount having the given source URL, or %NULL
**/
EAccount *
e_get_account_by_source_url (const gchar *source_url)
{
EAccountList *account_list;
EAccount *account = NULL;
EIterator *iterator;
CamelProvider *provider;
CamelURL *source_curl;
g_return_val_if_fail (source_url != NULL, NULL);
source_curl = camel_url_new (source_url, NULL);
g_return_val_if_fail (source_curl != NULL, NULL);
provider = camel_provider_get (source_url, NULL);
g_return_val_if_fail (provider != NULL, NULL);
g_return_val_if_fail (provider->url_equal != NULL, NULL);
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
while (account == NULL && e_iterator_is_valid (iterator)) {
EAccount *candidate;
CamelURL *curl;
/* XXX EIterator misuses const. */
candidate = (EAccount *) e_iterator_get (iterator);
e_iterator_next (iterator);
if (!account_has_source_url (candidate))
continue;
curl = camel_url_new (candidate->source->url, NULL);
if (curl == NULL)
continue;
if (provider->url_equal (curl, source_curl))
account = candidate;
camel_url_free (curl);
}
g_object_unref (iterator);
camel_url_free (source_curl);
return account;
}
/**
* e_get_account_by_transport_url:
* @transport_url: a transport URL
*
* Returns the #EAccount with the given transport URL, or %NULL if no
* such account exists.
*
* Returns: an #EAccount having the given transport URL, or %NULL
**/
EAccount *
e_get_account_by_transport_url (const gchar *transport_url)
{
EAccountList *account_list;
EAccount *account = NULL;
EIterator *iterator;
CamelProvider *provider;
CamelURL *transport_curl;
g_return_val_if_fail (transport_url != NULL, NULL);
transport_curl = camel_url_new (transport_url, NULL);
g_return_val_if_fail (transport_curl != NULL, NULL);
provider = camel_provider_get (transport_url, NULL);
g_return_val_if_fail (provider != NULL, NULL);
g_return_val_if_fail (provider->url_equal != NULL, NULL);
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
while (account == NULL && e_iterator_is_valid (iterator)) {
EAccount *candidate;
CamelURL *curl;
/* XXX EIterator misuses const. */
candidate = (EAccount *) e_iterator_get (iterator);
e_iterator_next (iterator);
if (!account_has_transport_url (candidate))
continue;
curl = camel_url_new (candidate->transport->url, NULL);
if (curl == NULL)
continue;
if (provider->url_equal (curl, transport_curl))
account = candidate;
camel_url_free (curl);
}
g_object_unref (iterator);
camel_url_free (transport_curl);
return account;
}
/**
* e_get_any_enabled_account:
*
......@@ -179,3 +316,42 @@ e_get_any_enabled_account (void)
return account;
}
/**
* e_get_default_transport:
*
* Returns transport information for the default account if it's enabled and
* has transport information, or else from the first enabled mail account in
* 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
**/
EAccountService *
e_get_default_transport (void)
{
EAccountList *account_list;
EAccount *account;
EIterator *iterator;
account = e_get_default_account ();
if (account_has_transport_url (account))
return account->transport;
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
while (e_iterator_is_valid (iterator)) {
/* XXX EIterator misuses const. */
account = (EAccount *) e_iterator_get (iterator);
if (account_has_transport_url (account)) {
g_object_unref (iterator);
return account->transport;
}
e_iterator_next (iterator);
}
g_object_unref (iterator);
return NULL;
}
......@@ -18,7 +18,6 @@
#ifndef E_ACCOUNT_UTILS_H
#define E_ACCOUNT_UTILS_H
#include <glib.h>
#include <libedataserver/e-account.h>
#include <libedataserver/e-account-list.h>
......@@ -29,7 +28,11 @@ EAccount * e_get_default_account (void);
void e_set_default_account (EAccount *account);
EAccount * e_get_account_by_name (const gchar *name);
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);
G_END_DECLS
......
......@@ -61,7 +61,6 @@
#include "e-mail-store.h"
#include "e-mail-backend.h"
#include "mail-config.h"
#include "em-utils.h"
#define d(x) x
......
......@@ -38,7 +38,6 @@
#include "mail/em-format-html-print.h"
#include "mail/em-utils.h"
#include "mail/mail-autofilter.h"
#include "mail/mail-config.h"
#include "mail/mail-ops.h"
#include "mail/mail-tools.h"
#include "mail/mail-vfolder.h"
......
......@@ -47,7 +47,6 @@
#include "mail/em-folder-tree.h"
#include "mail/em-utils.h"
#include "mail/mail-autofilter.h"
#include "mail/mail-config.h"
#include "mail/mail-ops.h"
#include "mail/mail-mt.h"
#include "mail/mail-vfolder.h"
......
......@@ -47,6 +47,7 @@
#include <libedataserver/e-flag.h>
#include "e-util/e-util.h"
#include "e-util/e-account-utils.h"
#include "e-util/e-alert-dialog.h"
#include "e-util/e-util-private.h"
......@@ -602,7 +603,7 @@ mail_session_get_password (CamelSession *session,
if (!strcmp(item, "popb4smtp_uri")) {
/* not 100% mt safe, but should be ok */
if (url
&& (account = mail_config_get_account_by_transport_url (url)))
&& (account = e_get_account_by_transport_url (url)))
ret = g_strdup (account->source->url);
else
ret = g_strdup (url);
......@@ -618,9 +619,9 @@ mail_session_get_password (CamelSession *session,
gboolean remember;
if (url) {
if ((account = mail_config_get_account_by_source_url (url)))
if ((account = e_get_account_by_source_url (url)))
config_service = account->source;
else if ((account = mail_config_get_account_by_transport_url (url)))
else if ((account = e_get_account_by_transport_url (url)))
config_service = account->transport;
}
......
......@@ -64,7 +64,6 @@
#include "em-account-editor.h"
#include "mail-send-recv.h"
#include "em-utils.h"
#include "mail-config.h"
#include "mail-ops.h"
#include "mail-mt.h"
......
......@@ -35,7 +35,6 @@
#include "mail-mt.h"
#include "mail-ops.h"
#include "mail-tools.h"
#include "mail-config.h"
#include "mail-send-recv.h"
#include "e-util/e-account-utils.h"
......@@ -816,7 +815,7 @@ create_new_composer (EShell *shell,
if (from_uri != NULL) {
GList *list;
account = mail_config_get_account_by_source_url (from_uri);
account = e_get_account_by_source_url (from_uri);
list = g_list_prepend (NULL, (gpointer) from_uri);
e_composer_header_table_set_post_to_list (table, list);
......@@ -881,7 +880,7 @@ em_utils_compose_new_message_with_mailto (EShell *shell,
table = e_msg_composer_get_header_table (composer);
if (from_uri
&& (account = mail_config_get_account_by_source_url (from_uri)))
&& (account = e_get_account_by_source_url (from_uri)))
e_composer_header_table_set_account_name (table, account->name);
composer_set_no_change (composer);
......
......@@ -39,7 +39,6 @@
#include "mail-ops.h"
#include "mail-mt.h"
#include "mail-vfolder.h"
#include "mail-config.h"
struct _prop_data {
gpointer object;
......
......@@ -27,8 +27,8 @@
#include <string.h>
#include <glib/gi18n.h>
#include <e-util/e-util.h>
#include <e-util/e-account-utils.h>
#include "mail-config.h"
#include "em-folder-tree.h"
#include "em-folder-selector.h"
#include "em-utils.h"
......@@ -100,7 +100,7 @@ folder_selection_button_set_contents (EMFolderSelectionButton *button)
return;
}
account = mail_config_get_account_by_source_url (uri);
account = e_get_account_by_source_url (uri);
if (account != NULL) {
gchar *tmp = folder_name;
......
......@@ -35,7 +35,6 @@
#include <glib/gi18n.h>
#include "mail-config.h"
#include "mail-tools.h"
#include "mail-mt.h"
#include "mail-ops.h"
......@@ -1073,7 +1072,7 @@ em_folder_tree_model_add_store (EMFolderTreeModel *model,
uri = camel_url_to_string (
((CamelService *) store)->url, CAMEL_URL_HIDE_ALL);
account = mail_config_get_account_by_source_url (uri);
account = e_get_account_by_source_url (uri);
/* Add the store to the tree. */
gtk_tree_store_append (tree_store, &iter, NULL);
......
......@@ -52,7 +52,6 @@
#include "mail-mt.h"
#include "mail-ops.h"
#include "mail-tools.h"
#include "mail-config.h"
#include "mail-send-recv.h"
#include "mail-vfolder.h"
......@@ -2548,7 +2547,7 @@ em_folder_tree_set_selected_list (EMFolderTree *folder_tree,
/* This makes sure all our parents up to the root are
* expanded. FIXME: Why does the expanded state store
* this made up path rather than the euri? */
if ((account = mail_config_get_account_by_source_url (u->uri)))
if ((account = e_get_account_by_source_url (u->uri)))
expand_key = g_strdup_printf ("%s/%s", account->uid, path);
else if (CAMEL_IS_VEE_STORE (u->store))
expand_key = g_strdup_printf ("vfolder/%s", path);
......
......@@ -48,7 +48,6 @@
#include "mail-mt.h"
#include "mail-ops.h"
#include "mail-tools.h"
#include "mail-config.h"
#include "mail-vfolder.h"
#include "mail-folder-cache.h"
......
......@@ -55,8 +55,6 @@
#include "e-cert-db.h"
#endif
#include "mail-config.h"
#include "e-mail-display.h"
#include "e-mail-attachment-bar.h"
#include "em-format-html-display.h"
......
......@@ -53,7 +53,6 @@
#include "mail-mt.h"
#include "mail-ops.h"
#include "mail-tools.h"
#include "mail-config.h"
#include "e-mail-tag-editor.h"
#include <libedataserver/e-data-server-util.h>
......@@ -1398,7 +1397,7 @@ gchar *em_uri_from_camel (const gchar *curi)
if (strcmp(curl->protocol, "vfolder") == 0)
uid = "vfolder@local";
else if ((account = mail_config_get_account_by_source_url (curi)) == NULL)
else if ((account = e_get_account_by_source_url (curi)) == NULL)
uid = "local@local";
else
uid = account->uid;
......@@ -2081,7 +2080,7 @@ guess_account_from_folder (CamelFolder *folder)
service = CAMEL_SERVICE (parent_store);
source_url = camel_url_to_string (service->url, CAMEL_URL_HIDE_ALL);
account = mail_config_get_account_by_source_url (source_url);
account = e_get_account_by_source_url (source_url);
g_free (source_url);
return account;
......@@ -2096,7 +2095,7 @@ guess_account_from_message (CamelMimeMessage *message)
if (source_url == NULL)
return NULL;
return mail_config_get_account_by_source_url (source_url);
return e_get_account_by_source_url (source_url);
}
GHashTable *
......
......@@ -283,119 +283,6 @@ mail_config_get_sync_timeout (void)
return res;
}
static EAccount *
mc_get_account_by (const gchar *given_url, const gchar * (get_url_string)(EAccount *account))
{
EAccountList *account_list;
EAccount *account = NULL;
EIterator *iter;
CamelURL *url;
CamelProvider *provider;
g_return_val_if_fail (given_url != NULL, NULL);
g_return_val_if_fail (get_url_string != NULL, NULL);
url = camel_url_new (given_url, NULL);
g_return_val_if_fail (url != NULL, NULL);
provider = camel_provider_get (given_url, NULL);
g_return_val_if_fail (provider != NULL && provider->url_equal != NULL, NULL);
account_list = e_get_account_list ();
iter = e_list_get_iterator ((EList *) account_list);
while (account == NULL && e_iterator_is_valid (iter)) {
CamelURL *account_url;
const gchar *account_url_string;
account = (EAccount *) e_iterator_get (iter);
e_iterator_next (iter);
account_url_string = get_url_string (account);
if ( !account_url_string || !*account_url_string) {
account = NULL;
continue;
}
account_url = camel_url_new (account_url_string, NULL);
if (account_url == NULL) {
account = NULL;
continue;
}
if (!provider->url_equal (url, account_url))
account = NULL; /* not a match */
camel_url_free (account_url);
}
g_object_unref (iter);
camel_url_free (url);
return account;
}
static const gchar *
get_source_url_string (EAccount *account)
{
if (account && account->source && account->source->url && *account->source->url)
return account->source->url;
return NULL;
}
static const gchar *
get_transport_url_string (EAccount *account)
{
if (account && account->transport && account->transport->url && *account->transport->url)
return account->transport->url;
return NULL;
}
EAccount *
mail_config_get_account_by_source_url (const gchar *source_url)
{
return mc_get_account_by (source_url, get_source_url_string);
}
EAccount *
mail_config_get_account_by_transport_url (const gchar *transport_url)
{
return mc_get_account_by (transport_url, get_transport_url_string);
}
EAccountService *
mail_config_get_default_transport (void)
{
EAccountList *account_list;
EAccount *account;
EIterator *iter;
account_list = e_get_account_list ();
account = e_get_default_account ();
if (account && account->enabled && account->transport && account->transport->url && account->transport->url[0])
return account->transport;
/* return the first account with a transport? */
iter = e_list_get_iterator ((EList *) account_list);
while (e_iterator_is_valid (iter)) {
account = (EAccount *) e_iterator_get (iter);
if (account->enabled && account->transport && account->transport->url && account->transport->url[0]) {
g_object_unref (iter);
return account->transport;
}
e_iterator_next (iter);
}
g_object_unref (iter);
return NULL;
}
static gchar *
uri_to_evname (const gchar *uri, const gchar *prefix)
{
......
......@@ -68,17 +68,8 @@ void mail_config_write (void);
/* General Accessor functions */
/* accounts */
EAccount * mail_config_get_account_by_source_url
(const gchar *url);
EAccount * mail_config_get_account_by_transport_url
(const gchar *url);
gint mail_config_get_address_count (void);
EAccountService *
mail_config_get_default_transport (void);
/* static utility functions */
gchar * mail_config_folder_to_cachename (CamelFolder *folder,
const gchar *prefix);
......
......@@ -39,7 +39,6 @@
#include "e-mail-session.h"
#include "em-event.h"
#include "em-filter-rule.h"
#include "mail-config.h"
#include "mail-folder-cache.h"
#include "mail-mt.h"
#include "mail-ops.h"
......@@ -1337,7 +1336,7 @@ mail_send (EMailSession *session)
struct _send_data *data;
send_info_t type;
transport = mail_config_get_default_transport ();
transport = e_get_default_transport ();
if (!transport || !transport->url)
return;
......
......@@ -41,7 +41,6 @@
#include "em-vfolder-editor.h"
#include "em-vfolder-rule.h"
#include "mail-autofilter.h"
#include "mail-config.h"
#include "mail-folder-cache.h"
#include "mail-mt.h"
#include "mail-ops.h"
......
......@@ -36,6 +36,7 @@
#include <gconf/gconf-client.h>
#include "e-util/e-account-utils.h"
#include "e-util/e-icon-factory.h"
#include "e-util/e-poolv.h"
#include "e-util/e-profile-event.h"
......@@ -1658,7 +1659,7 @@ ml_tree_value_at_ex (ETreeModel *etm,
uri = camel_folder_get_uri (folder);
euri = em_uri_from_camel (uri);
account = mail_config_get_account_by_source_url (uri);
account = e_get_account_by_source_url (uri);
if (account) {
curl = camel_url_new (uri, NULL);
......
......@@ -33,7 +33,6 @@
#include "widgets/misc/e-search-bar.h"
#include "em-utils.h"
#include "mail-config.h"
#include "mail-ops.h"
#include "message-list.h"
......
......@@ -72,7 +72,7 @@ action_mail_account_disable_cb (GtkAction *action,
g_return_if_fail (folder_uri != NULL);
account_list = e_get_account_list ();
account = mail_config_get_account_by_source_url (folder_uri);
account = e_get_account_by_source_url (folder_uri);
g_return_if_fail (account != NULL);
if (e_account_list_account_has_proxies (account_list, account))
......@@ -1066,7 +1066,7 @@ action_mail_tools_subscriptions_cb (GtkAction *action,
uri = em_folder_tree_get_selected_uri (folder_tree);
if (uri != NULL) {
account = mail_config_get_account_by_source_url (uri);
account = e_get_account_by_source_url (uri);
g_free (uri);
}
......
......@@ -53,7 +53,6 @@
#include "em-subscription-editor.h"
#include "em-utils.h"
#include "mail-autofilter.h"
#include "mail-config.h"
#include "mail-ops.h"
#include "mail-send-recv.h"
#include "mail-tools.h"
......
......@@ -910,7 +910,7 @@ mail_shell_view_update_actions (EShellView *shell_view)
folder_tree_and_message_list_agree =
(g_strcmp0 (uri, folder_uri) == 0);
account = mail_config_get_account_by_source_url (uri);
account = e_get_account_by_source_url (uri);
/* FIXME This belongs in a GroupWise plugin. */
account_is_groupwise =
......
......@@ -50,7 +50,6 @@
#include "widgets/misc/e-signature-manager.h"
#include "widgets/misc/e-signature-preview.h"
#include "mail-config.h"
#include "em-config.h"
#include "em-folder-selection-button.h"
......
......@@ -46,7 +46,6 @@
#include "e-mail-backend.h"
#include "e-mail-label-manager.h"
#include "e-mail-reader-utils.h"
#include "mail-config.h"