aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/image2.png
blob: e6a4c75dbe3adf79096ba3c1ce9080d99d2fd723 (plain) (blame)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 30 00 00 00 30 08 06 00 00 00 57 02 f9 .PNG........IHDR...0...0.....W..
0020 87 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 00 09 70 48 59 73 00 00 0b 12 00 00 0b .....gAMA......a.....pHYs.......
0040 12 01 d2 dd 7e fc 00 00 07 65 49 44 41 54 78 9c ed 97 db af 5c 55 1d c7 3f 6b 5f 67 9f 99 33 e7 ....~....eIDATx.....\U..?k_g..3.
0060 f4 b4 3d 3d a5 b4 b6 95 a2 72 2f 17 11 f1 16 8d 91 a0 89 68 73 0a bc a0 21 24 c6 7b 02 91 07 fd ..==.....r/........hs...!$.{....
0080 07 7c 10 8d 3c f0 e0 8b d1 a8 40 8f e1 6a 0b d1 42 11 b1 20 35 c5 90 88 bd 48 29 a5 97 73 99 73 .|..<.....@..j..B...5....H)..s.s
00a0 66 66 cf ec 3d 7b ed cb fa f9 30 a7 d3 9e 16 64 68 43 7c 70 be c9 ca 5c f6 9a d9 df cf 6f ad df ff..={....0....dhC|p...\.....o..
00c0 ef b7 36 0c 34 d0 40 03 0d 34 d0 40 ff 3b a9 7e 26 d9 b6 ad 8c 31 1e b0 c2 b2 d4 9d 28 75 39 02 ..6.4.@..4.@.;.~&....1......(u9.
00e0 22 06 11 00 59 7c 7d 57 cd 03 fb 80 83 c0 9b 40 0d 88 81 d6 b9 98 87 3e 00 4a 81 bf 31 08 82 d7 "...Y|}W.......@.......>.J..1...
0100 af bb ee 5a 66 66 4e e0 f9 1e 1b 36 ae 63 64 b4 c2 f8 f8 04 e5 60 88 91 d1 31 2a 95 0a 22 42 aa ...ZffN....6.cd......`...1*.."B.
0120 35 51 1c 11 45 6d 8e 1d 3f 86 29 0a c2 30 44 c4 a0 75 86 88 e2 ef 2f bf 42 b3 11 92 65 39 69 9a 5Q..Em..?.)..0D..u..../.B...e9i.
0140 62 8c f4 15 c8 73 02 18 19 19 be 61 6c c5 b2 dd db 77 3c 46 96 a5 0c 97 ab 94 cb 23 58 96 85 b2 b....s.....al....w<F.......#X...
0160 2c 8a 22 27 8a 22 8a 5c 63 3b 1e 5a c7 94 fc 80 2c cb c8 4c 46 bb 1d 62 29 45 27 89 69 36 eb c4 ,."'.".\c;.Z....,..LF..b)E'.i6..
0180 49 9b b8 13 d1 6e 47 3c b2 6d 07 bb 76 ee ee cb c7 3b c9 79 b7 09 59 96 bd d5 0e 63 ca 43 15 16 I....nG<.m..v....;.y..Y....c.C..
01a0 ea 73 44 9d 08 9d a5 20 86 34 cf 48 3a 31 ca 02 ad 35 b5 f9 69 8c 14 80 22 cb 32 d2 4c 23 22 20 .sD......4.H:1...5..i...".2.L#".
01c0 dd 2d 26 08 22 dd 71 e2 d8 2c 43 43 01 c0 3d e7 6a be 2f 80 38 4e 8e 26 49 4a 6d 7e 86 ea f0 28 .-&.".q..,CC..=.j./.8N.&IJm~...(
01e0 f5 46 8d 46 b8 40 79 a8 42 aa 35 71 12 51 2a 05 c4 71 84 63 3b 14 46 51 14 05 28 b5 d4 bc 48 0f .F.F.@y.B.5q.Q*..q.c;.FQ..(...H.
0200 20 4d 33 74 aa b1 1d 1b e0 0f e7 03 60 f5 45 e9 38 1c d8 ff 3a 95 f2 28 9d 24 a6 5c ae 92 67 05 .M3t........`.E.8...:..(.$.\..g.
0220 46 0c 16 a7 8c ea 2c 25 8f 3b 64 61 8b 24 6c 62 5b 76 2f e2 ca b2 7a ef 5b 61 44 d8 6c b3 77 cf F.....,%.;da.$lb[v/...z.[aD.l.w.
0240 ab d0 4d e6 73 d6 bb ae 00 80 88 99 5a b9 7c 7c 32 2f 32 d2 34 c1 18 43 10 94 89 ea 21 d5 ea 32 ..M.s.......Z.||2/2.4..C....!..2
0260 e6 17 66 28 95 ca 2c 6c df 45 f2 f2 ab 60 59 60 0c e9 68 15 eb 43 eb f0 ae be 04 29 79 5d 50 ba ..f(..,l.E...`Y`..h..C.....)y]P.
0280 2b 94 17 05 45 61 00 d2 f7 1d c0 b6 6d 62 1d 93 a4 1d 0a 11 ca 7e 89 46 73 1e 65 59 b4 a3 16 4a +...Ea......mb.......~.Fs.eY...J
02a0 29 a2 28 c4 f9 e8 65 8c dd 78 0d ed b0 8e 35 df 22 3d 78 98 e2 c0 11 3a 7b f7 61 7d f9 d3 58 17 ).(...e..x....5."=x....:{.a}..X.
02c0 ac c2 b2 2c 82 c0 27 f0 7d 9a 8d 16 40 7f 05 f8 7c 00 d2 34 23 d3 19 cd 46 0d 8c a1 d1 98 67 fe ...,..'.}...@...|..4#...F.....g.
02e0 af 7b 48 9e 79 09 93 a6 e0 38 04 df bb 8d d2 c8 30 51 dc 66 68 7c 25 71 25 c0 5e 37 4e 60 39 c4 .{H.y....8......0Q.fh|%q%.^7N`9.
0300 3b 77 63 9e 7c 1e f7 ae 2d e8 3c eb 7a 56 74 73 e5 94 26 17 c7 8b c0 cf fa 05 38 2b 07 2c cb ba ;wc.|...-.<.zVts..&.......8+.,..
0320 af 7b 07 04 f8 2e e0 18 63 3e a6 b5 66 ae 36 43 2b 6a d2 68 ce 53 ba e4 22 fc 2d 9f c5 1a 2e 43 .{......c>..f.6C+j.h.S..".-....C
0340 96 e3 da 1e 9d 4e 84 e7 fa 74 92 0e 22 dd 95 2b 2c 50 9f b9 06 aa 15 b2 67 5f 5e 4c 64 88 e3 0e .....N...t.."..+,P......g_^Ld...
0360 7e c9 03 58 eb 79 ee 53 43 e5 60 db fa 8d 6b 27 95 e2 a7 c0 7d e7 0a 70 9f 31 e6 ee af dd 79 2b ~..X.y.SC.`...k'....}..p.1....y+
0380 8f 3e f1 30 b7 dd 36 79 ff 45 9b 36 ec 1f 5b 3e ba b6 de 9e ee 6e 13 c7 c3 20 a8 92 8b fc fb 18 .>.0..6y.E.6..[>.....n..........
03a0 94 7c a0 5b 22 2d 65 51 98 82 a2 28 10 11 5c d7 27 4d 35 22 e0 7f e2 1a 8a e3 b3 bd 84 56 4a b1 .|.["-eQ...(..\.'M5".........VJ.
03c0 6a 62 25 d7 5e 7f e5 91 2f dd f2 85 9b 7e fb f0 2f 79 ea e9 ed dc 7a fb 57 01 ee 06 2e ec 07 60 jb%.^.../....~../y....z.W......`
03e0 c9 16 b2 6d 7b f2 9b df f9 3a f7 de fb 43 4c 5e b0 62 7c 04 c7 fe c6 c6 28 6a 31 57 3b 81 e3 ba ...m{....:...CL^.b|.....(j1W;...
0400 74 92 0e ae eb 13 bd 71 84 f4 5f 87 70 ef f8 22 c5 9e 7f 92 74 62 fc 60 88 44 27 20 82 5f 0a 88 t......q.._.p.."....tb.`.D'.._..
0420 e2 56 17 c4 f1 48 c6 ca a0 33 10 c1 f3 5c 2e ba 78 03 37 df 7c 13 d5 ea 32 86 2b 23 b4 a2 90 3d .V...H...3...\..x.7.|...2.+#...=
0440 7b 5f 60 f2 f6 5b 78 e9 c5 bd 1c 7e e3 f0 0d c0 d4 7b 02 10 91 b5 9b 36 5d 4c a3 5e e3 b5 03 7b {_`..[x....~.....{.....6]L.^...{
0460 71 1d 0f 65 59 a4 69 82 6d 3b 44 71 0b b5 58 1a ad b0 83 c9 32 c4 b1 b1 6e bc 12 11 21 d1 dd ad q..eY.i.m;Dq..X.....2...n...!...
0480 33 5c ae d2 8a 9a 8b 55 c7 c2 18 83 84 11 ea b4 9e e0 b9 2e b5 fa 2c f3 f5 1a 3a 4d 7a a5 f8 f8 3\.....U..............,...:Mz...
04a0 f4 31 66 a6 a7 fb 09 3e 70 c6 16 f2 7c 6f ea b5 d7 f6 d3 6c d5 41 84 34 d3 24 49 4c 51 14 a4 99 .1f....>p...|o.....l.A.4.$ILQ...
04c0 c6 88 60 4c 41 aa 3b e4 d5 00 2c b5 a4 bb 8a 80 ef fa e8 34 a1 48 33 e4 fe 87 b1 f3 82 74 7a 0e ..`LA.;...,........4.H3......tz.
04e0 f5 f8 9f 91 0d 17 f4 e6 26 5a 33 37 3b cf 5c ad 46 92 68 10 e1 c4 89 39 76 fd e9 05 3a 9d a4 6f ........&Z37;.\.F.h....9v...:..o
0500 80 a5 2b 60 cc d4 43 bf fb fd e4 07 d6 4f b0 e1 83 17 d2 0a db 3c bd 7d 17 61 d8 62 66 ba c6 0f ..+`..C......O.......<.}.a.bf...
0520 7e f4 2d 8c 31 20 82 1a 1f 03 23 98 c3 27 50 eb 57 23 02 25 3f e8 96 d4 b8 05 79 b7 c2 e4 61 1b ~.-.1.....#..'P.W#.%?.....y...a.
0540 f5 e4 f3 10 f8 98 1b af e8 01 2c d4 ea 3c f8 9b c7 71 6c 9b 44 6b ae ff f8 66 2a c3 65 9e db f9 ..........,..<...ql.Dk...f*.e...
0560 22 c0 5b f4 b1 7d ce 02 d0 3a 9d 12 61 ea 27 3f 7e 60 72 d3 87 37 72 70 ff 21 a2 a8 f3 56 96 66 ".[..}...:..a.'?~`r..7rp.!...V.f
0580 f7 38 ae b3 6d 6c d9 38 f3 f3 d3 bd 68 ab 8d 6b 28 9e dd 83 35 f9 39 28 0f 91 e7 a7 ce 3f ae e7 .8..ml.8....h..k(...5.9(.....?..
05a0 93 01 b2 fd 2f c8 f8 18 e6 53 9b 91 93 dd 18 21 0c db 4c 1f 9f 05 d8 0a 6c db fe d8 33 b8 ae 43 ..../....S.....!..L.....l...3..C
05c0 96 e5 00 77 f4 bb 02 67 95 d1 34 4d b7 36 1a cd 1b f6 bc f4 8f ad 8d 7a b8 55 27 7a 9d 31 66 ca ...w...g..4M.6.........z.U'z.1f.
05e0 98 82 20 28 f7 cc 0b 82 f5 c9 ab 20 d1 98 27 9e c7 74 74 cf bc e7 95 c0 73 bb 1d 2a ea a0 66 17 ...(..........'..tt.....s..*..f.
0600 b0 b7 ed 44 d2 ac 57 46 13 dd 6b c0 53 c0 72 60 4b 96 e5 0f 01 57 01 cf f5 0b d0 d7 31 36 08 4a ...D..WF..k.S.r`K....W......16.J
0620 25 63 4c 67 c7 1f a7 38 72 f4 d0 92 83 99 99 6b 20 8f 3c 0b 3a 85 c0 47 4a 3e ee a5 9b d0 97 ad %cLg...8r......k..<.:..GJ>......
0640 ef 3e f0 70 fa a1 4e ba 0d 46 84 bf ed 7e 85 07 7f fd 68 df 1e de 49 7d 75 62 20 bd ea ea 4b b1 .>.p..N..F...~....h...I}ub....K.
0660 6d 77 89 79 11 81 e5 23 70 d7 2d 70 7c 16 79 73 1a 0a 83 5e 5e e9 ce 59 34 7b ca fc a9 2a 54 ad mw.y...#p.-p|.ys...^^..Y4{...*T.
0680 56 4e fe f7 18 b0 f0 7e 03 0c 69 9d d1 8e 5a 67 55 9d 93 c6 58 bd 02 99 58 71 da b5 53 d7 cf 8c VN.....~..i...ZgU...X...Xq..S...
06a0 7e 37 47 7a b7 1e 3e 1f 80 be 8e d3 49 a2 bf b2 66 cd aa c5 67 e0 b7 31 7f fa e7 33 22 fd 76 e6 ~7Gz..>.....I...f...g..1...3".v.
06c0 45 04 94 62 62 f5 4a 80 cd e7 6a be 6f 00 11 f9 c5 65 57 5c 42 b3 55 5f 6a fe 4c 98 77 1a 9c fd E..bb.J...j.o....eW\B.U_j.L.w...
06e0 9d eb 3a 5c be f9 23 00 5b ce 07 a0 9f 04 b2 80 e2 db df bf 93 30 6c 32 ba ac 8a 6d 77 97 df 71 ..:\..#.[............0l2...mw..q
0700 6d 10 21 2f 0c 49 47 33 54 0e 08 c3 16 a6 30 ac 5c b5 02 cf 75 38 7a e4 38 ca b2 28 05 25 40 58 m.!/.IG3T.....0.\...u8z.8..(.%@X
0720 bd 66 15 45 61 88 a2 98 4e 3b e6 81 9f ff 0a 63 c4 03 b2 f7 0b c0 01 3e 5f 2e 97 77 24 49 42 65 .f.Ea...N;.....c.......>_..w$IBe
0740 b8 4c 29 f0 31 45 c1 c4 05 13 8c 8f 8f a1 75 8a ef fb e4 79 86 11 70 6d 9b 34 cf 10 23 64 79 8e .L).1E........u....y..pm.4..#dy.
0760 4e 74 ef 66 46 84 20 08 a8 54 02 12 9d 31 37 53 e3 c0 be 43 01 d0 7f fb 7d 8f 00 ff ed 77 6a 71 Nt.fF....T...17S...C....}....wjq
0780 9c cc c8 14 40 29 e5 01 c5 49 cf 4a 29 04 31 4a 29 14 0a db b1 3c 05 69 5e 18 55 e4 85 5a 9c 3b ....@)...I.J).1J)....<.i^.U..Z.;
07a0 d0 40 03 0d 34 d0 40 03 0d 34 d0 ff 9b fe 03 37 f9 c2 2b f1 6f 86 54 00 00 00 00 49 45 4e 44 ae .@..4.@..4.....7..+.o.T....IEND.
07c0 42 60 82 B`.
2'>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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* mail-ops.c: callbacks for the mail toolbar/menus */

/* 
 * Authors: 
 *  Dan Winship <danw@ximian.com>
 *  Peter Williams <peterw@ximian.com>
 *  Jeffrey Stedfast <fejj@ximian.com>
 *
 * Copyright 2000 Ximian, Inc. (www.ximian.com)
 *
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

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

#include <errno.h>
#include <time.h>
#include <libgnome/gnome-paper.h>
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-dialog-util.h>
#include <libgnomeui/gnome-stock.h>
#include <libgnome/gnome-paper.h>
#include <libgnomeprint/gnome-print-master.h>
#include <libgnomeprint/gnome-print-master-preview.h>
#include <bonobo/bonobo-widget.h>
#include <bonobo/bonobo-socket.h>
#include <gal/e-table/e-table.h>
#include <gal/widgets/e-gui-utils.h>
#include <filter/filter-editor.h>
#include "mail.h"
#include "message-browser.h"
#include "mail-callbacks.h"
#include "mail-config.h"
#include "mail-accounts.h"
#include "mail-config-druid.h"
#include "mail-mt.h"
#include "mail-tools.h"
#include "mail-ops.h"
#include "mail-local.h"
#include "mail-search.h"
#include "mail-send-recv.h"
#include "mail-vfolder.h"
#include "mail-folder-cache.h"
#include "folder-browser.h"
#include "subscribe-dialog.h"
#include "e-messagebox.h"

/* FIXME: is there another way to do this? */
#include "Evolution.h"
#include "evolution-storage.h"

#include "evolution-shell-client.h"

#ifndef HAVE_MKSTEMP
#include <fcntl.h>
#include <sys/stat.h>
#endif

struct post_send_data {
    CamelFolder *folder;
    gchar *uid;
    guint32 flags;
};

static void
druid_destroyed (void)
{
    gtk_main_quit ();
}

static gboolean
configure_mail (FolderBrowser *fb)
{
    MailConfigDruid *druid;
    
    if (fb) {
        GtkWidget *dialog;
        
        dialog = gnome_message_box_new (
            _("You have not configured the mail client.\n"
              "You need to do this before you can send,\n"
              "receive or compose mail.\n"
              "Would you like to configure it now?"),
            GNOME_MESSAGE_BOX_QUESTION,
            GNOME_STOCK_BUTTON_YES,
            GNOME_STOCK_BUTTON_NO, NULL);
        
        /*
         * Focus YES
         */
        gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
        gtk_widget_grab_focus (GTK_WIDGET (GNOME_DIALOG (dialog)->buttons->data));
        
        gnome_dialog_set_parent (GNOME_DIALOG (dialog),
                     GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb), GTK_TYPE_WINDOW)));
        
        switch (gnome_dialog_run_and_close (GNOME_DIALOG (dialog))) {
        case 0:
            druid = mail_config_druid_new (fb->shell);
            gtk_signal_connect (GTK_OBJECT (druid), "destroy",
                        GTK_SIGNAL_FUNC (druid_destroyed), NULL);
            gtk_widget_show (GTK_WIDGET (druid));
            gtk_grab_add (GTK_WIDGET (druid));
            gtk_main ();
            break;
        case 1:
        default:
            break;
        }
    }
    
    return mail_config_is_configured ();
}

static gboolean
check_send_configuration (FolderBrowser *fb)
{
    const MailConfigAccount *account;
    
    /* Check general */
    if (!mail_config_is_configured ()) {
        if (!configure_mail (fb))
            return FALSE;
    }
    
    /* Get the default account */
    account = mail_config_get_default_account ();
    
    /* Check for an identity */
    if (!account) {
        GtkWidget *message;
        
        message = gnome_warning_dialog_parented (_("You need to configure an identity\n"
                               "before you can compose mail."),
                             GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb),
                                                  GTK_TYPE_WINDOW)));
        gnome_dialog_run_and_close (GNOME_DIALOG (message));
        return FALSE;
    }
    
    /* Check for a transport */
    if (!account->transport || !account->transport->url) {
        GtkWidget *message;
        
        message = gnome_warning_dialog_parented (_("You need to configure a mail transport\n"
                               "before you can compose mail."),
                             GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (fb),
                                                  GTK_TYPE_WINDOW)));
        gnome_dialog_run_and_close (GNOME_DIALOG (message));
        return FALSE;
    }
    
    return TRUE;
}

#if 0
/* FIXME: is this still required when we send & receive email ?  I am not so sure ... */
static void
main_select_first_unread (CamelObject *object, gpointer event_data, gpointer data)
{
    FolderBrowser *fb = FOLDER_BROWSER (data);
    /*ETable *table = E_TABLE_SCROLLED (fb->message_list->etable)->table;*/
    
    message_list_select (fb->message_list, 0, MESSAGE_LIST_SELECT_NEXT,
                 0, CAMEL_MESSAGE_SEEN);
}

static void
select_first_unread (CamelObject *object, gpointer event_data, gpointer data)
{
    mail_op_forward_event (main_select_first_unread, object, event_data, data);
}
#endif

void
send_receive_mail (GtkWidget *widget, gpointer user_data)
{
    const MailConfigAccount *account;
    
    /* receive first then send, this is a temp fix for POP-before-SMTP */
    if (!mail_config_is_configured ()) {
        if (!configure_mail (FOLDER_BROWSER (user_data)))
            return;
    }
    
    account = mail_config_get_default_account ();
    if (!account || !account->transport) {
        GtkWidget *win = gtk_widget_get_ancestor (GTK_WIDGET (user_data), GTK_TYPE_WINDOW);
        gnome_error_dialog_parented (_("You have not set a mail transport method"), GTK_WINDOW (win));
        return;
    }
    
    mail_send_receive ();
}

static void
msgbox_destroyed (GtkWidget *widget, gpointer data)
{
    gboolean *show_again = data;
    GtkWidget *checkbox;
    
    checkbox = e_message_box_get_checkbox (E_MESSAGE_BOX (widget));
    *show_again = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
}

static gboolean
ask_confirm_for_empty_subject (EMsgComposer *composer)
{
    /* FIXME: EMessageBox should really handle this stuff
           automagically. What Miguel thinks would be nice is to pass
           in a message-id which could be used as a key in the config
           file and the value would be an int. -1 for always show or
           the button pressed otherwise. This probably means we'd have
           to write e_messagebox_run () */
    gboolean show_again = TRUE;
    GtkWidget *mbox;
    int button;
    
    if (!mail_config_get_prompt_empty_subject ())
        return TRUE;
    
    mbox = e_message_box_new (_("This message has no subject.\nReally send?"),
                  E_MESSAGE_BOX_QUESTION,
                  GNOME_STOCK_BUTTON_YES,
                  GNOME_STOCK_BUTTON_NO,
                  NULL);
    
    gtk_signal_connect (GTK_OBJECT (mbox), "destroy",
                msgbox_destroyed, &show_again);
    
    button = gnome_dialog_run_and_close (GNOME_DIALOG (mbox));
    
    mail_config_set_prompt_empty_subject (show_again);
    
    if (button == 0)
        return TRUE;
    else
        return FALSE;
}

static gboolean
ask_confirm_for_only_bcc (EMsgComposer *composer)
{
    /* FIXME: EMessageBox should really handle this stuff
           automagically. What Miguel thinks would be nice is to pass
           in a message-id which could be used as a key in the config
           file and the value would be an int. -1 for always show or
           the button pressed otherwise. This probably means we'd have
           to write e_messagebox_run () */
    gboolean show_again = TRUE;
    GtkWidget *mbox;
    int button;
    
    if (!mail_config_get_prompt_only_bcc ())
        return TRUE;
    
    mbox = e_message_box_new (_("This message contains only Bcc recipients.\nIt is "
                    "possible that the mail server may reveal the recipients "
                    "by adding an Apparently-To header.\nSend anyway?"),
                  E_MESSAGE_BOX_QUESTION,
                  GNOME_STOCK_BUTTON_YES,
                  GNOME_STOCK_BUTTON_NO,
                  NULL);
    
    gtk_signal_connect (GTK_OBJECT (mbox), "destroy",
                msgbox_destroyed, &show_again);
    
    button = gnome_dialog_run_and_close (GNOME_DIALOG (mbox));
    
    mail_config_set_prompt_only_bcc (show_again);
    
    if (button == 0)
        return TRUE;
    else
        return FALSE;
}

static void
free_psd (GtkWidget *composer, gpointer user_data)
{
    struct post_send_data *psd = user_data;
    
    if (psd->folder)
        camel_object_unref (CAMEL_OBJECT (psd->folder));
    if (psd->uid)
        g_free (psd->uid);
    g_free (psd);
}

struct _send_data {
    EMsgComposer *composer;
    struct post_send_data *psd;
};

static void
composer_sent_cb(char *uri, CamelMimeMessage *message, gboolean sent, void *data)
{
    struct _send_data *send = data;
    
    if (sent) {
        if (send->psd) {
            camel_folder_set_message_flags (send->psd->folder, send->psd->uid,
                            send->psd->flags, send->psd->flags);
        }
        gtk_widget_destroy (GTK_WIDGET (send->composer));
    } else {
        gtk_widget_show (GTK_WIDGET (send->composer));
        gtk_object_unref (GTK_OBJECT (send->composer));
    }
    
    g_free (send);
    camel_object_unref (CAMEL_OBJECT (message));
}

static CamelMimeMessage *
composer_get_message (EMsgComposer *composer)
{
    static char *recipient_type[] = {
        CAMEL_RECIPIENT_TYPE_TO,
        CAMEL_RECIPIENT_TYPE_CC,
        CAMEL_RECIPIENT_TYPE_BCC
    };
    const CamelInternetAddress *iaddr;
    const MailConfigAccount *account;
    CamelMimeMessage *message;
    const char *subject;
    int num_addrs, i;
    
    message = e_msg_composer_get_message (composer);
    if (message == NULL)
        return NULL;
    
    /* Check for recipients */
    for (num_addrs = 0, i = 0; i < 3; i++) {
        iaddr = camel_mime_message_get_recipients (message, recipient_type[i]);
        num_addrs += iaddr ? camel_address_length (CAMEL_ADDRESS (iaddr)) : 0;
    }
    
    /* I'm sensing a lack of love, er, I mean recipients. */
    if (num_addrs == 0) {
        GtkWidget *message_box;
        
        message_box = gnome_message_box_new (_("You must specify recipients in order to "
                               "send this message."),
                             GNOME_MESSAGE_BOX_WARNING,
                             GNOME_STOCK_BUTTON_OK,
                             NULL);
        
        gnome_dialog_run_and_close (GNOME_DIALOG (message_box));
        
        camel_object_unref (CAMEL_OBJECT (message));
        return NULL;
    }
    
    if (iaddr && num_addrs == camel_address_length (CAMEL_ADDRESS (iaddr))) {
        /* this means that the only recipients are Bcc's */
        if (!ask_confirm_for_only_bcc (composer)) {
            camel_object_unref (CAMEL_OBJECT (message));
            return NULL;
        }
    }

    /* Check for no subject */
    subject = camel_mime_message_get_subject (message);
    if (subject == NULL || subject[0] == '\0') {
        if (!ask_confirm_for_empty_subject (composer)) {
            camel_object_unref (CAMEL_OBJECT (message));
            return NULL;
        }
    }
    
    /* Add info about the sending account */
    account = e_msg_composer_get_preferred_account (composer);
    if (account) {
        camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Account", account->name);
        camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Transport", account->transport->url);
        camel_medium_set_header (CAMEL_MEDIUM (message), "X-Evolution-Fcc", account->sent_folder_uri);
    }
    
    return message;
}

void
composer_send_cb (EMsgComposer *composer, gpointer data)
{
    const MailConfigService *transport;
    CamelMimeMessage *message;
    struct post_send_data *psd = data;
    struct _send_data *send;
    
    if (!mail_config_is_configured ()) {
        GtkWidget *dialog;
        
        dialog = gnome_ok_dialog_parented (_("You must configure an account before you "
                             "can send this email."),
                           GTK_WINDOW (composer));
        gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
        return;
    }
    
    message = composer_get_message (composer);
    if (!message)
        return;

    transport = mail_config_get_default_transport ();
    if (!transport)
        return;

    send = g_malloc (sizeof (*send));
    send->psd = psd;
    send->composer = composer;
    gtk_object_ref (GTK_OBJECT (composer));
    gtk_widget_hide (GTK_WIDGET (composer));
    mail_send_mail (transport->url, message, composer_sent_cb, send);
}

static void
append_mail_cleanup (CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, int ok, void *data)
{
    camel_message_info_free (info);
}

void
composer_postpone_cb (EMsgComposer *composer, gpointer data)
{
    extern CamelFolder *outbox_folder;
    CamelMimeMessage *message;
    CamelMessageInfo *info;
    struct post_send_data *psd = data;
    
    message = composer_get_message (composer);
    if (message == NULL)
        return;
    info = camel_message_info_new ();
    info->flags = CAMEL_MESSAGE_SEEN;
    
    mail_append_mail (outbox_folder, message, info, append_mail_cleanup, NULL);
    camel_object_unref (CAMEL_OBJECT (message));
    
    if (psd)
        camel_folder_set_message_flags (psd->folder, psd->uid, psd->flags, psd->flags);
    
    gtk_widget_destroy (GTK_WIDGET (composer));
}

static GtkWidget *
create_msg_composer (const char *url)
{
    const MailConfigAccount *account;
    gboolean send_html;
    EMsgComposer *composer;
    
    account   = mail_config_get_default_account ();
    send_html = mail_config_get_send_html ();
    
    composer = url ? e_msg_composer_new_from_url (url) : e_msg_composer_new ();

    if (composer) {
        e_msg_composer_set_send_html (composer, send_html);
        e_msg_composer_show_sig_file (composer);
    }

    return GTK_WIDGET (composer);
}

void
compose_msg (GtkWidget *widget, gpointer user_data)
{
    GtkWidget *composer;

    if (!check_send_configuration (FOLDER_BROWSER (user_data)))
        return;
    
    composer = create_msg_composer (NULL);
    if (!composer)
        return;
    
    gtk_signal_connect (GTK_OBJECT (composer), "send",
                GTK_SIGNAL_FUNC (composer_send_cb), NULL);
    gtk_signal_connect (GTK_OBJECT (composer), "postpone",
                GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);

    gtk_widget_show (composer);
}

/* Send according to a mailto (RFC 2368) URL. */
void
send_to_url (const char *url)
{
    GtkWidget *composer;
    
    /* FIXME: no way to get folder browser? Not without
     * big pain in the ass, as far as I can tell */
    if (!check_send_configuration (NULL))
        return;
    
    composer = create_msg_composer (url);
    if (!composer)
        return;
    
    gtk_signal_connect (GTK_OBJECT (composer), "send",
                GTK_SIGNAL_FUNC (composer_send_cb), NULL);
    gtk_signal_connect (GTK_OBJECT (composer), "postpone",
                GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);

    gtk_widget_show (composer);
}   

static GList *
list_add_addresses (GList *list, const CamelInternetAddress *cia, const GSList *accounts,
            GHashTable *rcpt_hash, const MailConfigAccount **me,
            const char *ignore_addr)
{
    const char *name, *addr;
    const GSList *l;
    gboolean notme;
    char *full;
    int i;
    
    for (i = 0; camel_internet_address_get (cia, i, &name, &addr); i++) {
        /* Make sure we don't want to ignore this address */
        if (!ignore_addr || g_strcasecmp (ignore_addr, addr)) {
            /* now, we format this, as if for display, but does the composer
               then use it as a real address?  If so, very broken. */
            /* we should probably pass around CamelAddresse's if thats what
               we mean */
            full = camel_internet_address_format_address (name, addr);
            
            /* Here I'll check to see if the cc:'d address is the address
               of the sender, and if so, don't add it to the cc: list; this
               is to fix Bugzilla bug #455. */
            notme = TRUE;
            l = accounts;
            while (l) {
                const MailConfigAccount *acnt = l->data;
                
                if (!strcmp (acnt->id->address, addr)) {
                    notme = FALSE;
                    if (me && !*me)
                        *me = acnt;
                    break;
                }
                
                l = l->next;
            }
            
            if (notme && !g_hash_table_lookup (rcpt_hash, addr)) {
                g_hash_table_insert (rcpt_hash, (char *) addr, GINT_TO_POINTER (1));
                list = g_list_append (list, full);
            } else
                g_free (full);
        }
    }
    
    return list;
}

static const MailConfigAccount *
guess_me (const CamelInternetAddress *to, const CamelInternetAddress *cc, const GSList *accounts)
{
    const char *name, *addr;
    const GSList *l;
    gboolean notme;
    char *full;
    int i;
    
    if (to) {
        for (i = 0; camel_internet_address_get (to, i, &name, &addr); i++) {
            full = camel_internet_address_format_address (name, addr);
            l = accounts;
            while (l) {
                const MailConfigAccount *acnt = l->data;
                
                if (!strcmp (acnt->id->address, addr)) {
                    notme = FALSE;
                    return acnt;
                }
                
                l = l->next;
            }
        }
    }
    
    if (cc) {
        for (i = 0; camel_internet_address_get (cc, i, &name, &addr); i++) {
            full = camel_internet_address_format_address (name, addr);
            l = accounts;
            while (l) {
                const MailConfigAccount *acnt = l->data;
                
                if (!strcmp (acnt->id->address, addr)) {
                    notme = FALSE;
                    return acnt;
                }
                
                l = l->next;
            }
        }
    }
    
    return NULL;
}

static void
free_recipients (GList *list)
{
    GList *l;
    
    for (l = list; l; l = l->next)
        g_free (l->data);
    g_list_free (list);
}

static EMsgComposer *
mail_generate_reply (CamelFolder *folder, CamelMimeMessage *message, const char *uid, int mode)
{
    const CamelInternetAddress *reply_to, *sender, *to_addrs, *cc_addrs;
    const char *name = NULL, *address = NULL, *source = NULL;
    const char *message_id, *references, *reply_addr = NULL;
    char *text, *subject, *date_str;
    const MailConfigAccount *me;
    const GSList *accounts = NULL;
    GList *to = NULL, *cc = NULL;
    EMsgComposer *composer;
    time_t date;
    int offset;
    
    source = camel_mime_message_get_source (message);
    me = mail_config_get_account_by_source_url (source);

    composer = e_msg_composer_new_with_sig_file ();
    if (!composer)
        return NULL;
    
    /* FIXME: should probably use a shorter date string */
    sender = camel_mime_message_get_from (message);
    camel_internet_address_get (sender, 0, &name, &address);
    date = camel_mime_message_get_date (message, &offset);
    date_str = header_format_date (date, offset);
    text = mail_tool_quote_message (message, _("On %s, %s wrote:"), date_str, name && *name ? name : address);
    g_free (date_str);
    
    if (text) {
        e_msg_composer_set_body_text (composer, text);
        g_free (text);
    }
    
    /* Set the recipients */
    accounts = mail_config_get_accounts ();
    
    if (mode == REPLY_LIST) {
        CamelMessageInfo *info;
        const char *mlist;
        int i, max, len;
        
        info = camel_folder_get_message_info (folder, uid);
        mlist = camel_message_info_mlist (info);
        
        if (mlist) {
            /* look through the recipients to find the *real* mailing list address */
            len = strlen (mlist);
            
            to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
            max = camel_address_length (CAMEL_ADDRESS (to_addrs));
            for (i = 0; i < max; i++) {
                camel_internet_address_get (to_addrs, i, NULL, &address);
                if (!g_strncasecmp (address, mlist, len))
                    break;
            }
            
            if (i == max) {
                cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
                max = camel_address_length (CAMEL_ADDRESS (cc_addrs));
                for (i = 0; i < max; i++) {
                    camel_internet_address_get (cc_addrs, i, NULL, &address);
                    if (!g_strncasecmp (address, mlist, len))
                        break;
                }
            }
            
            /* We only want to reply to the list address - if it even exists */
            to = address && i != max ? g_list_append (to, g_strdup (address)) : to;
        }
    } else {
        GHashTable *rcpt_hash;
        
        rcpt_hash = g_hash_table_new (g_str_hash, g_str_equal);
        
        reply_to = camel_mime_message_get_reply_to (message);
        if (!reply_to)
            reply_to = camel_mime_message_get_from (message);
        if (reply_to) {
            /* Get the Reply-To address so we can ignore references to it in the Cc: list */
            if (camel_internet_address_get (reply_to, 0, NULL, &reply_addr)) {
                g_hash_table_insert (rcpt_hash, (char *) reply_addr, GINT_TO_POINTER (1));
                to = g_list_append (to, camel_address_format (CAMEL_ADDRESS (reply_to)));
            }
        }
        
        to_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO);
        cc_addrs = camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_CC);
        
        if (mode == REPLY_ALL) {
            cc = list_add_addresses (cc, to_addrs, accounts, rcpt_hash, &me, NULL);
            cc = list_add_addresses (cc, cc_addrs, accounts, rcpt_hash, me ? NULL : &me, reply_addr);
        } else if (me == NULL) {
            me = guess_me (to_addrs, cc_addrs, accounts);
        }
        
        g_hash_table_destroy (rcpt_hash);
    }
    
    /* Set the subject of the new message. */
    subject = (char *)camel_mime_message_get_subject (message);
    if (!subject)
        subject = g_strdup ("");
    else {
        if (!g_strncasecmp (subject, "Re: ", 4))
            subject = g_strdup (subject);
        else
            subject = g_strdup_printf ("Re: %s", subject);
    }
    
    e_msg_composer_set_headers (composer, me ? me->name : NULL, to, cc, NULL, subject);
    free_recipients (to);
    free_recipients (cc);
    g_free (subject);
    
    /* Add In-Reply-To and References. */
    message_id = camel_medium_get_header (CAMEL_MEDIUM (message), "Message-Id");
    references = camel_medium_get_header (CAMEL_MEDIUM (message), "References");
    if (message_id) {
        char *reply_refs;
        
        e_msg_composer_add_header (composer, "In-Reply-To", message_id);
        
        if (references)
            reply_refs = g_strdup_printf ("%s %s", references, message_id);
        else
            reply_refs = g_strdup (message_id);
        
        e_msg_composer_add_header (composer, "References", reply_refs);
        g_free (reply_refs);
    } else if (references) {
        e_msg_composer_add_header (composer, "References", references);
    }
    
    return composer;
}

static void
requeue_mail_reply(CamelFolder *folder, char *uid, CamelMimeMessage *msg, void *data)
{
    int mode = GPOINTER_TO_INT(data);

    mail_reply(folder, msg, uid, mode);
}

void
mail_reply (CamelFolder *folder, CamelMimeMessage *msg, const char *uid, int mode)
{
    EMsgComposer *composer;
    struct post_send_data *psd;
    
    g_return_if_fail (folder != NULL);
    g_return_if_fail (uid != NULL);
    
    if (!msg) {
        mail_get_message (folder, uid, requeue_mail_reply,
                  GINT_TO_POINTER(mode), mail_thread_new);
        return;
    }

    psd = g_new (struct post_send_data, 1);
    psd->folder = folder;
    camel_object_ref (CAMEL_OBJECT (psd->folder));
    psd->uid = g_strdup (uid);
    psd->flags = CAMEL_MESSAGE_ANSWERED;
    
    composer = mail_generate_reply (folder, msg, uid, mode);
    if (!composer)
        return;
    
    gtk_signal_connect (GTK_OBJECT (composer), "send",
                GTK_SIGNAL_FUNC (composer_send_cb), psd);
    gtk_signal_connect (GTK_OBJECT (composer), "postpone",
                GTK_SIGNAL_FUNC (composer_postpone_cb), psd);
    gtk_signal_connect (GTK_OBJECT (composer), "destroy",
                GTK_SIGNAL_FUNC (free_psd), psd);
    
    gtk_widget_show (GTK_WIDGET (composer));    
    e_msg_composer_unset_changed (composer);
}

void
reply_to_sender (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (!check_send_configuration (fb))
        return;
    
    mail_reply (fb->folder, fb->mail_display->current_message, 
            fb->message_list->cursor_uid, REPLY_SENDER);
}

void
reply_to_list (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (!check_send_configuration (fb))
        return;
    
    mail_reply (fb->folder, fb->mail_display->current_message, 
            fb->message_list->cursor_uid, REPLY_LIST);
}

void
reply_to_all (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (!check_send_configuration (fb))
        return;
    
    mail_reply (fb->folder, fb->mail_display->current_message, 
            fb->message_list->cursor_uid, REPLY_ALL);
}

void
enumerate_msg (MessageList *ml, const char *uid, gpointer data)
{
    g_ptr_array_add ((GPtrArray *) data, g_strdup (uid));
}


static EMsgComposer *
forward_get_composer (const char *subject)
{
    const MailConfigAccount *account;
    EMsgComposer *composer;
    
    account  = mail_config_get_default_account ();
    composer = e_msg_composer_new_with_sig_file ();
    if (composer) {
        gtk_signal_connect (GTK_OBJECT (composer), "send",
                    GTK_SIGNAL_FUNC (composer_send_cb), NULL);
        gtk_signal_connect (GTK_OBJECT (composer), "postpone",
                    GTK_SIGNAL_FUNC (composer_postpone_cb), NULL);
        e_msg_composer_set_headers (composer, account->name, NULL, NULL, NULL, subject);
    } else {
        g_warning("Could not create composer");
    }
    
    return composer;
}

static void
do_forward_non_attached (CamelFolder *folder, char *uid, CamelMimeMessage *message, void *data)
{
    char *subject;
    char *text;
    
    if (!message)
        return;

    subject = mail_tool_generate_forward_subject (message);
    if (GPOINTER_TO_INT (data) == MAIL_CONFIG_FORWARD_INLINE)
        text = mail_tool_forward_message (message);
    else
        text = mail_tool_quote_message (message, _("Forwarded message:\n"));

    if (text) {
        EMsgComposer *composer = forward_get_composer (subject);
        if (composer) {
            e_msg_composer_set_body_text (composer, text);
            gtk_widget_show (GTK_WIDGET (composer));
            e_msg_composer_unset_changed (composer);
        }
        g_free (text);
    }

    g_free (subject);
}

static void
forward_message (FolderBrowser *fb, MailConfigForwardStyle style)
{
    if (!fb->message_list->cursor_uid)
        return;
    if (!check_send_configuration (fb))
        return;

    mail_get_message (fb->folder, fb->message_list->cursor_uid,
              do_forward_non_attached, GINT_TO_POINTER (style),
              mail_thread_new);
}

void
forward_inline (GtkWidget *widget, gpointer user_data)
{
    forward_message (user_data, MAIL_CONFIG_FORWARD_INLINE);
}

void
forward_quoted (GtkWidget *widget, gpointer user_data)
{
    forward_message (user_data, MAIL_CONFIG_FORWARD_QUOTED);
}

static void
do_forward_attach (CamelFolder *folder, GPtrArray *messages, CamelMimePart *part, char *subject, void *data)
{
    if (part) {
        EMsgComposer *composer = forward_get_composer (subject);
        if (composer) {
            e_msg_composer_attach (composer, part);
            gtk_widget_show (GTK_WIDGET (composer));
            e_msg_composer_unset_changed (composer);
        }
    }
}

void
forward_attached (GtkWidget *widget, gpointer user_data)
{
    GPtrArray *uids;
    FolderBrowser *fb = (FolderBrowser *)user_data;
    
    if (!check_send_configuration (fb))
        return;
    
    uids = g_ptr_array_new ();
    message_list_foreach (fb->message_list, enumerate_msg, uids);
    mail_build_attachment (fb->message_list->folder, uids, do_forward_attach, NULL);
}

void
forward (GtkWidget *widget, gpointer user_data)
{
    MailConfigForwardStyle style = mail_config_get_default_forward_style ();

    if (style == MAIL_CONFIG_FORWARD_ATTACHED)
        forward_attached (widget, user_data);
    else
        forward_message (user_data, style);
}

static void
transfer_msg (GtkWidget *widget, gpointer user_data, gboolean delete_from_source)
{
    FolderBrowser *fb = user_data;
    MessageList *ml = fb->message_list;
    GPtrArray *uids;
    char *uri, *physical, *path;
    char *desc;
    const char *allowed_types[] = { "mail", "vtrash", NULL };
    extern EvolutionShellClient *global_shell_client;
    static char *last = NULL;
    
    if (last == NULL)
        last = g_strdup ("");
    
    if (delete_from_source)
        desc = _("Move message(s) to");
    else
        desc = _("Copy message(s) to");
    
    evolution_shell_client_user_select_folder  (global_shell_client, desc, last,
                            allowed_types, &uri, &physical);
    if (!uri)
        return;
    
    path = strchr (uri, '/');
    if (path && strcmp (last, path) != 0) {
        g_free (last);
        last = g_strdup (path);
    }
    g_free (uri);
    
    uids = g_ptr_array_new ();
    message_list_foreach (ml, enumerate_msg, uids);
    mail_transfer_messages (ml->folder, uids, delete_from_source,
                physical, NULL, NULL);
}

void
move_msg (GtkWidget *widget, gpointer user_data)
{
    transfer_msg (widget, user_data, TRUE);
}

void
copy_msg (GtkWidget *widget, gpointer user_data)
{
    transfer_msg (widget, user_data, FALSE);
}

/* Copied from e-shell-view.c */
static GtkWidget *
find_socket (GtkContainer *container)
{
        GList *children, *tmp;

        children = gtk_container_children (container);
        while (children) {
                if (BONOBO_IS_SOCKET (children->data))
                        return children->data;
                else if (GTK_IS_CONTAINER (children->data)) {
                        GtkWidget *socket = find_socket (children->data);
                        if (socket)
                                return socket;
                }
                tmp = children->next;
                g_list_free_1 (children);
                children = tmp;
        }
        return NULL;
}

void
addrbook_sender (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    CamelMimeMessage *msg = NULL;
    const CamelInternetAddress *addr;
    gchar *addr_str;
    GtkWidget *win;
    GtkWidget *control;
    GtkWidget *socket;

    if (fb && fb->mail_display)
        msg = fb->mail_display->current_message;

    if (msg == NULL)
        return;

    addr = camel_mime_message_get_from (msg);
    if (addr == NULL)
        return;

    addr_str = camel_address_format (CAMEL_ADDRESS (addr));

    win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (win), _("Sender"));

    control = bonobo_widget_new_control ("OAFIID:GNOME_Evolution_Addressbook_AddressPopup",
                         CORBA_OBJECT_NIL);
    bonobo_widget_set_property (BONOBO_WIDGET (control),
                    "email", addr_str,
                    NULL);

    socket = find_socket (GTK_CONTAINER (control));
    gtk_signal_connect_object (GTK_OBJECT (socket),
                   "destroy",
                   GTK_SIGNAL_FUNC (gtk_widget_destroy),
                   GTK_OBJECT (win));

    gtk_container_add (GTK_CONTAINER (win), control);
    gtk_widget_show_all (win);
}

void
apply_filters (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
        MessageList *ml = fb->message_list;
    GPtrArray *uids;
    
    uids = g_ptr_array_new ();
    message_list_foreach (ml, enumerate_msg, uids);

    mail_filter_on_demand(fb->folder, uids);
}

void
select_all (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
        MessageList *ml = fb->message_list;
    ESelectionModel *etsm = e_tree_get_selection_model (ml->tree);

    if (ml->folder == NULL)
        return;

    e_selection_model_select_all (etsm);
}

/* Thread selection */

typedef struct thread_select_info {
    MessageList *ml;
    GPtrArray *paths;
} thread_select_info_t;

static gboolean
select_node (ETreeModel *tm, ETreePath path, gpointer user_data)
{
    thread_select_info_t *tsi = (thread_select_info_t *) user_data;

    g_ptr_array_add (tsi->paths, path);
    return FALSE; /*not done yet*/
}

static void
thread_select_foreach (ETreePath path, gpointer user_data)
{
    thread_select_info_t *tsi = (thread_select_info_t *) user_data;
    ETreeModel *tm = tsi->ml->model;
    ETreePath node;

    /* @path part of the initial selection. If it has children,
     * we select them as well. If it doesn't, we select its siblings and
     * their children (ie, the current node must be inside the thread
     * that the user wants to mark.
     */

    if (e_tree_model_node_get_first_child (tm, path)) 
        node = path;
    else {
        node = e_tree_model_node_get_parent (tm, path);

        /* Let's make an exception: if no parent, then we're about
         * to mark the whole tree. No. */
        if (e_tree_model_node_is_root (tm, node)) 
            node = path;
    }

    e_tree_model_node_traverse (tm, node, select_node, tsi);
}

void
select_thread (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
        MessageList *ml = fb->message_list;
    ETreeSelectionModel *selection_model;
    thread_select_info_t tsi;
    int i;

    if (ml->folder == NULL)
        return;

    /* For every selected item, select the thread containing it.
     * We can't alter the selection while iterating through it,
     * so build up a list of paths.
     */

    tsi.ml = ml;
    tsi.paths = g_ptr_array_new ();

    e_tree_selected_path_foreach (ml->tree, thread_select_foreach, &tsi);

    selection_model = E_TREE_SELECTION_MODEL (e_tree_get_selection_model (ml->tree));

    for (i = 0; i < tsi.paths->len; i++)
        e_tree_selection_model_add_to_selection (selection_model,
                             tsi.paths->pdata[i]);
    g_ptr_array_free (tsi.paths, TRUE);
}

void
invert_selection (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
        MessageList *ml = fb->message_list;
    ESelectionModel *etsm = e_tree_get_selection_model (ml->tree);

    if (ml->folder == NULL)
        return;

    e_selection_model_invert_selection (etsm);
}

/* flag all selected messages. Return number flagged */
static int
flag_messages(FolderBrowser *fb, guint32 mask, guint32 set)
{
        MessageList *ml = fb->message_list;
    GPtrArray *uids;
    int i;
    
    if (ml->folder == NULL)
        return 0;
    
    /* could just use specific callback but i'm lazy */
    uids = g_ptr_array_new ();
    message_list_foreach (ml, enumerate_msg, uids);
    camel_folder_freeze (ml->folder);
    for (i = 0; i < uids->len; i++) {
        camel_folder_set_message_flags (ml->folder, uids->pdata[i], mask, set);
        g_free (uids->pdata[i]);
    }
    camel_folder_thaw (ml->folder);
    
    g_ptr_array_free (uids, TRUE);

    return i;
}

static int
toggle_flags (FolderBrowser *fb, guint32 mask)
{
        MessageList *ml = fb->message_list;
    GPtrArray *uids;
    int i;
    
    if (ml->folder == NULL)
        return 0;
    
    /* could just use specific callback but i'm lazy */
    uids = g_ptr_array_new ();
    message_list_foreach (ml, enumerate_msg, uids);
    camel_folder_freeze (ml->folder);
    for (i = 0; i < uids->len; i++) {
        gint flags;

        flags = camel_folder_get_message_flags (ml->folder, uids->pdata[i]);

        if (flags & mask)
            camel_folder_set_message_flags (ml->folder, uids->pdata[i], mask, 0);
        else {
            if ((mask & CAMEL_MESSAGE_FLAGGED) && (flags & CAMEL_MESSAGE_DELETED))
                camel_folder_set_message_flags (ml->folder, uids->pdata[i], CAMEL_MESSAGE_DELETED, 0);
            camel_folder_set_message_flags (ml->folder, uids->pdata[i], mask, mask);
        }
        
        g_free (uids->pdata[i]);
    }
    camel_folder_thaw (ml->folder);
    
    g_ptr_array_free (uids, TRUE);

    return i;
}

void
mark_as_seen (BonoboUIComponent *uih, void *user_data, const char *path)
{
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
}

void
mark_as_unseen (BonoboUIComponent *uih, void *user_data, const char *path)
{
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_SEEN, 0);
}

void
mark_all_as_seen (BonoboUIComponent *uih, void *user_data, const char *path)
{
    select_all (uih, user_data, path);
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
}

void
mark_as_important (BonoboUIComponent *uih, void *user_data, const char *path)
{
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0);
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED);
}

void
toggle_as_important (BonoboUIComponent *uih, void *user_data, const char *path)
{
    toggle_flags (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_FLAGGED);
}

static void
do_edit_messages(CamelFolder *folder, GPtrArray *uids, GPtrArray *messages, void *data)
{
    /*FolderBrowser *fb = data;*/
    int i;
    
    for (i = 0; i < messages->len; i++) {
        EMsgComposer *composer;

        composer = e_msg_composer_new_with_message (messages->pdata[i]);

        if (composer) {
            gtk_signal_connect (GTK_OBJECT (composer), "send",
                        composer_send_cb, NULL);
            gtk_signal_connect (GTK_OBJECT (composer), "postpone",
                        composer_postpone_cb, NULL);

            gtk_widget_show (GTK_WIDGET (composer));
        }
    }
}

static gboolean
are_you_sure (const char *msg, GPtrArray *uids, FolderBrowser *fb)
{
    GtkWidget *window = gtk_widget_get_ancestor (GTK_WIDGET (fb), GTK_TYPE_WINDOW);
    GtkWidget *dialog;
    char *buf;
    int button, i;

    buf = g_strdup_printf (msg, uids->len);
    dialog = gnome_ok_cancel_dialog_parented (buf, NULL, NULL, (GtkWindow *)window);
    button = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
    if (button != 0) {
        for (i = 0; i < uids->len; i++)
            g_free (uids->pdata[i]);
        g_ptr_array_free (uids, TRUE);
    }

    return button == 0;
}

static void
edit_msg_internal (FolderBrowser *fb)
{
    GPtrArray *uids;
    
    if (!check_send_configuration (fb))
        return;
    
    uids = g_ptr_array_new ();
    message_list_foreach (fb->message_list, enumerate_msg, uids);
    
    if (uids->len > 10 && !are_you_sure (_("Are you sure you want to edit all %d messages?"), uids, fb)) {
        int i;
        
        for (i = 0; i < uids->len; i++)
            g_free (uids->pdata[i]);
        
        g_ptr_array_free (uids, TRUE);
        
        return;
    }

    mail_get_messages (fb->folder, uids, do_edit_messages, fb);
}

void
edit_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (!folder_browser_is_drafts (fb)) {
        GtkWidget *message;
        
        message = gnome_warning_dialog (_("You may only edit messages saved\n"
                          "in the Drafts folder."));
        gnome_dialog_run_and_close (GNOME_DIALOG (message));
        return;
    }
    
    edit_msg_internal (fb);
}

static void
do_resend_messages (CamelFolder *folder, GPtrArray *uids, GPtrArray *messages, void *data)
{
    int i;
    
    for (i = 0; i < messages->len; i++) {
        /* generate a new Message-Id because they need to be unique */
        camel_mime_message_set_message_id (messages->pdata[i], NULL);
    }
    
    /* "Resend" should open up the composer to let the user edit the message */
    do_edit_messages (folder, uids, messages, data);
}



void
resend_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    GPtrArray *uids;
    
    if (!folder_browser_is_sent (fb)) {
        GtkWidget *message;
        
        message = gnome_warning_dialog (_("You may only resend messages\n"
                          "in the Sent folder."));
        gnome_dialog_run_and_close (GNOME_DIALOG (message));
        return;
    }
    
    if (!check_send_configuration (fb))
        return;
    
    uids = g_ptr_array_new ();
    message_list_foreach (fb->message_list, enumerate_msg, uids);
    
    if (uids->len > 10 && !are_you_sure (_("Are you sure you want to resend all %d messages?"), uids, fb)) {
        int i;
        
        for (i = 0; i < uids->len; i++)
            g_free (uids->pdata[i]);
        
        g_ptr_array_free (uids, TRUE);
        
        return;
    }
    
    mail_get_messages (fb->folder, uids, do_resend_messages, fb);
}

void
search_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    GtkWidget *w;

    if (fb->mail_display->current_message == NULL) {
        gtk_widget_show_all (gnome_warning_dialog (_("No Message Selected")));
        return;
    }

    w = mail_search_new (fb->mail_display);
    gtk_widget_show_all (w);
}

void
load_images (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);

    mail_display_load_images (fb->mail_display);
}

static void
save_msg_ok (GtkWidget *widget, gpointer user_data)
{
    CamelFolder *folder;
    GPtrArray *uids;
    char *path;
    int fd, ret = 0;
    
    /* FIXME: is path an allocated string? */
    path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (user_data));
    
        fd = open (path, O_RDONLY);
    if (fd != -1) {
        GtkWidget *dlg;
        GtkWidget *text;
        
        close (fd);
        
        dlg = gnome_dialog_new (_("Overwrite file?"),
                    GNOME_STOCK_BUTTON_YES, 
                    GNOME_STOCK_BUTTON_NO,
                    NULL);
        text = gtk_label_new (_("A file by that name already exists.\nOverwrite it?"));
        gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox), text, TRUE, TRUE, 4);
        gtk_window_set_policy (GTK_WINDOW (dlg), FALSE, TRUE, FALSE);
        gtk_widget_show (text);
        
        ret = gnome_dialog_run_and_close (GNOME_DIALOG (dlg));
    }
    
    if (ret == 0) {
        folder = gtk_object_get_data (GTK_OBJECT (user_data), "folder");
        uids = gtk_object_get_data (GTK_OBJECT (user_data), "uids");
        gtk_object_remove_no_notify (GTK_OBJECT (user_data), "uids");
        mail_save_messages (folder, uids, path, NULL, NULL);
        gtk_widget_destroy (GTK_WIDGET (user_data));
    }
}

static void
save_msg_destroy (gpointer user_data)
{
    GPtrArray *uids = user_data;
    
    if (uids) {
        int i;
        
        for (i = 0; i < uids->len; i++)
            g_free (uids->pdata[i]);
        
        g_ptr_array_free (uids, TRUE);
    }
}

void
save_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    GtkFileSelection *filesel;
    GPtrArray *uids;
    char *title, *path;
    
    uids = g_ptr_array_new ();
    message_list_foreach (fb->message_list, enumerate_msg, uids);
    
    if (uids->len == 1)
        title = _("Save Message As...");
    else
        title = _("Save Messages As...");
    
    filesel = GTK_FILE_SELECTION (gtk_file_selection_new (title));
    path = g_strdup_printf ("%s/", g_get_home_dir ());
    gtk_file_selection_set_filename (filesel, path);
    g_free (path);
    gtk_object_set_data_full (GTK_OBJECT (filesel), "uids", uids, save_msg_destroy);
    gtk_object_set_data (GTK_OBJECT (filesel), "folder", fb->folder);
    gtk_signal_connect (GTK_OBJECT (filesel->ok_button),
                "clicked", GTK_SIGNAL_FUNC (save_msg_ok), filesel);
    gtk_signal_connect_object (GTK_OBJECT (filesel->cancel_button),
                   "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
                   GTK_OBJECT (filesel));
    
    gtk_widget_show (GTK_WIDGET (filesel));
}

void
delete_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int deleted, row;

    deleted = flag_messages (fb, CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN,
                 CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN);

    /* Select the next message if we are only deleting one message */
    if (deleted == 1) {
        row = e_tree_row_of_node (fb->message_list->tree,
                      e_tree_get_cursor (fb->message_list->tree));
        message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT,
                     0, 0);
    }
}

void
undelete_msg (GtkWidget *button, gpointer user_data)
{
    flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0);
}

void
next_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_NEXT, 0, 0);
}

void
next_unread_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row,
                 MESSAGE_LIST_SELECT_NEXT,
                 0, CAMEL_MESSAGE_SEEN);
}

void
next_flagged_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row,
                 MESSAGE_LIST_SELECT_NEXT,
                 CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED);
}

void
previous_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row, MESSAGE_LIST_SELECT_PREVIOUS, 0, 0);
}

void
previous_unread_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row,
                 MESSAGE_LIST_SELECT_PREVIOUS,
                 0, CAMEL_MESSAGE_SEEN);
}

void
previous_flagged_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    int row;
    
    row = e_tree_row_of_node (fb->message_list->tree, e_tree_get_cursor (fb->message_list->tree));
    message_list_select (fb->message_list, row,
                 MESSAGE_LIST_SELECT_PREVIOUS,
                 CAMEL_MESSAGE_FLAGGED, CAMEL_MESSAGE_FLAGGED);
}

struct _expunged_folder_data {
    FolderBrowser *fb;
    gboolean hidedeleted;
};

static void
expunged_folder (CamelFolder *f, void *data)
{
    FolderBrowser *fb = ((struct _expunged_folder_data *) data)->fb;
    gboolean hidedeleted = ((struct _expunged_folder_data *) data)->hidedeleted;
    
    fb->expunging = NULL;
    message_list_set_hidedeleted (fb->message_list, hidedeleted);
    
    g_free (data);
}

void
expunge_folder (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (fb->folder && (fb->expunging == NULL || fb->folder != fb->expunging)) {
        struct _expunged_folder_data *data;
        CamelMessageInfo *info;
        
        data = g_malloc (sizeof (*data));
        data->fb = fb;
        data->hidedeleted = fb->message_list->hidedeleted;
        
        /* hide the deleted messages so user can't click on them while we expunge */
        message_list_set_hidedeleted (fb->message_list, TRUE);
        
        /* Only blank the mail display if the message being
                   viewed is one of those to be expunged */
        info = camel_folder_get_message_info (fb->folder, fb->loaded_uid);
        if (info->flags & CAMEL_MESSAGE_DELETED)
            mail_display_set_message (fb->mail_display, NULL);
        
        fb->expunging = fb->folder;
        mail_expunge_folder (fb->folder, expunged_folder, data);
    }
}

/********************** Begin Filter Editor ********************/

static GtkWidget *filter_editor = NULL;

static void
filter_editor_destroy (GtkWidget *dialog, gpointer user_data)
{
    filter_editor = NULL;
}

static void
filter_editor_clicked (GtkWidget *dialog, int button, FolderBrowser *fb)
{
    FilterContext *fc;
    
    if (button == 0) {
        char *user;
        
        fc = gtk_object_get_data (GTK_OBJECT (dialog), "context");
        user = g_strdup_printf ("%s/filters.xml", evolution_dir);
        rule_context_save ((RuleContext *)fc, user);
        g_free (user);
    }
    
    if (button != -1) {
        gnome_dialog_close (GNOME_DIALOG (dialog));
    }
}

static const char *filter_source_names[] = {
    "incoming",
    "outgoing",
    NULL,
};

void
filter_edit (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    FilterContext *fc;
    char *user, *system;
    
    if (filter_editor) {
        /* FIXME: raise the filter_editor dialog? */
        return;
    }
    
    fc = filter_context_new ();
    user = g_strdup_printf ("%s/filters.xml", evolution_dir);
    system = EVOLUTION_DATADIR "/evolution/filtertypes.xml";
    rule_context_load ((RuleContext *)fc, system, user);
    g_free (user);
    
    if (((RuleContext *)fc)->error) {
        GtkWidget *dialog;
        gchar *err;
        
        err = g_strdup_printf (_("Error loading filter information:\n%s"),
                       ((RuleContext *)fc)->error);
        dialog = gnome_warning_dialog (err);
        g_free (err);
        
        gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
        return;
    }
    
    filter_editor = (GtkWidget *)filter_editor_new (fc, filter_source_names);
    gtk_window_set_title (GTK_WINDOW (filter_editor), _("Filters"));
    
    gtk_object_set_data_full (GTK_OBJECT (filter_editor), "context", fc, (GtkDestroyNotify)gtk_object_unref);
    gtk_signal_connect (GTK_OBJECT (filter_editor), "clicked", filter_editor_clicked, fb);
    gtk_signal_connect (GTK_OBJECT (filter_editor), "destroy", filter_editor_destroy, NULL);
    gtk_widget_show (GTK_WIDGET (filter_editor));
}

/********************** End Filter Editor ********************/

void
vfolder_edit_vfolders (BonoboUIComponent *uih, void *user_data, const char *path)
{
    vfolder_edit ();
}

void
providers_config (BonoboUIComponent *uih, void *user_data, const char *path)
{
    static MailAccountsDialog *dialog = NULL;
    
    if (!dialog) {
        dialog = mail_accounts_dialog_new ((FOLDER_BROWSER (user_data))->shell);
        gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
        dialog = NULL;
    } else {
        /* FIXME: raise the dialog? */
    }
}

/*
 * FIXME: This routine could be made generic, by having a closure
 * function plus data, and having the whole process be taken care
 * of for you
 */
static void
do_mail_print (MailDisplay *md, gboolean preview)
{
    GnomePrintContext *print_context;
    GnomePrintMaster *print_master;
    GnomePrintDialog *gpd;
    GnomePrinter *printer = NULL;
    int copies = 1;
    int collate = FALSE;

    if (!preview){

        gpd = GNOME_PRINT_DIALOG (
            gnome_print_dialog_new (_("Print Message"), GNOME_PRINT_DIALOG_COPIES));
        gnome_dialog_set_default (GNOME_DIALOG (gpd), GNOME_PRINT_PRINT);

        switch (gnome_dialog_run (GNOME_DIALOG (gpd))){
        case GNOME_PRINT_PRINT:
            break;
            
        case GNOME_PRINT_PREVIEW:
            preview = TRUE;
            break;

        case -1:
            return;

        default:
            gnome_dialog_close (GNOME_DIALOG (gpd));
            return;
        }

        gnome_print_dialog_get_copies (gpd, &copies, &collate);
        printer = gnome_print_dialog_get_printer (gpd);
        gnome_dialog_close (GNOME_DIALOG (gpd));
    }

    print_master = gnome_print_master_new ();

/*  FIXME: set paper size gnome_print_master_set_paper (print_master,  */

    if (printer)
        gnome_print_master_set_printer (print_master, printer);
    gnome_print_master_set_copies (print_master, copies, collate);
    print_context = gnome_print_master_get_context (print_master);
    gtk_html_print (md->html, print_context);
    gnome_print_master_close (print_master);

    if (preview){
        gboolean landscape = FALSE;
        GnomePrintMasterPreview *preview;
        
        preview = gnome_print_master_preview_new_with_orientation (
            print_master, _("Print Preview"), landscape);
        gtk_widget_show (GTK_WIDGET (preview));
    } else {
        int result = gnome_print_master_print (print_master);

        if (result == -1){
            e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
                  _("Printing of message failed"));
        }
    }
    gtk_object_unref (GTK_OBJECT (print_master));
}

void
mail_print_preview_msg (MailDisplay *md)
{
    do_mail_print (md, TRUE);
}

void
mail_print_msg (MailDisplay *md)
{
    do_mail_print (md, FALSE);
}

void
print_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = user_data;

    mail_print_msg (fb->mail_display);
}

void
print_preview_msg (GtkWidget *button, gpointer user_data)
{
    FolderBrowser *fb = user_data;

    mail_print_preview_msg (fb->mail_display);
}

/******************** Begin Subscription Dialog ***************************/

static GtkWidget *subscribe_dialog = NULL;

static void
subscribe_dialog_destroy (GtkWidget *widget, gpointer user_data)
{
    subscribe_dialog = NULL;
}

void
manage_subscriptions (BonoboUIComponent *uih, void *user_data, const char *path)
{
    if (!subscribe_dialog) {
        subscribe_dialog = subscribe_dialog_new ((FOLDER_BROWSER (user_data))->shell);
        gtk_signal_connect (GTK_OBJECT (subscribe_dialog), "destroy",
                    subscribe_dialog_destroy, NULL);
        
        gtk_widget_show (subscribe_dialog);
    } else {
        /* FIXME: raise the subscription dialog window... */
    }
}

/******************** End Subscription Dialog ***************************/

void
configure_folder (BonoboUIComponent *uih, void *user_data, const char *path)
{
    FolderBrowser *fb = FOLDER_BROWSER(user_data);

    mail_local_reconfigure_folder(fb);
}

static void
do_view_message (CamelFolder *folder, char *uid, CamelMimeMessage *message, void *data)
{
    FolderBrowser *fb = FOLDER_BROWSER (data);
    
    if (message && fb) {
        GtkWidget *mb;
        
        camel_folder_set_message_flags (folder, uid, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
        mb = message_browser_new (fb->shell, fb->uri, uid);
        gtk_widget_show (mb);
    }
}

void
view_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    GPtrArray *uids;
    int i;
    
    if (!fb->folder)
        return;
    
    uids = g_ptr_array_new ();
    message_list_foreach (fb->message_list, enumerate_msg, uids);

    if (uids->len > 10 && !are_you_sure (_("Are you sure you want to open all %d messages in separate windows?"), uids, fb))
        return;

    for (i = 0; i < uids->len; i++) {
        mail_get_message (fb->folder, uids->pdata [i], do_view_message, fb, mail_thread_queued);
        g_free (uids->pdata [i]);
    }
    g_ptr_array_free (uids, TRUE);
}

void
open_msg (GtkWidget *widget, gpointer user_data)
{
    FolderBrowser *fb = FOLDER_BROWSER (user_data);
    
    if (folder_browser_is_drafts (fb))
        edit_msg_internal (fb);
    else
        view_msg (NULL, user_data);
}

void
open_message (BonoboUIComponent *uih, void *user_data, const char *path)
{
    open_msg (NULL, user_data);
}

void
edit_message (BonoboUIComponent *uih, void *user_data, const char *path)
{
        edit_msg (NULL, user_data);
}

void
stop_threads (BonoboUIComponent *uih, void *user_data, const char *path)
{
    camel_operation_cancel (NULL);
}

static void
empty_trash_expunged_cb (CamelFolder *folder, void *data)
{
    camel_object_unref (CAMEL_OBJECT (folder));
}

void
empty_trash (BonoboUIComponent *uih, void *user_data, const char *path)
{
    MailConfigAccount *account;
    CamelProvider *provider;
    CamelFolder *vtrash;
    const GSList *accounts;
    CamelException *ex;
    
    ex = camel_exception_new ();
    
    /* expunge all remote stores */
    accounts = mail_config_get_accounts ();
    while (accounts) {
        account = accounts->data;
        
        /* make sure this is a valid source */
        if (account->source && account->source->url) {
            provider = camel_session_get_provider (session, account->source->url, NULL);            
            if (provider) {
                /* make sure this store is a remote store */
                if (provider->flags & CAMEL_PROVIDER_IS_STORAGE &&
                    provider->flags & CAMEL_PROVIDER_IS_REMOTE) {
                    char *url;
                    
                    url = g_strdup_printf ("vtrash:%s", account->source->url);
                    vtrash = mail_tool_uri_to_folder (url, NULL);
                    g_free (url);
                    
                    if (vtrash)
                        mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
                }
            }
        }
        accounts = accounts->next;
    }
    
    /* Now empty the local trash folder */
    vtrash = mail_tool_uri_to_folder ("vtrash:file:/", ex);
    if (vtrash)
        mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
    
    camel_exception_free (ex);
}

static void
create_folders (EvolutionStorage *storage, const char *prefix, CamelFolderInfo *fi)
{
    char *path;
    
    if (fi->url) {
        mail_folder_cache_set_update_estorage (fi->url, storage);
        mail_folder_cache_note_folderinfo (fi->url, fi);
    }

    path = g_strdup_printf ("%s/%s", prefix, fi->name);
    evolution_storage_new_folder (storage, path, fi->name,
                      "mail", fi->url ? fi->url : "",
                      fi->name, /* description */
                      fi->unread_message_count > 0);

    if (fi->child)
        create_folders (storage, path, fi->child);
    g_free (path);
    
    if (fi->sibling)
        create_folders (storage, prefix, fi->sibling);
}

void
folder_created (CamelStore *store, const char *prefix, CamelFolderInfo *fi)
{
    EvolutionStorage *storage;
    
    if ((storage = mail_lookup_storage (store))) {
        create_folders (storage, prefix, fi);
        gtk_object_unref (GTK_OBJECT (storage));
    }
}

void
mail_storage_create_folder (EvolutionStorage *storage, CamelStore *store, CamelFolderInfo *fi)
{
    gboolean unref = FALSE;
    
    if (!storage && store) {
        storage = mail_lookup_storage (store);
        unref = TRUE;
    }
    
    if (storage) {
        if (fi)
            create_folders (storage, "", fi);
        
        if (unref)
            gtk_object_unref (GTK_OBJECT (storage));
    }
}

static void
delete_folders (EvolutionStorage *storage, CamelFolderInfo *fi)
{
    char *path;
    
    if (fi->child)
        delete_folders (storage, fi->child);
    
    path = g_strdup_printf ("/%s", fi->full_name);
    evolution_storage_removed_folder (storage, path);
    g_free (path);
    
    if (fi->sibling)
        delete_folders (storage, fi->sibling);
}

void
folder_deleted (CamelStore *store, CamelFolderInfo *fi)
{
    EvolutionStorage *storage;
    
    if ((storage = mail_lookup_storage (store))) {
        if (fi)
            delete_folders (storage, fi);
        
        gtk_object_unref (GTK_OBJECT (storage));
    }
}