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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
|
/*
* 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:
* Peter Williams <peterw@ximian.com>
* Michael Zucchi <notzed@ximian.com>
* Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
* Copyright (C) 2009 Intel Corporation
*
*/
/**
* SECTION: mail-folder-cache
* @short_description: Stores information about open folders
**/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <time.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <libedataserver/libedataserver.h>
#include <libemail-engine/mail-mt.h>
#include "mail-folder-cache.h"
#include "e-mail-utils.h"
#include "e-mail-folder-utils.h"
#include "e-mail-session.h"
#include "e-mail-store-utils.h"
#define w(x)
#define d(x)
#define MAIL_FOLDER_CACHE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), MAIL_TYPE_FOLDER_CACHE, MailFolderCachePrivate))
typedef struct _StoreInfo StoreInfo;
typedef struct _FolderInfo FolderInfo;
typedef struct _UpdateClosure UpdateClosure;
struct _MailFolderCachePrivate {
GMainContext *main_context;
/* source id for the ping timeout callback */
guint ping_id;
/* Store to storeinfo table, active stores */
GHashTable *store_info_ht;
GMutex store_info_ht_lock;
/* hack for people who LIKE to have unsent count */
gint count_sent;
gint count_trash;
GQueue local_folder_uris;
GQueue remote_folder_uris;
};
enum {
PROP_0,
PROP_MAIN_CONTEXT,
};
enum {
FOLDER_AVAILABLE,
FOLDER_UNAVAILABLE,
FOLDER_DELETED,
FOLDER_RENAMED,
FOLDER_UNREAD_UPDATED,
FOLDER_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
struct _StoreInfo {
volatile gint ref_count;
GMutex lock;
CamelStore *store;
gulong folder_opened_handler_id;
gulong folder_created_handler_id;
gulong folder_deleted_handler_id;
gulong folder_renamed_handler_id;
gulong folder_subscribed_handler_id;
gulong folder_unsubscribed_handler_id;
GHashTable *folder_info_ht; /* by full_name */
gboolean first_update; /* TRUE, then FALSE forever */
/* Hold a reference to keep them alive. */
CamelFolder *vjunk;
CamelFolder *vtrash;
/* Outstanding folderinfo requests */
GQueue folderinfo_updates;
};
struct _FolderInfo {
volatile gint ref_count;
GMutex lock;
CamelStore *store;
gchar *full_name;
CamelFolderInfoFlags flags;
GWeakRef folder;
gulong folder_changed_handler_id;
};
struct _UpdateClosure {
GWeakRef cache;
CamelStore *store;
/* Signal ID for one of:
* AVAILABLE, DELETED, RENAMED, UNAVAILABLE */
guint signal_id;
gboolean new_messages;
gchar *full_name;
gchar *oldfull;
gint unread;
/* for only one new message... */
gchar *msg_uid;
gchar *msg_sender;
gchar *msg_subject;
};
struct _update_data {
NoteDoneFunc done;
gpointer data;
MailFolderCache *cache;
GCancellable *cancellable;
};
/* Forward Declarations */
static void store_folder_created_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache);
static void store_folder_deleted_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache);
static void store_folder_opened_cb (CamelStore *store,
CamelFolder *folder,
MailFolderCache *cache);
static void store_folder_renamed_cb (CamelStore *store,
const gchar *old_name,
CamelFolderInfo *info,
MailFolderCache *cache);
static void store_folder_subscribed_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache);
static void store_folder_unsubscribed_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache);
G_DEFINE_TYPE (MailFolderCache, mail_folder_cache, G_TYPE_OBJECT)
static FolderInfo *
folder_info_new (CamelStore *store,
const gchar *full_name,
CamelFolderInfoFlags flags)
{
FolderInfo *folder_info;
folder_info = g_slice_new0 (FolderInfo);
folder_info->ref_count = 1;
folder_info->store = g_object_ref (store);
folder_info->full_name = g_strdup (full_name);
folder_info->flags = flags;
g_mutex_init (&folder_info->lock);
return folder_info;
}
static FolderInfo *
folder_info_ref (FolderInfo *folder_info)
{
g_return_val_if_fail (folder_info != NULL, NULL);
g_return_val_if_fail (folder_info->ref_count > 0, NULL);
g_atomic_int_inc (&folder_info->ref_count);
return folder_info;
}
static void
folder_info_clear_folder (FolderInfo *folder_info)
{
CamelFolder *folder;
g_return_if_fail (folder_info != NULL);
g_mutex_lock (&folder_info->lock);
folder = g_weak_ref_get (&folder_info->folder);
if (folder != NULL) {
g_signal_handler_disconnect (
folder,
folder_info->folder_changed_handler_id);
g_weak_ref_set (&folder_info->folder, NULL);
folder_info->folder_changed_handler_id = 0;
g_object_unref (folder);
}
g_mutex_unlock (&folder_info->lock);
}
static void
folder_info_unref (FolderInfo *folder_info)
{
g_return_if_fail (folder_info != NULL);
g_return_if_fail (folder_info->ref_count > 0);
if (g_atomic_int_dec_and_test (&folder_info->ref_count)) {
folder_info_clear_folder (folder_info);
g_clear_object (&folder_info->store);
g_free (folder_info->full_name);
g_mutex_clear (&folder_info->lock);
g_slice_free (FolderInfo, folder_info);
}
}
static StoreInfo *
store_info_new (CamelStore *store)
{
StoreInfo *store_info;
store_info = g_slice_new0 (StoreInfo);
store_info->ref_count = 1;
store_info->store = g_object_ref (store);
store_info->first_update = TRUE;
store_info->folder_info_ht = g_hash_table_new_full (
(GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) NULL,
(GDestroyNotify) folder_info_unref);
g_mutex_init (&store_info->lock);
/* If these are vfolders then they need to be opened
* now, otherwise they won't keep track of all folders. */
if (store->flags & CAMEL_STORE_VJUNK)
store_info->vjunk = camel_store_get_junk_folder_sync (
store, NULL, NULL);
if (store->flags & CAMEL_STORE_VTRASH)
store_info->vtrash = camel_store_get_trash_folder_sync (
store, NULL, NULL);
return store_info;
}
static StoreInfo *
store_info_ref (StoreInfo *store_info)
{
g_return_val_if_fail (store_info != NULL, NULL);
g_return_val_if_fail (store_info->ref_count > 0, NULL);
g_atomic_int_inc (&store_info->ref_count);
return store_info;
}
static void
store_info_unref (StoreInfo *store_info)
{
g_return_if_fail (store_info != NULL);
g_return_if_fail (store_info->ref_count > 0);
if (g_atomic_int_dec_and_test (&store_info->ref_count)) {
struct _update_data *ud;
while (!g_queue_is_empty (&store_info->folderinfo_updates)) {
ud = g_queue_pop_head (&store_info->folderinfo_updates);
g_cancellable_cancel (ud->cancellable);
}
if (store_info->folder_opened_handler_id > 0) {
g_signal_handler_disconnect (
store_info->store,
store_info->folder_opened_handler_id);
}
if (store_info->folder_created_handler_id > 0) {
g_signal_handler_disconnect (
store_info->store,
store_info->folder_created_handler_id);
}
if (store_info->folder_deleted_handler_id > 0) {
g_signal_handler_disconnect (
store_info->store,
store_info->folder_deleted_handler_id);
}
if (store_info->folder_subscribed_handler_id > 0) {
g_signal_handler_disconnect (
store_info->store,
store_info->folder_subscribed_handler_id);
}
if (store_info->folder_unsubscribed_handler_id > 0) {
g_signal_handler_disconnect (
store_info->store,
store_info->folder_unsubscribed_handler_id);
}
g_hash_table_destroy (store_info->folder_info_ht);
g_clear_object (&store_info->store);
g_clear_object (&store_info->vjunk);
g_clear_object (&store_info->vtrash);
g_mutex_clear (&store_info->lock);
g_slice_free (StoreInfo, store_info);
}
}
static FolderInfo *
store_info_ref_folder_info (StoreInfo *store_info,
const gchar *folder_name)
{
GHashTable *folder_info_ht;
FolderInfo *folder_info;
g_return_val_if_fail (store_info != NULL, NULL);
g_return_val_if_fail (folder_name != NULL, NULL);
g_mutex_lock (&store_info->lock);
folder_info_ht = store_info->folder_info_ht;
folder_info = g_hash_table_lookup (folder_info_ht, folder_name);
if (folder_info != NULL)
folder_info_ref (folder_info);
g_mutex_unlock (&store_info->lock);
return folder_info;
}
static void
store_info_insert_folder_info (StoreInfo *store_info,
FolderInfo *folder_info)
{
GHashTable *folder_info_ht;
g_return_if_fail (store_info != NULL);
g_return_if_fail (folder_info != NULL);
g_return_if_fail (folder_info->full_name != NULL);
g_mutex_lock (&store_info->lock);
folder_info_ht = store_info->folder_info_ht;
g_hash_table_insert (
folder_info_ht,
folder_info->full_name,
folder_info_ref (folder_info));
g_mutex_unlock (&store_info->lock);
}
static GList *
store_info_list_folder_info (StoreInfo *store_info)
{
GList *list;
g_return_val_if_fail (store_info != NULL, NULL);
g_mutex_lock (&store_info->lock);
list = g_hash_table_get_values (store_info->folder_info_ht);
g_list_foreach (list, (GFunc) folder_info_ref, NULL);
g_mutex_unlock (&store_info->lock);
return list;
}
static FolderInfo *
store_info_steal_folder_info (StoreInfo *store_info,
const gchar *folder_name)
{
GHashTable *folder_info_ht;
FolderInfo *folder_info;
g_return_val_if_fail (store_info != NULL, NULL);
g_return_val_if_fail (folder_name != NULL, NULL);
g_mutex_lock (&store_info->lock);
folder_info_ht = store_info->folder_info_ht;
folder_info = g_hash_table_lookup (folder_info_ht, folder_name);
if (folder_info != NULL) {
folder_info_ref (folder_info);
g_hash_table_remove (folder_info_ht, folder_name);
}
g_mutex_unlock (&store_info->lock);
return folder_info;
}
static UpdateClosure *
update_closure_new (MailFolderCache *cache,
CamelStore *store)
{
UpdateClosure *closure;
closure = g_slice_new0 (UpdateClosure);
g_weak_ref_set (&closure->cache, cache);
closure->store = g_object_ref (store);
return closure;
}
static void
update_closure_free (UpdateClosure *closure)
{
g_weak_ref_set (&closure->cache, NULL);
g_clear_object (&closure->store);
g_free (closure->full_name);
g_free (closure->oldfull);
g_free (closure->msg_uid);
g_free (closure->msg_sender);
g_free (closure->msg_subject);
g_slice_free (UpdateClosure, closure);
}
static StoreInfo *
mail_folder_cache_new_store_info (MailFolderCache *cache,
CamelStore *store)
{
StoreInfo *store_info;
gulong handler_id;
g_return_val_if_fail (store != NULL, NULL);
store_info = store_info_new (store);
handler_id = g_signal_connect (
store, "folder-opened",
G_CALLBACK (store_folder_opened_cb), cache);
store_info->folder_opened_handler_id = handler_id;
handler_id = g_signal_connect (
store, "folder-created",
G_CALLBACK (store_folder_created_cb), cache);
store_info->folder_created_handler_id = handler_id;
handler_id = g_signal_connect (
store, "folder-deleted",
G_CALLBACK (store_folder_deleted_cb), cache);
store_info->folder_deleted_handler_id = handler_id;
handler_id = g_signal_connect (
store, "folder-renamed",
G_CALLBACK (store_folder_renamed_cb), cache);
store_info->folder_renamed_handler_id = handler_id;
if (CAMEL_IS_SUBSCRIBABLE (store)) {
handler_id = g_signal_connect (
store, "folder-subscribed",
G_CALLBACK (store_folder_subscribed_cb), cache);
store_info->folder_subscribed_handler_id = handler_id;
handler_id = g_signal_connect (
store, "folder-unsubscribed",
G_CALLBACK (store_folder_unsubscribed_cb), cache);
store_info->folder_unsubscribed_handler_id = handler_id;
}
g_mutex_lock (&cache->priv->store_info_ht_lock);
g_hash_table_insert (
cache->priv->store_info_ht,
g_object_ref (store),
store_info_ref (store_info));
g_mutex_unlock (&cache->priv->store_info_ht_lock);
return store_info;
}
static StoreInfo *
mail_folder_cache_ref_store_info (MailFolderCache *cache,
CamelStore *store)
{
GHashTable *store_info_ht;
StoreInfo *store_info;
g_return_val_if_fail (store != NULL, NULL);
g_mutex_lock (&cache->priv->store_info_ht_lock);
store_info_ht = cache->priv->store_info_ht;
store_info = g_hash_table_lookup (store_info_ht, store);
if (store_info != NULL)
store_info_ref (store_info);
g_mutex_unlock (&cache->priv->store_info_ht_lock);
return store_info;
}
static GList *
mail_folder_cache_list_stores (MailFolderCache *cache)
{
GHashTable *store_info_ht;
GList *list;
g_mutex_lock (&cache->priv->store_info_ht_lock);
store_info_ht = cache->priv->store_info_ht;
list = g_hash_table_get_keys (store_info_ht);
g_list_foreach (list, (GFunc) g_object_ref, NULL);
g_mutex_unlock (&cache->priv->store_info_ht_lock);
return list;
}
static StoreInfo *
mail_folder_cache_steal_store_info (MailFolderCache *cache,
CamelStore *store)
{
GHashTable *store_info_ht;
StoreInfo *store_info;
g_return_val_if_fail (store != NULL, NULL);
g_mutex_lock (&cache->priv->store_info_ht_lock);
store_info_ht = cache->priv->store_info_ht;
store_info = g_hash_table_lookup (store_info_ht, store);
if (store_info != NULL) {
store_info_ref (store_info);
g_hash_table_remove (store_info_ht, store);
}
g_mutex_unlock (&cache->priv->store_info_ht_lock);
return store_info;
}
static FolderInfo *
mail_folder_cache_ref_folder_info (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
StoreInfo *store_info;
FolderInfo *folder_info = NULL;
store_info = mail_folder_cache_ref_store_info (cache, store);
if (store_info != NULL) {
folder_info = store_info_ref_folder_info (
store_info, folder_name);
store_info_unref (store_info);
}
return folder_info;
}
static FolderInfo *
mail_folder_cache_steal_folder_info (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
StoreInfo *store_info;
FolderInfo *folder_info = NULL;
store_info = mail_folder_cache_ref_store_info (cache, store);
if (store_info != NULL) {
folder_info = store_info_steal_folder_info (
store_info, folder_name);
store_info_unref (store_info);
}
return folder_info;
}
static gboolean
mail_folder_cache_update_idle_cb (gpointer user_data)
{
MailFolderCache *cache;
UpdateClosure *closure;
closure = (UpdateClosure *) user_data;
/* Sanity checks. */
g_return_val_if_fail (closure->full_name != NULL, FALSE);
cache = g_weak_ref_get (&closure->cache);
if (cache != NULL) {
if (closure->signal_id == signals[FOLDER_DELETED]) {
g_signal_emit (
cache,
closure->signal_id, 0,
closure->store,
closure->full_name);
}
if (closure->signal_id == signals[FOLDER_UNAVAILABLE]) {
g_signal_emit (
cache,
closure->signal_id, 0,
closure->store,
closure->full_name);
}
if (closure->signal_id == signals[FOLDER_AVAILABLE]) {
g_signal_emit (
cache,
closure->signal_id, 0,
closure->store,
closure->full_name);
}
if (closure->signal_id == signals[FOLDER_RENAMED]) {
g_signal_emit (
cache,
closure->signal_id, 0,
closure->store,
closure->oldfull,
closure->full_name);
}
/* update unread counts */
g_signal_emit (
cache,
signals[FOLDER_UNREAD_UPDATED], 0,
closure->store,
closure->full_name,
closure->unread);
/* XXX The old code excluded this on FOLDER_RENAMED.
* Not sure if that was intentional (if so it was
* very subtle!) but we'll preserve the behavior.
* If it turns out to be a bug then just remove
* the signal_id check. */
if (closure->signal_id != signals[FOLDER_RENAMED]) {
g_signal_emit (
cache,
signals[FOLDER_CHANGED], 0,
closure->store,
closure->full_name,
closure->new_messages,
closure->msg_uid,
closure->msg_sender,
closure->msg_subject);
}
if (CAMEL_IS_VEE_STORE (closure->store) &&
(closure->signal_id == signals[FOLDER_AVAILABLE] ||
closure->signal_id == signals[FOLDER_RENAMED])) {
/* Normally the vfolder store takes care of the
* folder_opened event itself, but we add folder to
* the noting system later, thus we do not know about
* search folders to update them in a tree, thus
* ensure their changes will be tracked correctly. */
CamelFolder *folder;
/* FIXME camel_store_get_folder_sync() may block. */
folder = camel_store_get_folder_sync (
closure->store,
closure->full_name,
0, NULL, NULL);
if (folder != NULL) {
mail_folder_cache_note_folder (cache, folder);
g_object_unref (folder);
}
}
g_object_unref (cache);
}
return FALSE;
}
static void
mail_folder_cache_submit_update (UpdateClosure *closure)
{
GMainContext *main_context;
MailFolderCache *cache;
GSource *idle_source;
g_return_if_fail (closure != NULL);
cache = g_weak_ref_get (&closure->cache);
g_return_if_fail (cache != NULL);
main_context = mail_folder_cache_ref_main_context (cache);
idle_source = g_idle_source_new ();
g_source_set_callback (
idle_source,
mail_folder_cache_update_idle_cb,
closure,
(GDestroyNotify) update_closure_free);
g_source_attach (idle_source, main_context);
g_source_unref (idle_source);
g_main_context_unref (main_context);
g_object_unref (cache);
}
/* This is how unread counts work (and don't work):
*
* camel_folder_unread_message_count() only gives a correct answer if
* the store is paying attention to the folder. (Some stores always
* pay attention to all folders, but IMAP can only pay attention to
* one folder at a time.) But it doesn't have any way to know when
* it's lying, so it's only safe to call it when you know for sure
* that the store is paying attention to the folder, such as when it's
* just been created, or you get a folder_changed signal on it.
*
* camel_store_get_folder_info() always gives correct answers for the
* folders it checks, but it can also return -1 for a folder, meaning
* it didn't check, and so you should stick with your previous answer.
*
* update_1folder is called from three places: with info != NULL when
* the folder is created (or get_folder_info), with info == NULL when
* a folder changed event is emitted.
*
* So if info is NULL, camel_folder_unread_message_count is correct,
* and if it's not NULL and its unread_message_count isn't -1, then
* it's correct. */
static void
update_1folder (MailFolderCache *cache,
FolderInfo *folder_info,
gint new_messages,
const gchar *msg_uid,
const gchar *msg_sender,
const gchar *msg_subject,
CamelFolderInfo *info)
{
ESourceRegistry *registry;
CamelService *service;
CamelSession *session;
CamelFolder *folder;
gint unread = -1;
gint deleted;
/* XXX This is a dirty way to obtain the ESourceRegistry,
* but it avoids MailFolderCache requiring it up front
* in mail_folder_cache_new(), which just complicates
* application startup even more. */
service = CAMEL_SERVICE (folder_info->store);
session = camel_service_get_session (service);
registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
folder = g_weak_ref_get (&folder_info->folder);
if (folder != NULL) {
gboolean folder_is_sent;
gboolean folder_is_drafts;
gboolean folder_is_outbox;
gboolean folder_is_vtrash;
gboolean special_case;
folder_is_sent = em_utils_folder_is_sent (registry, folder);
folder_is_drafts = em_utils_folder_is_drafts (registry, folder);
folder_is_outbox = em_utils_folder_is_outbox (registry, folder);
folder_is_vtrash = CAMEL_IS_VTRASH_FOLDER (folder);
special_case =
(cache->priv->count_trash && folder_is_vtrash) ||
(cache->priv->count_sent && folder_is_sent) ||
folder_is_drafts || folder_is_outbox;
if (special_case) {
d (printf (" total count\n"));
unread = camel_folder_get_message_count (folder);
if (folder_is_drafts || folder_is_outbox) {
guint32 junked = 0;
deleted = camel_folder_get_deleted_message_count (folder);
if (deleted > 0)
unread -= deleted;
junked = camel_folder_summary_get_junk_count (folder->summary);
if (junked > 0)
unread -= junked;
}
} else {
d (printf (" unread count\n"));
if (info)
unread = info->unread;
else
unread = camel_folder_get_unread_message_count (folder);
}
g_object_unref (folder);
}
d (printf (
"folder updated: unread %d: '%s'\n",
unread, folder_info->full_name));
if (unread >= 0) {
UpdateClosure *up;
up = update_closure_new (cache, folder_info->store);
up->full_name = g_strdup (folder_info->full_name);
up->unread = unread;
up->new_messages = new_messages;
up->msg_uid = g_strdup (msg_uid);
up->msg_sender = g_strdup (msg_sender);
up->msg_subject = g_strdup (msg_subject);
mail_folder_cache_submit_update (up);
}
}
static void
folder_changed_cb (CamelFolder *folder,
CamelFolderChangeInfo *changes,
MailFolderCache *cache)
{
static GHashTable *last_newmail_per_folder = NULL;
time_t latest_received, new_latest_received;
CamelFolder *local_drafts;
CamelFolder *local_outbox;
CamelFolder *local_sent;
CamelSession *session;
CamelStore *parent_store;
CamelMessageInfo *info;
FolderInfo *folder_info;
const gchar *full_name;
gint new = 0;
gint i;
guint32 flags;
gchar *uid = NULL, *sender = NULL, *subject = NULL;
full_name = camel_folder_get_full_name (folder);
parent_store = camel_folder_get_parent_store (folder);
session = camel_service_ref_session (CAMEL_SERVICE (parent_store));
if (!last_newmail_per_folder)
last_newmail_per_folder = g_hash_table_new (g_direct_hash, g_direct_equal);
/* it's fine to hash them by folder pointer here */
latest_received = GPOINTER_TO_INT (
g_hash_table_lookup (last_newmail_per_folder, folder));
new_latest_received = latest_received;
local_drafts = e_mail_session_get_local_folder (
E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS);
local_outbox = e_mail_session_get_local_folder (
E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_OUTBOX);
local_sent = e_mail_session_get_local_folder (
E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_SENT);
if (!CAMEL_IS_VEE_FOLDER (folder)
&& folder != local_drafts
&& folder != local_outbox
&& folder != local_sent
&& changes && (changes->uid_added->len > 0)) {
/* for each added message, check to see that it is
* brand new, not junk and not already deleted */
for (i = 0; i < changes->uid_added->len; i++) {
info = camel_folder_get_message_info (
folder, changes->uid_added->pdata[i]);
if (info) {
flags = camel_message_info_flags (info);
if (((flags & CAMEL_MESSAGE_SEEN) == 0) &&
((flags & CAMEL_MESSAGE_JUNK) == 0) &&
((flags & CAMEL_MESSAGE_DELETED) == 0) &&
(camel_message_info_date_received (info) > latest_received)) {
if (camel_message_info_date_received (info) > new_latest_received)
new_latest_received = camel_message_info_date_received (info);
new++;
if (new == 1) {
uid = g_strdup (camel_message_info_uid (info));
sender = g_strdup (camel_message_info_from (info));
subject = g_strdup (camel_message_info_subject (info));
} else {
g_free (uid);
g_free (sender);
g_free (subject);
uid = NULL;
sender = NULL;
subject = NULL;
}
}
camel_folder_free_message_info (folder, info);
}
}
}
if (new > 0)
g_hash_table_insert (
last_newmail_per_folder, folder,
GINT_TO_POINTER (new_latest_received));
folder_info = mail_folder_cache_ref_folder_info (
cache, parent_store, full_name);
if (folder_info != NULL) {
update_1folder (
cache, folder_info, new,
uid, sender, subject, NULL);
folder_info_unref (folder_info);
}
g_free (uid);
g_free (sender);
g_free (subject);
g_object_unref (session);
}
static void
unset_folder_info (MailFolderCache *cache,
FolderInfo *folder_info,
gint delete)
{
d (printf ("unset folderinfo '%s'\n", folder_info->uri));
folder_info_clear_folder (folder_info);
if ((folder_info->flags & CAMEL_FOLDER_NOSELECT) == 0) {
UpdateClosure *up;
up = update_closure_new (cache, folder_info->store);
up->full_name = g_strdup (folder_info->full_name);
if (delete)
up->signal_id = signals[FOLDER_DELETED];
else
up->signal_id = signals[FOLDER_UNAVAILABLE];
mail_folder_cache_submit_update (up);
}
}
static void
setup_folder (MailFolderCache *cache,
CamelFolderInfo *fi,
StoreInfo *store_info)
{
FolderInfo *folder_info;
folder_info = store_info_ref_folder_info (store_info, fi->full_name);
if (folder_info != NULL) {
update_1folder (cache, folder_info, 0, NULL, NULL, NULL, fi);
folder_info_unref (folder_info);
} else {
UpdateClosure *up;
folder_info = folder_info_new (
store_info->store,
fi->full_name,
fi->flags);
store_info_insert_folder_info (store_info, folder_info);
up = update_closure_new (cache, store_info->store);
up->full_name = g_strdup (fi->full_name);
up->unread = fi->unread;
if ((fi->flags & CAMEL_FOLDER_NOSELECT) == 0)
up->signal_id = signals[FOLDER_AVAILABLE];
mail_folder_cache_submit_update (up);
folder_info_unref (folder_info);
}
}
static void
create_folders (MailFolderCache *cache,
CamelFolderInfo *fi,
StoreInfo *store_info)
{
while (fi) {
setup_folder (cache, fi, store_info);
if (fi->child)
create_folders (cache, fi->child, store_info);
fi = fi->next;
}
}
static void
store_folder_subscribed_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache)
{
StoreInfo *store_info;
store_info = mail_folder_cache_ref_store_info (cache, store);
if (store_info != NULL) {
setup_folder (cache, info, store_info);
store_info_unref (store_info);
}
}
static void
store_folder_created_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache)
{
/* We only want created events to do more work
* if we dont support subscriptions. */
if (!CAMEL_IS_SUBSCRIBABLE (store))
store_folder_subscribed_cb (store, info, cache);
}
static void
store_folder_opened_cb (CamelStore *store,
CamelFolder *folder,
MailFolderCache *cache)
{
mail_folder_cache_note_folder (cache, folder);
}
static void
store_folder_unsubscribed_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache)
{
FolderInfo *folder_info;
folder_info = mail_folder_cache_steal_folder_info (
cache, store, info->full_name);
if (folder_info != NULL) {
unset_folder_info (cache, folder_info, TRUE);
folder_info_unref (folder_info);
}
}
static void
store_folder_deleted_cb (CamelStore *store,
CamelFolderInfo *info,
MailFolderCache *cache)
{
/* We only want deleted events to do more work
* if we dont support subscriptions. */
if (!CAMEL_IS_SUBSCRIBABLE (store))
store_folder_unsubscribed_cb (store, info, cache);
}
static void
rename_folders (MailFolderCache *cache,
StoreInfo *store_info,
const gchar *oldbase,
const gchar *newbase,
CamelFolderInfo *fi)
{
gchar *old, *olduri, *oldfile, *newuri, *newfile;
FolderInfo *old_folder_info;
FolderInfo *new_folder_info;
UpdateClosure *up;
const gchar *config_dir;
up = update_closure_new (cache, store_info->store);
up->signal_id = signals[FOLDER_AVAILABLE];
/* Form what was the old name, and try and look it up */
old = g_strdup_printf ("%s%s", oldbase, fi->full_name + strlen (newbase));
old_folder_info = store_info_steal_folder_info (store_info, old);
if (old_folder_info != NULL) {
up->oldfull = g_strdup (old_folder_info->full_name);
up->signal_id = signals[FOLDER_RENAMED];
folder_info_unref (old_folder_info);
}
new_folder_info = folder_info_new (
store_info->store,
fi->full_name,
fi->flags);
store_info_insert_folder_info (store_info, new_folder_info);
folder_info_unref (new_folder_info);
up->full_name = g_strdup (fi->full_name);
up->unread = fi->unread==-1 ? 0 : fi->unread;
/* No signal emission for NOSELECT folders. */
if ((fi->flags & CAMEL_FOLDER_NOSELECT) != 0)
up->signal_id = 0;
mail_folder_cache_submit_update (up);
/* rename the meta-data we maintain ourselves */
config_dir = mail_session_get_config_dir ();
olduri = e_mail_folder_uri_build (store_info->store, old);
e_filename_make_safe (olduri);
newuri = e_mail_folder_uri_build (store_info->store, fi->full_name);
e_filename_make_safe (newuri);
oldfile = g_strdup_printf ("%s/custom_view-%s.xml", config_dir, olduri);
newfile = g_strdup_printf ("%s/custom_view-%s.xml", config_dir, newuri);
g_rename (oldfile, newfile);
g_free (oldfile);
g_free (newfile);
oldfile = g_strdup_printf ("%s/current_view-%s.xml", config_dir, olduri);
newfile = g_strdup_printf ("%s/current_view-%s.xml", config_dir, newuri);
g_rename (oldfile, newfile);
g_free (oldfile);
g_free (newfile);
g_free (olduri);
g_free (newuri);
g_free (old);
}
static void
get_folders (CamelFolderInfo *fi,
GPtrArray *folders)
{
while (fi) {
g_ptr_array_add (folders, fi);
if (fi->child)
get_folders (fi->child, folders);
fi = fi->next;
}
}
static gint
folder_cmp (gconstpointer ap,
gconstpointer bp)
{
const CamelFolderInfo *a = ((CamelFolderInfo **) ap)[0];
const CamelFolderInfo *b = ((CamelFolderInfo **) bp)[0];
return strcmp (a->full_name, b->full_name);
}
static void
store_folder_renamed_cb (CamelStore *store,
const gchar *old_name,
CamelFolderInfo *info,
MailFolderCache *cache)
{
StoreInfo *store_info;
store_info = mail_folder_cache_ref_store_info (cache, store);
if (store_info != NULL) {
GPtrArray *folders = g_ptr_array_new ();
CamelFolderInfo *top;
gint ii;
/* Ok, so for some reason the folderinfo we have comes in all
* messed up from imap, should find out why ... this makes it
* workable.
* XXX This refers to the old IMAP backend, not IMAPX, and so
* this may not be needed anymore. */
get_folders (info, folders);
g_ptr_array_sort (folders, (GCompareFunc) folder_cmp);
top = folders->pdata[0];
for (ii = 0; ii < folders->len; ii++) {
rename_folders (
cache, store_info, old_name,
top->full_name, folders->pdata[ii]);
}
g_ptr_array_free (folders, TRUE);
store_info_unref (store_info);
}
}
static void
mail_folder_cache_first_update (MailFolderCache *cache,
StoreInfo *store_info)
{
CamelService *service;
CamelSession *session;
const gchar *uid;
service = CAMEL_SERVICE (store_info->store);
session = camel_service_ref_session (service);
uid = camel_service_get_uid (service);
if (store_info->vjunk != NULL)
mail_folder_cache_note_folder (cache, store_info->vjunk);
if (store_info->vtrash != NULL)
mail_folder_cache_note_folder (cache, store_info->vtrash);
/* Some extra work for the "On This Computer" store. */
if (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0) {
CamelFolder *folder;
gint ii;
for (ii = 0; ii < E_MAIL_NUM_LOCAL_FOLDERS; ii++) {
folder = e_mail_session_get_local_folder (
E_MAIL_SESSION (session), ii);
mail_folder_cache_note_folder (cache, folder);
}
}
g_object_unref (session);
}
static void
update_folders (CamelStore *store,
GAsyncResult *result,
struct _update_data *ud)
{
CamelFolderInfo *fi;
StoreInfo *store_info;
GError *error = NULL;
gboolean free_fi = TRUE;
fi = camel_store_get_folder_info_finish (store, result, &error);
/* Silently ignore cancellation errors. */
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free (error);
} else if (error != NULL) {
g_warning ("%s", error->message);
g_error_free (error);
}
store_info = mail_folder_cache_ref_store_info (ud->cache, store);
if (store_info != NULL) {
/* The store info is still there, so we can remove ourselves
* from its list. Or else its not, and we're on our own and
* free anyway. */
g_mutex_lock (&store_info->lock);
g_queue_remove (&store_info->folderinfo_updates, ud);
g_mutex_unlock (&store_info->lock);
if (fi != NULL && !g_cancellable_is_cancelled (ud->cancellable))
create_folders (ud->cache, fi, store_info);
/* Do some extra work for the first update. */
if (store_info->first_update) {
mail_folder_cache_first_update (ud->cache, store_info);
store_info->first_update = FALSE;
}
store_info_unref (store_info);
}
if (ud->done != NULL)
free_fi = ud->done (ud->cache, store, fi, ud->data);
if (fi && free_fi)
camel_store_free_folder_info (store, fi);
if (ud->cancellable != NULL)
g_object_unref (ud->cancellable);
g_free (ud);
}
struct _ping_store_msg {
MailMsg base;
CamelStore *store;
};
static gchar *
ping_store_desc (struct _ping_store_msg *m)
{
gchar *service_name;
gchar *msg;
service_name = camel_service_get_name (CAMEL_SERVICE (m->store), TRUE);
msg = g_strdup_printf (_("Pinging %s"), service_name);
g_free (service_name);
return msg;
}
static void
ping_store_exec (struct _ping_store_msg *m,
GCancellable *cancellable,
GError **error)
{
CamelServiceConnectionStatus status;
CamelService *service;
gboolean online = FALSE;
service = CAMEL_SERVICE (m->store);
status = camel_service_get_connection_status (service);
if (status == CAMEL_SERVICE_CONNECTED) {
if (CAMEL_IS_DISCO_STORE (m->store) &&
camel_disco_store_status (
CAMEL_DISCO_STORE (m->store)) !=CAMEL_DISCO_STORE_OFFLINE)
online = TRUE;
else if (CAMEL_IS_OFFLINE_STORE (m->store) &&
camel_offline_store_get_online (
CAMEL_OFFLINE_STORE (m->store)))
online = TRUE;
}
if (online)
camel_store_noop_sync (m->store, cancellable, error);
}
static void
ping_store_free (struct _ping_store_msg *m)
{
g_object_unref (m->store);
}
static MailMsgInfo ping_store_info = {
sizeof (struct _ping_store_msg),
(MailMsgDescFunc) ping_store_desc,
(MailMsgExecFunc) ping_store_exec,
(MailMsgDoneFunc) NULL,
(MailMsgFreeFunc) ping_store_free
};
static gboolean
ping_cb (MailFolderCache *cache)
{
GList *list, *link;
list = mail_folder_cache_list_stores (cache);
for (link = list; link != NULL; link = g_list_next (link)) {
CamelService *service;
CamelServiceConnectionStatus status;
struct _ping_store_msg *m;
service = CAMEL_SERVICE (link->data);
status = camel_service_get_connection_status (service);
if (status != CAMEL_SERVICE_CONNECTED)
continue;
m = mail_msg_new (&ping_store_info);
m->store = g_object_ref (service);
mail_msg_slow_ordered_push (m);
}
g_list_free_full (list, (GDestroyNotify) g_object_unref);
return TRUE;
}
static gboolean
store_has_folder_hierarchy (CamelStore *store)
{
CamelProvider *provider;
g_return_val_if_fail (store != NULL, FALSE);
provider = camel_service_get_provider (CAMEL_SERVICE (store));
g_return_val_if_fail (provider != NULL, FALSE);
if (provider->flags & CAMEL_PROVIDER_IS_STORAGE)
return TRUE;
if (provider->flags & CAMEL_PROVIDER_IS_EXTERNAL)
return TRUE;
return FALSE;
}
static void
store_go_online_cb (CamelStore *store,
GAsyncResult *result,
struct _update_data *ud)
{
StoreInfo *store_info;
/* FIXME Not checking the GAsyncResult for error. */
store_info = mail_folder_cache_ref_store_info (ud->cache, store);
if (store_info != NULL &&
!g_cancellable_is_cancelled (ud->cancellable)) {
/* We're already in the store update list. */
if (store_has_folder_hierarchy (store))
camel_store_get_folder_info (
store, NULL,
CAMEL_STORE_FOLDER_INFO_FAST |
CAMEL_STORE_FOLDER_INFO_RECURSIVE |
CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
G_PRIORITY_DEFAULT, ud->cancellable,
(GAsyncReadyCallback) update_folders, ud);
} else {
if (store_info != NULL) {
g_mutex_lock (&store_info->lock);
g_queue_remove (&store_info->folderinfo_updates, ud);
g_mutex_unlock (&store_info->lock);
}
/* The store vanished, that means we were probably cancelled,
* or at any rate, need to clean ourselves up. */
if (ud->cancellable != NULL)
g_object_unref (ud->cancellable);
g_free (ud);
}
if (store_info != NULL)
store_info_unref (store_info);
}
static GList *
find_folder_uri (GQueue *queue,
CamelSession *session,
const gchar *folder_uri)
{
GList *head, *link;
head = g_queue_peek_head_link (queue);
for (link = head; link != NULL; link = g_list_next (link))
if (e_mail_folder_uri_equal (session, link->data, folder_uri))
break;
return link;
}
static void
mail_folder_cache_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_MAIN_CONTEXT:
g_value_take_boxed (
value,
mail_folder_cache_ref_main_context (
MAIL_FOLDER_CACHE (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_folder_cache_dispose (GObject *object)
{
MailFolderCachePrivate *priv;
priv = MAIL_FOLDER_CACHE_GET_PRIVATE (object);
g_hash_table_remove_all (priv->store_info_ht);
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (mail_folder_cache_parent_class)->dispose (object);
}
static void
mail_folder_cache_finalize (GObject *object)
{
MailFolderCachePrivate *priv;
priv = MAIL_FOLDER_CACHE_GET_PRIVATE (object);
g_main_context_unref (priv->main_context);
g_hash_table_destroy (priv->store_info_ht);
g_mutex_clear (&priv->store_info_ht_lock);
if (priv->ping_id > 0) {
g_source_remove (priv->ping_id);
priv->ping_id = 0;
}
while (!g_queue_is_empty (&priv->local_folder_uris))
g_free (g_queue_pop_head (&priv->local_folder_uris));
while (!g_queue_is_empty (&priv->remote_folder_uris))
g_free (g_queue_pop_head (&priv->remote_folder_uris));
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (mail_folder_cache_parent_class)->finalize (object);
}
static void
mail_folder_cache_folder_available (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
CamelService *service;
CamelSession *session;
CamelProvider *provider;
GQueue *queue;
gchar *folder_uri;
/* Disregard virtual stores. */
if (CAMEL_IS_VEE_STORE (store))
return;
/* Disregard virtual Junk folders. */
if (store->flags & CAMEL_STORE_VJUNK)
if (g_strcmp0 (folder_name, CAMEL_VJUNK_NAME) == 0)
return;
/* Disregard virtual Trash folders. */
if (store->flags & CAMEL_STORE_VTRASH)
if (g_strcmp0 (folder_name, CAMEL_VTRASH_NAME) == 0)
return;
service = CAMEL_SERVICE (store);
session = camel_service_ref_session (service);
provider = camel_service_get_provider (service);
/* Reuse the store info lock just because it's handy. */
g_mutex_lock (&cache->priv->store_info_ht_lock);
folder_uri = e_mail_folder_uri_build (store, folder_name);
if (provider->flags & CAMEL_PROVIDER_IS_REMOTE)
queue = &cache->priv->remote_folder_uris;
else
queue = &cache->priv->local_folder_uris;
if (find_folder_uri (queue, session, folder_uri) == NULL)
g_queue_push_tail (queue, folder_uri);
else
g_free (folder_uri);
g_mutex_unlock (&cache->priv->store_info_ht_lock);
g_object_unref (session);
}
static void
mail_folder_cache_folder_unavailable (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
CamelService *service;
CamelSession *session;
CamelProvider *provider;
GQueue *queue;
GList *link;
gchar *folder_uri;
/* Disregard virtual stores. */
if (CAMEL_IS_VEE_STORE (store))
return;
/* Disregard virtual Junk folders. */
if (store->flags & CAMEL_STORE_VJUNK)
if (g_strcmp0 (folder_name, CAMEL_VJUNK_NAME) == 0)
return;
/* Disregard virtual Trash folders. */
if (store->flags & CAMEL_STORE_VTRASH)
if (g_strcmp0 (folder_name, CAMEL_VTRASH_NAME) == 0)
return;
service = CAMEL_SERVICE (store);
session = camel_service_ref_session (service);
provider = camel_service_get_provider (service);
/* Reuse the store info lock just because it's handy. */
g_mutex_lock (&cache->priv->store_info_ht_lock);
folder_uri = e_mail_folder_uri_build (store, folder_name);
if (provider->flags & CAMEL_PROVIDER_IS_REMOTE)
queue = &cache->priv->remote_folder_uris;
else
queue = &cache->priv->local_folder_uris;
link = find_folder_uri (queue, session, folder_uri);
if (link != NULL) {
g_free (link->data);
g_queue_delete_link (queue, link);
}
g_free (folder_uri);
g_mutex_unlock (&cache->priv->store_info_ht_lock);
g_object_unref (session);
}
static void
mail_folder_cache_folder_deleted (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
CamelService *service;
CamelSession *session;
GQueue *queue;
GList *link;
gchar *folder_uri;
/* Disregard virtual stores. */
if (CAMEL_IS_VEE_STORE (store))
return;
/* Disregard virtual Junk folders. */
if (store->flags & CAMEL_STORE_VJUNK)
if (g_strcmp0 (folder_name, CAMEL_VJUNK_NAME) == 0)
return;
/* Disregard virtual Trash folders. */
if (store->flags & CAMEL_STORE_VTRASH)
if (g_strcmp0 (folder_name, CAMEL_VTRASH_NAME) == 0)
return;
service = CAMEL_SERVICE (store);
session = camel_service_ref_session (service);
/* Reuse the store info lock just because it's handy. */
g_mutex_lock (&cache->priv->store_info_ht_lock);
folder_uri = e_mail_folder_uri_build (store, folder_name);
queue = &cache->priv->local_folder_uris;
link = find_folder_uri (queue, session, folder_uri);
if (link != NULL) {
g_free (link->data);
g_queue_delete_link (queue, link);
}
queue = &cache->priv->remote_folder_uris;
link = find_folder_uri (queue, session, folder_uri);
if (link != NULL) {
g_free (link->data);
g_queue_delete_link (queue, link);
}
g_free (folder_uri);
g_mutex_unlock (&cache->priv->store_info_ht_lock);
g_object_unref (session);
}
static void
mail_folder_cache_class_init (MailFolderCacheClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (class, sizeof (MailFolderCachePrivate));
object_class = G_OBJECT_CLASS (class);
object_class->get_property = mail_folder_cache_get_property;
object_class->dispose = mail_folder_cache_dispose;
object_class->finalize = mail_folder_cache_finalize;
class->folder_available = mail_folder_cache_folder_available;
class->folder_unavailable = mail_folder_cache_folder_unavailable;
class->folder_deleted = mail_folder_cache_folder_deleted;
g_object_class_install_property (
object_class,
PROP_MAIN_CONTEXT,
g_param_spec_boxed (
"main-context",
"Main Context",
"The main loop context on "
"which to attach event sources",
G_TYPE_MAIN_CONTEXT,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* MailFolderCache::folder-available
* @store: the #CamelStore containing the folder
* @folder_name: the name of the folder
*
* Emitted when a folder becomes available
**/
signals[FOLDER_AVAILABLE] = g_signal_new (
"folder-available",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_available),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
CAMEL_TYPE_STORE,
G_TYPE_STRING);
/**
* MailFolderCache::folder-unavailable
* @store: the #CamelStore containing the folder
* @folder_name: the name of the folder
*
* Emitted when a folder becomes unavailable. This represents a
* transient condition. See MailFolderCache::folder-deleted to be
* notified when a folder is permanently removed.
**/
signals[FOLDER_UNAVAILABLE] = g_signal_new (
"folder-unavailable",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_unavailable),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
CAMEL_TYPE_STORE,
G_TYPE_STRING);
/**
* MailFolderCache::folder-deleted
* @store: the #CamelStore containing the folder
* @folder_name: the name of the folder
*
* Emitted when a folder is deleted
**/
signals[FOLDER_DELETED] = g_signal_new (
"folder-deleted",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_deleted),
NULL, NULL, /* accumulator */
NULL,
G_TYPE_NONE, 2,
CAMEL_TYPE_STORE,
G_TYPE_STRING);
/**
* MailFolderCache::folder-renamed
* @store: the #CamelStore containing the folder
* @old_folder_name: the old name of the folder
* @new_folder_name: the new name of the folder
*
* Emitted when a folder is renamed
**/
signals[FOLDER_RENAMED] = g_signal_new (
"folder-renamed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_renamed),
NULL, NULL, NULL,
G_TYPE_NONE, 3,
CAMEL_TYPE_STORE,
G_TYPE_STRING,
G_TYPE_STRING);
/**
* MailFolderCache::folder-unread-updated
* @store: the #CamelStore containing the folder
* @folder_name: the name of the folder
* @unread: the number of unread mails in the folder
*
* Emitted when a we receive an update to the unread count for a folder
**/
signals[FOLDER_UNREAD_UPDATED] = g_signal_new (
"folder-unread-updated",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_unread_updated),
NULL, NULL, NULL,
G_TYPE_NONE, 3,
CAMEL_TYPE_STORE,
G_TYPE_STRING,
G_TYPE_INT);
/**
* MailFolderCache::folder-changed
* @store: the #CamelStore containing the folder
* @folder_name: the name of the folder
* @new_messages: the number of new messages for the folder
* @msg_uid: uid of the new message, or NULL
* @msg_sender: sender of the new message, or NULL
* @msg_subject: subject of the new message, or NULL
*
* Emitted when a folder has changed. If @new_messages is not
* exactly 1, @msg_uid, @msg_sender, and @msg_subject will be NULL.
**/
signals[FOLDER_CHANGED] = g_signal_new (
"folder-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MailFolderCacheClass, folder_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 6,
CAMEL_TYPE_STORE,
G_TYPE_STRING,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
}
static void
mail_folder_cache_init (MailFolderCache *cache)
{
GHashTable *store_info_ht;
const gchar *buf;
guint timeout;
store_info_ht = g_hash_table_new_full (
(GHashFunc) g_direct_hash,
(GEqualFunc) g_direct_equal,
(GDestroyNotify) g_object_unref,
(GDestroyNotify) store_info_unref);
cache->priv = MAIL_FOLDER_CACHE_GET_PRIVATE (cache);
cache->priv->main_context = g_main_context_ref_thread_default ();
cache->priv->store_info_ht = store_info_ht;
g_mutex_init (&cache->priv->store_info_ht_lock);
cache->priv->count_sent = getenv ("EVOLUTION_COUNT_SENT") != NULL;
cache->priv->count_trash = getenv ("EVOLUTION_COUNT_TRASH") != NULL;
buf = getenv ("EVOLUTION_PING_TIMEOUT");
timeout = buf ? strtoul (buf, NULL, 10) : 600;
cache->priv->ping_id = g_timeout_add_seconds (
timeout, (GSourceFunc) ping_cb, cache);
g_queue_init (&cache->priv->local_folder_uris);
g_queue_init (&cache->priv->remote_folder_uris);
}
MailFolderCache *
mail_folder_cache_new (void)
{
return g_object_new (MAIL_TYPE_FOLDER_CACHE, NULL);
}
/**
* mail_folder_cache_ref_main_context:
*
* Returns the #GMainContext on which event sources for @cache are to be
* attached.
*
* The returned #GMainContext is referenced for thread-safety and should
* be unreferenced with g_main_context_unref() when finished with it.
*
* Returns: a #GMainContext
**/
GMainContext *
mail_folder_cache_ref_main_context (MailFolderCache *cache)
{
g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), NULL);
return g_main_context_ref (cache->priv->main_context);
}
/**
* mail_folder_cache_note_store:
*
* Add a store whose folders should appear in the shell The folders are scanned
* from the store, and/or added at runtime via the folder_created event. The
* @done function returns if we can free folder info.
*/
void
mail_folder_cache_note_store (MailFolderCache *cache,
CamelStore *store,
GCancellable *cancellable,
NoteDoneFunc done,
gpointer data)
{
CamelSession *session;
StoreInfo *store_info;
struct _update_data *ud;
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (CAMEL_IS_STORE (store));
session = camel_service_ref_session (CAMEL_SERVICE (store));
store_info = mail_folder_cache_ref_store_info (cache, store);
if (store_info == NULL)
store_info = mail_folder_cache_new_store_info (cache, store);
ud = g_malloc0 (sizeof (*ud));
ud->done = done;
ud->data = data;
ud->cache = cache;
if (G_IS_CANCELLABLE (cancellable))
ud->cancellable = g_object_ref (cancellable);
/* We might get a race when setting up a store, such that it is
* still left in offline mode, after we've gone online. This
* catches and fixes it up when the shell opens us. */
if (CAMEL_IS_DISCO_STORE (store)) {
if (camel_session_get_online (session) &&
camel_disco_store_status (CAMEL_DISCO_STORE (store)) ==
CAMEL_DISCO_STORE_OFFLINE) {
e_mail_store_go_online (
store, G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) store_go_online_cb, ud);
} else {
goto normal_setup;
}
} else if (CAMEL_IS_OFFLINE_STORE (store)) {
if (camel_session_get_online (session) &&
!camel_offline_store_get_online (
CAMEL_OFFLINE_STORE (store))) {
e_mail_store_go_online (
store, G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) store_go_online_cb, ud);
} else {
goto normal_setup;
}
} else {
normal_setup:
if (store_has_folder_hierarchy (store))
camel_store_get_folder_info (
store, NULL,
CAMEL_STORE_FOLDER_INFO_FAST |
CAMEL_STORE_FOLDER_INFO_RECURSIVE |
CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) update_folders, ud);
}
g_mutex_lock (&store_info->lock);
g_queue_push_tail (&store_info->folderinfo_updates, ud);
g_mutex_unlock (&store_info->lock);
store_info_unref (store_info);
g_object_unref (session);
}
/**
* mail_folder_cache_note_folder:
*
* When a folder has been opened, notify it for watching. The folder must have
* already been created on the store (which has already been noted) before the
* folder can be opened
*/
void
mail_folder_cache_note_folder (MailFolderCache *cache,
CamelFolder *folder)
{
CamelStore *parent_store;
CamelFolder *cached_folder;
FolderInfo *folder_info;
const gchar *full_name;
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (CAMEL_IS_FOLDER (folder));
full_name = camel_folder_get_full_name (folder);
parent_store = camel_folder_get_parent_store (folder);
folder_info = mail_folder_cache_ref_folder_info (
cache, parent_store, full_name);
/* XXX Not sure we should just be returning quietly here, but
* the old code did. Using g_return_if_fail() causes a few
* warnings on startup which might be worth tracking down. */
if (folder_info == NULL)
return;
g_mutex_lock (&folder_info->lock);
cached_folder = g_weak_ref_get (&folder_info->folder);
if (cached_folder != NULL) {
g_signal_handler_disconnect (
cached_folder,
folder_info->folder_changed_handler_id);
g_object_unref (cached_folder);
}
g_weak_ref_set (&folder_info->folder, folder);
update_1folder (cache, folder_info, 0, NULL, NULL, NULL, NULL);
folder_info->folder_changed_handler_id =
g_signal_connect (
folder, "changed",
G_CALLBACK (folder_changed_cb), cache);
g_mutex_unlock (&folder_info->lock);
folder_info_unref (folder_info);
}
/**
* mail_folder_cache_has_folder_info:
* @cache: a #MailFolderCache
* @store: a #CamelStore
* @folder_name: a folder name
*
* Returns whether @cache has information about the folder described by
* @store and @folder_name. This does not necessarily mean it has the
* #CamelFolder instance, but it at least has some meta-data about it.
*
* You can use this function as a folder existence test.
*
* Returns: %TRUE if @cache has folder info, %FALSE otherwise
**/
gboolean
mail_folder_cache_has_folder_info (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
FolderInfo *folder_info;
gboolean has_info = FALSE;
g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), FALSE);
g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
g_return_val_if_fail (folder_name != NULL, FALSE);
folder_info = mail_folder_cache_ref_folder_info (
cache, store, folder_name);
if (folder_info != NULL) {
folder_info_unref (folder_info);
has_info = TRUE;
}
return has_info;
}
/**
* mail_folder_cache_ref_folder:
* @cache: a #MailFolderCache
* @store: a #CamelStore
* @folder_name: a folder name
*
* Returns the #CamelFolder for @store and @folder_name if available, or
* else %NULL if a #CamelFolder instance is not yet cached. This function
* does not block.
*
* The returned #CamelFolder is referenced for thread-safety and must be
* unreferenced with g_object_unref() when finished with it.
*
* Returns: a #CamelFolder, or %NULL
**/
CamelFolder *
mail_folder_cache_ref_folder (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name)
{
FolderInfo *folder_info;
CamelFolder *folder = NULL;
g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), NULL);
g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
g_return_val_if_fail (folder_name != NULL, NULL);
folder_info = mail_folder_cache_ref_folder_info (
cache, store, folder_name);
if (folder_info != NULL) {
folder = g_weak_ref_get (&folder_info->folder);
folder_info_unref (folder_info);
}
return folder;
}
/**
* mail_folder_cache_get_folder_info_flags:
* @cache: a #MailFolderCache
* @store: a #CamelStore
* @folder_name: a folder name
* @flags: return location for #CamelFolderInfoFlags
*
* Obtains #CamelFolderInfoFlags for @store and @folder_name if available,
* and returns %TRUE to indicate @flags was set. If no folder information
* is available for @store and @folder_name, the function returns %FALSE.
*
* Returns: whether @flags was set
**/
gboolean
mail_folder_cache_get_folder_info_flags (MailFolderCache *cache,
CamelStore *store,
const gchar *folder_name,
CamelFolderInfoFlags *flags)
{
FolderInfo *folder_info;
gboolean flags_set = FALSE;
g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), FALSE);
g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
g_return_val_if_fail (folder_name != NULL, FALSE);
g_return_val_if_fail (flags != NULL, FALSE);
folder_info = mail_folder_cache_ref_folder_info (
cache, store, folder_name);
if (folder_info != NULL) {
*flags = folder_info->flags;
folder_info_unref (folder_info);
flags_set = TRUE;
}
return flags_set;
}
void
mail_folder_cache_get_local_folder_uris (MailFolderCache *cache,
GQueue *out_queue)
{
GList *head, *link;
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (out_queue != NULL);
/* Reuse the store_info_ht_lock just because it's handy. */
g_mutex_lock (&cache->priv->store_info_ht_lock);
head = g_queue_peek_head_link (&cache->priv->local_folder_uris);
for (link = head; link != NULL; link = g_list_next (link))
g_queue_push_tail (out_queue, g_strdup (link->data));
g_mutex_unlock (&cache->priv->store_info_ht_lock);
}
void
mail_folder_cache_get_remote_folder_uris (MailFolderCache *cache,
GQueue *out_queue)
{
GList *head, *link;
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (out_queue != NULL);
/* Reuse the store_info_ht_lock just because it's handy. */
g_mutex_lock (&cache->priv->store_info_ht_lock);
head = g_queue_peek_head_link (&cache->priv->remote_folder_uris);
for (link = head; link != NULL; link = g_list_next (link))
g_queue_push_tail (out_queue, g_strdup (link->data));
g_mutex_unlock (&cache->priv->store_info_ht_lock);
}
void
mail_folder_cache_service_removed (MailFolderCache *cache,
CamelService *service)
{
StoreInfo *store_info;
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (CAMEL_IS_SERVICE (service));
if (!CAMEL_IS_STORE (service))
return;
store_info = mail_folder_cache_steal_store_info (
cache, CAMEL_STORE (service));
if (store_info != NULL) {
GList *list, *link;
g_signal_handlers_disconnect_matched (
service, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, cache);
list = store_info_list_folder_info (store_info);
for (link = list; link != NULL; link = g_list_next (link))
unset_folder_info (cache, link->data, FALSE);
g_list_free_full (list, (GDestroyNotify) folder_info_unref);
store_info_unref (store_info);
}
}
void
mail_folder_cache_service_enabled (MailFolderCache *cache,
CamelService *service)
{
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (CAMEL_IS_SERVICE (service));
mail_folder_cache_note_store (
cache, CAMEL_STORE (service), NULL, NULL, NULL);
}
void
mail_folder_cache_service_disabled (MailFolderCache *cache,
CamelService *service)
{
g_return_if_fail (MAIL_IS_FOLDER_CACHE (cache));
g_return_if_fail (CAMEL_IS_SERVICE (service));
/* To the folder cache, disabling a service is the same as
* removing it. We keep a separate callback function only
* to use as a breakpoint target in a debugger. */
mail_folder_cache_service_removed (cache, service);
}
|