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
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* mail-ops.c: callbacks for the mail toolbar/menus */
/*
* Authors:
* Dan Winship <danw@ximian.com>
* Peter Williams <peterw@ximian.com>
* Jeffrey Stedfast <fejj@ximian.com>
*
* Copyright 2000 Ximian, Inc. (www.ximian.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include <time.h>
#include <libgnome/gnome-paper.h>
#include <libgnomeui/gnome-stock.h>
#include <libgnome/gnome-paper.h>
#include <libgnomeprint/gnome-print-master.h>
#include <libgnomeprint/gnome-print-master-preview.h>
#include <bonobo/bonobo-widget.h>
#include <bonobo/bonobo-socket.h>
#include <gal/e-table/e-table.h>
#include <gal/widgets/e-gui-utils.h>
#include <gal/widgets/e-unicode.h>
#include <e-util/e-dialog-utils.h>
#include <filter/filter-editor.h>
#include "mail.h"
#include "message-browser.h"
#include "mail-callbacks.h"
#include "mail-config.h"
#include "mail-accounts.h"
#include "mail-config-druid.h"
#include "mail-mt.h"
#include "mail-tools.h"
#include "mail-ops.h"
#include "mail-local.h"
#include "mail-search.h"
#include "mail-send-recv.h"
#include "mail-vfolder.h"
#include "mail-folder-cache.h"
#include "folder-browser.h"
#include "subscribe-dialog.h"
#include "e-messagebox.h"
#include "Evolution.h"
#include "evolution-storage.h"
#include "evolution-shell-client.h"
#ifndef HAVE_MKSTEMP
#include <fcntl.h>
#include <sys/stat.h>
#endif
#define FB_WINDOW(fb) GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb), GTK_TYPE_WINDOW))
struct post_send_data {
CamelFolder *folder;
gchar *uid;
guint32 flags, set;
};
static void
druid_destroyed (void)
{
gtk_main_quit ();
}
static gboolean
configure_mail (FolderBrowser *fb)
{
MailConfigDruid *druid;
GtkWidget *dialog;
dialog = gnome_message_box_new (
_("You have not configured the mail client.\n"
"You need to do this before you can send,\n"
"receive or compose mail.\n"
"Would you like to configure it now?"),
GNOME_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO, NULL);
/*
* Focus YES
*/
gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
gtk_widget_grab_focus (GTK_WIDGET (GNOME_DIALOG (dialog)->buttons->data));
e_gnome_dialog_set_parent (GNOME_DIALOG (dialog), FB_WINDOW (fb));
switch (gnome_dialog_run_and_close (GNOME_DIALOG (dialog))) {
case 0:
druid = mail_config_druid_new (fb->shell);
gtk_signal_connect (GTK_OBJECT (druid), "destroy",
GTK_SIGNAL_FUNC (druid_destroyed), NULL);
gtk_widget_show (GTK_WIDGET (druid));
gtk_grab_add (GTK_WIDGET (druid));
gtk_main ();
break;
case 1:
default:
break;
}
return mail_config_is_configured ();
}
static gboolean
check_send_configuration (FolderBrowser *fb)
{
const MailConfigAccount *account;
/* Check general */
if (!mail_config_is_configured () && !configure_mail (fb))
return FALSE;
/* Get the default account */
account = mail_config_get_default_account ();
/* Check for an identity */
if (!account) {
GtkWidget *message;
message = e_gnome_warning_dialog_parented (_("You need to configure an identity\n"
"before you can compose mail."),
FB_WINDOW (fb));
gnome_dialog_set_close (GNOME_DIALOG (message), TRUE);
gtk_widget_show (message);
return FALSE;
}
/* Check for a transport */
if (!account->transport || !account->transport->url) {
GtkWidget *message;
message = e_gnome_warning_dialog_parented (_("You need to configure a mail transport\n"
"before you can compose mail."),
GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb),
GTK_TYPE_WINDOW)));
gnome_dialog_set_close (GNOME_DIALOG (message), TRUE);
gtk_widget_show (message);
return FALSE;
}
return TRUE;
}
void
send_receive_mail (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
const MailConfigAccount *account;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!mail_config_is_configured () && !configure_mail (fb))
return;
account = mail_config_get_default_account ();
if (!account || !account->transport) {
GtkWidget *dialog;
dialog = gnome_error_dialog_parented (_("You have not set a mail transport method"),
FB_WINDOW (fb));
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
mail_send_receive (fb->folder);
}
static void
msgbox_destroyed (GtkWidget *widget, gpointer data)
{
gboolean *show_again = data;
GtkWidget *checkbox;
checkbox = e_message_box_get_checkbox (E_MESSAGE_BOX (widget));
*show_again = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
}
static gboolean
ask_confirm_for_unwanted_html_mail (EMsgComposer *composer, EDestination **recipients)
{
gboolean show_again = TRUE;
GString *str;
GtkWidget *mbox;
gint i, button;
if (!mail_config_get_confirm_unwanted_html ()) {
g_message ("doesn't want to see confirm html messages!");
return TRUE;
}
/* FIXME: this wording sucks */
str = g_string_new (_("You are sending an HTML-formatted message, but the following recipients "
"do not want HTML-formatted mail:\n"));
for (i = 0; recipients[i] != NULL; ++i) {
if (!e_destination_get_html_mail_pref (recipients[i])) {
const char *name;
char *buf;
name = e_destination_get_textrep (recipients[i]);
buf = e_utf8_to_locale_string (name);
g_string_sprintfa (str, " %s\n", buf);
g_free (buf);
}
}
g_string_append (str, _("Send anyway?"));
mbox = e_message_box_new (str->str,
E_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
g_string_free (str, TRUE);
gtk_signal_connect (GTK_OBJECT (mbox), "destroy",
msgbox_destroyed, &show_again);
button = gnome_dialog_run_and_close (GNOME_DIALOG (mbox));
if (!show_again) {
mail_config_set_confirm_unwanted_html (show_again);
g_message ("don't show HTML warning again");
}
if (button == 0)
return TRUE;
else
return FALSE;
}
static gboolean
ask_confirm_for_empty_subject (EMsgComposer *composer)
{
/* FIXME: EMessageBox should really handle this stuff
automagically. What Miguel thinks would be nice is to pass
in a unique id which could be used as a key in the config
file and the value would be an int. -1 for always show or
the button pressed otherwise. This probably means we'd have
to write e_messagebox_run () */
gboolean show_again = TRUE;
GtkWidget *mbox;
int button;
if (!mail_config_get_prompt_empty_subject ())
return TRUE;
mbox = e_message_box_new (_("This message has no subject.\nReally send?"),
E_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
gtk_signal_connect (GTK_OBJECT (mbox), "destroy",
msgbox_destroyed, &show_again);
button = gnome_dialog_run_and_close (GNOME_DIALOG (mbox));
mail_config_set_prompt_empty_subject (show_again);
if (button == 0)
return TRUE;
else
return FALSE;
}
static gboolean
ask_confirm_for_only_bcc (EMsgComposer *composer, gboolean hidden_list_case)
{
/* FIXME: EMessageBox should really handle this stuff
automagically. What Miguel thinks would be nice is to pass
in a message-id which could be used as a key in the config
file and the value would be an int. -1 for always show or
the button pressed otherwise. This probably means we'd have
to write e_messagebox_run () */
gboolean show_again = TRUE;
GtkWidget *mbox;
int button;
const gchar *first_text;
gchar *message_text;
if (!mail_config_get_prompt_only_bcc ())
return TRUE;
/* If the user is mailing a hidden contact list, it is possible for
them to create a message with only Bcc recipients without really
realizing it. To try to avoid being totally confusing, I've changed
this dialog to provide slightly different text in that case, to
better explain what the hell is going on. */
if (hidden_list_case) {
first_text = _("Since the contact list you are sending to "
"is configured to hide the list's addresses, "
"this message will contain only Bcc recipients.");
} else {
first_text = _("This message contains only Bcc recipients.");
}
message_text = g_strdup_printf ("%s\n%s", first_text,
_("It is possible that the mail server may reveal the recipients "
"by adding an Apparently-To header.\nSend anyway?"));
mbox = e_message_box_new (message_text,
E_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
gtk_signal_connect (GTK_OBJECT (mbox), "destroy",
msgbox_destroyed, &show_again);
button = gnome_dialog_run_and_close (GNOME_DIALOG (mbox));
mail_config_set_prompt_only_bcc (show_again);
g_free (message_text);
if (button == 0)
return TRUE;
else
return FALSE;
}
static void
free_psd (GtkWidget *composer, gpointer user_data)
{
struct post_send_data *psd = user_data;
if (psd->folder)
camel_object_unref (CAMEL_OBJECT (psd->folder));
if (psd->uid)
g_free (psd->uid);
g_free (psd);
}
struct _send_data {
EMsgComposer *composer;
struct post_send_data *psd;
};
static void
composer_sent_cb (char *uri, CamelMimeMessage *message, gboolean sent, void *data)
{
struct _send_data *send = data;
if (sent) {
if (send->psd) {
camel_folder_set_message_flags (send->psd->folder, send->psd->uid,
send->psd->flags, send->psd->set);
}
gtk_widget_destroy (GTK_WIDGET (send->composer));
} else {
e_msg_composer_set_enable_autosave(send->composer, TRUE);
gtk_widget_show (GTK_WIDGET (send->composer));
gtk_object_unref (GTK_OBJECT (send->composer));
}
g_free (send);
camel_object_unref (CAMEL_OBJECT (message));
}
static CamelMimeMessage *
composer_get_message (EMsgComposer *composer)
{
static char *recipient_type[] = {
CAMEL_RECIPIENT_TYPE_TO,
CAMEL_RECIPIENT_TYPE_CC,
CAMEL_RECIPIENT_TYPE_BCC
};
const CamelInternetAddress *iaddr;
const MailConfigAccount *account;
CamelMimeMessage *message;
EDestination **recipients;
const char *subject;
int num_addrs, i;
message = e_msg_composer_get_message (composer);
if (message == NULL)
return NULL;
/* Add info about the sending account */
account = e_msg_composer_get_preferred_account (composer);
if (account) {
camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Account", account->name);
camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Transport", account->transport->url);
camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Fcc", account->sent_folder_uri);
if (account->id->organization)
camel_medium_set_header (CAMEL_MEDIUM (message), "Organization", account->id->organization);
}
/* get the message recipients */
recipients = e_msg_composer_get_recipients (composer);
/* Check for recipients */
for (num_addrs = 0, i = 0; i < 3; i++) {
iaddr = camel_mime_message_get_recipients (message, recipient_type[i]);
num_addrs += iaddr ? camel_address_length (CAMEL_ADDRESS (iaddr)) : 0;
}
/* I'm sensing a lack of love, er, I mean recipients. */
if (num_addrs == 0) {
GtkWidget *message_box;
message_box = gnome_message_box_new (_("You must specify recipients in order to "
"send this message."),
GNOME_MESSAGE_BOX_WARNING,
GNOME_STOCK_BUTTON_OK,
NULL);
gnome_dialog_run_and_close (GNOME_DIALOG (message_box));
camel_object_unref (CAMEL_OBJECT (message));
message = NULL;
goto finished;
}
if (iaddr && num_addrs == camel_address_length (CAMEL_ADDRESS (iaddr))) {
/* this means that the only recipients are Bcc's */
/* OK, this is an abusive hack. If someone sends a mail with a
hidden contact list on to to: line and no other recipients,
they will unknowingly create a message with only bcc: recipients.
We try to detect this and pass a flag to ask_confirm_for_only_bcc,
so that it can present the user with a dialog whose text has been
modified to reflect this situation. */
const char *to_header = camel_medium_get_header (CAMEL_MEDIUM (message), CAMEL_RECIPIENT_TYPE_TO);
gboolean hidden_list_case = FALSE;
if (to_header && !strcmp (to_header, "Undisclosed-Recipient:;"))
hidden_list_case = TRUE;
if (!ask_confirm_for_only_bcc (composer, hidden_list_case)) {
camel_object_unref (CAMEL_OBJECT (message));
message = NULL;
goto finished;
}
}
/* Only show this warning if our default is to send html. If it isn't, we've
manually switched into html mode in the composer and (presumably) had a good
reason for doing this. */
if (e_msg_composer_get_send_html (composer)
&& mail_config_get_send_html ()
&& mail_config_get_confirm_unwanted_html ()) {
gboolean html_problem = FALSE;
for (i = 0; recipients[i] != NULL && !html_problem; ++i) {
if (!e_destination_get_html_mail_pref (recipients[i]))
html_problem = TRUE;
}
if (html_problem) {
html_problem = !ask_confirm_for_unwanted_html_mail (composer, recipients);
if (html_problem) {
camel_object_unref (CAMEL_OBJECT (message));
message = NULL;
goto finished;
}
}
}
/* Check for no subject */
subject = camel_mime_message_get_subject (message);
if (subject == NULL || subject[0] == '\0') {
if (!ask_confirm_for_empty_subject (composer)) {
camel_object_unref (CAMEL_OBJECT (message));
message = NULL;
goto finished;
}
}
/* Get the message recipients and 'touch' them, boosting their use scores */
e_destination_touchv (recipients);
finished:
e_destination_freev (recipients);
return message;
}
void
composer_send_cb (EMsgComposer *composer, gpointer data)
{
const MailConfigService *transport;
CamelMimeMessage *message;
struct post_send_data *psd = data;
struct _send_data *send;
if (!mail_config_is_configured ()) {
GtkWidget *dialog;
dialog = gnome_ok_dialog_parented (_("You must configure an account before you "
"can send this email."),
GTK_WINDOW (composer));
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
message = composer_get_message (composer);
if (!message)
return;
transport = mail_config_get_default_transport ();
if (!transport)
return;
send = g_malloc (sizeof (*send));
send->psd = psd;
send->composer = composer;
gtk_object_ref (GTK_OBJECT (composer));
gtk_widget_hide (GTK_WIDGET (composer));
e_msg_composer_set_enable_autosave (composer, FALSE);
mail_send_mail (transport->url, message, composer_sent_cb, send);
}
static void
append_mail_cleanup (CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, int ok, void *data)
{
camel_message_info_free (info);
}
void
composer_postpone_cb (EMsgComposer *composer, gpointer data)
{
extern CamelFolder *outbox_folder;
CamelMimeMessage *message;
CamelMessageInfo *info;
struct post_send_data *psd = data;
message = composer_get_message (composer);
if (message == NULL)
return;
info = camel_message_info_new ();
info->flags = CAMEL_MESSAGE_SEEN;
mail_append_mail (outbox_folder, message, info, append_mail_cleanup, NULL);
camel_object_unref (CAMEL_OBJECT (message));
if (psd)
camel_folder_set_message_flags (psd->folder, psd->uid, psd->flags, psd->set);
gtk_widget_destroy (GTK_WIDGET (composer));
}
struct _save_draft_info {
EMsgComposer *composer;
int quit;
};
static void
save_draft_done (CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, int ok, void *data)
{
struct _save_draft_info *sdi = data;
if (ok && sdi->quit)
gtk_widget_destroy (GTK_WIDGET (sdi->composer));
else
gtk_object_unref (GTK_OBJECT (sdi->composer));
g_free (info);
g_free (sdi);
}
static void
use_default_drafts_cb (int reply, gpointer data)
{
extern CamelFolder *drafts_folder;
CamelFolder **folder = data;
if (reply == 0) {
*folder = drafts_folder;
camel_object_ref (CAMEL_OBJECT (*folder));
}
}
static void
save_draft_folder (char *uri, CamelFolder *folder, gpointer data)
{
CamelFolder **save = data;
if (folder) {
*save = folder;
camel_object_ref (CAMEL_OBJECT (folder));
}
}
void
composer_save_draft_cb (EMsgComposer *composer, int quit, gpointer data)
{
extern char *default_drafts_folder_uri;
extern CamelFolder *drafts_folder;
CamelMimeMessage *msg;
CamelMessageInfo *info;
const MailConfigAccount *account;
struct _save_draft_info *sdi;
CamelFolder *folder = NULL;
account = e_msg_composer_get_preferred_account (composer);
if (account && account->drafts_folder_uri &&
strcmp (account->drafts_folder_uri, default_drafts_folder_uri) != 0) {
int id;
id = mail_get_folder (account->drafts_folder_uri, 0, save_draft_folder, &folder, mail_thread_new);
mail_msg_wait (id);
if (!folder) {
GtkWidget *dialog;
dialog = gnome_ok_cancel_dialog_parented (_("Unable to open the drafts folder for this account.\n"
"Would you like to use the default drafts folder?"),
use_default_drafts_cb, &folder, GTK_WINDOW (composer));
gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
if (!folder)
return;
}
} else {
folder = drafts_folder;
camel_object_ref (CAMEL_OBJECT (folder));
}
msg = e_msg_composer_get_message_draft (composer);
info = g_new0 (CamelMessageInfo, 1);
info->flags = CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_SEEN;
sdi = g_malloc (sizeof (struct _save_draft_info));
sdi->composer = composer;
gtk_object_ref (GTK_OBJECT (composer));
sdi->quit = quit;
mail_append_mail (folder, msg, info, save_draft_done, sdi);
camel_object_unref (CAMEL_OBJECT (folder));
camel_object_unref (CAMEL_OBJECT (msg));
}
static GtkWidget *
create_msg_composer (const MailConfigAccount *account, const char *url)
{
EMsgComposer *composer;
gboolean send_html;
/* Make sure that we've actually been passed in an account. If one has
* not been passed in, grab the default account.
*/
if (account == NULL) {
account = mail_config_get_default_account ();
}
send_html = mail_config_get_send_html ();
composer = url ? e_msg_composer_new_from_url (url) : e_msg_composer_new ();
if (composer) {
e_msg_composer_hdrs_set_from_account (E_MSG_COMPOSER_HDRS (composer->hdrs), account->name);
e_msg_composer_set_send_html (composer, send_html);
e_msg_composer_show_sig_file (composer);
return GTK_WIDGET (composer);
} else
return NULL;
}
void
compose_msg (GtkWidget *widget, gpointer user_data)
{
const MailConfigAccount *account;
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GtkWidget *composer;
if (FOLDER_BROWSER_IS_DESTROYED (fb) || !check_send_configuration (fb))
return;
/* Figure out which account we want to initially compose from */
account = mail_config_get_account_by_source_url (fb->uri);
composer = create_msg_composer (account, NULL);
if (!composer)
return;
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
GTK_SIGNAL_FUNC (composer_save_draft_cb), NULL);
gtk_widget_show (composer);
}
/* Send according to a mailto (RFC 2368) URL. */
void
send_to_url (const char *url)
{
GtkWidget *composer;
/* FIXME: no way to get folder browser? Not without
* big pain in the ass, as far as I can tell */
if (!check_send_configuration (NULL))
return;
/* Tell create_msg_composer to use the default email profile */
composer = create_msg_composer (NULL, url);
if (!composer)
return;
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
GTK_SIGNAL_FUNC (composer_save_draft_cb), NULL);
gtk_widget_show (composer);
}
static GList *
list_add_addresses (GList *list, const CamelInternetAddress *cia, const GSList *accounts,
GHashTable *rcpt_hash, const MailConfigAccount **me)
{
const MailConfigAccount *account;
GHashTable *account_hash;
const char *name, *addr;
const GSList *l;
int i;
account_hash = g_hash_table_new (g_strcase_hash, g_strcase_equal);
l = accounts;
while (l) {
account = l->data;
g_hash_table_insert (account_hash, (char *) account->id->address, (void *) account);
l = l->next;
}
for (i = 0; camel_internet_address_get (cia, i, &name, &addr); i++) {
/* Here I'll check to see if the cc:'d address is the address
of the sender, and if so, don't add it to the cc: list; this
is to fix Bugzilla bug #455. */
account = g_hash_table_lookup (account_hash, addr);
if (account && me && !*me)
*me = account;
if (!account && !g_hash_table_lookup (rcpt_hash, addr)) {
EDestination *dest;
dest = e_destination_new ();
e_destination_set_name (dest, name);
e_destination_set_email (dest, addr);
list = g_list_append (list, dest);
g_hash_table_insert (rcpt_hash, (char *) addr, GINT_TO_POINTER (1));
}
}
g_hash_table_destroy (account_hash);
return list;
}
static const MailConfigAccount *
guess_me (const CamelInternetAddress *to, const CamelInternetAddress *cc, const GSList *accounts)
{
const MailConfigAccount *account;
GHashTable *account_hash;
const char *addr;
const GSList *l;
int i;
/* "optimization" */
if (!to && !cc)
return NULL;
account_hash = g_hash_table_new (g_strcase_hash, g_strcase_equal);
l = accounts;
while (l) {
account = l->data;
g_hash_table_insert (account_hash, (char *) account->id->address, (void *) account);
l = l->next;
}
if (to) {
for (i = 0; camel_internet_address_get (to, i, NULL, &addr); i++) {
account = g_hash_table_lookup (account_hash, addr);
if (account)
goto found;
}
}
if (cc) {
for (i = 0; camel_internet_address_get (cc, i, NULL, &addr); i++) {
account = g_hash_table_lookup (account_hash, addr);
if (account)
goto found;
}
}
account = NULL;
found:
g_hash_table_destroy (account_hash);
return account;
}
inline static void
mail_ignore (EMsgComposer *composer, const gchar *name, const gchar *address)
{
e_msg_composer_ignore (composer, name && *name ? name : address);
}
static void
mail_ignore_address (EMsgComposer *composer, const CamelInternetAddress *addr)
{
const gchar *name, *address;
gint i, max;
max = camel_address_length (CAMEL_ADDRESS (addr));
for (i = 0; i < max; i++) {
camel_internet_address_get (addr, i, &name, &address);
mail_ignore (composer, name, address);
}
}
static EMsgComposer *
mail_generate_reply (CamelFolder *folder, CamelMimeMessage *message, const char *uid, int mode)
{
const CamelInternetAddress *reply_to, *sender, *to_addrs, *cc_addrs;
const char *name = NULL, *address = NULL, *source = NULL;
const char *message_id, *references, *reply_addr = NULL;
char *text, *subject, date_str[100], *format;
const MailConfigAccount *me = NULL;
const GSList *accounts = NULL;
GList *to = NULL, *cc = NULL;
EDestination **tov, **ccv;
EMsgComposer *composer;
time_t date;
const int max_subject_length = 1024;
composer = e_msg_composer_new ();
if (!composer)
return NULL;
e_msg_composer_add_message_attachments (composer, message, TRUE);
if ((mode & REPLY_NO_QUOTE) == 0) {
sender = camel_mime_message_get_from (message);
if (sender != NULL && camel_address_length (CAMEL_ADDRESS (sender)) > 0) {
camel_internet_address_get (sender, 0, &name, &address);
} else {
name = _("an unknown sender");
}
date = camel_mime_message_get_date (message, NULL);
strftime (date_str, sizeof (date_str), _("On %a, %Y-%m-%d at %H:%M, %%s wrote:"),
localtime (&date));
format = e_utf8_from_locale_string (date_str);
text = mail_tool_quote_message (message, format, name && *name ? name : address);
mail_ignore (composer, name, address);
g_free (format);
if (text) {
e_msg_composer_set_body_text (composer, text);
g_free (text);
}
}
/* Set the recipients */
accounts = mail_config_get_accounts ();
to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
mail_ignore_address (composer, to_addrs);
mail_ignore_address (composer, cc_addrs);
if (mode == REPLY_LIST) {
CamelMessageInfo *info;
const char *mlist;
int i, max, len;
info = camel_folder_get_message_info (folder, uid);
mlist = camel_message_info_mlist (info);
if (mlist) {
/* look through the recipients to find the *real* mailing list address */
len = strlen (mlist);
to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
max = camel_address_length (CAMEL_ADDRESS (to_addrs));
for (i = 0; i < max; i++) {
camel_internet_address_get (to_addrs, i, &name, &address);
if (!g_strncasecmp (address, mlist, len))
break;
}
if (i == max) {
cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
max = camel_address_length (CAMEL_ADDRESS (cc_addrs));
for (i = 0; i < max; i++) {
camel_internet_address_get (cc_addrs, i, &name, &address);
if (!g_strncasecmp (address, mlist, len))
break;
}
}
if (address && i != max) {
EDestination *dest;
dest = e_destination_new ();
e_destination_set_name (dest, name);
e_destination_set_email (dest, address);
to = g_list_append (to, dest);
}
}
me = guess_me (to_addrs, cc_addrs, accounts);
} else {
GHashTable *rcpt_hash;
rcpt_hash = g_hash_table_new (g_strcase_hash, g_strcase_equal);
reply_to = camel_mime_message_get_reply_to (message);
if (!reply_to)
reply_to = camel_mime_message_get_from (message);
if (reply_to) {
int i;
for (i = 0; camel_internet_address_get (reply_to, i, &name, &reply_addr); i++) {
/* Get the Reply-To address so we can ignore references to it in the Cc: list */
EDestination *dest;
dest = e_destination_new ();
e_destination_set_name (dest, name);
e_destination_set_email (dest, reply_addr);
to = g_list_append (to, dest);
g_hash_table_insert (rcpt_hash, (char *) reply_addr, GINT_TO_POINTER (1));
mail_ignore (composer, name, reply_addr);
}
}
if (mode == REPLY_ALL) {
cc = list_add_addresses (cc, to_addrs, accounts, rcpt_hash, &me);
cc = list_add_addresses (cc, cc_addrs, accounts, rcpt_hash, me ? NULL : &me);
} else {
me = guess_me (to_addrs, cc_addrs, accounts);
}
g_hash_table_destroy (rcpt_hash);
}
if (me == NULL) {
/* as a last resort, set the replying account (aka me)
to the account this was fetched from */
source = camel_mime_message_get_source (message);
me = mail_config_get_account_by_source_url (source);
}
/* Set the subject of the new message. */
subject = (char *)camel_mime_message_get_subject (message);
if (!subject)
subject = g_strdup ("");
else {
if (!g_strncasecmp (subject, "Re: ", 4))
subject = g_strndup (subject, max_subject_length);
else {
if (strlen (subject) < max_subject_length) {
subject = g_strdup_printf ("Re: %s", subject);
} else {
/* We can't use %.*s because it depends on the locale being C/POSIX
or UTF-8 to work correctly in glibc */
char *sub;
/*subject = g_strdup_printf ("Re: %.*s...", max_subject_length, subject);*/
sub = g_malloc (max_subject_length + 8);
memcpy (sub, "Re: ", 4);
memcpy (sub + 4, subject, max_subject_length);
memcpy (sub + 4 + max_subject_length, "...", 4);
subject = sub;
}
}
}
tov = e_destination_list_to_vector (to);
ccv = e_destination_list_to_vector (cc);
g_list_free (to);
g_list_free (cc);
e_msg_composer_set_headers (composer, me ? me->name : NULL, tov, ccv, NULL, subject);
e_destination_freev (tov);
e_destination_freev (ccv);
g_free (subject);
/* Add In-Reply-To and References. */
message_id = camel_medium_get_header (CAMEL_MEDIUM (message), "Message-Id");
references = camel_medium_get_header (CAMEL_MEDIUM (message), "References");
if (message_id) {
char *reply_refs;
e_msg_composer_add_header (composer, "In-Reply-To", message_id);
if (references)
reply_refs = g_strdup_printf ("%s %s", references, message_id);
else
reply_refs = g_strdup (message_id);
e_msg_composer_add_header (composer, "References", reply_refs);
g_free (reply_refs);
} else if (references) {
e_msg_composer_add_header (composer, "References", references);
}
return composer;
}
static void
requeue_mail_reply (CamelFolder *folder, char *uid, CamelMimeMessage *msg, void *data)
{
int mode = GPOINTER_TO_INT (data);
mail_reply (folder, msg, uid, mode);
}
void
mail_reply (CamelFolder *folder, CamelMimeMessage *msg, const char *uid, int mode)
{
EMsgComposer *composer;
struct post_send_data *psd;
g_return_if_fail (folder != NULL);
g_return_if_fail (uid != NULL);
if (!msg) {
mail_get_message (folder, uid, requeue_mail_reply,
GINT_TO_POINTER (mode), mail_thread_new);
return;
}
psd = g_new (struct post_send_data, 1);
psd->folder = folder;
camel_object_ref (CAMEL_OBJECT (psd->folder));
psd->uid = g_strdup (uid);
psd->flags = CAMEL_MESSAGE_ANSWERED | CAMEL_MESSAGE_NEEDS_REPLY;
psd->set = CAMEL_MESSAGE_ANSWERED;
composer = mail_generate_reply (folder, msg, uid, mode);
if (!composer)
return;
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), psd);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
GTK_SIGNAL_FUNC (composer_postpone_cb), psd);
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
GTK_SIGNAL_FUNC (composer_save_draft_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "destroy",
GTK_SIGNAL_FUNC (free_psd), psd);
gtk_widget_show (GTK_WIDGET (composer));
e_msg_composer_unset_changed (composer);
}
void
reply_to_sender (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
/* FIXME: make this always load the message based on cursor */
if (FOLDER_BROWSER_IS_DESTROYED (fb) || !check_send_configuration (fb))
return;
mail_reply (fb->folder, fb->mail_display->current_message,
fb->message_list->cursor_uid, REPLY_SENDER);
}
void
reply_to_list (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb) || !check_send_configuration (fb))
return;
/* FIXME: make this always load the message based on cursor */
mail_reply (fb->folder, fb->mail_display->current_message,
fb->message_list->cursor_uid, REPLY_LIST);
}
void
reply_to_all (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb) || !check_send_configuration (fb))
return;
/* FIXME: make this always load the message based on cursor */
mail_reply (fb->folder, fb->mail_display->current_message,
fb->message_list->cursor_uid, REPLY_ALL);
}
void
enumerate_msg (MessageList *ml, const char *uid, gpointer data)
{
g_return_if_fail (ml != NULL);
g_ptr_array_add ((GPtrArray *) data, g_strdup (uid));
}
static EMsgComposer *
forward_get_composer (CamelMimeMessage *message, const char *subject)
{
const MailConfigAccount *account = NULL;
EMsgComposer *composer;
if (message) {
const CamelInternetAddress *to_addrs, *cc_addrs;
const GSList *accounts = NULL;
accounts = mail_config_get_accounts ();
to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
account = guess_me (to_addrs, cc_addrs, accounts);
if (!account) {
const char *source;
source = camel_mime_message_get_source (message);
account = mail_config_get_account_by_source_url (source);
}
}
if (!account)
account = mail_config_get_default_account ();
composer = e_msg_composer_new ();
if (composer) {
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
GTK_SIGNAL_FUNC (composer_save_draft_cb), NULL);
e_msg_composer_set_headers (composer, account->name, NULL, NULL, NULL, subject);
} else {
g_warning ("Could not create composer");
}
return composer;
}
static void
do_forward_non_attached (CamelFolder *folder, char *uid, CamelMimeMessage *message, void *data)
{
MailConfigForwardStyle style = GPOINTER_TO_INT (data);
char *subject, *text;
if (!message)
return;
subject = mail_tool_generate_forward_subject (message);
text = mail_tool_forward_message (message, style == MAIL_CONFIG_FORWARD_QUOTED);
if (text) {
EMsgComposer *composer = forward_get_composer (message, subject);
if (composer) {
CamelDataWrapper *wrapper;
e_msg_composer_set_body_text (composer, text);
wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (message));
if (CAMEL_IS_MULTIPART (wrapper))
e_msg_composer_add_message_attachments (composer, message, FALSE);
gtk_widget_show (GTK_WIDGET (composer));
e_msg_composer_unset_changed (composer);
}
g_free (text);
}
g_free (subject);
}
static void
forward_message (FolderBrowser *fb, MailConfigForwardStyle style)
{
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!check_send_configuration (fb))
return;
if (fb->mail_display && fb->mail_display->current_message) {
do_forward_non_attached (fb->folder, NULL,
fb->mail_display->current_message,
GINT_TO_POINTER (style));
} else {
mail_get_message (fb->folder, fb->message_list->cursor_uid,
do_forward_non_attached, GINT_TO_POINTER (style),
mail_thread_new);
}
}
void
forward_inline (GtkWidget *widget, gpointer user_data)
{
forward_message (user_data, MAIL_CONFIG_FORWARD_INLINE);
}
void
forward_quoted (GtkWidget *widget, gpointer user_data)
{
forward_message (user_data, MAIL_CONFIG_FORWARD_QUOTED);
}
static void
do_forward_attach (CamelFolder *folder, GPtrArray *messages, CamelMimePart *part, char *subject, void *data)
{
CamelMimeMessage *message = data;
if (part) {
EMsgComposer *composer = forward_get_composer (message, subject);
if (composer) {
e_msg_composer_attach (composer, part);
gtk_widget_show (GTK_WIDGET (composer));
e_msg_composer_unset_changed (composer);
}
}
}
void
forward_attached (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = (FolderBrowser *) user_data;
GPtrArray *uids;
if (FOLDER_BROWSER_IS_DESTROYED (fb) || !check_send_configuration (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
mail_build_attachment (fb->folder, uids, do_forward_attach,
uids->len == 1 ? fb->mail_display->current_message : NULL);
}
void
forward (GtkWidget *widget, gpointer user_data)
{
MailConfigForwardStyle style = mail_config_get_default_forward_style ();
if (style == MAIL_CONFIG_FORWARD_ATTACHED)
forward_attached (widget, user_data);
else
forward_message (user_data, style);
}
static EMsgComposer *
redirect_get_composer (CamelMimeMessage *message)
{
const MailConfigAccount *account = NULL;
const CamelInternetAddress *to_addrs, *cc_addrs;
const GSList *accounts = NULL;
EMsgComposer *composer;
g_return_val_if_fail (message != NULL, NULL);
accounts = mail_config_get_accounts ();
to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
account = guess_me (to_addrs, cc_addrs, accounts);
if (!account) {
const char *source;
source = camel_mime_message_get_source (message);
account = mail_config_get_account_by_source_url (source);
}
if (!account)
account = mail_config_get_default_account ();
composer = e_msg_composer_new_redirect (message, account->name);
if (composer) {
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
GTK_SIGNAL_FUNC (composer_save_draft_cb), NULL);
} else {
g_warning ("Could not create composer");
}
return composer;
}
static void
do_redirect (CamelFolder *folder, char *uid, CamelMimeMessage *message, void *data)
{
EMsgComposer *composer;
if (!message)
return;
composer = redirect_get_composer (message);
if (composer) {
CamelDataWrapper *wrapper;
wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (message));
if (CAMEL_IS_MULTIPART (wrapper))
e_msg_composer_add_message_attachments (composer, message, FALSE);
gtk_widget_show (GTK_WIDGET (composer));
e_msg_composer_unset_changed (composer);
}
}
void
redirect (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = (FolderBrowser *) user_data;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!check_send_configuration (fb))
return;
if (fb->mail_display && fb->mail_display->current_message) {
do_redirect (fb->folder, NULL,
fb->mail_display->current_message,
NULL);
} else {
mail_get_message (fb->folder, fb->message_list->cursor_uid,
do_redirect, NULL, mail_thread_new);
}
}
static void
transfer_msg_done (gboolean ok, void *data)
{
FolderBrowser *fb = data;
int row;
if (ok && !FOLDER_BROWSER_IS_DESTROYED (fb)) {
row = e_tree_row_of_node (fb->message_list->tree,
e_tree_get_cursor (fb->message_list->tree));
/* If this is the last message and deleted messages
are hidden, select the previous */
if ((row + 1 == e_tree_row_count (fb->message_list->tree))
&& mail_config_get_hide_deleted ())
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS,
0, CAMEL_MESSAGE_DELETED, FALSE);
else
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT,
0, 0, FALSE);
}
gtk_object_unref (GTK_OBJECT (fb));
}
static void
transfer_msg (FolderBrowser *fb, gboolean delete_from_source)
{
const char *allowed_types[] = { "mail", "vtrash", NULL };
extern EvolutionShellClient *global_shell_client;
char *uri, *physical, *path, *desc;
static char *last = NULL;
GPtrArray *uids;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (last == NULL)
last = g_strdup ("");
if (delete_from_source)
desc = _("Move message(s) to");
else
desc = _("Copy message(s) to");
uri = NULL;
physical = NULL;
evolution_shell_client_user_select_folder (global_shell_client,
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (fb))),
desc, last,
allowed_types, &uri, &physical);
if (!uri)
return;
path = strchr (uri, '/');
if (path && strcmp (last, path) != 0) {
g_free (last);
last = g_strdup_printf ("evolution:%s", path);
}
g_free (uri);
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
if (delete_from_source) {
gtk_object_ref (GTK_OBJECT (fb));
mail_transfer_messages (fb->folder, uids, delete_from_source,
physical, 0, transfer_msg_done, fb);
} else {
mail_transfer_messages (fb->folder, uids, delete_from_source,
physical, 0, NULL, NULL);
}
g_free(physical);
}
void
move_msg_cb (GtkWidget *widget, gpointer user_data)
{
transfer_msg (user_data, TRUE);
}
void
move_msg (BonoboUIComponent *uih, void *user_data, const char *path)
{
transfer_msg (user_data, TRUE);
}
void
copy_msg_cb (GtkWidget *widget, gpointer user_data)
{
transfer_msg (user_data, FALSE);
}
void
copy_msg (BonoboUIComponent *uih, void *user_data, const char *path)
{
transfer_msg (user_data, FALSE);
}
/* Copied from e-shell-view.c */
static GtkWidget *
find_socket (GtkContainer *container)
{
GList *children, *tmp;
children = gtk_container_children (container);
while (children) {
if (BONOBO_IS_SOCKET (children->data))
return children->data;
else if (GTK_IS_CONTAINER (children->data)) {
GtkWidget *socket = find_socket (children->data);
if (socket)
return socket;
}
tmp = children->next;
g_list_free_1 (children);
children = tmp;
}
return NULL;
}
static void
popup_listener_cb (BonoboListener *listener,
char *event_name,
CORBA_any *any,
CORBA_Environment *ev,
gpointer user_data)
{
char *type = bonobo_event_subtype (event_name);
if (!strcmp (type, "Destroy")) {
gtk_widget_destroy (GTK_WIDGET (user_data));
}
g_free (type);
}
void
addrbook_sender (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
CamelMimeMessage *msg = NULL;
const CamelInternetAddress *addr;
gchar *addr_str;
GtkWidget *win;
GtkWidget *control;
GtkWidget *socket;
/* FIXME: make this use the cursor message id */
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
msg = fb->mail_display->current_message;
if (msg == NULL)
return;
addr = camel_mime_message_get_from (msg);
if (addr == NULL)
return;
addr_str = camel_address_format (CAMEL_ADDRESS (addr));
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (win), _("Sender"));
control = bonobo_widget_new_control ("OAFIID:GNOME_Evolution_Addressbook_AddressPopup",
CORBA_OBJECT_NIL);
bonobo_widget_set_property (BONOBO_WIDGET (control),
"email", addr_str,
NULL);
bonobo_event_source_client_add_listener (bonobo_widget_get_objref (BONOBO_WIDGET (control)),
popup_listener_cb, NULL, NULL, win);
socket = find_socket (GTK_CONTAINER (control));
gtk_signal_connect_object (GTK_OBJECT (socket),
"destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (win));
gtk_container_add (GTK_CONTAINER (win), control);
gtk_widget_show_all (win);
}
void
add_sender_to_addrbook (BonoboUIComponent *uih, void *user_data, const char *path)
{
addrbook_sender (NULL, user_data);
}
void
apply_filters (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GPtrArray *uids;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
mail_filter_on_demand (fb->folder, uids);
}
void
select_all (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
ESelectionModel *etsm;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (GTK_WIDGET_HAS_FOCUS (fb->mail_display->html)) {
gtk_html_select_all (fb->mail_display->html);
} else {
etsm = e_tree_get_selection_model (fb->message_list->tree);
e_selection_model_select_all (etsm);
}
}
/* Thread selection */
typedef struct thread_select_info {
MessageList *ml;
GPtrArray *paths;
} thread_select_info_t;
static gboolean
select_node (ETreeModel *tm, ETreePath path, gpointer user_data)
{
thread_select_info_t *tsi = (thread_select_info_t *) user_data;
g_ptr_array_add (tsi->paths, path);
return FALSE; /*not done yet*/
}
static void
thread_select_foreach (ETreePath path, gpointer user_data)
{
thread_select_info_t *tsi = (thread_select_info_t *) user_data;
ETreeModel *tm = tsi->ml->model;
ETreePath node;
/* @path part of the initial selection. If it has children,
* we select them as well. If it doesn't, we select its siblings and
* their children (ie, the current node must be inside the thread
* that the user wants to mark.
*/
if (e_tree_model_node_get_first_child (tm, path))
node = path;
else {
node = e_tree_model_node_get_parent (tm, path);
/* Let's make an exception: if no parent, then we're about
* to mark the whole tree. No. */
if (e_tree_model_node_is_root (tm, node))
node = path;
}
e_tree_model_node_traverse (tm, node, select_node, tsi);
}
void
select_thread (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
ETreeSelectionModel *selection_model;
thread_select_info_t tsi;
int i;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
/* For every selected item, select the thread containing it.
* We can't alter the selection while iterating through it,
* so build up a list of paths.
*/
tsi.ml = fb->message_list;
tsi.paths = g_ptr_array_new ();
e_tree_selected_path_foreach (fb->message_list->tree, thread_select_foreach, &tsi);
selection_model = E_TREE_SELECTION_MODEL (e_tree_get_selection_model (fb->message_list->tree));
for (i = 0; i < tsi.paths->len; i++)
e_tree_selection_model_add_to_selection (selection_model,
tsi.paths->pdata[i]);
g_ptr_array_free (tsi.paths, TRUE);
}
void
invert_selection (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
ESelectionModel *etsm;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
etsm = e_tree_get_selection_model (fb->message_list->tree);
e_selection_model_invert_selection (etsm);
}
/* flag all selected messages. Return number flagged */
static int
flag_messages (FolderBrowser *fb, guint32 mask, guint32 set)
{
GPtrArray *uids;
int i;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return 0;
/* could just use specific callback but i'm lazy */
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
camel_folder_freeze (fb->folder);
for (i = 0; i < uids->len; i++) {
camel_folder_set_message_flags (fb->folder, uids->pdata[i], mask, set);
g_free (uids->pdata[i]);
}
camel_folder_thaw (fb->folder);
g_ptr_array_free (uids, TRUE);
return i;
}
static int
toggle_flags (FolderBrowser *fb, guint32 mask)
{
GPtrArray *uids;
int i;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return 0;
/* could just use specific callback but i'm lazy */
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
camel_folder_freeze (fb->folder);
for (i = 0; i < uids->len; i++) {
int flags;
flags = camel_folder_get_message_flags (fb->folder, uids->pdata[i]);
if (flags & mask)
camel_folder_set_message_flags (fb->folder, uids->pdata[i], mask, 0);
else {
if ((mask & CAMEL_MESSAGE_FLAGGED) && (flags & CAMEL_MESSAGE_DELETED))
camel_folder_set_message_flags (fb->folder, uids->pdata[i], CAMEL_MESSAGE_DELETED, 0);
camel_folder_set_message_flags (fb->folder, uids->pdata[i], mask, mask);
}
g_free (uids->pdata[i]);
}
camel_folder_thaw (fb->folder);
g_ptr_array_free (uids, TRUE);
return i;
}
void
mark_as_seen (BonoboUIComponent *uih, void *user_data, const char *path)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
}
void
mark_as_unseen (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
/* Remove the automatic mark-as-read timer first */
if (fb->seen_id) {
gtk_timeout_remove (fb->seen_id);
fb->seen_id = 0;
}
flag_messages (fb, CAMEL_MESSAGE_SEEN, 0);
}
void
mark_all_as_seen (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GPtrArray *uids;
int i;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
uids = camel_folder_get_uids (fb->folder);
camel_folder_freeze (fb->folder);
for (i = 0; i < uids->len; i++)
camel_folder_set_message_flags (fb->folder, uids->pdata[i], CAMEL_MESSAGE_SEEN, ~0);
camel_folder_thaw (fb->folder);
g_ptr_array_free (uids, TRUE);
}
void
mark_as_important (BonoboUIComponent *uih, void *user_data, const char *path)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0);
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED);
}
void
mark_as_unimportant (BonoboUIComponent *uih, void *user_data, const char *path)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_FLAGGED, 0);
}
void
toggle_as_important (BonoboUIComponent *uih, void *user_data, const char *path)
{
toggle_flags (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_FLAGGED);
}
void
mark_as_needing_reply (BonoboUIComponent *uih, void *user_data, const char *path)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0);
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_NEEDS_REPLY, CAMEL_MESSAGE_NEEDS_REPLY);
}
void
mark_as_not_needing_reply (BonoboUIComponent *uih, void *user_data, const char *path)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_NEEDS_REPLY, 0);
}
void
toggle_need_reply (BonoboUIComponent *uih, void *user_data, const char *path)
{
toggle_flags (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_NEEDS_REPLY);
}
void
zoom_in (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
gtk_html_zoom_in (fb->mail_display->html);
}
void
zoom_out (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
gtk_html_zoom_out (fb->mail_display->html);
}
void
zoom_reset (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
gtk_html_zoom_reset (fb->mail_display->html);
}
static void
do_edit_messages (CamelFolder *folder, GPtrArray *uids, GPtrArray *messages, void *data)
{
/*FolderBrowser *fb = data;*/
int i;
if (messages == NULL)
return;
for (i = 0; i < messages->len; i++) {
EMsgComposer *composer;
camel_medium_remove_header (CAMEL_MEDIUM (messages->pdata[i]), "X-Mailer");
composer = e_msg_composer_new_with_message (messages->pdata[i]);
if (composer) {
gtk_signal_connect (GTK_OBJECT (composer), "send",
composer_send_cb, NULL);
gtk_signal_connect (GTK_OBJECT (composer), "postpone",
composer_postpone_cb, NULL);
/* FIXME: we want to pass data to this callback so
we can remove the old draft when they save again */
gtk_signal_connect (GTK_OBJECT (composer), "save-draft",
composer_save_draft_cb, NULL);
gtk_widget_show (GTK_WIDGET (composer));
}
}
}
static gboolean
are_you_sure (const char *msg, GPtrArray *uids, FolderBrowser *fb)
{
GtkWidget *dialog;
char *buf;
int button, i;
buf = g_strdup_printf (msg, uids->len);
dialog = e_gnome_ok_cancel_dialog_parented (buf, NULL, NULL, FB_WINDOW (fb));
button = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
if (button != 0) {
for (i = 0; i < uids->len; i++)
g_free (uids->pdata[i]);
g_ptr_array_free (uids, TRUE);
}
return button == 0;
}
static void
edit_msg_internal (FolderBrowser *fb)
{
GPtrArray *uids;
if (!check_send_configuration (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
if (uids->len > 10 && !are_you_sure (_("Are you sure you want to edit all %d messages?"), uids, fb)) {
int i;
for (i = 0; i < uids->len; i++)
g_free (uids->pdata[i]);
g_ptr_array_free (uids, TRUE);
return;
}
mail_get_messages (fb->folder, uids, do_edit_messages, fb);
}
void
edit_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!folder_browser_is_drafts (fb)) {
GtkWidget *dialog;
dialog = gnome_warning_dialog_parented (_("You may only edit messages saved\n"
"in the Drafts folder."),
FB_WINDOW (fb));
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
edit_msg_internal (fb);
}
static void
do_resend_messages (CamelFolder *folder, GPtrArray *uids, GPtrArray *messages, void *data)
{
int i;
for (i = 0; i < messages->len; i++) {
/* generate a new Message-Id because they need to be unique */
camel_mime_message_set_message_id (messages->pdata[i], NULL);
}
/* "Resend" should open up the composer to let the user edit the message */
do_edit_messages (folder, uids, messages, data);
}
void
resend_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GPtrArray *uids;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!folder_browser_is_sent (fb)) {
GtkWidget *dialog;
dialog = gnome_warning_dialog_parented (_("You may only resend messages\n"
"in the Sent folder."),
FB_WINDOW (fb));
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
if (!check_send_configuration (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
if (uids->len > 10 && !are_you_sure (_("Are you sure you want to resend all %d messages?"), uids, fb)) {
int i;
for (i = 0; i < uids->len; i++)
g_free (uids->pdata[i]);
g_ptr_array_free (uids, TRUE);
return;
}
mail_get_messages (fb->folder, uids, do_resend_messages, fb);
}
void
search_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GtkWidget *w;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (fb->mail_display->current_message == NULL) {
GtkWidget *dialog;
dialog = gnome_warning_dialog_parented (_("No Message Selected"), FB_WINDOW (fb));
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
w = mail_search_new (fb->mail_display);
gtk_widget_show_all (w);
}
void
load_images (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
mail_display_load_images (fb->mail_display);
}
static void
save_msg_ok (GtkWidget *widget, gpointer user_data)
{
CamelFolder *folder;
GPtrArray *uids;
const char *path;
int fd, ret = 0;
struct stat st;
path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (user_data));
if (path[0] == '\0')
return;
/* make sure we can actually save to it... */
if (stat (path, &st) != -1 && !S_ISREG (st.st_mode))
return;
fd = open (path, O_RDONLY);
if (fd != -1) {
GtkWidget *dialog;
GtkWidget *text;
close (fd);
dialog = gnome_dialog_new (_("Overwrite file?"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
e_gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (user_data));
text = gtk_label_new (_("A file by that name already exists.\nOverwrite it?"));
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), text, TRUE, TRUE, 4);
gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);
gtk_widget_show (text);
ret = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
}
if (ret == 0) {
folder = gtk_object_get_data (GTK_OBJECT (user_data), "folder");
uids = gtk_object_get_data (GTK_OBJECT (user_data), "uids");
gtk_object_remove_no_notify (GTK_OBJECT (user_data), "uids");
mail_save_messages (folder, uids, path, NULL, NULL);
gtk_widget_destroy (GTK_WIDGET (user_data));
}
}
static void
save_msg_destroy (gpointer user_data)
{
GPtrArray *uids = user_data;
if (uids) {
int i;
for (i = 0; i < uids->len; i++)
g_free (uids->pdata[i]);
g_ptr_array_free (uids, TRUE);
}
}
void
save_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GtkFileSelection *filesel;
GPtrArray *uids;
char *title, *path;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
if (uids->len == 1)
title = _("Save Message As...");
else
title = _("Save Messages As...");
filesel = GTK_FILE_SELECTION (gtk_file_selection_new (title));
path = g_strdup_printf ("%s/", g_get_home_dir ());
gtk_file_selection_set_filename (filesel, path);
g_free (path);
gtk_object_set_data_full (GTK_OBJECT (filesel), "uids", uids, save_msg_destroy);
gtk_object_set_data (GTK_OBJECT (filesel), "folder", fb->folder);
gtk_signal_connect (GTK_OBJECT (filesel->ok_button),
"clicked", GTK_SIGNAL_FUNC (save_msg_ok), filesel);
gtk_signal_connect_object (GTK_OBJECT (filesel->cancel_button),
"clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (filesel));
gtk_widget_show (GTK_WIDGET (filesel));
}
void
delete_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int deleted, row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
deleted = flag_messages (fb, CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN,
CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN);
/* Select the next message if we are only deleting one message */
if (deleted == 1) {
row = e_tree_row_of_node (fb->message_list->tree,
e_tree_get_cursor (fb->message_list->tree));
/* If this is the last message and deleted messages
are hidden, select the previous */
if ((row+1 == e_tree_row_count (fb->message_list->tree))
&& mail_config_get_hide_deleted ())
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS,
0, CAMEL_MESSAGE_DELETED, FALSE);
else
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT,
0, 0, FALSE);
}
}
void
undelete_msg (GtkWidget *button, gpointer user_data)
{
flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0);
}
void
next_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT, 0, 0, FALSE);
}
void
next_unread_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT,
0, CAMEL_MESSAGE_SEEN, TRUE);
}
void
next_flagged_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT,
CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED, FALSE);
}
void
previous_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS,
0, 0, FALSE);
}
void
previous_unread_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS,
0, CAMEL_MESSAGE_SEEN, TRUE);
}
void
previous_flagged_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
int row;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS,
CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED, TRUE);
}
struct _expunged_folder_data {
FolderBrowser *fb;
gboolean hidedeleted;
};
static void
expunged_folder (CamelFolder *f, void *data)
{
FolderBrowser *fb = ((struct _expunged_folder_data *) data)->fb;
gboolean hidedeleted = ((struct _expunged_folder_data *) data)->hidedeleted;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
fb->expunging = NULL;
message_list_set_hidedeleted (fb->message_list, hidedeleted);
g_free (data);
}
static gboolean
confirm_expunge (FolderBrowser *fb)
{
GtkWidget *dialog, *label, *checkbox;
int button;
if (!mail_config_get_confirm_expunge ())
return TRUE;
dialog = gnome_dialog_new (_("Warning"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
e_gnome_dialog_set_parent (GNOME_DIALOG (dialog), FB_WINDOW (fb));
label = gtk_label_new (_("This operation will permanently erase all messages marked as deleted. If you continue, you will not be able to recover these messages.\n\nReally erase these messages?"));
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 4);
checkbox = gtk_check_button_new_with_label (_("Do not ask me again."));
gtk_object_ref (GTK_OBJECT (checkbox));
gtk_widget_show (checkbox);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), checkbox, TRUE, TRUE, 4);
button = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
if (button == 0 && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)))
mail_config_set_confirm_expunge (FALSE);
gtk_object_unref (GTK_OBJECT (checkbox));
if (button == 0)
return TRUE;
else
return FALSE;
}
void
expunge_folder (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (fb->folder && (fb->expunging == NULL || fb->folder != fb->expunging) && confirm_expunge (fb)) {
struct _expunged_folder_data *data;
CamelMessageInfo *info;
data = g_malloc (sizeof (*data));
data->fb = fb;
data->hidedeleted = fb->message_list->hidedeleted;
/* hide the deleted messages so user can't click on them while we expunge */
message_list_set_hidedeleted (fb->message_list, TRUE);
/* Only blank the mail display if the message being
viewed is one of those to be expunged */
if (fb->loaded_uid) {
info = camel_folder_get_message_info (fb->folder, fb->loaded_uid);
if (!info || info->flags & CAMEL_MESSAGE_DELETED)
mail_display_set_message (fb->mail_display, NULL);
}
fb->expunging = fb->folder;
mail_expunge_folder (fb->folder, expunged_folder, data);
}
}
/********************** Begin Filter Editor ********************/
static GtkWidget *filter_editor = NULL;
static void
filter_editor_destroy (GtkWidget *dialog, gpointer user_data)
{
filter_editor = NULL;
}
static void
filter_editor_clicked (GtkWidget *dialog, int button, FolderBrowser *fb)
{
FilterContext *fc;
if (button == 0) {
char *user;
fc = gtk_object_get_data (GTK_OBJECT (dialog), "context");
user = g_strdup_printf ("%s/filters.xml", evolution_dir);
rule_context_save ((RuleContext *)fc, user);
g_free (user);
}
if (button != -1) {
gnome_dialog_close (GNOME_DIALOG (dialog));
}
}
static const char *filter_source_names[] = {
"incoming",
"outgoing",
NULL,
};
void
filter_edit (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
FilterContext *fc;
char *user, *system;
if (filter_editor) {
gdk_window_raise (GTK_WIDGET (filter_editor)->window);
return;
}
fc = filter_context_new ();
user = g_strdup_printf ("%s/filters.xml", evolution_dir);
system = EVOLUTION_DATADIR "/evolution/filtertypes.xml";
rule_context_load ((RuleContext *)fc, system, user);
g_free (user);
if (((RuleContext *)fc)->error) {
GtkWidget *dialog;
char *err;
err = g_strdup_printf (_("Error loading filter information:\n%s"),
((RuleContext *)fc)->error);
dialog = gnome_warning_dialog_parented (err, FB_WINDOW (fb));
g_free (err);
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
gtk_widget_show (dialog);
return;
}
filter_editor = (GtkWidget *)filter_editor_new (fc, filter_source_names);
gnome_dialog_set_parent (GNOME_DIALOG (filter_editor), FB_WINDOW (fb));
gtk_window_set_title (GTK_WINDOW (filter_editor), _("Filters"));
gtk_object_set_data_full (GTK_OBJECT (filter_editor), "context", fc, (GtkDestroyNotify)gtk_object_unref);
gtk_signal_connect (GTK_OBJECT (filter_editor), "clicked", filter_editor_clicked, fb);
gtk_signal_connect (GTK_OBJECT (filter_editor), "destroy", filter_editor_destroy, NULL);
gtk_widget_show (GTK_WIDGET (filter_editor));
}
/********************** End Filter Editor ********************/
void
vfolder_edit_vfolders (BonoboUIComponent *uih, void *user_data, const char *path)
{
vfolder_edit ();
}
static MailAccountsDialog *accounts_dialog = NULL;
static void
accounts_dialog_close (GtkWidget *widget, gpointer user_data)
{
accounts_dialog = NULL;
}
void
providers_config (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (!accounts_dialog) {
accounts_dialog = mail_accounts_dialog_new (fb->shell);
gtk_widget_set_parent_window (GTK_WIDGET (accounts_dialog),
GTK_WIDGET (FB_WINDOW (fb))->window);
gtk_signal_connect (GTK_OBJECT (accounts_dialog), "destroy",
accounts_dialog_close, NULL);
gnome_dialog_set_close (GNOME_DIALOG (accounts_dialog), TRUE);
gtk_widget_show (GTK_WIDGET (accounts_dialog));
} else {
gdk_window_raise (GTK_WIDGET (accounts_dialog)->window);
gtk_widget_grab_focus (GTK_WIDGET (accounts_dialog));
}
}
/* static void
header_print_cb (GtkHTML *html, GnomePrintContext *print_context,
double x, double y, double width, double height, gpointer user_data)
{
printf ("header_print_cb %f,%f x %f,%f\n", x, y, width, height);
gnome_print_newpath (print_context);
gnome_print_setlinewidth (print_context, 12.0);
gnome_print_setrgbcolor (print_context, 1.0, 0.0, 0.0);
gnome_print_moveto (print_context, x, y);
gnome_print_lineto (print_context, x+width, y-height);
gnome_print_strokepath (print_context);
} */
struct footer_info {
GnomeFont *local_font;
gint page_num, pages;
};
static void
footer_print_cb (GtkHTML *html, GnomePrintContext *print_context,
double x, double y, double width, double height, gpointer user_data)
{
struct footer_info *info = (struct footer_info *) user_data;
if (info->local_font) {
gchar *text = g_strdup_printf (_("Page %d of %d"), info->page_num, info->pages);
gdouble tw = gnome_font_get_width_string (info->local_font, text);
gnome_print_newpath (print_context);
gnome_print_setrgbcolor (print_context, .0, .0, .0);
gnome_print_moveto (print_context, x + width - tw, y - gnome_font_get_ascender (info->local_font));
gnome_print_setfont (print_context, info->local_font);
gnome_print_show (print_context, text);
g_free (text);
info->page_num++;
}
}
static void
footer_info_free (struct footer_info *info)
{
if (info->local_font)
gnome_font_unref (info->local_font);
g_free (info);
}
static struct footer_info *
footer_info_new (GtkHTML *html, GnomePrintContext *pc, gdouble *line)
{
struct footer_info *info;
info = g_new (struct footer_info, 1);
info->local_font = gnome_font_new_closest ("Helvetica", GNOME_FONT_BOOK, FALSE, 10);
if (info->local_font) {
*line = gnome_font_get_ascender (info->local_font) + gnome_font_get_descender (info->local_font);
}
info->page_num = 1;
info->pages = gtk_html_print_get_pages_num (html, pc, 0.0, *line);
return info;
}
static void
do_mail_print (FolderBrowser *fb, gboolean preview)
{
GtkHTML *html;
GnomePrintContext *print_context;
GnomePrintMaster *print_master;
GnomePrintDialog *dialog;
GnomePrinter *printer = NULL;
gdouble line = 0.0;
int copies = 1;
int collate = FALSE;
struct footer_info *info;
if (!preview) {
dialog = GNOME_PRINT_DIALOG (gnome_print_dialog_new (_("Print Message"),
GNOME_PRINT_DIALOG_COPIES));
gnome_dialog_set_default (GNOME_DIALOG (dialog), GNOME_PRINT_PRINT);
e_gnome_dialog_set_parent (GNOME_DIALOG (dialog), FB_WINDOW (fb));
switch (gnome_dialog_run (GNOME_DIALOG (dialog))) {
case GNOME_PRINT_PRINT:
break;
case GNOME_PRINT_PREVIEW:
preview = TRUE;
break;
case -1:
return;
default:
gnome_dialog_close (GNOME_DIALOG (dialog));
return;
}
gnome_print_dialog_get_copies (dialog, &copies, &collate);
printer = gnome_print_dialog_get_printer (dialog);
gnome_dialog_close (GNOME_DIALOG (dialog));
}
print_master = gnome_print_master_new ();
if (printer)
gnome_print_master_set_printer (print_master, printer);
gnome_print_master_set_paper (print_master, gnome_paper_with_name (_("US-Letter")));
gnome_print_master_set_copies (print_master, copies, collate);
print_context = gnome_print_master_get_context (print_master);
html = GTK_HTML (gtk_html_new ());
mail_display_initialize_gtkhtml (fb->mail_display, html);
/* Set our 'printing' flag to true and render. This causes us
to ignoring any adjustments we made to accomodate the
user's theme. */
fb->mail_display->printing = TRUE;
mail_display_render (fb->mail_display, html);
gtk_html_print_set_master (html, print_master);
info = footer_info_new (html, print_context, &line);
gtk_html_print_with_header_footer (html, print_context, 0.0, line, NULL, footer_print_cb, info);
footer_info_free (info);
fb->mail_display->printing = FALSE;
gnome_print_master_close (print_master);
if (preview){
gboolean landscape = FALSE;
GnomePrintMasterPreview *preview;
preview = gnome_print_master_preview_new_with_orientation (
print_master, _("Print Preview"), landscape);
gtk_widget_show (GTK_WIDGET (preview));
} else {
int result = gnome_print_master_print (print_master);
if (result == -1){
e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
_("Printing of message failed"));
}
}
/* FIXME: We are leaking the GtkHTML object */
}
/* This is pretty evil. FolderBrowser's API should be extended to allow these sorts of
things to be done in a more natural way. */
/* <evil_code> */
struct blarg_this_sucks {
FolderBrowser *fb;
gboolean preview;
};
static void
done_message_selected (CamelFolder *folder, char *uid, CamelMimeMessage *msg, void *data)
{
struct blarg_this_sucks *blarg = data;
FolderBrowser *fb = blarg->fb;
gboolean preview = blarg->preview;
g_free (blarg);
mail_display_set_message (fb->mail_display, (CamelMedium *)msg);
g_free (fb->loaded_uid);
fb->loaded_uid = fb->loading_uid;
fb->loading_uid = NULL;
do_mail_print (fb, preview);
}
/* Ack! Most of this is copied from folder-browser.c */
static void
do_mail_fetch_and_print (FolderBrowser *fb, gboolean preview)
{
if (! fb->preview_shown) {
/* If the preview pane is closed, we have to do some
extra magic to load the message. */
struct blarg_this_sucks *blarg = g_new (struct blarg_this_sucks, 1);
blarg->fb = fb;
blarg->preview = preview;
fb->loading_id = 0;
/* if we are loading, then set a pending, but leave the loading, coudl cancel here (?) */
if (fb->loading_uid) {
g_free (fb->pending_uid);
fb->pending_uid = g_strdup (fb->new_uid);
} else {
if (fb->new_uid) {
fb->loading_uid = g_strdup (fb->new_uid);
mail_get_message (fb->folder, fb->loading_uid, done_message_selected, blarg, mail_thread_new);
} else {
mail_display_set_message (fb->mail_display, NULL);
g_free (blarg);
}
}
} else {
do_mail_print (fb, preview);
}
}
/* </evil_code> */
void
print_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
do_mail_fetch_and_print (fb, FALSE);
}
void
print_preview_msg (GtkWidget *button, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
do_mail_fetch_and_print (fb, TRUE);
}
/******************** Begin Subscription Dialog ***************************/
static GtkObject *subscribe_dialog = NULL;
static void
subscribe_dialog_destroy (GtkWidget *widget, gpointer user_data)
{
gtk_object_unref (subscribe_dialog);
subscribe_dialog = NULL;
}
void
manage_subscriptions (BonoboUIComponent *uih, void *user_data, const char *path)
{
if (!subscribe_dialog) {
subscribe_dialog = subscribe_dialog_new ();
gtk_signal_connect (GTK_OBJECT (SUBSCRIBE_DIALOG (subscribe_dialog)->app), "destroy",
subscribe_dialog_destroy, NULL);
gnome_dialog_set_close (GNOME_DIALOG (SUBSCRIBE_DIALOG (subscribe_dialog)->app), TRUE);
subscribe_dialog_show (subscribe_dialog);
} else {
gdk_window_raise (SUBSCRIBE_DIALOG (subscribe_dialog)->app->window);
}
}
/******************** End Subscription Dialog ***************************/
void
configure_folder (BonoboUIComponent *uih, void *user_data, const char *path)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (fb->uri && strncmp (fb->uri, "vfolder:", 8) == 0) {
vfolder_edit_rule (fb->uri);
} else {
mail_local_reconfigure_folder (fb);
}
}
static void
do_view_message (CamelFolder *folder, char *uid, CamelMimeMessage *message, void *data)
{
FolderBrowser *fb = FOLDER_BROWSER (data);
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (message) {
GtkWidget *mb;
camel_folder_set_message_flags (folder, uid, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
mb = message_browser_new (fb->shell, fb->uri, uid);
gtk_widget_show (mb);
}
}
void
view_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
GPtrArray *uids;
int i;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
uids = g_ptr_array_new ();
message_list_foreach (fb->message_list, enumerate_msg, uids);
if (uids->len > 10 && !are_you_sure (_("Are you sure you want to open all %d messages in separate windows?"), uids, fb))
return;
for (i = 0; i < uids->len; i++) {
mail_get_message (fb->folder, uids->pdata [i], do_view_message, fb, mail_thread_queued);
g_free (uids->pdata [i]);
}
g_ptr_array_free (uids, TRUE);
}
void
open_msg (GtkWidget *widget, gpointer user_data)
{
FolderBrowser *fb = FOLDER_BROWSER (user_data);
extern CamelFolder *outbox_folder;
if (FOLDER_BROWSER_IS_DESTROYED (fb))
return;
if (folder_browser_is_drafts (fb) || fb->folder == outbox_folder)
edit_msg_internal (fb);
else
view_msg (NULL, user_data);
}
void
open_message (BonoboUIComponent *uih, void *user_data, const char *path)
{
open_msg (NULL, user_data);
}
void
edit_message (BonoboUIComponent *uih, void *user_data, const char *path)
{
edit_msg (NULL, user_data);
}
void
stop_threads (BonoboUIComponent *uih, void *user_data, const char *path)
{
camel_operation_cancel (NULL);
}
static void
empty_trash_expunged_cb (CamelFolder *folder, void *data)
{
camel_object_unref (CAMEL_OBJECT (folder));
}
void
empty_trash (BonoboUIComponent *uih, void *user_data, const char *path)
{
MailConfigAccount *account;
CamelProvider *provider;
const GSList *accounts;
CamelFolder *vtrash;
FolderBrowser *fb;
CamelException ex;
fb = user_data ? FOLDER_BROWSER (user_data) : NULL;
if (fb && !confirm_expunge (fb))
return;
camel_exception_init (&ex);
/* expunge all remote stores */
accounts = mail_config_get_accounts ();
while (accounts) {
account = accounts->data;
/* make sure this is a valid source */
if (account->source && account->source->enabled && account->source->url) {
provider = camel_session_get_provider (session, account->source->url, &ex);
if (provider) {
/* make sure this store is a remote store */
if (provider->flags & CAMEL_PROVIDER_IS_STORAGE &&
provider->flags & CAMEL_PROVIDER_IS_REMOTE) {
vtrash = mail_tool_get_trash (account->source->url, FALSE, &ex);
if (vtrash) {
mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
}
}
}
/* clear the exception for the next round */
camel_exception_clear (&ex);
}
accounts = accounts->next;
}
/* Now empty the local trash folder */
vtrash = mail_tool_get_trash ("file:/", TRUE, &ex);
if (vtrash) {
mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
}
camel_exception_clear (&ex);
}
|