From 7933886a5c5c402e90da921c93d7d9ba7d92420d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 22 Jan 2011 11:46:26 +0100 Subject: [PATCH] Migrated to evolution-data-server 2.32. --- configure.ac | 2 +- src/camelsession.c | 31 +++++++------------------ src/camelsession.h | 42 +++++++++++++++++++++------------ src/mail.c | 58 ++++++++++++++++++++++++++++++++-------------- src/solipa.c | 3 +-- tests/mail.c | 2 +- 6 files changed, 78 insertions(+), 60 deletions(-) diff --git a/configure.ac b/configure.ac index c3ccf3c..131ab16 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_PROG_RANLIB PKG_CHECK_MODULES(SOLIPA, [gobject-2.0 >= 2.24.0 glib-2.0 >= 2.24.0 libgdaex >= 0.2.2 - camel-provider-1.2 >= 2.24 + camel-provider-1.2 >= 2.32 gtk+-2.0 >= 2.20 gio-2.0 >= 2.24]) diff --git a/src/camelsession.c b/src/camelsession.c index da3892b..41749d2 100644 --- a/src/camelsession.c +++ b/src/camelsession.c @@ -22,39 +22,24 @@ #include "camelsession.h" +G_DEFINE_TYPE (SolipaCamelSession, solipa_camel_session, CAMEL_TYPE_SESSION) + static void -solipa_camel_session_class_init (SolipaCamelSessionClass *solipa_camel_session_class) +solipa_camel_session_class_init (SolipaCamelSessionClass *class) { - CamelSessionClass *camel_session_class = CAMEL_SESSION_CLASS (solipa_camel_session_class); } -CamelType -solipa_camel_session_get_type (void) +static void +solipa_camel_session_init (SolipaCamelSession *session) { - static CamelType type = CAMEL_INVALID_TYPE; - - if (type == CAMEL_INVALID_TYPE) { - type = camel_type_register ( - camel_session_get_type (), - "SolipaCamelSession", - sizeof (SolipaCamelSession), - sizeof (SolipaCamelSessionClass), - (CamelObjectClassInitFunc) solipa_camel_session_class_init, - NULL, - NULL, - NULL); - } - - return type; } -CamelSession -*solipa_camel_session_new (const gchar *path) +CamelSession * +solipa_camel_session_new (const gchar *path) { CamelSession *session; - session = CAMEL_SESSION (camel_object_new (SOLIPA_CAMEL_SESSION_TYPE)); - + session = g_object_new (SOLIPA_TYPE_CAMEL_SESSION, NULL); camel_session_construct (session, path); return session; diff --git a/src/camelsession.h b/src/camelsession.h index 5d5df24..3915d41 100644 --- a/src/camelsession.h +++ b/src/camelsession.h @@ -19,32 +19,44 @@ #ifndef __SOLIPA_CAMEL_SESSION_H__ #define __SOLIPA_CAMEL_SESSION_H__ -#include +#include G_BEGIN_DECLS -#define SOLIPA_CAMEL_SESSION_TYPE (solipa_camel_session_get_type ()) -#define SOLIPA_CAMEL_SESSION(obj) (CAMEL_CHECK_CAST((obj), SOLIPA_CAMEL_SESSION_TYPE, SolipaCamelSession)) -#define SOLIPA_CAMEL_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), SOLIPA_CAMEL_SESSION_TYPE, SolipaCamelSessionClass)) -#define SOLIPA_CAMEL_IS_SESSION(o) (CAMEL_CHECK_TYPE((o), SOLIPA_CAMEL_SESSION_TYPE)) +#define SOLIPA_TYPE_CAMEL_SESSION \ + (solipa_camel_session_get_type ()) +#define SOLIPA_CAMEL_SESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), SOLIPA_TYPE_CAMEL_SESSION, SolipaCamelSession)) +#define SOLIPA_CAMEL_SESSION_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), SOLIPA_TYPE_CAMEL_SESSION, SolipaCamelSessionClass)) +#define SOLIPA_IS_CAMEL_SESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), SOLIPA_TYPE_CAMEL_SESSION)) +#define SOLIPA_IS_CAMEL_SESSION_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), SOLIPA_TYPE_CAMEL_SESSION)) +#define SOLIPA_CAMEL_SESSION_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), SOLIPA_TYPE_CAMEL_SESSION, SolipaCamelSessionClass)) + +G_BEGIN_DECLS typedef struct _SolipaCamelSession SolipaCamelSession; typedef struct _SolipaCamelSessionClass SolipaCamelSessionClass; -struct _SolipaCamelSession - { - CamelSession parent_object; - }; - -struct _SolipaCamelSessionClass - { - CamelSessionClass parent_class; - }; +struct _SolipaCamelSession { + CamelSession parent; +}; -CamelType solipa_camel_session_get_type (void); +struct _SolipaCamelSessionClass { + CamelSessionClass parent_class; +}; +GType solipa_camel_session_get_type (void); CamelSession *solipa_camel_session_new (const gchar *path); diff --git a/src/mail.c b/src/mail.c index 975ad86..0c60223 100644 --- a/src/mail.c +++ b/src/mail.c @@ -305,6 +305,8 @@ solipa_mail_get_as_string (SolipaMail *mail) { gchar *ret; + GError *error; + CamelMimeMessage *msg; CamelStream *mem; @@ -319,20 +321,31 @@ solipa_mail_get_as_string (SolipaMail *mail) } mem = camel_stream_mem_new (); - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), mem); - if (camel_stream_reset (mem) < 0) + error = NULL; + camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), mem, &error); + if (error != NULL) + { + g_warning ("Unable to to write to stream: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + return NULL; + } + error = NULL; + if (camel_stream_reset (mem, &error) < 0) { - g_warning ("Unable to reset the camel mem stream."); + g_warning ("Unable to reset the camel mem stream: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); return NULL; } ret = g_strdup (""); while (!camel_stream_eos (mem)) { - nb_read = camel_stream_read (mem, tmp_buf, sizeof (tmp_buf)); + error = NULL; + nb_read = camel_stream_read (mem, tmp_buf, sizeof (tmp_buf), &error); if (nb_read < 0) { - g_warning ("Error on camel stream reading."); + g_warning ("Error on camel stream reading: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); break; } else if (nb_read > 0) @@ -349,9 +362,11 @@ solipa_mail_send (SolipaMail *mail, const gchar *url) { SolipaMailPrivate *priv; + GError *error; + gboolean ret; + CamelMimeMessage *msg; - CamelException *ex; CamelInternetAddress *from, *addr, *to; CamelService *trans; @@ -372,25 +387,27 @@ solipa_mail_send (SolipaMail *mail, const gchar *url) return; } - ex = camel_exception_new (); - if (camel_mime_message_get_from (msg) == NULL) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "Cannot send message: no from address set."); + g_warning ("Cannot send message: no from address set."); return; } - trans = camel_session_get_service (solipa_get_camel_session (priv->solipa), url, CAMEL_PROVIDER_TRANSPORT, ex); - if (camel_exception_is_set (ex)) + error = NULL; + trans = camel_session_get_service (solipa_get_camel_session (priv->solipa), url, CAMEL_PROVIDER_TRANSPORT, &error); + if (trans == NULL || error != NULL) { - g_warning ("Not service: %s", camel_exception_get_description (ex)); + g_warning ("Not service: %s", + error != NULL && error->message != NULL ? error->message : "no details"); return; } - gboolean ret = camel_service_connect (trans, ex); - if (camel_exception_is_set (ex)) + error = NULL; + ret = camel_service_connect (trans, &error); + if (!ret || error != NULL) { - g_warning ("Not connected: %s", camel_exception_get_description (ex)); + g_warning ("Not connected: %s", + error != NULL && error->message != NULL ? error->message : "no details"); goto noconnect; } @@ -404,12 +421,17 @@ solipa_mail_send (SolipaMail *mail, const gchar *url) } } - camel_transport_send_to (CAMEL_TRANSPORT (trans), msg, CAMEL_ADDRESS (camel_mime_message_get_from (msg)), CAMEL_ADDRESS (to), ex); - camel_object_unref (to); + ret = camel_transport_send_to (CAMEL_TRANSPORT (trans), msg, CAMEL_ADDRESS (camel_mime_message_get_from (msg)), CAMEL_ADDRESS (to), &error); + if (!ret || error != NULL) + { + g_warning ("Unable to send the email: %s", + error != NULL && error->message != NULL ? error->message : "no details"); + } + g_object_unref (to); camel_service_disconnect (trans, FALSE, NULL); noconnect: - camel_object_unref (trans); + g_object_unref (trans); } /* PRIVATE */ diff --git a/src/solipa.c b/src/solipa.c index 4556771..86ac2e7 100644 --- a/src/solipa.c +++ b/src/solipa.c @@ -25,6 +25,7 @@ #include #include "solipa.h" +#include "camelsession.h" #include "utils.h" static void solipa_class_init (SolipaClass *class); @@ -92,7 +93,6 @@ Solipa solipa = SOLIPA (g_object_new (solipa_get_type (), NULL)); priv = SOLIPA_GET_PRIVATE (solipa); -#ifndef G_OS_WIN32 /* creo la directory temporanea per camel */ camel_tmpdir = g_mkdtemp (g_build_filename (g_get_tmp_dir (), g_strdup ("solipa-camel-XXXXXX"), NULL)); @@ -101,7 +101,6 @@ Solipa camel_provider_init (); priv->camel_session = solipa_camel_session_new (camel_tmpdir); -#endif /* gui */ #ifdef G_OS_WIN32 diff --git a/tests/mail.c b/tests/mail.c index 0c112f6..26f6673 100644 --- a/tests/mail.c +++ b/tests/mail.c @@ -42,7 +42,7 @@ main (int argc, char **argv) camel_internet_address_add (addr, "tux", "tux@sid-sviluppo.miodominio.it"); solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO); - camel_object_unref (addr); + g_object_unref (addr); solipa_mail_set_body (smail, "This is the text\nof the email\n that i'm trying to send to myself.\n\nBye bye\n\nSee you later.", NULL); -- 2.49.0