~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to web/cgi/alpine-2.0/common.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2008-09-23 12:17:56 UTC
  • mfrom: (2.1.8 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080923121756-6u4x8bwq89qlzt32
Tags: 2.00+dfsg-2
Update to package description: note that Alpine is no longer in
alpha. (Closes: #499640)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: common 391 2007-01-25 03:53:59Z mikes@u.washington.edu $
 
2
# ========================================================================
 
3
# Copyright 2008 University of Washington
 
4
#
 
5
# Licensed under the Apache License, Version 2.0 (the "License");
 
6
# you may not use this file except in compliance with the License.
 
7
# You may obtain a copy of the License at
 
8
#
 
9
#     http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
# ========================================================================
 
12
 
 
13
#  common.tcl
 
14
#
 
15
#  Purpose:  TCL script snippets that the various CGI script generating pages
 
16
#            have in common
 
17
#
 
18
 
 
19
proc wpSelectedClass {seld unread defclass} {
 
20
  set class $defclass
 
21
  if {[expr $seld]} {
 
22
    append class " sel"
 
23
  }
 
24
 
 
25
  if {$unread} {
 
26
    append class " bld"
 
27
  }
 
28
 
 
29
  return $class
 
30
}
 
31
 
 
32
proc wpPageTitle {page} {
 
33
  return "$page - Web Alpine 2.0"
 
34
}
 
35
 
 
36
proc current_context {page c f cc cf} {
 
37
  set ct {[lsearch {browse view} $page] >= 0 && }
 
38
  if {0 == $cc && 0 == [string compare -nocase inbox $cf]} {
 
39
    append ct {0 == $c && 0 == [string compare -nocase inbox $f]}
 
40
  } else {
 
41
    append ct {$cc == $c && 0 == [string compare $cf $f]}
 
42
  }
 
43
 
 
44
  set current [expr $ct]
 
45
}
 
46
 
 
47
proc folder_link {current page c f u unread {ficon ""}} {
 
48
  set url "browse/$c/[WPPercentQuote $f]"
 
49
  set clickurl $url
 
50
  set urlid ""
 
51
  set fclass ""
 
52
  set fid ""
 
53
  if {$current} {
 
54
    set urlid "id=\"gFolder\""
 
55
    set urid "id=\"unreadCurrent\""
 
56
    set fid "id=\"fCurrent\""
 
57
    set onclick "onClick=return newMessageList({parms:{op:'unfocus',page:'new'}});"
 
58
  } elseif {[string length $ficon]} {
 
59
    set fq [cgi_quote_html $f]
 
60
    set urid "id=\"unread${fq}\""
 
61
    set fid "id=\"f${fq}\""
 
62
    set onclick [onClick $clickurl]
 
63
  } else {
 
64
    set urid ""
 
65
    set onclick ""
 
66
  }
 
67
 
 
68
  if {$unread} {
 
69
    set fclass "class=bld"
 
70
    set urc " ($unread)"
 
71
  } elseif {[string length $ficon] || $current} {
 
72
    set urc ""
 
73
  }
 
74
 
 
75
  if {[info exists urc]} {
 
76
    set urt [cgi_span "class=wap unrd" $urid $urc]
 
77
  } else {
 
78
    set urt ""
 
79
  }
 
80
 
 
81
  if {![string length $ficon]} {
 
82
    set ficon [cgi_span "class=sp splc splc7" ""]
 
83
  }
 
84
  return "[cgi_url "$ficon[cgi_span $fid $fclass [cgi_quote_html $f]]" $url class=wap $urlid $onclick]$urt"
 
85
}
 
86
 
 
87
proc empty_link {current falias c} {
 
88
  if {$current} {
 
89
    set emptyfunc emptyCurrent
 
90
  } else {
 
91
    switch $falias {
 
92
      Trash { set emptyfunc emptyTrash}
 
93
      Junk { set emptyfunc emptyJunk }
 
94
    }
 
95
  }
 
96
  if {[info exists emptyfunc]} {
 
97
    return "\[[cgi_url "Empty" "#" "onClick=panelConfirm('Are you sure you want to permanently delete the contents of the $falias folder?<p>Deleted messages are gone forever.',{text:'Empty $falias',fn:$emptyfunc}); return false;" title="Permanently delete all messages in the $falias folder" class=wap]\]"
 
98
  }
 
99
 
 
100
  return ""
 
101
}
 
102
 
 
103
proc context_class {current} {
 
104
  if {$current && ![WPCmd PEMailbox focus]} {
 
105
    return "fld sel"
 
106
  }
 
107
 
 
108
  return "fld"
 
109
}
 
110
 
 
111
proc div_folder {page c f u cc cf unread {ficon ""}} {
 
112
  set current [current_context $page $c $f $cc $cf]
 
113
  cgi_division class="[context_class $current]" {
 
114
      cgi_put [folder_link $current $page $cc $cf $u $unread $ficon]
 
115
  }
 
116
}
 
117
 
 
118
proc wpStatusAndNewmailJavascript {} {
 
119
  foreach sm [WPCmd PEInfo statmsgs] {
 
120
    regsub -all {'} $sm {\'} sm
 
121
    cgi_puts "  addStatusMessage('$sm',15);"
 
122
  }
 
123
  if {[catch {WPCmd PEMailbox newmail 0} newmail]} {
 
124
    regsub -all {'} $newmail {\'} newmail
 
125
    cgi_puts "  addStatusMessage('new mail error: $newmail',15);"
 
126
  } else {
 
127
    catch {WPCmd PEMailbox newmailreset}
 
128
    if {[lindex $newmail 0] > 0} {
 
129
      cgi_puts "  addStatusMessage(parseNewMail('$newmail'),15);"
 
130
    }
 
131
  }
 
132
  cgi_puts "  displayStatusMessages();"
 
133
}
 
134
 
 
135
set clicktest ""
 
136
 
 
137
proc onClick {dest} {
 
138
  global clicktest
 
139
 
 
140
  if {[string length $clicktest]} {
 
141
    return "onClick=[$clicktest $dest]"
 
142
  }
 
143
 
 
144
  return ""
 
145
}
 
146
 
 
147
# table representing common overall page layout
 
148
#
 
149
# NOTES: bodyform doesn't flow thru cgi.tcl,but it keeps menu bar's
 
150
#        easier for caller to keep stright
 
151
#
 
152
proc wpCommonPageLayout {curpage c f u context searchform leavetest cmds menubar_top content menubar_bottom} {
 
153
  global _wp clicktest
 
154
 
 
155
  set thispage [lindex $curpage 0]
 
156
 
 
157
  set clicktest $leavetest
 
158
 
 
159
  # various positioned elements
 
160
 
 
161
  # busy cue
 
162
  cgi_division id="bePatient" {
 
163
    cgi_put "Working..."
 
164
  }
 
165
 
 
166
  cgi_table class="page" cellpadding="0" cellspacing="0" {
 
167
    cgi_puts "<tbody>"
 
168
 
 
169
    cgi_table_row  {
 
170
      cgi_table_data  class="spc" colspan="3" {
 
171
        cgi_put [cgi_span "class=sp trans" "style=height:1px;width:2px;" [cgi_span " "]]
 
172
      }
 
173
    }
 
174
 
 
175
    # CONTEXT
 
176
    cgi_table_row {
 
177
      cgi_table_data class="wap topHdr" {
 
178
        cgi_division id=hdrLogo {
 
179
          cgi_puts [cgi_img "img/cbn/alpinelogo.gif" name="logo" class="logo" "title=Web Alpine [WPCmd PEInfo version]" class=wap]
 
180
          cgi_puts [cgi_span "class=logo wap" "v [WPCmd PEInfo version].[WPCmd PEInfo revision]"]
 
181
        }
 
182
      }
 
183
 
 
184
      cgi_table_data  class="topHdr" {
 
185
        cgi_put [cgi_span "class=sp trans" "style=height:2px;width:5px;" " "]
 
186
      }
 
187
 
 
188
      cgi_table_data  class="wap topHdr" {
 
189
        cgi_division class=hdrContent {
 
190
          # RSS INFO STREAM
 
191
          if {[catch {WPCmd PERss news} news]} {
 
192
            cgi_put [cgi_nbspace]
 
193
            cgi_html_comment "RSS FAILURE: $news"
 
194
          } else {
 
195
            if {[llength $news] > 0} {
 
196
              set style ""
 
197
              set n 0
 
198
              foreach item $news {
 
199
                cgi_put [cgi_span class=RSS $style "[cgi_span "class=sp newsImg" "onClick=\"return rotateNews(this);\"" ""][cgi_url [lindex $item 0] [lindex $item 1] "onClick=this.blur();" id=newsItem$n target=_blank]"]
 
200
                set style "style=display: none;"
 
201
              }
 
202
            } else {
 
203
            cgi_put [cgi_nbspace]
 
204
            }
 
205
          }
 
206
 
 
207
          # STATUS LINE
 
208
          cgi_division class=wbar id=statusMessage {
 
209
            cgi_division class=status {
 
210
              cgi_division "class=\"flt edge\"" {
 
211
                cgi_put [cgi_span "class=sp spsm sm1" ""]
 
212
              }
 
213
              cgi_division "class=\"frt cap\"" {}
 
214
              cgi_division "class=\"frt edge\"" {
 
215
                cgi_put [cgi_url [cgi_span "class=sp spsm sm2" ""] "" class=wap "onClick=hideStatusMessage(); return false;"]
 
216
              }
 
217
              cgi_division class=center id=statusMessageText {}
 
218
            }
 
219
          }
 
220
 
 
221
          # WEATHER/USAGE/STATUS
 
222
          cgi_division class=wbar id=weatherBar {
 
223
            # RSS WEATHER
 
224
            cgi_division class=weather id=rssWeather {
 
225
              if {[catch {WPCmd PERss weather} weather]} {
 
226
                cgi_html_comment "RSS FAILURE: $weather"
 
227
                cgi_put [cgi_nbspace]
 
228
              } else {
 
229
                if {[llength $weather] > 0} {
 
230
                  set item [lindex $weather 0]
 
231
                  cgi_html_comment "index 2 is: [lindex $item 2]"
 
232
                  cgi_put [cgi_url [lindex $item 0] [lindex $item 1] "onClick=this.blur();" target=_blank]
 
233
                } else {
 
234
                  cgi_put [cgi_nbspace]
 
235
                }
 
236
              }
 
237
            }
 
238
            if {[info exists _wp(usage)]
 
239
                && 0 == [catch {exec -- $_wp(usage) [WPCmd set env(WPUSER)]} usage]
 
240
                && [regexp {^([0-9]+)[ ]+([0-9]+)$} $usage dummy use_current use_total]
 
241
                && $use_total > 0
 
242
                && $use_current <= $use_total} {
 
243
              cgi_division class=usage {
 
244
                cgi_table  width="180px" cellpadding="0" cellspacing="0" {
 
245
                  cgi_table_row  {
 
246
                    cgi_table_data class=wap width="1%" align=right {
 
247
                      cgi_put [cgi_nbspace]
 
248
                    }
 
249
                    cgi_table_data class=wap width="98%" {
 
250
 
 
251
                      set useperc [expr {($use_current * 100) / $use_total}]
 
252
 
 
253
                      cgi_table  border=0 width="100%" height="12px" cellspacing=0 cellpadding=0 align=right {
 
254
                        set percentage [expr {($use_current * 100)/$use_total}]
 
255
                        cgi_table_row  {
 
256
                          cgi_table_data class=wap align=right "style=\"border: 1px solid black; border-right: 0; background-color: #408040;\"" width="$useperc%" {
 
257
                            cgi_put [cgi_span "class=sp trans" "style=height:1px;width:1px;" [cgi_span " "]]
 
258
                          }
 
259
                          cgi_table_data class=wap align=right "style=\"border: 1px solid black; background-color: #ffffff;\"" width="[expr {100 - $useperc}]%" {
 
260
                            cgi_put [cgi_span "class=sp trans" "style=height:1px;width:1px;" [cgi_span " "]]
 
261
                          }
 
262
                        }
 
263
                      }
 
264
                    }
 
265
                    cgi_table_data class=wap width="1%" align=right {
 
266
                      set units MB
 
267
                      if {[info exists _wp(usage_link)]} {
 
268
                        set txt [cgi_url $use_total $_wp(usage_link) "onClick=this.blur();" title="Detailed usage report" target="_blank"]
 
269
                      } else {
 
270
                        set txt $use_total
 
271
                      }
 
272
 
 
273
                      cgi_put [cgi_span "style=margin-left: .25em" $txt]
 
274
                    }
 
275
                  }
 
276
                }
 
277
              }
 
278
            }
 
279
          }
 
280
 
 
281
          cgi_division class=pageTitle id=pageTitle {
 
282
            cgi_put $context
 
283
          }
 
284
 
 
285
          cgi_division class=commands {
 
286
            uplevel 1 $cmds
 
287
          }
 
288
        }
 
289
      }
 
290
    }
 
291
 
 
292
    cgi_noscript {
 
293
      cgi_table_row  {
 
294
        cgi_table_data class=noscript  colspan="3" {
 
295
          cgi_put "This version of Web Alpine requires Javascript.  Please enable Javascript, or use the [cgi_url "HTML Version" "$_wp(serverpath)/$_wp(appdir)/wp.tcl"] of Web Alpine"
 
296
        }
 
297
      }
 
298
    }
 
299
 
 
300
    cgi_table_row  {
 
301
      cgi_table_data id=leftColumn class="wap checkMailandCompose" {
 
302
        cgi_table class="toolbarTbl" cellpadding="0" cellspacing="0" {
 
303
          cgi_put "<tbody>"
 
304
          cgi_table_row  {
 
305
            cgi_table_data class="wap" {
 
306
              set nUrl "browse/"
 
307
              if {0 == [regexp {^[0-9]+$} $c]} {
 
308
                append nUrl "/0'"
 
309
              } else {
 
310
                append nUrl "/$c'"
 
311
              }
 
312
 
 
313
              if {0 == [string length $f]} {
 
314
                append nUrl "/INBOX'"
 
315
              } else {
 
316
                append nUrl "/[WPPercentQuote $f]"
 
317
              }
 
318
 
 
319
              set nUrl "browse/$c/$f"
 
320
              set onArrival "newMessageList({parms:{'op':'noop'}});"
 
321
              cgi_put [cgi_url [cgi_span "class=sp spmbi spmb15" "Check Mail"] $nUrl title="Check for New Mail" id=gCheck "onClick=return newMailCheck(0);"]
 
322
            }
 
323
            cgi_table_data  class="wap dv1" {
 
324
              cgi_puts [cgi_span "class=sp spmb spmb3" ""]
 
325
            }
 
326
            cgi_table_data class="wap" {
 
327
              set cUrl compose
 
328
              if {[string compare compose $thispage]} {
 
329
                switch $thispage {
 
330
                  browse  { append cUrl "?pop=browse/$c/$f" }
 
331
                  view    { append cUrl "?pop=view/$c/$f/$u" }
 
332
                  default { append cUrl "?pop=$thispage" } 
 
333
                }
 
334
              }
 
335
 
 
336
              cgi_put [cgi_url [cgi_span "class=sp spmbi spmb16" "Compose"] $cUrl id=composeLink title="Compose New Message" [onClick $cUrl]]
 
337
            }
 
338
          }
 
339
          cgi_put "</tbody>"
 
340
        }
 
341
 
 
342
        cgi_division class=searchFormDiv {
 
343
          cgi_form [lindex $searchform 0] id=searchForm method=post enctype=multipart/form-data {
 
344
            if {[string length [lindex $searchform 3]]} {
 
345
              set sclick [lindex $searchform 3]
 
346
            } else {
 
347
              set sclick "showStatusMessage('Search is NOT implemented yet',3)"
 
348
            }
 
349
 
 
350
            cgi_text "searchText=Search in [lindex $searchform 1]" class=wap id=searchField title="Click here to search" "onBlur=recallTextField(this, 'Search in [lindex $searchform 1]')" "onClick=\"clearTextField(this, 'Search in [lindex $searchform 1]')\"" "onKeyPress=\"return searchOnEnter(event,'searchButton');\"" maxlength="256"
 
351
            cgi_put "<input alt=\"Search\" name=\"search\" class=\"sp searchBtn\" type=\"submit\" value=\"\" src=\"\" id=\"searchButton\" onClick=\"${sclick}; this.blur(); return false;\" />"
 
352
 
 
353
            set srclass "fld"
 
354
            set searched 0
 
355
            if {[lsearch {browse view} $thispage] >= 0 && [set searched [WPCmd PEMailbox searched]]} {
 
356
              set style ""
 
357
              if {[WPCmd PEMailbox focus]} {
 
358
                append srclass " sel"
 
359
              }
 
360
            } else {
 
361
              set style "display:none;"
 
362
            }
 
363
 
 
364
            cgi_division id="searchRefine" style=\"$style\" {
 
365
              cgi_select scope id=searchScope {
 
366
                cgi_option "Search within Results" value=narrow
 
367
                cgi_option "Add to Search Results" value=broad
 
368
                cgi_option "New Search" value=new selected
 
369
              }
 
370
            }
 
371
          }
 
372
        }
 
373
 
 
374
        if {[lindex $searchform 2]} {
 
375
          cgi_division id=searchAdvance {
 
376
            cgi_puts [cgi_url "Advanced Search" "browse/$c/$f?search=1" class="wap" "onClick=return advanceSearch();"]
 
377
          }
 
378
          cgi_division id=searchClear style=$style {
 
379
            cgi_puts "\[[cgi_url Clear # class="wap" "onClick=return newMessageList({parms:{op:'search',type:'none',page:'new'}});"]\]"
 
380
          }
 
381
        }
 
382
 
 
383
        cgi_division class=searchFormDiv {cgi_puts [cgi_nbspace]}
 
384
 
 
385
        cgi_division id=searchResult class="$srclass" style=\"$style\" {
 
386
          cgi_puts [cgi_url "[cgi_span "class=sp splc splc9" ""][cgi_span class=bld id=searchResultText [cgi_quote_html "Search Result ($searched)"]]" browse/$c/$f?search=1 class=wap "onClick=return listSearchResults();"]
 
387
        }
 
388
 
 
389
        if {0 == [string compare [lindex $curpage 0] settings]} {
 
390
          uplevel 1 [lindex $curpage 1]
 
391
        } else {
 
392
        cgi_division class="folderPane" {
 
393
          cgi_anchor_name folders
 
394
          cgi_division class=folderList  {
 
395
            set defc [WPCmd PEFolder defaultcollection]
 
396
 
 
397
            cgi_javascript {
 
398
              cgi_puts "function emptyCurrent(){"
 
399
              cgi_puts "  doEmpty(null,'all');"
 
400
              cgi_puts "}"
 
401
              cgi_puts "function emptyTrash(){"
 
402
              cgi_puts "  emptyFolder('$defc','[lindex [WPCmd PEConfig varget trash-folder] 0]','all',{status:true,fn:'fixupUnreadCount(\"Trash\",0)'});"
 
403
              cgi_puts "}"
 
404
              if {[info exists _wp(spamfolder)]} {
 
405
                cgi_puts "function emptyJunk(){"
 
406
                cgi_puts "  emptyFolder('$defc','$_wp(spamfolder)','all',{status:true,fn:'fixupUnreadCount(\"Junk\",0)'});"
 
407
                cgi_puts "}"
 
408
              }
 
409
            }
 
410
 
 
411
            set current [current_context $thispage $c $f 0 INBOX]
 
412
            cgi_division class="[context_class $current]" id=targetInbox {
 
413
              cgi_put [folder_link $current $thispage 0 INBOX $u [WPCmd PEFolder unread 0 INBOX] [cgi_span "class=sp splc splc1" ""]]
 
414
              if {0 == [string compare browse $thispage] && [string compare -nocase inbox $f]} {
 
415
                lappend ddtargets [list targetInbox 0 INBOX]
 
416
              }
 
417
            }
 
418
 
 
419
            set draftf [lindex [WPCmd PEConfig varget postponed-folder] 0]
 
420
            if {0 == [catch {WPCmd PEFolder exists $defc $draftf} result] && $result} {
 
421
              div_folder $thispage $c $f $u $defc Drafts [WPCmd PEFolder unread $defc $draftf] [cgi_span "class=sp splc splc2" ""]
 
422
            }
 
423
 
 
424
            div_folder $thispage $c $f $u $defc Sent [WPCmd PEFolder unread $defc [lindex [WPCmd PEConfig varget default-fcc] 0]] [cgi_span "class=sp splc splc3" ""]
 
425
 
 
426
            if {[info exists _wp(spamfolder)]} {
 
427
              set current [current_context $thispage $c [wpSpecialFolder $c $f] $defc Junk]
 
428
              cgi_division class="[context_class $current]" {
 
429
                cgi_put [cgi_span "xclass=left" [folder_link $current $thispage $defc Junk $u [WPCmd PEFolder unread $defc $_wp(spamfolder)] [cgi_span "class=sp splc splc4" ""]]]
 
430
                cgi_put [cgi_span "class=right" [empty_link $current Junk $defc]]
 
431
              }
 
432
            }
 
433
 
 
434
            set current [current_context $thispage $c [wpSpecialFolder $c $f] $defc Trash]
 
435
            cgi_division class="[context_class $current]" id=targetTrash {
 
436
              set trashf [lindex [WPCmd PEConfig varget trash-folder] 0]
 
437
              cgi_put [cgi_span class=left [folder_link $current $thispage $defc Trash $u [WPCmd PEFolder unread $defc $trashf] [cgi_span "class=sp splc splc5" id=targetTrashIcon [cgi_span [cgi_nbspace]]]]]
 
438
              cgi_put [cgi_span class=right [empty_link $current Trash $defc]]
 
439
              if {0 == [string compare browse $thispage] && [string compare Trash $f]} {
 
440
                lappend ddtargets [list targetTrash $defc $trashf]
 
441
              }
 
442
            }
 
443
            cgi_division class="wap fld" {
 
444
              cgi_put [cgi_nbspace]
 
445
            }
 
446
 
 
447
            cgi_division class="[wpSelectedClass "0 == [string compare $thispage contacts]" 0 "fld"]" id=targetContacts {
 
448
              set cUrl contacts
 
449
              cgi_put [cgi_url "[cgi_span "class=sp splc splc6" ""][cgi_span Contacts]" $cUrl title="Contact List" class=wap [onClick $cUrl]]
 
450
              if {0 == [string compare browse $thispage]} {
 
451
                if {0 == [catch {WPCmd PEAddress books} booklist]} {
 
452
                  set tAFargs "\{books:\["
 
453
                  set comma ""
 
454
                  foreach b $booklist {
 
455
                    regsub -all {'} [lindex $b 1] {\'} bname
 
456
                    append tAFargs "${comma}\{book:[lindex $b 0],name:'$bname'\}"
 
457
                    set comma ","
 
458
                  }
 
459
 
 
460
                  append tAFargs "\]\}"
 
461
                } else {
 
462
                  set tAFargs {{}}
 
463
                }
 
464
 
 
465
                # pass address book list 
 
466
                cgi_puts "<script>setDragTarget('targetContacts',takeAddressFrom,$tAFargs);</script>"
 
467
              }
 
468
            }
 
469
            cgi_division  class="fld" {
 
470
              cgi_put [cgi_nbspace]
 
471
            }
 
472
            cgi_division  class="ftitle bld" {
 
473
              cgi_put "Recent Folders"
 
474
            }
 
475
 
 
476
            if {[catch {WPSessionState left_column_folders} fln]} {
 
477
              set fln $_wp(fldr_cache_def)
 
478
            }
 
479
 
 
480
            set nfl 0
 
481
 
 
482
            foreach fce [getFolderCache] {
 
483
              set fccol [lindex $fce 0]
 
484
              set fcname [lindex $fce 1]
 
485
              if {0 == [catch {WPCmd PEFolder exists $fccol $fcname} result] && $result} {
 
486
                set current [current_context $thispage $c $f $fccol $fcname]
 
487
                set folderID target$nfl
 
488
                cgi_division class="[context_class $current]" id=$folderID {
 
489
                  cgi_put [folder_link $current $thispage $fccol $fcname $u [WPCmd PEFolder unread $fccol $fcname] [cgi_span "class=sp splc splc7" id=${folderID}Icon [cgi_span [cgi_nbspace]]]]
 
490
                  if {0 == [string compare browse $thispage] && !($c == $fccol && 0 == [string compare $f $fcname])} {
 
491
                    lappend ddtargets [list $folderID $fccol $fcname]
 
492
                  }
 
493
                }
 
494
              }
 
495
 
 
496
              if {[incr nfl] >= $fln} {
 
497
                break
 
498
              }
 
499
            }
 
500
 
 
501
            cgi_division class="wap fld" {
 
502
              cgi_put [cgi_nbspace]
 
503
            }
 
504
            cgi_division  class="[wpSelectedClass "0 == [string compare $thispage folders]" 0 "fld"]" {
 
505
              set fUrl "folders"
 
506
              cgi_put [cgi_url "[cgi_span "class=sp splc splc8" ""][cgi_span "View/Manage Folders..."]" $fUrl title="View, Create, Rename, and Delete Folders" class=wap [onClick $fUrl]]
 
507
            }
 
508
          }
 
509
        }
 
510
      }
 
511
      }
 
512
 
 
513
      cgi_table_data  class="spc" rowspan="2" {
 
514
        cgi_put [cgi_span "class=sp trans" "style=height:2px;width:5px;" [cgi_span " "]]
 
515
      }
 
516
 
 
517
      cgi_table_data width="100%" valign="top" {
 
518
        # pay not attention to the man behind the curtain
 
519
        cgi_table class="wap content" cellpadding="0" cellspacing="0" {
 
520
          cgi_puts "<tbody>"
 
521
          cgi_table_row  {
 
522
            cgi_table_data id=topToolbar class=wap {
 
523
              cgi_anchor_name toolbar
 
524
              uplevel 1 $menubar_top
 
525
            }
 
526
          }
 
527
 
 
528
          # display page content
 
529
          cgi_table_row  {
 
530
            cgi_table_data height="100%" valign="top" {
 
531
              cgi_division id=alpineContent {
 
532
                uplevel 1 $content
 
533
              }
 
534
            }
 
535
          }
 
536
 
 
537
          cgi_puts "</tbody>"
 
538
        }
 
539
      }
 
540
    }
 
541
 
 
542
    cgi_table_row  {
 
543
      cgi_table_data {
 
544
        cgi_table  class="toolbarTbl" cellpadding="0" cellspacing="0" {
 
545
          cgi_puts "<tbody>"
 
546
          cgi_table_row  {
 
547
            cgi_table_data  class="wap txt" {
 
548
              cgi_put [cgi_nbspace]
 
549
            }
 
550
          }
 
551
          cgi_puts "</tbody>"
 
552
        }
 
553
      }
 
554
 
 
555
      cgi_table_data id=bottomToolbar class=wap  valign="bottom" {
 
556
        uplevel 1 $menubar_bottom
 
557
      }
 
558
    }
 
559
 
 
560
    cgi_table_row  {
 
561
      cgi_table_data id=ftrContent colspan="3" class="wap footer" align="center" {
 
562
        set ft "Powered by [cgi_url Alpine "http://www.washington.edu/alpine/" target="_blank"] - [cgi_copyright] 2007 University of Washington"
 
563
        if {0 == [string compare browse $thispage]} {
 
564
          append ft " - [cgi_url "HTML Version" "$_wp(serverpath)/$_wp(appdir)/wp.tcl"]"
 
565
        }
 
566
 
 
567
        if {[info exists _wp(comments)] && [lsearch {browse view} $thispage] >= 0} {
 
568
          append ft " - [cgi_url "Comments?" "mailto?to=$_wp(comments)&pop=browse/$c/[WPPercentQuote $f]"]"
 
569
        }
 
570
 
 
571
        cgi_puts $ft
 
572
      }
 
573
    }
 
574
    cgi_puts "</tbody>"
 
575
  }
 
576
 
 
577
  if {[info exists ddtargets]} {
 
578
    cgi_puts "<script>"
 
579
    foreach t $ddtargets {
 
580
      regsub -all {'} [lindex $t 2] {\'} fn
 
581
      cgi_puts "setDragTarget('[lindex $t 0]',dragOntoFolder,{c:'[lindex $t 1]',f:'$fn'});"
 
582
    }
 
583
    cgi_puts "</script>"
 
584
  }
 
585
}
 
586
 
 
587
proc setCurrentFolder {_c _f _u} {
 
588
  global _wp
 
589
 
 
590
  upvar 1 $_c c
 
591
  upvar 1 $_f f
 
592
  upvar 1 $_u u
 
593
 
 
594
  # verify current collection/folder
 
595
  if {[catch {WPCmd PEFolder current} curfold]} {
 
596
    error [list _action browse "cannot determine default folder: $curfold"]
 
597
  } else {
 
598
    set curc [lindex $curfold 0]
 
599
    set curf [lindex $curfold 1]
 
600
  }
 
601
 
 
602
  # "current" folder's context
 
603
  if {$c < 0} {
 
604
    set c $curc
 
605
  }
 
606
 
 
607
  # "current" folder
 
608
  if {0 == [string length $f]} {
 
609
    set f $curf
 
610
  }
 
611
 
 
612
  set defc [WPCmd PEFolder defaultcollection]
 
613
 
 
614
  # open a different folder?
 
615
  if {!($c == $curc && 0 == [string compare $f $curf])} {
 
616
    # BUG: DEAL WITH AUTHENTICATION around open below
 
617
 
 
618
    # weed out special use folders
 
619
    if {0 == $c && 0 == [string compare -nocase $f inbox]} {
 
620
      set f INBOX
 
621
      set truef INBOX
 
622
    } else {
 
623
      if {$c == $defc} {
 
624
        switch -regexp -- $f {
 
625
          {^Drafts$} {
 
626
            set mode draft
 
627
            catch {WPCmd set pre_draft_folder [WPCmd PEFolder current]}
 
628
            set pf [lindex [WPCmd PEConfig varget postponed-folder] 0]
 
629
            if {[string compare $curf $pf]} {
 
630
              set truef $pf
 
631
              if {[catch {
 
632
                if {[WPCmd PEFolder exists $c $pf] <= 0} {
 
633
                  WPCmd PEFolder create $c $pf
 
634
                }
 
635
              } result]} {
 
636
                WPCmd PEInfo statmsg $result
 
637
              }
 
638
            }
 
639
          }
 
640
          {^Trash$} {
 
641
            set mode trash
 
642
            set pf [lindex [WPCmd PEConfig varget trash-folder] 0]
 
643
            if {[string compare $curf $pf]} {
 
644
              set truef $pf
 
645
              if {[catch {
 
646
                if {[WPCmd PEFolder exists $c "$pf"] <= 0} {
 
647
                  WPCmd PEFolder create $c "$pf"
 
648
                }
 
649
              } result]} {
 
650
                WPCmd PEInfo statmsg $result
 
651
              }
 
652
            }
 
653
          }
 
654
          {^Junk$} {
 
655
            if {[info exists _wp(spamfolder)]} {
 
656
              set mode junk
 
657
              set pf $_wp(spamfolder)
 
658
              if {[string compare $curf $pf]} {
 
659
                set truef $pf
 
660
                if {[catch {
 
661
                  if {[WPCmd PEFolder exists $c $pf] <= 0} {
 
662
                    WPCmd PEFolder create $c $pf
 
663
                  }
 
664
                } result]} {
 
665
                  WPCmd PEInfo statmsg $result
 
666
                }
 
667
              }
 
668
            } else {
 
669
              set truef $f
 
670
            }
 
671
          }
 
672
          {^Sent$} {
 
673
            set mode sent
 
674
            set pf [lindex [WPCmd PEConfig varget default-fcc] 0]
 
675
            if {[string compare $curf $pf]} {
 
676
              set truef $pf
 
677
              if {[catch {
 
678
                if {[WPCmd PEFolder exists $c $pf] <= 0} {
 
679
                  WPCmd PEFolder create $c $pf
 
680
                }
 
681
              } result]} {
 
682
                WPCmd PEInfo statmsg $result
 
683
              }
 
684
            }
 
685
          }
 
686
          default {
 
687
            set truef $f
 
688
          }
 
689
        }
 
690
      } else {
 
691
        set truef $f
 
692
      }
 
693
    }
 
694
 
 
695
    if {[info exists truef]} {
 
696
      if {[catch {eval WPCmd PEMailbox open [list $c $truef]} reason]} {
 
697
        error $reason
 
698
      } else {
 
699
        # do_broach handled this: WPCmd PEInfo statmsg "$f opened with [WPCmd PEMailbox messagecount] messages"
 
700
 
 
701
        if {![info exists mode]} {
 
702
          addFolderCache $c $f
 
703
        }
 
704
 
 
705
        if {[catch {WPCmd PEMailbox trashdeleted current} result]} {
 
706
          WPCmd PEInfo statmsg "Detete FAILURE: $result"
 
707
        }
 
708
      }
 
709
    }
 
710
  } else {
 
711
    # verify $c $f (and $u if present) exists
 
712
    if {!($c == 0 && 0 == [string compare -nocase inbox $f])} {
 
713
      if {[catch {WPCmd PEFolder exists $c $f} result]} {
 
714
        WPCmd PEInfo statmsg "Cannot test $f for existance: $result"
 
715
      } elseif {$result <= 0} {
 
716
        WPCmd PEInfo statmsg "Folder $f in collection $c does not exist"
 
717
      }
 
718
    }
 
719
 
 
720
    if {$u > 0 && [catch {WPCmd PEMessage $u number} result]} {
 
721
      WPCmd PEInfo statmsg "Message $u does not exist: $result"
 
722
    }
 
723
  }
 
724
}
 
725
 
 
726
proc wpFolderMode {c f} {
 
727
  if {$c == [WPCmd PEFolder defaultcollection]} {
 
728
    switch -exact -- $f {
 
729
      Drafts { return draft }
 
730
      Sent   { return sent  }
 
731
      Junk   { return junk  }
 
732
      Trash  { return trash }
 
733
    }
 
734
  }
 
735
 
 
736
  return ""
 
737
}
 
738
 
 
739
proc wpInitPageFraming {_u _n _mc _ppg _pn _pt} {
 
740
  upvar 1 $_u u
 
741
  upvar 1 $_n n
 
742
  upvar 1 $_mc mc
 
743
  upvar 1 $_ppg ppg
 
744
  upvar 1 $_pn pn
 
745
  upvar 1 $_pt pt
 
746
 
 
747
  set focused [WPCmd PEMailbox focus]
 
748
 
 
749
  if {$n > 0} {
 
750
    set pt [expr {$mc / $ppg}]
 
751
 
 
752
    if {$pt < 1} {
 
753
      set pt 1
 
754
    } elseif {$mc % $ppg} {
 
755
      incr pt
 
756
    }
 
757
 
 
758
    if {$focused} {
 
759
      set nth [WPCmd PEMailbox messagecount before $n]
 
760
      incr nth
 
761
    } else {
 
762
      set nth $n
 
763
    }
 
764
 
 
765
    if {$nth > $ppg} {
 
766
      set pn [expr {$nth / $ppg}]
 
767
      if {$nth % $ppg} {
 
768
        incr pn
 
769
      }
 
770
 
 
771
      set n [expr {(($pn - 1) * $ppg) + 1}]
 
772
      if {$focused} {
 
773
        set n [WPCmd PEMailbox next [WPCmd PEMailbox first] $n]
 
774
      }
 
775
    } else {
 
776
      set pn 1
 
777
      set n [WPCmd PEMailbox first]
 
778
    }
 
779
 
 
780
    set u [WPCmd PEMailbox uid $n]
 
781
  } else {
 
782
    set mc 0
 
783
    set pt 1
 
784
    set pn 1
 
785
  }
 
786
}
 
787
 
 
788
proc wpHandleAuthException {err c {f ""}} {
 
789
  global _wp
 
790
 
 
791
  if {[regexp {^CERTQUERY ([^+]+)\+\+(.*)$} $err dummy server reason]} {
 
792
    return "code:'CERTQUERY',server:\"${server}\",reason:\"${reason}\""
 
793
  } elseif {[regexp {^CERTFAIL ([^+]+)\+\+(.*)$} $err dummy server reason]} {
 
794
    return "code:'CERTFAIL',server:\"${server}\",reason:\"${reason}\""
 
795
  } elseif {[regexp {^NOPASSWD (.*)$} $err dummy server]} {
 
796
    return "code:'NOPASSWD',c:[lindex $c 0],f:\"${f}\",server:\"{${server}/tls}\",reason:\"[lindex $c 1]\",sessid:\"$_wp(sessid)\""
 
797
  } elseif {[regexp {^BADPASSWD (.*)$} $err dummy server]} {
 
798
    return "code:'BADPASSWD',c:[lindex $c 0],f:\"${f}\",server:\"{${server}/tls}\",reason:\"[lindex $c 1]\",sessid:\"$_wp(sessid)\""
 
799
  }
 
800
 
 
801
  return {}
 
802
}
 
803
 
 
804
proc reportAuthException {exp} {
 
805
  cgi_put "processAuthException(\{$exp\});"
 
806
}
 
807
 
 
808
proc wpSaveMenuJavascript {p c f dc onDone {df ""}} {
 
809
  set nn 0;
 
810
  cgi_put "updateSaveCache(\"$p\",$c,\"$f\",$dc,$onDone,\["
 
811
  foreach {oname oval} [getSaveCache $df] {
 
812
    if {[incr nn] > 1} {
 
813
      cgi_put ","
 
814
    }
 
815
 
 
816
    cgi_put "{fn:\"$oname\",fv:\"$oval\"}"
 
817
  }
 
818
  cgi_puts "\]);"
 
819
}
 
820
 
 
821
proc wpLiteralFolder {c f} {
 
822
  global _wp
 
823
 
 
824
  if {$c == [WPCmd PEFolder defaultcollection]} {
 
825
    switch -exact -- $f {
 
826
      Draft {
 
827
        return [lindex [WPCmd PEConfig varget postponed-folder] 0]
 
828
      }
 
829
      Sent  {
 
830
        return [lindex [WPCmd PEConfig varget default-fcc] 0]
 
831
      }
 
832
      Junk  {
 
833
        if {[info exists _wp(spamfolder)]} {
 
834
          return $_wp(spamfolder)
 
835
        }
 
836
      }
 
837
      Trash {
 
838
        return [lindex [WPCmd PEConfig varget trash-folder] 0]
 
839
      }
 
840
    }
 
841
  }
 
842
 
 
843
  return $f
 
844
}
 
845
 
 
846
proc wpSpecialFolder {c f} {
 
847
  global _wp
 
848
 
 
849
  if {$c == [WPCmd PEFolder defaultcollection]} {
 
850
    if {0 == [string compare $f [lindex [WPCmd PEConfig varget postponed-folder] 0]]} {
 
851
      return Draft
 
852
    }
 
853
 
 
854
    if {0 == [string compare $f [lindex [WPCmd PEConfig varget default-fcc] 0]]} {
 
855
      return Sent
 
856
    }
 
857
    if {[info exists _wp(spamfolder)]} {
 
858
      if {0 == [string compare $f $_wp(spamfolder)]} {
 
859
        return Junk
 
860
      }
 
861
    }
 
862
    if {0 == [string compare $f [lindex [WPCmd PEConfig varget trash-folder] 0]]} {
 
863
      return Trash
 
864
    }
 
865
  }
 
866
 
 
867
  return $f
 
868
}