summaryrefslogtreecommitdiff
path: root/web/cgi/alpine/2.0/view
blob: 0466c2e24febaf2364c508a1ce9f91cee83fc201 (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
#!./tclsh
# $Id: view 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
#
# ========================================================================

#  view.tcl
#
#  Purpose:  CGI script generating page to display text of requested
#            message
#
#  Input:    PATH_INFO: [/<col_number>]/<folder_name>[/<uid_of_viewed_msg>
#            along with possible search parameters:
set view_args {
  {delete	{}	0}
  {spam		{}	0}
  {unread	{}	0}
  {star		{}	{}}
  {showimg	{}	{}}
  {hideimg	{}	{}}
  {searchText	{}	{}}
}


# On input failure, redirect to home page "browse"
proc view_redirect {} {
  global _wp

  cgi_http_head {
    cgi_redirect "[cgi_root]/$_wp(appdir)/$_wp(ui2dir)/browse"
  }
}

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

# 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 $view_args {
  # grok PATH_INFO for collection 'c' and folder 'f'
  if {[info exists env(PATH_INFO)] && [string length $env(PATH_INFO)]} {
    if {0 == [regexp {^/([0-9]+)/(.*)/([0-9]+)$} $env(PATH_INFO) dummy c f u]} {
      WPCmd PEInfo statmsg "Cannot open invalid path: $env(PATH_INFO)"
      error [list _redirect "[cgi_root]/$_wp(appdir)/$_wp(ui2dir)/browse/0/INBOX"]
    }
  } else {
    WPCmd PEInfo statmsg "Cannot view unspecified folder"
    error [list _redirect "[cgi_root]/$_wp(appdir)/$_wp(ui2dir)/browse/0/INBOX"]
  }

  # verify or visit specified collection/folder
  if {[catch {setCurrentFolder c f u} result]} {
    set authlist [wpHandleAuthException $result [list $c "folders in collection"] $f]
    if {0 == [llength $authlist]} {
      WPCmd PEInfo statmsg "$result"
      error [list _redirect "$_wp(serverpath)/$_wp(appdir)/$_wp(ui2dir)/browse/$c/$f"]
    }
  }

  # load message drawing routine for this session
  # save per-message source, proc overhead
  # to reinstall on the fly:
  #catch {WPCmd rename drawMessageText {}}
  if {0 == [llength [WPCmd info commands drawMessageText]]} {
    set cgidir [file join $_wp(cgipath) $_wp(appdir) $_wp(ui2dir)]
    if {[catch {
      WPCmd source "${cgidir}/messageview.tcl"
      WPCmd source "${cgidir}/messagelist.tcl"
    } result]} {
      error [list _action browse "cannot load message viewer: $result"]
    }
  }

  # process any actions specified by view_args
  if {$delete > 0} {
    if {0 == [catch [WPCmd PEMessage $delete number] dnum]} {
      
    }
    # ELSE already deleted, don't worry about it
  } elseif {$spam > 0} {
    if {0 == [catch [WPCmd PEMessage $spam number] snum]} {

    }
    # ELSE already reported, don't worry about it
  } elseif {$unread > 0} {
    if {[catch {WPCmd PEMessage $unread flag new 1} result]} {
      # ERROR: Cannot set $u unread
    }
  } elseif {[string length $star]} {
    switch -- $star {
      0 {
	if {[catch {WPCmd PEMessage $u flag important 0} result]} {
	  # ERROR: Cannot set Star on message $u
	}
      }
      1 {
	if {[catch {WPCmd PEMessage $u flag important 1} result]} {
	  # ERROR: Cannot set Star on message $u
	}
      }
      default {}
    }
  }

  if {[catch {WPCmd PEMessage $u charset} charset]
      || [string length $charset] == 0
      || [string compare us-ascii [string tolower $charset]] == 0} {
    set charset "ISO-8859-1"
  }

  if {[catch {WPCmd PEMessage $u number} n]} {
    WPCmd PEInfo statmsg "$n"
    error [list _redirect "$_wp(serverpath)/$_wp(appdir)/$_wp(ui2dir)/browse/$c/$f"]
  }

  cgi_http_head {
    WPStdHttpHdrs "text/html; charset=$charset"
  }

  # counts and so forth
  set mc [WPCmd PEMailbox messagecount]

  set unext [WPCmd PEMailbox uid [WPCmd PEMailbox next $n 1]]
  set delim [WPCmd PEFolder delimiter $c]


  cgi_html {
    cgi_head {
      cgi_content_type "text/html; charset=$charset"
      cgi_title [wpPageTitle "Message $n of $mc in $f"]
      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
      # Yahoo UI 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.count = $mc;"
	cgi_puts "YAHOO.alpine.current.selected = [WPCmd PEMailbox selected];"
	cgi_puts "YAHOO.alpine.current.searched = [WPCmd PEMailbox searched];"
	cgi_puts "YAHOO.alpine.current.focused = [WPCmd PEMailbox focus];"
	cgi_puts "function bodyOnLoad() {"
	cgi_puts " initMenus();"
	cgi_puts " initMorcButton('viewMorcButton');"
	cgi_puts " if(YAHOO.env.ua.gecko > 0){ sizeVPHeight(); window.onresize = resizeVPHeight; }"
	cgi_puts " setCheckMailFunction('gCheck', newMailCheck);"
	cgi_puts " setNewMailCheckInterval([WPCmd PEInfo inputtimeout]);"
	wpStatusAndNewmailJavascript
	wpSaveMenuJavascript "view" $c $f [WPCmd PEFolder defaultcollection] morcInViewDone
        cgi_puts "}"

	cgi_puts "browserDetect();"
      }
    }

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

      wpCommonPageLayout view $c $f $u [cgi_url "[cgi_quote_html $f], Message $n of $mc" browse/$c/[WPPercentQuote $f $delim] id=gBigContext] [list [cgi_cgi "$_wp(appdir)/$_wp(ui2dir)/browse/${c}/${f}?u=${u}"] "$f" 1 mailboxSearch()] {} {
	# CONTEXT COMMANDS
	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 "style=\"display: none;\"" {
	  cgi_puts [WPCmd cgi_buffer "drawTopListMenuBar $c {$f}"]
	}
	cgi_division id=viewTopMenubar {
	  cgi_puts [WPCmd cgi_buffer "drawTopViewMenuBar $c {$f} $u $n"]
	}
      } {
	cgi_puts [WPCmd cgi_buffer "drawMessageText $c {$f} $u $showimg"]
      } {
	cgi_division id=listBottomMenubar "style=\"display: none;\"" {
	  cgi_puts [WPCmd cgi_buffer "drawBottomListMenuBar $c {$f} 0 0 $mc"]
	}
	cgi_division id=viewBottomMenubar {
	  cgi_puts [WPCmd cgi_buffer "drawBottomViewMenuBar $c {$f} $u $n $mc"]
	}
      }

      # any debugging info to insert?
      foreach dmsg $dmsgs {
	cgi_html_comment "DEBUG: $dmsg"
	cgi_puts ""
      }
    }
  }
}