aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-remote
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2005-05-27 19:18:41 +0800
committerMichael Zucci <zucchi@src.gnome.org>2005-05-27 19:18:41 +0800
commit7265cc314c68f9b9b0196661540bed628b5aad16 (patch)
tree33ad1883f3d4a77c202fbd242a0d06313b870e21 /plugins/mail-remote
parent07419207d4478491adfbcc63776388db5723787b (diff)
downloadgsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.gz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.bz2
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.lz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.xz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.zst
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.zip
A camel-stream to wrap Evolution_Mail_MessageStream.
2005-05-27 Not Zed <NotZed@Ximian.com> * em-message-stream.[ch]: A camel-stream to wrap Evolution_Mail_MessageStream. * evolution-mail-messagestream.[ch]: simplified read-only stream interface rather than using bonobo-stream. It wraps a camel-stream only & simplified lifecycle management. * evolution-mail-store.c (evolution_mail_store_changed): if we have no more listeners, close the camelstore object off. * Evolution-DataServer-Mail.idl: changed exceptions to use one exception type with details. Fixed code to use these. svn path=/trunk/; revision=29418
Diffstat (limited to 'plugins/mail-remote')
-rw-r--r--plugins/mail-remote/ChangeLog15
-rw-r--r--plugins/mail-remote/Evolution-DataServer-Mail.idl84
-rw-r--r--plugins/mail-remote/Makefile.am5
-rw-r--r--plugins/mail-remote/client.c112
-rw-r--r--plugins/mail-remote/e-corba-utils.c91
-rw-r--r--plugins/mail-remote/e-corba-utils.h10
-rw-r--r--plugins/mail-remote/em-message-stream.c144
-rw-r--r--plugins/mail-remote/em-message-stream.h57
-rw-r--r--plugins/mail-remote/evolution-mail-folder.c86
-rw-r--r--plugins/mail-remote/evolution-mail-folder.h5
-rw-r--r--plugins/mail-remote/evolution-mail-messageiterator.c2
-rw-r--r--plugins/mail-remote/evolution-mail-messageiterator.h2
-rw-r--r--plugins/mail-remote/evolution-mail-messagestream.c158
-rw-r--r--plugins/mail-remote/evolution-mail-messagestream.h53
-rw-r--r--plugins/mail-remote/evolution-mail-session.c2
-rw-r--r--plugins/mail-remote/evolution-mail-store.c69
-rw-r--r--plugins/mail-remote/evolution-mail-store.h5
17 files changed, 726 insertions, 174 deletions
diff --git a/plugins/mail-remote/ChangeLog b/plugins/mail-remote/ChangeLog
index de6a0cb4b9..2e687b633a 100644
--- a/plugins/mail-remote/ChangeLog
+++ b/plugins/mail-remote/ChangeLog
@@ -1,3 +1,18 @@
+2005-05-27 Not Zed <NotZed@Ximian.com>
+
+ * em-message-stream.[ch]: A camel-stream to wrap
+ Evolution_Mail_MessageStream.
+
+ * evolution-mail-messagestream.[ch]: simplified read-only stream
+ interface rather than using bonobo-stream. It wraps a
+ camel-stream only & simplified lifecycle management.
+
+ * evolution-mail-store.c (evolution_mail_store_changed): if we
+ have no more listeners, close the camelstore object off.
+
+ * Evolution-DataServer-Mail.idl: changed exceptions to use one
+ exception type with details. Fixed code to use these.
+
2005-05-26 Not Zed <NotZed@Ximian.com>
* evolution-mail-folderlistener.[ch]:
diff --git a/plugins/mail-remote/Evolution-DataServer-Mail.idl b/plugins/mail-remote/Evolution-DataServer-Mail.idl
index 4d6b0ad43d..453637f643 100644
--- a/plugins/mail-remote/Evolution-DataServer-Mail.idl
+++ b/plugins/mail-remote/Evolution-DataServer-Mail.idl
@@ -1,4 +1,4 @@
-/* Evolution Mail Interface
+/* Evolution Mail Data Interface
*
* Copyright (C) 2005 Novell, Inc.
*
@@ -12,14 +12,34 @@
module Evolution {
module Mail {
- exception NOT_SUPPORTED {
-// string why;
+ /* ********************************************************************** */
+ // NB: tiny subset of omg properties service
+ typedef string PropertyName;
+ typedef sequence <PropertyName> PropertyNames;
+ struct Property {
+ PropertyName name;
+ any value;
+ };
+ typedef sequence <Property> Properties;
+
+ /* ********************************************************************** */
+ // exceptions
+
+ enum ErrorType {
+ SYSTEM_ERROR,
+ CAMEL_ERROR,
+ FAILED,
+ NOT_SUPPORTED,
+ NO_PERMISSION
};
- exception FAILED {
-// string why;
+ exception MailException {
+ ErrorType id;
+ string desc;
};
+ /* ********************************************************************** */
+ // Main interfaces
interface Folder;
typedef sequence<Folder> Folders;
@@ -76,14 +96,22 @@ module Mail {
typedef sequence <MessageInfoSet> MessageInfoSets;
/* ********************************************************************** */
- // NB: tiny subset of omg properties service
- typedef string PropertyName;
- typedef sequence <PropertyName> PropertyNames;
- struct Property {
- PropertyName name;
- any value;
+ /* Messages are passed as full rfc822 encoded messages in a stream */
+ typedef sequence <octet>Buffer;
+
+ interface MessageStream : Bonobo::Unknown {
+ Buffer next(in long size)
+ raises (MailException);
+
+ void dispose();
+ };
+
+ interface MessageIterator : Bonobo::Unknown {
+ MessageInfos next(in long limit)
+ raises (MailException);
+
+ void dispose();
};
- typedef sequence <Property> Properties;
/* ********************************************************************** */
@@ -119,6 +147,10 @@ module Mail {
oneway void changed(in Session session, in SessionChanges changes);
oneway void shutdown(in Session session);
+
+ // We need to use gnome-keyring instead of an interface like this?
+ // Or does gnome-keyring run off this?
+ //string getPassword(in Session session, string uri, string domain, string item, string prompt, long flags);
};
interface StoreListener : Bonobo::Unknown {
@@ -139,7 +171,8 @@ module Mail {
interface Session : Bonobo::Unknown {
boolean getProperties(in PropertyNames names, out Properties props);
- StoreInfos getStores(in string pattern, in StoreListener listener);
+ StoreInfos getStores(in string pattern, in StoreListener listener)
+ raises (MailException);
void addListener(in SessionListener listener);
void removeListener(in SessionListener listener);
@@ -149,33 +182,26 @@ module Mail {
boolean getProperties(in PropertyNames names, out Properties props);
FolderInfos getFolders(in string pattern, in FolderListener listener)
- raises (NOT_SUPPORTED, FAILED);
-
- void sendMessage(in Bonobo::Stream msg)
- raises (NOT_SUPPORTED, FAILED);
- };
+ raises (MailException);
- interface MessageIterator : Bonobo::Unknown {
- MessageInfos next(in long limit)
- raises (FAILED);
-
- void dispose();
+ void sendMessage(in MessageStream msg)
+ raises (MailException);
};
interface Folder : Bonobo::Unknown {
boolean getProperties(in PropertyNames names, out Properties props);
MessageIterator getMessages(in string pattern)
- raises (NOT_SUPPORTED, FAILED);
+ raises (MailException);
void changeMessages(in MessageInfoSets infos)
- raises (NOT_SUPPORTED);
+ raises (MailException);
- Bonobo::Stream getMessage(in string uid)
- raises (NOT_SUPPORTED, FAILED);
+ MessageStream getMessage(in string uid)
+ raises (MailException);
- void appendMessage(in MessageInfoSet info, in Bonobo::Stream msg)
- raises (NOT_SUPPORTED, FAILED);
+ void appendMessage(in MessageInfoSet info, in MessageStream msg)
+ raises (MailException);
};
};
};
diff --git a/plugins/mail-remote/Makefile.am b/plugins/mail-remote/Makefile.am
index 8214ce36f1..80fb0fcc97 100644
--- a/plugins/mail-remote/Makefile.am
+++ b/plugins/mail-remote/Makefile.am
@@ -13,6 +13,8 @@ liborg_gnome_evolution_mail_remote_la_SOURCES = \
$(IDL_GENERATED_H) \
e-corba-utils.c \
e-corba-utils.h \
+ em-message-stream.c \
+ em-message-stream.h \
evolution-mail-folder.c \
evolution-mail-folder.h \
evolution-mail-folderlistener.c \
@@ -21,6 +23,8 @@ liborg_gnome_evolution_mail_remote_la_SOURCES = \
evolution-mail-marshal.h \
evolution-mail-messageiterator.c \
evolution-mail-messageiterator.h \
+ evolution-mail-messagestream.c \
+ evolution-mail-messagestream.h \
evolution-mail-session.c \
evolution-mail-session.h \
evolution-mail-sessionlistener.c \
@@ -42,6 +46,7 @@ client_LDADD = \
evolution-mail-storelistener.o \
evolution-mail-folderlistener.o \
evolution-mail-marshal.o \
+ evolution-mail-messagestream.o \
Evolution-DataServer-Mail-common.o \
Evolution-DataServer-Mail-stubs.o \
Evolution-DataServer-Mail-skels.o
diff --git a/plugins/mail-remote/client.c b/plugins/mail-remote/client.c
index 0db3212426..8e97a1c618 100644
--- a/plugins/mail-remote/client.c
+++ b/plugins/mail-remote/client.c
@@ -9,6 +9,7 @@
#include "evolution-mail-sessionlistener.h"
#include "evolution-mail-storelistener.h"
#include "evolution-mail-folderlistener.h"
+#include "evolution-mail-messagestream.h"
#include <camel/camel-folder.h>
@@ -16,6 +17,72 @@ static EvolutionMailSessionListener *listener_sess;
static EvolutionMailStoreListener *listener_store;
static EvolutionMailFolderListener *listener_folder;
+#if 0
+static char *
+em_map_mail_ex(CORBA_Environment *ev, void *data)
+{
+ Evolution_Mail_MailException *x = CORBA_exception_value(ev);
+
+ switch (x->id) {
+ case Evolution_Mail_SYSTEM_ERROR:
+ return g_strdup_printf(_("System error: %s"), x->desc);
+ case Evolution_Mail_CAMEL_ERROR:
+ return g_strdup_printf(_("Camel error: %s"), x->desc);
+ default:
+ return g_strdup(x->desc);
+ }
+}
+#endif
+
+static void e_mail_exception_dump(CORBA_Environment *ev, char *what)
+{
+#if 0
+ static int init = 0;
+ char *d;
+
+ /* *shrug* this doesn't work */
+ if (!init) {
+ bonobo_exception_add_handler_fn(ex_Evolution_Mail_MailException, em_map_mail_ex, NULL, NULL);
+ init = 1;
+ }
+
+ d = bonobo_exception_get_text(ev);
+
+ if (d) {
+ printf("Failed %s: %s\n", what, d);
+ g_free(d);
+ }
+ CORBA_exception_free(ev);
+#else
+ const char *id = CORBA_exception_id(ev);
+
+ switch (ev->_major) {
+ case CORBA_USER_EXCEPTION:
+ if (!strcmp(id, ex_Evolution_Mail_MailException)) {
+ Evolution_Mail_MailException *x = CORBA_exception_value(ev);
+
+ switch (x->id) {
+ case Evolution_Mail_SYSTEM_ERROR:
+ printf("Failed %s: System error %s\n", what, x->desc);
+ break;
+ case Evolution_Mail_CAMEL_ERROR:
+ printf("Failed %s: Camel error %s\n", what, x->desc);
+ break;
+ default:
+ printf("Failed %s: %s\n", what, x->desc);
+ break;
+ }
+ break;
+ }
+ default:
+ printf("Failed %s: %s\n", what, id);
+ break;
+ }
+
+ CORBA_exception_free(ev);
+#endif
+}
+
static Evolution_Mail_Session
get_session(void)
{
@@ -37,8 +104,7 @@ get_session(void)
listener_folder = evolution_mail_folderlistener_new();
Evolution_Mail_Session_addListener(sess, bonobo_object_corba_objref((BonoboObject *)listener_sess), &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("AddListener failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
+ e_mail_exception_dump(&ev, "adding store listener");
}
}
@@ -54,8 +120,7 @@ list_folder(Evolution_Mail_Folder folder)
iter = Evolution_Mail_Folder_getMessages(folder, "", &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("getmessages failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
+ e_mail_exception_dump(&ev, "getting mssages");
return;
}
@@ -65,8 +130,7 @@ list_folder(Evolution_Mail_Folder folder)
msgs = Evolution_Mail_MessageIterator_next(iter, 50, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("msgs.next(): %s\n", ev._id);
- CORBA_exception_free(&ev);
+ e_mail_exception_dump(&ev, "getting next messages");
break;
}
@@ -85,11 +149,8 @@ list_folder(Evolution_Mail_Folder folder)
changes->_buffer[j].flagMask = CAMEL_MESSAGE_SEEN;
}
Evolution_Mail_Folder_changeMessages(folder, changes, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- printf("changemessages failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
- memset(&ev, 0, sizeof(ev));
- }
+ if (ev._major != CORBA_NO_EXCEPTION)
+ e_mail_exception_dump(&ev, "changing messages");
}
total += msgs->_length;
@@ -102,7 +163,11 @@ list_folder(Evolution_Mail_Folder folder)
CORBA_free(msgs);
} while (more);
+ printf("calling dispose\n");
Evolution_Mail_MessageIterator_dispose(iter, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ e_mail_exception_dump(&ev, "disposing messageiterator");
+
CORBA_Object_release(iter, &ev);
printf("Got %d messages total\n", total);
@@ -119,7 +184,7 @@ add_message(Evolution_Mail_Folder folder, const char *msg)
mis.flagSet = CAMEL_MESSAGE_SEEN;
mis.flagMask = CAMEL_MESSAGE_SEEN;
- mem = bonobo_stream_mem_create(msg, strlen(msg), TRUE, FALSE);
+ mem = (BonoboObject *)evolution_mail_messagestream_new_buffer(msg, strlen(msg));
printf("attempt send mail to store\n");
Evolution_Mail_Folder_appendMessage(folder, &mis, bonobo_object_corba_objref(mem), &ev);
@@ -128,8 +193,6 @@ add_message(Evolution_Mail_Folder folder, const char *msg)
CORBA_exception_free(&ev);
CORBA_exception_init(&ev);
}
-
- bonobo_object_unref(mem);
}
static int domain(void *data)
@@ -144,8 +207,7 @@ static int domain(void *data)
stores = Evolution_Mail_Session_getStores(sess, "", bonobo_object_corba_objref((BonoboObject *)listener_store), &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("getStores failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
+ e_mail_exception_dump(&ev, "getting stores");
_exit(1);
return 0;
}
@@ -170,7 +232,7 @@ static int domain(void *data)
#if 0
Evolution_Mail_Store_getProperties(store, &names, &props, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("getProperties failed\n");
+ e_mail_exception_dump(&ev, "getting store properties");
return 1;
}
@@ -195,25 +257,19 @@ static int domain(void *data)
"Blah blah, test message!\r\n";
BonoboObject *mem;
- mem = bonobo_stream_mem_create(msg, strlen(msg), TRUE, FALSE);
+ mem = (BonoboObject *)evolution_mail_messagestream_new_buffer(msg, strlen(msg));
printf("attempt send mail to store\n");
Evolution_Mail_Store_sendMessage(store, bonobo_object_corba_objref(mem), &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- printf("sendmessage failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
- CORBA_exception_init(&ev);
- }
-
- g_object_unref(mem);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ e_mail_exception_dump(&ev, "sending message to store");
+ /* If we get a system exception, do we have to dispose it ourselves?? */
}
#endif
folders = Evolution_Mail_Store_getFolders(store, "", bonobo_object_corba_objref((BonoboObject *)listener_folder), &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- printf("getfolders failed\n");
- /* FIXME: leaks ex data? */
- CORBA_exception_free(&ev);
+ e_mail_exception_dump(&ev, "getting folders");
} else {
for (f = 0; f<folders->_length;f++) {
printf("folder %p full:'%s' name:'%s'\n", folders->_buffer[f].folder, folders->_buffer[f].full_name, folders->_buffer[f].name);
diff --git a/plugins/mail-remote/e-corba-utils.c b/plugins/mail-remote/e-corba-utils.c
index 2396f52d70..bd08ac0502 100644
--- a/plugins/mail-remote/e-corba-utils.c
+++ b/plugins/mail-remote/e-corba-utils.c
@@ -1,18 +1,29 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+
#include "e-corba-utils.h"
#include "evolution-mail-store.h"
#include "evolution-mail-folder.h"
+#include "evolution-mail-messagestream.h"
+
+#include "em-message-stream.h"
#include <camel/camel-folder-summary.h>
#include <camel/camel-stream-mem.h>
#include <camel/camel-mime-message.h>
#include <bonobo/bonobo-stream-memory.h>
+#include <bonobo/bonobo-i18n.h>
+#include <bonobo/bonobo-exception.h>
#include <libedataserver/e-msgport.h>
-CORBA_char *
+static CORBA_char *
e_corba_strdup(const char *v)
{
if (v)
@@ -113,69 +124,50 @@ e_mail_folderinfo_set_folder(Evolution_Mail_FolderInfo *fi, EvolutionMailFolder
fi->folder = CORBA_Object_duplicate(bonobo_object_corba_objref((BonoboObject *)emf), NULL);
}
-int
-e_stream_bonobo_to_camel(Bonobo_Stream in, CamelStream *out)
-{
- Bonobo_Stream_iobuf *buf;
- CORBA_Environment ev;
- int go;
-
- do {
- Bonobo_Stream_read(in, 4096, &buf, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- printf("stream read failed: %s\n", ev._id);
- CORBA_exception_free(&ev);
- return -1;
- }
-
- go = buf->_length > 0;
- if (go && camel_stream_write(out, buf->_buffer, buf->_length) == -1) {
- CORBA_free(buf);
- return -1;
- }
-
- CORBA_free(buf);
- } while (go);
-
- camel_stream_reset(out);
-
- return 0;
-}
-
CamelMimeMessage *
-e_stream_bonobo_to_message(Bonobo_Stream in)
+e_messagestream_to_message(const Evolution_Mail_MessageStream in, CORBA_Environment *ev)
{
- CamelStream *mem;
+ CamelStream *emms;
CamelMimeMessage *msg;
- mem = camel_stream_mem_new();
- if (e_stream_bonobo_to_camel(in, mem) == -1)
+ emms = em_message_stream_new(in);
+ if (emms == NULL) {
+ e_mail_exception_set(ev, Evolution_Mail_FAILED, _("Unknown reason"));
return NULL;
+ }
msg = camel_mime_message_new();
- if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, mem) == -1) {
+ if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, emms) == -1) {
+ e_mail_exception_set(ev, Evolution_Mail_SYSTEM_ERROR, g_strerror(errno));
camel_object_unref(msg);
msg = NULL;
}
- camel_object_unref(mem);
+ camel_object_unref(emms);
return msg;
}
-Bonobo_Stream
-e_stream_message_to_bonobo(CamelMimeMessage *msg)
+Evolution_Mail_MessageStream
+e_messagestream_from_message(CamelMimeMessage *msg, CORBA_Environment *ev)
{
CamelStreamMem *mem;
- BonoboObject *bmem;
+ EvolutionMailMessageStream *emms;
+ Evolution_Mail_MessageStream out;
/* didn't say it was going to be efficient ... */
mem = (CamelStreamMem *)camel_stream_mem_new();
- camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, (CamelStream *)mem);
- bmem = bonobo_stream_mem_create(mem->buffer->data, mem->buffer->len, TRUE, FALSE);
+ if (camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, (CamelStream *)mem) == -1) {
+ e_mail_exception_set(ev, Evolution_Mail_SYSTEM_ERROR, g_strerror(errno));
+ out = CORBA_OBJECT_NIL;
+ } else {
+ camel_stream_reset((CamelStream *)mem);
+ emms = evolution_mail_messagestream_new((CamelStream *)mem);
+ out = CORBA_Object_duplicate(bonobo_object_corba_objref((BonoboObject *)emms), NULL);
+ }
camel_object_unref(mem);
- return bonobo_object_corba_objref((BonoboObject *)bmem);
+ return out;
}
struct _e_mail_listener {
@@ -279,3 +271,18 @@ void e_mail_listener_free(struct _EDList *list)
}
}
+void e_mail_exception_set(CORBA_Environment *ev, Evolution_Mail_ErrorType id, const char *desc)
+{
+ Evolution_Mail_MailException *x;
+
+ x = Evolution_Mail_MailException__alloc();
+ x->id = id;
+ x->desc = CORBA_string_dup(desc);
+ CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_MailException, x);
+}
+
+void e_mail_exception_xfer_camel(CORBA_Environment *ev, CamelException *ex)
+{
+ e_mail_exception_set(ev, Evolution_Mail_CAMEL_ERROR, ex && ex->desc ? ex->desc:"");
+ camel_exception_clear(ex);
+}
diff --git a/plugins/mail-remote/e-corba-utils.h b/plugins/mail-remote/e-corba-utils.h
index cba1fb49ac..ba70976882 100644
--- a/plugins/mail-remote/e-corba-utils.h
+++ b/plugins/mail-remote/e-corba-utils.h
@@ -9,6 +9,7 @@ struct _EvolutionMailFolder;
struct _CamelMessageInfo;
struct _CamelStream;
struct _CamelMimeMessage;
+struct _CamelException;
void e_mail_property_set_string(Evolution_Mail_Property *prop, const char *name, const char *val);
void e_mail_property_set_null(Evolution_Mail_Property *prop, const char *name);
@@ -19,9 +20,8 @@ void e_mail_folderinfo_set_folder(Evolution_Mail_FolderInfo *fi, struct _Evoluti
void e_mail_messageinfo_set_message(Evolution_Mail_MessageInfo *mi, struct _CamelMessageInfo *info);
struct _CamelMessageInfo *e_mail_messageinfoset_to_info(const Evolution_Mail_MessageInfoSet *mi);
-int e_stream_bonobo_to_camel(Bonobo_Stream in, struct _CamelStream *out);
-struct _CamelMimeMessage *e_stream_bonobo_to_message(Bonobo_Stream in);
-Bonobo_Stream e_stream_message_to_bonobo(struct _CamelMimeMessage *msg);
+struct _CamelMimeMessage *e_messagestream_to_message(const Evolution_Mail_MessageStream in, CORBA_Environment *ev);
+Evolution_Mail_MessageStream e_messagestream_from_message(struct _CamelMimeMessage *msg, CORBA_Environment *ev);
struct _EDList;
@@ -32,4 +32,8 @@ gboolean e_mail_listener_remove(struct _EDList *list, CORBA_Object listener);
gboolean e_mail_listener_emit(struct _EDList *list, EMailListenerChanged emit, CORBA_Object source, void *changes);
void e_mail_listener_free(struct _EDList *list);
+/* raise an exception */
+void e_mail_exception_set(CORBA_Environment *ev, Evolution_Mail_ErrorType id, const char *desc);
+void e_mail_exception_xfer_camel(CORBA_Environment *ev, struct _CamelException *ex);
+
#endif /* !_E_CORBA_UTILS_H */
diff --git a/plugins/mail-remote/em-message-stream.c b/plugins/mail-remote/em-message-stream.c
new file mode 100644
index 0000000000..77f6300cb5
--- /dev/null
+++ b/plugins/mail-remote/em-message-stream.c
@@ -0,0 +1,144 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Michael Zucchi <notzed@novel.com>
+ *
+ * Copyright 2005 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * 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.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <camel/camel-stream.h>
+#include "em-message-stream.h"
+
+#define d(x)
+
+#define EMSS_CLASS(x) ((EMMessageStreamClass *)(((CamelObject *)(x))->klass))
+
+static CamelStreamClass *parent_class = NULL;
+
+static ssize_t
+emms_read(CamelStream *stream, char *buffer, size_t n)
+{
+ EMMessageStream *emms = (EMMessageStream *)stream;
+ ssize_t len;
+ Evolution_Mail_Buffer *buf;
+ CORBA_Environment ev = { 0 };
+
+ /* To avoid all of the rount-trip overhead, this could always fire off
+ one request in advance, to pipeline the data. Using another thread. */
+
+ if (emms->source == CORBA_OBJECT_NIL) {
+ errno = EBADF;
+ return -1;
+ }
+
+ buf = Evolution_Mail_MessageStream_next(emms->source, n, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free(&ev);
+ Evolution_Mail_MessageStream_dispose(emms->source, &ev);
+ emms->source = CORBA_OBJECT_NIL;
+ stream->eos = TRUE;
+ errno = EBADF;
+ return -1;
+ }
+
+ if (buf->_length == 0)
+ stream->eos = TRUE;
+
+ len = buf->_length;
+ memcpy(buffer, buf->_buffer, buf->_length);
+ CORBA_free(buf);
+
+ return len;
+}
+
+static void
+em_message_stream_init (CamelObject *object)
+{
+ /*EMMessageStream *emss = (EMMessageStream *)object;*/
+}
+
+static void
+em_message_stream_finalize (CamelObject *object)
+{
+ EMMessageStream *emms = (EMMessageStream *)object;
+
+ printf("EMMessageStream.finalise()\n");
+
+ if (emms->source) {
+ CORBA_Environment ev = { 0 };
+
+ Evolution_Mail_MessageStream_dispose(emms->source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ CORBA_exception_free(&ev);
+
+ CORBA_Object_release(emms->source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ CORBA_exception_free(&ev);
+ }
+}
+
+static void
+em_message_stream_class_init (EMMessageStreamClass *klass)
+{
+ CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (klass);
+
+ parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
+
+ stream_class->read = emms_read;
+}
+
+CamelType
+em_message_stream_get_type (void)
+{
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (type == CAMEL_INVALID_TYPE) {
+ type = camel_type_register (CAMEL_STREAM_TYPE,
+ "EMMessageStream",
+ sizeof (EMMessageStream),
+ sizeof (EMMessageStreamClass),
+ (CamelObjectClassInitFunc) em_message_stream_class_init,
+ NULL,
+ (CamelObjectInitFunc) em_message_stream_init,
+ (CamelObjectFinalizeFunc) em_message_stream_finalize);
+ }
+
+ return type;
+}
+
+CamelStream *
+em_message_stream_new(const Evolution_Mail_MessageStream source)
+{
+ EMMessageStream *ems = (EMMessageStream *)camel_object_new(em_message_stream_get_type());
+ CORBA_Environment ev = { 0 };
+
+ ems->source = CORBA_Object_duplicate(source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free(&ev);
+ camel_object_unref(ems);
+ ems = NULL;
+ }
+
+ return (CamelStream *)ems;
+}
diff --git a/plugins/mail-remote/em-message-stream.h b/plugins/mail-remote/em-message-stream.h
new file mode 100644
index 0000000000..4d738c64a8
--- /dev/null
+++ b/plugins/mail-remote/em-message-stream.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Authors: Michael Zucchi <notzed@ximian.com>
+ *
+ * Copyright 2003 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * 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.
+ *
+ */
+
+#ifndef EM_MESSAGE_STREAM_H
+#define EM_MESSAGE_STREAM_H
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+#define EM_MESSAGE_STREAM_TYPE (em_message_stream_get_type ())
+#define EM_MESSAGE_STREAM(obj) (CAMEL_CHECK_CAST((obj), EM_MESSAGE_STREAM_TYPE, EMMessageStream))
+#define EM_MESSAGE_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), EM_MESSAGE_STREAM_TYPE, EMMessageStreamClass))
+#define EM_IS_MESSAGE_STREAM(o) (CAMEL_CHECK_TYPE((o), EM_MESSAGE_STREAM_TYPE))
+
+#include <camel/camel-stream.h>
+#include "Evolution-DataServer-Mail.h"
+
+typedef struct _EMMessageStream {
+ CamelStream parent_stream;
+
+ Evolution_Mail_MessageStream source;
+} EMMessageStream;
+
+typedef struct {
+ CamelStreamClass parent_class;
+} EMMessageStreamClass;
+
+CamelType em_message_stream_get_type (void);
+
+CamelStream *em_message_stream_new(const Evolution_Mail_MessageStream source);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* EM_MESSAGE_STREAM_H */
diff --git a/plugins/mail-remote/evolution-mail-folder.c b/plugins/mail-remote/evolution-mail-folder.c
index a64881015e..f25ef44e35 100644
--- a/plugins/mail-remote/evolution-mail-folder.c
+++ b/plugins/mail-remote/evolution-mail-folder.c
@@ -139,18 +139,16 @@ impl_getMessages(PortableServer_Servant _servant, const CORBA_char * pattern, CO
EvolutionMailMessageIterator *emi;
Evolution_Mail_MessageIterator iter;
- folder = evolution_mail_folder_get_folder(emf);
- if (folder == NULL) {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
+ folder = evolution_mail_folder_get_folder(emf, ev);
+ if (folder == NULL)
return CORBA_OBJECT_NIL;
- }
emi = evolution_mail_messageiterator_new(folder, pattern);
camel_object_unref(folder);
/* NB: How do we destroy the object once we're done? */
- iter = bonobo_object_corba_objref((BonoboObject *)emi);
+ iter = CORBA_Object_duplicate(bonobo_object_corba_objref((BonoboObject *)emi), NULL);
return iter;
}
@@ -162,11 +160,9 @@ impl_changeMessages(PortableServer_Servant _servant, const Evolution_Mail_Messag
struct _CamelFolder *folder;
int i, j;
- folder = evolution_mail_folder_get_folder(emf);
- if (folder == NULL) {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
+ folder = evolution_mail_folder_get_folder(emf, ev);
+ if (folder == NULL)
return;
- }
camel_folder_freeze(folder);
for (i=0;i<infos->_length;i++) {
@@ -194,52 +190,47 @@ impl_changeMessages(PortableServer_Servant _servant, const Evolution_Mail_Messag
camel_object_unref(folder);
}
-static Bonobo_Stream
+static Evolution_Mail_MessageStream
impl_getMessage(PortableServer_Servant _servant, const CORBA_char * uid, CORBA_Environment *ev)
{
EvolutionMailFolder *emf = (EvolutionMailFolder *)bonobo_object_from_servant(_servant);
struct _CamelFolder *folder;
CamelMimeMessage *msg;
- Bonobo_Stream out;
+ Evolution_Mail_MessageStream out;
CamelException ex = { 0 };
- folder = evolution_mail_folder_get_folder(emf);
+ folder = evolution_mail_folder_get_folder(emf, ev);
if (folder == NULL)
- goto fail;
+ return CORBA_OBJECT_NIL;
msg = camel_folder_get_message(folder, uid, &ex);
- if (msg == NULL)
- goto fail;
-
- out = e_stream_message_to_bonobo(msg);
- camel_object_unref(msg);
+ if (msg == NULL) {
+ e_mail_exception_xfer_camel(ev, &ex);
+ out = CORBA_OBJECT_NIL;
+ } else {
+ out = e_messagestream_from_message(msg, ev);
+ camel_object_unref(msg);
+ }
+ camel_object_unref(folder);
return out;
-
-fail:
- if (folder)
- camel_object_unref(folder);
-
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
- camel_exception_clear(&ex);
-
- return CORBA_OBJECT_NIL;
}
static void
-impl_appendMessage(PortableServer_Servant _servant, const Evolution_Mail_MessageInfoSet*mi, const Bonobo_Stream message, CORBA_Environment *ev)
+impl_appendMessage(PortableServer_Servant _servant, const Evolution_Mail_MessageInfoSet*mi, const Evolution_Mail_MessageStream message, CORBA_Environment *ev)
{
EvolutionMailFolder *emf = (EvolutionMailFolder *)bonobo_object_from_servant(_servant);
struct _CamelFolder *folder;
CamelMimeMessage *msg = NULL;
CamelMessageInfo *info;
CamelException ex = { 0 };
+ CORBA_Environment wev = { 0 };
- folder = evolution_mail_folder_get_folder(emf);
+ folder = evolution_mail_folder_get_folder(emf, ev);
if (folder == NULL)
goto fail3;
- msg = e_stream_bonobo_to_message(message);
+ msg = e_messagestream_to_message(message, ev);
if (msg == NULL)
goto fail2;
@@ -248,20 +239,13 @@ impl_appendMessage(PortableServer_Servant _servant, const Evolution_Mail_Message
camel_message_info_free(info);
if (camel_exception_is_set(&ex))
- goto fail;
-
- camel_object_unref(msg);
- camel_object_unref(folder);
-
- return;
+ e_mail_exception_xfer_camel(ev, &ex);
-fail:
camel_object_unref(msg);
fail2:
camel_object_unref(folder);
fail3:
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
- camel_exception_clear(&ex);
+ Evolution_Mail_MessageStream_dispose(message, &wev);
}
/* Initialization */
@@ -368,14 +352,14 @@ emf_folder_changed(CamelObject *o, void *d, void *data)
CORBA_free(changes);
}
-struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf)
+struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf, CORBA_Environment *ev)
{
struct _EvolutionMailFolderPrivate *p = _PRIVATE(emf);
CamelStore *store;
CamelException ex;
if (p->folder == NULL) {
- store = evolution_mail_store_get_store(emf->store);
+ store = evolution_mail_store_get_store(emf->store, ev);
if (store == NULL)
return NULL;
@@ -384,7 +368,7 @@ struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf)
if (p->folder) {
p->folder_changed = camel_object_hook_event(p->folder, "folder_changed", emf_folder_changed, emf);
} else {
- camel_exception_clear(&ex);
+ e_mail_exception_xfer_camel(ev, &ex);
}
camel_object_unref(store);
}
@@ -395,6 +379,23 @@ struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf)
return p->folder;
}
+int evolution_mail_folder_close_folder(EvolutionMailFolder *emf)
+{
+ struct _EvolutionMailFolderPrivate *p = _PRIVATE(emf);
+
+ /* FIXME: locking */
+ if (p->folder) {
+ if (!e_dlist_empty(&p->listeners))
+ return -1;
+
+ camel_object_remove_event(p->folder, p->folder_changed);
+ camel_object_unref(p->folder);
+ p->folder = NULL;
+ }
+
+ return 0;
+}
+
void evolution_mail_folder_addlistener(EvolutionMailFolder *emf, Evolution_Mail_FolderListener listener)
{
struct _EvolutionMailFolderPrivate *p = _PRIVATE(emf);
@@ -411,5 +412,6 @@ evolution_mail_folder_changed(EvolutionMailFolder *emf, Evolution_Mail_FolderCha
if (!e_mail_listener_emit(&p->listeners, (EMailListenerChanged)Evolution_Mail_FolderListener_changed,
bonobo_object_corba_objref((BonoboObject *)emf), changes)) {
printf("No more listeners for folder, could dispose store object now\n");
+ evolution_mail_folder_close_folder(emf);
}
}
diff --git a/plugins/mail-remote/evolution-mail-folder.h b/plugins/mail-remote/evolution-mail-folder.h
index 74320f4d78..ea9ce76b3a 100644
--- a/plugins/mail-remote/evolution-mail-folder.h
+++ b/plugins/mail-remote/evolution-mail-folder.h
@@ -16,7 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: JP Rosevear <jpr@ximian.com>
+ * Author: Michael Zucchi <notzed@novell.com>
*/
#ifndef _EVOLUTION_MAIL_FOLDER_H_
@@ -58,6 +58,7 @@ EvolutionMailFolder *evolution_mail_folder_new(struct _EvolutionMailStore *ems,
void evolution_mail_folder_addlistener(EvolutionMailFolder *emf, Evolution_Mail_FolderListener listener);
void evolution_mail_folder_changed(EvolutionMailFolder *emf, Evolution_Mail_FolderChanges *changes);
-struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf);
+struct _CamelFolder *evolution_mail_folder_get_folder(EvolutionMailFolder *emf, CORBA_Environment *ev);
+int evolution_mail_folder_close_folder(EvolutionMailFolder *emf);
#endif /* _EVOLUTION_MAIL_FOLDER_H_ */
diff --git a/plugins/mail-remote/evolution-mail-messageiterator.c b/plugins/mail-remote/evolution-mail-messageiterator.c
index 0fa25f730f..2a039f7e9a 100644
--- a/plugins/mail-remote/evolution-mail-messageiterator.c
+++ b/plugins/mail-remote/evolution-mail-messageiterator.c
@@ -125,7 +125,7 @@ impl_mi_dispose(PortableServer_Servant _servant, CORBA_Environment *ev)
EvolutionMailMessageIterator *emmi = (EvolutionMailMessageIterator *)bonobo_object_from_servant(_servant);
bonobo_object_set_immortal((BonoboObject *)emmi, FALSE);
- /*bonobo_object_unref((BonoboObject *)emmi);*/
+ bonobo_object_unref((BonoboObject *)emmi);
}
/* Initialization */
diff --git a/plugins/mail-remote/evolution-mail-messageiterator.h b/plugins/mail-remote/evolution-mail-messageiterator.h
index 772ea8f2b0..41fb66bd72 100644
--- a/plugins/mail-remote/evolution-mail-messageiterator.h
+++ b/plugins/mail-remote/evolution-mail-messageiterator.h
@@ -16,7 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: JP Rosevear <jpr@ximian.com>
+ * Author: Michael Zucchi <notzed@novell.com>
*/
#ifndef _EVOLUTION_MAIL_MESSAGEITERATOR_H_
diff --git a/plugins/mail-remote/evolution-mail-messagestream.c b/plugins/mail-remote/evolution-mail-messagestream.c
new file mode 100644
index 0000000000..f00e904e5f
--- /dev/null
+++ b/plugins/mail-remote/evolution-mail-messagestream.c
@@ -0,0 +1,158 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2005 Novell, Inc.
+ *
+ * Authors: Michael Zucchi <notzed@novell.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <bonobo/bonobo-i18n.h>
+#include <bonobo/bonobo-exception.h>
+#include "evolution-mail-messagestream.h"
+#include <camel/camel-stream-mem.h>
+
+#include "e-corba-utils.h"
+
+#define PARENT_TYPE bonobo_object_get_type ()
+
+static BonoboObjectClass *parent_class = NULL;
+
+/* GObject methods */
+
+static void
+impl_dispose (GObject *object)
+{
+ (* G_OBJECT_CLASS (parent_class)->dispose) (object);
+}
+
+static void
+impl_finalize (GObject *object)
+{
+ EvolutionMailMessageStream *emms = (EvolutionMailMessageStream *)object;
+
+ printf("EvolutionMailMessageStream: finalise\n");
+
+ if (emms->source)
+ camel_object_unref(emms->source);
+ g_free(emms->buffer);
+
+ (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+}
+
+/* Evolution.Mail.MessageStream */
+
+static Evolution_Mail_Buffer *
+impl_next(PortableServer_Servant _servant, const CORBA_long limit, CORBA_Environment * ev)
+{
+ EvolutionMailMessageStream *emf = (EvolutionMailMessageStream *)bonobo_object_from_servant(_servant);
+ Evolution_Mail_Buffer *buf;
+ ssize_t len;
+
+ buf = Evolution_Mail_Buffer__alloc();
+ buf->_maximum = limit;
+ buf->_buffer = Evolution_Mail_Buffer_allocbuf(buf->_maximum);
+
+ if (emf->source) {
+ len = camel_stream_read(emf->source, buf->_buffer, buf->_maximum);
+ if (len == -1) {
+ Evolution_Mail_MailException *x;
+
+ x = Evolution_Mail_MailException__alloc();
+ x->id = Evolution_Mail_SYSTEM_ERROR;
+ x->desc = CORBA_string_dup(g_strerror(errno));
+ CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_MailException, x);
+ CORBA_free(buf);
+ buf = CORBA_OBJECT_NIL;
+ } else {
+ buf->_length = len;
+ }
+ } else {
+ len = MIN(limit, (emf->len - emf->pos));
+ memcpy(buf->_buffer, emf->buffer + emf->pos, len);
+ emf->pos += len;
+ buf->_length = len;
+ }
+
+ return buf;
+}
+
+static void
+impl_mi_dispose(PortableServer_Servant _servant, CORBA_Environment *ev)
+{
+ EvolutionMailMessageStream *emmi = (EvolutionMailMessageStream *)bonobo_object_from_servant(_servant);
+
+ bonobo_object_set_immortal((BonoboObject *)emmi, FALSE);
+ bonobo_object_unref((BonoboObject *)emmi);
+}
+
+/* Initialization */
+
+static void
+evolution_mail_messagestream_class_init (EvolutionMailMessageStreamClass *klass)
+{
+ POA_Evolution_Mail_MessageStream__epv *epv = &klass->epv;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ epv->next = impl_next;
+ epv->dispose = impl_mi_dispose;
+
+ object_class->dispose = impl_dispose;
+ object_class->finalize = impl_finalize;
+}
+
+static void
+evolution_mail_messagestream_init(EvolutionMailMessageStream *emi, EvolutionMailMessageStreamClass *klass)
+{
+ bonobo_object_set_immortal((BonoboObject *)emi, TRUE);
+}
+
+BONOBO_TYPE_FUNC_FULL (EvolutionMailMessageStream, Evolution_Mail_MessageStream, PARENT_TYPE, evolution_mail_messagestream)
+
+EvolutionMailMessageStream *
+evolution_mail_messagestream_new(CamelStream *source)
+{
+ /* FIXME: use right poa, thread per object? */
+ EvolutionMailMessageStream *emf = g_object_new(evolution_mail_messagestream_get_type(), NULL);
+
+ emf->source = source;
+ camel_object_ref(source);
+
+ return emf;
+}
+
+EvolutionMailMessageStream *
+evolution_mail_messagestream_new_buffer(const char *buffer, size_t len)
+{
+ /* FIXME: use right poa, thread per object? */
+ EvolutionMailMessageStream *emf = g_object_new(evolution_mail_messagestream_get_type(), NULL);
+
+ emf->buffer = g_malloc(len);
+ memcpy(emf->buffer, buffer, len);
+ emf->len = len;
+ emf->pos = 0;
+
+ return emf;
+}
+
+
diff --git a/plugins/mail-remote/evolution-mail-messagestream.h b/plugins/mail-remote/evolution-mail-messagestream.h
new file mode 100644
index 0000000000..dfd4f50593
--- /dev/null
+++ b/plugins/mail-remote/evolution-mail-messagestream.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2005 Novell, 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
+ * 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: Michael Zucchi <notzed@novell.com>
+ */
+
+#ifndef _EVOLUTION_MAIL_MESSAGESTREAM_H_
+#define _EVOLUTION_MAIL_MESSAGESTREAM_H_
+
+#include <bonobo/bonobo-object.h>
+#include "Evolution-DataServer-Mail.h"
+
+typedef struct _EvolutionMailMessageStream EvolutionMailMessageStream;
+typedef struct _EvolutionMailMessageStreamClass EvolutionMailMessageStreamClass;
+
+struct _EvolutionMailMessageStream {
+ BonoboObject parent;
+
+ /* only one or the other is set */
+ struct _CamelStream *source;
+
+ char *buffer;
+ size_t len;
+ size_t pos;
+};
+
+struct _EvolutionMailMessageStreamClass {
+ BonoboObjectClass parent_class;
+
+ POA_Evolution_Mail_MessageStream__epv epv;
+};
+
+GType evolution_mail_messagestream_get_type(void);
+
+EvolutionMailMessageStream *evolution_mail_messagestream_new(struct _CamelStream *source);
+EvolutionMailMessageStream *evolution_mail_messagestream_new_buffer(const char *buffer, size_t len);
+
+#endif /* _EVOLUTION_MAIL_MESSAGESTREAM_H_ */
diff --git a/plugins/mail-remote/evolution-mail-session.c b/plugins/mail-remote/evolution-mail-session.c
index 9fa6fdfdb7..e670e40f50 100644
--- a/plugins/mail-remote/evolution-mail-session.c
+++ b/plugins/mail-remote/evolution-mail-session.c
@@ -328,6 +328,8 @@ evolution_mail_session_init (EvolutionMailSession *ems, EvolutionMailSessionClas
p->account_removed = g_signal_connect(p->accounts, "account_removed", G_CALLBACK(ems_account_removed), ems);
ems->session = mail_component_peek_session(NULL);
+
+ bonobo_object_set_immortal((BonoboObject *)ems, TRUE);
}
void
diff --git a/plugins/mail-remote/evolution-mail-store.c b/plugins/mail-remote/evolution-mail-store.c
index 349925dd61..c5025900cb 100644
--- a/plugins/mail-remote/evolution-mail-store.c
+++ b/plugins/mail-remote/evolution-mail-store.c
@@ -47,6 +47,7 @@
#include <e-util/e-account.h>
#include "mail/mail-component.h"
+#include "mail/mail-send-recv.h"
#define PARENT_TYPE bonobo_object_get_type ()
@@ -418,9 +419,8 @@ impl_getFolders(PortableServer_Servant _servant,
int i;
CamelStore *store;
- store = evolution_mail_store_get_store(ems);
+ store = evolution_mail_store_get_store(ems, ev);
if (store == NULL) {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
return CORBA_OBJECT_NIL;
}
@@ -434,8 +434,7 @@ impl_getFolders(PortableServer_Servant _servant,
camel_store_free_folder_info(store, fi);
ems_sort_folders(p);
} else {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
-
+ e_mail_exception_xfer_camel(ev, &ex);
camel_object_unref(store);
return CORBA_OBJECT_NIL;
}
@@ -461,7 +460,7 @@ impl_getFolders(PortableServer_Servant _servant,
static void
impl_sendMessage(PortableServer_Servant _servant,
- const Bonobo_Stream message,
+ const Evolution_Mail_MessageStream message,
CORBA_Environment * ev)
{
EvolutionMailStore *ems = (EvolutionMailStore *)bonobo_object_from_servant(_servant);
@@ -469,25 +468,18 @@ impl_sendMessage(PortableServer_Servant _servant,
CamelMimeMessage *msg;
CamelInternetAddress *from;
CamelMessageInfo *info;
+ CORBA_Environment wev = { 0 };
if (ems->account == NULL
|| ems->account->transport == NULL
|| ems->account->transport->url == NULL) {
-#if 0
- Evolution_Mail_NOT_SUPPORTED *x;
-
- x = Evolution_Mail_NOT_SUPPORTED__alloc();
- x->why = CORBA_string_dup(ex.desc);
-#endif
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_NOT_SUPPORTED, NULL);
- return;
+ e_mail_exception_set(ev, Evolution_Mail_NOT_SUPPORTED, _("Account cannot send e-mail"));
+ goto done;
}
- msg = e_stream_bonobo_to_message(message);
- if (msg == NULL) {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
- return;
- }
+ msg = e_messagestream_to_message(message, ev);
+ if (msg == NULL)
+ goto done;
from = camel_internet_address_new();
camel_internet_address_add(from, ems->account->id->name, ems->account->id->address);
@@ -506,13 +498,16 @@ impl_sendMessage(PortableServer_Servant _servant,
camel_message_info_free(info);
if (camel_exception_is_set(&ex)) {
- CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_Evolution_Mail_FAILED, NULL);
- camel_exception_clear(&ex);
+ e_mail_exception_xfer_camel(ev, &ex);
} else {
- /*mail_send();*/
+ mail_send();
}
camel_object_unref(msg);
+done:
+ Evolution_Mail_MessageStream_dispose(message, &wev);
+ if (wev._major != CORBA_NO_EXCEPTION)
+ CORBA_exception_free(&wev);
}
/* Initialization */
@@ -587,7 +582,7 @@ const char *evolution_mail_store_get_uid(EvolutionMailStore *ems)
return "local@local";
}
-CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems)
+CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems, CORBA_Environment *ev)
{
struct _EvolutionMailStorePrivate *p = _PRIVATE(ems);
@@ -603,10 +598,11 @@ CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems)
if (uri && *uri) {
p->store = camel_session_get_store(ems->session->session, uri, &ex);
if (camel_exception_is_set(&ex)) {
- camel_exception_clear(&ex);
+ e_mail_exception_xfer_camel(ev, &ex);
return NULL;
}
} else {
+ e_mail_exception_set(ev, Evolution_Mail_NOT_SUPPORTED, _("No store available"));
return NULL;
}
}
@@ -623,6 +619,30 @@ CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems)
return p->store;
}
+int evolution_mail_store_close_store(EvolutionMailStore *ems)
+{
+ struct _EvolutionMailStorePrivate *p = _PRIVATE(ems);
+
+ /* FIXME: locking */
+ if (p->store) {
+ if (!e_dlist_empty(&p->listeners))
+ return -1;
+
+ camel_object_remove_event(p->store, p->folder_opened);
+ camel_object_remove_event(p->store, p->folder_created);
+ camel_object_remove_event(p->store, p->folder_deleted);
+ camel_object_remove_event(p->store, p->folder_renamed);
+ camel_object_remove_event(p->store, p->folder_subscribed);
+ camel_object_remove_event(p->store, p->folder_unsubscribed);
+ camel_object_unref(p->store);
+ p->store = NULL;
+ }
+
+ /* FIXME: need to close of sub-folders too? */
+
+ return 0;
+}
+
void
evolution_mail_store_addlistener(EvolutionMailStore *ems, Evolution_Mail_StoreListener listener)
{
@@ -639,6 +659,7 @@ evolution_mail_store_changed(EvolutionMailStore *ems, Evolution_Mail_StoreChange
if (!e_mail_listener_emit(&p->listeners, (EMailListenerChanged)Evolution_Mail_StoreListener_changed,
bonobo_object_corba_objref((BonoboObject *)ems), changes)) {
- printf("No more listeners for store, could dispose store object now\n");
+ evolution_mail_store_close_store(ems);
+ printf("No more listeners for store, could dispose store object now?\n");
}
}
diff --git a/plugins/mail-remote/evolution-mail-store.h b/plugins/mail-remote/evolution-mail-store.h
index d93c32c26e..e3afa94251 100644
--- a/plugins/mail-remote/evolution-mail-store.h
+++ b/plugins/mail-remote/evolution-mail-store.h
@@ -16,7 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: JP Rosevear <jpr@ximian.com>
+ * Author: Michael Zucchi <notzed@novell.com>
*/
#ifndef _EVOLUTION_MAIL_STORE_H_
@@ -62,6 +62,7 @@ const char *evolution_mail_store_get_name(EvolutionMailStore *);
const char *evolution_mail_store_get_uid(EvolutionMailStore *);
/* unref when done */
-struct _CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems);
+struct _CamelStore *evolution_mail_store_get_store(EvolutionMailStore *ems, CORBA_Environment *ev);
+int evolution_mail_store_close_store(EvolutionMailStore *ems);
#endif /* _EVOLUTION_MAIL_STORE_H_ */