summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/2.0/browse
blob: 9669fd8cf076591e86f14b30cc5ef45e5b1e8416 (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
#!./tclsh
# $Id: browse 1266 2009-07-14 18:39:12Z hubert@u.washington.edu $
# ========================================================================
# Copyright 2008 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
#
# ========================================================================

#  browse
#
#  Purpose:  CGI script that generates a page displaying a message
#            list of the indicated folder. 
#
#  Input:    PATH_INFO: [/<col_number>]/<folder_name>[/<uid_of_first_msg>
#            along with possible search parameters:
set browse_args {
  {u		{}	0}
  {pageFirst	{}	""}
  {pagePrev	{}	""}
  {pageNext	{}	""}
  {pageLast	{}	""}
  {sort		{}	""}
  {rev		{}	""}
}

# inherit global config
source ./alpine.tcl
source ./common.tcl
source ./foldercache.tcl

# default browse state
set c 0
set f INBOX

# TEST:
proc cgi_suffix {args} {
  return ""
}

# for inserting debug comments at end of page
set dmsgs ""
proc dm {s} {
  global dmsgs
  lappend dmsgs $s
}

WPEval $browse_args {
  # grok PATH_INFO for collection, 'c', and folder 'f'
  if {[info exists env(PATH_INFO)] && [string length $env(PATH_INFO)]} {
    if {![regexp {^/([0-9]+)/(.*)$} $env(PATH_INFO) dummy c f]} {
      WPCmd PEInfo statmsg "Cannot open invalid path: $env(PATH_INFO)"
      set c 0
      set f INBOX
    }
  } elseif {[catch {WPCmd PEFolder current} curf]
	    || [lindex $curf 0] != 0
	    || [string compare -nocase [lindex $curf 1] inbox]} {
    WPCmd PEInfo statmsg "No Folder Specified, opening INBOX"
  }

  # verify or visit specified collection/folder

  if {[catch {setCurrentFolder c f u} result]} {
    set authlist [wpHandleAuthException $result [list $c "open folder $f"] $f]
    if {0 == [llength $authlist]} {
      WPCmd PEInfo statmsg "$result"
      set c 0
      set f INBOX
    } else {
      set opening_folder 1
    }
  }

  if {[info exists opening_folder]} {
    set n 1
    set u 0
  } else {
    # move anything deleted to Trash
    if {[catch {WPCmd PEMailbox trashdeleted current} result]} {
      WPCmd PEInfo statmsg "Trash move Failed: $result"
    }

    # set uid to "current" message?
    if {$u <= 0 && 0 == [catch {WPCmd PEMailbox current} cm]} {
      set u [lindex $cm 1]
    }
  }

  # get default sort
  if {[catch {WPCmd PEMailbox sort} cursort]} {
    set sort date
    set rev 1
  }

  # load index drawing routine for this session
  # save perpage source, proc overhead
  # call to reinstall during debugging:
  #catch {WPCmd rename drawMessageList {}}
  if {0 == [llength [WPCmd info commands drawMessageList]]} {
    set cgidir [file join $_wp(cgipath) $_wp(appdir) $_wp(ui2dir)]
    if {[catch {
      WPCmd source "$_wp(confdir)/alpine.tcl"
      WPCmd source "${cgidir}/common.tcl"
      WPCmd source "${cgidir}/messagelist.tcl"
      WPCmd source "${cgidir}/messageview.tcl"
      WPCmd rename WPCmd {}
      WPCmd rename WPEval {}
      WPCmd rename WPGetInputAndID {}
      WPCmd rename WPCmdEval WPCmd
    } result]} {
      error [list _action browse "cannot load index lister: $result"]
    }
  }

  # current context or folder changed?
  if {$c == 0 && 0 == [string compare -nocase $f inbox]} {
    set f INBOX
  }

  # gain situational awareness, UID and number of message that must be on page
  if {[catch {WPCmd PEMailbox focus} focused]} {
    set mc 0
    set focused 0
  } elseif {$focused > 0} {
    set mc $focused
  } else {
    set mc [WPCmd PEMailbox messagecount]
  }

  if {$u == 0} {
    # non given, set to first message in folder
    set n 1
    if {[catch {WPCmd PEMailbox uid 1} u]} {
      set n 0
      set u 0
    }
  } elseif {[catch {WPCmd PEMessage $u number} n]} {
    set n 0
    set u 0
  }

  # lines per page
  if {[catch {WPCmd PEInfo indexlines} ppg] || $ppg <= 0} {
    set ppg $_wp(indexlines)
  } elseif {$ppg > $_wp(indexlinesmax)} {
    set ppg $_wp(indexlinesmax)
  }

  # look for image button clicks
  foreach item $browse_args {
    if {0 == [catch {cgi_import [lindex $item 0].x}]} {
      set [lindex $item 0] 1
    }
  }

  # preform actions specfied in browse_args
  # NOTE: basic stuff only to be executed in absense of JS
  if {[string length $pageFirst]} {
    set n 1
    set u [WPCmd PEMailbox uid 1]
  } elseif {[string length $pagePrev]} {
    if {$ppg >= $n} {
      set n 1
    } else {
      set n [expr {$n - $ppg}]
    }

    if {[catch {WPCmd PEMailbox uid $n} u]} {
      set u 0
    }
  } elseif {[string length $pageNext]} {
    if {($n + $ppg) <= $mc} {
      incr n $ppg
      if {[catch {WPCmd PEMailbox uid $n} u]} {
	set u 0
      }
    }
  } elseif {[string length $pageLast]} {
    set n $mc
    if {[catch {WPCmd PEMailbox uid $n} u]} {
      set u 0
    }
  } elseif {[string length $sort]} {
    switch $rev {
      0 -
      1 {
      }
      default {
	set rev [lindex $cursort 1]
      }
    }

    if {[catch {WPCmd PEMailbox sort $sort $rev} cursort]} {
      WPCmd PEInfo statmsg "Cannot set sort: $cursort"
      set cursort [list nonsense 0]
    } else {
      # store result 
      WPCmd set sort [list $sort $rev]
    }
  }

  # page framing
  if {[catch {
    set nm [WPCmd PEMailbox flagcount [list unseen undeleted]]
    set defcol [WPCmd PEFolder defaultcollection]
    wpInitPageFraming u n mc ppg pn pt
  }]} {
    set pn 1
    set pt 0
    set nm 0
    set defcol 0
  }

  cgi_http_head {
    WPStdHttpHdrs "text/html; charset=UTF-8"
  }

  cgi_html {
    cgi_head {
      #      WPStdHttpHdrs "text/html; charset=UTF-8"
      cgi_title [wpPageTitle "$f, $pn of $pt ($nm)"]
      cgi_base "href=$_wp(serverpath)/$_wp(appdir)/$_wp(ui2dir)/"
      cgi_stylesheet css/menu.css
      cgi_stylesheet css/cbn/screen.css
      cgi_stylesheet css/cbn/folderdialog.css
      cgi_stylesheet $_wp(yui)/build/container/assets/container-core.css
      cgi_stylesheet $_wp(yui)/build/menu/assets/skins/sam/menu.css
      cgi_stylesheet $_wp(yui)/build/button/assets/skins/sam/button.css
      # YahooUI libraries
      cgi_script type=text/javascript language="JavaScript" src="$_wp(yui)/build/utilities/utilities.js" {}
      cgi_script type=text/javascript language="JavaScript" src="$_wp(yui)/build/container/container-min.js" {}
      cgi_script type=text/javascript language="JavaScript" src="$_wp(yui)/build/datasource/datasource-min.js" {}
      cgi_script type=text/javascript language="JavaScript" src="$_wp(yui)/build/menu/menu-min.js" {}
      cgi_script type=text/javascript language="JavaScript" src="$_wp(yui)/build/button/button-min.js" {}
      # local libraries
      cgi_script type=text/javascript language="JavaScript" src="lib/common.js" {}
      cgi_script type=text/javascript language="JavaScript" src="lib/mailbox.js" {}
      # page specfic JS
      cgi_javascript {
	cgi_puts "YAHOO.alpine.cgi_root = '$_wp(serverpath)';"
	cgi_puts "YAHOO.alpine.app_root = '$_wp(serverpath)/$_wp(appdir)/$_wp(ui2dir)';"
	cgi_puts "YAHOO.alpine.current.c = $c;"
	cgi_puts "YAHOO.alpine.current.f = \"$f\";"
	cgi_puts "YAHOO.alpine.current.u = $u;"
	cgi_puts "YAHOO.alpine.current.page = $pn;"
	cgi_puts "YAHOO.alpine.current.count = $mc;"
	if {[catch {
	  set mb_sel [WPCmd PEMailbox selected]
	  set mb_srch [WPCmd PEMailbox searched]
	}]} {
	    set mb_sel 0
	    set mb_srch 0
	}
	
	cgi_puts "YAHOO.alpine.current.selected = $mb_sel;"
	cgi_puts "YAHOO.alpine.current.searched = $mb_srch;"
	cgi_puts "YAHOO.alpine.current.focused = $focused;"
	cgi_puts "function bodyOnLoad(){"
	cgi_puts " initMenus();"
	cgi_puts " initMorcButton('listMorcButton');"
	cgi_puts " initSelection();"
	cgi_puts " if(YAHOO.env.ua.gecko > 0){ sizeVPHeight(); window.onresize = resizeVPHeight; }"
	wpSetMessageListNewMailCheck
	wpStatusAndNewmailJavascript
	wpSaveMenuJavascript "browse" $c $f $defcol morcInBrowseDone
	cgi_puts " if(self.loadDDElements) loadDDElements();"

	if {[info exists authlist]} {
	  cgi_puts "YAHOO.alpine.resubmitRequest = function(){ window.location.href = 'browse/$c/$f'; };"
	  cgi_puts "YAHOO.alpine.cancelRequest = function(){ window.location.href = 'browse/0/INBOX'; };"
	  reportAuthException $authlist
	}
	cgi_puts "}"
	cgi_puts "browserDetect();"
      }
    }

    cgi_body class="wap" "onLoad=bodyOnLoad()" {
      cgi_division id="skip" {
	cgi_put [cgi_url "Skip to Next Page" "\#" "onClick=return newMessageList({control:this,parms:{op:'next'}});"]
	cgi_put [cgi_url "Skip to Folders" "folders"]
	cgi_put [cgi_url "Skip to Compose" "compose"]
      }

      cgi_division id=msgDragProxy {
	cgi_put "<b class=b1></b><b class=b2></b><b class=b3></b><b class=b4></b><div id=msgDragProxyText></div><b class=b4></b><b class=b3></b><b class=b2></b><b class=b1></b>"
      }

      if {$focused} {
	set context "Search Results in [cgi_quote_html $f]"
      } else {
	set context [cgi_quote_html $f]
      }
      wpCommonPageLayout browse $c $f $u $context [list [cgi_cgi "$_wp(appdir)/$_wp(ui2dir)/browse/${c}/${f}"] "$f" 1 mailboxSearch()] "" {
	cgi_division class=hdrBtns {
	  cgi_javascript {
	    cgi_put "if(window.print) document.write('[cgi_buffer {cgi_put [cgi_url "[cgi_span "class=sp hdrBtnImg hbi1" ""][cgi_span "class=hdrBtnText" Print]" "print" "onClick=return printContent()"]}]');"
	  }
	  cgi_put [cgi_url "[cgi_span "class=sp hdrBtnImg hbi2" ""][cgi_span "class=hdrBtnText" Settings]" "settings"]
	  cgi_put [cgi_url "[cgi_span "class=sp hdrBtnImg hbi3" ""][cgi_span "class=hdrBtnText" Help]" \# "onClick=return openMailboxHelp();" class=wap]
	  cgi_put [cgi_url "[cgi_span "class=sp hdrBtnImg hbi4" ""][cgi_span "class=hdrBtnText" "Sign out"]" "../../session/logout.tcl?cid=[WPCmd PEInfo key]&sessid=${sessid}"]
	}
      } {
	cgi_division id=listTopMenubar {
	  cgi_puts [WPCmd cgi_buffer "drawTopListMenuBar $c {$f}"]
	}
	cgi_division id=viewTopMenubar "style=\"display: none;\"" {
	  cgi_puts [WPCmd cgi_buffer "drawTopViewMenuBar $c {$f} $u $n"]
	}
      } {
	if {[info exists opening_folder]} {
	  cgi_puts "Opening $f..."
	} else {
	  cgi_puts [WPCmd cgi_buffer "drawMessageList $c {$f} $n $ppg"]
	}
      } {
	cgi_division id=listBottomMenubar {
	  cgi_puts [WPCmd cgi_buffer "drawBottomListMenuBar $c {$f} $pn $pt $mc"]
	}
	cgi_division id=viewBottomMenubar "style=\"display: none;\"" {
	  cgi_puts [WPCmd cgi_buffer "drawBottomViewMenuBar $c {$f} $u $n $mc"]
	}
      }

      foreach dmsg $dmsgs {
	cgi_html_comment "DEBUG: $dmsg"
	cgi_puts ""
      }
    }
  }
}