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
|
/*
* folder-info.c: Implementation of GNOME_Evolution_FolderInfo
*
* Copyright (C) 2001 Ximian, Inc.
*
* Authors: Iain Holmes <iain@ximian.com>
*/
#include "Mail.h"
#include <glib.h>
#include <libgnome/gnome-defs.h>
#include <bonobo/bonobo-xobject.h>
#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-context.h>
#include <bonobo/bonobo-exception.h>
#include "mail-mt.h"
#include <camel/camel-exception.h>
#define FOLDER_INFO_IID "OAFIID:GNOME_Evolution_FolderInfo_Factory"
#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
static BonoboObjectClass *parent_class = NULL;
typedef struct _EvolutionFolderInfo EvolutionFolderInfo;
typedef struct _EvolutionFolderInfoClass EvolutionFolderInfoClass;
struct _EvolutionFolderInfo {
BonoboXObject parent;
};
struct _EvolutionFolderInfoClass {
BonoboXObjectClass parent_class;
POA_GNOME_Evolution_FolderInfo__epv epv;
};
/* MT stuff */
struct _folder_info_msg {
struct _mail_msg msg;
Bonobo_Listener listener;
char *foldername;
int read;
int unread;
};
static void
do_get_info (struct _mail_msg *mm)
{
struct _folder_info_msg *m = (struct _folder_info_msg *) mm;
char *uri_dup;
char *foldername, *start, *end;
char *storage, *protocol, *uri;
CamelFolder *folder;
CamelException *ex;
#if 0
/* Fixme: Do other stuff. Different stuff to the stuff below */
uri_dup = g_strdup (m->foldername);
start = uri_dup + 11;
g_warning ("Start: %s", start);
end = strrchr (start, '/');
if (end == NULL) {
g_warning ("Bugger");
return;
}
storage = g_strndup (start, end - start);
start = end + 1;
foldername = g_strdup (start);
g_free (uri_dup);
/* Work out the protocol.
The storage is going to start as local, or vfolder, or an imap
server. */
g_warning ("Storage: %s", storage);
if (strncmp (storage, "local", 5) == 0) {
char *evolution_dir;
char *proto;
evolution_dir = gnome_util_prepend_user_home ("evolution/local");
proto = g_strconcat ("file://", evolution_dir, NULL);
uri = e_path_to_physical (proto, foldername);
g_free (evolution_dir);
g_free (proto);
} else if (strncmp (storage, "vfolder", 7) == 0) {
uri = g_strconcat ("vfolder://", foldername, NULL);
} else {
uri = g_strconcat ("imap://", storage, foldername, NULL);
}
#endif
ex = camel_exception_new ();
folder = mail_tool_uri_to_folder (m->foldername, ex);
if (camel_exception_is_set (ex)) {
g_warning ("Camel exception: %s", camel_exception_get_description (ex));
}
camel_exception_free (ex);
m->read = camel_folder_get_message_count (folder);
m->unread = camel_folder_get_unread_message_count (folder);
}
static void
do_got_info (struct _mail_msg *mm)
{
struct _folder_info_msg *m = (struct _folder_info_msg *) mm;
CORBA_Environment ev;
CORBA_any a;
GNOME_Evolution_FolderInfo_MessageCount count;
g_print ("You've got mail: %d, %d\n", m->read, m->unread);
count.path = m->foldername;
count.count = m->read;
count.unread = m->unread;
a._type = (CORBA_TypeCode) TC_GNOME_Evolution_FolderInfo_MessageCount;
a._value = &count;
CORBA_exception_init (&ev);
Bonobo_Listener_event (m->listener, "youve-got-mail", &a, &ev);
if (BONOBO_EX (&ev)) {
g_warning ("Got exception on listener: %s", CORBA_exception_id (&ev));
}
CORBA_exception_free (&ev);
}
static void
do_free_info (struct _mail_msg *mm)
{
struct _folder_info_msg *m = (struct _folder_info_msg *) mm;
g_free (m->foldername);
}
struct _mail_msg_op get_info_op = {
NULL,
do_get_info,
do_got_info,
do_free_info,
};
typedef struct {
int read;
int unread;
} MailFolderInfo;
/* Returns a MailFolderInfo struct or NULL on error */
static void
mail_get_info (const char *foldername,
Bonobo_Listener listener)
{
CORBA_Environment ev;
struct _folder_info_msg *m;
m = mail_msg_new (&get_info_op, NULL, sizeof (*m));
g_print ("Folder: %s", foldername);
m->foldername = g_strdup (foldername);
CORBA_exception_init (&ev);
m->listener = bonobo_object_dup_ref (listener, &ev);
CORBA_exception_free (&ev);
e_thread_put (mail_thread_new, (EMsg *) m);
}
static void
impl_GNOME_Evolution_FolderInfo_getInfo (PortableServer_Servant servant,
const CORBA_char *foldername,
const Bonobo_Listener listener,
CORBA_Environment *ev)
{
mail_get_info (foldername, listener);
}
static void
evolution_folder_info_class_init (EvolutionFolderInfoClass *klass)
{
POA_GNOME_Evolution_FolderInfo__epv *epv = &klass->epv;
parent_class = gtk_type_class (PARENT_TYPE);
epv->getInfo = impl_GNOME_Evolution_FolderInfo_getInfo;
}
static void
evolution_folder_info_init (EvolutionFolderInfo *info)
{
}
BONOBO_X_TYPE_FUNC_FULL (EvolutionFolderInfo,
GNOME_Evolution_FolderInfo,
PARENT_TYPE,
evolution_folder_info);
static BonoboObject *
evolution_folder_info_factory_fn (BonoboGenericFactory *factory,
void *closure)
{
EvolutionFolderInfo *info;
info = gtk_type_new (evolution_folder_info_get_type ());
return BONOBO_OBJECT (info);
}
void
evolution_folder_info_factory_init (void)
{
BonoboGenericFactory *factory;
factory = bonobo_generic_factory_new (FOLDER_INFO_IID,
evolution_folder_info_factory_fn,
NULL);
if (factory == NULL) {
g_warning ("Error starting FolderInfo");
return;
}
bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory));
}
|