From: Dirk-Jan C. Binnema Date: Fri, 12 May 2006 12:37:40 +0000 (+0000) Subject: * first hackish implementation of *sending* mail X-Git-Tag: git_migration_finished~4798 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=b53b477100c6e2ea5c424fba05c232aa7a016679 * first hackish implementation of *sending* mail pmo-trunk-r50 --- diff --git a/src/Makefile.am b/src/Makefile.am index cbfc400..a65d0d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,9 @@ modest_SOURCES=\ modest-tny-msg-view.c\ modest-proto.h\ modest-proto.c\ + modest-ui.h\ + modest-tny-transport-actions.c\ + modest-tny-transport-actions.h\ modest-ui.h modest_LDADD = \ diff --git a/src/modest-tny-transport-actions.c b/src/modest-tny-transport-actions.c new file mode 100644 index 0000000..822b743 --- /dev/null +++ b/src/modest-tny-transport-actions.c @@ -0,0 +1,171 @@ +/* modest-tny-transport-actions.c */ + +/* insert (c)/licensing information) */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#include "modest-tny-transport-actions.h" +/* include other impl specific header files */ + +/* 'private'/'protected' functions */ +static void modest_tny_transport_actions_class_init (ModestTnyTransportActionsClass *klass); +static void modest_tny_transport_actions_init (ModestTnyTransportActions *obj); +static void modest_tny_transport_actions_finalize (GObject *obj); + +/* list my signals */ +enum { + /* MY_SIGNAL_1, */ + /* MY_SIGNAL_2, */ + LAST_SIGNAL +}; + +typedef struct _ModestTnyTransportActionsPrivate ModestTnyTransportActionsPrivate; +struct _ModestTnyTransportActionsPrivate { + /* my private members go here, eg. */ + /* gboolean frobnicate_mode; */ +}; +#define MODEST_TNY_TRANSPORT_ACTIONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_TNY_TRANSPORT_ACTIONS, \ + ModestTnyTransportActionsPrivate)) +/* globals */ +static GObjectClass *parent_class = NULL; + +/* uncomment the following if you have defined any signals */ +/* static guint signals[LAST_SIGNAL] = {0}; */ + +GType +modest_tny_transport_actions_get_type (void) +{ + static GType my_type = 0; + if (!my_type) { + static const GTypeInfo my_info = { + sizeof(ModestTnyTransportActionsClass), + NULL, /* base init */ + NULL, /* base finalize */ + (GClassInitFunc) modest_tny_transport_actions_class_init, + NULL, /* class finalize */ + NULL, /* class data */ + sizeof(ModestTnyTransportActions), + 1, /* n_preallocs */ + (GInstanceInitFunc) modest_tny_transport_actions_init, + }; + my_type = g_type_register_static (G_TYPE_OBJECT, + "ModestTnyTransportActions", + &my_info, 0); + } + return my_type; +} + +static void +modest_tny_transport_actions_class_init (ModestTnyTransportActionsClass *klass) +{ + GObjectClass *gobject_class; + gobject_class = (GObjectClass*) klass; + + parent_class = g_type_class_peek_parent (klass); + gobject_class->finalize = modest_tny_transport_actions_finalize; + + g_type_class_add_private (gobject_class, sizeof(ModestTnyTransportActionsPrivate)); + + /* signal definitions go here, e.g.: */ +/* signals[MY_SIGNAL_1] = */ +/* g_signal_new ("my_signal_1",....); */ +/* signals[MY_SIGNAL_2] = */ +/* g_signal_new ("my_signal_2",....); */ +/* etc. */ +} + +static void +modest_tny_transport_actions_init (ModestTnyTransportActions *obj) +{ +/* uncomment the following if you init any of the private data */ +/* ModestTnyTransportActionsPrivate *priv = MODEST_TNY_TRANSPORT_ACTIONS_GET_PRIVATE(obj); */ + +/* initialize this object, eg.: */ +/* priv->frobnicate_mode = FALSE; */ +} + +static void +modest_tny_transport_actions_finalize (GObject *obj) +{ +/* free/unref instance resources here */ +} + +GObject* +modest_tny_transport_actions_new (void) +{ + return G_OBJECT(g_object_new(MODEST_TYPE_TNY_TRANSPORT_ACTIONS, NULL)); +} + + + +gboolean +modest_tny_transport_actions_send_message (ModestTnyTransportActions *self, + TnyTransportAccountIface *transport_account, + const gchar *from, + const gchar *to, + const gchar *cc, + const gchar *bcc, + const gchar *subject, + const gchar *body) +{ + TnyMsgIface *new_msg; + TnyMsgMimePartIface *body_part; + TnyMsgHeaderIface *headers; + TnyStreamIface *body_stream; + + new_msg = TNY_MSG_IFACE(tny_msg_new ()); + headers = TNY_MSG_HEADER_IFACE(tny_msg_header_new ()); + body_stream = TNY_STREAM_IFACE (tny_stream_camel_new + (camel_stream_mem_new_with_buffer + (body, strlen(body)))); + body_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new + (camel_mime_part_new())); + + tny_msg_header_iface_set_from (TNY_MSG_HEADER_IFACE (headers), from); + tny_msg_header_iface_set_to (TNY_MSG_HEADER_IFACE (headers), to); + tny_msg_header_iface_set_cc (TNY_MSG_HEADER_IFACE (headers), cc); + tny_msg_header_iface_set_bcc (TNY_MSG_HEADER_IFACE (headers), bcc); + tny_msg_header_iface_set_subject (TNY_MSG_HEADER_IFACE (headers), subject); + + tny_msg_iface_set_header (new_msg, headers); + tny_msg_mime_part_iface_construct_from_stream (body_part, body_stream, + "text/plain"); + tny_msg_mime_part_iface_set_content_type (body_part,"text/plain"); + + tny_msg_mime_part_iface_set_content_type ( + TNY_MSG_MIME_PART_IFACE(new_msg), "text/plain"); + tny_stream_iface_reset (body_stream); + + tny_msg_mime_part_iface_construct_from_stream (TNY_MSG_MIME_PART_IFACE(new_msg), + body_stream, "text/plain"); + + tny_transport_account_iface_send (transport_account, new_msg); + + g_object_unref (G_OBJECT(body_stream)); + g_object_unref (G_OBJECT(body_part)); + g_object_unref (G_OBJECT(headers)); + g_object_unref (G_OBJECT(new_msg)); + + return TRUE; +} + + + diff --git a/src/modest-tny-transport-actions.h b/src/modest-tny-transport-actions.h new file mode 100644 index 0000000..7fb6d51 --- /dev/null +++ b/src/modest-tny-transport-actions.h @@ -0,0 +1,55 @@ +/* modest-tny-transport-actions.h */ +/* insert (c)/licensing information) */ + +#ifndef __MODEST_TNY_TRANSPORT_ACTIONS_H__ +#define __MODEST_TNY_TRANSPORT_ACTIONS_H__ + +#include +#include + +G_BEGIN_DECLS + +/* standard convenience macros */ +#define MODEST_TYPE_TNY_TRANSPORT_ACTIONS (modest_tny_transport_actions_get_type()) +#define MODEST_TNY_TRANSPORT_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_TNY_TRANSPORT_ACTIONS,ModestTnyTransportActions)) +#define MODEST_TNY_TRANSPORT_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_TNY_TRANSPORT_ACTIONS,GObject)) +#define MODEST_IS_TNY_TRANSPORT_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_TNY_TRANSPORT_ACTIONS)) +#define MODEST_IS_TNY_TRANSPORT_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_TNY_TRANSPORT_ACTIONS)) +#define MODEST_TNY_TRANSPORT_ACTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_TNY_TRANSPORT_ACTIONS,ModestTnyTransportActionsClass)) + +typedef struct _ModestTnyTransportActions ModestTnyTransportActions; +typedef struct _ModestTnyTransportActionsClass ModestTnyTransportActionsClass; + +struct _ModestTnyTransportActions { + GObject parent; + /* insert public members, if any */ +}; + +struct _ModestTnyTransportActionsClass { + GObjectClass parent_class; + /* insert signal callback declarations, eg. */ + /* void (* my_event) (ModestTnyTransportActions* obj); */ +}; + +/* member functions */ +GType modest_tny_transport_actions_get_type (void) G_GNUC_CONST; + +/* typical parameter-less _new function */ +/* if this is a kind of GtkWidget, it should probably return at GtkWidget*, */ +/* otherwise probably a GObject*. */ +GObject* modest_tny_transport_actions_new (void); + + +gboolean modest_tny_transport_actions_send_message (ModestTnyTransportActions *self, + TnyTransportAccountIface *transport_account, + const gchar *from, + const gchar *to, + const gchar *cc, + const gchar *bcc, + const gchar *subject, + const gchar *body); + +G_END_DECLS + +#endif /* __MODEST_TNY_TRANSPORT_ACTIONS_H__ */ +