2
# $Id: newview.tcl 1266 2009-07-14 18:39:12Z hubert@u.washington.edu $
3
# ========================================================================
4
# Copyright 2008 University of Washington
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# ========================================================================
16
# Purpose: CGI script that generates a page displaying a message
17
# list of the indicated folder.
19
# Input: PATH_INFO: [/<col_number>]/<folder_name>[/<uid_of_first_msg>
20
# along with possible search parameters:
28
# inherit global config
31
source ./foldercache.tcl
33
# default newview state
37
proc cgi_suffix {args} {
41
proc next_message {_n _u {i 1}} {
45
if {[catch {WPCmd PEMailbox next $n $i} nnext]} {
46
WPCmd PEInfo statmsg "Cannot get next message: $nnext"
49
if {[catch {WPCmd PEMailbox uid $n} u]} {
50
WPCmd PEInfo statmsg "Message $nnext has no UID: $u"
57
# grok PATH_INFO for collection 'c' and folder 'f'
58
if {[info exists env(PATH_INFO)] && [string length $env(PATH_INFO)]} {
59
if {[regexp {^/([0-9]+)/(.*)/([0-9]+)$} $env(PATH_INFO) dummy c f u]} {
60
# Import data validate it and get session id
61
if {[catch {WPGetInputAndID sessid} result]} {
62
set harderr "Invalid Session: $result"
66
foreach item $newview_args {
67
if {[catch {eval WPImport $item} result]} {
68
set harderr "Cannot read input: $result"
73
if {[catch {WPCmd PEMessage $u number} n]} {
74
set harderr "Message no longer exists in $f"
78
set harderr "Invalid path: $env(PATH_INFO)"
82
set harderr "No Folder Specified!"
86
if {[info exists harderr]} {
87
if {[info exists deadsession]} {
88
cgi_puts "Content-type: text/html; charset=\"UTF-8\"\n"
89
cgi_puts "Your Web Alpine Session has been closed."
91
catch { WPCmd PEInfo statmsg "$harderr" }
94
if {[info exists nofolder]} {
95
set env(PATH_INFO) "/0/INBOX"
97
set env(PATH_INFO) "/${c}/${f}"
106
cgi_puts "Content-type: text/html; charset=\"UTF-8\"\n"
108
if {[catch {WPCmd PEMessage $u number} n]} {
109
WPCmd PEInfo statmsg "Message access error: $n"
112
switch -regexp -- $op {
120
WPCmd PEInfo mode full-header-mode 2
123
WPCmd PEInfo mode full-header-mode 0
126
if {[catch {WPCmd PEMessage $u flag new 1} result]} {
127
WPCmd PEInfo statmsg "Delete of $u failed: $result"
133
if {[catch {WPCmd PEMessage $u flag deleted 1} result]} {
134
WPCmd PEInfo statmsg "Delete of $u failed: $result"
136
WPCmd PEInfo statmsg "Message moved to Trash"
140
} elseif {$n == [WPCmd PEMailbox messagecount]} {
150
if {[catch {WPCmd PEFolder empty $c [wpLiteralFolder $c $f] $u} result]} {
151
WPCmd PEInfo statmsg "Cannot delete forever: $result"
153
WPCmd PEInfo statmsg "Message deleted forever"
154
set mc [WPCmd PEMailbox messagecount]
163
if {[catch {WPCmd PEMailbox uid $n} u]} {
164
WPCmd PEInfo statmsg "Cannot get UID of $n: $u"
173
if {[string length $df] && [regexp {^([0-9]+)/(.*)$} $df dummy dfc dfn] && [string length $dfn]} {
174
if {[catch {WPCmd PEMessage $u $op $dfc [wpLiteralFolder $dfc $dfn]} result]} {
175
WPCmd PEInfo statmsg "Cannot $op message $n: $result"
177
if {0 == [string compare $op move]} {
178
if {$c == [WPCmd PEFolder defaultcollection]
179
&& (([info exists _wp(spamfolder)] && 0 == [string compare $f $_wp(spamfolder)])
180
|| 0 == [string compare $f Trash])} {
181
if {[catch {WPCmd PEFolder empty $c $f $u} result]} {
182
WPCmd PEInfo statmsg "Cannot empty Trash: $result"
184
set mc [WPCmd PEMailbox messagecount]
193
if {[catch {WPCmd PEMailbox uid $n} u]} {
194
WPCmd PEInfo statmsg "Cannot get UID of $n: $u"
201
if {[catch {WPCmd PEMailbox expunge} blasted] || [string length $blasted]} {
202
WPCmd PEInfo statmsg "Move Problem: $blasted"
209
# feedback from alpined
210
if {[string compare -nocase inbox $dfn]} {
212
set savecachechange $dfn
216
WPCmd PEInfo statmsg "Cannot $op to $df"
220
if {[info exists _wp(spamsubj)]} {
221
set spamsubj $_wp(spamsubj)
223
set spamsubj "Spam Report"
226
if {[info exists _wp(spamfolder)] && [string length $_wp(spamfolder)]
228
set defc [WPCmd PEFolder defaultcollection]
229
if {[WPCmd PEFolder exists $defc $_wp(spamfolder)] == 0} {
230
WPCmd PEFolder create $defc $_wp(spamfolder)
233
WPCmd PEMessage $u save $defc $_wp(spamfolder)
235
WPCmd PEInfo statmsg "Error spamifying message $message: $result"
237
} elseif {[info exists _wp(spamaddr)] && [string length $_wp(spamaddr)]
238
&& [catch {WPCmd PEMessage $u spam $_wp(spamaddr) $spamsubj} result]} {
239
WPCmd PEInfo statmsg "Can't Report Spam: $result"
240
} elseif {[catch {WPCmd PEMessage $u flag deleted 1} result]} {
241
WPCmd PEInfo statmsg "Error spamifying message $message: $result"
243
WPCmd PEInfo statmsg "Message $n reported as Spam and flagged for deletion"
247
} elseif {$n == [WPCmd PEMailbox messagecount]} {
258
# $img == 0 : remove current from from allow_cid_images list
259
# $img == 1 : allow images for this message this once
260
# $img == "from" : always allow images from this address
261
if {[regexp {0|1|from} $img]} {
266
WPCmd PEInfo statmsg "Unrecognized option: $op"
272
cgi_puts [WPCmd cgi_buffer "drawMessageText $c {$f} $u $showimg"]
274
if {0 == [catch {WPCmd PEMessage $u needpasswd}]} {
275
cgi_put "getSmimePassphrase({sessid:'$_wp(sessid)',control:this,parms:{op:'noop',page:'new'}});"
277
if {[catch {WPCmd PEMailbox next $n 1} nnext]} {
278
WPCmd PEInfo statmsg "Cannot get next message: $nnext"
280
if {[catch {WPCmd PEMailbox uid $nnext} unext]} {
281
WPCmd PEInfo statmsg "Message $nnext has no UID: $unext"
285
cgi_puts "updateViewLinksAndSuch(\{u:$u,n:$n,unext:$unext,unread:[WPCmd PEMailbox flagcount [list unseen undeleted]],count:[WPCmd PEMailbox messagecount],selected:[WPCmd PEMailbox selected]\});"
286
if {0 == [string compare new $page]} {
287
cgi_puts "showViewMenus();"
288
cgi_puts "initMenus();"
289
cgi_puts "initMorcButton('viewMorcButton');"
290
wpSaveMenuJavascript "view" $c $f [WPCmd PEFolder defaultcollection] morcInViewDone
292
if {[info exists savecachechange]} {
293
wpSaveMenuJavascript "view" $c $f [WPCmd PEFolder defaultcollection] morcInViewDone $savecachechange
296
cgi_puts "document.getElementById('alpineContent').scrollTop = 0;"
297
wpStatusAndNewmailJavascript
298
cgi_puts "setCheckMailFunction('gCheck', newMailCheck);"
299
cgi_puts "setNewMailCheckInterval([WPCmd PEInfo inputtimeout]);"
303
cgi_puts "updateViewLinksAndSuch({});"
304
wpStatusAndNewmailJavascript