summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/1.0/folders.tcl
blob: a173b778d97c8db40e941a544c806bba60d6daf2 (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
# $Id: folders.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
#
# ========================================================================

#  folders.tcl
#
#  Purpose:  CGI script to generate html output associated with folder
#	     and collection management
#
#  Input:
set folder_vars {
  {uid		""	0}
  {cid		{}	""}
  {show		{}	""}
  {expand	{}	""}
  {contract	{}	""}
  {oncancel	""	main}
  {frestore	""	0}
  {delquery	{}	""}
  {dwnquery	{}	""}
  {delete	{}	""}
  {renquery	{}	""}
  {rename	{}	""}
  {newfolder	{}	""}
  {folder	{}	""}
  {newdir	{}	""}
  {directory	{}	""}
  {import	{}	""}
  {cancelled	{}	""}
  {fid		{}	""}
  {reload}
}

set indention 18

#  Output:
#
#	HTML/Javascript/CSS data representing the message specified
#	by the 'uid' argument

proc linecolor {linenum} {
  if {$linenum % 2} {
    return "#EEEEEE"
  } else {
    return "#FFFFFF"
  }
}

proc pretty_folder_name {collections folder} {
  set fcolid [lindex $folder 0]
  for {set i 0} {$i < [llength $collections]} {incr i} {
    set col [lindex $collections $i]
    if {$fcolid == [lindex $col 0]} {
      set coltext [lindex $col 1]
    }
  }    
  return "${coltext}:[join [lrange $folder 1 end] /]"
}

#
# Display the given folder list in a table (w/ mihodge mods)
#
proc blat_folder_list {colid flist shown path baseurl scroll anchorcntref depth} {
  global key border indention mbox _wp

  upvar $anchorcntref anchorcnt

  set rownum 0

  foreach folder $flist {
    set t [lindex $folder 0]
    set f [lindex $folder 1]
    set ff [linsert $path [llength $path] $f]
    set index -1

    set bgcolor [linecolor [incr anchorcnt]]

    # initial pad=12, expand/contract control is 9px wide
    set cellpad [expr {12 + ($depth * $indention)}]
    set delim [WPCmd PEFolder delimiter $colid]
    set fullpath [join [lrange $ff 1 end] $delim]

    if {[string first F $t] >= 0} {
      regsub -all {(')} [lrange $ff 1 end] {\\\\\1} ef
      set celldata [cgi_url $f open.tcl?colid=${colid}&folder=[WPPercentQuote $fullpath]&oncancel=folders&cid=$key target=_top]
    } else {
      set celldata $f
    }

    if {[string first D $t] >= 0} {

      if {[set index [lsearch $shown $ff]] < 0} {
	set control expand
      } else {
	set control contract
      }

      set celldata "[cgi_url [cgi_imglink $control] "${baseurl}${control}=[WPPercentQuote $ff]#f_[WPPercentQuote $ff]" name=f_[WPPercentQuote $ff] "style=\"padding-right:10px\""]$celldata"
      incr cellpad -19
    }

    cgi_table_row bgcolor=$bgcolor {

      cgi_table_data align=center {
	if {[string first F $t] >= 0 || ([WPCmd PEFolder isincoming $colid] == 0 && [string compare $mbox $fullpath])} {
	  cgi_radio_button "fid=f_[WPPercentQuote $ff]"
	}
      }

      cgi_table_data align=left "style=\"padding-left: ${cellpad}px\"" nowrap {
	cgi_put $celldata
      }

      cgi_table_data valign=top nowrap {
	if {[info exists control] && [string compare $control contract] == 0} {
	  cgi_submit_button "new_[WPPercentQuote $ff]=Create New..."
	  cgi_submit_button "imp_[WPPercentQuote $ff]=Import..."
	} else {
	  cgi_puts [cgi_nbspace]
	}
      }
    }

    if {[string first D $t] >= 0 && $index >= 0} {
      set nflist [eval WPCmd PEFolder list $ff]
      set newpath $path
      lappend newpath $f
      blat_folder_list $colid $nflist $shown $newpath $baseurl $scroll anchorcnt [expr {$depth + 1}]
    }

    catch {unset control}
  }
}


#
# Command Menu definition for Message View Screen
#
set folder_menu {
}

set common_menu {
  {
    {}
    {
      {
	# * * * * Ubiquitous INBOX link * * * *
	if {[string compare inbox [string tolower $mbox]]} {
	  cgi_put [cgi_url INBOX [cgi_root]/$_wp(appdir)/$_wp(ui1dir)/open.tcl?folder=INBOX&colid=0&cid=[WPCmd PEInfo key] target=_top class=navbar]
	} else {
	  cgi_put [cgi_url INBOX fr_main.tcl target=_top class=navbar]
	}
      }
    }
  }
  {
    {}
    {
      {
	# * * * * COMPOSE * * * *
	cgi_puts [cgi_url Compose wp.tcl?page=compose&oncancel=folders&cid=$key target=_top class=navbar]
      }
    }
  }
  {
    {}
    {
      {
	# * * * * RESUME * * * *
	#set button [cgi_img [WPimg but_resume] border=0 alt="Resume"]
	set button Resume
	cgi_puts [cgi_url $button wp.tcl?page=resume&oncancel=folders&cid=$key class=navbar]
      }
    }
  }
  {
    {}
    {
      {
	# * * * * Addr books * * * *
	#set button [cgi_img [WPimg but_abook] border=0 alt="Address Book"]
	set button "Address Book"
	cgi_puts [cgi_url $button wp.tcl?page=addrbook&oncancel=folders class=navbar]
      }
    }
  }
  {{cgi_puts [cgi_nbspace]}}
  {
    {}
    {
      {
	cgi_put [cgi_url "Configure" wp.tcl?page=conf_process&newconf=1&oncancel=folders&cid=[WPCmd PEInfo key] class=navbar target=_top]
      }
    }
  }
  {
    {}
    {
      {
	cgi_put [cgi_url "Get Help" wp.tcl?page=help&oncancel=folders class=navbar target=_top]
      }
    }
  }
  {{cgi_puts [cgi_nbspace]}}
  {
    {}
    {
      {
	# * * * * LOGOUT * * * *
	if {[WPCmd PEInfo feature quit-without-confirm]} {
	  cgi_puts [cgi_url "Quit $_wp(appname)" $_wp(serverpath)/session/logout.tcl?cid=[WPCmd PEInfo key]&sessid=$sessid target=_top class=navbar]
	} else {
	  cgi_puts [cgi_url "Quit $_wp(appname)" wp.tcl?page=quit&cid=[WPCmd PEInfo key] target=_top class=navbar]
	}
      }
    }
  }
}

## read vars
foreach item $folder_vars {
  if {[catch {cgi_import [lindex $item 0].x}]} {
    if {[catch {eval WPImport $item} errstr]} {
      error [list _action "Impart Variable" $errstr]
    }
  } else {
    set [lindex $item 0] 1
  }
}

if {[catch {WPCmd PEInfo key} key]} {
  error [list _action "command ID" $key]
}

# perform requested op
if {$delquery == 1 || [string compare $delquery Delete] == 0} {
  if {[string length $fid]} {
    set fid [string range $fid 2 end]
    source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_querydelfldr.tcl]
    set nopage 1
  } else {
    lappend newmail [list "Click button next to folder name then Click [cgi_italic Delete]"]
  }
} elseif {$delete == 1 || [string compare $delete Delete] == 0} {
  if {$cid != $key} {
    lappend newmail [list "Invalid Command ID"]
  } elseif {[string length $fid]} {
    if {[catch [concat WPCmd PEFolder delete $fid] result] == 0} {
      lappend newmail [list "'[lindex $fid end]' permanently removed"]
    }
  } else {
    lappend newmail [list "Click button next to folder name then Click [cgi_italic Delete]"]
  }
} elseif {[string compare $delete Cancel] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  lappend newmail [list "Folder Delete Cancelled"]
} elseif {[string compare $rename Cancel] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  lappend newmail [list "Folder Rename Cancelled"]
} elseif {$renquery == 1 || [string compare $renquery Rename] == 0} {
  if {$cid != $key} {
    lappend newmail [list "Invalid Command ID"]
  } elseif {[string length $fid]} {
    set fid [string range $fid 2 end]
    source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_queryrenfldr.tcl]
    set nopage 1
  } else {
    lappend newmail [list "Click button next to folder name then Click [cgi_italic Rename]"]
  }
} elseif {$dwnquery == 1 || [string compare $dwnquery Export] == 0} {
  if {$cid != $key} {
    lappend newmail [list "Invalid Command ID"]
  } elseif {[string length $fid] <= 0} {
    lappend newmail [list "Click button next to folder name then Click [cgi_italic Export]"]
  } elseif {[file isdirectory $_wp(detachpath)] <= 0} {
    lappend newmail [list "Server Configuration Problem: $_wp(detachpath) does not exist"]
  } else {
    source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) exporting.tcl]
    set nopage 1
  }
} elseif {[string compare $rename Rename] == 0} {
  if {[string length $folder]} {
    if {[catch [concat WPCmd PEFolder rename $fid [list $folder]] result]} {
    } else {
      lappend newmail [list "'[lindex $fid end]' renamed to '$folder'"]
    }
  } else {
    lappend newmail [list "Rename failed: no new name provided"]
  }
} elseif {[string compare [string range $newfolder 0 5] Create] == 0} {
  if {$cid != $key} {
    lappend newmail [list "Invalid Command ID"]
  } elseif {[string length $folder]} {
    set fpath [lrange $fid 1 end]
    lappend fpath $folder
    if {[catch {WPCmd PEFolder delimiter [lindex $fid 0]} result]
	|| [catch {WPCmd PEFolder create [lindex $fid 0] [join $fpath $result]} result]} {
      lappend newmail [list "Create failed: $result"]
    } else {
      lappend newmail [list "Folder $folder created"]
    }
  } else {
    lappend newmail [list "Folder creation failed: no folder name provided"]
  }
} elseif {[string compare $newfolder Cancel] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  lappend newmail [list "Folder Create Cancelled"]
} elseif {[string compare [string range $import 0 5] Import] == 0} {
  if {[catch {WPImport file "Missing File Upload"} errstr] == 0} {
    set local_file [lindex $file 0]

    if {[catch {WPImport iname "import name"} errstr] == 0} {
      set iname [string trim $iname]

      if {[string length $iname]} {

	set colid [lindex $fid 0]
	set fldr [eval "file join [lrange $fid 1 end] $iname"]

	if {[catch {WPCmd PEFolder import $local_file $colid $fldr} errstr] == 0} {
	  lappend newmail [list "Imported folder $iname"]
	} else {
	  lappend newmail [list "Can't Import File: $errstr"]
	}
      } else {
	lappend newmail [list "Must provide uploaded folder name"]
      }
    } else {
      lappend newmail [list "Can't get uploaded folder name"]
    }

    catch {file delete -force $local_file}
  } else {
    lappend newmail [list "Problem uploading file"]
  }
} elseif {[string compare [string range $newdir 0 5] Create] == 0} {
  if {$cid != $key} {
    lappend newmail [list "Invalid Command ID"]
  } elseif {[string length $directory]} {
    set fpath [lrange $fid 1 end]
    lappend fpath "${directory}/"
    if {[catch {WPCmd PEFolder delimiter [lindex $fid 0]} result]
	|| [catch {WPCmd PEFolder create [lindex $fid 0] [join $fpath $result]} result]} {
      lappend newmail [list "Create failed: $result"]
    } else {
      lappend newmail [list "Folder $directory created"]
    }
  } else {
    lappend newmail [list "Directory Create failed: no name provided"]
  }
} elseif {[string compare $newdir Cancel] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  lappend newmail [list "Directory Creation Cancelled"]
} elseif {[string compare $cancelled Cancel] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  lappend newmail [list "New Folder or Directory Creation Cancelled"]
} elseif {[catch {WPCmd PEInfo set wp_folder_script} script] == 0} {
  catch {WPCmd PEInfo unset wp_folder_script}
  set uid 0
  source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) $script]
  set nopage 1
} else {
  foreach i [cgi_import_list] {
    switch -regexp -- $i {
      ^new_[a-zA-Z0-9%_]*$ {
	set fid [string range $i 4 end]
	catch {WPCmd PEInfo set fid $fid}
	catch {WPCmd PEInfo set wp_folder_script fr_querynewdir.tcl}
	source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_querynewfoldir.tcl]
	set nopage 1
      }
      ^nd_[a-zA-Z0-9%_]*$ {
	set fid [string range $i 3 end]
	catch {WPCmd PEInfo set fid $fid}
	catch {WPCmd PEInfo set wp_folder_script fr_querynewdir.tcl}
	source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_querynewdir.tcl]
	set nopage 1
      }
      ^nf_[a-zA-Z0-9%_]*$ {
	set fid [string range $i 3 end]
	catch {WPCmd set fid $fid}
	catch {WPCmd set wp_folder_script fr_querynewfldr.tcl}
	source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_querynewfldr.tcl]
	set nopage 1
      }
      ^imp_[a-zA-Z0-9%_]*$ {
	set fid [string range $i 4 end]
	source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_queryimport.tcl]
	set nopage 1
      }
      default {
      }
    }

    catch {WPCmd PEInfo unset fid}
    catch {WPCmd PEInfo unset wp_folder_script}
  }
}

if {[info exists nopage] == 0} {
  if {$reload || $frestore || ([string length $show] == 0 && [string length $expand] == 0 && [string length $contract] == 0)} {
    catch {set show [WPCmd PEInfo set fr_show]
    set expand [WPCmd PEInfo set fr_expand]
    set contract [WPCmd PEInfo set fr_contract]}
  } else {
    WPCmd set fr_show $show
    WPCmd set fr_expand $expand
    WPCmd set fr_contract $contract
  }

  # collect top level folder lists
  if {[catch {WPCmd PEFolder collections} collections]} {
    error [list _action "Collection list" $collections]
  }

  set shown [split $show ,]
  set scroll {}
  set anchorcnt 0

  # mihodge: process actions
  if {[llength $expand]} {
    lappend shown $expand
    set scroll $expand
  }

  if {[llength $contract]} {
    if {[set index [lsearch $shown $contract]] >= 0} {
      set shown [lreplace $shown $index $index]
      set scroll $contract
    }
  }

  set baseurl wp.tcl?page=folders&

  if {[llength $shown]} {
    append baseurl "show=[WPPercentQuote [join $shown ,]]&"
  }

  # build top-level collection's folder list
  for {set i 0} {$i < [llength $collections]} {incr i} {
    set col [lindex $collections $i]
    set colid [lindex $col 0]

    if {[llength $collections] == 1} {
      set flist 1
    } else {
      if {[set index [lsearch $shown $colid]] < 0} {
	set flist {}
      } else {
	set flist 1
      }
    }

    if {[llength $flist]} {
      if {[catch {WPCmd PEFolder list $colid} flist]} {
	if {[string compare BADPASSWD [string range $flist 0 8]] == 0} {
	  # control error messages
	  set statmsgs [WPCmd PEInfo statmsgs]
	  WPCmd PEMailbox newmailreset
	  if {[catch {WPCmd PESession creds [lindex $expand 0] folder} creds] == 0 && $creds != 0} {
	    catch {WPCmd PEInfo statmsg "Invalid Username or Password"}
	    WPCmd PESession nocred $expand folder
	  }

	  if {[catch {WPCmd PEFolder clextended} coln]} {
	    WPCmd set reason "Can't get Collection Info: $coln"
	  } else {
	    set coln [lindex $coln $expand]
	    if {[regexp {^([a-zA-Z\.]+).*\/user=([^ /]*)} [lindex $coln 4] dummy srvname authuser]} {
	      WPCmd set reason "Listing folders in the [cgi_bold [lindex $coln 1]] collection first requires that you log in to the server [cgi_bold "$srvname"]."
	      WPCmd set authuser $authuser
	    } else {
	      WPCmd set reason "Folders in the [cgi_bold [lindex $coln 1]] collection are on a server that must be logged into."
	    }
	  }

	  WPCmd set cid [WPCmd PEInfo key]
	  WPCmd set authcol [lindex $expand 0]
	  WPCmd set authfolder folder
	  WPCmd set authpage [WPPercentQuote "[cgi_root]/$_wp(appdir)/$_wp(ui1dir)/wp.tcl?page=folders&expand=$expand"]
	  WPCmd set authcancel [WPPercentQuote "[cgi_root]/$_wp(appdir)/$_wp(ui1dir)/wp.tcl?page=folders"]

	  source [file join $_wp(cgipath) $_wp(appdir) $_wp(ui1dir) fr_queryauth.tcl]

	  catch {WPCmd unset fr_expand}

	  set nopage 1
	} else {
	  set flist {}
	}
      }
    }

    lappend collectionfolders $flist
  }
}

if {[info exists nopage] == 0} {
  # collect new mail message and errors
  if {[catch {WPNewMail $reload} newmailmsg]} {
    error [list _action "new mail" $newmailmsg]
  } else {
    foreach m $newmailmsg {
      lappend newmail $m
    }
    
    if {[info exists newmail] == 0} {
      set newmail ""
    }
  }

  # paint the page
  cgi_http_head {
    WPStdHttpHdrs text/html
  }

  cgi_html {
    cgi_head {
      WPStdHtmlHdr "Folder List" folders

      set onload "onLoad="
      set onunload "onUnload="
      set normalreload [cgi_buffer {WPHtmlHdrReload "$_wp(appdir)/$_wp(ui1dir)/wp.tcl?page=folders"}]

      if {[info exists _wp(exitonclose)]} {
	WPExitOnClose
	append onload "wpLoad();"
	append onunload "wpUnLoad();"

	cgi_script  type="text/javascript" language="JavaScript" {
	  cgi_put  "function viewReloadTimer(t){"
	  cgi_put  " reloadtimer = window.setInterval('wpLink(); window.location.replace(\\'[cgi_root]/$_wp(appdir)/$_wp(ui1dir)/wp.tcl?page=folders&reload=1\\')', t * 1000);"
	  cgi_puts "}"
	}

	append onload "viewReloadTimer($_wp(refresh));"
	cgi_noscript {
	  cgi_puts $normalreload
	}
      } else {
	cgi_puts $normalreload
      }

      WPStyleSheets
      if {$_wp(keybindings)} {
	set kequiv {
	  {{i} {top.location = 'fr_main.tcl'}}
	  {{a} {top.location = 'wp.tcl?page=addrbook'}}
	  {{?} {top.location = 'wp.tcl?page=help&oncancel=folders'}}
	}

	lappend kequiv [list {c} "top.location = 'wp.tcl?page=compose&oncancel=folders&cid=$key'"]

	append onload [WPTFKeyEquiv $kequiv]
      }
    }

    cgi_body bgcolor=$_wp(bordercolor) background=[file join $_wp(imagepath) logo $_wp(logodir) back.gif] "style=\"background-repeat: repeat-x\"" $onload $onunload {

      catch {WPCmd PEInfo set help_context folders}

      # prepare context and navigation information

      set mbox [WPCmd PEMailbox mailboxname]

      lappend pagehier [list "Folder List"]
      lappend pagehier [list [cgi_bold "\[Return to $mbox\]"] fr_main.tcl "View list of messages"]
      if {[string compare $oncancel view] == 0} {
	if {$uid} {
	  set num [WPCmd PEMessage $uid number]
	} else {
	  set num View
	}

	lappend pagehier [list [cgi_bold "\[Return to Message $num\]"] view.tcl "View Message"]
      }

      set navops ""

      WPTFTitle "Folder List" $newmail 0 "folders"

      cgi_table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%" {

	cgi_table_row {
	  cgi_table_data valign=top class=navbar {
	    cgi_table bgcolor=$_wp(menucolor) border=0 cellspacing=0 cellpadding=0 {
	      cgi_table_row {
		cgi_table_data class=navbar "style=\"padding: 6 0 0 4\"" {
		  cgi_puts [cgi_span "style=font-weight: bold" "Current Folder"]
		  cgi_division align=center "style=margin-top:4;margin-bottom:4" {
		    set mbn [WPCmd PEMailbox mailboxname]
		    if {[string length $mbn] > 16} {
		      set mbn "[string range $mbn 0 14]..."
		    }

		    cgi_put [cgi_url $mbn fr_main.tcl target=_top class=navbar]

		    switch -exact -- [WPCmd PEMailbox state] {
		      readonly {
			cgi_br
			#cgi_put [cgi_span "style=color: black; border: 1px solid red; background-color: pink; font-weight: bold" "Read Only"]
			cgi_put [cgi_span "style=color: pink; font-weight: bold" "(Read Only)"]
		      }
		      closed {
			cgi_br
			#cgi_put [cgi_span "style=color: black; border: 1px solid red; background-color: pink; font-weight: bold" "Closed"]
			cgi_put [cgi_span "style=color: pink; font-weight: bold" "(Closed)"]
		      }
		      ok -
		      default {}
		    }

		    cgi_br
		  }

		  cgi_hr "width=75%"
		}
	      }

	      # next comes the menu down the left side, with suitable
	      cgi_table_row {
		eval {
		  cgi_table_data $_wp(menuargs) class=navbar style=padding-bottom:10 {
		    WPTFCommandMenu folder_menu common_menu
		  }
		}
	      }
	    }
	  }

	  # down the right side of the table is the window's contents
	  cgi_table_data width="100%" bgcolor=#ffffff valign=top {

	    if {[llength $collections] > 1} {
	      cgi_division "style=\"font-family: helvetica; padding: 18; text-align: center\"" {
		cgi_puts [cgi_span "style=font-weight: bold; font-size: 14pt; vertical-align: middle" "Folder Collections"]
		cgi_br
		cgi_puts [cgi_span "style=font-size: smaller" "(click to expand, open, delete, etc.)"]
	      }
	    }

	    cgi_form $_wp(appdir)/$_wp(ui1dir)/wp method=post target=_top {
	      cgi_text "page=folders" type=hidden notab
	      cgi_text "cid=$key" type=hidden notab
	      cgi_text "frestore=1" type=hidden notab
	      # then the table representing the folders
	      cgi_table border=0 cellspacing=0 cellpadding=2 align=center {
		for {set i 0} {$i < [llength $collections]} {incr i} {
		  set col [lindex $collections $i]
		  set colid [lindex $col 0]

		  if {[llength $collections] == 1} {
		    set menu "c"
		    set flist 1
		  } else {
		    if {[set index [lsearch $shown $colid]] < 0} {
		      set menu "ce"
		      set flist {}
		    } else {
		      set menu "cc"
		      set flist 1
		    }
		  }

		  cgi_table_row {
		    cgi_table_data nowrap valign=middle {
		      if {[WPCmd PEFolder isincoming $colid] == 0 && [llength $flist]} {
			cgi_image_button delquery=[WPimg but_folddel] border=0 alt=Delete
			cgi_image_button renquery=[WPimg but_foldren] border=0 alt=Rename style=margin-left:4
			cgi_image_button dwnquery=[WPimg but_foldexp] border=0 alt=Export style=margin-left:4
		      }
		    }

		    if {[llength $collections] > 1} {
		      if {[set index [lsearch $shown $colid]] < 0} {
			set colpref [cgi_url [cgi_imglink expand] "${baseurl}expand=$colid" name=f_$colid]
		      } else {
			set colpref [cgi_url [cgi_imglink contract] "${baseurl}contract=$colid" name=f_$colid]
		      }
		    } else {
		      set colpref ""
		    }

		    cgi_table_data align=left "style=\"padding-left:10\"" nowrap {
		      if {[llength [lindex $collectionfolders $i]]} {
			set flist [lindex $collectionfolders $i]
		      }

		      cgi_puts ${colpref}[cgi_span "style=font-family:Helvetica; size: large; padding-left:10" "[lindex $col 1]"]
		    }

		    if {[llength $flist]} {
		      if {[WPCmd PEFolder isincoming $colid] == 0} {
			cgi_table_data valign=middle nowrap {
			  cgi_submit_button "new_$colid=Create New..."
			  cgi_submit_button "imp_$colid=Import..."
			}
		      }
		    }
		  }

		  if {[llength $flist]} {
		    blat_folder_list $colid $flist $shown $colid $baseurl $scroll anchorcnt 1
		  }

		  cgi_table_row {
		    cgi_table_data height=12 {
		      cgi_put [cgi_nbspace]
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
}