summaryrefslogtreecommitdiffstats
path: root/moz/mozilla-source-1.0.patch
blob: 46787d6bac99793ff011c97ec40720bd5e10612d (plain)
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
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
Index: directory/xpcom/base/public/nsILDAPConnection.idl
===================================================================
RCS file: /mozilla/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl	22 Oct 2003 02:37:04 -0000	1.1.1.1
+++ miss/build/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl	22 Oct 2003 09:45:04 -0000	1.2
@@ -69,7 +69,7 @@
      * @exception NS_ERROR_FAILURE              
      * @exception NS_ERROR_UNEXPECTED           internal error
      */
-    void init(in string aHost, in short aPort, in boolean aSSL,
+    void init(in string aHost, in long aPort, in boolean aSSL,
               in wstring aBindName, 
               in nsILDAPMessageListener aMessageListener);
 
Index: directory/xpcom/base/src/nsLDAPConnection.cpp
===================================================================
RCS file: /mozilla/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp	22 Oct 2003 02:37:04 -0000	1.1.1.1
+++ miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp	22 Oct 2003 09:45:04 -0000	1.2
@@ -48,7 +48,6 @@
 #include "nsIConsoleService.h"
 #include "nsIDNSService.h"
 #include "nsIRequestObserver.h"
-#include "nsIProxyObjectManager.h"
 #include "netCore.h"
 
 const char kConsoleServiceContractId[] = "@mozilla.org/consoleservice;1";
@@ -169,11 +168,10 @@
 
 
 NS_IMETHODIMP
-nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, PRBool aSSL,
+nsLDAPConnection::Init(const char *aHost, PRInt32 aPort, PRBool aSSL,
                        const PRUnichar *aBindName, 
                        nsILDAPMessageListener *aMessageListener)
 {
-    nsCOMPtr<nsIDNSListener> selfProxy;
     nsresult rv;
 
     if ( !aHost || !aMessageListener) {
@@ -222,22 +220,6 @@
         return NS_ERROR_FAILURE;
     }
 
-    // Get a proxy object so the callback happens on the current thread.
-    // This is now a Synchronous proxy, due to the fact that the DNS
-    // service hands out data which it later deallocates, and the async
-    // proxy makes this unreliable. See bug 102227 for more details.
-    //
-    rv = NS_GetProxyForObject(NS_CURRENT_EVENTQ,
-                              NS_GET_IID(nsIDNSListener), 
-                              NS_STATIC_CAST(nsIDNSListener*, this), 
-                              PROXY_SYNC | PROXY_ALWAYS, 
-                              getter_AddRefs(selfProxy));
-
-    if (NS_FAILED(rv)) {
-        NS_ERROR("nsLDAPConnection::Init(): couldn't "
-                 "create proxy to this object for callback");
-        return NS_ERROR_FAILURE;
-    }
 
     // Do the pre-resolve of the hostname, using the DNS service. This
     // will also initialize the LDAP connection properly, once we have
@@ -256,7 +238,8 @@
         return NS_ERROR_FAILURE;
     }
     rv = pDNSService->Lookup(aHost, 
-                             selfProxy,
+                             //selfProxy,
+                             this,   // SDBC change
                              nsnull, 
                              getter_AddRefs(mDNSRequest));
 
Index: directory/xpcom/base/src/nsLDAPConnection.h
===================================================================
RCS file: /mozilla/mozilla/directory/xpcom/base/src/nsLDAPConnection.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.h	22 Oct 2003 02:37:04 -0000	1.1.1.1
+++ miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.h	22 Oct 2003 09:45:04 -0000	1.2
@@ -119,7 +119,7 @@
     nsSupportsHashtable *mPendingOperations; // keep these around for callbacks
     nsLDAPConnectionLoop *mRunnable;    // nsIRunnable object
 
-    PRInt16 mPort;                      // The LDAP port we're binding to
+    PRInt32 mPort;                      // The LDAP port we're binding to
     PRBool mSSL;                        // the options
 
     nsCString mResolvedIP;              // Preresolved list of host IPs
Index: mailnews/addrbook/Makefile.in
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/Makefile.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/Makefile.in	22 Oct 2003 02:43:08 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/Makefile.in	9 Dec 2003 03:27:41 -0000	1.2
@@ -31,7 +31,7 @@
 EXTRA_COMPONENTS += src/nsLDAPPrefsService.js
 endif
 
-DIRS		= public src build
+DIRS		= public src build
 
 include $(topsrcdir)/config/rules.mk
 
Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp	22 Oct 2003 09:45:04 -0000	1.2
@@ -39,6 +39,7 @@
 #include "nsAbBoolExprToLDAPFilter.h"
 #include "nsAbLDAPProperties.h"
 #include "nsXPIDLString.h"
+#include "nsAbUtils.h"
 
 const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ;
 const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ;
@@ -80,6 +81,35 @@
     if (count == 0)
         return NS_OK;
 
+    /*
+     * 3rd party query integration with Mozilla is achieved 
+     * by calling nsAbLDAPDirectoryQuery::DoQuery(). Thus
+     * we can arrive here with a query asking for all the
+     * ldap attributes using the card:nsIAbCard interface.
+     *
+     * So we need to check that we are not creating a condition 
+     * filter against this otherwise we can end an 
+     * invalid filter equal to "(|)".
+    */
+
+    if (count == 1 )
+    {
+        nsCOMPtr<nsISupports> item;
+        rv = childExpressions->GetElementAt (0, getter_AddRefs (item));
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
+        if (NS_SUCCEEDED(rv))
+        {
+            nsXPIDLCString name;
+            rv = childCondition->GetName (getter_Copies (name));
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            if(name.Equals("card:nsIAbCard"))
+                return NS_OK;
+        }
+    }
+
     filter += NS_LITERAL_CSTRING("(");
     switch (operation)
     {
@@ -157,13 +187,16 @@
     rv = condition->GetName (getter_Copies (name));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    const char* ldapProperty = name.get ();
+    CharPtrArrayGuard attrs;
     if (flags & TRANSLATE_CARD_PROPERTY)
     {
-        const MozillaLdapPropertyRelation* p =
-            MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ());
-        if (p)
-            ldapProperty = p->ldapProperty;
+        if(const MozillaLdapPropertyRelation* property =
+            MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ()))
+        {
+            // allow even single ldap attribute mapppings to go through this to simplify the filter creation later.
+            rv = MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (property->ldapProperty, attrs.GetSizeAddr(), attrs.GetArrayAddr() );
+            NS_ENSURE_SUCCESS(rv, rv);
+        }
         else if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY))
             return NS_OK;
     }
@@ -173,6 +206,37 @@
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ConvertUCS2toUTF8 vUTF8 (value);
 
+    // check if using multiple ldap attributes
+    if(attrs.GetSize() == 1 ) 
+        GenerateSingleFilter(conditionType,filter,vUTF8,attrs.GetArray()[0]);
+    else
+    {
+        // add the opening brace if using multiple ldap attributes
+        switch (conditionType)
+        {
+            // 'NOT' conditionals use the 'AND' operator 
+            case nsIAbBooleanConditionTypes::DoesNotExist:
+            case nsIAbBooleanConditionTypes::DoesNotContain:
+            case nsIAbBooleanConditionTypes::IsNot:
+                filter += NS_LITERAL_CSTRING("(&");
+                break;
+            default:
+                filter += NS_LITERAL_CSTRING("(|");
+                break;
+        }
+        GenerateMultipleFilter(conditionType,filter,vUTF8,&attrs);
+        // add the closing brace if using multiple ldap attributes
+        filter += NS_LITERAL_CSTRING(")");
+    }
+
+    return rv;
+}
+void nsAbBoolExprToLDAPFilter:: GenerateSingleFilter(
+    nsAbBooleanConditionType conditionType,
+    nsCString& filter,
+    NS_ConvertUCS2toUTF8 &vUTF8,
+    const char *ldapProperty)
+{
     switch (conditionType)
     {
         case nsIAbBooleanConditionTypes::DoesNotExist:
@@ -253,7 +317,47 @@
         default:
             break;
     }
-
-    return rv;
 }
+void nsAbBoolExprToLDAPFilter:: GenerateMultipleFilter(
+    nsAbBooleanConditionType conditionType,
+    nsCString& filter,
+    NS_ConvertUCS2toUTF8 &vUTF8,
+    CharPtrArrayGuard *pAttrs)
+{
+    PRUint16 i = 0;
+    PRUint16 inner = 0;
 
+    /*
+     * This function is based on the fact that we are trying to generate support
+     * for multiple occurring ldap attributes. Consider the following query:
+     * (PagerNumber,=,123456) where PagerNumber = pager|pagerphone translates to: 
+     * (|(&(pager=*)(pager=123456))(&(!(pager=*))(pagerphone=123456)))
+     * This can be shortened to:
+     * (|(pager=123456)(&(!(pager=*))(pagerphone=123456)))
+     *
+     * i.e. use the first occurring attribute if it exists otherwise if first 
+     * does not exist use the second etc. The assumption is that the first
+     * always takes precedence.
+     * This translates to: 
+     *      GenerateSingleFilter(Is);
+     *          GenerateSingleFilter(DoesNotExists); 
+     *          GenerateSingleFilter(Is);
+    */
+
+    for (i = 0; i < pAttrs->GetSize(); i++)
+    {
+        if(i == 0)
+            GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]); 
+        else
+        {
+            filter += NS_LITERAL_CSTRING("(&");
+            nsAbBooleanConditionType doesNotExistsType = nsIAbBooleanConditionTypes::DoesNotExist; 
+            for(inner = 0; inner < i; ++inner)
+            {
+                GenerateSingleFilter(doesNotExistsType,filter,vUTF8,pAttrs->GetArray()[inner]); 
+            }
+            GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]); 
+            filter += NS_LITERAL_CSTRING(")");
+        }
+    }
+}
Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h	22 Oct 2003 09:45:04 -0000	1.2
@@ -42,6 +42,7 @@
 #include "nsIAbBooleanExpression.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "nsAbUtils.h"
 
 class nsAbBoolExprToLDAPFilter
 {
@@ -67,6 +68,16 @@
         nsIAbBooleanConditionString* condition,
         nsCString& filter,
         int flags);
+    static void GenerateMultipleFilter(
+       nsAbBooleanConditionType conditionType,
+       nsCString& filter,
+       NS_ConvertUCS2toUTF8 &vUTF8,
+       CharPtrArrayGuard *pAttrs);
+    static void GenerateSingleFilter(
+       nsAbBooleanConditionType conditionType,
+       nsCString& filter,
+       NS_ConvertUCS2toUTF8 &vUTF8,
+       const char *ldapProperty);
 };
 
 #endif
Index: mailnews/addrbook/src/nsAbLDAPDirectory.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -w -b -i -r1.1.1.1 -r1.3
--- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp	8 Jan 2004 04:26:20 -0000	1.3
@@ -112,15 +112,82 @@
 
     // use mURINoQuery to get a prefName
     nsCAutoString prefName;
-    prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) + NS_LITERAL_CSTRING(".uri");
+    prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) ;
 
     // turn moz-abldapdirectory://ldap_2.servers.nscpphonebook into -> "ldap_2.servers.nscpphonebook.uri"
     nsXPIDLCString URI;
-    rv = prefs->CopyCharPref(prefName.get(), getter_Copies(URI));
+    nsCAutoString uriPrefName;
+    uriPrefName = prefName + NS_LITERAL_CSTRING(".uri");
+    rv = prefs->CopyCharPref(uriPrefName.get(), getter_Copies(URI));
+    if (NS_FAILED(rv))
+    {
+        /*
+         * A recent change in Mozilla now means that the LDAP Address Book
+         * RDF Resource URI is based on the unique preference name value i.e.  
+         * [moz-abldapdirectory://prefName]
+         * Prior to this valid change it was based on the actual uri i.e. 
+         * [moz-abldapdirectory://host:port/basedn]
+         * Basing the resource on the prefName allows these attributes to 
+         * change. 
+         *
+         * But the uri value was also the means by which third-party
+         * products could integrate with Mozilla's LDAP Address Books without 
+         * necessarily having an entry in the preferences file or more importantly
+         * needing to be able to change the preferences entries. Thus to set the 
+         * URI Spec now, it is only necessary to read the uri pref entry, while in the case
+         * where it is not a preference, we need to replace the "moz-abldapdirectory".
+        */
+        nsCAutoString tempLDAPURL(mURINoQuery);
+        tempLDAPURL.ReplaceSubstring("moz-abldapdirectory:", "ldap:"); 
+        rv = mURL->SetSpec(tempLDAPURL);
     NS_ENSURE_SUCCESS(rv,rv);
     
+        nsCAutoString aHost;
+        mURL->GetHost(aHost);
+        aHost.ReplaceChar('.','_');
+        prefName = nsDependentCString("ldap_2.servers.") + aHost;
+        PRBool useSSL=0;
+        rv = prefs->GetBoolPref(
+                PromiseFlatCString(prefName
+                + NS_LITERAL_CSTRING(".UseSSL")).get(),
+                &useSSL
+            );
+        
+        // If use SSL,ldap url will look like this ldaps://host:port/.....
+        if (!NS_FAILED(rv) && useSSL)
+        {
+            tempLDAPURL.ReplaceSubstring("ldap:", "ldaps:"); 
+            rv = mURL->SetSpec(tempLDAPURL);
+        }
+        //NS_FAILED(rv) means ldap_2.servers.nscpphonebook.UseSSL not exist
+        rv = 0;
+
+    }
+    else
+    {
     rv = mURL->SetSpec(URI);
+    }
     NS_ENSURE_SUCCESS(rv, rv);
+
+    // get the login information, if there is any 
+    //
+    rv = prefs->GetCharPref(
+        PromiseFlatCString(prefName
+            + NS_LITERAL_CSTRING(".auth.dn")).get(),
+        getter_Copies(mLogin));
+    if (NS_FAILED(rv)) {
+        mLogin.Truncate();  // zero out mLogin
+    }
+
+    // get the password information, if there is any 
+    //
+    rv = prefs->GetCharPref(
+        PromiseFlatCString(prefName
+            + NS_LITERAL_CSTRING(".auth.pwd")).get(),
+        getter_Copies(mPassword));
+    if (NS_FAILED(rv)) {
+        mPassword.Truncate();  // zero out mLogin
+    }
 
     mConnection = do_CreateInstance(NS_LDAPCONNECTION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -w -b -i -r1.1.1.1 -r1.3
--- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp	8 Jan 2004 04:26:20 -0000	1.3
@@ -68,7 +68,7 @@
         PRInt32 resultLimit = -1,
         PRInt32 timeOut = 0);
     virtual ~nsAbQueryLDAPMessageListener ();
-
+    void SetPassword(const nsAString& aPassword){m_sPassword = aPassword;};
 protected:
     nsresult OnLDAPMessageBind (nsILDAPMessage *aMessage);
     nsresult OnLDAPMessageSearchEntry (nsILDAPMessage *aMessage,
@@ -99,6 +99,8 @@
     PRBool mInitialized;
     PRBool mCanceled;
 
+    nsAutoString m_sPassword;
+
     nsCOMPtr<nsILDAPOperation> mSearchOperation;
 
     PRLock* mLock;
@@ -253,6 +255,7 @@
         do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
+#if 0
     nsCOMPtr<nsILDAPMessageListener> proxyListener;
     rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ,
                      NS_GET_IID(nsILDAPMessageListener),
@@ -261,10 +264,14 @@
                      getter_AddRefs(proxyListener));
 
     rv = ldapOperation->Init(mConnection, proxyListener);
+#endif
+#if 1
+    rv = ldapOperation->Init(mConnection, this);
+#endif
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Bind
-    rv = ldapOperation->SimpleBind(nsnull);
+    rv = ldapOperation->SimpleBind(m_sPassword.get());
     NS_ENSURE_SUCCESS(rv, rv);
 
     return rv;
@@ -280,6 +287,7 @@
     mSearchOperation = do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
+#if 0
     nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
 	    do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
 	  NS_ENSURE_SUCCESS(rv, rv);
@@ -290,6 +298,10 @@
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mSearchOperation->Init (mConnection, proxyListener);
+#endif
+#if 1
+    rv = mSearchOperation->Init (mConnection, this);
+#endif
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsXPIDLCString dn;
@@ -519,6 +531,23 @@
     rv = nsAbBoolExprToLDAPFilter::Convert (expression, filter);
     NS_ENSURE_SUCCESS(rv, rv);
 
+    /*
+     * Mozilla itself cannot arrive here with a blank filter
+     * as the nsAbLDAPDirectory::StartSearch() disallows it.
+     * But 3rd party LDAP query integration with Mozilla begins 
+     * in this method.
+     *
+     * Default the filter string if blank, otherwise it gets
+     * set to (objectclass=*) which returns everything. Set 
+     * the default to (objectclass=inetorgperson) as this 
+     * is the most appropriate default objectclass which is 
+     * central to the makeup of the mozilla ldap address book 
+     * entries.
+    */
+    if(filter.IsEmpty())
+    {
+        filter += NS_LITERAL_CSTRING("(objectclass=inetorgperson)");
+    }
 
     // Set up the search ldap url
     nsCOMPtr<nsILDAPURL> directoryUrl;
@@ -592,6 +621,11 @@
                 timeOut);
     if (_messageListener == NULL)
             return NS_ERROR_OUT_OF_MEMORY;
+    
+    nsAutoString wPassword;
+    wPassword.AssignWithConversion(mPassword.get());
+    _messageListener->SetPassword(wPassword);
+
     messageListener = _messageListener;
     nsVoidKey key (NS_REINTERPRET_CAST(void *,contextID));
 
@@ -604,9 +638,12 @@
 
     *_retval = contextID;
 
+     nsAutoString wLogin;
+     wLogin.AssignWithConversion(mLogin.get());
+
     // Now lets initialize the LDAP connection properly. We'll kick
     // off the bind operation in the callback function, |OnLDAPInit()|.
-    rv = ldapConnection->Init(host.get(), port, options, nsnull,
+    rv = ldapConnection->Init(host.get(), port, options, wLogin.get(),
                               messageListener);
     NS_ENSURE_SUCCESS(rv, rv);
 
Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h	8 Jan 2004 04:26:20 -0000	1.2
@@ -72,6 +72,8 @@
     friend class nsAbQueryLDAPMessageListener;
     nsresult RemoveListener (PRInt32 contextID);
     nsresult Initiate ();
+    nsXPIDLCString mLogin; // authenticate to the LDAP server as...
+    nsXPIDLCString mPassword; // password to the LDAP server as...
 
 private:
     nsCString mLdapUrl;
Index: mailnews/addrbook/src/nsAbLDAPProperties.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp	22 Oct 2003 09:45:04 -0000	1.2
@@ -39,6 +39,7 @@
 #include "nsAbLDAPProperties.h"
 
 #include "nsAbUtils.h"
+#include "nsCRT.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
@@ -59,6 +60,21 @@
     If there are multiple entries for a mozilla
     property the first takes precedence.
 
+    But where we need to do a query against 
+    a multiple occurring ldap attribute we 
+    need to OR all the possible ldap entries e.g.
+
+    (CellularNumber=123456) translates to 
+    (|(mobile=123456)(&(!(mobile=*))(cellphone=123456))(&(!(mobile=*))(!(cellphone=*))(carphone=123456)))
+
+    i.e. use the first occurring attribute otherwise if 
+    first does not exist use the second etc.
+
+    [Multiple occurring ldap attributes do not
+    include aliases. We have also ignored the case 
+    for including 'displayname' as the first occurring
+    attribute 'cn' is a required attribute.] 
+
     This ensures that
     
         1) Generality is maintained when mapping from
@@ -101,55 +117,32 @@
     {MozillaProperty_String, "FaxNumber",        "fax"},
     // organizationalPerson
     {MozillaProperty_String, "FaxNumber",        "facsimiletelephonenumber"},
-    // inetOrgPerson
-    {MozillaProperty_String, "PagerNumber",        "pager"},
-    // ?
-    {MozillaProperty_String, "PagerNumber",        "pagerphone"},
-    // inetOrgPerson
-    {MozillaProperty_String, "CellularNumber",    "mobile"},
-    // ?
-    {MozillaProperty_String, "CellularNumber",    "cellphone"},
-    // ?
-    {MozillaProperty_String, "CellularNumber",    "carphone"},
+    // inetOrgPerson ?
+    {MozillaProperty_String, "PagerNumber",        "pager,pagerphone"},
+    // inetOrgPerson ? ?
+    {MozillaProperty_String, "CellularNumber",    "mobile,cellphone,carphone"},
 
     // No Home* properties defined yet
 
-    // organizationalPerson
-    {MozillaProperty_String, "WorkAddress",        "postofficebox"},
-    // ?
-    {MozillaProperty_String, "WorkAddress",        "streetaddress"},
+    // organizationalPerson ?
+    {MozillaProperty_String, "WorkAddress",        "postofficebox,streetaddress"},
     // ?
     {MozillaProperty_String, "WorkCity",        "l"},
     // ?
     {MozillaProperty_String, "WorkCity",        "locality"},
-    // ?
-    {MozillaProperty_String, "WorkState",        "st"},
-    // ?
-    {MozillaProperty_String, "WorkState",        "region"},
-    // organizationalPerson
-    {MozillaProperty_String, "WorkZipCode",        "postalcode"},
-    // ?
-    {MozillaProperty_String, "WorkZipCode",        "zip"},
+    // ? ?
+    {MozillaProperty_String, "WorkState",        "st,region"},
+    // organizationalPerson ?
+    {MozillaProperty_String, "WorkZipCode",        "postalcode,zip"},
     // ?
     {MozillaProperty_String, "WorkCountry",        "countryname"},
 
     // organizationalPerson
     {MozillaProperty_String, "JobTitle",        "title"},
-    // ?
-    {MozillaProperty_String, "Department",        "ou"},
-    // ?
-    {MozillaProperty_String, "Department",        "orgunit"},
-    // ?
-    {MozillaProperty_String, "Department",        "department"},
-    // ?
-    {MozillaProperty_String, "Department",        "departmentnumber"},
-    // inetOrgPerson
-    {MozillaProperty_String, "Company",        "o"},
-    // ?
-    {MozillaProperty_String, "Company",        "company"},
-    // ?
-    {MozillaProperty_String, "WorkCountry",        "countryname"},
-
+    // ? ? ? ?
+    {MozillaProperty_String, "Department",        "ou,orgunit,department,departmentnumber"},
+    // inetOrgPerson ?
+    {MozillaProperty_String, "Company",        "o,company"},
     // ?
     {MozillaProperty_String, "WebPage1",        "workurl"},
     // ?
@@ -167,10 +160,8 @@
     // ?
     {MozillaProperty_String, "Custom4",        "custom4"},
 
-    // ?
-    {MozillaProperty_String, "Notes",        "notes"},
-    // person
-    {MozillaProperty_String, "Notes",        "description"},
+    // ? person
+    {MozillaProperty_String, "Notes",        "notes,description"},
 
     // mozilla specfic
     {MozillaProperty_Int, "PreferMailFormat",    "xmozillausehtmlmail"},
@@ -208,10 +199,22 @@
     if (IsInitialized) { return ; }
 
     for (int i = tableSize - 1 ; i >= 0 ; -- i) {
-        nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
-        nsCStringKey keyLdap (table [i].ldapProperty, -1, nsCStringKey::NEVER_OWN);
 
+        char *attrToken = nsnull;
+        char *LDAPProperty = nsCRT::strdup(table[i].ldapProperty);
+        char *tmpLDAPProperty;
+
+        attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
+        while (attrToken != nsnull)
+        {
+            while ( ' ' == *attrToken) 
+                attrToken++;
+            nsCStringKey keyLdap (attrToken, -1, nsCStringKey::NEVER_OWN);
         mLdapToMozilla.Put(&keyLdap, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
+            attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
+        }
+
+        nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
         mMozillaToLdap.Put(&keyMozilla, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
     }
     IsInitialized = PR_TRUE;
@@ -233,10 +236,13 @@
 const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (const char* ldapProperty)
 {
     Initialize();
+    char *attrToken;
+    char *tmpLDAPProperty;
+    attrToken = nsCRT::strtok(NS_CONST_CAST(char *,ldapProperty), ",", &tmpLDAPProperty);
     // ensure that we always do a case insensitive comparison
     // against the incoming ldap attributes.
-    nsCAutoString lowercasedProp (ldapProperty) ;
-    ToLowerCase(nsDependentCString(ldapProperty),lowercasedProp);
+    nsCAutoString lowercasedProp (attrToken) ;
+    ToLowerCase(nsDependentCString(attrToken),lowercasedProp);
     nsCStringKey key (lowercasedProp) ;
 
     return NS_REINTERPRET_CAST(const MozillaLdapPropertyRelation *, mLdapToMozilla.Get(&key)) ;
@@ -286,5 +292,66 @@
         }
     }
 
+    return rv;
+}
+
+// Parse the input string which may contain a single ldap attribute or multiple attributes in the form
+// "string" or "string1,string2,string3" respectively and assign to the array.
+nsresult MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes)
+{
+    NS_ENSURE_ARG_POINTER(aAttrCount);
+    NS_ENSURE_ARG_POINTER(aAttributes);
+
+    nsresult rv = NS_OK;
+
+    *aAttributes = 0;
+    // we must have at least one attribute 
+    *aAttrCount = 1;
+
+    // if no multiple ldap attributes then allocate our single entry and exit
+    if (!strchr(aLDAPProperty,','))
+    {
+        if (!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(sizeof(char *)))))
+            return NS_ERROR_OUT_OF_MEMORY;
+        if (!((*aAttributes)[0] = nsCRT::strdup(aLDAPProperty)))
+            return NS_ERROR_OUT_OF_MEMORY;
+
+        return rv;
+    }
+
+    char *attrToken = nsnull;
+    char *LDAPProperty = nsnull;
+    char *tmpLDAPProperty;
+
+    if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    // set our tokenizer to the start 
+    attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty); 
+
+    // Count up the attribute names 
+    while ((attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty)) != nsnull)
+        *aAttrCount += 1;
+
+    nsCRT::free (LDAPProperty);
+    if(!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(*aAttrCount * sizeof(char *)))))
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    PRInt32 j = 0;
+    attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
+    while (nsnull != attrToken) {
+        if(((*aAttributes)[j++] = nsCRT::strdup(attrToken)) == nsnull)
+        {
+            nsCRT::free(LDAPProperty);
+            return NS_ERROR_OUT_OF_MEMORY;
+        }
+		
+        attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
+    }
+
+    nsCRT::free(LDAPProperty);
     return rv;
 }
Index: mailnews/addrbook/src/nsAbLDAPProperties.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h	22 Oct 2003 09:45:04 -0000	1.2
@@ -85,6 +85,7 @@
     static nsresult createCardPropertyFromLDAPMessage (nsILDAPMessage* message,
             nsIAbCard* card,
             PRBool* hasSetCardProperty);
+    static nsresult getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes);
 };
 
 #endif
Index: mailnews/addrbook/src/nsAbOutlookCard.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp	9 Dec 2003 03:26:47 -0000	1.2
@@ -97,6 +97,8 @@
 {
     index_DisplayName = 0,
     index_EmailAddress,
+    index_SecondEmailAddress,
+    //index_ScreenName,
     index_FirstName,
     index_LastName,
     index_NickName,
@@ -124,32 +126,35 @@
 
 static const ULONG OutlookCardMAPIProps [] = 
 {
-    PR_DISPLAY_NAME_W,
-    PR_EMAIL_ADDRESS_W,
-    PR_GIVEN_NAME_W,
-    PR_SURNAME_W,
-    PR_NICKNAME_W,
-    PR_BUSINESS_TELEPHONE_NUMBER_W,
-    PR_HOME_TELEPHONE_NUMBER_W,
-    PR_BUSINESS_FAX_NUMBER_W,
-    PR_PAGER_TELEPHONE_NUMBER_W,
-    PR_MOBILE_TELEPHONE_NUMBER_W,
-    PR_HOME_ADDRESS_CITY_W,
-    PR_HOME_ADDRESS_STATE_OR_PROVINCE_W,
-    PR_HOME_ADDRESS_POSTAL_CODE_W,
-    PR_HOME_ADDRESS_COUNTRY_W,
-    PR_BUSINESS_ADDRESS_CITY_W,
-    PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W,
-    PR_BUSINESS_ADDRESS_POSTAL_CODE_W,
-    PR_BUSINESS_ADDRESS_COUNTRY_W,
-    PR_TITLE_W,
-    PR_DEPARTMENT_NAME_W,
-    PR_COMPANY_NAME_W,
-    PR_BUSINESS_HOME_PAGE_W,
-    PR_PERSONAL_HOME_PAGE_W,
-    PR_COMMENT_W
+    PR_DISPLAY_NAME_A,//0x8035001E,//PR_DISPLAY_NAME_A,
+    PR_EMAIL_ADDRESS_A,//0x8034001E,//PR_EMAIL_ADDRESS_A,
+    PR_SECOND_EMAIL_ADDRESS_A,//Second Email Address
+    //PR_SCREEN_NAME_A,//AimScreenName
+    PR_GIVEN_NAME_A,
+    PR_SURNAME_A,
+    PR_NICKNAME_A,
+    PR_BUSINESS_TELEPHONE_NUMBER_A,
+    PR_HOME_TELEPHONE_NUMBER_A,
+    PR_BUSINESS_FAX_NUMBER_A,
+    PR_PAGER_TELEPHONE_NUMBER_A,
+    PR_MOBILE_TELEPHONE_NUMBER_A,
+    PR_HOME_ADDRESS_CITY_A,
+    PR_HOME_ADDRESS_STATE_OR_PROVINCE_A,
+    PR_HOME_ADDRESS_POSTAL_CODE_A,
+    PR_HOME_ADDRESS_COUNTRY_A,
+    PR_BUSINESS_ADDRESS_CITY_A,
+    PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_A,
+    PR_BUSINESS_ADDRESS_POSTAL_CODE_A,
+    PR_BUSINESS_ADDRESS_COUNTRY_A,
+    PR_TITLE_A,
+    PR_DEPARTMENT_NAME_A,
+    PR_COMPANY_NAME_A,
+    PR_BUSINESS_HOME_PAGE_A,
+    PR_PERSONAL_HOME_PAGE_A,
+    PR_COMMENT_A
 } ;
 
+
 nsresult nsAbOutlookCard::Init(const char *aUri)
 {
     nsresult retCode = nsRDFResource::Init(aUri) ;
@@ -176,6 +181,8 @@
         SetDisplayName(unichars [index_DisplayName]->get()) ;
         SetNickName(unichars [index_NickName]->get()) ;
         SetPrimaryEmail(unichars [index_EmailAddress]->get()) ;
+        SetSecondEmail(unichars [index_SecondEmailAddress]->get()) ;
+        //SetAimScreenName(unichars [index_ScreenName]->get()) ;
         SetWorkPhone(unichars [index_WorkPhoneNumber]->get()) ;
         SetHomePhone(unichars [index_HomePhoneNumber]->get()) ;
         SetFaxNumber(unichars [index_WorkFaxNumber]->get()) ;
@@ -210,12 +217,12 @@
     nsAutoString unichar ;
     nsAutoString unicharBis ;
 
-    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, unichar)) {
+    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_A, unichar)) {
         splitString(unichar, unicharBis) ;
         SetHomeAddress(unichar.get()) ;
         SetHomeAddress2(unicharBis.get()) ;
     }
-    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, unichar)) {
+    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_A, unichar)) {
         splitString(unichar, unicharBis) ;
         SetWorkAddress(unichar.get()) ;
         SetWorkAddress2(unicharBis.get()) ;
@@ -297,6 +304,8 @@
     SetDisplayName(properties [index_DisplayName]) ;
     GetNickName(getter_Copies(properties [index_NickName])) ;
     GetPrimaryEmail(getter_Copies(properties [index_EmailAddress])) ;
+    GetSecondEmail(getter_Copies(properties [index_SecondEmailAddress])) ;
+    //GetAimScreenName(getter_Copies(properties [index_ScreenName])) ;
     GetWorkPhone(getter_Copies(properties [index_WorkPhoneNumber])) ;
     GetHomePhone(getter_Copies(properties [index_HomePhoneNumber])) ;
     GetFaxNumber(getter_Copies(properties [index_WorkFaxNumber])) ;
@@ -316,11 +325,20 @@
     GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
     GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
     GetNotes(getter_Copies(properties [index_Comments])) ;
-    if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps, 
-        index_LastProp, properties)) {
-        PRINTF(("Cannot set general properties.\n")) ;
+
+    int i=0;
+    for (i=0;i<index_LastProp;i++)
+    {
+        if (!mapiAddBook->SetPropertyUString(*mMapiData,
+                                            OutlookCardMAPIProps[i],
+                                            properties[i]))
+        {
+            PRINTF(("Cannot set properties:%d.\n",OutlookCardMAPIProps[i])) ;
     }
+    }
+
     delete [] properties ;
+
     nsXPIDLString unichar ;
     nsXPIDLString unichar2 ;
     WORD year = 0 ; 
Index: mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp	22 Oct 2003 02:43:10 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp	9 Dec 2003 03:26:47 -0000	1.2
@@ -125,8 +125,8 @@
     nsCAutoString uri ;
     nsCOMPtr<nsIRDFResource> resource ;
 
-    for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) {
-        folders.mEntries [i].ToString(entryId) ;
+    for (ULONG i = 0 ; i < folders.GetSize() ; ++ i) {
+        folders[i].ToString(entryId) ;
         buildAbWinUri(kOutlookDirectoryScheme, abType, uri) ;
         uri.Append(entryId) ;
         
Index: mailnews/addrbook/src/nsAbOutlookDirectory.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -w -b -i -r1.1.1.1 -r1.3
--- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp	9 Dec 2003 03:26:47 -0000	1.3
@@ -125,7 +125,7 @@
         PRINTF(("Cannot get type.\n")) ;
         return NS_ERROR_FAILURE ;
     }
-    if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, unichars)) {
+    if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, unichars)) {
         PRINTF(("Cannot get name.\n")) ;
         return NS_ERROR_FAILURE ;
     }
@@ -161,45 +161,85 @@
     return retCode ;
 }
 
+nsresult nsAbOutlookDirectory::BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard, 
+                                                PRBool aSearchForOld, PRBool& aIsNewCard)
+{   
+    nsresult retCode = NS_OK ;
+    if (aSearchForOld) {
+        nsCStringKey key(uriName) ;
+        nsCOMPtr<nsISupports> existingCard = mCardList.Get(&key) ;
+        
+        if (existingCard) {
+            nsCOMPtr<nsIAbCard> card(do_QueryInterface(existingCard, &retCode)) ;
+            
+            NS_ENSURE_SUCCESS(retCode, retCode) ;
+            NS_IF_ADDREF(*aNewCard = card) ;
+            aIsNewCard = PR_FALSE ;
+            return retCode ;
+        }
+    }
+    aIsNewCard = PR_TRUE ;
+    nsCOMPtr<nsIRDFResource> resource ;
+
+    nsCOMPtr<nsIAbCard> childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    resource = do_QueryInterface(childCard, &retCode) ;
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    retCode = resource->Init(uriName.get()) ;
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    NS_IF_ADDREF(*aNewCard = childCard);
+    return retCode ;
+}
+
 NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
 {
     if (!aCards) { return NS_ERROR_NULL_POINTER ; }
     *aCards = nsnull ;
     nsCOMPtr<nsISupportsArray> cardList ;
+    nsCStringArray uriList ;
+    nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
     nsresult retCode ;
     
-    mCardList.Reset() ;
     if (mIsQueryURI) {
         retCode = StartSearch() ;
-        NS_NewISupportsArray(getter_AddRefs(cardList)) ;
     }
     else {
-        retCode = GetChildCards(getter_AddRefs(cardList), nsnull) ;
+        retCode = GetChildCards(uriList, nsnull) ;
     }
+    NS_NewISupportsArray(getter_AddRefs(cardList)) ;
     if (NS_SUCCEEDED(retCode)) {
         // Fill the results array and update the card list
         // Also update the address list and notify any changes.
         PRUint32 nbCards = 0 ;
-        nsCOMPtr<nsISupports> element ;
+        nsCAutoString uriName;
+        nsCOMPtr <nsIAbCard> childCard;
+        PRBool searchForOldCards = (mCardList.Count() != 0) ;
+
+        nbCards = uriList.Count();
+		NS_NewISupportsArray(getter_AddRefs(m_AddressList));
         
-        cardList->Enumerate(aCards) ;
-        cardList->Count(&nbCards) ;
         for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
-            cardList->GetElementAt(i, getter_AddRefs(element)) ;
-            nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ;
-            nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
+            PRBool isNewCard = PR_FALSE ;
+
+            uriList.CStringAt(i,uriName);
+            retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), searchForOldCards, isNewCard);
+            NS_ENSURE_SUCCESS(retCode, retCode) ;
+            cardList->AppendElement(childCard);
 
-            if (!oldElement) {
+            if (isNewCard) {
                 // We are dealing with a new element (probably directly
                 // added from Outlook), we may need to sync m_AddressList
-                mCardList.Put(&newKey, element) ;
-                nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
+                nsCStringKey newKey(uriName) ;
+
+                mCardList.Put(&newKey, childCard) ;
+                nsCOMPtr<nsIAbCard> card (do_QueryInterface(childCard, &retCode)) ;
 
                 NS_ENSURE_SUCCESS(retCode, retCode) ;
                 PRBool isMailList = PR_FALSE ;
 
                 retCode = card->GetIsMailList(&isMailList) ;
                 NS_ENSURE_SUCCESS(retCode, retCode) ;
+
                 if (isMailList) {
                     // We can have mailing lists only in folder, 
                     // we must add the directory to m_AddressList
@@ -222,18 +262,33 @@
                     NotifyItemAddition(card) ;
                 }
             }
-            else {
-                NS_ASSERTION(oldElement == element, "Different card stored") ;
             }
         }
+    return cardList->Enumerate(aCards) ;
     }
+
+static nsresult ExtractUriFromCard(nsIAbCard *aCard, nsCString& aUri) {
+    nsresult retCode = NS_OK ;
+    nsCOMPtr<nsIRDFResource> resource (do_QueryInterface(aCard, &retCode)) ;
+    
+    // Receiving a non-RDF card is accepted
+    if (NS_FAILED(retCode)) { return NS_OK ; }
+    nsXPIDLCString uri ;
+    
+    retCode = resource->GetValue(getter_Copies(uri)) ;
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    aUri = uri.get() ;
     return retCode ;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
 {
     if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
-    nsVoidKey key (NS_STATIC_CAST(void *, aCard)) ;
+    *aHasCard = PR_FALSE ;
+    nsCString uri ;
+
+    ExtractUriFromCard(aCard, uri) ;
+    nsCStringKey key(uri) ;
 
     *aHasCard = mCardList.Exists(&key) ;
     return NS_OK ;
@@ -315,7 +370,10 @@
                 PRINTF(("Cannot delete card %s.\n", entryString.get())) ;
             }
             else {
-                nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
+                nsCString uri ;
+
+                ExtractUriFromCard(card, uri) ;
+                nsCStringKey key(uri) ;
                 
                 mCardList.Remove(&key) ;
                 if (m_IsMailList) { m_AddressList->RemoveElement(element) ; }
@@ -378,7 +436,10 @@
     }
     retCode = CreateCard(aData, addedCard) ;
     NS_ENSURE_SUCCESS(retCode, retCode) ;
-    nsVoidKey newKey (NS_STATIC_CAST(void *, *addedCard)) ;
+    nsCString uri ;
+
+    ExtractUriFromCard(*addedCard, uri) ;
+    nsCStringKey newKey(uri) ;
     
     mCardList.Put(&newKey, *addedCard) ;
     if (m_IsMailList) { m_AddressList->AppendElement(*addedCard) ; }
@@ -449,7 +510,7 @@
     if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
     retCode = GetDirName(getter_Copies(name)) ;
     NS_ENSURE_SUCCESS(retCode, retCode) ;
-    if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, name.get())) {
+    if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, name.get())) {
         return NS_ERROR_FAILURE ;
     }
     retCode = CommitAddressList() ;
@@ -510,6 +571,8 @@
     {"DisplayName", PR_DISPLAY_NAME_A},
     {"NickName", PR_NICKNAME_A},
     {"PrimaryEmail", PR_EMAIL_ADDRESS_A},
+    //{"_AimScreenName",PR_SCREEN_NAME_A},
+    {"SecondEmail",PR_SECOND_EMAIL_ADDRESS_A},
     {"WorkPhone", PR_BUSINESS_TELEPHONE_NUMBER_A},
     {"HomePhone", PR_HOME_TELEPHONE_NUMBER_A},
     {"FaxNumber", PR_BUSINESS_FAX_NUMBER_A},
@@ -950,6 +1013,7 @@
         delete threadArgs ;
         return NS_ERROR_OUT_OF_MEMORY ;
     }
+
     nsIntegerKey newKey(*aReturnValue) ;
     
     mQueryThreads.Put(&newKey, newThread) ;
@@ -1018,7 +1082,10 @@
 
 nsresult nsAbOutlookDirectory::OnSearchFoundCard(nsIAbCard *aCard) 
 {
-    nsVoidKey newKey (NS_STATIC_CAST(void *, aCard)) ;
+    nsCString uri ;
+
+    ExtractUriFromCard(aCard, uri) ;
+    nsCStringKey newKey(uri) ;
     nsresult retCode = NS_OK ;
     
     mCardList.Put(&newKey, aCard) ;
@@ -1042,14 +1109,14 @@
     retCode = BuildRestriction(aArguments, arguments) ;
     NS_ENSURE_SUCCESS(retCode, retCode) ;
     nsCOMPtr<nsISupportsArray> resultsArray ;
+    nsCStringArray uriArray ;
     PRUint32 nbResults = 0 ;
     
-    retCode = GetChildCards(getter_AddRefs(resultsArray), 
+    retCode = GetChildCards(uriArray, 
                             arguments.rt == RES_COMMENT ? nsnull : &arguments) ;
     DestroyRestriction(arguments) ;
     NS_ENSURE_SUCCESS(retCode, retCode) ;
-    retCode = resultsArray->Count(&nbResults) ;
-    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    nbResults = uriArray.Count() ;
     nsCOMPtr<nsIAbDirectoryQueryResult> result ;
     nsAbDirectoryQueryResult *newResult = nsnull ;
 
@@ -1057,15 +1124,18 @@
         nbResults = NS_STATIC_CAST(PRUint32, aResultLimit) ; 
     }
     PRUint32 i = 0 ;
-    nsCOMPtr<nsISupports> element ;
     nsCOMPtr<nsISupportsArray> propertyValues ;
     
+    nsCAutoString uriName;
+    nsCOMPtr <nsIAbCard> card;
+
     for (i = 0 ; i < nbResults ; ++ i) {
-        retCode = resultsArray->GetElementAt(i, getter_AddRefs(element)) ;
-        NS_ENSURE_SUCCESS(retCode, retCode) ;
-        nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
+        PRBool isNewCard = PR_FALSE ;
         
+        uriArray.CStringAt(i,uriName);
+        retCode = BuildCardFromURI(uriName,getter_AddRefs(card), PR_FALSE, isNewCard);
         NS_ENSURE_SUCCESS(retCode, retCode) ;
+        
         FillPropertyValues(card, aArguments, getter_AddRefs(propertyValues)) ;
         newResult = new nsAbDirectoryQueryResult(0, aArguments,
                                                  nsIAbDirectoryQueryResult::queryResultMatch, 
@@ -1090,6 +1160,38 @@
     if (!aCards) { return NS_ERROR_NULL_POINTER ; }
     *aCards = nsnull ;
     nsresult retCode = NS_OK ;
+
+    nsCOMPtr<nsISupportsArray> cards;
+    retCode = NS_NewISupportsArray(getter_AddRefs(cards));
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+
+    nsCStringArray uriList;
+    retCode = GetChildCards(uriList,aRestriction);
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    
+    nsCAutoString uriName;
+    nsCOMPtr <nsIAbCard> childCard;
+    PRUint32 nbURIs = 0 ;
+    nbURIs = uriList.Count();
+    PRUint32 i = 0 ;
+        
+    for (i = 0 ; i < nbURIs ; ++ i) {
+        PRBool isNewCard = PR_FALSE ;
+
+        uriList.CStringAt(i,uriName);
+        retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), PR_TRUE, isNewCard);
+        NS_ENSURE_SUCCESS(retCode, retCode) ;
+        cards->AppendElement(childCard);
+    }        
+    
+    NS_IF_ADDREF(*aCards = cards);
+    return retCode ;
+}
+
+nsresult nsAbOutlookDirectory::GetChildCards(nsCStringArray& aURI, 
+                                             void *aRestriction)
+{
+    nsresult retCode = NS_OK ;
     nsCOMPtr<nsISupportsArray> cards ;
     nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
     nsMapiEntryArray cardEntries ;
@@ -1104,18 +1206,14 @@
     }
     nsCAutoString entryId ;
     nsCAutoString uriName ;
-    nsCOMPtr<nsIRDFResource> resource ;
+    aURI.Clear();
 
-    for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
-        cardEntries.mEntries [card].ToString(entryId) ;
+    for (ULONG card = 0 ; card < cardEntries.GetSize() ; ++ card) {
+        cardEntries [card].ToString(entryId) ;
         buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
         uriName.Append(entryId) ;
-        retCode = gRDFService->GetResource(uriName.get(), getter_AddRefs(resource)) ;
-        NS_ENSURE_SUCCESS(retCode, retCode) ;
-        cards->AppendElement(resource) ;
+        aURI.AppendCString(uriName);
     }
-    *aCards = cards ;
-    NS_ADDREF(*aCards) ;
     return retCode ;
 }
 
@@ -1139,8 +1237,8 @@
     nsCAutoString uriName ;
     nsCOMPtr <nsIRDFResource> resource ;
 
-    for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) {
-        nodeEntries.mEntries [node].ToString(entryId) ;
+    for (ULONG node = 0 ; node < nodeEntries.GetSize() ; ++ node) {
+        nodeEntries [node].ToString(entryId) ;
         buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName) ;
         uriName.Append(entryId) ;
         retCode = gRDFService->GetResource(uriName.get(), getter_AddRefs(resource)) ;
@@ -1261,7 +1359,7 @@
         // In the case of a mailing list, we cannot directly create a new card,
         // we have to create a temporary one in a real folder (to be able to use
         // templates) and then copy it to the mailing list.
-        if (m_IsMailList) {
+        if (m_IsMailList && mAbWinType == nsAbWinType_OutlookExp) {
             nsMapiEntry parentEntry ;
             nsMapiEntry temporaryEntry ;
 
@@ -1291,10 +1389,11 @@
     uri.Append(entryString) ;
     nsCOMPtr<nsIRDFResource> resource ;
     
-    retCode = gRDFService->GetResource(uri.get(), getter_AddRefs(resource)) ;
+    nsCOMPtr<nsIAbCard> newCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
     NS_ENSURE_SUCCESS(retCode, retCode) ;
-    nsCOMPtr<nsIAbCard> newCard(do_QueryInterface(resource, &retCode)) ;
-    
+    resource = do_QueryInterface(newCard, &retCode) ;
+    NS_ENSURE_SUCCESS(retCode, retCode) ;
+    retCode = resource->Init(uri.get()) ;
     NS_ENSURE_SUCCESS(retCode, retCode) ;
     if (!didCopy) {
         retCode = newCard->Copy(aData) ;
Index: mailnews/addrbook/src/nsAbOutlookDirectory.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h	22 Oct 2003 09:45:04 -0000	1.2
@@ -46,6 +46,7 @@
 #include "nsHashtable.h"
 
 #include "nsISupportsArray.h"
+#include "nsVoidArray.h"
 
 struct nsMapiEntry ;
 
@@ -91,6 +92,8 @@
 protected:
     // Retrieve hierarchy as cards, with an optional restriction
     nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
+    // Retrieve hierarchy as URIs, with an optional restriction
+    nsresult GetChildCards(nsCStringArray& aURI, void *aRestriction) ;
     // Retrieve hierarchy as directories
     nsresult GetChildNodes(nsISupportsArray **aNodes) ;
     // Create a new card
@@ -102,6 +105,9 @@
     nsresult CommitAddressList(void) ;
     // Read MAPI repository
     nsresult UpdateAddressList(void) ;
+    // Search for an existing card or build a new one
+    nsresult BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard, 
+                              PRBool aSearchForOld, PRBool& aIsNewCard) ;
 
     nsMapiEntry *mMapiData ;
     // Container for the query threads
Index: mailnews/addrbook/src/nsAbWinHelper.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -w -b -i -r1.1.1.1 -r1.3
--- miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp	9 Dec 2003 03:26:47 -0000	1.3
@@ -41,6 +41,9 @@
 #define USES_IID_IABContainer
 #define USES_IID_IMAPITable
 #define USES_IID_IDistList
+#define USES_IID_IMsgStore
+#define USES_IID_IMessage
+#define USES_IID_IMAPIFolder
 
 #include "nsAbWinHelper.h"
 #include "nsAbUtils.h"
@@ -59,19 +62,6 @@
 
 #define PRINTF(args) PR_LOG(gAbWinHelperLog, PR_LOG_DEBUG, args)
 
-// Small utility to ensure release of all MAPI interfaces
-template <class tInterface> struct nsMapiInterfaceWrapper
-{
-    tInterface mInterface ;
-
-    nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
-    ~nsMapiInterfaceWrapper(void) {
-        if (mInterface != NULL) { mInterface->Release() ; }
-    }
-    operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
-    tInterface operator -> (void) const { return mInterface ; }
-    operator tInterface *(void) { return &mInterface ; }
-} ;
 
 static void assignEntryID(LPENTRYID& aTarget, LPENTRYID aSource, ULONG aByteCount)
 {
@@ -249,24 +239,28 @@
 MOZ_DECL_CTOR_COUNTER(nsMapiEntryArray)
 
 nsMapiEntryArray::nsMapiEntryArray(void)
-: mEntries(NULL), mNbEntries(0)
 {
     MOZ_COUNT_CTOR(nsMapiEntryArray) ;
 }
 
 nsMapiEntryArray::~nsMapiEntryArray(void)
 {
-    if (mEntries) { delete [] mEntries ; }
+    CleanUp();
     MOZ_COUNT_DTOR(nsMapiEntryArray) ;
 }
-
+void  nsMapiEntryArray::AddItem(nsMapiEntry * aEntries)
+{
+    m_array.AppendElement(aEntries);
+}
 void nsMapiEntryArray::CleanUp(void)
 {
-    if (mEntries != NULL) { 
-        delete [] mEntries ;
-        mEntries = NULL ;
-        mNbEntries = 0 ;
+    nsMapiEntry *pEntries;
+    for (int i = 0; i < m_array.Count(); i++)
+    {
+        pEntries = (nsMapiEntry *)m_array.ElementAt( i);
+        delete pEntries;
     }
+    m_array.Clear();
 }
 
 MOZ_DECL_CTOR_COUNTER(nsAbWinHelper)
@@ -280,100 +274,55 @@
 // same protection (MAPI is supposed to be thread-safe).
 PRLock *nsAbWinHelper::mMutex = PR_NewLock() ;
 
+int            nsAbWinHelper::m_clients = 0;
+
+PRUnichar *    nsAbWinHelper::m_pUniBuff = NULL;
+int            nsAbWinHelper::m_uniBuffLen = 0;
+char      *    nsAbWinHelper::m_pCStrBuff = NULL;
+int            nsAbWinHelper::m_cstrBuffLen = 0;
+
 nsAbWinHelper::nsAbWinHelper(void)
-: mAddressBook(NULL), mLastError(S_OK)
+:mLastError(S_OK)
 {
     MOZ_COUNT_CTOR(nsAbWinHelper) ;
+    m_clients++;
 }
 
 nsAbWinHelper::~nsAbWinHelper(void)
 {
     MOZ_COUNT_DTOR(nsAbWinHelper) ;
-}
-
-BOOL nsAbWinHelper::GetFolders(nsMapiEntryArray& aFolders)
+    m_clients--;
+    if (!m_clients)
 {
-    aFolders.CleanUp() ;
-    nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
-    nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
-    ULONG objType = 0 ;
-    ULONG rowCount = 0 ;
-    SRestriction restriction ;
-    SPropTagArray folderColumns ;
-
-    mLastError = mAddressBook->OpenEntry(0, NULL, NULL, 0, &objType, 
-                                         rootFolder) ;
-    if (HR_FAILED(mLastError)) { 
-        PRINTF(("Cannot open root %08x.\n", mLastError)) ;
-        return FALSE ; 
+        delete [] m_pUniBuff;
+        m_pUniBuff = NULL;
+        m_uniBuffLen = 0;
+        delete [] m_pCStrBuff;
+        m_pCStrBuff = NULL;
+        m_cstrBuffLen = 0;
     }
-    mLastError = rootFolder->GetHierarchyTable(0, folders) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot get hierarchy %08x.\n", mLastError)) ;
-        return FALSE ; 
-    }
-    // We only take into account modifiable containers, 
-    // otherwise, we end up with all the directory services...
-    restriction.rt = RES_BITMASK ;
-    restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
-    restriction.res.resBitMask.relBMR = BMR_NEZ ;
-    restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
-    mLastError = folders->Restrict(&restriction, 0) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
-    }
-    folderColumns.cValues = 1 ;
-    folderColumns.aulPropTag [0] = PR_ENTRYID ;
-    mLastError = folders->SetColumns(&folderColumns, 0) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
-        return FALSE ;
     }
-    mLastError = folders->GetRowCount(0, &rowCount) ;
-    if (HR_SUCCEEDED(mLastError)) {
-        aFolders.mEntries = new nsMapiEntry [rowCount] ;
-        aFolders.mNbEntries = 0 ;
-        do {
-            LPSRowSet rowSet = NULL ;
 
-            rowCount = 0 ;
-            mLastError = folders->QueryRows(1, 0, &rowSet) ;
-            if (HR_SUCCEEDED(mLastError)) {
-                rowCount = rowSet->cRows ;
-                if (rowCount > 0) {
-                    nsMapiEntry& current = aFolders.mEntries [aFolders.mNbEntries ++] ;
-                    SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
-                    
-                    current.Assign(currentValue.Value.bin.cb,
-                                   NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
-                }
-                MyFreeProws(rowSet) ;
-            }
-            else {
-                PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
-            }
-        } while (rowCount > 0) ;
-    }
-    return HR_SUCCEEDED(mLastError) ;
-}
 
 BOOL nsAbWinHelper::GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
                              nsMapiEntryArray& aCards)
 {
     aCards.CleanUp() ;
-    return GetContents(aParent, aRestriction, &aCards.mEntries, aCards.mNbEntries, 0) ;
+    return GetContents(aParent, aRestriction, &aCards, 0) ;
 }
  
 BOOL nsAbWinHelper::GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes)
 { 
     aNodes.CleanUp() ;
-    return GetContents(aParent, NULL, &aNodes.mEntries, aNodes.mNbEntries, MAPI_DISTLIST) ;
+    return GetContents(aParent, NULL, &aNodes, MAPI_DISTLIST) ;
 }
 
 BOOL nsAbWinHelper::GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards) 
 {
-    aNbCards = 0 ;
-    return GetContents(aParent, NULL, NULL, aNbCards, 0) ;
+    nsMapiEntryArray aCards;
+    BOOL ret=GetContents(aParent, NULL, &aCards,  0) ;
+    aNbCards=aCards.GetSize();
+    return ret;
 }
 
 BOOL nsAbWinHelper::GetPropertyString(const nsMapiEntry& aObject,
@@ -390,7 +339,7 @@
             aName = values->Value.lpszA ;
         }
         else if (PROP_TYPE(values->ulPropTag) == PT_UNICODE) {
-            aName.AssignWithConversion(values->Value.lpszW) ;
+            UnicodeToCStr(values->Value.lpszW,aName) ;
         }
     }
     FreeBuffer(values) ;
@@ -410,7 +359,7 @@
             aName = values->Value.lpszW ;
         }
         else if (PROP_TYPE(values->ulPropTag) == PT_STRING8) {
-            aName.AssignWithConversion(values->Value.lpszA) ;
+            CStrToUnicode(values->Value.lpszA,aName) ;
         }
     }
     FreeBuffer(values) ;
@@ -431,16 +380,24 @@
         ULONG i = 0 ;
 
         for (i = 0 ; i < valueCount ; ++ i) {
-            if (values [i].ulPropTag == aPropertyTags [i]) {
+           
+            if (PROP_TYPE( values [i].ulPropTag) != PT_ERROR && values [i].Value.l != MAPI_E_NOT_FOUND) 
+            {
                 if (PROP_TYPE(values [i].ulPropTag) == PT_STRING8) {
                     nsAutoString temp ;
 
-                    temp.AssignWithConversion (values [i].Value.lpszA) ;
+                    CStrToUnicode(values [i].Value.lpszA,temp) ;
                     aNames.AppendString(temp) ;
                 }
                 else if (PROP_TYPE(values [i].ulPropTag) == PT_UNICODE) {
                     aNames.AppendString(nsAutoString (values [i].Value.lpszW)) ;
                 }
+                else if (aPropertyTags [i] == PR_EMAIL_ADDRESS_A) {
+                    nsAutoString temp ;
+
+                    CStrToUnicode (values [i].Value.lpszA,temp) ;
+                    aNames.AppendString(temp) ;
+                }
                 else {
                     aNames.AppendString(nsAutoString((const PRUnichar *) "")) ;
                 }
@@ -466,7 +423,6 @@
     if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
     if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
         SYSTEMTIME readableTime ;
-
         if (FileTimeToSystemTime(&values->Value.ft, &readableTime)) {
             aYear = readableTime.wYear ;
             aMonth = readableTime.wMonth ;
@@ -518,7 +474,7 @@
     nsMapiInterfaceWrapper<LPMAPIPROP> subObject ;
     ULONG objType = 0 ;
     
-    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                          &IID_IMAPIContainer, 0, &objType, 
                                          container) ;
     if (HR_FAILED(mLastError)) {
@@ -537,7 +493,7 @@
     SBinary entry ;
     SBinaryArray entryArray ;
 
-    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                          &IID_IABContainer, MAPI_MODIFY, &objType, 
                                          container) ;
     if (HR_FAILED(mLastError)) {
@@ -567,14 +523,15 @@
         value.Value.lpszW = NS_CONST_CAST(WORD *, aValue) ;
     }
     else if (PROP_TYPE(aPropertyTag) == PT_STRING8) {
-        alternativeValue.AssignWithConversion(aValue) ;
+        UnicodeToCStr(aValue,alternativeValue) ;
         value.Value.lpszA = NS_CONST_CAST(char *, alternativeValue.get()) ;
     }
     else {
         PRINTF(("Property %08x is not a string.\n", aPropertyTag)) ;
         return TRUE ;
     }
-    return SetMAPIProperties(aObject, 1, &value) ;
+    LPSPropValue values=&value;
+    return SetMAPIProperties(aObject, 1, values) ;
 }
 
 BOOL nsAbWinHelper::SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
@@ -592,7 +549,7 @@
             values [currentValue ++].Value.lpszW = NS_CONST_CAST(WORD *, aValues [i].get()) ;
         }
         else if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
-            alternativeValue.AssignWithConversion(aValues [i].get()) ;
+            UnicodeToCStr(aValues [i].get(),alternativeValue) ;
             values [currentValue ++].Value.lpszA = nsCRT::strdup(alternativeValue.get()) ;
         }
     }
@@ -624,7 +581,8 @@
         readableTime.wSecond = 0 ;
         readableTime.wMilliseconds = 0 ;
         if (SystemTimeToFileTime(&readableTime, &value.Value.ft)) {
-            return SetMAPIProperties(aObject, 1, &value) ;
+            LPSPropValue values=&value;
+            return SetMAPIProperties(aObject, 1, values) ;
         }
         return TRUE ;
     }
@@ -636,7 +594,7 @@
     nsMapiInterfaceWrapper<LPABCONT> container ;
     ULONG objType = 0 ;
 
-    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
+    mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
                                          &IID_IABContainer, MAPI_MODIFY, &objType,
                                          container) ;
     if (HR_FAILED(mLastError)) { 
@@ -699,7 +657,7 @@
     nsMapiInterfaceWrapper<LPABCONT> container ;
     ULONG objType = 0 ;
 
-    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
+    mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
                                          &IID_IABContainer, MAPI_MODIFY, &objType,
                                          container) ;
     if (HR_FAILED(mLastError)) {
@@ -764,7 +722,7 @@
     nsMapiInterfaceWrapper<LPABCONT> container ;
     ULONG objType = 0 ;
 
-    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                          &IID_IABContainer, MAPI_MODIFY, &objType,
                                          container) ;
     if (HR_FAILED(mLastError)) { 
@@ -801,194 +759,77 @@
     return TRUE ;
 }
 
-BOOL nsAbWinHelper::GetDefaultContainer(nsMapiEntry& aContainer)
-{
-    LPENTRYID entryId = NULL ; 
-    ULONG byteCount = 0 ;
 
-    mLastError = mAddressBook->GetPAB(&byteCount, &entryId) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot get PAB %08x.\n", mLastError)) ;
-        return FALSE ;
-    }
-    aContainer.Assign(byteCount, entryId) ;
-    FreeBuffer(entryId) ;
-    return TRUE ;
-}
 
-enum
-{
-    ContentsColumnEntryId = 0,
-    ContentsColumnObjectType,
-    ContentsColumnsSize
-} ;
 
-static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
-{
-    ContentsColumnsSize,
-    {
-        PR_ENTRYID,
-        PR_OBJECT_TYPE
-    }
-} ;
-
-BOOL nsAbWinHelper::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
-                                nsMapiEntry **aList, ULONG& aNbElements, ULONG aMapiType)
+void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
 {
-    if (aList != NULL) { *aList = NULL ; }
-    aNbElements = 0 ;
-    nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
-    nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
-    ULONG objType = 0 ;
-    ULONG rowCount = 0 ;
+    if (aRowset == NULL) { return ; }
+    ULONG i = 0 ;
 
-    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId, 
-                                         &IID_IMAPIContainer, 0, &objType, 
-                                         parent) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
-        return FALSE ; 
-    }
-    // Here, flags for WAB and MAPI could be different, so this works
-    // only as long as we don't want to use any flag in GetContentsTable
-    mLastError = parent->GetContentsTable(0, contents) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
-        return FALSE ; 
-    }
-    if (aRestriction != NULL) {
-        mLastError = contents->Restrict(aRestriction, 0) ;
-        if (HR_FAILED(mLastError)) {
-            PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
-            return FALSE ;
-        }
-    }
-    mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
-        return FALSE ;
-    }
-    mLastError = contents->GetRowCount(0, &rowCount) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
-        return FALSE ;
+    for (i = 0 ; i < aRowset->cRows ; ++ i) {
+        FreeBuffer(aRowset->aRow [i].lpProps) ;
     }
-    if (aList != NULL) { *aList = new nsMapiEntry [rowCount] ; }
-    aNbElements = 0 ;
-    do {
-        LPSRowSet rowSet = NULL ;
-        
-        rowCount = 0 ;
-        mLastError = contents->QueryRows(1, 0, &rowSet) ;
-        if (HR_FAILED(mLastError)) {
-            PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
-            return FALSE ;
+    FreeBuffer(aRowset) ;
         }
-        rowCount = rowSet->cRows ;
-        if (rowCount > 0 &&
-            (aMapiType == 0 ||
-            rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)) {
-            if (aList != NULL) {
-                nsMapiEntry& current = (*aList) [aNbElements] ;
-                SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
-                
-                current.Assign(currentValue.Value.bin.cb,
-                    NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
+void nsAbWinHelper::CStrToUnicode( const char *pStr, nsString& result)
+{
+    result.Truncate( 0);
+    int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
+    if (wLen >= m_uniBuffLen)
+    {
+        delete [] m_pUniBuff;
+        m_pUniBuff = new PRUnichar[wLen + 64];
+        m_uniBuffLen = wLen + 64;
             }
-            ++ aNbElements ;
+    if (wLen)
+    {
+        MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
+        result = m_pUniBuff;
         }
-        MyFreeProws(rowSet) ;
-    } while (rowCount > 0) ;
-    return TRUE ;
 }
-
-BOOL nsAbWinHelper::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
-                                      ULONG aNbProperties, LPSPropValue& aValue, 
-                                      ULONG& aValueCount)
+void nsAbWinHelper::UnicodeToCStr( const  PRUnichar *pUStr,nsCString& result)
 {
-    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
-    ULONG objType = 0 ;
-    LPSPropTagArray properties = NULL ;
-    ULONG i = 0 ;
-    
-    mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
-                                         &IID_IMAPIProp, 0, &objType, 
-                                         object) ;
-    if (HR_FAILED(mLastError)) { 
-        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
-        return FALSE ; 
+    result.Truncate( 0);
+    int cLen = WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, 0,NULL,NULL);
+    if (cLen >= m_cstrBuffLen) {
+        if (m_pCStrBuff)
+            delete [] m_pCStrBuff;
+        m_pCStrBuff = new char[cLen + 64];
+        m_cstrBuffLen = cLen + 64;
     }
-    AllocateBuffer(CbNewSPropTagArray(aNbProperties), 
-                   NS_REINTERPRET_CAST(void **, &properties)) ;
-    properties->cValues = aNbProperties ;
-    for (i = 0 ; i < aNbProperties ; ++ i) {
-        properties->aulPropTag [i] = aPropertyTags [i] ;
+    if (cLen) {
+        WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, m_cstrBuffLen,NULL,NULL);
+        result = m_pCStrBuff;
     }
-    mLastError = object->GetProps(properties, 0, &aValueCount, &aValue) ;
-    FreeBuffer(properties) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot get props %08x.\n", mLastError)) ;
-    }
-    return HR_SUCCEEDED(mLastError) ;
 }
 
-BOOL nsAbWinHelper::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
-                                      const LPSPropValue& aValues)
-{
-    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
-    ULONG objType = 0 ;
-    LPSPropProblemArray problems = NULL ;
+static nsAbWinHelper *getOutlookAddressBook(void) {
+    static nsMapiAddressBook *addressBook = NULL ;
 
-    mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
-                                         &IID_IMAPIProp, MAPI_MODIFY, &objType, 
-                                         object) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
-        return FALSE ;
-    }
-    mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
-        return FALSE ;
-    }
-    if (problems != NULL) {
-        for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
-            PRINTF(("Problem %d: index %d code %08x.\n", i, 
-                problems->aProblem [i].ulIndex, 
-                problems->aProblem [i].scode)) ;
-        }
-    }
-    mLastError = object->SaveChanges(0) ;
-    if (HR_FAILED(mLastError)) {
-        PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
-    }
-    return HR_SUCCEEDED(mLastError) ;
+    if (addressBook == NULL) { addressBook = new nsMapiAddressBook ; } 
+    return addressBook ;
 }
 
-void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
-{
-    if (aRowset == NULL) { return ; }
-    ULONG i = 0 ; 
+static nsAbWinHelper *getOutlookExpAddressBook(void) {
+    static nsWabAddressBook *addressBook = NULL ;
 
-    for (i = 0 ; i < aRowset->cRows ; ++ i) {
-        FreeBuffer(aRowset->aRow [i].lpProps) ;
-    }
-    FreeBuffer(aRowset) ;
+    if (addressBook == NULL) { addressBook = new nsWabAddressBook ; } 
+    return addressBook ;
 }
 
 nsAbWinHelperGuard::nsAbWinHelperGuard(PRUint32 aType)
 : mHelper(NULL) 
 {
     switch(aType) {
-    case nsAbWinType_Outlook: mHelper = new nsMapiAddressBook ; break ;
-    case nsAbWinType_OutlookExp: mHelper = new nsWabAddressBook ; break ;
+    case nsAbWinType_Outlook: mHelper = getOutlookAddressBook() ; break ;
+    case nsAbWinType_OutlookExp: mHelper = getOutlookExpAddressBook() ; break ;
     default: break ;
     }
 }
 
 nsAbWinHelperGuard::~nsAbWinHelperGuard(void)
 {
-    delete mHelper ;
 }
 
 const char *kOutlookDirectoryScheme = "moz-aboutlookdirectory://" ;
Index: mailnews/addrbook/src/nsAbWinHelper.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbWinHelper.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h	9 Dec 2003 03:26:47 -0000	1.2
@@ -45,6 +45,24 @@
 #include "nsVoidArray.h"
 #include "nsXPIDLString.h"
  
+#define PR_SECOND_EMAIL_ADDRESS_A  0x8033001E
+#define PR_SCREEN_NAME_A           0x805B001E
+ 
+
+// Small utility to ensure release of all MAPI interfaces
+template <class tInterface> struct nsMapiInterfaceWrapper
+{
+    tInterface mInterface ;
+
+    nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
+    ~nsMapiInterfaceWrapper(void) {
+        if (mInterface ) { mInterface->Release() ; }
+    }
+    operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
+    tInterface operator -> (void) const { return mInterface ; }
+    operator tInterface *(void) { return &mInterface ; }
+} ;
+
 struct nsMapiEntry
 {
     ULONG     mByteCount ;
@@ -62,14 +80,28 @@
 
 struct nsMapiEntryArray 
 {
-    nsMapiEntry *mEntries ;
-    ULONG      mNbEntries ;
 
     nsMapiEntryArray(void) ;
     ~nsMapiEntryArray(void) ;
 
-    const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
+    void  AddItem(nsMapiEntry * aEntries);
+    void  AddItem(    ULONG     mByteCount , LPENTRYID mEntryId )
+    {
+        nsMapiEntry * aEntries=new nsMapiEntry();
+        aEntries->Assign(mByteCount,mEntryId);
+        AddItem(aEntries);
+    }
+
+    ULONG        GetSize( void) { return( m_array.Count());}
+    nsMapiEntry& operator [] (int aIndex)  { return *(nsMapiEntry*)m_array.ElementAt(aIndex); }
+    nsMapiEntry* ElementAt(int aIndex)  { return (nsMapiEntry*)m_array.ElementAt(aIndex); }
     void CleanUp(void) ;
+    void Remove(nsMapiEntry * aEntries){ m_array.RemoveElement(aEntries); }
+    void Remove(int index){ m_array.RemoveElementAt(index); }
+    ULONG IndexOf(nsMapiEntry * aEntries){return m_array.IndexOf(aEntries);};
+private:
+    nsVoidArray        m_array;
+
 } ;
 
 class nsAbWinHelper
@@ -79,7 +111,7 @@
     virtual ~nsAbWinHelper(void) ;
 
     // Get the top address books
-    BOOL GetFolders(nsMapiEntryArray& aFolders) ;
+    virtual BOOL GetFolders(nsMapiEntryArray& aFolders) =0;
     // Get a list of entries for cards/mailing lists in a folder/mailing list
     BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
                   nsMapiEntryArray& aCards) ;
@@ -97,18 +129,14 @@
     BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag, 
                               ULONG aNbProperties, nsStringArray& aValues) ;
     // Get the value of a MAPI property of type SYSTIME
-    BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
+    virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
                          WORD& aYear, WORD& aMonth, WORD& aDay) ;
-    // Get the value of a MAPI property of type LONG
-    BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
     // Get the value of a MAPI property of type BIN
     BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
     // Tests if a container contains an entry
     BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
-    // Delete an entry in the address book
-    BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
     // Set the value of a MAPI property of type string in unicode
-    BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag, 
+    virtual BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag, 
                              const PRUnichar *aValue) ;
     // Same as previous, but with a bunch of properties in one call
     BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
@@ -117,32 +145,44 @@
     BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
                          WORD aYear, WORD aMonth, WORD aDay) ;
     // Create entry in the address book
-    BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
+    virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
+    // Delete an entry in the address book
+    virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
     // Create a distribution list in the address book
-    BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
+    virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
     // Copy an existing entry in the address book
-    BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
+    virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
     // Get a default address book container
-    BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
+    virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer) =0;
     // Is the helper correctly initialised?
-    BOOL IsOK(void) const { return mAddressBook != NULL ; }
+    virtual BOOL IsOK(void) =0;/*const { return mAddressBook != NULL ; }*/
+
+    // Get the value of a MAPI property of type LONG
+    virtual BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
 
 protected:
     HRESULT mLastError ;
-    LPADRBOOK mAddressBook ;
     static ULONG mEntryCounter ;
     static PRLock *mMutex ;
 
+    virtual HRESULT OpenEntry(ULONG cbEntryID,
+                    LPENTRYID lpEntryID,
+                    LPCIID lpInterface,
+                    ULONG ulFlags,
+                    ULONG FAR * lpulObjType,
+                    LPUNKNOWN FAR * lppUnk
+                    ) = 0;
+
     // Retrieve the contents of a container, with an optional restriction
-    BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
-                     nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
+    virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
+                     nsMapiEntryArray *aList, ULONG aMapiType) =0;
     // Retrieve the values of a set of properties on a MAPI object
-    BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
+    virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
                            ULONG aNbProperties,
-                           LPSPropValue& aValues, ULONG& aValueCount) ;
+                           LPSPropValue& aValues, ULONG& aValueCount) =0;
     // Set the values of a set of properties on a MAPI object
-    BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
-                           const LPSPropValue& aValues) ;
+    virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
+                           LPSPropValue& aValues) =0;
     // Clean-up a rowset returned by QueryRows
     void MyFreeProws(LPSRowSet aSet) ;
     // Allocation of a buffer for transmission to interfaces
@@ -150,7 +190,16 @@
     // Destruction of a buffer provided by the interfaces
     virtual void FreeBuffer(LPVOID aBuffer) = 0 ;
 
+    static void            CStrToUnicode( const char *pStr, nsString& result);
+    static void            UnicodeToCStr( const PRUnichar *pStr, nsCString& result);
+
 private:
+    static int                m_clients;
+    static PRUnichar *        m_pUniBuff;
+    static int                m_uniBuffLen;
+    static char *             m_pCStrBuff;
+    static int                m_cstrBuffLen;
+
 } ;
 
 enum nsAbWinType 
@@ -168,6 +217,7 @@
 
     nsAbWinHelper *operator ->(void) { return mHelper ; }
 
+    static void FreeWinAbLibrarys();
 private:
     nsAbWinHelper *mHelper ;
 } ;
Index: mailnews/addrbook/src/nsMapiAddressBook.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp	9 Dec 2003 03:26:47 -0000	1.2
@@ -41,6 +41,22 @@
 
 #include "prlog.h"
 
+static char * stristr(const char *big, const char *little)
+{
+    PRUint32 len;
+
+    if (!big || !little || !*big || !*little)
+      return 0;
+    len = strlen(little);
+
+    for( ; *big; big++ )
+       if(!_strnicmp (big, little, 1) && ! _strnicmp (big, little, len) )
+          return (char *)big;
+
+    return (char *)0;
+
+}
+
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gMapiAddressBookLog
     = PR_NewLogModule("nsMapiAddressBookLog");
@@ -48,6 +64,60 @@
 
 #define PRINTF(args) PR_LOG(gMapiAddressBookLog, PR_LOG_DEBUG, args)
 
+#define    OUTLOOK_EMAIL_DIAPLAY_MAPI_ID    0x00008005  //use to get and set display
+#define    OUTLOOK_EMAIL1_MAPI_ID           0x00008084  //use to get and set primary email address
+#define    OUTLOOK_EMAIL2_MAPI_ID           0x00008094  //use to get and set second  email address
+#define    OUTLOOK_EMAIL_SCREEN_NAME        0x8061001E  //use to get and set screen name
+#define    OUTLOOK_EMAIL_ORGID              0x00008085  //use to get orginal entryid to add to distlist
+#define    OUTLOOK_EMAIL_LIST1              0x00008054  //use to get distlist table
+#define    OUTLOOK_EMAIL_LIST2              0x00008055  //use to set distlist table
+
+static const TagMap TagMaps[]={
+    {PR_DISPLAY_NAME_A,         OUTLOOK_EMAIL_DIAPLAY_MAPI_ID,    PT_STRING8},
+    {PR_EMAIL_ADDRESS_A,        OUTLOOK_EMAIL1_MAPI_ID,           PT_STRING8},
+    {PR_SECOND_EMAIL_ADDRESS_A, OUTLOOK_EMAIL2_MAPI_ID,           PT_STRING8},
+    {PR_SCREEN_NAME_A,          OUTLOOK_EMAIL_SCREEN_NAME,        PT_STRING8}};
+
+enum {
+    ieidPR_ENTRYID = 0,
+    ieidPR_OBJECT_TYPE,
+    ieidPR_DISPLAY_NAME,
+    ieidPR_MESSAGE_CLASS,
+    ieidPR_STORE_ENTRYID,
+    ieidPR_MESSAGE_RECIPIENTS,
+    ieidMax
+};
+
+static const SizedSPropTagArray(ieidMax, ptaEid)=
+{
+    ieidMax,
+    {
+        PR_ENTRYID,
+        PR_OBJECT_TYPE,
+        PR_DISPLAY_NAME,
+        PR_MESSAGE_CLASS,
+        PR_STORE_ENTRYID,
+        PR_MESSAGE_RECIPIENTS
+    }
+};
+
+enum
+{
+    ContentsColumnEntryId = 0,
+    ContentsColumnObjectType,
+    ContentsColumnMessageClass,
+    ContentsColumnsSize
+} ;
+
+static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
+{
+    ContentsColumnsSize,
+    {
+        PR_ENTRYID,
+        PR_OBJECT_TYPE,
+        PR_MESSAGE_CLASS
+    }
+} ;
 
 HMODULE nsMapiAddressBook::mLibrary = NULL ;
 PRInt32 nsMapiAddressBook::mLibUsage = 0 ;
@@ -60,7 +130,6 @@
 BOOL nsMapiAddressBook::mInitialized = FALSE ;
 BOOL nsMapiAddressBook::mLogonDone = FALSE ;
 LPMAPISESSION nsMapiAddressBook::mRootSession = NULL ;
-LPADRBOOK nsMapiAddressBook::mRootBook = NULL ;
 
 BOOL nsMapiAddressBook::LoadMapiLibrary(void)
 {
@@ -106,22 +175,19 @@
                            MAPI_NEW_SESSION,
                            &mRootSession) ;
     if (HR_FAILED(retCode)) { 
-        PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ; return FALSE ;
+        PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ;
+        return FALSE ;
     }
     mLogonDone = TRUE ;
-    retCode = mRootSession->OpenAddressBook(0, NULL, 0, &mRootBook) ;
-    if (HR_FAILED(retCode)) { 
-        PRINTF(("Cannot open MAPI address book %08x.\n", retCode)) ;
-    }
+
     return HR_SUCCEEDED(retCode) ;
 }
 
 void nsMapiAddressBook::FreeMapiLibrary(void)
 {
     if (mLibrary) {
-        if (-- mLibUsage == 0) {
+        if (--mLibUsage < 0) {
             {
-                if (mRootBook) { mRootBook->Release() ; }
                 if (mRootSession) {
                     if (mLogonDone) { 
                         mRootSession->Logoff(NULL, 0, 0) ; 
@@ -135,6 +201,7 @@
                 }
             }  
             FreeLibrary(mLibrary) ;
+            mRootSession = NULL;
             mLibrary = NULL ; 
         }
     }
@@ -146,7 +213,6 @@
 : nsAbWinHelper()
 {
     BOOL result = Initialize() ;
-
     NS_ASSERTION(result == TRUE, "Couldn't initialize Mapi Helper") ;
     MOZ_COUNT_CTOR(nsMapiAddressBook) ;
 }
@@ -154,35 +220,1691 @@
 nsMapiAddressBook::~nsMapiAddressBook(void)
 {
     nsAutoLock guard(mMutex) ;
-
+    CleanUpMDB();
     FreeMapiLibrary() ;
     MOZ_COUNT_DTOR(nsMapiAddressBook) ;
 }
 
-BOOL nsMapiAddressBook::Initialize(void)
+LPSPropValue nsMapiAddressBook::GetMapiProperty( LPMAPIPROP pProp, ULONG tag)
 {
-    if (mAddressBook) { return TRUE ; }
-    nsAutoLock guard(mMutex) ;
+    if (!pProp)
+        return( NULL);
 
-    if (!LoadMapiLibrary()) {
-        PRINTF(("Cannot load library.\n")) ;
+    int    sz = CbNewSPropTagArray( 1);
+    SPropTagArray *pTag = (SPropTagArray *) new char[sz];
+    pTag->cValues = 1;
+    pTag->aulPropTag[0] = tag;
+    LPSPropValue    lpProp = NULL;
+    ULONG    cValues = 0;
+    HRESULT hr = pProp->GetProps( pTag, 0, &cValues, &lpProp);
+    delete pTag;
+    if (HR_FAILED( hr) || (cValues != 1)) {
+        if (lpProp)
+            mMAPIFreeBuffer( lpProp);
+        return( NULL);
+    }
+    else {
+        if (PROP_TYPE( lpProp->ulPropTag) == PT_ERROR) {
+            if (lpProp->Value.l == MAPI_E_NOT_FOUND) {
+                mMAPIFreeBuffer( lpProp);
+                lpProp = NULL;
+            }
+        }
+    }
+
+    return( lpProp);
+}
+BOOL nsMapiAddressBook::GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal)
+{
+    if (!pVal)
+        return( FALSE);
+    
+    BOOL bResult = TRUE;
+    switch (PROP_TYPE(pVal->ulPropTag))
+    {
+        case PT_BINARY:
+            cbEntryId = pVal->Value.bin.cb;
+            mMAPIAllocateBuffer( cbEntryId, (LPVOID *) &lpEntryId);
+            memcpy( lpEntryId, pVal->Value.bin.lpb, cbEntryId);
+        break;
+
+        default:
+            PRINTF(( "EntryId not in BINARY prop value\n"));
+            bResult = FALSE;
+        break;
+    }
+
+    if (pVal && delVal)
+        mMAPIFreeBuffer( pVal);
+
+    return( bResult);
+}
+
+BOOL nsMapiAddressBook::HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
+{
+    LPMDB  lpMsgStore;
+    ULONG objType=0;
+    HRESULT             hr;
+
+    if (oType == MAPI_MESSAGE)
+        return FALSE;
+    if (oType == MAPI_STORE)
+    {
+        hr=mRootSession->OpenEntry(
+                    cb,
+                    pEntry,
+                    &IID_IMsgStore,
+                    0,
+                    &objType,
+                    (IUnknown**)&lpMsgStore);
+        if (FAILED(hr))
         return FALSE ;
+        //Add MDB to a list to make it can be released when class  destroyed.
+        //We must leave it openned or else we can't open address store in it.
+        AddToMDBArray(lpMsgStore);
+
+        LPSPropValue    pVal;
+        pVal=GetMapiProperty(lpMsgStore,PR_IPM_SUBTREE_ENTRYID);
+        
+        
+        if (pVal) {
+            ULONG            cbEntry;
+            LPENTRYID        pEntry;
+            nsMapiInterfaceWrapper<LPMAPICONTAINER> lpSubTree;
+
+            if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) {
+                // Open up the folder!
+                BOOL bResult = TRUE;
+                bResult = lpMsgStore->OpenEntry(
+                                cbEntry,
+                                pEntry,
+                                NULL,
+                                0,
+                                &objType,
+                                lpSubTree);
+                mMAPIFreeBuffer( pEntry);
+                if (!bResult && *(LPMAPICONTAINER*)&lpSubTree) {
+                    // Iterate the subtree with the results going into the folder list
+                    bResult = IterateHierarchy(*(LPMAPICONTAINER*)&lpSubTree,aFolders);
+    }
+                else {
+                    PRINTF(( "GetStoreFolders: Error opening sub tree.\n"));
+                }
+            }
+            else {
+                PRINTF(( "GetStoreFolders: Error getting entryID from sub tree property val.\n"));
     }
-    mAddressBook = mRootBook ; 
+        }
+        else {
+            PRINTF(( "GetStoreFolders: Error getting sub tree property.\n"));
+        }
+    }
+    else
+    {
+        PRINTF(("Type:%d\n",oType));
+    }
+
     return TRUE ;
 }
 
-void nsMapiAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
+BOOL nsMapiAddressBook::IterateHierarchy(LPMAPICONTAINER pFolder,nsMapiEntryArray& aFolders, ULONG flags)
 {
-    mMAPIAllocateBuffer(aByteCount, aBuffer) ;
+    // flags can be CONVENIENT_DEPTH or 0
+    // CONVENIENT_DEPTH will return all depths I believe instead
+    // of just children
+    HRESULT        hr;
+    nsMapiInterfaceWrapper<LPMAPITABLE>    lpTable;
+    hr = pFolder->GetHierarchyTable( CONVENIENT_DEPTH , lpTable);
+    if (HR_FAILED(hr)) {
+        PRINTF(( "IterateHierarchy: GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr));
+        return( FALSE);
 }
 
-void nsMapiAddressBook::FreeBuffer(LPVOID aBuffer)
+    ULONG rowCount;
+    hr = lpTable->GetRowCount( 0, &rowCount);
+    if (!rowCount) {
+        return( TRUE);
+    }
+
+    hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
+    if (HR_FAILED(hr)) {
+        PRINTF(( "IterateHierarchy: SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr));
+        return( FALSE);
+    }
+
+    hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
+    if (HR_FAILED(hr)) {
+        PRINTF(( "IterateHierarchy: SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr));
+        return( FALSE);
+    }
+
+    int            cNumRows = 0;
+    LPSRowSet    lpRow;
+    BOOL        keepGoing = TRUE;
+    BOOL        bResult = TRUE;
+    do {
+        
+        lpRow = NULL;
+        hr = lpTable->QueryRows( 1, 0, &lpRow);
+
+        if (HR_FAILED(hr))
 {
-    mMAPIFreeBuffer(aBuffer) ;
+            PRINTF(( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr));
+            bResult = FALSE;
+            break;
+        }
+
+        if (lpRow){
+            cNumRows = lpRow->cRows;
+
+            if (cNumRows) {
+                LPENTRYID    lpEntry = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
+                ULONG        cb = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
+                ULONG        oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
+                
+                keepGoing = HandleHierarchyItem( oType, cb, lpEntry,aFolders);
+
+            }
+            MyFreeProws(lpRow);
+        }
+
+    } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing);
+
+    
+    if (bResult && !keepGoing)
+        bResult = FALSE;
+
+    return( bResult);
+}
+BOOL nsMapiAddressBook::HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
+{
+    ULONG objType=0;
+    if (oType == MAPI_FOLDER)
+    {
+        nsMapiInterfaceWrapper<LPMAPICONTAINER> pFolder ;
+        if (!mRootSession->OpenEntry(
+                        cb,
+                        pEntry,
+                        0,
+                        NULL,
+                        &objType,
+                        pFolder))
+        {
+            LPSPropValue        pVal;
+
+
+            pVal = GetMapiProperty(*(LPMAPICONTAINER*)&pFolder, PR_CONTAINER_CLASS);
+            if (pVal)
+            {
+                if (strcmp("IPF.Contact",pVal->Value.lpszA) == 0)
+                {
+                    SPropValue *currentValue=GetMapiProperty( *(LPMAPICONTAINER*)&pFolder, PR_ENTRYID);
+                    
+                    aFolders.AddItem(currentValue->Value.bin.cb,
+                                  NS_REINTERPRET_CAST(LPENTRYID, currentValue->Value.bin.lpb)) ;
+
+                }
+            }
+        }
+    }
+    else
+    {
+        PRINTF(( "GetStoreFolders - HandleHierarchyItem: Unhandled ObjectType: %ld\n", oType));
+    }
+
+    return( TRUE);
+}
+
+
+BOOL nsMapiAddressBook::GetFolders(nsMapiEntryArray& aFolders)
+{
+    aFolders.CleanUp() ;
+    nsMapiInterfaceWrapper<LPMAPICONTAINER> rootFolder ;
+    nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
+    ULONG objType = 0 ;
+    ULONG rowCount = 0 ;
+
+    nsMapiInterfaceWrapper<LPMAPITABLE>    lpTable;
+
+    mLastError = mRootSession->GetMsgStoresTable( 0, lpTable);
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open MAPI MsgStores %08x.\n", mLastError));
+        return mLastError;
+    }
+
+    mLastError = lpTable->GetRowCount( 0, &rowCount);
+
+    mLastError = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
+    if (FAILED(mLastError))
+        return( mLastError);
+    mLastError = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
+    if (FAILED(mLastError))
+        return mLastError;
+    
+    int            cNumRows = 0;
+    LPSRowSet    lpRow;
+    BOOL        keepGoing = TRUE;
+    BOOL        bResult = TRUE;
+    do {
+        
+        lpRow = NULL;
+        mLastError = lpTable->QueryRows( 1, 0, &lpRow);
+
+        if (HR_FAILED(mLastError)){
+            bResult = FALSE;
+            break;
+        }
+
+        if (lpRow){
+            cNumRows = lpRow->cRows;
+
+            if (cNumRows) {
+                LPENTRYID    lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
+                ULONG        cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
+                ULONG        oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
+
+
+                keepGoing = HandleContentsItem( oType, cbEID, lpEID,aFolders);
+            }
+            MyFreeProws( lpRow);
+        }
+
+    } while ( SUCCEEDED(mLastError) && cNumRows && lpRow && keepGoing);
+
+    
+    return HR_SUCCEEDED(mLastError) ;
+}
+BOOL nsMapiAddressBook::CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction)
+{
+    ULONG conditionType = 0 ;
+    ULONG ulResIndex;
+    if (!aRestriction)
+        return FALSE;
+    for (ulResIndex=0;ulResIndex < aRestrictionNum;ulResIndex++)
+    {
+        conditionType = aRestriction[ulResIndex].rt;
+        switch (conditionType) 
+        {
+        case RES_EXIST  :
+            aRestriction[ulResIndex].res.resExist.ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resExist.ulPropTag);
+            break ;
+        case RES_BITMASK  :
+            aRestriction[ulResIndex].res.resBitMask.ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resBitMask.ulPropTag);
+            break ;
+        case RES_CONTENT :
+            aRestriction[ulResIndex].res.resContent.ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.ulPropTag);
+            aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag);
+            break ;
+        case RES_PROPERTY :
+            aRestriction[ulResIndex].res.resProperty.ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.ulPropTag);
+            aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag);
+            break ;
+        case RES_SIZE :
+            aRestriction[ulResIndex].res.resSize.ulPropTag = 
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resSize.ulPropTag);
+            break ;
+        case RES_COMPAREPROPS :
+            aRestriction[ulResIndex].res.resCompareProps.ulPropTag1 =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag1);
+            aRestriction[ulResIndex].res.resCompareProps.ulPropTag2 =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag2);
+            break ;
+        case RES_NOT :
+            CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resNot.lpRes);
+            break;
+        case RES_AND :
+            CorrectRestriction(aMapiProp,
+                                aRestriction[ulResIndex].res.resAnd.cRes,
+                                aRestriction[ulResIndex].res.resAnd.lpRes);
+            break;
+        case RES_OR :
+            CorrectRestriction(aMapiProp,
+                                aRestriction[ulResIndex].res.resOr.cRes,
+                                aRestriction[ulResIndex].res.resOr.lpRes);
+            break;
+
+        case RES_COMMENT :
+            CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resComment.lpRes);
+            aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag =
+                GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag);
+            break;
+        case RES_SUBRESTRICTION :
+            CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resSub.lpRes);
+            break;
+        default:
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
+BOOL nsMapiAddressBook::Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList)
+{
+    if (!aRestriction)
+        return FALSE;
+
+    ULONG conditionType = 0 ;
+
+    nsMapiEntryArray listOut;
+    ULONG listindex=0;
+    
+    nsMapiEntryArray listDel;
+    ULONG delindex=0;
+
+    ULONG listsize;
+    ULONG resCount = 0;
+    ULONG resIndex = 0;
+
+    listsize = aList->GetSize();
+    conditionType = aRestriction->rt;
+    switch (conditionType) 
+    {
+    case RES_EXIST  :
+    case RES_BITMASK  :
+    case RES_CONTENT :
+    case RES_PROPERTY :
+    case RES_SIZE :
+    case RES_COMPAREPROPS :
+    case RES_COMMENT :
+    case RES_SUBRESTRICTION :
+        {
+            while(listindex < aList->GetSize())
+            {
+                if (!FilterOnOneRow(aList->ElementAt(listindex),aRestriction))
+                    aList->Remove(listindex);
+                else
+                    listindex++;
+            }
+        }
+        break;
+    case RES_NOT :
+        aRestriction->res.resNot.ulReserved = 1;
+    case RES_AND :
+    case RES_OR :
+        {
+            if (conditionType == RES_OR)
+            {
+                for(listindex=0;listindex<aList->GetSize();listindex++)
+                {
+                    listDel.AddItem(aList->ElementAt(listindex));
+                }
+            }
+
+            resCount = aRestriction->res.resAnd.cRes;
+            //notice that SAndRestriction ,SNotRestriction ,SOrRestriction
+            //use the same struct
+            for (resIndex = 0;resIndex < resCount;resIndex++)
+            {
+                //can't call listOut.CleanUp() here
+                //because it will destroy all Element too
+                while(listOut.GetSize())
+                {
+                    listOut.Remove(0);
+                }
+
+                for(listindex=0;listindex<aList->GetSize();listindex++)
+                {
+                    listOut.AddItem(aList->ElementAt(listindex));
+                }
+
+                Filter(&aRestriction->res.resAnd.lpRes[resIndex],&listOut);
+                if (conditionType == RES_NOT)
+                {
+                    for(listindex=0;listindex<listOut.GetSize();listindex++)
+                    {
+                        aList->Remove(listOut.ElementAt(listindex));
+                    }
+                }
+                else if (conditionType == RES_AND )
+                {
+                    for(listindex=0;listindex<listOut.GetSize();listindex++)
+                    {
+                        if (!aList->IndexOf(listOut.ElementAt(listindex)))
+                        {
+                            aList->Remove(listOut.ElementAt(listindex));
+                        }
+                    }
+                }
+                else if (conditionType == RES_OR )
+                {
+                    for(listindex=0;listindex<listOut.GetSize();listindex++)
+                    {
+                        listDel.Remove(listOut.ElementAt(listindex));
+                    }
+                    if (listDel.GetSize() == 0)
+                    {
+                        break;
+                    }
+                }
+            }
+            if (conditionType == RES_OR)
+            {
+                for(listindex=0;listindex<listDel.GetSize();listindex++)
+                {
+                    aList->Remove(listDel.ElementAt(listindex));
+                }
+            }
+        }
+
+    }
+    while(listDel.GetSize())
+    {
+        listDel.Remove(0);
+    }
+    while(listOut.GetSize())
+    {
+        listOut.Remove(0);
+    }
+
+
+    return TRUE;
+}
+
+BOOL nsMapiAddressBook::FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction)
+{
+    LPMAPIPROP object ;
+    ULONG objType = 0 ;
+    LPSPropValue realValue = NULL ;
+    LPSPropValue resValue  = NULL ;
+     ULONG valueCount = 0 ;
+   
+    mLastError = OpenEntry(aEntry->mByteCount, aEntry->mEntryId,
+                                         &IID_IMAPIProp, 0, &objType, 
+                                         (IUnknown **)&object) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    
+    ULONG conditionType = 0 ;
+    conditionType = aRestriction->rt;
+
+    switch (conditionType) 
+    {
+    case RES_EXIST  :
+        if (!GetMAPIProperties(*aEntry,&aRestriction->res.resExist.ulPropTag,1,realValue,valueCount)) 
+            return FALSE;
+        resValue = NULL;
+        break ;
+    case RES_CONTENT :
+        if (!GetMAPIProperties(*aEntry,&aRestriction->res.resContent.ulPropTag,1,realValue,valueCount)) 
+            return FALSE;
+        resValue = aRestriction->res.resContent.lpProp;
+        break ;
+    case RES_PROPERTY :
+        if (!GetMAPIProperties(*aEntry,&aRestriction->res.resProperty.ulPropTag,1,realValue,valueCount)) 
+            return FALSE;
+        resValue = aRestriction->res.resProperty.lpProp;
+        break ;
+    case RES_BITMASK  :
+        return FALSE; //not support
+        break ;
+    case RES_SIZE :
+        return FALSE;//not been used now
+        break ;
+    case RES_COMPAREPROPS :
+        return FALSE;//not been used now
+        break ;
+    case RES_NOT :
+        return FALSE;//not need care here
+        break;
+    case RES_AND :
+        return FALSE;//not need care here
+        break;
+    case RES_OR :
+        return FALSE;//not need care here
+        break;
+    case RES_COMMENT :
+        return TRUE;//comment
+        break;
+    case RES_SUBRESTRICTION :
+        return FALSE;//not been used now
+        break ;
+}
+    return AtomyFilter(aRestriction,realValue,resValue);
+
+}
+
+BOOL nsMapiAddressBook::AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue)
+{
+    ULONG conditionType = 0 ;
+    conditionType = aRestriction->rt;
+
+    BOOL bTagEq=(aRealValue &&
+                PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) && 
+                aFilterValue;
+                // PROP_TYPE( aRealValue->ulPropTag ) == PROP_TYPE( aFilterValue->ulPropTag ));
+    switch (conditionType) 
+    {
+    case RES_EXIST  :
+        return (aRealValue && PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) ;
+        break ;
+    case RES_CONTENT :
+        if (bTagEq)
+        {
+            switch(aRestriction->res.resContent.ulFuzzyLevel)
+            {
+            case FL_FULLSTRING :
+                return !stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA);
+                break;
+            case FL_PREFIX :
+                return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == aRealValue->Value.lpszA;
+                break;
+            case FL_SUBSTRING :
+            default:
+                return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
+                break;
+            }
+        }
+        return FALSE;
+        break ;
+    case RES_PROPERTY :
+        if (bTagEq)
+        {
+            switch(aRestriction->res.resProperty.relop)
+            {
+            case RELOP_GE :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) >= 0;
+                break;
+            case RELOP_GT :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) > 0;
+                break;
+            case RELOP_LE :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) <= 0;
+                break;
+            case RELOP_LT :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) < 0;
+                break;
+            case RELOP_EQ :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == 0;
+                break;
+            case RELOP_NE :
+                return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != 0;
+                break;
+            case RELOP_RE :
+            default:
+                return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
+                break;
+
+            }
+        }
+        return FALSE;
+        break ;
+    case RES_BITMASK  :
+        return FALSE; //not support
+        break ;
+    case RES_SIZE :
+        return FALSE;//not been used now
+        break ;
+    case RES_COMPAREPROPS :
+        return FALSE;//not been used now
+        break ;
+    case RES_NOT :
+        return FALSE;//not need care here
+        break;
+    case RES_AND :
+        return FALSE;//not need care here
+        break;
+    case RES_OR :
+        return FALSE;//not need care here
+        break;
+    case RES_COMMENT :
+        return TRUE;//comment
+        break;
+    case RES_SUBRESTRICTION :
+        return FALSE;//not been used now
+        break ;
+    }
+    return TRUE;
+}
+
+BOOL nsMapiAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
+                                nsMapiEntryArray *aList, ULONG aMapiType)
+{
+    if (aList)
+        aList->CleanUp();
+
+    nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
+    nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
+    ULONG objType = 0 ;
+    ULONG rowCount = 0 ;
+
+
+    nsMapiInterfaceWrapper<LPMAPIPROP> pFolder;
+    nsCString cs;
+    aParent.ToString(cs);
+    
+    mLastError = OpenEntry(aParent.mByteCount,     aParent.mEntryId,
+                    0, 0, &objType, pFolder);
+    if (HR_FAILED(mLastError))
+    {
+        PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
+        return FALSE;
+    }
+
+
+    LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&pFolder,PR_MESSAGE_CLASS);
+    if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
+    {
+        HRESULT             hr;
+        LPSPropValue aValue = NULL ;
+        ULONG aValueCount = 0 ;
+
+        LPSPropTagArray properties = NULL ;
+        mMAPIAllocateBuffer(CbNewSPropTagArray(1),
+                           (void **)&properties);
+        properties->cValues = 1;
+        properties->aulPropTag [0] = GetEmailPropertyTag(*(LPMAPIPROP*)&pFolder,OUTLOOK_EMAIL_LIST1);
+        hr = pFolder->GetProps(properties, 0, &aValueCount, &aValue) ;
+
+        SBinaryArray *sa=&aValue->Value.MVbin;
+
+        LPENTRYID    lpEID;
+        ULONG        cbEID;
+        
+        ULONG idx;
+        nsMapiEntry testEntry;
+        nsCString sClass;
+        for (idx=0;sa->lpbin && idx<sa->cValues ;idx++)
+        {
+            lpEID= (LPENTRYID) sa->lpbin[idx].lpb;
+            cbEID = sa->lpbin[idx].cb;
+            testEntry.Assign(sa->lpbin[idx].cb,NS_REINTERPRET_CAST(LPENTRYID,sa->lpbin[idx].lpb));
+            
+            if (GetPropertyString(testEntry,PR_MESSAGE_CLASS,sClass)) //Error get property
+            {
+                aList->AddItem(cbEID,lpEID);
+            }
+        }
+        Filter(aRestriction,aList);
+    }
+    else
+    {
+        if (aRestriction && !CorrectRestriction(*(LPMAPICONTAINER*)&pFolder,1,aRestriction))
+            return FALSE;
+        mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIContainer, 0, &objType,
+                                         parent) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+
+        mLastError = parent->GetContentsTable(0, contents) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
+            return FALSE;
+        }
+        if (aRestriction) {
+            mLastError = contents->Restrict(aRestriction, TBL_BATCH) ;
+            if (HR_FAILED(mLastError)) {
+                PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
+                return FALSE ;
+            }
+        }
+        mLastError = contents->SetColumns((LPSPropTagArray)&ContentsColumns, 0);
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+        mLastError = contents->GetRowCount(0, &rowCount) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+        do {
+            LPSRowSet rowSet = NULL ;
+
+            rowCount = 0 ;
+            mLastError = contents->QueryRows(1, 0, &rowSet) ;
+            if (HR_FAILED(mLastError)) {
+                PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
+                return FALSE ;
+            }
+            rowCount = rowSet->cRows ;
+            if (rowCount > 0 && aList)
+            {
+                if (aMapiType == 0 || rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)
+                {
+                    SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
+                    aList->AddItem(currentValue.Value.bin.cb,
+                        NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
+                }
+                else if (aMapiType == MAPI_DISTLIST)
+                {
+                    if (strcmp("IPM.DistList",rowSet->aRow->lpProps[ContentsColumnMessageClass].Value.lpszA)==0)
+                    {
+                        SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
+                        aList->AddItem(currentValue.Value.bin.cb,
+                            NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
+
+                    }
 }
 
+            }
+            MyFreeProws(rowSet) ;
+        } while (rowCount > 0) ;
+    }
 
 
+    return TRUE ;
+}
 
+BOOL nsMapiAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
+                                      ULONG aNbProperties, LPSPropValue& aValue,
+                                      ULONG& aValueCount)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
+    ULONG objType = 0 ;
+    LPSPropTagArray properties = NULL ;
+    ULONG i = 0 ;
+    
+    mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType, 
+                                         object) ;
 
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    AllocateBuffer(CbNewSPropTagArray(aNbProperties),
+                   NS_REINTERPRET_CAST(void **, &properties));
+    properties->cValues = aNbProperties ;
+    for (i = 0 ; i < aNbProperties ; ++ i)
+    {
+        properties->aulPropTag [i] = GetRealMapiPropertyTag(*(LPMAPIPROP*)&object,aPropertyTags [i],TRUE);
+    }
+    mLastError = object->GetProps(properties, 0 , &aValueCount, &aValue) ;
+    FreeBuffer(properties) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Error get props %08x.\n", mLastError)) ;
+    }
+    return HR_SUCCEEDED(mLastError);
+}
+
+BOOL nsMapiAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
+                                      LPSPropValue& aValues)
+{
+    nsMapiInterfaceWrapper<LPMESSAGE> object;
+    ULONG objType = 0 ;
+    LPSPropProblemArray problems = NULL ;
+    ULONG i = 0 ;
+
+    LPMDB lpMsgStore=GetMsgStore(aObject);
+    
+    if (!lpMsgStore)
+    {
+        return FALSE;
+    }
+    mLastError = lpMsgStore->OpenEntry(aObject.mByteCount, aObject.mEntryId,
+                                         &IID_IMessage, MAPI_MODIFY , &objType, 
+                                         object) ;
+    lpMsgStore->Release();
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    for (i = 0 ; i < aNbProperties ; ++ i)
+    {
+        aValues[i].ulPropTag = GetRealMapiPropertyTag(*(LPMESSAGE*)&object,aValues[i].ulPropTag,TRUE);
+    }
+    mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    if (problems) {
+        for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
+            PRINTF(("Problem %d: index %d code %08x.\n", i,
+                problems->aProblem [i].ulIndex,
+                problems->aProblem [i].scode)) ;
+        }
+    }
+    mLastError = object->SaveChanges(0) ;
+    if (MAPI_E_OBJECT_CHANGED == mLastError)
+    {
+        mLastError = object->SaveChanges(FORCE_SAVE ) ;
+    }
+    return HR_SUCCEEDED(mLastError) ;
+}
+
+BOOL nsMapiAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
+{
+    return FALSE ;
+}
+
+BOOL nsMapiAddressBook::IsOK(void)
+{
+    return mRootSession && mLibUsage;
+}
+
+BOOL nsMapiAddressBook::Initialize(void)
+{
+
+    nsAutoLock guard(mMutex) ;
+
+    if (!LoadMapiLibrary()) {
+        PRINTF(("Cannot load library.\n")) ;
+        return FALSE ;
+    }
+    return TRUE;
+}
+
+void nsMapiAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
+{
+    mMAPIAllocateBuffer(aByteCount, aBuffer) ;
+}
+
+void nsMapiAddressBook::FreeBuffer(LPVOID aBuffer)
+{
+    mMAPIFreeBuffer(aBuffer) ;
+}
+
+ULONG nsMapiAddressBook::GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID)
+{
+    static GUID emailGUID =
+    {
+       0x00062004, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46
+    };
+
+
+  MAPINAMEID mapiNameID;
+  mapiNameID.lpguid = &emailGUID;
+  mapiNameID.ulKind = MNID_ID;
+  mapiNameID.Kind.lID = nameID;
+
+  LPMAPINAMEID lpMapiNames = &mapiNameID;
+  LPSPropTagArray lpMailTagArray = NULL;
+
+  HRESULT result = lpProp->GetIDsFromNames(1L, &lpMapiNames, 0, &lpMailTagArray);
+  if (result == S_OK)
+  {
+    ULONG lTag = lpMailTagArray->aulPropTag[0];
+    mMAPIFreeBuffer(lpMailTagArray);
+    return lTag;
+  }
+  return 0L;
+}
+ULONG nsMapiAddressBook::GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest)
+{
+    LPSPropValue addr;
+    ULONG        upRealTag=aPropertyTag;
+    ULONG        lSize=sizeof(TagMaps) / sizeof(TagMap);
+    
+    for(int i=0; i<lSize; i++)
+    {
+        if (TagMaps[i].AddressTag == aPropertyTag)
+        {
+
+            ULONG kPriEmailColumn=GetEmailPropertyTag(lpProp,TagMaps[i].NameID);
+            if (aTest)
+            {
+                if (PR_DISPLAY_NAME_A == aPropertyTag)
+                {
+                    //We need not change PR_DISPLAY_NAME_A tag if we are not using an address
+                    LPSPropValue msgClass=GetMapiProperty(lpProp,PR_MESSAGE_CLASS);
+                    if (msgClass && !strcmp("IPM.Contact",msgClass->Value.lpszA))
+                    {
+                        if (kPriEmailColumn)
+                            upRealTag  = kPriEmailColumn | TagMaps[i].TypeMask;
+                    }
+                    else
+                    {
+                        FreeBuffer(msgClass);
+                        upRealTag = aPropertyTag;
+                    }
+                }
+                else //PR_DISPLAY_NAME_A == aPropertyTag
+                {
+                    addr=GetMapiProperty(lpProp,aPropertyTag);
+                    if (!addr || PROP_TYPE( addr->ulPropTag) == PT_ERROR ||
+                        addr->Value.l == MAPI_E_NOT_FOUND)
+                    {
+                        if (kPriEmailColumn)
+                            upRealTag  = kPriEmailColumn | TagMaps[i].TypeMask;
+                    }
+                }
+            }
+            else //aTest
+            {
+                if (kPriEmailColumn)
+                    upRealTag  = kPriEmailColumn | TagMaps[i].TypeMask;
+            }
+      
+            break; //we find it,exit
+        }
+    }
+
+    return upRealTag;
+}
+
+BOOL nsMapiAddressBook::GetPropertyLong(const nsMapiEntry& aObject,
+                                    ULONG aPropertyTag,
+                                    ULONG& aValue)
+{
+    aValue = 0 ;
+    LPSPropValue values = NULL ;
+    ULONG valueCount = 0 ;
+
+    if (PR_OBJECT_TYPE == aPropertyTag)
+    {
+        nsMapiInterfaceWrapper<LPMAPIFOLDER> pFolder ;
+        ULONG objType=0;
+        mLastError = OpenEntry(aObject.mByteCount,aObject.mEntryId,
+                         NULL,0,&objType, pFolder);
+        if (HR_FAILED(mLastError))
+        {
+            PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
+            return FALSE;
+        }
+        LPSPropValue msgClass=GetMapiProperty(*(LPMAPIFOLDER*)&pFolder,PR_MESSAGE_CLASS);
+        if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
+        {
+            FreeBuffer(msgClass);
+            aValue = MAPI_DISTLIST;
+            return TRUE;
+        }
+    }
+
+    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) 
+        return FALSE ;
+
+    if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_LONG) {
+        aValue = values->Value.ul ;
+    }
+    FreeBuffer(values) ;
+    return TRUE ;
+}
+
+BOOL nsMapiAddressBook::GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
+                                    WORD& aYear, WORD& aMonth, WORD& aDay)
+{
+    aYear = 0;
+    aMonth = 0;
+    aDay = 0;
+    LPSPropValue values = NULL ;
+    ULONG valueCount = 0 ;
+
+    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount))
+        return FALSE ;
+
+    if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
+        SYSTEMTIME readableTime ;
+        FILETIME   localTime ;
+        FileTimeToLocalFileTime(&values->Value.ft,&localTime);
+        if (FileTimeToSystemTime(&localTime, &readableTime)) {
+            aYear = readableTime.wYear ;
+            aMonth = readableTime.wMonth ;
+            aDay = readableTime.wDay ;
+        }
+    }
+    FreeBuffer(values) ;
+    return TRUE ;
+}
+
+HRESULT     nsMapiAddressBook::OpenEntry(ULONG cbEntryID,
+                    LPENTRYID lpEntryID,
+                    LPCIID lpInterface,
+                    ULONG ulFlags,
+                    ULONG FAR * lpulObjType,
+                    LPUNKNOWN FAR * lppUnk
+                    )
+{
+
+    int err;
+    HRESULT rv;
+    __try
+    {
+        rv=mRootSession->OpenEntry(cbEntryID,
+                    lpEntryID,
+                    lpInterface,
+                    ulFlags ,
+                    lpulObjType,
+                    lppUnk
+                    );
+    }__except(err)
+    {
+        return (-1);
+    }
+
+    if (HR_FAILED(rv) && !m_MDBArray.Count())
+    {
+        //There are no openned Message store,so we have to open them all
+        nsMapiEntryArray aFolders;
+        if (GetFolders(aFolders))
+        {
+            __try
+            {
+                rv=mRootSession->OpenEntry(cbEntryID,
+                            lpEntryID,
+                            lpInterface,
+                            ulFlags ,
+                            lpulObjType,
+                            lppUnk
+                            );
+            }__except(err)
+            {
+                return (-1);
+            }
+        }
+    }
+    return rv;
+
+}
+
+BOOL nsMapiAddressBook::AddEntryToList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> container ;
+    ULONG objType = 0 ;
+
+    nsMapiEntry parentEntry;
+    if (!GetEntryParent(aDistlist,parentEntry))
+        return FALSE;
+    
+    LPMDB lpMsgStore=GetMsgStore(parentEntry);
+    
+    if (!lpMsgStore)
+        return FALSE;
+    mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
+                                         &IID_IMAPIProp, MAPI_MODIFY, &objType,
+                                         container) ;
+    lpMsgStore->Release();
+
+    if (HR_FAILED(mLastError))       
+        return FALSE ;
+    
+
+    /*
+    When add mail address to distlist,Mapi need update 2 tag.
+    */
+    //update OUTLOOK_EMAIL_LIST1
+    ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
+    SBinaryArray oldChilds;
+    LPSBinary    bins=NULL;
+    SBinaryArray newChilds;
+    LPSPropValue oldChildValue = NULL ;
+    ULONG valueCount = 0 ;
+
+    if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
+    {
+        PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
+        return FALSE;
+    }
+
+    if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
+    {
+        oldChilds = oldChildValue->Value.MVbin;
+        newChilds.cValues=oldChilds.cValues + 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+        for (ULONG i=0;i<oldChilds.cValues;i++)
+        {
+            newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
+            newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
+        }
+    }
+    else
+    {
+        newChilds.cValues = 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+    }
+
+    nsMapiEntry orgEntryID;
+    if (!GetPropertyBin(aNewEntry,
+        GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_ORGID) | PT_BINARY,
+        orgEntryID))
+    {
+        return FALSE;
+    }
+    newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
+    newChilds.lpbin[newChilds.cValues-1].cb  = orgEntryID.mByteCount;
+
+    SPropValue childs;
+    childs.ulPropTag = listTag;
+    childs.Value.MVbin = newChilds;
+
+    LPSPropProblemArray problems = NULL ;
+    mLastError = container->SetProps(1, &childs, &problems) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    //update OUTLOOK_EMAIL_LIST2
+    listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
+    if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
+    {
+        PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
+        return FALSE;
+    }
+    
+    if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
+    {
+        oldChilds = oldChildValue->Value.MVbin;
+        newChilds.cValues=oldChilds.cValues + 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+        for (ULONG i=0;i<oldChilds.cValues;i++)
+        {
+            newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
+            newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
+        }
+    }
+    else
+    {
+        newChilds.cValues = 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+    }
+
+    /*
+    Need more work here.
+    There are two kind of mail address in outlook DistList.
+    One is sample,not include in parent folder.
+    The other is a link to a unattached address in parents folders.
+    Currently we can only add first kind of address to a outlook distlist.
+    */
+    
+    newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
+    newChilds.lpbin[newChilds.cValues-1].cb  = orgEntryID.mByteCount;
+
+    childs.ulPropTag = listTag;
+    childs.Value.MVbin = newChilds;
+
+    mLastError = container->SetProps(1, &childs, &problems) ;
+    if (HR_FAILED(mLastError))
+    {
+        PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    mMAPIFreeBuffer(bins);
+
+    mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    return TRUE ;
+}
+BOOL nsMapiAddressBook::DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> container ;
+    ULONG objType = 0 ;
+
+    nsMapiEntry parentEntry;
+    if (!GetEntryParent(aDistlist,parentEntry))
+        return FALSE;
+
+    LPMDB lpMsgStore=GetMsgStore(parentEntry);
+    if (!lpMsgStore)
+        return FALSE;
+
+    mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
+                                         &IID_IMAPIProp, MAPI_MODIFY, &objType,
+                                         container) ;
+    lpMsgStore->Release();
+
+    if (HR_FAILED(mLastError))
+        return FALSE ;
+    /*
+    When delete mail address from distlist,Mapi need update 2 tag.
+    */
+    //update OUTLOOK_EMAIL_LIST1
+    ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
+
+    SBinaryArray oldChilds;
+    LPSBinary    bins=NULL;
+    SBinaryArray newChilds;
+    LPSPropValue oldChildValue = NULL ;
+    ULONG valueCount = 0 ;
+
+    newChilds.lpbin=NULL;
+
+    ULONG lDeleteEntry=0;
+    ULONG newIndex=0;
+    ULONG oldIndex=0;
+    if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
+    {
+        PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
+        return FALSE;
+    }
+    
+    if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
+    {
+        oldChilds = oldChildValue->Value.MVbin;
+        newChilds.cValues=oldChilds.cValues - 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+        for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
+        {
+            if ( oldChilds.lpbin[oldIndex].cb == aNewEntry.mByteCount &&
+                !memcmp((void*)(oldChilds.lpbin[oldIndex].lpb+4),
+                        (void*)(aNewEntry.mEntryId->ab),
+                        oldChilds.lpbin[oldIndex].cb-4))
+            {
+                lDeleteEntry=oldIndex;
+            }
+            else
+            {
+                newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
+                newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
+                newIndex++;
+            }
+        }
+    }
+    else
+        return FALSE;
+
+
+    SPropValue childs;
+    LPSPropProblemArray problems = NULL ;
+    
+    if (newChilds.cValues == 0)
+    {
+        SPropTagArray delTags;
+        delTags.cValues = 1;
+        delTags.aulPropTag[0] = listTag;
+
+        mLastError = container->DeleteProps(&delTags, &problems) ;
+    }
+    else
+    {
+        childs.ulPropTag = listTag;
+        childs.Value.MVbin = newChilds;
+        mLastError = container->SetProps(1, &childs, &problems) ;
+    }
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    //update OUTLOOK_EMAIL_LIST2
+    listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
+    if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
+    {
+        PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
+        return FALSE;
+    }
+
+    newIndex=0;
+    if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
+    {
+        oldChilds = oldChildValue->Value.MVbin;
+        newChilds.cValues=oldChilds.cValues - 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+        for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
+        {
+            if (oldIndex != lDeleteEntry)
+            {
+                newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
+                newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
+                newIndex++;
+            }
+        }
+    }
+    else
+    {
+        newChilds.cValues = 1;
+        mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
+        newChilds.lpbin = bins;
+    }
+
+
+    
+    if (newChilds.cValues == 0)
+    {
+        SPropTagArray delTags;
+        delTags.cValues = 1;
+        delTags.aulPropTag[0] = listTag;
+
+        mLastError = container->DeleteProps(&delTags, &problems) ;
+    }
+    else
+    {
+        childs.ulPropTag = listTag;
+        childs.Value.MVbin = newChilds;
+        mLastError = container->SetProps(1, &childs, &problems) ;
+    }
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    mMAPIFreeBuffer(bins);
+
+    mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    return TRUE ;
+}
+
+BOOL nsMapiAddressBook::GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
+    ULONG objType = 0 ;
+    mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType,
+                                         (IUnknown **)&object) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    SPropValue *parentID=GetMapiProperty(*(LPMAPIPROP*)&object, PR_PARENT_ENTRYID);
+
+    if (parentID->Value.l == MAPI_E_NOT_FOUND)
+        return FALSE;
+    aParentEntry.Assign(parentID->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, parentID->Value.bin.lpb));
+    return TRUE;
+}
+BOOL nsMapiAddressBook::CreateEntryInList(const nsMapiEntry& aDistlist, nsMapiEntry& aNewEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> container ;
+    ULONG objType = 0 ;
+
+    nsMapiEntry parentEntry;
+    if (!GetEntryParent(aDistlist,parentEntry))
+    {
+        return FALSE;
+    }
+    nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
+    if (!CreateEntry(parentEntry,aNewEntry)) //Create a entry in parent folder
+        return FALSE;
+
+    return AddEntryToList(aDistlist,aNewEntry);
+}
+
+BOOL nsMapiAddressBook::CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
+    ULONG objType = 0 ;
+
+    nsMapiInterfaceWrapper<LPMAPIPROP> object;
+    mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType,
+                                         object) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return NULL ;
+    }
+    LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
+
+    if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
+        return CreateEntryInList(aParent,aNewEntry);        //Create entry in DistList
+    
+    LPMDB lpMsgStore=GetMsgStore(aParent);
+    
+    if (!lpMsgStore)
+        return FALSE;
+    
+    mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIFolder, MAPI_MODIFY, &objType,
+                                         container) ;
+    lpMsgStore->Release();
+
+    if (HR_FAILED(mLastError))
+        return FALSE;
+    
+    nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
+
+    mLastError = container->CreateMessage(&IID_IMessage,
+                                        0,
+                                        newEntry) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    SPropValue messageclass ;
+    LPSPropProblemArray problems = NULL ;
+    nsCString tempName ;
+
+    messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
+    tempName.Assign("IPM.Contact") ;
+    messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
+    mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set temporary name %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    SPropTagArray property ;
+    LPSPropValue value = NULL ;
+    ULONG valueCount = 0 ;
+
+    property.cValues = 1 ;
+    property.aulPropTag [0] = PR_ENTRYID ;
+    mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
+    if (HR_FAILED(mLastError) || valueCount != 1) {
+        PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
+    FreeBuffer(value) ;
+    return TRUE ;
+}
+
+BOOL nsMapiAddressBook::CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
+    ULONG objType = 0 ;
+
+    LPMDB lpMsgStore=GetMsgStore(aParent);
+    if (!lpMsgStore)
+        return FALSE;
+    mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIFolder, MAPI_MODIFY, &objType,
+                                         container) ;
+    lpMsgStore->Release();
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
+    mLastError = container->CreateMessage(&IID_IMAPIProp,
+                                        0,
+                                        newEntry) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    SPropValue messageclass ;
+    LPSPropProblemArray problems = NULL ;
+    nsCString tempName ;
+
+    messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
+    tempName.Assign("IPM.DistList") ;
+    messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
+    mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set PR_MESSAGE_CLASS_A %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    ULONG valueCount = 0 ;
+    SPropTagArray property ;
+    LPSPropValue value = NULL ;
+
+    property.cValues = 1 ;
+    property.aulPropTag [0] = PR_ENTRYID ;
+    mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
+    if (HR_FAILED(mLastError) || valueCount != 1) {
+        PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
+
+    FreeBuffer(value) ;
+    return TRUE ;
+}
+
+
+BOOL nsMapiAddressBook::CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource,
+                              nsMapiEntry& aTarget)
+{
+    nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
+    nsMapiInterfaceWrapper<LPMAPIFOLDER> targetFolder ;
+    ULONG objType = 0 ;
+    nsMapiInterfaceWrapper<LPMAPIPROP> object;
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType,
+                                         object) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
+
+    if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
+    {
+        //Add Entry To DistList
+        if (!AddEntryToList(aContainer,aSource))
+            return FALSE;
+        aTarget.Assign(aSource.mByteCount,aSource.mEntryId);
+        return TRUE;
+    }
+
+    SBinary entry ;
+    SBinaryArray entryArray ;
+
+    entry.cb = aSource.mByteCount ;
+    entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aSource.mEntryId) ;
+    entryArray.cValues = 1 ;
+    entryArray.lpbin = &entry ;
+ 
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+                                         &IID_IMAPIFolder, MAPI_MODIFY, &objType,
+                                         container) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    mLastError = OpenEntry(aTarget.mByteCount, aTarget.mEntryId,
+                                         &IID_IMAPIFolder, MAPI_MODIFY, &objType,
+                                         targetFolder) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open Target folder %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+
+    nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;
+
+    mLastError = container->CopyMessages(&entryArray,
+                                        &IID_IMessage,
+                                        (void*)&targetFolder,
+                                        0,
+                                        NULL,
+                                        NULL) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    return TRUE ;
+}
+
+BOOL nsMapiAddressBook::DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
+    ULONG objType = 0 ;
+    SBinary entry ;
+    SBinaryArray entryArray ;
+
+    
+    nsMapiInterfaceWrapper<LPMAPIPROP> object;
+    mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType,
+                                         object) ;
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
+
+    if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
+        return DeleteEntryFromList(aContainer,aEntry);      //Delete Entry from DistList
+
+    LPMDB lpMsgStore=GetMsgStore(aContainer);
+    if (!lpMsgStore)
+        return FALSE;
+
+    mLastError = lpMsgStore->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
+                                         &IID_IMAPIFolder, MAPI_MODIFY, &objType, 
+                                         container) ;
+    lpMsgStore->Release();
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    entry.cb = aEntry.mByteCount ;
+    entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aEntry.mEntryId) ;
+    entryArray.cValues = 1 ;
+    entryArray.lpbin = &entry ;
+    mLastError = container->DeleteMessages(&entryArray, 0,0,0) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot delete entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    return TRUE ;
+}
+
+//Use to open message store in write mode
+LPMDB nsMapiAddressBook::GetMsgStore(const nsMapiEntry& aEntry)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> object;
+    ULONG objType=0;
+
+    mLastError = OpenEntry(aEntry.mByteCount, aEntry.mEntryId,
+                                         &IID_IMAPIProp, MAPI_BEST_ACCESS  , &objType, 
+                                         object) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return NULL ;
+    }
+    SPropValue *svMsgSore=GetMapiProperty( *(LPMAPIPROP*)&object, PR_STORE_ENTRYID);;
+
+    LPMDB  lpMsgStore=NULL;
+    mLastError=mRootSession->OpenMsgStore(0,
+                              svMsgSore->Value.bin.cb,
+                              (ENTRYID*)svMsgSore->Value.bin.lpb,
+                              &IID_IMsgStore,
+                              MDB_NO_MAIL  | MDB_WRITE ,
+                              &lpMsgStore);
+
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open MsgStore %08x.\n", mLastError)) ;
+        return NULL ;
+    }
+    
+    return lpMsgStore;
+}
Index: mailnews/addrbook/src/nsMapiAddressBook.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h	9 Dec 2003 03:26:47 -0000	1.2
@@ -40,12 +40,42 @@
 
 #include "nsAbWinHelper.h"
  
+struct TagMap
+{
+    ULONG AddressTag;
+    ULONG NameID;
+    ULONG TypeMask;
+};
 class nsMapiAddressBook : public nsAbWinHelper
 {
 public :
     nsMapiAddressBook(void) ;
     virtual ~nsMapiAddressBook(void) ;
 
+    // Get the top address books
+    virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
+
+    // Get a default address book container
+    virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
+    // Is the helper correctly initialised?
+    virtual BOOL IsOK(void);
+    virtual BOOL GetPropertyLong(const nsMapiEntry& aObject,
+                                    ULONG aPropertyTag,
+                                    ULONG& aValue);
+    // Get the value of a MAPI property of type SYSTIME
+    virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
+                         WORD& aYear, WORD& aMonth, WORD& aDay);
+    // Create entry in the address book
+    virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
+    // Delete an entry in the address book
+    virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
+    // Create a distribution list in the address book
+    virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
+    // Copy an existing entry in the address book
+    virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
+
+    static void FreeMapiLibrary(void) ;
+
 protected :
     // Class members to handle the library/entry points
     static HMODULE mLibrary ;
@@ -67,19 +97,77 @@
     static BOOL mInitialized ;
     static BOOL mLogonDone ;
     static LPMAPISESSION mRootSession ;
-    static LPADRBOOK mRootBook ;
+
 
     // Load the MAPI environment
     BOOL Initialize(void) ;
+
+    virtual HRESULT OpenEntry(ULONG cbEntryID,
+                    LPENTRYID lpEntryID,
+                    LPCIID lpInterface,
+                    ULONG ulFlags,
+                    ULONG FAR * lpulObjType,
+                    LPUNKNOWN FAR * lppUnk
+                    );
+ 
+
+    // Retrieve the contents of a container, with an optional restriction
+    virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
+                     nsMapiEntryArray *aList, ULONG aMapiType) ;
+    // Retrieve the values of a set of properties on a MAPI object
+    virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
+                           ULONG aNbProperties,
+                           LPSPropValue& aValues, ULONG& aValueCount) ;
+    // Set the values of a set of properties on a MAPI object
+    virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
+                           LPSPropValue& aValues);
+
+
     // Allocation of a buffer for transmission to interfaces
     virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
     // Destruction of a buffer provided by the interfaces
     virtual void FreeBuffer(LPVOID aBuffer) ;
     // Library management 
     static BOOL LoadMapiLibrary(void) ;
-    static void FreeMapiLibrary(void) ;
+
+    BOOL HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
+    LPSPropValue GetMapiProperty( LPMAPIPROP pProp, ULONG tag);
+    BOOL GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal=FALSE);
+    BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
+    BOOL IterateHierarchy(IMAPIContainer * pFolder, nsMapiEntryArray& aFolders,ULONG flags=0);
+    ULONG GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID);
+    ULONG GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest=FALSE);
+    LPMDB GetMsgStore(const nsMapiEntry& aEntry);
+    BOOL CreateEntryInList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry);
+    BOOL AddEntryToList(const nsMapiEntry& aParent,const nsMapiEntry& aNewEntry);
+    BOOL DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry);
+    BOOL GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry);
+    BOOL CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction);
+
+    //filter
+    BOOL Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList);
+    BOOL FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction);
+    BOOL AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue);
+
+    void AddToMDBArray(LPMDB aMDB)
+    {
+        m_MDBArray.AppendElement(aMDB);
+    }
+    void CleanUpMDB()
+    {
+        LPMDB mdb;
+        for (int i = 0; i < m_MDBArray.Count(); i++)
+        {
+            mdb = (LPMDB)m_MDBArray.ElementAt(i);
+            mdb->Release();
+        }
+        m_MDBArray.Clear();
+    }
 
 private :
+    //use to keep all openned MsgStore,if we not open a message store,we can't open any thing on it
+    //so we have to kill message stores openned
+    nsVoidArray        m_MDBArray; 
 } ;
 
 #endif // nsMapiAddressBook_h___
Index: mailnews/addrbook/src/nsWabAddressBook.cpp
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp	9 Dec 2003 03:26:47 -0000	1.2
@@ -47,6 +47,22 @@
 
 #define PRINTF(args) PR_LOG(gWabAddressBookLog, PR_LOG_DEBUG, args)
 
+enum
+{
+    ContentsColumnEntryId = 0,
+    ContentsColumnObjectType,
+    ContentsColumnsSize
+} ;
+
+static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
+{
+    ContentsColumnsSize,
+    {
+        PR_ENTRYID,
+        PR_OBJECT_TYPE
+    }
+} ;
+
 HMODULE nsWabAddressBook::mLibrary = NULL ;
 PRInt32 nsWabAddressBook::mLibUsage = 0 ;
 LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
@@ -95,7 +111,7 @@
 MOZ_DECL_CTOR_COUNTER(nsWabAddressBook)
 
 nsWabAddressBook::nsWabAddressBook(void)
-: nsAbWinHelper()
+: nsAbWinHelper(),mAddressBook(NULL)
 {
     BOOL result = Initialize() ;
 
@@ -110,9 +126,254 @@
     MOZ_COUNT_DTOR(nsWabAddressBook) ;
 }
 
+BOOL nsWabAddressBook::GetFolders(nsMapiEntryArray& aFolders)
+{
+    aFolders.CleanUp() ;
+    nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
+    nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
+    ULONG objType = 0 ;
+    ULONG rowCount = 0 ;
+    SRestriction restriction ;
+    SPropTagArray folderColumns ;
+
+    mLastError = OpenEntry(0, NULL, NULL, 0, &objType,
+                                         rootFolder);
+    if (HR_FAILED(mLastError)){
+        PRINTF(("Cannot open root %08x.\n", mLastError));
+        return FALSE;
+    }
+    mLastError = rootFolder->GetHierarchyTable(0, folders);
+    if (HR_FAILED(mLastError)){
+        PRINTF(("Cannot get hierarchy %08x.\n", mLastError));
+        return FALSE;
+    }
+    // We only take into account modifiable containers,
+    // otherwise, we end up with all the directory services...
+    restriction.rt = RES_BITMASK ;
+    restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
+    restriction.res.resBitMask.relBMR = BMR_NEZ ;
+    restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
+    mLastError = folders->Restrict(&restriction, 0) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
+    }
+    folderColumns.cValues = 1 ;
+    folderColumns.aulPropTag [0] = PR_ENTRYID ;
+    mLastError = folders->SetColumns(&folderColumns, 0) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    mLastError = folders->GetRowCount(0, &rowCount) ;
+    if (HR_SUCCEEDED(mLastError)) {
+        do {
+            LPSRowSet rowSet = NULL ;
+
+            rowCount = 0 ;
+            mLastError = folders->QueryRows(1, 0, &rowSet) ;
+            if (HR_SUCCEEDED(mLastError)) {
+                rowCount = rowSet->cRows ;
+                if (rowCount > 0) {
+                    SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
+                    
+                    aFolders.AddItem(currentValue.Value.bin.cb,
+                                   NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
+                }
+                MyFreeProws(rowSet) ;
+            }
+            else {
+                PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
+            }
+        } while (rowCount > 0) ;
+    }
+    return HR_SUCCEEDED(mLastError) ;
+}
+BOOL nsWabAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
+                                nsMapiEntryArray *aList, ULONG aMapiType)
+{
+    if (aList) { aList->CleanUp(); }
+    nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
+    nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
+    ULONG objType = 0 ;
+    ULONG rowCount = 0 ;
+
+    mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
+                                         &IID_IMAPIContainer, 0, &objType,
+                                         parent) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    // Here, flags for WAB and MAPI could be different, so this works
+    // only as long as we don't want to use any flag in GetContentsTable
+    mLastError = parent->GetContentsTable(0, contents) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    if (aRestriction) {
+        mLastError = contents->Restrict(aRestriction, 0) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+    }
+    int entryId = ContentsColumnEntryId ;
+    int objectType = ContentsColumnObjectType ;
+
+    if (aRestriction) 
+    {
+        LPSPropTagArray allColumns = NULL ;
+
+        mLastError = contents->QueryColumns(TBL_ALL_COLUMNS, &allColumns) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot query columns %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+
+        for (unsigned int j = 0 ; j < allColumns->cValues ; ++ j) {
+            if (allColumns->aulPropTag [j] == PR_ENTRYID) { 
+                entryId = j ; 
+            }
+            else if (allColumns->aulPropTag [j] == PR_OBJECT_TYPE) { 
+                objectType = j ; 
+            }
+        }
+        mLastError = contents->SetColumns(allColumns, 0) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+        FreeBuffer(allColumns) ;
+    }
+    else
+    {
+
+        mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+     }    
+    
+    mLastError = contents->GetRowCount(0, &rowCount) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    do {
+        LPSRowSet rowSet = NULL ;
+        
+        rowCount = 0 ;
+        mLastError = contents->QueryRows(1, 0, &rowSet) ;
+        if (HR_FAILED(mLastError)) {
+            PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
+            return FALSE ;
+        }
+        rowCount = rowSet->cRows ;
+        if (rowCount > 0 &&
+            (aMapiType == 0 ||
+            rowSet->aRow->lpProps[objectType].Value.ul == aMapiType)) {
+            if (aList) {
+                SPropValue& currentValue = rowSet->aRow->lpProps[entryId] ;
+                
+                aList->AddItem(currentValue.Value.bin.cb,
+                    NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
+                
+            }
+        }
+        MyFreeProws(rowSet) ;
+    } while (rowCount > 0) ;
+    return TRUE ;
+}
+
+BOOL nsWabAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
+                                      ULONG aNbProperties, LPSPropValue& aValue, 
+                                      ULONG& aValueCount)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
+    IMsgStore * mdb=NULL;
+    ULONG objType = 0 ;
+    LPSPropTagArray properties = NULL ;
+    ULONG i = 0 ;
+    
+    mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
+                                         &IID_IMAPIProp, 0, &objType, 
+                                         object) ;
+
+    if (HR_FAILED(mLastError)){
+        PRINTF(("Cannot open entry %08x.\n", mLastError));
+        return FALSE;
+    }
+    AllocateBuffer(CbNewSPropTagArray(aNbProperties),
+                   NS_REINTERPRET_CAST(void **, &properties));
+    properties->cValues = aNbProperties;
+    for (i = 0 ; i < aNbProperties ; ++ i) {
+        properties->aulPropTag [i] = aPropertyTags [i];
+    }
+    mLastError = object->GetProps(properties, 0, &aValueCount, &aValue);
+    FreeBuffer(properties);
+    if (HR_FAILED(mLastError)){
+        PRINTF(("Cannot get props %08x.\n", mLastError));
+    }
+    return HR_SUCCEEDED(mLastError) ;
+}
+
+BOOL nsWabAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
+                                      LPSPropValue& aValues)
+{
+    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
+    ULONG objType = 0 ;
+    LPSPropProblemArray problems = NULL ;
+
+    mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
+                                         &IID_IMAPIProp, MAPI_MODIFY, &objType, 
+                                         object) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
+        return FALSE ;
+    }
+    if (problems) {
+        for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
+            PRINTF(("Problem %d: index %d code %08x.\n", i,
+                problems->aProblem [i].ulIndex,
+                problems->aProblem [i].scode));
+        }
+    }
+    mLastError = object->SaveChanges(0) ;
+    if (HR_FAILED(mLastError)) {
+        PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
+    }
+    return HR_SUCCEEDED(mLastError) ;
+}
+
+BOOL nsWabAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
+{
+    LPENTRYID entryId = NULL;
+    ULONG byteCount = 0;
+
+    mLastError = mAddressBook->GetPAB(&byteCount, &entryId);
+    if (HR_FAILED(mLastError)){
+        PRINTF(("Cannot get PAB %08x.\n", mLastError));
+        return FALSE;
+    }
+    aContainer.Assign(byteCount, entryId);
+    FreeBuffer(entryId) ;
+    return TRUE ;
+}
+
+BOOL nsWabAddressBook::IsOK(void)
+{
+    return mAddressBook != NULL ;
+}
+
 BOOL nsWabAddressBook::Initialize(void)
 {
-    if (mAddressBook) { return TRUE ; }
     nsAutoLock guard(mMutex) ;
 
     if (!LoadWabLibrary()) {
Index: mailnews/addrbook/src/nsWabAddressBook.h
===================================================================
RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsWabAddressBook.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h	22 Oct 2003 02:43:11 -0000	1.1.1.1
+++ miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h	9 Dec 2003 03:26:47 -0000	1.2
@@ -47,6 +47,15 @@
     nsWabAddressBook(void) ;
     virtual ~nsWabAddressBook(void) ;
 
+    // Get the top address books
+    virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
+
+    // Get a default address book container
+    virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
+    // Is the helper correctly initialised?
+    virtual BOOL IsOK(void);
+    static void FreeWabLibrary(void) ;
+
 protected :
     // Session and address book that will be shared by all instances
     // (see nsMapiAddressBook.h for details)
@@ -57,15 +66,46 @@
     static HMODULE mLibrary ;
     static LPWABOPEN mWABOpen ;
 
+    LPADRBOOK mAddressBook ;
+
     // Load the WAB environment
     BOOL Initialize(void) ;
+
+    virtual HRESULT OpenEntry(ULONG cbEntryID,
+                    LPENTRYID lpEntryID,
+                    LPCIID lpInterface,
+                    ULONG ulFlags,
+                    ULONG FAR * lpulObjType,
+                    LPUNKNOWN FAR * lppUnk
+                    )
+    {
+        return mAddressBook->OpenEntry(cbEntryID,
+                    lpEntryID,
+                    lpInterface,
+                    ulFlags,
+                    lpulObjType,
+                    lppUnk
+                    );
+    }
+ 
+
+    // Retrieve the contents of a container, with an optional restriction
+    virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
+                     nsMapiEntryArray *aList, ULONG aMapiType) ;
+    // Retrieve the values of a set of properties on a MAPI object
+    virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
+                           ULONG aNbProperties,
+                           LPSPropValue& aValues, ULONG& aValueCount) ;
+    // Set the values of a set of properties on a MAPI object
+    virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, 
+                           LPSPropValue& aValues) ;
+
     // Allocation of a buffer for transmission to interfaces
     virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
     // Destruction of a buffer provided by the interfaces
     virtual void FreeBuffer(LPVOID aBuffer) ;
     // Manage the library
     static BOOL LoadWabLibrary(void) ;
-    static void FreeWabLibrary(void) ;
 
 private :
 } ;
Index: profile/src/nsProfile.cpp
===================================================================
RCS file: /mozilla/mozilla/profile/src/nsProfile.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -w -b -i -r1.1.1.1 -r1.2
--- miss/build/mozilla/profile/src/nsProfile.cpp	22 Oct 2003 02:40:14 -0000	1.1.1.1
+++ miss/build/mozilla/profile/src/nsProfile.cpp	22 Oct 2003 09:45:04 -0000	1.2
@@ -555,6 +555,7 @@
                 rv = curProfileDir->Exists(&exists);
             if (NS_FAILED(rv) || !exists)
                 profileURLStr = PROFILE_MANAGER_URL; 
+#if 0
             if (exists)
             {
                 // If the profile is locked, we need the UI
@@ -564,6 +565,7 @@
                 if (NS_FAILED(rv))
                     profileURLStr = PROFILE_MANAGER_URL;
             } 
+#endif
         }
         else
             profileURLStr = PROFILE_SELECTION_URL;
@@ -1200,6 +1202,7 @@
     else
         isSwitch = PR_FALSE;
     
+#if 0
     nsProfileLock localLock;
     nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir, &rv));
     if (NS_FAILED(rv)) return rv;
@@ -1209,6 +1212,7 @@
         NS_ERROR("Could not get profile directory lock.");
         return rv;
     }
+#endif
 
     nsCOMPtr<nsIObserverService> observerService = 
              do_GetService("@mozilla.org/observer-service;1", &rv);
@@ -1244,7 +1248,9 @@
     gProfileDataAccess->SetCurrentProfile(aCurrentProfile);
     gProfileDataAccess->mProfileDataChanged = PR_TRUE;
     gProfileDataAccess->UpdateRegistry(nsnull);
+#if 0
     mCurrentProfileLock = localLock;
+#endif
             
     if (NS_FAILED(rv)) return rv;
     mCurrentProfileAvailable = PR_TRUE;
@@ -1331,7 +1337,9 @@
     UpdateCurrentProfileModTime(PR_TRUE);
     mCurrentProfileAvailable = PR_FALSE;
     mCurrentProfileName.Truncate(0);
+#if 0
     mCurrentProfileLock.Unlock();
+#endif
     
     return NS_OK;
 }

--- miss/build/mozilla/.mozconfig	Tue Jul 22 21:52:27 2003
+++ misc/build/mozilla/.mozconfig	Mon Jul 28 15:07:20 2003
@@ -0,0 +1,8 @@
+ac_add_options --disable-tests
+ac_add_options --disable-xprint
+ac_add_options --without-system-zlib
+ac_add_options --enable-ldap
+ac_add_options --disable-debug
+ac_add_options --enable-optimize
+ac_add_options --enable-crypto
+ac_add_options --enable-strip

--- misc/build/mozilla/client.mk	Fri Aug  1 10:14:27 2003
+++ misc/build/mozilla/client.mk	Fri Aug  1 10:11:31 2003
@@ -386,9 +386,9 @@
 	fi
 
 ifdef _IS_FIRST_CHECKOUT
-all:: checkout build
+all::  build
 else
-all:: checkout alldep
+all::  alldep
 endif
 
 # Windows equivalents