~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to mail/src/cd-mail-applet-accounts.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program,
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Christophe Chapuis (for any bug report, please mail me to tofe@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <string.h>
 
30
#include <cairo-dock.h>
 
31
#include <libetpan/libetpan.h>
 
32
 
 
33
#include "cd-mail-applet-struct.h"
 
34
#include "cd-mail-applet-etpan.h"
 
35
#include "cd-mail-applet-accounts.h"
 
36
 
 
37
#define _add_icon(pMailAccount)\
 
38
                pIcon = g_new0 (Icon, 1);\
 
39
                pIcon->acName = g_strdup (pMailAccount->name);\
 
40
                pIcon->acFileName = g_strdup (myConfig.cNoMailUserImage);\
 
41
                pIcon->cQuickInfo = g_strdup ("...");\
 
42
                pIcon->fOrder = i;\
 
43
                pIcon->fScale = 1.;\
 
44
                pIcon->fAlpha = 1.;\
 
45
                pIcon->fWidthFactor = 1.;\
 
46
                pIcon->fHeightFactor = 1.;\
 
47
                pIcon->acCommand = g_strdup ("none");\
 
48
                pIcon->cParentDockName = g_strdup (myIcon->acName);\
 
49
                cd_debug (" + %s (%s)\n", pIcon->acName, pIcon->acFileName);\
 
50
                pIconList = g_list_append (pIconList, pIcon);\
 
51
                pMailAccount->icon = pIcon;
 
52
 
 
53
void cd_mail_create_pop3_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
54
{
 
55
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "pop3");
 
56
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);  // on lui met un widget pour ne pas que la cle se fasse bazarder lors d'une mise a jour du fichier de conf.
 
57
        
 
58
        g_key_file_set_string (pKeyFile, pMailAccountName, "host", "pop3.myhost.org");
 
59
        g_key_file_set_comment (pKeyFile, pMailAccountName, "host", "s0 server address:", NULL);
 
60
 
 
61
        g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
 
62
        g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:", NULL);
 
63
 
 
64
        g_key_file_set_string (pKeyFile, pMailAccountName, "password", "");
 
65
        g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:\n{The password will be crypted.}", NULL);
 
66
 
 
67
        g_key_file_set_integer (pKeyFile, pMailAccountName, "port", 0);
 
68
        g_key_file_set_comment (pKeyFile, pMailAccountName, "port", "i0 port:\n{Enter 0 to use the default port. Default ports are 110 for POP3 or APOP and 995 for POP3S.}", NULL);
 
69
 
 
70
        g_key_file_set_boolean (pKeyFile, pMailAccountName, "use secure connection", FALSE);
 
71
        g_key_file_set_comment (pKeyFile, pMailAccountName, "use secure connection", "b0 use secure connection (SSL)", NULL);
 
72
 
 
73
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
74
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
75
}
 
76
 
 
77
void cd_mail_retrieve_pop3_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
78
{
 
79
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
80
 
 
81
  gboolean bFlushConfFileNeeded = FALSE;
 
82
 
 
83
  mailaccount->driver = POP3_STORAGE;
 
84
  mailaccount->storage = mailstorage_new(NULL);
 
85
  mailaccount->folder = NULL;
 
86
  mailaccount->server = NULL;
 
87
  mailaccount->port = 0;
 
88
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
89
  mailaccount->user = NULL;
 
90
  mailaccount->password = NULL;
 
91
  mailaccount->auth_type = POP3_AUTH_TYPE_TRY_APOP;
 
92
  mailaccount->path = NULL;
 
93
  mailaccount->timeout = 0;
 
94
  
 
95
  if (g_key_file_has_key (pKeyFile, mailbox_name, "host", NULL))
 
96
  {
 
97
    mailaccount->server = CD_CONFIG_GET_STRING (mailbox_name, "host");
 
98
  }
 
99
  if (g_key_file_has_key (pKeyFile, mailbox_name, "username", NULL))
 
100
  {
 
101
    mailaccount->user = CD_CONFIG_GET_STRING (mailbox_name, "username");
 
102
  }
 
103
  if (g_key_file_has_key (pKeyFile, mailbox_name, "password", NULL))
 
104
  {
 
105
    gchar *encryptedPassword = CD_CONFIG_GET_STRING (mailbox_name, "password");
 
106
    cairo_dock_decrypt_string( encryptedPassword,  &(mailaccount->password) );
 
107
 
 
108
    if( encryptedPassword ) g_free(encryptedPassword);
 
109
  }
 
110
  mailaccount->connection_type = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT (mailbox_name, "use secure connection", FALSE)?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN;
 
111
  mailaccount->port = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "port", 0);
 
112
 
 
113
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
114
}
 
115
 
 
116
void cd_mail_create_imap_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
117
{
 
118
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "imap");
 
119
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
120
 
 
121
        g_key_file_set_string (pKeyFile, pMailAccountName, "host", "imap.myhost.org");
 
122
        g_key_file_set_comment (pKeyFile, pMailAccountName, "host", "s0 server address:", NULL);
 
123
 
 
124
        g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
 
125
        g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:", NULL);
 
126
 
 
127
        g_key_file_set_string (pKeyFile, pMailAccountName, "password", "");
 
128
        g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:", NULL);
 
129
 
 
130
        g_key_file_set_integer (pKeyFile, pMailAccountName, "port", 0);
 
131
        g_key_file_set_comment (pKeyFile, pMailAccountName, "port", "i0 port:\n{Enter 0 to use the default port. Default ports are 143 for IMAP4 and 993 for IMAP4 over SSL.}", NULL);
 
132
 
 
133
        g_key_file_set_boolean (pKeyFile, pMailAccountName, "use secure connection", FALSE);
 
134
        g_key_file_set_comment (pKeyFile, pMailAccountName, "use secure connection", "b0 use secure connection (SSL)", NULL);
 
135
 
 
136
        g_key_file_set_string (pKeyFile, pMailAccountName, "server_directory", "Inbox");
 
137
        g_key_file_set_comment (pKeyFile, pMailAccountName, "server_directory", "s0 directory on server:", NULL);
 
138
 
 
139
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
140
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
141
}
 
142
 
 
143
void cd_mail_retrieve_imap_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
144
{
 
145
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
146
 
 
147
  gboolean bFlushConfFileNeeded = FALSE;
 
148
 
 
149
  mailaccount->driver = IMAP_STORAGE;
 
150
  mailaccount->storage = mailstorage_new(NULL);
 
151
  mailaccount->folder = NULL;
 
152
  mailaccount->server = NULL;
 
153
  mailaccount->port = 0;
 
154
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
155
  mailaccount->user = NULL;
 
156
  mailaccount->password = NULL;
 
157
  mailaccount->auth_type = IMAP_AUTH_TYPE_PLAIN;
 
158
  mailaccount->path = g_strdup("/");
 
159
  mailaccount->timeout = 0;
 
160
  
 
161
  if (g_key_file_has_key (pKeyFile, mailbox_name, "host", NULL))
 
162
  {
 
163
    mailaccount->server = CD_CONFIG_GET_STRING (mailbox_name, "host");
 
164
  }
 
165
  if (g_key_file_has_key (pKeyFile, mailbox_name, "username", NULL))
 
166
  {
 
167
    mailaccount->user = CD_CONFIG_GET_STRING (mailbox_name, "username");
 
168
  }
 
169
  if (g_key_file_has_key (pKeyFile, mailbox_name, "password", NULL))
 
170
  {
 
171
    gchar *encryptedPassword = CD_CONFIG_GET_STRING (mailbox_name, "password");
 
172
    cairo_dock_decrypt_string( encryptedPassword,  &(mailaccount->password) );
 
173
 
 
174
    if( encryptedPassword ) g_free(encryptedPassword);
 
175
  }
 
176
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
177
  mailaccount->port = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "port", 0);
 
178
 
 
179
  mailaccount->connection_type = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT (mailbox_name, "use secure connection", FALSE)?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN;
 
180
 
 
181
  /* CONNECTION_TYPE_TLS ? CONNECTION_TYPE_STARTTLS ? */
 
182
 
 
183
  if (g_key_file_has_key (pKeyFile, mailbox_name, "server_directory", NULL))
 
184
  {
 
185
    mailaccount->path = CD_CONFIG_GET_STRING (mailbox_name, "server_directory");
 
186
  }
 
187
}
 
188
 
 
189
void cd_mail_create_mbox_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
190
{
 
191
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "mbox");
 
192
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
193
 
 
194
        g_key_file_set_string (pKeyFile, pMailAccountName, "filename", "");
 
195
        g_key_file_set_comment (pKeyFile, pMailAccountName, "filename", "s0 path of mbox file:", NULL);
 
196
 
 
197
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
198
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
199
}
 
200
 
 
201
void cd_mail_retrieve_mbox_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
202
{
 
203
        if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
204
 
 
205
        gboolean bFlushConfFileNeeded = FALSE;
 
206
 
 
207
        mailaccount->driver = MBOX_STORAGE;
 
208
        mailaccount->storage = mailstorage_new(NULL);
 
209
        mailaccount->folder = NULL;
 
210
        mailaccount->server = NULL;
 
211
        mailaccount->port = 0;
 
212
        mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
213
        mailaccount->user = NULL;
 
214
        mailaccount->password = NULL;
 
215
        mailaccount->auth_type = POP3_AUTH_TYPE_PLAIN;
 
216
        mailaccount->timeout = 0;
 
217
        if (g_key_file_has_key (pKeyFile, mailbox_name, "filename", NULL))
 
218
                mailaccount->path = CD_CONFIG_GET_STRING_WITH_DEFAULT (mailbox_name, "filename", "/");
 
219
        if (mailaccount->path == NULL)
 
220
                mailaccount->path = g_strdup("/");
 
221
        mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
222
 
 
223
        //{"filename", "ctime", "size", "interval", NULL, NULL}
 
224
}
 
225
 
 
226
void cd_mail_create_mh_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
227
{
 
228
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "mh");
 
229
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
230
 
 
231
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
232
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
233
}
 
234
 
 
235
void cd_mail_retrieve_mh_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
236
{
 
237
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
238
 
 
239
  gboolean bFlushConfFileNeeded = FALSE;
 
240
 
 
241
  mailaccount->driver = MH_STORAGE;
 
242
  mailaccount->storage = mailstorage_new(NULL);
 
243
  mailaccount->folder = NULL;
 
244
  mailaccount->server = NULL;
 
245
  mailaccount->port = 0;
 
246
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
247
  mailaccount->user = NULL;
 
248
  mailaccount->password = NULL;
 
249
  mailaccount->auth_type = POP3_AUTH_TYPE_PLAIN;
 
250
  mailaccount->path = g_strdup("/");
 
251
  mailaccount->timeout = 0;
 
252
 
 
253
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
254
}
 
255
 
 
256
void cd_mail_create_maildir_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
257
{
 
258
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "maildir");
 
259
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
260
 
 
261
        g_key_file_set_string (pKeyFile, pMailAccountName, "path", "");
 
262
        g_key_file_set_comment (pKeyFile, pMailAccountName, "path", "s0 path to mail directory:", NULL);
 
263
 
 
264
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
265
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
266
}
 
267
 
 
268
void cd_mail_retrieve_maildir_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
269
{
 
270
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
271
 
 
272
  gboolean bFlushConfFileNeeded = FALSE;
 
273
 
 
274
  mailaccount->driver = MAILDIR_STORAGE;
 
275
  mailaccount->storage = mailstorage_new(NULL);
 
276
  mailaccount->folder = NULL;
 
277
  mailaccount->server = NULL;
 
278
  mailaccount->port = 0;
 
279
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
280
  mailaccount->user = NULL;
 
281
  mailaccount->password = NULL;
 
282
  mailaccount->auth_type = POP3_AUTH_TYPE_PLAIN;
 
283
  mailaccount->path = g_strdup("/");
 
284
  mailaccount->timeout = 0;
 
285
 
 
286
  if (g_key_file_has_key (pKeyFile, mailbox_name, "path", NULL))
 
287
  {
 
288
    mailaccount->path = CD_CONFIG_GET_STRING (mailbox_name, "path");
 
289
  }
 
290
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
291
 
 
292
  //{"path", "mtime", "interval", NULL, NULL, NULL, NULL}
 
293
}
 
294
 
 
295
void cd_mail_create_gmail_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
296
{
 
297
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "gmail");
 
298
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
299
 
 
300
        g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
 
301
        g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:", NULL);
 
302
 
 
303
        g_key_file_set_string (pKeyFile, pMailAccountName, "password", "");
 
304
        g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:", NULL);
 
305
 
 
306
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
307
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
308
}
 
309
 
 
310
void cd_mail_retrieve_gmail_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
311
{
 
312
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
313
 
 
314
  gboolean bFlushConfFileNeeded = FALSE;
 
315
 
 
316
#if ( __WORDSIZE == 64 )
 
317
/* in 64bit libetpan crashes with RSS, so use the IMAP feature of GMail
 
318
 * instead of RSS. */
 
319
  mailaccount->driver = IMAP_STORAGE;
 
320
  mailaccount->storage = mailstorage_new(NULL);
 
321
  mailaccount->folder = NULL;
 
322
  mailaccount->server = g_strdup("imap.gmail.com");
 
323
  mailaccount->port = 993;
 
324
  mailaccount->connection_type = CONNECTION_TYPE_TLS;
 
325
  mailaccount->user = NULL;
 
326
  mailaccount->password = NULL;
 
327
  mailaccount->auth_type = IMAP_AUTH_TYPE_PLAIN;
 
328
  mailaccount->path = g_strdup("Inbox");
 
329
  mailaccount->timeout = 0;
 
330
  
 
331
  if (g_key_file_has_key (pKeyFile, mailbox_name, "username", NULL))
 
332
  {
 
333
    mailaccount->user = CD_CONFIG_GET_STRING (mailbox_name, "username");
 
334
  }
 
335
  if (g_key_file_has_key (pKeyFile, mailbox_name, "password", NULL))
 
336
  {
 
337
    gchar *encryptedPassword = CD_CONFIG_GET_STRING (mailbox_name, "password");
 
338
    cairo_dock_decrypt_string( encryptedPassword,  &(mailaccount->password) );
 
339
 
 
340
    if( encryptedPassword ) g_free(encryptedPassword);
 
341
  }
 
342
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
343
#else
 
344
  mailaccount->driver = FEED_STORAGE;
 
345
  mailaccount->storage = mailstorage_new(NULL);
 
346
  mailaccount->folder = NULL;
 
347
  mailaccount->server = NULL;
 
348
  mailaccount->port = 443;
 
349
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
350
  mailaccount->user = NULL;
 
351
  mailaccount->password = NULL;
 
352
  mailaccount->auth_type = POP3_AUTH_TYPE_PLAIN;
 
353
  mailaccount->path = NULL;
 
354
  mailaccount->timeout = 0;
 
355
  
 
356
  if (g_key_file_has_key (pKeyFile, mailbox_name, "username", NULL))
 
357
  {
 
358
    mailaccount->user = CD_CONFIG_GET_STRING (mailbox_name, "username");
 
359
  }
 
360
  if (g_key_file_has_key (pKeyFile, mailbox_name, "password", NULL))
 
361
  {
 
362
    gchar *encryptedPassword = CD_CONFIG_GET_STRING (mailbox_name, "password");
 
363
    cairo_dock_decrypt_string( encryptedPassword,  &(mailaccount->password) );
 
364
 
 
365
    if( encryptedPassword ) g_free(encryptedPassword);
 
366
  }
 
367
 
 
368
  gchar *user_without_column = NULL;
 
369
  gchar *password_without_column = NULL;
 
370
 
 
371
  if( mailaccount->user )
 
372
  {
 
373
    gchar **splitString = g_strsplit(mailaccount->user, ":", 0);
 
374
    user_without_column = g_strjoinv("%3A", splitString);
 
375
    g_strfreev( splitString );
 
376
  }
 
377
  if( mailaccount->password )
 
378
  {
 
379
    gchar **splitString = g_strsplit(mailaccount->password, ":", 0);
 
380
    password_without_column = g_strjoinv("%3A", splitString);
 
381
    g_strfreev( splitString );
 
382
  }
 
383
 
 
384
  if( user_without_column && password_without_column )
 
385
  {
 
386
    mailaccount->path = g_strconcat("https://", user_without_column, ":", password_without_column, "@mail.google.com/mail/feed/atom", NULL);
 
387
  }
 
388
  else
 
389
  {
 
390
    mailaccount->path = g_strdup( "https://mail.google.com/mail/feed/atom" );
 
391
  }
 
392
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
393
 
 
394
  g_free( user_without_column );
 
395
  g_free( password_without_column );
 
396
#endif
 
397
}
 
398
 
 
399
void cd_mail_create_feed_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
 
400
{
 
401
        g_key_file_set_string (pKeyFile, pMailAccountName, "type", "feed");
 
402
        g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);
 
403
 
 
404
        g_key_file_set_string (pKeyFile, pMailAccountName, "path", "http://www.cairo-dock.org/rss/cd_svn.xml");
 
405
        g_key_file_set_comment (pKeyFile, pMailAccountName, "path", "s0 address of feed:", NULL);
 
406
 
 
407
        g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
 
408
        g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
 
409
}
 
410
 
 
411
void cd_mail_retrieve_feed_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name)
 
412
{
 
413
  if( !mailaccount || !pKeyFile || !mailbox_name ) return;
 
414
 
 
415
  extern int mailstream_debug;
 
416
  mailstream_debug = 1;
 
417
 
 
418
  gboolean bFlushConfFileNeeded = FALSE;
 
419
 
 
420
  mailaccount->driver = FEED_STORAGE;
 
421
  mailaccount->storage = mailstorage_new(NULL);
 
422
  mailaccount->folder = NULL;
 
423
  mailaccount->server = NULL;
 
424
  mailaccount->port = 443;
 
425
  mailaccount->connection_type = CONNECTION_TYPE_PLAIN;
 
426
  mailaccount->user = NULL;
 
427
  mailaccount->password = NULL;
 
428
  mailaccount->auth_type = POP3_AUTH_TYPE_PLAIN;
 
429
  mailaccount->path = NULL;
 
430
  mailaccount->timeout = 0;
 
431
  
 
432
  if (g_key_file_has_key (pKeyFile, mailbox_name, "path", NULL))
 
433
  {
 
434
    mailaccount->path = CD_CONFIG_GET_STRING (mailbox_name, "path");
 
435
  }
 
436
  mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10);
 
437
}
 
438
 
 
439
/*{
 
440
  {POP3_STORAGE, "pop3", {"host", "username", "password", "auth_type", "timeout mn", "port", NULL}},
 
441
  {IMAP_STORAGE, "imap", {"host", "username", "password", "auth_type", "timeout mn", "port", "server_directory"}},
 
442
  {NNTP_STORAGE, "nntp", {NULL, NULL, NULL, NULL, NULL, NULL, NULL}},
 
443
  {MBOX_STORAGE, "mbox", {"filename", "ctime", "size", "interval", NULL, NULL}},
 
444
  {MH_STORAGE, "mh", {"timeout mn", NULL, NULL, NULL, NULL, NULL, NULL}},
 
445
  {MAILDIR_STORAGE, "maildir", {"path", "mtime", "interval", NULL, NULL, NULL, NULL}},
 
446
  {FEED_STORAGE, "feed", {"username", "password", "timeout mn", NULL, NULL, NULL, NULL}},
 
447
  {FEED_STORAGE, "gmail", {"username", "password", "timeout mn", NULL, NULL, NULL, NULL}},
 
448
};*/
 
449
 
 
450
 
 
451
void cd_mail_init_accounts(CairoDockModuleInstance *myApplet)
 
452
{       
 
453
        if (myData.pMailAccounts == NULL)
 
454
                return ;
 
455
        g_print ("%s (%d comptes)\n", __func__, myData.pMailAccounts->len);
 
456
        
 
457
        //\_______________________ On initialise chaque compte.
 
458
        CDMailAccount *pMailAccount;
 
459
        GList *pIconList = NULL;
 
460
        Icon *pIcon;
 
461
        int iNbIcons = 0;
 
462
        int r;
 
463
        guint i;
 
464
        for (i = 0; i < myData.pMailAccounts->len; i ++)
 
465
        {
 
466
                pMailAccount = g_ptr_array_index (myData.pMailAccounts, i);
 
467
                if( !pMailAccount ) continue;
 
468
                
 
469
                // init this account
 
470
                switch (pMailAccount->driver) {
 
471
                        case POP3_STORAGE:
 
472
                                r = pop3_mailstorage_init(pMailAccount->storage, pMailAccount->server, pMailAccount->port,
 
473
                                        NULL, pMailAccount->connection_type,
 
474
                                        pMailAccount->auth_type, pMailAccount->user, pMailAccount->password,
 
475
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
476
                        break;
 
477
 
 
478
                        case IMAP_STORAGE:
 
479
                                r = imap_mailstorage_init(pMailAccount->storage, pMailAccount->server, pMailAccount->port,
 
480
                                        NULL, pMailAccount->connection_type,
 
481
                                        IMAP_AUTH_TYPE_PLAIN, pMailAccount->user, pMailAccount->password,
 
482
                                        FALSE /*cached*/, NULL /*cache_directory*/);
 
483
                        break;
 
484
 
 
485
                        case NNTP_STORAGE:
 
486
                                r = nntp_mailstorage_init(pMailAccount->storage, pMailAccount->server, pMailAccount->port,
 
487
                                        NULL, pMailAccount->connection_type,
 
488
                                        NNTP_AUTH_TYPE_PLAIN, pMailAccount->user, pMailAccount->password,
 
489
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
490
                        break;
 
491
 
 
492
                        case MBOX_STORAGE:
 
493
                                r = mbox_mailstorage_init(pMailAccount->storage, pMailAccount->path,
 
494
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
495
                        break;
 
496
 
 
497
                        case MH_STORAGE:
 
498
                                r = mh_mailstorage_init(pMailAccount->storage, pMailAccount->path,
 
499
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
500
                        break;
 
501
                        
 
502
                        case MAILDIR_STORAGE:
 
503
                                r = maildir_mailstorage_init(pMailAccount->storage, pMailAccount->path,
 
504
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
505
                        break;
 
506
                        
 
507
                        case FEED_STORAGE:
 
508
                                r = feed_mailstorage_init(pMailAccount->storage, pMailAccount->path,
 
509
                                        FALSE /*cached*/, NULL /*cache_directory*/, NULL /*flags_directory*/);
 
510
                        break;
 
511
                        default :
 
512
                                r = -1;
 
513
                }
 
514
                
 
515
                // add an icon for this account.
 
516
                if (myData.pMailAccounts->len == 1)  // 1 seul compte
 
517
                {
 
518
                        pIcon = myIcon;
 
519
                }
 
520
                else
 
521
                {
 
522
                        _add_icon (pMailAccount);
 
523
                }
 
524
                iNbIcons ++;
 
525
                
 
526
                //  if all is OK, then set a timeout for this mail account
 
527
                if (r == MAIL_NO_ERROR)
 
528
                {
 
529
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("...");
 
530
                        pMailAccount->pAccountMailTimer = cairo_dock_new_task (pMailAccount->timeout * 60,
 
531
                                (CairoDockGetDataAsyncFunc) cd_mail_get_folder_data,
 
532
                                (CairoDockUpdateSyncFunc) cd_mail_update_account_status,
 
533
                                pMailAccount);
 
534
                        cairo_dock_launch_task (pMailAccount->pAccountMailTimer);
 
535
                }
 
536
                else
 
537
                {
 
538
                        cd_warning ("mail : the mail account %s couldn't be initialized !", pMailAccount->name);
 
539
                        CairoContainer *pContainer = (myData.pMailAccounts->len == 1 ? myContainer : CD_APPLET_MY_ICONS_LIST_CONTAINER);
 
540
                        cairo_dock_set_quick_info (myDrawContext, "N/A", pIcon, cairo_dock_get_max_scale (pContainer));
 
541
                }
 
542
        }
 
543
        
 
544
        //\_______________________ On efface l'ancienne liste.
 
545
        CD_APPLET_DELETE_MY_ICONS_LIST;
 
546
        
 
547
        //\_______________________ On charge la nouvelle liste.
 
548
        if (myData.pMailAccounts->len > 1)
 
549
        {
 
550
                gpointer pConfig[2] = {GINT_TO_POINTER (FALSE), GINT_TO_POINTER (FALSE)};
 
551
                CD_APPLET_LOAD_MY_ICONS_LIST (pIconList, myConfig.cRenderer, (iNbIcons > 1 ? "Caroussel" : "Simple"), (iNbIcons > 1 ? pConfig : NULL));
 
552
        }
 
553
        
 
554
        //\_______________ On dessine l'icone principale initialement.
 
555
        CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cNoMailUserImage);
 
556
        if (iNbIcons > 0)
 
557
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("...");
 
558
}
 
559
 
 
560
 
 
561
void cd_mail_free_account (CDMailAccount *pMailAccount)
 
562
{
 
563
        if (pMailAccount == NULL)
 
564
                return ;
 
565
        
 
566
        cairo_dock_free_task( pMailAccount->pAccountMailTimer );
 
567
        
 
568
        g_free( pMailAccount->name );
 
569
        g_free( pMailAccount->server );
 
570
        g_free( pMailAccount->user );
 
571
        g_free( pMailAccount->password );
 
572
        g_free( pMailAccount->path );
 
573
 
 
574
        if( pMailAccount->folder )
 
575
                mailfolder_free(pMailAccount->folder);
 
576
        if( pMailAccount->storage )
 
577
                mailstorage_free(pMailAccount->storage);
 
578
        
 
579
        g_list_foreach (pMailAccount->pUnseenMessageList, (GFunc) g_free, NULL);
 
580
        g_list_free (pMailAccount->pUnseenMessageList);
 
581
        
 
582
        g_free( pMailAccount );
 
583
}
 
584
 
 
585
void cd_mail_free_all_accounts (CairoDockModuleInstance *myApplet)
 
586
{
 
587
        if (myData.pMailAccounts == NULL)
 
588
                return ;
 
589
        CDMailAccount *pMailAccount;
 
590
        guint i;
 
591
        for (i = 0; i < myData.pMailAccounts->len; i ++)
 
592
        {
 
593
                pMailAccount = g_ptr_array_index (myData.pMailAccounts, i);
 
594
                cd_mail_free_account (pMailAccount);
 
595
        }
 
596
        g_ptr_array_free (myData.pMailAccounts, TRUE);
 
597
        myData.pMailAccounts = NULL;
 
598
}