#include "e-corba-utils.h" #include "evolution-mail-store.h" #include "evolution-mail-folder.h" #include #include #include #include #include CORBA_char * e_corba_strdup(const char *v) { if (v) return CORBA_string_dup(v); else return CORBA_string_dup(""); } void e_mail_property_set_string(Evolution_Mail_Property *prop, const char *name, const char *val) { prop->value._release = CORBA_TRUE; prop->value._type = TC_CORBA_string; prop->value._value = CORBA_sequence_CORBA_string_allocbuf(1); ((char **)prop->value._value)[0] = CORBA_string_dup(val); prop->name = CORBA_string_dup(name); } void e_mail_property_set_null(Evolution_Mail_Property *prop, const char *name) { prop->value._release = CORBA_TRUE; prop->value._type = TC_null; prop->name = CORBA_string_dup(name); } void e_mail_storeinfo_set_store(Evolution_Mail_StoreInfo *si, EvolutionMailStore *store) { si->name = CORBA_string_dup(evolution_mail_store_get_name(store)); si->uid = CORBA_string_dup(evolution_mail_store_get_uid(store)); si->store = CORBA_Object_duplicate(bonobo_object_corba_objref((BonoboObject *)store), NULL); } void e_mail_messageinfo_set_message(Evolution_Mail_MessageInfo *mi, CamelMessageInfo *info) { const CamelTag *tag; const CamelFlag *flag; int i; mi->uid = CORBA_string_dup(camel_message_info_uid(info)); mi->subject = e_corba_strdup(camel_message_info_subject(info)); mi->to = e_corba_strdup(camel_message_info_to(info)); mi->from = e_corba_strdup(camel_message_info_from(info)); mi->flags = camel_message_info_flags(info); flag = camel_message_info_user_flags(info); mi->userFlags._maximum = camel_flag_list_size((CamelFlag **)&flag); mi->userFlags._length = mi->userFlags._maximum; if (mi->userFlags._maximum) { mi->userFlags._buffer = Evolution_Mail_UserFlags_allocbuf(mi->userFlags._maximum); CORBA_sequence_set_release(&mi->userFlags, CORBA_TRUE); for (i=0;flag;flag = flag->next,i++) { mi->userFlags._buffer[i] = CORBA_string_dup(flag->name); g_assert(mi->userFlags._buffer[i]); } } tag = camel_message_info_user_tags(info); mi->userTags._maximum = camel_tag_list_size((CamelTag **)&tag); mi->userTags._length = mi->userTags._maximum; if (mi->userTags._maximum) { mi->userTags._buffer = Evolution_Mail_UserTags_allocbuf(mi->userTags._maximum); CORBA_sequence_set_release(&mi->userFlags, CORBA_TRUE); for (i=0;tag;tag = tag->next,i++) { mi->userTags._buffer[i].name = CORBA_string_dup(tag->name); mi->userTags._buffer[i].value = CORBA_string_dup(tag->value); g_assert(mi->userTags._buffer[i].name); g_assert(mi->userTags._buffer[i].value); } } } CamelMessageInfo * e_mail_messageinfoset_to_info(const Evolution_Mail_MessageInfoSet *mi) { CamelMessageInfo *info; int i; info = camel_message_info_new(NULL); camel_message_info_set_flags(info, mi->flagSet, mi->flagMask); for (i=0;iuserFlagSet._length;i++) camel_message_info_set_user_flag(info, mi->userFlagSet._buffer[i], TRUE); for (i=0;iuserTags._length;i++) camel_message_info_set_user_tag(info, mi->userTags._buffer[i].name, mi->userTags._buffer[i].value); return info; } void e_mail_folderinfo_set_folder(Evolution_Mail_FolderInfo *fi, EvolutionMailFolder *emf) { fi->name = CORBA_string_dup(emf->name); fi->full_name = CORBA_string_dup(emf->full_name); 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) { CamelStream *mem; CamelMimeMessage *msg; mem = camel_stream_mem_new(); if (e_stream_bonobo_to_camel(in, mem) == -1) return NULL; msg = camel_mime_message_new(); if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, mem) == -1) { camel_object_unref(msg); msg = NULL; } camel_object_unref(mem); return msg; } Bonobo_Stream e_stream_message_to_bonobo(CamelMimeMessage *msg) { CamelStreamMem *mem; BonoboObject *bmem; /* 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); camel_object_unref(mem); return bonobo_object_corba_objref((BonoboObject *)bmem); } struct _e_mail_listener { struct _e_mail_listener *next; struct _e_mail_listener *prev; CORBA_Object listener; }; static struct _e_mail_listener * eml_find(struct _EDList *list, CORBA_Object listener) { struct _e_mail_listener *l, *n; l = (struct _e_mail_listener *)list->head; n = l->next; while (n) { if (l->listener == listener) return l; l = n; n = n->next; } return NULL; } static void eml_remove(struct _e_mail_listener *l) { CORBA_Environment ev = { 0 }; e_dlist_remove((EDListNode *)l); CORBA_Object_release(l->listener, &ev); g_free(l); if (ev._major != CORBA_NO_EXCEPTION) CORBA_exception_free(&ev); } void e_mail_listener_add(struct _EDList *list, CORBA_Object listener) { struct _e_mail_listener *l; CORBA_Environment ev = { 0 }; if (eml_find(list, listener) != NULL) return; listener = CORBA_Object_duplicate(listener, &ev); if (ev._major != CORBA_NO_EXCEPTION) { CORBA_exception_free(&ev); } else { l = g_malloc(sizeof(*l)); l->listener = listener; e_dlist_addtail(list, (EDListNode *)l); } } gboolean e_mail_listener_remove(struct _EDList *list, CORBA_Object listener) { struct _e_mail_listener *l; l = eml_find(list, listener); if (l) eml_remove(l); return !e_dlist_empty(list); } gboolean e_mail_listener_emit(struct _EDList *list, EMailListenerChanged emit, CORBA_Object source, void *changes) { struct _e_mail_listener *l, *n; CORBA_Environment ev = { 0 }; l = (struct _e_mail_listener *)list->head; n = l->next; while (n) { emit(l->listener, source, changes, &ev); if (ev._major != CORBA_NO_EXCEPTION) { printf("emit changed failed '%s', removing listener\n", ev._id); CORBA_exception_free(&ev); eml_remove(l); } l = n; n = n->next; } return !e_dlist_empty(list); } void e_mail_listener_free(struct _EDList *list) { struct _e_mail_listener *l, *n; l = (struct _e_mail_listener *)list->head; n = l->next; while (n) { eml_remove(l); l = n; n = n->next; } }