aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell-view.c
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2000-08-29 16:46:15 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2000-08-29 16:46:15 +0800
commit7c6a10ab046ddb963e4b250f7b3876c3acd78e20 (patch)
treed74e05019a3c4d423c9d6598915b4d3b8e2980bb /shell/e-shell-view.c
parent919e333a783ac045a45a34ed8efca6fb730ed968 (diff)
downloadgsoc2013-evolution-7c6a10ab046ddb963e4b250f7b3876c3acd78e20.tar.gz
gsoc2013-evolution-7c6a10ab046ddb963e4b250f7b3876c3acd78e20.tar.zst
gsoc2013-evolution-7c6a10ab046ddb963e4b250f7b3876c3acd78e20.zip
Strip off newlines when setting the messages in the statusbar, so that
the statusbar's size doesn't change in a bad way if the component gives us a message including a newline. (The latter shouldn't happen anyway, but this is a different issue.) svn path=/trunk/; revision=5094
Diffstat (limited to 'shell/e-shell-view.c')
-rw-r--r--shell/e-shell-view.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index be0845da32..3a7f838d3b 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -694,10 +694,22 @@ shell_view_interface_set_message_cb (EvolutionShellView *shell_view,
gtk_progress_set_value (GTK_PROGRESS (app_bar->progress), 1.0);
- if (message != NULL)
- gnome_appbar_set_status (app_bar, message);
- else
+ if (message != NULL) {
+ const char *newline;
+
+ newline = strchr (message, '\n');
+ if (newline == NULL) {
+ gnome_appbar_set_status (app_bar, message);
+ } else {
+ char *message_until_newline;
+
+ message_until_newline = g_strndup (message, newline - message);
+ gnome_appbar_set_status (app_bar, message_until_newline);
+ g_free (message_until_newline);
+ }
+ } else {
gnome_appbar_set_status (app_bar, "");
+ }
if (busy)
start_progress_bar (E_SHELL_VIEW (data));
nsport.' href='/~lantw44/cgit/gsoc2013-evolution/commit/mail/mail-config.c?id=8fbd4ab4bd5fdbaa7f126b3f1d733e8dc9e8a958'>8fbd4ab4bd
57574f0be3

4503c052d0
448d624c00
8fbd4ab4bd
3e82887a54
27a61acf27
e0f414941d
98d262b594
e0f414941d
f256a6120f
e75013c201
0eef4618ca
8fed71251f
0eef4618ca
0eef4618ca
8d3a2ebd28
54b80a7271
a2d998fe13
fb6caf533c
9e4fcb29cf
948235c3d1
9e4fcb29cf
d48d40c7ce
52ba74cef4
9e4fcb29cf
253a05d03c
2c0ce47a99


2c0ce47a99
71e5a4dcbb
c9d8512b2e
64c6a63cf2

948235c3d1
0cf607076d
2b60e44890
aea82dfd60

42333eed03
60ba84e6a4
52ba74cef4
60ba84e6a4
52ba74cef4




a1ce3904ce
9e4fcb29cf
448d624c00
a1ce3904ce
60ba84e6a4

9e4fcb29cf
52ba74cef4















60ba84e6a4

52ba74cef4

42333eed03
7aa2882d38

a09f4c7c08

7aa2882d38
60ba84e6a4



9e4fcb29cf
60ba84e6a4
a09f4c7c08


bfe4d349ad
9e4fcb29cf
f8626b2845
bfe4d349ad

9e4fcb29cf
bfe4d349ad
60ba84e6a4


42333eed03
aea82dfd60
60ba84e6a4
42333eed03
60ba84e6a4

aea82dfd60
4f4615a46d


4f4615a46d










2c0ce47a99
52ba74cef4
2c0ce47a99
4503c052d0
2c0ce47a99
4503c052d0
179db75ce0


4503c052d0
179db75ce0
4503c052d0
2c0ce47a99


948235c3d1
2c0ce47a99




948235c3d1
179db75ce0
















2c0ce47a99

5b89cbe4f5
52ba74cef4



253a05d03c
52ba74cef4
253a05d03c
52ba74cef4




0a7017c1a6


52ba74cef4



0a7017c1a6
52ba74cef4
0a7017c1a6
52ba74cef4




956cd913f1

e0053bce8e
49b857afdc
8fbd4ab4bd
e0f414941d


b7dede1a27

9e4fcb29cf
98d262b594

e0f414941d


9e4fcb29cf
fb6caf533c
cd2628ec5b

8fed71251f
d120c67b62


c9d8512b2e


d120c67b62


948235c3d1
253a05d03c
9e4fcb29cf
253a05d03c





b67d6b02ca
























23df769955
948235c3d1
424506262d
faf1c14c11
4f4615a46d
e0053bce8e
d158af8cdf
23df769955
9e4fcb29cf
23df769955

9e4fcb29cf
23df769955
d158af8cdf

23df769955


faf1c14c11

d158af8cdf

948235c3d1
4f4615a46d
e0053bce8e
9e4fcb29cf
4f4615a46d
9e4fcb29cf
23df769955


d158af8cdf
4f4615a46d
d158af8cdf
9e4fcb29cf
23df769955
d158af8cdf

4f4615a46d
d158af8cdf
4f4615a46d
23df769955
4f4615a46d

d158af8cdf
424506262d
9e4fcb29cf
e0053bce8e
c7d3c9f956
9e4fcb29cf
d158af8cdf
7b02bff821

948235c3d1
23df769955
4157d65284
23df769955



ef395aea81
948235c3d1
23df769955





9e4fcb29cf
e0053bce8e
948235c3d1
4157d65284
23df769955

9e4fcb29cf
23df769955
948235c3d1
23df769955

4157d65284
9e4fcb29cf
e0053bce8e
a2d998fe13
875c9d02c4
e0f414941d
e0053bce8e

9e4fcb29cf
e0f414941d


05601e86eb
a2d998fe13
9e4fcb29cf
a293a2aa21
e0f414941d
e0053bce8e

9e4fcb29cf
05601e86eb
e0053bce8e
9e4fcb29cf
a293a2aa21
e0053bce8e
9e4fcb29cf
e0053bce8e
a293a2aa21
9e4fcb29cf
e0053bce8e
9e4fcb29cf
a293a2aa21
491b3c3c77

948235c3d1

c585c8203f
54b80a7271
948235c3d1

9e4fcb29cf
968ea42023
54b80a7271
c585c8203f



54b80a7271
c585c8203f
54b80a7271
c585c8203f



0eef4618ca
948235c3d1
0c43bcb20b
e0f414941d
e0053bce8e

948235c3d1

0cf607076d






9e4fcb29cf
e0f414941d

e0053bce8e

9e4fcb29cf
e0053bce8e


0c43bcb20b

9e4fcb29cf
e0053bce8e


0c43bcb20b

9e4fcb29cf
e0053bce8e
0c43bcb20b
9e4fcb29cf
e0053bce8e
9e4fcb29cf
c585c8203f

9e4fcb29cf
c585c8203f



448d624c00
c585c8203f


9e4fcb29cf
0c43bcb20b

e0053bce8e
0c43bcb20b

0eef4618ca
948235c3d1
0c43bcb20b
e0f414941d
e0053bce8e

948235c3d1
54b80a7271


0c43bcb20b
174c942e09



9e4fcb29cf
e0f414941d

e0053bce8e

9e4fcb29cf
e0053bce8e

54b80a7271
0c43bcb20b

9e4fcb29cf
e0053bce8e

54b80a7271
0c43bcb20b

9e4fcb29cf
e0053bce8e
0c43bcb20b
9e4fcb29cf
0c43bcb20b

e0053bce8e
0c43bcb20b

9e4fcb29cf
e0053bce8e
56d33b7e47

56d33b7e47

948235c3d1
b7ac37f6b1
80237e0c26
948235c3d1
9e4fcb29cf
0d27a62785
804acf56c6
9e4fcb29cf
b7ac37f6b1


948235c3d1

b7ac37f6b1
948235c3d1
54b80a7271
9e4fcb29cf
968ea42023
b7ac37f6b1
0755131616
6affbe33e9
0755131616
a2d998fe13
9e4fcb29cf
80237e0c26


2c0ce47a99
71e5a4dcbb
2c0ce47a99



e4afd3f9fb
2c0ce47a99




71e5a4dcbb
2c0ce47a99





71e5a4dcbb







2c0ce47a99
71e5a4dcbb
2c0ce47a99
0eef4618ca


























efa5316395

0eef4618ca
0eef4618ca

4887542c24



0eef4618ca












































































































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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
  
                                                                


                                                               
  


                                                                    


                                                                   
                                                                             


           


                                                        
  
                                                        
                                       
  

   
                    
                   

      
                    
                        
 
                                              
                          
                                   
                                     
 
                               
 
                         
                        
                              
                         
                       
 
                
                           
 
                     
 
                       
 
                                  
                           


                          
                             
                                        
                                  

             
                                                            
 
                                 

           
                         
 
                            
                        




                              
                 
 
                                                    
                                                               

                       
 















                                                                     

                                                                  

                                                                                   
 

                                                                                                       

                                         
 



                                                                      
                                             
         


                          
                              
 
                                                                                   

                    
 
                              


           
                                                        
                                                           
 
                              

 
           


                                                                       










                                                                                                      
                                                             
                                                                
 
                     
                                
 


                                                                  
                                                                                                                                       
 
                                 


                                    
                                                              




                                                          
                                                                                                             
















                                                                                                                        

 
           



                                                  
 
                             
 




                                                                            


           



                                             
 
                             
 




                                                                           

 
    
                        
 


                                       

                       
 

                                                 


                                               
 
                                                        

 
                        


                                   


                                    


                             
    
                                    
 





                                      
























                                                                                                 
                 
                                                                                             
 
                                   
                                 
                        
                      
                                
 

                                                            
 
                                              

                                                 


                                                                                     

                                                            

                                                               
                                                
 
                                                             
 
                                       
 


                                                                   
                                       
                                 
                 
 
                                                                       

                                          
                                 
                 
 
                                                            

                                                          
                                             
         
 
                              
                             
 
                       

 
                    
                                         
 



                                                                                        
 
                    





                                                                                                 
 
          
                                                               
 

                                                                     
 
          
                                                                     

                                                                           
 
 
                 
                                        
 
                                   

                          
 


                                             
                                                                                                                       
                                          
 
                                                        
                                                            

                                                             
 
                                                                                                                      
                                              
 
                                                  
                 
 
                                       
         
 
                              
 
                    

 

                                                     
 
                              

                    
 
                                                
 



                                       
                                                                                  
            
                                                                          



                      
           
                                                                                  
 
                                   

                          

                                 






                                       
 

                                                            

                                                             
 


                                                                                          

                                 
 


                                                                                              

                                 
 
                                       
         
 
                              
 

                                                        
 



                                                                        
                                            


                                 
 

                       
                                     

 
           
                                                                
 
                                   

                          
                      


                                             
                                                



                                                                   
 

                                                            

                                                             
 

                                                                                          
                                                                                    

                                 
 

                                                                                              
                                                                                        

                                 
 
                                       
         
 

                         
                                     

 
    
                                                                                    

                                           

 
       
                                                    
 
                   
 
                                                
                                   
 


                   

                                                                          
 
                                         
                                
 
                                                    
                                                      
                                                         
                                                                            
                          
                     
 


                        
    
                                      



                                                  
            




                                                                        
                                  





                                                  







                                                  
 
                                              
 


























                                                                                                                           

                                               
 

                                     



                                                              












































































































                                                                             
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *   Jeffrey Stedfast <fejj@ximian.com>
 *   Radek Doulik <rodo@ximian.com>
 *   Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 * Copyright (C) 2009 Intel Corporation
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>
#include <glib/gstdio.h>

#include <libedataserver/e-data-server-util.h>
#include <e-util/e-util.h>
#include "e-util/e-account-utils.h"
#include "e-util/e-signature-utils.h"

#include <gconf/gconf-client.h>

#include "e-mail-local.h"
#include "mail-config.h"
#include "mail-folder-cache.h"
#include "mail-session.h"
#include "mail-tools.h"

typedef struct {
    GConfClient *gconf;

    gchar *gtkrc;

    GSList *labels;

    gboolean address_compress;
    gint address_count;

    GSList *jh_header;
    gboolean jh_check;
    gboolean book_lookup;
    gboolean book_lookup_local_only;
    gboolean scripts_disabled;
} MailConfig;

extern gint camel_header_param_encode_filenames_in_rfc_2047;

static MailConfig *config = NULL;

static void
config_write_style (void)
{
    GConfClient *client;
    gboolean custom;
    gchar *fix_font;
    gchar *var_font;
    gchar *citation_color;
    gchar *spell_color;
    const gchar *key;
    FILE *rc;

    if (!(rc = g_fopen (config->gtkrc, "wt"))) {
        g_warning ("unable to open %s", config->gtkrc);
        return;
    }

    client = config->gconf;

    key = "/apps/evolution/mail/display/fonts/use_custom";
    custom = gconf_client_get_bool (client, key, NULL);

    key = "/apps/evolution/mail/display/fonts/variable";
    var_font = gconf_client_get_string (client, key, NULL);

    key = "/apps/evolution/mail/display/fonts/monospace";
    fix_font = gconf_client_get_string (client, key, NULL);

    key = "/apps/evolution/mail/display/citation_colour";
    citation_color = gconf_client_get_string (client, key, NULL);

    key = "/apps/evolution/mail/composer/spell_color";
    spell_color = gconf_client_get_string (client, key, NULL);

    fprintf (rc, "style \"evolution-mail-custom-fonts\" {\n");
    fprintf (rc, "        GtkHTML::spell_error_color = \"%s\"\n", spell_color);
    g_free (spell_color);

    if (gconf_client_get_bool (config->gconf, "/apps/evolution/mail/display/mark_citations", NULL))
        fprintf (rc, "        GtkHTML::cite_color = \"%s\"\n",
             citation_color);
    g_free (citation_color);

    if (custom && var_font && fix_font) {
        fprintf (rc,
             "        GtkHTML::fixed_font_name = \"%s\"\n"
             "        font_name = \"%s\"\n",
             fix_font, var_font);
    }
    g_free (fix_font);
    g_free (var_font);

    fprintf (rc, "}\n\n");

    fprintf (rc, "class \"EWebView\" style \"evolution-mail-custom-fonts\"\n");
    fflush (rc);
    fclose (rc);

    gtk_rc_reparse_all ();
}

static void
gconf_style_changed (GConfClient *client, guint cnxn_id,
             GConfEntry *entry, gpointer user_data)
{
    config_write_style ();
}

static void
gconf_outlook_filenames_changed (GConfClient *client, guint cnxn_id,
                 GConfEntry *entry, gpointer user_data)
{
    g_return_if_fail (client != NULL);

    /* pass option to the camel */
    if (gconf_client_get_bool (client, "/apps/evolution/mail/composer/outlook_filenames", NULL)) {
        camel_header_param_encode_filenames_in_rfc_2047 = 1;
    } else {
        camel_header_param_encode_filenames_in_rfc_2047 = 0;
    }
}

static void
gconf_jh_headers_changed (GConfClient *client, guint cnxn_id,
                          GConfEntry *entry, gpointer user_data)
{
    GSList *node;
    GPtrArray *name, *value;

    g_slist_foreach (config->jh_header, (GFunc) g_free, NULL);
    g_slist_free (config->jh_header);

    config->jh_header = gconf_client_get_list (config->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, NULL);

    node = config->jh_header;
    name = g_ptr_array_new ();
    value = g_ptr_array_new ();
    while (node && node->data) {
        gchar **tok = g_strsplit (node->data, "=", 2);
        g_ptr_array_add (name, g_strdup(tok[0]));
        g_ptr_array_add (value, g_strdup(tok[1]));
        node = node->next;
        g_strfreev (tok);
    }
    mail_session_set_junk_headers ((const gchar **)name->pdata, (const gchar **)value->pdata, name->len);

    g_ptr_array_foreach (name, (GFunc) g_free, NULL);
    g_ptr_array_foreach (value, (GFunc) g_free, NULL);
    g_ptr_array_free (name, TRUE);
    g_ptr_array_free (value, TRUE);
}

static void
gconf_jh_check_changed (GConfClient *client, guint cnxn_id,
             GConfEntry *entry, gpointer user_data)
{
    config->jh_check = gconf_client_get_bool (config->gconf, "/apps/evolution/mail/junk/check_custom_header", NULL);
    if (!config->jh_check) {
        mail_session_set_junk_headers (NULL, NULL, 0);
    } else {
        gconf_jh_headers_changed (NULL, 0, NULL, NULL);
    }
}

static void
gconf_bool_value_changed (GConfClient *client,
                          guint cnxn_id,
                          GConfEntry *entry,
                          gboolean *save_location)
{
    GError *error = NULL;

    *save_location = gconf_client_get_bool (client, entry->key, &error);
    if (error != NULL) {
        g_warning ("%s", error->message);
        g_error_free (error);
    }
}

static void
gconf_int_value_changed (GConfClient *client,
                         guint cnxn_id,
                         GConfEntry *entry,
                         gint *save_location)
{
    GError *error = NULL;

    *save_location = gconf_client_get_int (client, entry->key, &error);
    if (error != NULL) {
        g_warning ("%s", error->message);
        g_error_free (error);
    }
}

void
mail_config_write (void)
{
    EAccountList *account_list;
    ESignatureList *signature_list;

    if (!config)
        return;

    account_list = e_get_account_list ();
    signature_list = e_get_signature_list ();

    e_account_list_save (account_list);
    e_signature_list_save (signature_list);

    gconf_client_suggest_sync (config->gconf, NULL);
}

/* Accessor functions */
GConfClient *
mail_config_get_gconf_client (void)
{
    if (!config)
        mail_config_init ();

    return config->gconf;
}

gint
mail_config_get_address_count (void)
{
    if (!config->address_compress)
        return -1;

    return config->address_count;
}

/* timeout interval, in seconds, when to call server update */
gint
mail_config_get_sync_timeout (void)
{
    GConfClient *gconf = mail_config_get_gconf_client ();
    gint res = 60;

    if (gconf) {
        GError *error = NULL;

        res = gconf_client_get_int (gconf, "/apps/evolution/mail/sync_interval", &error);

        /* do not allow recheck sooner than every 30 seconds */
        if (error || res == 0)
            res = 60;
        else if (res < 30)
            res = 30;

        if (error)
            g_error_free (error);
    }

    return res;
}

static EAccount *
mc_get_account_by (const gchar *given_url, const gchar * (get_url_string)(EAccount *account))
{
    EAccountList *account_list;
    EAccount *account = NULL;
    EIterator *iter;
    CamelURL *url;
    CamelProvider *provider;

    g_return_val_if_fail (given_url != NULL, NULL);
    g_return_val_if_fail (get_url_string != NULL, NULL);

    url = camel_url_new (given_url, NULL);
    g_return_val_if_fail (url != NULL, NULL);

    provider = camel_provider_get (given_url, NULL);
    g_return_val_if_fail (provider != NULL && provider->url_equal != NULL, NULL);

    account_list = e_get_account_list ();
    iter = e_list_get_iterator ((EList *) account_list);
    while (account == NULL && e_iterator_is_valid (iter)) {
        CamelURL *account_url;
        const gchar *account_url_string;

        account = (EAccount *) e_iterator_get (iter);

        e_iterator_next (iter);

        account_url_string = get_url_string (account);

        if ( !account_url_string || !*account_url_string) {
            account = NULL;
            continue;
        }

        account_url = camel_url_new (account_url_string, NULL);
        if (account_url == NULL) {
            account = NULL;
            continue;
        }

        if (!provider->url_equal (url, account_url))
            account = NULL;  /* not a match */

        camel_url_free (account_url);
    }

    g_object_unref (iter);
    camel_url_free (url);

    return account;
}

static const gchar *
get_source_url_string (EAccount *account)
{
    if (account && account->source && account->source->url && *account->source->url)
        return account->source->url;
    return NULL;
}

static const gchar *
get_transport_url_string (EAccount *account)
{
    if (account && account->transport && account->transport->url && *account->transport->url)
        return account->transport->url;
    return NULL;
}

EAccount *
mail_config_get_account_by_source_url (const gchar *source_url)
{
    return mc_get_account_by (source_url, get_source_url_string);
}

EAccount *
mail_config_get_account_by_transport_url (const gchar *transport_url)
{
    return mc_get_account_by (transport_url, get_transport_url_string);
}

EAccountService *
mail_config_get_default_transport (void)
{
    EAccountList *account_list;
    EAccount *account;
    EIterator *iter;

    account_list = e_get_account_list ();
    account = e_get_default_account ();

    if (account && account->enabled && account->transport && account->transport->url && account->transport->url[0])
        return account->transport;

    /* return the first account with a transport? */
    iter = e_list_get_iterator ((EList *) account_list);
    while (e_iterator_is_valid (iter)) {
        account = (EAccount *) e_iterator_get (iter);

        if (account->enabled && account->transport && account->transport->url && account->transport->url[0]) {
            g_object_unref (iter);

            return account->transport;
        }

        e_iterator_next (iter);
    }

    g_object_unref (iter);

    return NULL;
}

static gchar *
uri_to_evname (const gchar *uri, const gchar *prefix)
{
    const gchar *data_dir;
    gchar *safe;
    gchar *tmp;

    data_dir = mail_session_get_data_dir ();

    safe = g_strdup (uri);
    e_filename_make_safe (safe);
    /* blah, easiest thing to do */
    if (prefix[0] == '*')
        tmp = g_strdup_printf ("%s/%s%s.xml", data_dir, prefix + 1, safe);
    else
        tmp = g_strdup_printf ("%s/%s%s", data_dir, prefix, safe);
    g_free (safe);
    return tmp;
}

static void
mail_config_uri_renamed (GCompareFunc uri_cmp, const gchar *old, const gchar *new)
{
    EAccountList *account_list;
    EAccount *account;
    EIterator *iter;
    gint i, work = 0;
    gchar *oldname, *newname;
    const gchar *cachenames[] = {
        "config/hidestate-",
        "config/et-expanded-",
        "config/et-header-",
        "*views/current_view-",
        "*views/custom_view-",
        NULL };

    account_list = e_get_account_list ();
    iter = e_list_get_iterator ((EList *) account_list);
    while (e_iterator_is_valid (iter)) {
        account = (EAccount *) e_iterator_get (iter);

        if (account->sent_folder_uri && uri_cmp (account->sent_folder_uri, old)) {
            g_free (account->sent_folder_uri);
            account->sent_folder_uri = g_strdup (new);
            work = 1;
        }

        if (account->drafts_folder_uri && uri_cmp (account->drafts_folder_uri, old)) {
            g_free (account->drafts_folder_uri);
            account->drafts_folder_uri = g_strdup (new);
            work = 1;
        }

        e_iterator_next (iter);
    }

    g_object_unref (iter);

    /* ignore return values or if the files exist or
     * not, doesn't matter */

    for (i = 0; cachenames[i]; i++) {
        oldname = uri_to_evname (old, cachenames[i]);
        newname = uri_to_evname (new, cachenames[i]);
        /*printf ("** renaming %s to %s\n", oldname, newname);*/
        g_rename (oldname, newname);
        g_free (oldname);
        g_free (newname);
    }

    /* nasty ... */
    if (work)
        mail_config_write ();
}

static void
mail_config_uri_deleted (GCompareFunc uri_cmp, const gchar *uri)
{
    EAccountList *account_list;
    EAccount *account;
    EIterator *iter;
    gint work = 0;
    const gchar *local_drafts_folder_uri;
    const gchar *local_sent_folder_uri;

    /* assumes these can't be removed ... */
    local_drafts_folder_uri =
        e_mail_local_get_folder_uri (E_MAIL_FOLDER_DRAFTS);
    local_sent_folder_uri =
        e_mail_local_get_folder_uri (E_MAIL_FOLDER_SENT);

    account_list = e_get_account_list ();
    iter = e_list_get_iterator ((EList *) account_list);
    while (e_iterator_is_valid (iter)) {
        account = (EAccount *) e_iterator_get (iter);

        if (account->sent_folder_uri && uri_cmp (account->sent_folder_uri, uri)) {
            g_free (account->sent_folder_uri);
            account->sent_folder_uri = g_strdup (local_sent_folder_uri);
            work = 1;
        }

        if (account->drafts_folder_uri && uri_cmp (account->drafts_folder_uri, uri)) {
            g_free (account->drafts_folder_uri);
            account->drafts_folder_uri = g_strdup (local_drafts_folder_uri);
            work = 1;
        }

        e_iterator_next (iter);
    }

    /* nasty again */
    if (work)
        mail_config_write ();
}

void
mail_config_service_set_save_passwd (EAccountService *service, gboolean save_passwd)
{
    service->save_passwd = save_passwd;
}

gchar *
mail_config_folder_to_safe_url (CamelFolder *folder)
{
    gchar *url;

    url = mail_tools_folder_to_url (folder);
    e_filename_make_safe (url);

    return url;
}

gchar *
mail_config_folder_to_cachename (CamelFolder *folder, const gchar *prefix)
{
    gchar *url, *basename, *filename;
    const gchar *config_dir;

    config_dir = mail_session_get_config_dir ();
    url = mail_config_folder_to_safe_url (folder);
    basename = g_strdup_printf ("%s%s", prefix, url);
    filename = g_build_filename (config_dir, "folders", basename, NULL);
    g_free (basename);
    g_free (url);

    return filename;
}

void
mail_config_reload_junk_headers (void)
{
    /* It automatically sets in the session */
    if (config == NULL)
        mail_config_init ();
    else
        gconf_jh_check_changed (config->gconf, 0, NULL, config);

}

gboolean
mail_config_get_lookup_book (void)
{
    /* It automatically sets in the session */
    if (config == NULL)
        mail_config_init ();

    return config->book_lookup;
}

gboolean
mail_config_get_lookup_book_local_only (void)
{
    /* It automatically sets in the session */
    if (config == NULL)
        mail_config_init ();

    return config->book_lookup_local_only;
}

static void
folder_deleted_cb (MailFolderCache *cache, CamelStore *store, const gchar *uri, gpointer user_data)
{
    mail_config_uri_deleted(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->compare_folder_name, uri);
}

static void
folder_renamed_cb (MailFolderCache *cache, CamelStore *store, const gchar *olduri, const gchar *newuri, gpointer user_data)
{
    mail_config_uri_renamed(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->compare_folder_name,
                olduri, newuri);
}

/* Config struct routines */
void
mail_config_init (void)
{
    GConfClientNotifyFunc func;
    const gchar *key;

    if (config)
        return;

    config = g_new0 (MailConfig, 1);
    config->gconf = gconf_client_get_default ();
    config->gtkrc = g_build_filename (
        mail_session_get_config_dir (),
        "gtkrc-mail-fonts", NULL);

    gtk_rc_parse (config->gtkrc);

    gconf_client_add_dir (
        config->gconf, "/apps/evolution/mail/prompts",
        GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

    /* Composer Configuration */

    gconf_client_add_dir (
        config->gconf, "/apps/evolution/mail/composer",
        GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

    key = "/apps/evolution/mail/composer/spell_color";
    func = (GConfClientNotifyFunc) gconf_style_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    key = "/apps/evolution/mail/composer/outlook_filenames";
    func = (GConfClientNotifyFunc) gconf_outlook_filenames_changed;
    gconf_outlook_filenames_changed (config->gconf, 0, NULL, NULL);
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    /* Display Configuration */

    gconf_client_add_dir (
        config->gconf, "/apps/evolution/mail/display",
        GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

    key = "/apps/evolution/mail/display/address_compress";
    func = (GConfClientNotifyFunc) gconf_bool_value_changed;
    gconf_client_notify_add (
        config->gconf, key, func,
        &config->address_compress, NULL, NULL);
    config->address_compress =
        gconf_client_get_bool (config->gconf, key, NULL);

    key = "/apps/evolution/mail/display/address_count";
    func = (GConfClientNotifyFunc) gconf_int_value_changed;
    gconf_client_notify_add (
        config->gconf, key, func,
        &config->address_count, NULL, NULL);
    config->address_count =
        gconf_client_get_int (config->gconf, key, NULL);

    key = "/apps/evolution/mail/display/citation_colour";
    func = (GConfClientNotifyFunc) gconf_style_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    key = "/apps/evolution/mail/display/mark_citations";
    func = (GConfClientNotifyFunc) gconf_style_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    /* Font Configuration */

    gconf_client_add_dir (
        config->gconf, "/apps/evolution/mail/display/fonts",
        GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

    key = "/apps/evolution/mail/display/fonts";
    func = (GConfClientNotifyFunc) gconf_style_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    /* Junk Configuration */

    gconf_client_add_dir (
        config->gconf, "/apps/evolution/mail/junk",
        GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

    key = "/apps/evolution/mail/junk/check_custom_header";
    func = (GConfClientNotifyFunc) gconf_jh_check_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);
    config->jh_check =
        gconf_client_get_bool (config->gconf, key, NULL);

    key = "/apps/evolution/mail/junk/custom_header";
    func = (GConfClientNotifyFunc) gconf_jh_headers_changed;
    gconf_client_notify_add (
        config->gconf, key, func, NULL, NULL, NULL);

    key = "/apps/evolution/mail/junk/lookup_addressbook";
    func = (GConfClientNotifyFunc) gconf_bool_value_changed;
    gconf_client_notify_add (
        config->gconf, key, func,
        &config->book_lookup, NULL, NULL);
    config->book_lookup =
        gconf_client_get_bool (config->gconf, key, NULL);

    key = "/apps/evolution/mail/junk/lookup_addressbook_local_only";
    func = (GConfClientNotifyFunc) gconf_bool_value_changed;
    gconf_client_notify_add (
        config->gconf, key, func,
        &config->book_lookup_local_only, NULL, NULL);
    config->book_lookup_local_only =
        gconf_client_get_bool (config->gconf, key, NULL);

    key = "/desktop/gnome/lockdown/disable_command_line";
    func = (GConfClientNotifyFunc) gconf_bool_value_changed;
    gconf_client_notify_add (
        config->gconf, key, func,
        &config->scripts_disabled, NULL, NULL);
    config->scripts_disabled =
        gconf_client_get_bool (config->gconf, key, NULL);

    gconf_jh_check_changed (config->gconf, 0, NULL, config);

    g_signal_connect (mail_folder_cache_get_default (), "folder-deleted",
              (GCallback) folder_deleted_cb, NULL);
    g_signal_connect (mail_folder_cache_get_default (), "folder-renamed",
              (GCallback) folder_renamed_cb, NULL);
}