From ba27767315674343c4a943ac77c77102dac3d990 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 28 Nov 2010 10:45:19 +0100 Subject: [PATCH] Inizio di SolipaMail. --- configure.ac | 4 +- libsolipa.pc.in | 2 +- src/Makefile.am | 6 +- src/mail.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++++ src/mail.h | 79 ++++++++++++++++++ 5 files changed, 294 insertions(+), 4 deletions(-) create mode 100644 src/mail.c create mode 100644 src/mail.h diff --git a/configure.ac b/configure.ac index 4b78194..9e37eef 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,9 @@ AC_PROG_RANLIB # Checks for libraries. PKG_CHECK_MODULES(SOLIPA, [gobject-2.0 >= 2.24.0 glib-2.0 >= 2.24.0 - libgdaex >= 0.2.2]) + libgdaex >= 0.2.2 + camel-provider-1.2 >= 2.30 + gtk+-2.0 >= 2.20]) AC_SUBST(SOLIPA_CFLAGS) AC_SUBST(SOLIPA_LIBS) diff --git a/libsolipa.pc.in b/libsolipa.pc.in index c51fe91..b49fd98 100644 --- a/libsolipa.pc.in +++ b/libsolipa.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Classe con funzioni varie di utilità. Version: @PACKAGE_VERSION@ -Requires: glib-2.0 +Requires: glib-2.0 gobject-2.0 libgdaex camel-provider-1.2 gtk+-2.0 Libs: -L${libdir} -lsolipa Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index e16786d..01aab5f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,12 +5,14 @@ AM_CPPFLAGS = $(SOLIPA_CFLAGS) lib_LTLIBRARIES = libsolipa.la libsolipa_la_SOURCES = solipa.c \ - allegato.c + allegato.c \ + mail.c libsolipa_la_LDFLAGS = -no-undefined libsolipa_include_HEADERS = libsolipa.h \ solipa.h \ - allegato.h + allegato.h \ + mail.h libsolipa_includedir = $(includedir)/libsolipa diff --git a/src/mail.c b/src/mail.c new file mode 100644 index 0000000..52a9005 --- /dev/null +++ b/src/mail.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "mail.h" + +static void solipa_mail_class_init (SolipaMailClass *class); +static void solipa_mail_init (SolipaMail *solipa_mail); + +static void solipa_mail_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void solipa_mail_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define SOLIPA_MAIL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_SOLIPA_MAIL, SolipaMailPrivate)) + +typedef struct _SolipaMailPrivate SolipaMailPrivate; +struct _SolipaMailPrivate + { + Solipa *solipa; + + CamelInternetAddress *from; + + GSList *recipients_to; /* CamelInternetAddress */ + GSList *recipients_cc; /* CamelInternetAddress */ + GSList *recipients_bcc; /* CamelInternetAddress */ + + gchar *body_plain; + gchar *body_html; + + GSList *attachments; + }; + +G_DEFINE_TYPE (SolipaMail, solipa_mail, G_TYPE_OBJECT) + +static void +solipa_mail_class_init (SolipaMailClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = solipa_mail_set_property; + object_class->get_property = solipa_mail_get_property; + + g_type_class_add_private (object_class, sizeof (SolipaMailPrivate)); +} + +static void +solipa_mail_init (SolipaMail *solipa_mail) +{ + SolipaMailPrivate *priv = SOLIPA_MAIL_GET_PRIVATE (solipa_mail); + + priv->from = NULL; + priv->recipients_to = NULL; + priv->recipients_cc = NULL; + priv->recipients_bcc = NULL; + priv->body_plain = NULL; + priv->body_html = NULL; + priv->attachments = NULL; +} + +/** + * solipa_mail_new: + * @solipa: + * + * Returns: the newly created #SolipaMail object. + */ +SolipaMail +*solipa_mail_new (Solipa *solipa) +{ + SolipaMail *solipa_mail; + SolipaMailPrivate *priv; + + g_return_val_if_fail (IS_SOLIPA (solipa), NULL); + + solipa_mail = SOLIPA_MAIL (g_object_new (solipa_mail_get_type (), NULL)); + + priv = SOLIPA_MAIL_GET_PRIVATE (solipa_mail); + + priv->solipa = solipa; + + return solipa_mail; +} + +void +solipa_mail_set_from (SolipaMail *mail, CamelInternetAddress *from) +{ + SolipaMailPrivate *priv; + + g_return_if_fail (IS_SOLIPA_MAIL (mail)); + + priv = SOLIPA_MAIL_GET_PRIVATE (mail); + + priv->from = g_memdup (from, sizeof (CamelInternetAddress)); +} + +void +solipa_mail_add_recipient (SolipaMail *mail, CamelInternetAddress *recipient, SolipaMailRecipientType type) +{ + SolipaMailPrivate *priv; + + g_return_if_fail (IS_SOLIPA_MAIL (mail)); + + priv = SOLIPA_MAIL_GET_PRIVATE (mail); + + switch (type) + { + case SOLIPA_MAIL_RECIPIENT_TYPE_TO: + priv->recipients_to = g_slist_append (priv->recipients_to, (gpointer)recipient); + break; + + case SOLIPA_MAIL_RECIPIENT_TYPE_CC: + priv->recipients_cc = g_slist_append (priv->recipients_to, (gpointer)recipient); + break; + + case SOLIPA_MAIL_RECIPIENT_TYPE_BCC: + priv->recipients_bcc = g_slist_append (priv->recipients_to, (gpointer)recipient); + break; + + default: + g_warning ("Recipient of type «%d» not supported.", type); + break; + } +} + +void +solipa_mail_set_body (SolipaMail *mail, const gchar *body_plain, const gchar *body_html) +{ + SolipaMailPrivate *priv; + + g_return_if_fail (IS_SOLIPA_MAIL (mail)); + + priv = SOLIPA_MAIL_GET_PRIVATE (mail); + + priv->body_plain = g_strdup (body_plain); + priv->body_html = g_strdup (body_html); +} + +void +solipa_mail_add_attachment (SolipaMail *mail, const gchar *filename) +{ + SolipaMailPrivate *priv; + + g_return_if_fail (IS_SOLIPA_MAIL (mail)); + + priv = SOLIPA_MAIL_GET_PRIVATE (mail); + + priv->attachments = g_slist_append (priv->attachments, (gpointer)filename); +} + +/* PRIVATE */ +static void +solipa_mail_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + SolipaMail *solipa_mail = (SolipaMail *)object; + + SolipaMailPrivate *priv = SOLIPA_MAIL_GET_PRIVATE (solipa_mail); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +solipa_mail_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + SolipaMail *solipa_mail = (SolipaMail *)object; + + SolipaMailPrivate *priv = SOLIPA_MAIL_GET_PRIVATE (solipa_mail); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/mail.h b/src/mail.h new file mode 100644 index 0000000..45decd1 --- /dev/null +++ b/src/mail.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __SOLIPA_MAIL_H__ +#define __SOLIPA_MAIL_H__ + +#include +#include + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_SOLIPA_MAIL (solipa_mail_get_type ()) +#define SOLIPA_MAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SOLIPA_MAIL, SolipaMail)) +#define SOLIPA_MAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SOLIPA_MAIL, SolipaMailClass)) +#define IS_SOLIPA_MAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SOLIPA_MAIL)) +#define IS_SOLIPA_MAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SOLIPA_MAIL)) +#define SOLIPA_MAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SOLIPA_MAIL, SolipaMailClass)) + +typedef struct _SolipaMail SolipaMail; +typedef struct _SolipaMailClass SolipaMailClass; + +struct _SolipaMail + { + GObject parent; + }; + +struct _SolipaMailClass + { + GObjectClass parent_class; + }; + +GType solipa_mail_get_type (void) G_GNUC_CONST; + + +SolipaMail *solipa_mail_new (Solipa *solipa); + +void solipa_mail_set_from (SolipaMail *mail, CamelInternetAddress *from); + +typedef enum +{ + SOLIPA_MAIL_RECIPIENT_TYPE_TO, + SOLIPA_MAIL_RECIPIENT_TYPE_CC, + SOLIPA_MAIL_RECIPIENT_TYPE_BCC +} SolipaMailRecipientType; + +void solipa_mail_add_recipient (SolipaMail *mail, CamelInternetAddress *recipient, SolipaMailRecipientType type); + +void solipa_mail_set_body (SolipaMail *mail, const gchar *body_plain, const gchar *body_html); + +void solipa_mail_add_attachment (SolipaMail *mail, const gchar *filename); + +gchar *solipa_mail_get_as_string (SolipaMail *mail); + + +G_END_DECLS + + +#endif /* __SOLIPA_MAIL_H__ */ -- 2.49.0