1 /* modest-tny-transport-actions.c */
3 /* insert (c)/licensing information) */
6 #include <tny-msg-iface.h>
7 #include <tny-msg-mime-part.h>
8 #include <tny-msg-mime-part-iface.h>
9 #include <tny-stream-iface.h>
10 #include <tny-msg-header.h>
11 #include <tny-msg-header-iface.h>
12 #include <tny-account-iface.h>
13 #include <tny-account-store-iface.h>
14 #include <tny-transport-account-iface.h>
15 #include <tny-transport-account.h>
16 #include <tny-stream-camel.h>
18 #include <camel/camel-folder.h>
19 #include <camel/camel.h>
20 #include <camel/camel-folder-summary.h>
24 #include "modest-tny-transport-actions.h"
25 /* include other impl specific header files */
27 /* 'private'/'protected' functions */
28 static void modest_tny_transport_actions_class_init (ModestTnyTransportActionsClass *klass);
29 static void modest_tny_transport_actions_init (ModestTnyTransportActions *obj);
30 static void modest_tny_transport_actions_finalize (GObject *obj);
39 typedef struct _ModestTnyTransportActionsPrivate ModestTnyTransportActionsPrivate;
40 struct _ModestTnyTransportActionsPrivate {
41 /* my private members go here, eg. */
42 /* gboolean frobnicate_mode; */
44 #define MODEST_TNY_TRANSPORT_ACTIONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
45 MODEST_TYPE_TNY_TRANSPORT_ACTIONS, \
46 ModestTnyTransportActionsPrivate))
48 static GObjectClass *parent_class = NULL;
50 /* uncomment the following if you have defined any signals */
51 /* static guint signals[LAST_SIGNAL] = {0}; */
54 modest_tny_transport_actions_get_type (void)
56 static GType my_type = 0;
58 static const GTypeInfo my_info = {
59 sizeof(ModestTnyTransportActionsClass),
61 NULL, /* base finalize */
62 (GClassInitFunc) modest_tny_transport_actions_class_init,
63 NULL, /* class finalize */
64 NULL, /* class data */
65 sizeof(ModestTnyTransportActions),
67 (GInstanceInitFunc) modest_tny_transport_actions_init,
69 my_type = g_type_register_static (G_TYPE_OBJECT,
70 "ModestTnyTransportActions",
77 modest_tny_transport_actions_class_init (ModestTnyTransportActionsClass *klass)
79 GObjectClass *gobject_class;
80 gobject_class = (GObjectClass*) klass;
82 parent_class = g_type_class_peek_parent (klass);
83 gobject_class->finalize = modest_tny_transport_actions_finalize;
85 g_type_class_add_private (gobject_class, sizeof(ModestTnyTransportActionsPrivate));
87 /* signal definitions go here, e.g.: */
88 /* signals[MY_SIGNAL_1] = */
89 /* g_signal_new ("my_signal_1",....); */
90 /* signals[MY_SIGNAL_2] = */
91 /* g_signal_new ("my_signal_2",....); */
96 modest_tny_transport_actions_init (ModestTnyTransportActions *obj)
98 /* uncomment the following if you init any of the private data */
99 /* ModestTnyTransportActionsPrivate *priv = MODEST_TNY_TRANSPORT_ACTIONS_GET_PRIVATE(obj); */
101 /* initialize this object, eg.: */
102 /* priv->frobnicate_mode = FALSE; */
106 modest_tny_transport_actions_finalize (GObject *obj)
108 /* free/unref instance resources here */
112 modest_tny_transport_actions_new (void)
114 return G_OBJECT(g_object_new(MODEST_TYPE_TNY_TRANSPORT_ACTIONS, NULL));
120 modest_tny_transport_actions_send_message (ModestTnyTransportActions *self,
121 TnyTransportAccountIface *transport_account,
126 const gchar *subject,
129 TnyMsgIface *new_msg;
130 TnyMsgMimePartIface *body_part;
131 TnyMsgHeaderIface *headers;
132 TnyStreamIface *body_stream;
134 new_msg = TNY_MSG_IFACE(tny_msg_new ());
135 headers = TNY_MSG_HEADER_IFACE(tny_msg_header_new ());
136 body_stream = TNY_STREAM_IFACE (tny_stream_camel_new
137 (camel_stream_mem_new_with_buffer
138 (body, strlen(body))));
139 body_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new
140 (camel_mime_part_new()));
142 tny_msg_header_iface_set_from (TNY_MSG_HEADER_IFACE (headers), from);
143 tny_msg_header_iface_set_to (TNY_MSG_HEADER_IFACE (headers), to);
144 tny_msg_header_iface_set_cc (TNY_MSG_HEADER_IFACE (headers), cc);
145 tny_msg_header_iface_set_bcc (TNY_MSG_HEADER_IFACE (headers), bcc);
146 tny_msg_header_iface_set_subject (TNY_MSG_HEADER_IFACE (headers), subject);
148 tny_msg_iface_set_header (new_msg, headers);
149 tny_msg_mime_part_iface_construct_from_stream (body_part, body_stream,
151 tny_msg_mime_part_iface_set_content_type (body_part,"text/plain");
153 tny_msg_mime_part_iface_set_content_type (
154 TNY_MSG_MIME_PART_IFACE(new_msg), "text/plain");
155 tny_stream_iface_reset (body_stream);
157 tny_msg_mime_part_iface_construct_from_stream (TNY_MSG_MIME_PART_IFACE(new_msg),
158 body_stream, "text/plain");
160 tny_transport_account_iface_send (transport_account, new_msg);
162 g_object_unref (G_OBJECT(body_stream));
163 g_object_unref (G_OBJECT(body_part));
164 g_object_unref (G_OBJECT(headers));
165 g_object_unref (G_OBJECT(new_msg));