[evolution-groupwise] Allow sending mails through groupwise soap protocol
- From: Chenthill Palanisamy <pchen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-groupwise] Allow sending mails through groupwise soap protocol
- Date: Mon, 14 May 2012 13:36:45 +0000 (UTC)
commit 2da9acc14377705348ce48a63389d6b6f03e0d72
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Mon May 14 19:05:28 2012 +0530
Allow sending mails through groupwise soap protocol
configure.ac | 1 +
src/camel/Makefile.am | 2 +-
src/camel/camel-groupwise-store.c | 25 +--
src/camel/camel-groupwise-transport.c | 34 +--
src/camel/camel-groupwise-transport.h | 11 +-
src/camel/gwsend/Makefile.am | 30 +++
src/camel/gwsend/camel-gwsend-provider.c | 147 ++++++++++++++
src/camel/gwsend/camel-gwsend-settings.c | 172 ++++++++++++++++
src/camel/gwsend/camel-gwsend-settings.h | 62 ++++++
src/camel/gwsend/camel-gwsend-transport.c | 314 +++++++++++++++++++++++++++++
src/camel/gwsend/camel-gwsend-transport.h | 67 ++++++
src/camel/gwsend/libcamelgwsend.urls | 1 +
12 files changed, 821 insertions(+), 45 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b46c419..532c6bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -333,6 +333,7 @@ src/calendar/Makefile
src/addressbook/Makefile
src/camel/Makefile
src/camel/groupwise/Makefile
+src/camel/gwsend/Makefile
src/camel/imapx/Makefile
src/server/libegroupwise-]EVO_GW_API_VERSION_MACRO[.pc:src/server/libegroupwise.pc.in
])
diff --git a/src/camel/Makefile.am b/src/camel/Makefile.am
index 1a15150..75afb93 100644
--- a/src/camel/Makefile.am
+++ b/src/camel/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . groupwise imapx
+SUBDIRS = . groupwise gwsend imapx
noinst_LTLIBRARIES = libcamelgroupwise.la
libcamelgroupwise_la_CPPFLAGS = \
diff --git a/src/camel/camel-groupwise-store.c b/src/camel/camel-groupwise-store.c
index 2abc39f..5db2c33 100644
--- a/src/camel/camel-groupwise-store.c
+++ b/src/camel/camel-groupwise-store.c
@@ -62,6 +62,7 @@ struct _CamelGroupwiseStorePrivate {
GHashTable *name_hash;/*get ids from names */
GHashTable *parent_hash;
EGwConnection *cnc;
+ CamelService *transport;
};
CamelServiceAuthType camel_groupwise_password_authtype = {
N_("Password"),
@@ -237,6 +238,7 @@ groupwise_connect_sync (CamelService *service,
return FALSE;
}
+
#if 0
static void
groupwise_disconnect_cleanup (CamelService *service,
@@ -292,6 +294,8 @@ groupwise_disconnect_sync (CamelService *service,
if (groupwise_store->priv && groupwise_store->priv->cnc) {
g_object_unref (groupwise_store->priv->cnc);
groupwise_store->priv->cnc = NULL;
+ if (groupwise_store->priv->transport)
+ camel_groupwise_transport_set_connection (groupwise_store->priv->transport, NULL);
}
groupwise_store_set_current_folder (groupwise_store, NULL);
@@ -1416,6 +1420,9 @@ groupwise_store_dispose (GObject *object)
groupwise_store->priv->cnc = NULL;
}
+ if (groupwise_store->priv->transport)
+ g_object_unref (groupwise_store->priv->transport);
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (camel_groupwise_store_parent_class)->dispose (object);
}
@@ -1492,6 +1499,8 @@ groupwise_store_authenticate_sync (CamelService *service,
priv->cnc = e_gw_connection_new_with_error_handler (
uri, user, password, &errors);
+ if (priv->transport)
+ camel_groupwise_transport_set_connection (priv->transport, priv->cnc);
g_free (uri);
@@ -1513,14 +1522,6 @@ groupwise_store_authenticate_sync (CamelService *service,
return result;
}
-static EGwConnection *
-get_connection (CamelService *transport, CamelStore *store, GCancellable *cancellable, GError **error)
-{
- CamelGroupwiseStore *gw_store = (CamelGroupwiseStore *) store;
-
- return gw_store->priv->cnc;
-}
-
static gboolean
groupwise_store_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -1582,13 +1583,11 @@ groupwise_store_initable_init (GInitable *initable,
transport, "settings",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
-
- camel_groupwise_transport_set_connection_callback (
- CAMEL_SERVICE (transport),
- get_connection,
- (CamelStore *) groupwise_store);
+
+ groupwise_store->priv->transport = g_object_ref (transport);
}
+
return (transport != NULL);
}
diff --git a/src/camel/camel-groupwise-transport.c b/src/camel/camel-groupwise-transport.c
index c4eb824..c59c7b2 100644
--- a/src/camel/camel-groupwise-transport.c
+++ b/src/camel/camel-groupwise-transport.c
@@ -43,8 +43,7 @@
G_DEFINE_TYPE (CamelGroupwiseTransport, camel_groupwise_transport, CAMEL_TYPE_TRANSPORT)
struct _CamelGroupwiseTransportPrivate {
- GetConnectionCb cb;
- CamelStore *store;
+ EGwConnection *cnc;
};
static void
@@ -54,9 +53,9 @@ groupwise_transport_dispose (GObject *object)
priv = CAMEL_GROUPWISE_TRANSPORT_GET_PRIVATE (object);
- if (priv->store) {
- g_object_unref (priv->store);
- priv->store = NULL;
+ if (priv->cnc) {
+ g_object_unref (priv->cnc);
+ priv->cnc = NULL;
}
/* Chain up to parent's dispose() method. */
@@ -111,7 +110,7 @@ groupwise_send_to_sync (CamelTransport *transport,
priv = CAMEL_GROUPWISE_TRANSPORT_GET_PRIVATE (transport);
- if (!transport || !priv->cb) {
+ if (!priv->cnc) {
g_set_error (
error, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
@@ -122,17 +121,7 @@ groupwise_send_to_sync (CamelTransport *transport,
camel_operation_push_message (cancellable, _("Sending Message") );
- /* callback for retreiving the connection */
- cnc = priv->cb (CAMEL_SERVICE (transport), priv->store, cancellable, error);
- if (!cnc) {
- g_warning ("||| Eh!!! Failure |||\n");
- camel_operation_pop_message (cancellable);
- g_set_error (
- error, CAMEL_SERVICE_ERROR,
- CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
- _("Authentication failed"));
- return FALSE;
- }
+ cnc = priv->cnc;
item = camel_groupwise_util_item_from_message (cnc, message, from);
@@ -216,14 +205,15 @@ camel_groupwise_transport_init (CamelGroupwiseTransport *transport)
}
void
-camel_groupwise_transport_set_connection_callback (CamelService *service,
- GetConnectionCb cb,
- CamelStore *store)
+camel_groupwise_transport_set_connection (CamelService *service,
+ EGwConnection *cnc)
{
CamelGroupwiseTransport *transport = CAMEL_GROUPWISE_TRANSPORT (service);
g_return_if_fail (CAMEL_IS_GROUPWISE_TRANSPORT (transport));
- transport->priv->cb = cb;
- transport->priv->store = g_object_ref (store);
+ if (transport->priv->cnc)
+ g_object_unref (transport->priv->cnc);
+ if (cnc)
+ transport->priv->cnc = g_object_ref (cnc);
}
diff --git a/src/camel/camel-groupwise-transport.h b/src/camel/camel-groupwise-transport.h
index acb3fee..e8e4671 100644
--- a/src/camel/camel-groupwise-transport.h
+++ b/src/camel/camel-groupwise-transport.h
@@ -60,17 +60,10 @@ struct _CamelGroupwiseTransportClass {
CamelTransportClass parent_class;
};
-typedef EGwConnection * (*GetConnectionCb)
- (CamelService *transport,
- CamelStore *store,
- GCancellable *cancellable,
- GError **error);
-
GType camel_groupwise_transport_get_type (void);
-void camel_groupwise_transport_set_connection_callback
+void camel_groupwise_transport_set_connection
(CamelService *transport,
- GetConnectionCb cb,
- CamelStore *store);
+ EGwConnection *cnc);
G_END_DECLS
diff --git a/src/camel/gwsend/Makefile.am b/src/camel/gwsend/Makefile.am
new file mode 100644
index 0000000..f7ca546
--- /dev/null
+++ b/src/camel/gwsend/Makefile.am
@@ -0,0 +1,30 @@
+camel_provider_LTLIBRARIES = libcamelgwsend.la
+camel_provider_DATA = libcamelgwsend.urls
+
+libcamelgwsend_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/camel \
+ -I$(top_srcdir)/src/server \
+ $(CAMEL_CFLAGS) \
+ $(SOUP_CFLAGS) \
+ -DPREFIX=\"$(prefix)\" \
+ -DG_LOG_DOMAIN=\"camel-groupwise-provider\"
+
+libcamelgwsend_la_SOURCES = \
+ camel-gwsend-transport.c \
+ camel-gwsend-transport.h \
+ camel-gwsend-settings.c \
+ camel-gwsend-settings.h \
+ camel-gwsend-provider.c
+
+libcamelgwsend_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED)
+
+libcamelgwsend_la_LIBADD = \
+ $(top_builddir)/src/server/libegroupwise-1.2.la \
+ $(top_builddir)/src/camel/libcamelgroupwise.la \
+ $(CAMEL_LIBS)
+
+EXTRA_DIST = libcamelgwsend.urls
+
+-include $(top_srcdir)/git.mk
diff --git a/src/camel/gwsend/camel-gwsend-provider.c b/src/camel/gwsend/camel-gwsend-provider.c
new file mode 100644
index 0000000..515dba3
--- /dev/null
+++ b/src/camel/gwsend/camel-gwsend-provider.c
@@ -0,0 +1,147 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-groupwise-provider.c: GroupWise provider registration code */
+
+/*
+ * Authors: Jeffrey Stedfast <fejj ximian com>
+ * Sivaiah Nallagatla <snallagatla novell com>
+ * Rodrigo Moya <rodrigo ximian com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <glib/gi18n-lib.h>
+#include <gmodule.h>
+
+#include "camel-gwsend-transport.h"
+#include "camel-groupwise-store.h"
+#include "camel-groupwise-transport.h"
+
+static void add_hash (guint *hash, gchar *s);
+static guint gwsend_url_hash (gconstpointer key);
+static gint check_equal (gchar *s1, gchar *s2);
+static gint gwsend_url_equal (gconstpointer a, gconstpointer b);
+
+CamelProviderPortEntry gwsend_port_entries[] = {
+ { 7191, N_("Default GroupWise port"), FALSE },
+ { 0, NULL, 0 }
+ };
+
+static CamelProvider gwsend_provider = {
+ "gwsend",
+ N_("Novell GroupWise"),
+
+ N_("For sending mails using soap protocol"),
+
+ "mail",
+
+ CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
+ CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL | CAMEL_PROVIDER_DISABLE_SENT_FOLDER,
+
+ CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
+
+ NULL,
+
+ gwsend_port_entries,
+
+ /* ... */
+};
+
+extern CamelServiceAuthType camel_groupwise_password_authtype; /*for the query_auth_types function */
+
+static gint
+gwsend_auto_detect_cb (CamelURL *url,
+ GHashTable **auto_detected,
+ GError **error)
+{
+ *auto_detected = g_hash_table_new (g_str_hash, g_str_equal);
+
+ g_hash_table_insert (*auto_detected, g_strdup ("poa"),
+ g_strdup (url->host));
+
+ return 0;
+}
+
+void
+camel_provider_module_init (void)
+{
+ gwsend_provider.url_hash = gwsend_url_hash;
+ gwsend_provider.url_equal = gwsend_url_equal;
+ gwsend_provider.auto_detect = gwsend_auto_detect_cb;
+ gwsend_provider.authtypes = g_list_prepend (gwsend_provider.authtypes, &camel_groupwise_password_authtype);
+ gwsend_provider.translation_domain = GETTEXT_PACKAGE;
+
+ gwsend_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_gwsend_transport_get_type ();
+
+ camel_provider_register (&gwsend_provider);
+}
+
+static void
+add_hash (guint *hash,
+ gchar *s)
+{
+ if (s)
+ *hash ^= g_str_hash(s);
+}
+
+static guint
+gwsend_url_hash (gconstpointer key)
+{
+ const CamelURL *u = (CamelURL *) key;
+ guint hash = 0;
+
+ add_hash (&hash, u->user);
+ add_hash (&hash, u->host);
+ hash ^= u->port;
+
+ return hash;
+}
+
+static gint
+check_equal (gchar *s1,
+ gchar *s2)
+{
+ if (s1 == NULL) {
+ if (s2 == NULL)
+ return TRUE;
+ else
+ return FALSE;
+ }
+
+ if (s2 == NULL)
+ return FALSE;
+
+ return strcmp (s1, s2) == 0;
+}
+
+static gint
+gwsend_url_equal (gconstpointer a,
+ gconstpointer b)
+{
+ const CamelURL *u1 = a, *u2 = b;
+
+ return check_equal (u1->protocol, u2->protocol)
+ && check_equal (u1->user, u2->user)
+ && check_equal (u1->host, u2->host)
+ && u1->port == u2->port;
+}
diff --git a/src/camel/gwsend/camel-gwsend-settings.c b/src/camel/gwsend/camel-gwsend-settings.c
new file mode 100644
index 0000000..a27bf73
--- /dev/null
+++ b/src/camel/gwsend/camel-gwsend-settings.c
@@ -0,0 +1,172 @@
+/*
+ * camel-gwsend-settings.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "camel-gwsend-settings.h"
+
+#define CAMEL_GWSEND_SETTINGS_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), CAMEL_TYPE_GWSEND_SETTINGS, CamelGwSendSettingsPrivate))
+
+enum {
+ PROP_0,
+ PROP_AUTH_MECHANISM,
+ PROP_HOST,
+ PROP_PORT,
+ PROP_SECURITY_METHOD,
+ PROP_USER
+};
+
+G_DEFINE_TYPE_WITH_CODE (
+ CamelGwSendSettings,
+ camel_gwsend_settings,
+ CAMEL_TYPE_SETTINGS,
+ G_IMPLEMENT_INTERFACE (
+ CAMEL_TYPE_NETWORK_SETTINGS, NULL))
+
+static void
+gwsend_settings_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_AUTH_MECHANISM:
+ camel_network_settings_set_auth_mechanism (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_string (value));
+ return;
+
+ case PROP_HOST:
+ camel_network_settings_set_host (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_string (value));
+ return;
+
+ case PROP_PORT:
+ camel_network_settings_set_port (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_uint (value));
+ return;
+
+ case PROP_SECURITY_METHOD:
+ camel_network_settings_set_security_method (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_enum (value));
+ return;
+
+ case PROP_USER:
+ camel_network_settings_set_user (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+gwsend_settings_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_AUTH_MECHANISM:
+ g_value_take_string (
+ value,
+ camel_network_settings_dup_auth_mechanism (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+
+ case PROP_HOST:
+ g_value_take_string (
+ value,
+ camel_network_settings_dup_host (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+
+ case PROP_PORT:
+ g_value_set_uint (
+ value,
+ camel_network_settings_get_port (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+
+ case PROP_SECURITY_METHOD:
+ g_value_set_enum (
+ value,
+ camel_network_settings_get_security_method (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+
+ case PROP_USER:
+ g_value_take_string (
+ value,
+ camel_network_settings_dup_user (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+camel_gwsend_settings_class_init (CamelGwSendSettingsClass *class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = gwsend_settings_set_property;
+ object_class->get_property = gwsend_settings_get_property;
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_AUTH_MECHANISM,
+ "auth-mechanism");
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_HOST,
+ "host");
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_PORT,
+ "port");
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_SECURITY_METHOD,
+ "security-method");
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_USER,
+ "user");
+}
+
+static void
+camel_gwsend_settings_init (CamelGwSendSettings *settings)
+{
+}
+
diff --git a/src/camel/gwsend/camel-gwsend-settings.h b/src/camel/gwsend/camel-gwsend-settings.h
new file mode 100644
index 0000000..437183e
--- /dev/null
+++ b/src/camel/gwsend/camel-gwsend-settings.h
@@ -0,0 +1,62 @@
+/*
+ * camel-gwsend-settings.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef CAMEL_GWSEND_SETTINGS_H
+#define CAMEL_GWSEND_SETTINGS_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_GWSEND_SETTINGS \
+ (camel_gwsend_settings_get_type ())
+#define CAMEL_GWSEND_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), CAMEL_TYPE_GWSEND_SETTINGS, CamelGwSendSettings))
+#define CAMEL_GWSEND_SETTINGS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), CAMEL_TYPE_GWSEND_SETTINGS, CamelGwSendSettingsClass))
+#define CAMEL_IS_GWSEND_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), CAMEL_TYPE_GWSEND_SETTINGS))
+#define CAMEL_IS_GWSEND_SETTINGS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), CAMEL_TYPE_GWSEND_SETTINGS))
+#define CAMEL_GWSEND_SETTINGS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), CAMEL_TYPE_GWSEND_SETTINGS, CamelGwSendSettingsClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelGwSendSettings CamelGwSendSettings;
+typedef struct _CamelGwSendSettingsClass CamelGwSendSettingsClass;
+typedef struct _CamelGwSendSettingsPrivate CamelGwSendSettingsPrivate;
+
+struct _CamelGwSendSettings {
+ CamelSettings parent;
+ CamelGwSendSettingsPrivate *priv;
+};
+
+struct _CamelGwSendSettingsClass {
+ CamelSettingsClass parent_class;
+};
+
+GType camel_gwsend_settings_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* CAMEL_GWSEND_SETTINGS_H */
diff --git a/src/camel/gwsend/camel-gwsend-transport.c b/src/camel/gwsend/camel-gwsend-transport.c
new file mode 100644
index 0000000..ce13487
--- /dev/null
+++ b/src/camel/gwsend/camel-gwsend-transport.c
@@ -0,0 +1,314 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-groupwise-transport.c : class for an groupwise transport */
+
+/*
+ * Authors: Sivaiah Nallagatla <snallagatla novell com>
+ * Parthasarathi Susarla <sparthasarathi novell com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <glib/gi18n-lib.h>
+
+#include "camel-gwsend-transport.h"
+#include "camel-gwsend-settings.h"
+#include "camel-groupwise-transport.h"
+#include "camel-groupwise-utils.h"
+
+#define CAMEL_GWSEND_TRANSPORT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), CAMEL_TYPE_GWSEND_TRANSPORT, CamelGwSendTransportPrivate))
+
+G_DEFINE_TYPE (CamelGwSendTransport, camel_gwsend_transport, CAMEL_TYPE_GROUPWISE_TRANSPORT)
+
+struct _CamelGwSendTransportPrivate {
+ EGwConnection *cnc;
+};
+
+static void
+gwsend_transport_dispose (GObject *object)
+{
+ CamelGwSendTransportPrivate *priv;
+
+ priv = CAMEL_GWSEND_TRANSPORT_GET_PRIVATE (object);
+
+ if (priv->cnc) {
+ g_object_unref (priv->cnc);
+ priv->cnc = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (camel_gwsend_transport_parent_class)->dispose (object);
+}
+
+static gchar *
+gwsend_transport_get_name (CamelService *service,
+ gboolean brief)
+{
+ CamelNetworkSettings *network_settings;
+ CamelSettings *settings;
+ const gchar *host;
+
+ settings = camel_service_get_settings (service);
+
+ network_settings = CAMEL_NETWORK_SETTINGS (settings);
+ host = camel_network_settings_get_host (network_settings);
+
+ if (brief)
+ return g_strdup_printf (
+ _("GroupWise server %s"), host);
+ else
+ return g_strdup_printf (
+ _("GroupWise mail delivery via %s"), host);
+}
+
+static gboolean
+check_for_connection (CamelService *service,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelNetworkSettings *network_settings;
+ CamelSettings *settings;
+ const gchar *host;
+ struct addrinfo hints, *ai;
+ GError *local_error = NULL;
+
+ settings = camel_service_get_settings (service);
+
+ network_settings = CAMEL_NETWORK_SETTINGS (settings);
+ host = camel_network_settings_get_host (network_settings);
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_family = PF_UNSPEC;
+ ai = camel_getaddrinfo(host, "groupwise", &hints, cancellable, &local_error);
+ if (ai == NULL && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ gchar *port_string;
+ guint16 soap_port;
+
+ g_clear_error (&local_error);
+
+ soap_port = camel_network_settings_get_port (network_settings);
+
+ port_string = g_strdup_printf ("%d", soap_port);
+ ai = camel_getaddrinfo (
+ host, port_string, &hints,
+ cancellable, &local_error);
+ g_free (port_string);
+ }
+
+ if (ai == NULL) {
+ g_propagate_error (error, local_error);
+ return FALSE;
+ }
+
+ camel_freeaddrinfo (ai);
+
+ return TRUE;
+
+}
+
+static CamelAuthenticationResult
+gwsend_authenticate_sync (CamelService *service,
+ const gchar *mechanism,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelGwSendTransport *gw_transport = CAMEL_GWSEND_TRANSPORT (service);
+ CamelGwSendTransportPrivate *priv = CAMEL_GWSEND_TRANSPORT_GET_PRIVATE (gw_transport);
+ CamelNetworkSettings *network_settings;
+ CamelNetworkSecurityMethod method;
+ CamelAuthenticationResult result;
+ CamelSettings *settings;
+ gchar *uri;
+ const gchar *host;
+ const gchar *user;
+ const gchar *scheme;
+ const gchar *password;
+ EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL};
+ guint16 soap_port;
+
+ password = camel_service_get_password (service);
+ settings = camel_service_get_settings (service);
+
+ if (password == NULL) {
+ g_set_error_literal (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
+ _("Authentication password not available"));
+ return CAMEL_AUTHENTICATION_ERROR;
+ }
+
+ network_settings = CAMEL_NETWORK_SETTINGS (settings);
+ host = camel_network_settings_get_host (network_settings);
+ user = camel_network_settings_get_user (network_settings);
+ method = camel_network_settings_get_security_method (network_settings);
+
+ soap_port = camel_network_settings_get_port (network_settings);
+
+ if (method == CAMEL_NETWORK_SECURITY_METHOD_NONE)
+ scheme = "http";
+ else
+ scheme = "https";
+
+ uri = g_strdup_printf (
+ "%s://%s:%d/soap", scheme, host, soap_port);
+
+ priv->cnc = e_gw_connection_new_with_error_handler (
+ uri, user, password, &errors);
+
+ g_free (uri);
+
+ if (E_IS_GW_CONNECTION (priv->cnc)) {
+ result = CAMEL_AUTHENTICATION_ACCEPTED;
+ } else if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) {
+ result = CAMEL_AUTHENTICATION_REJECTED;
+ } else {
+ g_set_error (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_UNAVAILABLE,
+ "%s", errors.description ?
+ errors.description :
+ _("You must be working online "
+ "to complete this operation"));
+ result = CAMEL_AUTHENTICATION_ERROR;
+ }
+
+ return result;
+}
+
+static gboolean
+gwsend_connect_sync (CamelService *service,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelGwSendTransport *gw_transport = CAMEL_GWSEND_TRANSPORT (service);
+ CamelGwSendTransportPrivate *priv = CAMEL_GWSEND_TRANSPORT_GET_PRIVATE (gw_transport);
+ CamelServiceConnectionStatus status;
+ CamelSession *session;
+
+ session = camel_service_get_session (service);
+ status = camel_service_get_connection_status (service);
+
+ if (status == CAMEL_SERVICE_DISCONNECTED)
+ return FALSE;
+
+ camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+
+ if (priv->cnc) {
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ return TRUE;
+ }
+
+ if (!check_for_connection (service, cancellable, error)) {
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ camel_service_disconnect_sync (service, TRUE, NULL);
+ return FALSE;
+ }
+
+ if (!camel_session_authenticate_sync (session, service, NULL, cancellable, error)) {
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ camel_service_disconnect_sync (service, TRUE, NULL);
+ return FALSE;
+ }
+
+ if (!e_gw_connection_get_version (priv->cnc)) {
+ camel_session_alert_user (session,
+ CAMEL_SESSION_ALERT_WARNING,
+ _("Some features may not work correctly with your current server version"),
+ FALSE);
+
+ }
+
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ if (E_IS_GW_CONNECTION (priv->cnc)) {
+ camel_groupwise_transport_set_connection (service, priv->cnc);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+gwsend_disconnect_sync (CamelService *service,
+ gboolean clean,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelGwSendTransport *gw_transport = CAMEL_GWSEND_TRANSPORT (service);
+
+ if (clean) {
+ camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ if (gw_transport->priv && gw_transport->priv->cnc) {
+ g_object_unref (gw_transport->priv->cnc);
+ gw_transport->priv->cnc = NULL;
+ camel_groupwise_transport_set_connection (service, NULL);
+ }
+
+
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ }
+
+ /* groupwise_disconnect_cleanup (service, clean, ex); */
+ return TRUE;
+}
+
+extern CamelServiceAuthType camel_groupwise_password_authtype;
+
+static GList *
+gwsend_query_auth_types_sync (CamelService *service,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *auth_types = NULL;
+
+ auth_types = g_list_prepend (auth_types, &camel_groupwise_password_authtype);
+ return auth_types;
+}
+
+static void
+camel_gwsend_transport_class_init (CamelGwSendTransportClass *class)
+{
+ GObjectClass *object_class;
+ CamelServiceClass *service_class;
+
+ g_type_class_add_private (
+ class, sizeof (CamelGwSendTransportPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->dispose = gwsend_transport_dispose;
+
+ service_class = CAMEL_SERVICE_CLASS (class);
+ service_class->settings_type = CAMEL_TYPE_GWSEND_SETTINGS;
+ service_class->get_name = gwsend_transport_get_name;
+ service_class->connect_sync = gwsend_connect_sync;
+ service_class->disconnect_sync = gwsend_disconnect_sync;
+ service_class->authenticate_sync = gwsend_authenticate_sync;
+ service_class->query_auth_types_sync = gwsend_query_auth_types_sync;
+}
+
+static void
+camel_gwsend_transport_init (CamelGwSendTransport *transport)
+{
+ transport->priv = CAMEL_GWSEND_TRANSPORT_GET_PRIVATE (transport);
+}
diff --git a/src/camel/gwsend/camel-gwsend-transport.h b/src/camel/gwsend/camel-gwsend-transport.h
new file mode 100644
index 0000000..a64cede
--- /dev/null
+++ b/src/camel/gwsend/camel-gwsend-transport.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-gwsend-transport.h : class for an groupwise transport */
+
+/*
+ * Authors: Sivaiah Nallagatla <snallagatla novell com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef CAMEL_GWSEND_TRANSPORT_H
+#define CAMEL_GWSEND_TRANSPORT_H
+
+#include "camel-groupwise-transport.h"
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_GWSEND_TRANSPORT \
+ (camel_gwsend_transport_get_type ())
+#define CAMEL_GWSEND_TRANSPORT(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), CAMEL_TYPE_GWSEND_TRANSPORT, CamelGwSendTransport))
+#define CAMEL_GWSEND_TRANSPORT_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), CAMEL_TYPE_GWSEND_TRANSPORT, CamelGwSendTransportClass))
+#define CAMEL_IS_GWSEND_TRANSPORT(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), CAMEL_TYPE_GWSEND_TRANSPORT))
+#define CAMEL_IS_GWSEND_TRANSPORT_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), CAMEL_TYPE_GWSEND_TRANSPORT))
+#define CAMEL_GWSEND_TRANSPORT_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), CAMEL_TYPE_GWSEND_TRANSPORT, CamelGwSendTransportClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelGwSendTransport CamelGwSendTransport;
+typedef struct _CamelGwSendTransportClass CamelGwSendTransportClass;
+typedef struct _CamelGwSendTransportPrivate CamelGwSendTransportPrivate;
+
+struct _CamelGwSendTransport {
+ CamelGroupwiseTransport parent;
+ CamelGwSendTransportPrivate *priv;
+};
+
+struct _CamelGwSendTransportClass {
+ CamelGroupwiseTransportClass parent_class;
+};
+
+GType camel_gwsend_transport_get_type (void);
+
+G_END_DECLS
+
+#endif /* CAMEL_GWSEND_TRANSPORT_H */
diff --git a/src/camel/gwsend/libcamelgwsend.urls b/src/camel/gwsend/libcamelgwsend.urls
new file mode 100644
index 0000000..efa2668
--- /dev/null
+++ b/src/camel/gwsend/libcamelgwsend.urls
@@ -0,0 +1 @@
+gwsend
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]