1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* evolution-composer.c
*
* Copyright (C) 2000 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* published by the Free Software Foundation; either version 2 of the
* 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 General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Dan Winship <danw@ximian.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gtk/gtksignal.h>
#include <bonobo/bonobo-item-handler.h>
#include <bonobo/bonobo-generic-factory.h>
#include <gal/util/e-util.h>
#include <gal/widgets/e-gui-utils.h>
#include <camel/camel.h>
#include "evolution-composer.h"
#include "mail/mail-config.h"
#include "e-util/e-html-utils.h"
#define PARENT_TYPE BONOBO_OBJECT_TYPE
static BonoboObjectClass *parent_class = NULL;
static void (*send_cb) (EMsgComposer *, gpointer);
static void (*save_draft_cb) (EMsgComposer *, int, gpointer);
/* CORBA interface implementation. */
static POA_GNOME_Evolution_Composer__vepv Composer_vepv;
static EDestination **
corba_recipientlist_to_destv (const GNOME_Evolution_Composer_RecipientList *cl)
{
GNOME_Evolution_Composer_Recipient *recip;
EDestination **destv;
int i;
if (cl->_length == 0)
return NULL;
destv = g_new (EDestination *, cl->_length+1);
for (i = 0; i < cl->_length; ++i) {
recip = &(cl->_buffer[i]);
destv[i] = e_destination_new ();
if (*recip->name)
e_destination_set_name (destv[i], recip->name);
e_destination_set_email (destv[i], recip->address);
}
destv[cl->_length] = NULL;
return destv;
}
static void
impl_Composer_set_headers (PortableServer_Servant servant,
const CORBA_char *from,
const GNOME_Evolution_Composer_RecipientList *to,
const GNOME_Evolution_Composer_RecipientList *cc,
const GNOME_Evolution_Composer_RecipientList *bcc,
const CORBA_char *subject,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
EDestination **tov, **ccv, **bccv;
const MailConfigAccount *account;
const GSList *accounts;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
account = mail_config_get_account_by_name (from);
if (!account) {
accounts = mail_config_get_accounts ();
while (accounts) {
account = accounts->data;
if (!g_strcasecmp (account->id->address, from))
break;
accounts = accounts->next;
}
if (!accounts)
account = mail_config_get_default_account ();
}
tov = corba_recipientlist_to_destv (to);
ccv = corba_recipientlist_to_destv (cc);
bccv = corba_recipientlist_to_destv (bcc);
e_msg_composer_set_headers (composer->composer, account->name,
tov, ccv, bccv, subject);
e_destination_freev (tov);
e_destination_freev (ccv);
e_destination_freev (bccv);
}
static void
impl_Composer_set_multipart_type (PortableServer_Servant servant,
GNOME_Evolution_Composer_MultipartType type,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
if (type == GNOME_Evolution_Composer_ALTERNATIVE) {
composer->composer->is_alternative = TRUE;
composer->composer->send_html = FALSE;
}
}
static void
impl_Composer_set_body (PortableServer_Servant servant,
const CORBA_char *body,
const CORBA_char *mime_type,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
if (!g_strcasecmp (mime_type, "text/plain")) {
char *htmlbody = e_text_to_html (body, E_TEXT_TO_HTML_PRE);
e_msg_composer_set_body_text (composer->composer, htmlbody);
g_free (htmlbody);
} else if (!g_strcasecmp (mime_type, "text/html"))
e_msg_composer_set_body_text (composer->composer, body);
else
e_msg_composer_set_body (composer->composer, body, mime_type);
}
static void
impl_Composer_attach_MIME (PortableServer_Servant servant,
const CORBA_char *data,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
CamelMimePart *attachment;
CamelStream *mem_stream;
int status;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
mem_stream = camel_stream_mem_new_with_buffer (data, strlen (data));
attachment = camel_mime_part_new ();
status = camel_data_wrapper_construct_from_stream (
CAMEL_DATA_WRAPPER (attachment), mem_stream);
camel_object_unref (CAMEL_OBJECT (mem_stream));
if (status == -1) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Composer_CouldNotParse,
NULL);
return;
}
e_msg_composer_attach (composer->composer, attachment);
camel_object_unref (CAMEL_OBJECT (attachment));
}
static void
impl_Composer_attach_data (PortableServer_Servant servant,
const CORBA_char *content_type,
const CORBA_char *filename,
const CORBA_char *description,
const CORBA_boolean show_inline,
const GNOME_Evolution_Composer_AttachmentData *data,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
CamelMimePart *attachment;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
attachment = camel_mime_part_new ();
camel_mime_part_set_content (attachment, data->_buffer, data->_length,
content_type);
if (*filename)
camel_mime_part_set_filename (attachment, filename);
if (*description)
camel_mime_part_set_description (attachment, description);
camel_mime_part_set_disposition (attachment, show_inline ?
"inline" : "attachment");
e_msg_composer_attach (composer->composer, attachment);
camel_object_unref (CAMEL_OBJECT (attachment));
}
static void
impl_Composer_show (PortableServer_Servant servant,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
gtk_widget_show (GTK_WIDGET (composer->composer));
}
static void
impl_Composer_send (PortableServer_Servant servant,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EvolutionComposer *composer;
bonobo_object = bonobo_object_from_servant (servant);
composer = EVOLUTION_COMPOSER (bonobo_object);
send_cb (composer->composer, NULL);
}
POA_GNOME_Evolution_Composer__epv *
evolution_composer_get_epv (void)
{
POA_GNOME_Evolution_Composer__epv *epv;
epv = g_new0 (POA_GNOME_Evolution_Composer__epv, 1);
epv->setHeaders = impl_Composer_set_headers;
epv->setMultipartType = impl_Composer_set_multipart_type;
epv->setBody = impl_Composer_set_body;
epv->attachMIME = impl_Composer_attach_MIME;
epv->attachData = impl_Composer_attach_data;
epv->show = impl_Composer_show;
epv->send = impl_Composer_send;
return epv;
}
/* GtkObject stuff */
static void
destroy (GtkObject *object)
{
EvolutionComposer *composer = EVOLUTION_COMPOSER (object);
if (composer->composer)
gtk_object_unref (GTK_OBJECT (composer->composer));
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
class_init (EvolutionComposerClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = destroy;
parent_class = gtk_type_class (bonobo_object_get_type ());
Composer_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv ();
Composer_vepv.GNOME_Evolution_Composer_epv = evolution_composer_get_epv ();
}
static void
init (EvolutionComposer *composer)
{
const MailConfigAccount *account;
account = mail_config_get_default_account ();
composer->composer = e_msg_composer_new ();
gtk_signal_connect (GTK_OBJECT (composer->composer), "send",
GTK_SIGNAL_FUNC (send_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer->composer), "save-draft",
GTK_SIGNAL_FUNC (save_draft_cb), NULL);
}
#if 0
static Bonobo_ItemContainer_ObjectNames *
enum_objects (BonoboItemHandler *handler, gpointer data, CORBA_Environment *ev)
{
}
#endif
static Bonobo_Unknown
get_object (BonoboItemHandler *h, const char *item_name, gboolean only_if_exists,
gpointer data, CORBA_Environment *ev)
{
EvolutionComposer *composer = data;
GSList *options, *l;
options = bonobo_item_option_parse (item_name);
for (l = options; l; l = l->next){
BonoboItemOption *option = l->data;
if (strcmp (option->key, "visible") == 0){
gboolean show = 1;
if (option->value)
show = atoi (option->value);
if (show)
gtk_widget_show (GTK_WIDGET (composer->composer));
else
gtk_widget_hide (GTK_WIDGET (composer->composer));
}
}
return bonobo_object_dup_ref (
BONOBO_OBJECT (composer)->corba_objref, ev);
}
void
evolution_composer_construct (EvolutionComposer *composer,
GNOME_Evolution_Composer corba_object)
{
BonoboObject *item_handler;
g_return_if_fail (composer != NULL);
g_return_if_fail (EVOLUTION_IS_COMPOSER (composer));
g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
bonobo_object_construct (BONOBO_OBJECT (composer), corba_object);
item_handler = BONOBO_OBJECT (
bonobo_item_handler_new (NULL, get_object, composer));
bonobo_object_add_interface (BONOBO_OBJECT (composer), BONOBO_OBJECT (item_handler));
}
EvolutionComposer *
evolution_composer_new (void)
{
EvolutionComposer *new;
POA_GNOME_Evolution_Composer *servant;
CORBA_Environment ev;
GNOME_Evolution_Composer corba_object;
servant = (POA_GNOME_Evolution_Composer *) g_new0 (BonoboObjectServant, 1);
servant->vepv = &Composer_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Evolution_Composer__init ((PortableServer_Servant) servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_free (servant);
CORBA_exception_free (&ev);
return NULL;
}
CORBA_exception_free (&ev);
new = gtk_type_new (evolution_composer_get_type ());
corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (new),
servant);
evolution_composer_construct (new, corba_object);
return new;
}
E_MAKE_TYPE (evolution_composer, "EvolutionComposer", EvolutionComposer, class_init, init, PARENT_TYPE)
#define GNOME_EVOLUTION_MAIL_COMPOSER_FACTORY_ID "OAFIID:GNOME_Evolution_Mail_ComposerFactory"
static BonoboObject *
factory_fn (BonoboGenericFactory *factory, void *closure)
{
if (!mail_config_is_configured ()) {
e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
_("Could not create composer window, because you "
"have not yet\nconfigured any identities in the "
"mail component."));
return NULL;
}
return BONOBO_OBJECT (evolution_composer_new ());
}
void
evolution_composer_factory_init (void (*send) (EMsgComposer *, gpointer),
void (*save_draft) (EMsgComposer *, int, gpointer))
{
if (bonobo_generic_factory_new (GNOME_EVOLUTION_MAIL_COMPOSER_FACTORY_ID,
factory_fn, NULL) == NULL) {
e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
_("Cannot initialize Evolution's composer."));
exit (1);
}
send_cb = send;
save_draft_cb = save_draft;
}
|