summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/1.0/tconfig.tcl
blob: 6274e8499bf612f5e06eacbba7fbd6f6bce11504 (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
# $Id: tconfig.tcl 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
# ========================================================================
# Copyright 2006 University of Washington
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# ========================================================================

#  tconfig.tcl
#
#  Purpose:  CGI script to configure features/variables

#  Input: 
set conf_vars {
  {newconf {} 0}
  {oncancel "Nothing set for oncancel"}
  {wv      "" general}
  {vlavar  "" ""}
}

#  Output:
#

# read config
source genvars.tcl

set confs {
  {general General g genconf}
  {msgl "Message List" ml mlconf}
  {msgv "Message View" mv mvconf}
  {composer Composer c compconf}
  {address "Address Books" ab abconf}
  {folder "Folders" f fldrconf}
  {rule  "Rules" r ruleconf}
}


set var_menu {
  {
    {}
    {
      {
	# * * * * Save Config * * * *
	#cgi_image_button save=[WPimg but_save] border=0 alt="Save Config"
	cgi_submit_button save=Save
      }
    }
  }
  {
    {}
    {
      {
	# * * * * Close * * * *
	#cgi_image_button cancel=[WPimg but_cancel] border=0 alt="Cancel"
	cgi_submit_button cancel=Cancel
      }
    }
  }
}

## read vars
foreach item $conf_vars {
  if {[catch {cgi_import [lindex $item 0].x}]} {
    if {[catch {eval WPImport $item} result]} {
      if {[llength $item] > 2} {
	set [lindex $item 0] [lindex $item 2]
      } else {
	error [list _action [lindex $item 1] $result]
      }
    }
  } else {
    set [lindex $item 0] 1
  }
}

set type $wv
WPCmd set conf_page $type
switch -- $type {
  msgl {
    set goodvars $msglist_vars
  }
  msgv {
    set goodvars $msgview_vars
  }
  address {
    set goodvars $address_vars
  }
  folder {
    set goodvars $folder_vars
  }
  composer {
    set goodvars $composer_vars
  }
  general {
    set goodvars $general_vars
  }
  rule {
    set goodvars $rule_vars
  }
}
set typeexp "General"

proc button_text {but butno fg bg text} {
  if {[string length $fg]} {
    set fg "color: #${fg};"
  }

  if {[string length $bg]} {
    set bg "background-color: #${bg}"
  }

  cgi_puts "<script><!-- "
  cgi_puts "document.write('<a href=\\\'#\\\' style=\\\"text-decoration: none;\\\" onClick=\"return setop(\\\'${but}\\\',$butno)\">');// -->"
  cgi_puts "</script>"

  cgi_put [cgi_span "style=$fg $bg" $text]

  cgi_puts "<script><!-- "
  cgi_puts "document.write('</a>');// -->"
  cgi_puts "</script>"
}

proc button_checked {def but} {
  if {[string compare $def $but]} {
    return ""
  } else {
    return checked
  }
}

foreach conf $confs {
  if {[string compare $type [lindex $conf 0]] == 0} {
    append ttitle [cgi_imglink "[lindex $conf 2]tab"]
    lappend conftitle [list [cgi_imglink "[lindex $conf 2]tab"] {} {}]
    set typeexp [lindex $conf 1]
    set _wp(helpname) [lindex $conf 3]
  } else {
    append ttitle "<input type=image name=\"[lindex $conf 2]tab\" src=\"[WPimg "tabs/[lindex $conf 2]dtab"]\" border=0 alt=\"[lindex $conf 1]\">";
  }
}

cgi_http_head {
  WPStdHttpHdrs
}

if {$newconf == 1} {
  WPCmd PEConfig newconf
}

cgi_html {
  cgi_head {
    WPStdHtmlHdr "Configuration"
    WPStyleSheets

    cgi_put  "<style type='text/css'>"
    cgi_put  ".vtext { font-size: 10pt; font-family: courier, 'new courier', monospace ; font-weight: medium ; padding-left: 6; border-left: 1px solid black}"
    cgi_put  ".instr { font-size: 10pt; font-weight: bold}"
    cgi_puts "</style>"

    cgi_javascript {
      cgi_put "function setop(b,i){"
      cgi_put " eval('document.varconfig.'+b+'\['+i+'\].checked = true');"
      cgi_put " return false;"
      cgi_put "}"
    }
  }

  cgi_body BGCOLOR="$_wp(bordercolor)" {
    set postjs ""

    cgi_form $_wp(appdir)/$_wp(ui1dir)/wp method=post name=varconfig enctype=multipart/form-data target=_top {
      cgi_text "oncancel=$oncancel" type=hidden notab
      cgi_text "cid=[WPCmd PEInfo key]" type=hidden notab
      cgi_text "page=conf_process" type=hidden notab

      cgi_table width="100%" cellpadding=0 cellspacing=0 {
	cgi_table_row {
	  cgi_table_data width=112 bgcolor=$_wp(menucolor) {
	    cgi_puts [cgi_img [WPimg dot2] width=1 height=1]
	  }
	  cgi_table_data align=right nowrap background="[WPimg [file join tabs tabbg]]" {
	    cgi_put $ttitle
	  }
	}
      }
      if {0} {
      cgi_division align=right  {
	cgi_put $ttitle
      }
      }
      cgi_table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%" {

	cgi_table_row {
	  #
	  # next comes the menu down the left side
	  #
	  eval {
	    cgi_table_data $_wp(menuargs) rowspan=4 {
	      WPTFCommandMenu var_menu {}
	    }
	  }

	  #
	  # In main body of screen goe confg list
	  #
	  cgi_table_data valign=top width="100%" class=dialog "style=\"padding-left: 6\"" {
	    cgi_h2 [cgi_bold "${typeexp} configuration settings:"]
	    switch -- $type {
	      msgl {
		cgi_text "wv=msgl" type=hidden notab
	      }
	      msgv {
		cgi_text "wv=msgv" type=hidden notab
	      }
	      address {
		cgi_text "wv=address" type=hidden notab
	      }
	      folder {
		cgi_text "wv=folder" type=hidden notab
	      }
	      composer {
		cgi_text "wv=composer" type=hidden notab
	      }
	      general {
		cgi_text "wv=general" type=hidden notab
	      }
	      rule {
		cgi_text "wv=rule" type=hidden notab
	      }
	    }
	    set setfeatures [WPCmd PEConfig featuresettings]
	    set icnt 0
	    cgi_table border=0 cellspacing=0 cellpadding=5 width=98% {
	      foreach tmpvar $goodvars {
		set vtypeinp [lindex $tmpvar 0]
		set varname [lindex $tmpvar 1]
		set vardesc [lindex $tmpvar 2]

		if {[catch {WPCmd PEConfig varget $varname}  section] == 0} {
		  set varvals [lindex $section 0]
		  set vartype [lindex $section 1]
		  set vtvals [lindex $section 2]
		  set v_is_default [lindex $section 3]
		  set v_is_fixed [lindex $section 4]
		} else {
		  # UNKNOWN VAR: configure disabled?
		  continue
		}

		switch -- $vtypeinp {
		  var {
		    cgi_table_row {

		      cgi_table_data align=right valign=top nowrap width=50% {
			if {[info exists varname]} {
			  # set script "help.tcl?vn=$varname"
			  # set js "cOpen('$script', 'help', 'scrollbars=yes', 600, 400); return false;"
			  # set js "return vh('$varname')"
			  # cgi_puts [WPurl null "" $varname "" onClick=$js]
			  # cgi_puts [WPurl null "" $vardesc "" onClick=$js]
			  # cgi_submit_button varhelp=$vardesc class=lnkbt
			  cgi_puts [cgi_font class=cfvn $vardesc]
			}
		      }
		      cgi_table_data valign=top {
			cgi_image_button "hlp.$varname=[WPimg cf_help]" alt="Help for $vardesc"
		      }
		      cgi_table_data align=left colspan=2 width=50% {
			switch -- $vartype {
			  listbox {
			    cgi_select $varname align=left {
			      foreach tmpvt $vtvals {
				set tmpvttxt [lindex $tmpvt 0]
				set tmpvtval $tmpvttxt
				if {[llength $tmpvt] > 1} {
				  set tmpvtval [lindex $tmpvt 1]
				}
				if {[string compare $tmpvtval [lindex $varvals 0]]} {
				  if {[llength $tmpvt] > 1} {
				    cgi_option "${tmpvttxt}" "value=${tmpvtval}"
				  } else {
				    cgi_option "${tmpvttxt}" "value=${tmpvttxt}"
				  }
				} else {
				  if {[llength $tmpvt] > 1} {
				    cgi_option "$tmpvttxt" "value=${tmpvtval}" selected
				  } else {
				    cgi_option "$tmpvttxt" selected
				  }
				}
			      }
			    }
			  }
			  textarea {
			    cgi_table border=0 cellpadding=0 cellspacing=0 {
			      set addfield 0
			      set tiwidth 30
			      foreach varval $varvals {
				if {[string length $varval] > [expr {[info exists maxwidth] ? $maxwidth : 0}]} {
				  set maxwidth [string length $varval]
				  incr maxwidth 5
				}
			      }
			      if {[info exists maxwidth]} {
				set tiwidth $maxwidth
			      }
			      if {$tiwidth < 20} {
				set tiwidth 20
			      } elseif {$tiwidth > 50} {
				set tiwidth 50
			      }
			      cgi_table_row {
				cgi_table_data colspan=4 {
				  cgi_image_button vla.$varname=[WPimg cf_add] alt="Add Value"
				}
			      }
			      if {[string compare $vlavar $varname] == 0} {
				set addfield 1
				cgi_table_row {
				  cgi_table_data {
				    cgi_text "varlistadd=$varname" type=hidden notab
				    cgi_text "$varname-add=" type=text size=$tiwidth
				  }
				  cgi_table_data colspan=3 {
				    cgi_puts [cgi_font class=cfntc "(The value entered here will be added.)"]
				  }
				}
			      }
			      set i 0
			      set vvsz [llength $varvals]
			      foreach varval $varvals {
				cgi_table_row {
				  cgi_table_data {
				    cgi_text vle.$varname.$i=$varval type=text size=$tiwidth
				  }
				  cgi_table_data {
				    cgi_image_button vld.$varname.$i=[WPimg cf_delete] alt="Delete Value"
				  }
				  cgi_table_data {
				    if {$i < [expr {$vvsz - 1}]} {
				      cgi_image_button vlsd.$varname.$i=[WPimg cf_shdown] alt="Shuffle Down"
				    } else {
				      cgi_puts [cgi_nbspace]
				    }
				  }
				  cgi_table_data width=50% {
				    if {$i || $addfield} {
				      cgi_image_button vlsu.$varname.$i=[WPimg cf_shup] alt="Shuffle Up"
				    } else {
				      cgi_puts [cgi_nbspace]
				    }
				  }
				}
				incr i
			      }
			      cgi_text "$varname-sz=$i" type=hidden notab
			    }
			  }
			  default {
			    set size [string length [lindex $varvals 0]]
			    if {$size == 0} {
			      set size 20
			    } else {
			      incr size 5
			    }
			    cgi_text "$varname=[lindex $varvals 0]" type=text size=$size tableindex=1
			  }
			}
		      }
		    }
		  }
		  feat {
		    cgi_table_row {
		      cgi_table_data align=right width=50% {
			if {[info exists varname]} {
			  # cgi_submit_button feathelp=$vardesc class=lnkbt
			  cgi_puts [cgi_font class=cfvn $vardesc]
			}
		      }
		      cgi_table_data {
			cgi_image_button "hlp.$varname=[WPimg cf_help]" alt="Help for $vardesc"
		      }
		      cgi_table_data align=left colspan=3 width=50% {
			if {[lsearch $setfeatures $varname] >= 0} {
			  cgi_checkbox $varname checked class=dialog
			} else {
			  cgi_checkbox $varname class=dialog
			}
		      }
		    }

		  }
		  special {
		    switch -- $varname {
		      wp-columns {
			cgi_table_row {
			  cgi_table_data align=right valign=top nowrap {
			    cgi_puts [cgi_font class=cfvn $vardesc]
			  }
			  cgi_table_data valign=top {
			    cgi_image_button "hlp.${varname}=[WPimg cf_help]" alt="Help for $vardesc"
			  }
			  cgi_table_data align=left colspan=2 {
			    set cols [WPCmd PEConfig columns]
			    cgi_select columns align=left {
			      for {set i 20} {$i <= 128} {incr i 4} {
				if {$i == $cols} {
				  cgi_option $i "value=$i" selected
				} else {
				  cgi_option $i "value=$i"
				}
			      }
			    }
			  }
			}
		      }
		      left-column-folders {
			cgi_table_row {
			  cgi_table_data align=right valign=top nowrap {
			    cgi_puts [cgi_font class=cfvn $vardesc]
			  }
			  cgi_table_data valign=top {
			    cgi_puts [cgi_nbspace]
			  }
			  cgi_table_data align=left colspan=2 {
			    if {[catch {WPSessionState left_column_folders} cols]} {
			      set cols $_wp(fldr_cache_def)
			    }

			    cgi_select fcachel align=left {
			      for {set i 0} {$i <= $_wp(fldr_cache_max)} {incr i} {
				if {$i == $cols} {
				  cgi_option $i "value=$i" selected
				} else {
				  cgi_option $i "value=$i"
				}
			      }
			    }
			  }
			}
		      }
		      signature {
			cgi_table_row {
			  cgi_table_data colspan=4 align=center {
			    cgi_puts "<fieldset>"
			    cgi_puts "<legend>Signature</legend>"

			    set rawsig [join [WPCmd PEConfig rawsig] "\n"]
			    cgi_textarea signature=$rawsig rows=8 cols=80 wrap=off

			    cgi_puts "</fieldset>"
			  }
			}

		      }
		      filters -
		      scores -
		      indexcolor -
		      collections {
			set flt 0
			set cll 0
			switch $varname {
			  filters {
			    set flt 1
			    set descsing "Filter"
			    set filts [WPCmd PEConfig filters]
			    set lvals $filts
			    set varhelp 1
			  }
			  scores {
			    set flt 1
			    set descsing "Scores"
			    set filts [WPCmd PEConfig scores]
			    set lvals $filts
			    set varhelp 1
			  }
			  indexcolor {
			    set flt 1
			    set descsing "Index Colors"
			    set filts [WPCmd PEConfig indexcolors]
			    set lvals $filts
			    set varhelp 1
			  }
			  default {
			    set cll 1
			    set descsing "Collection"
			    set colls [WPCmd PEConfig collections]
			    set lvals $colls
			  }
			}
			set tasize [llength $lvals]
			cgi_table_row {
			  cgi_table_data align=center colspan=4 width=50% {
			    cgi_table border=0 cellpadding=3 cellspacing=0 width=100% {
			      cgi_table_row {
				cgi_table_data width=50%  {
				  cgi_puts [cgi_bold $vardesc]
				}
				if {[info exists varhelp]} {
				  cgi_table_data valign=top {
				    cgi_image_button "hlp.$varname=[WPimg cf_help]" alt="Help for $vardesc"
				  }
				}
				cgi_table_data "style=\"padding-left: 10px\"" {
				  cgi_image_button vla.$varname=[WPimg cf_add] alt="Add $descsing"
				}
			      }
			      set i 0
			      foreach lval $lvals {
				cgi_table_row {
				  cgi_table_data "style=\"padding-left: 8px\"" {
				    if {$flt} {
				      cgi_puts [cgi_font class=cfvn "[cgi_nbspace]$lval"]
				    } else {
				      cgi_puts "[cgi_font class=cfvn [lindex $lval 0]]<br>[cgi_span class=cfval "style=margin-left: 8px" [lindex $lval 1]]"
				    }
				  }

				  cgi_table_data "style=\"padding-left: 10px\"" valign=top width=30% {
				    cgi_unbreakable {
				      cgi_image_button vle.$varname.$i=[WPimg cf_edit] alt="Edit $descsing"

				      cgi_image_button vld.$varname.$i=[WPimg cf_delete] alt="Delete $descsing"

				      if {$i < [expr {$tasize - 1}]} {
					cgi_image_button vlsd.$varname.$i=[WPimg cf_shdown] alt="Shuffle Down"
				      } else {
					cgi_puts [cgi_img [WPimg dot2] width=18]
				      }

				      if {$i} {
					cgi_image_button vlsu.$varname.$i=[WPimg cf_shup] alt="Shuffle Up"
				      }
				    }
				  }
				}
				incr i
			      }
			      cgi_text "$varname-sz=$i" type=hidden notab
			    }
			  }
			}
		      }
		      index-format {
			cgi_table_row {
			  cgi_table_data align=left colspan=4 {
			    cgi_puts "<fieldset style=\"margin-left:1%; margin-right:1%\">"
			    #set helpbut [cgi_buffer {cgi_image_button "hlp.$varname=[WPimg cf_help]" alt="Help for $vardesc"}]
			    cgi_puts "<legend>Message Line Format</legend>"

			    set varval [WPCmd PEConfig varget $varname]
			    if {[llength [lindex $varval 0]]} {
			      set fmt ""
			      foreach fms [lindex [lindex $varval 0] 0] {
				if {[regexp {^([a-zA-Z]+[0-9]*)\(([0-9]+[%]?)\)$} $fms dummy f w]} {
				  lappend fmt [list $f $w]
				} elseif {[regexp {^([a-zA-Z]+[0-9]*)$} $fms dummy f]} {
				  lappend fmt [list $f ""]
				}
			      }
			    } else {
			      set fmt [WPCmd PEMailbox indexformat]
			    }

			    cgi_text "index-format=$fmt" type=hidden notab

			    cgi_table cellpadding=0 cellspacing=0 width=100% align=center "bgcolor=#999999" "style=\"border: 1px solid black \"" border=0 {
			      cgi_table_row "bgcolor=#999999" {
				if {[WPCmd PEInfo feature enable-aggregate-command-set]} {
				  cgi_td [cgi_img [WPimg dot2]]
				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				}

				foreach fme $fmt {
				  set f [lindex $fme 0]
				  set w [lindex $fme 1]
				  cgi_td xcolspan=3 [cgi_span "style=font-size: 10px; color: white;" $f]
				  if {[regexp {[0123456789]+[%]} $w]} {
				    cgi_td xcolspan=2 align=right [cgi_span "style=font-size: 10px; color: white; padding-right: 4" "(${w})"]
				  } else {
				    cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				  }

				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				}
			      }

			      cgi_table_row {
				if {[WPCmd PEInfo feature enable-aggregate-command-set]} {
				  cgi_table_data background="[WPimg bg_index]" align=center valign=middle "style=\"padding-left: 4; padding-right: 4\"" {
				    cgi_checkbox bogus
				  }

				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				}

				foreach fme $fmt {
				  set f [lindex $fme 0]
				  set w [lindex $fme 1]

				  switch -regexp $w {
				    [0123456789]+[%] {
				      set width width=$w
				    }
				    "" {
				      set r [WPTFIndexWidthRatio $fmt $f]
				      switch $r {
					1 { set width "" }
					default {
					  set width "width=[expr {round((100/[llength $fmt]) * $r)}]%"
					}
				      }
				    }
				  }

				  set align ""
				  set class ""
				  switch [string toupper [lindex $f 0]] {
				    TO {
				      set varval [WPCmd PEConfig varget personal-name]
				      if {[string length [lindex $varval 0]]} {
					set ftext "To: [lindex $varval 0]"
				      } else {
					set ftext "To: <sender@foo.bar.com>"
				      }
				    }
				    FROM -
				    FROMORTO {
				      set varval [WPCmd PEConfig varget personal-name]
				      if {[string length [lindex $varval 0]]} {
					set ftext [lindex $varval 0]
				      } else {
					set ftext "<sender@foo.bar.com>"
				      }
				    }
				    FULLSTATUS -
				    IMAPSTATUS -
				    STATUS {
				      set ftext "+N"
				      set align "align=center"
				    }
				    MSGNO {
				      set ftext [WPcomma [WPCmd PEMailbox messagecount]]
				      set align "align=center"
				    }
				    SIZE {
				      set ftext [cgi_span class=isize "(1234)"]
				      set class class=isize
				      set align "align=center"
				    }
				    KSIZE {
				      set ftext [cgi_span class=isize "(1K)"]
				      set class class=isize
				      set align "align=center"
				    }
				    SIZECOMMA {
				      set ftext [cgi_span class=isize "(1,234)"]
				      set class class=isize
				      set align "align=center"
				    }
				    DESCRIPSIZE {
				      set ftext "(short+)"
				      set align "align=center"
				    }
				    SIZENARROW {
					set ftext (1K)
				    }
				    DATE {
				      set ftext [clock format [clock seconds] -format "%b %d"]
				      set align "align=center"
				    }
				    DATEISO {
				      set ftext [clock format [clock seconds] -format "%Y-%m-%d"]
				      set align "align=center"
				    }
				    SHORTDATE1 {
				      set ftext [clock format [clock seconds] -format "%m/%d/%y"]
				      set align "align=center"
				    }
				    SHORTDATE2 {
				      set ftext [clock format [clock seconds] -format "%d/%m/%y"]
				      set align "align=center"
				    }
				    SHORTDATE3 {
				      set ftext [clock format [clock seconds] -format "%d.%m.%y"]
				      set align "align=center"
				    }
				    SHORTDATE4 {
				      set ftext [clock format [clock seconds] -format "%y.%m.%d"]
				      set align "align=center"
				    }
				    SHORTDATEISO {
				      set ftext [clock format [clock seconds] -format "%y-%m-%d"]
				      set align "align=center"
				    }
				    SMARTTIME -
				    SMARTDATETIME -
				    TIME12 {
				      regsub {^0*(.*)$} [string tolower [clock format [clock seconds] -format "%I:%M%p"]] {\1} ftext
				      set align "align=center"
				    }
				    TIME24 {
				      set ftext [clock format [clock seconds] -format "%H:%M"]
				      set align "align=center"
				    }
				    TIMEZONE {
				      set ftext [clock format [clock seconds] -format "%z"]
				      set align "align=center"
				    }
				    SUBJECT {
				      set ftext "Re: Config changes..."
				    }
				    ATT {
				      set ftext "1"
				    }
				    CC {
				      set ftext "user@domain"
				    }
				    FROMORTONOTNEWS {
				      set ftext "news.group"
				    }
				    LONGDATE {
				      set ftext [clock format [clock seconds] -format "%b %d, %Y"]
				      set align "align=center"
				    }
				    MONTHABBREV {
				      set ftext [clock format [clock seconds] -format "%b"]
				      set align "align=center"
				    }
				    NEWS {
					set ftext "news.group"
				    }
				    SENDER -
				    RECIPS -
				    NEWSANDTO -
				    RECIPSANDNEWS -
				    NEWSANDRECIPS {
					set ftext "user@domain"
				    }
				    SCORE {
					set ftext "50"
				    }
				    SMARTDATE {
					set ftext "Today"
				    }
				    TOANDNEWS {
					set ftext TOANDNEWS
				    }
				    default {
				      set ftext [lindex $f 0]
				    }
				  }
				  cgi_td $align $class $width nowrap height=34 colspan=2 "style=\"padding-right: 4; padding-left: 4\"" background="[WPimg bg_index]" $ftext
				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				}
			      }

			      cgi_table_row {
				if {[WPCmd PEInfo feature enable-aggregate-command-set]} {
				  cgi_table_data "bgcolor=#ffffff" {
				    cgi_put [cgi_img [WPimg dot2]]
				  }

				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]

				  set cols 2
				} else {
				  set cols 0
				}

				set fmturl "wp.tcl?page=conf_process&wv=msgl&adjust=Change&cid=[WPCmd PEInfo key]&oncancel=$oncancel&index-format=[WPPercentQuote $fmt]"
				foreach fme $fmt {
				  cgi_table_data colspan=2 nowrap "bgcolor=#ffffff" align=center valign=middle {
				    set cellurl "${fmturl}&ifield=[lindex $fme 0]"
				    cgi_puts [cgi_url [cgi_img [WPimg if_left] border=0 "alt=Move Field Left" height=11 width=11] "${cellurl}&iop=left" target=_top]
				    cgi_puts [cgi_url [cgi_img [WPimg if_wider] border=0 "alt=Widen Field" height=11 width=11] "${cellurl}&iop=widen" target=_top]
				    cgi_puts [cgi_url [cgi_img [WPimg if_remove] border=0 "alt=Remove Field" height=11 width=11] "${cellurl}&iop=remove" target=_top]
				    cgi_puts [cgi_url [cgi_img [WPimg if_narrow2] border=0 "alt=Narrow Field" height=11 width=11] "${cellurl}&iop=narrow" target=_top]
				    cgi_puts [cgi_url [cgi_img [WPimg if_right] border=0 "alt=Move Field Right" height=11 width=11] "${cellurl}&iop=right" target=_top]
				  }

				  cgi_td width=1 [cgi_img [WPimg dot2] width=1]
				}
			      }
			    }

			    if {[catch {WPCmd PEConfig indextokens} tokens] == 0} {
			      cgi_division align=center {style="margin-top: 16; margin-bottom: 10"} {
				cgi_submit_button "indexadd=Add Field"
				cgi_image_button "hlp.index_tokens=[WPimg cf_help]" alt="Help for $vardesc"
				cgi_select indexaddfield {
				  cgi_option {[  Choose Field to Insert  ]} "value="

				  foreach af [lsort -dictionary $tokens] {
				    if {[lsearch $fmt $af] < 0} {
				      if {[string compare $af MSGNO]} {
					cgi_option $af "value=$af"
				      } else {
					cgi_option $af "value=$af" selected
				      }
				    }
				  }
				}
			      }
			    }

			    cgi_puts "</fieldset>"
			  }
			}
		      }
		      view-colors {
			cgi_table_row {
			  cgi_table_data colspan=4 {
			    cgi_puts "<fieldset style=\"margin-left:1%; margin-right:1%\">"
			    #set helpbut [cgi_buffer {cgi_image_button "hlp.$varname=[WPimg cf_help]" alt="Help for $vardesc"}]
			    cgi_puts "<legend>Color Settings </legend>"

			    cgi_division class=instr "style=\"padding-bottom: 6\"" {
			      cgi_put [cgi_span "style=padding: 2; background-color: #ffcc66; border: 1px solid black" "1"]
			      cgi_put " Choose text below to color, or[cgi_nbspace]enter[cgi_nbspace]field[cgi_nbspace]"
			      cgi_text newfield= class=instr size=12 maxlength=32
			      cgi_put "[cgi_nbspace]to[cgi_nbspace]"
			      cgi_submit_button "addfield=add to colored headers"
			    }

			    set std_hdrs [list Date From To Cc Subject]
			    set samp_hdrs $std_hdrs
			    set samp_text [list normal quote1 quote2 quote3]
			    set colors {}

			    foreach goodkolor $samp_text {
			      set tcolor [WPCmd PEConfig colorget "${goodkolor}"]
			      lappend colors [list $goodkolor [lindex $tcolor 0] [lindex $tcolor 1]]
			    }

			    set hcolors [WPCmd PEConfig colorget "viewer-hdr-colors"]
			    set hi 0
			    foreach hcolor $hcolors {
			      set i 0
			      set dhdr 0
			      foreach samp_hdr $samp_hdrs {
				if {[string compare [string tolower [lindex $hcolor 0]] [string tolower [lindex $samp_hdr 0]]] == 0} {
				  if {[string length [lindex $hcolor 3]] == 0} {
				    switch -- $samp_hdr {
				      Date {
					set samptxt [clock format [clock seconds] -format "%a, %d %b %Y %H:%M:%S %Z"]
				      }
				      From {
					set samptxt [WPCmd PECompose from]
				      }
				      Subject {
					set samptxt "Your colors are Fabulous!"
				      }
				      default {
					set samptxt Sample
				      }
				    }
				    lappend samp_hdr [list [lindex $hcolor 1] [lindex $hcolor 2] $samptxt "" $hi]
				    set samp_hdrs [lreplace $samp_hdrs $i $i $samp_hdr]
				    set dhdr 1
				    break
				  } else {
				    lappend samp_hdr [list [lindex $hcolor 1] [lindex $hcolor 2] [lindex $hcolor 3] [lindex $hcolor 3] $hi]
				    set samp_hdrs [lreplace $samp_hdrs $i $i $samp_hdr]
				    set dhdr 1
				    break
				  }
				}
				incr i
			      }
			      if {$dhdr == 0} {
				set smptxt "Sample"
				if {[string compare "" [lindex $hcolor 3]]} {
				  set smptxt [lindex $hcolor 3]
				}
				lappend samp_hdrs [list [lindex $hcolor 0] [list [lindex $hcolor 1] [lindex $hcolor 2] $smptxt [lindex $hcolor 3] $hi]]
			      }
			      incr hi
			    }

			    set dfgc "ffffff"
			    set dbgc "000000"
			    set dq1fgc "ffffff"
			    set dq1bgc "000000"
			    set dq2fgc "ffffff"
			    set dq2bgc "000000"
			    set dq3fgc "ffffff"
			    set dq3bgc "000000"

			    foreach color $colors {
			      switch -- [lindex $color 0] {
				normal {
				  set dfgc [lindex $color 1]
				  set dbgc [lindex $color 2]
				}
				quote1 {
				  set dq1fgc [lindex $color 1]
				  set dq1bgc [lindex $color 2]
				}
				quote2 {
				  set dq2fgc [lindex $color 1]
				  set dq2bgc [lindex $color 2]
				}
				quote3 {
				  set dq3fgc [lindex $color 1]
				  set dq3bgc [lindex $color 2]
				}
			      }

			      set colarr([lindex $color 0]) [list [lindex $color 1] [lindex $color 2]]
			    }

			    foreach hcolor $hcolors {
			      set colarr([lindex $color 0]) [list [lindex $color 1] [lindex $color 2]]
			    }

			    set butno -1
			    if {[catch {WPCmd PEInfo set config_defground} defground] || ![string length $defground]} {
			      set defground f
			    }

			    if {[catch {WPCmd PEInfo set config_deftext} deftext] || ![string length $deftext]} {
			      set deftext normal
			    }

			    # paint example text
			    cgi_table cellpadding=0 cellspacing=0 width=100% align=center border=0 {
			      cgi_table_row {
				cgi_table_data align=center {

				  cgi_table border=0 cellpadding=0 cellspacing=0 width=100% align=center bgcolor=#${dbgc} "style=\"border-right: 1px solid black\"" {

				    cgi_table_row {
				      cgi_td class=dialog [cgi_img [WPimg dot2]]
				      cgi_td height=1 "bgcolor=#000000" [cgi_img [WPimg dot2] height=1]
				    }

				    foreach samp_hdr $samp_hdrs {
				      set field [string tolower [lindex $samp_hdr 0]]
				      incr butno
				      cgi_table_row {
					cgi_table_data class=dialog align=center nowrap {
					  cgi_radio_button text=hdr.${field} [button_checked $deftext ${field}]
					  if {[llength $samp_hdr] == 1} {
					    set hdrfg $dfgc
					    set hdrbg $dbgc
					  } else {
					    set cp [lindex $samp_hdr end]
					    set hdrfg [lindex $cp 0]
					    set hdrbg [lindex $cp 1]
					  }

					  cgi_text "dfg.${field}=$hdrfg" type=hidden notab
					  cgi_text "dbg.${field}=$hdrbg" type=hidden notab
					}

					cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc};\"" {
					  cgi_put "[lindex $samp_hdr 0]: "

					  if {[llength $samp_hdr] == 1} {
					    switch -- [lindex $samp_hdr 0] {
					      Date {
						set samptxt [clock format [clock seconds] -format "%a, %d %b %Y %H:%M:%S %Z"]
					      }
					      From {
						set samptxt [WPCmd PECompose from]
					      }
					      default {
						set samptxt Sample
					      }
					    }

					    button_text text $butno $dfgc $dbgc [cgi_quote_html $samptxt]
					    cgi_text "add.${field}=1" type=hidden notab
					  } else {
					    cgi_text "hi.${field}=[lindex [lindex $samp_hdr end] end]" type=hidden notab

					    set pref ""
					    foreach cp [lrange $samp_hdr 1 end] {
					      button_text text $butno $hdrfg $hdrbg [cgi_quote_html "${pref}[lindex $cp 2]"]
					      set pref ", "
					    }
					  }
					}
				      }
				    }

				    if {0} {
				    cgi_table_row {
				      cgi_td class=dialog [cgi_nbspace]
				      cgi_table_data {
					cgi_text newfield= class=vtext
					cgi_submit_button "addfield=Add New Header Field" class=vtext
				      }
				    }
				    }

				    cgi_table_row {
				      cgi_td class=dialog [cgi_nbspace]
				      cgi_td class=vtext [cgi_nbspace]
				    }

				    cgi_table_row {
				      cgi_table_data class=dialog align=center {
					incr butno
					cgi_radio_button text=normal [button_checked $deftext normal]
					cgi_text "dfg.normal=$dfgc" type=hidden notab
					cgi_text "dbg.normal=$dbgc" type=hidden notab
				      }

				      cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					button_text text $butno $dfgc $dbgc "This is a rather silly message."
				      }
				    }

				    cgi_table_row {
				      cgi_td class=dialog [cgi_nbspace]
				      cgi_td class=vtext [cgi_nbspace]
				    }

				    cgi_table_row {
				      cgi_td class=dialog [cgi_img [WPimg dot2]]
				      cgi_table_data colspan=2 class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					cgi_put "On Apr 1, 2001, Sample wrote:</a>"
				      }
				    }

				    cgi_table_row {
				      cgi_table_data class=dialog align=center {
					incr butno
					cgi_radio_button text=quote3 [button_checked $deftext quote3]
					cgi_text "dfg.quote3=[lindex $colarr(quote3) 0]" type=hidden notab
					cgi_text "dbg.quote3=[lindex $colarr(quote3) 1]" type=hidden notab
				      }

				      cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					cgi_put [cgi_span "style=color: #[lindex $colarr(quote1) 0]; background-color: #[lindex $colarr(quote1) 1]" "&gt; "]
					cgi_put [cgi_span "style=color: #[lindex $colarr(quote2) 0]; background-color: #[lindex $colarr(quote2) 1]" "&gt; "]
					button_text text $butno [lindex $colarr(quote3) 0] [lindex $colarr(quote3) 1] "&gt; This is an example of text that is quoted 3 times"
				      }
				    }

				    cgi_table_row {
				      cgi_table_data class=dialog align=center {
					incr butno
					cgi_radio_button text=quote2 [button_checked $deftext quote2]
					cgi_text "dfg.quote2=[lindex $colarr(quote2) 0]" type=hidden notab
					cgi_text "dbg.quote2=[lindex $colarr(quote2) 1]" type=hidden notab
				      }

				      cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					cgi_put [cgi_span "style=color: #[lindex $colarr(quote1) 0]; background-color: #[lindex $colarr(quote1) 1]" "&gt; "]
					button_text text $butno [lindex $colarr(quote2) 0] [lindex $colarr(quote2) 1] "&gt; This is an example of text that is quoted 2 times"
				      }
				    }

				    cgi_table_row {
				      cgi_table_data class=dialog align=center {
					incr butno
					cgi_radio_button text=quote1 [button_checked $deftext quote1]
					cgi_text "dfg.quote1=[lindex $colarr(quote1) 0]" type=hidden notab
					cgi_text "dbg.quote1=[lindex $colarr(quote1) 1]" type=hidden notab
				      }
				      cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					button_text text $butno [lindex $colarr(quote1) 0] [lindex $colarr(quote1) 1] "&gt; This is an example of text that is quoted 1 time"
				      }
				    }

				    if {[llength [WPCmd PEInfo signature]]} {
				      cgi_table_row "style=\"border-right: 1px solid black\"" {
					cgi_td class=dialog [cgi_img [WPimg dot2]]
					cgi_table_data class=vtext "style=\"color: #${dfgc}\; background-color: #${dbgc}\"" {
					  foreach i [WPCmd PEInfo signature] {
					    cgi_puts "$i[cgi_nl]"
					  }
					}
				      }
				    }

				    cgi_table_row {
				      cgi_td class=dialog [cgi_img [WPimg dot2]]
				      cgi_td height=1 "bgcolor=#000000" [cgi_img [WPimg dot2] height=1]
				    }
				  }
				}
			      }

			      cgi_table_row {
				cgi_table_data align=center "style=\"padding-top: 16\"" {
				  cgi_table width=100% border=0 {

				    cgi_table_row colspan=2 {
				      cgi_td valign=top align=left xrowspan=3 class=instr "style=\"padding-right: 4; background-color: #ffcc66; border: 1px solid black\"" [cgi_span "style=padding: 2;" "2"]
				      cgi_td width=30% colspan=2 valign=top class=instr "Choose fore- or background..."
				      cgi_td rowspan=3 width=3% [cgi_img [WPimg dot2]]
				      cgi_td valign=top align=left xrowspan=3 class=instr "style=\"padding-right: 4; background-color: #ffcc66; border: 1px solid black\"" [cgi_span "style=padding: 2;" "3"]
				      cgi_table_data valign=middle class=instr nowrap {
					cgi_put "Choose item's color below, or[cgi_nbspace]"
					cgi_submit_button "reset=restore its default colors"
				      }
				    }

				    cgi_table_row {
				      cgi_td rowspan=2 [cgi_img [WPimg dot2]]
				      cgi_table_data align=right {
					if {[string compare $defground f] == 0} {
					  set checked checked
					} else {
					  set checked ""
					}

					cgi_radio_button ground=f $checked
				      }

				      cgi_table_data "style=\"font-size: 10pt\"" {
					button_text ground 0 "" "" Foreground
				      }

				      cgi_td rowspan=2 [cgi_img [WPimg dot2]]
				      cgi_table_data rowspan=2 {
					cgi_image_button "colormap=[WPimg nondither10x10]" alt="Color Pattern" "style=\"border: 1px solid black\""
				      }
				    }

				    cgi_table_row {
				      cgi_table_data align=right {
					if {[string compare $defground b] == 0} {
					  set checked checked
					} else {
					  set checked ""
					}

					cgi_radio_button ground=b $checked
				      }

				      cgi_table_data "style=\"font-size: 10pt\"" {
					button_text ground 1 "" "" [cgi_span "style=color: black; background-color: #FFCC66; padding: 4" "Background"]
				      }
				    }
				  }
				}
			      }

			      cgi_table_row {
				cgi_table_data colspan=2 align=center class=instr nowrap "style=\"padding-top: 16; padding-bottom: 10;\"" {
				  cgi_puts "Alternatively, you can also "
				  cgi_submit_button "reset=Restore All Color Defaults"
				}
			      }

			      if {0} {
			      cgi_table_row {
				cgi_table_data class=instr nowrap "style=\"padding-top: 16; padding-bottom: 10;\"" {
				  cgi_put [cgi_span "style=padding: 2; background-color: #ffcc66; border: 1px solid black" "OR"]
				  cgi_put " Enter header name[cgi_nbspace]"
				  cgi_text newfield= class=vtext
				  cgi_put "[cgi_nbspace]to[cgi_nbspace]"
				  cgi_submit_button "addfield=Add to Those Being Colored"
				}
			      }
			      }
			    }

			    cgi_puts "</fieldset>"
			  }
			}
		      }
		    }
		  }
		}
		incr icnt
	      }
	    }
	  }
	}
      }
    }
  }
}