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

« back to all changes in this revision

Viewing changes to web/cgi/alpine/2.0/newview.tcl

  • Committer: Package Import Robot
  • Author(s): Asheesh Laroia
  • Date: 2013-05-19 16:15:01 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130519161501-epf6pfldn07xnd11
Tags: 2.10+dfsg-1
* New upstream release.
* This release ships a fix for an issue where the PREFDATETIME token
  was always set to "Sun" incorrectly. (Closes: #692870)
* This release ships a fix for IMAP-encoded non-ASCII folder names.
  (Closes: #674067)
* This release simplifies (and corrects) S/MIME handling for messages
  that encrypted *and* signed. (Closes: #653420)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!./tclsh
 
2
# $Id: newview.tcl 1266 2009-07-14 18:39:12Z hubert@u.washington.edu $
 
3
# ========================================================================
 
4
# Copyright 2008 University of Washington
 
5
#
 
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
 
9
#
 
10
#     http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
# ========================================================================
 
13
 
 
14
#  newview.tcl
 
15
#
 
16
#  Purpose:  CGI script that generates a page displaying a message
 
17
#            list of the indicated folder. 
 
18
#
 
19
#  Input:    PATH_INFO: [/<col_number>]/<folder_name>[/<uid_of_first_msg>
 
20
#            along with possible search parameters:
 
21
set newview_args {
 
22
  {op   {}      ""}
 
23
  {df   {}      ""}
 
24
  {img  {}      0}
 
25
  {page {}      ""}
 
26
}
 
27
 
 
28
# inherit global config
 
29
source ./alpine.tcl
 
30
source ./common.tcl
 
31
source ./foldercache.tcl
 
32
 
 
33
# default newview state
 
34
set showimg ""
 
35
 
 
36
# TEST
 
37
proc cgi_suffix {args} {
 
38
  return ""
 
39
}
 
40
 
 
41
proc next_message {_n _u {i 1}} {
 
42
  upvar 1 $_n n
 
43
  upvar 1 $_u u
 
44
 
 
45
  if {[catch {WPCmd PEMailbox next $n $i} nnext]} {
 
46
    WPCmd PEInfo statmsg "Cannot get next message: $nnext"
 
47
  } else {
 
48
    set n $nnext
 
49
    if {[catch {WPCmd PEMailbox uid $n} u]} {
 
50
      WPCmd PEInfo statmsg "Message $nnext has no UID: $u"
 
51
      set n 0
 
52
      set u 0
 
53
    }
 
54
  }
 
55
}
 
56
 
 
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"
 
63
      set deadsession 1
 
64
    } else {
 
65
      # grok parameters
 
66
      foreach item $newview_args {
 
67
        if {[catch {eval WPImport $item} result]} {
 
68
          set harderr "Cannot read input: $result"
 
69
          break;
 
70
        }
 
71
      }
 
72
 
 
73
      if {[catch {WPCmd PEMessage $u number} n]} {
 
74
        set harderr "Message no longer exists in $f"
 
75
      }
 
76
    }
 
77
  } else {
 
78
    set harderr "Invalid path: $env(PATH_INFO)"
 
79
    set nofolder 1
 
80
  }
 
81
} else {
 
82
  set harderr "No Folder Specified!"
 
83
  set nofolder 1
 
84
}
 
85
 
 
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."
 
90
  } else {
 
91
    catch { WPCmd PEInfo statmsg "$harderr" }
 
92
    unset harderr
 
93
 
 
94
    if {[info exists nofolder]} {
 
95
      set env(PATH_INFO) "/0/INBOX"
 
96
    } else {
 
97
      set env(PATH_INFO) "/${c}/${f}"
 
98
    }
 
99
 
 
100
    source newlist.tcl
 
101
  }
 
102
 
 
103
  exit
 
104
}
 
105
 
 
106
cgi_puts "Content-type: text/html; charset=\"UTF-8\"\n"
 
107
 
 
108
if {[catch {WPCmd PEMessage $u number} n]} {
 
109
  WPCmd PEInfo statmsg "Message access error: $n"
 
110
  set n 0
 
111
} else {
 
112
  switch -regexp -- $op {
 
113
    ^next$ {
 
114
      next_message n u
 
115
    }
 
116
    ^prev$ {
 
117
      next_message n u -1
 
118
    }
 
119
    ^hdron$ {
 
120
      WPCmd PEInfo mode full-header-mode 2
 
121
    }
 
122
    ^hdroff$ {
 
123
      WPCmd PEInfo mode full-header-mode 0
 
124
    }
 
125
    ^unread$ {
 
126
      if {[catch {WPCmd PEMessage $u flag new 1} result]} {
 
127
        WPCmd PEInfo statmsg "Delete of $u failed: $result"
 
128
      } else {
 
129
        next_message n u
 
130
      }
 
131
    }
 
132
    ^delete$ {
 
133
      if {[catch {WPCmd PEMessage $u flag deleted 1} result]} {
 
134
        WPCmd PEInfo statmsg "Delete of $u failed: $result"
 
135
      } else {
 
136
        WPCmd PEInfo statmsg "Message moved to Trash"
 
137
        if {$n == 1} {
 
138
          next_message n u
 
139
          set n 1
 
140
        } elseif {$n == [WPCmd PEMailbox messagecount]} {
 
141
          next_message n u -1
 
142
        } else {
 
143
          set nnext $n
 
144
          next_message n u
 
145
          set n $nnext
 
146
        }
 
147
      }
 
148
    }
 
149
    ^trash$ {
 
150
      if {[catch {WPCmd PEFolder empty $c [wpLiteralFolder $c $f] $u} result]} {
 
151
        WPCmd PEInfo statmsg "Cannot delete forever: $result"
 
152
      } else {
 
153
        WPCmd PEInfo statmsg "Message deleted forever"
 
154
        set mc [WPCmd PEMailbox messagecount]
 
155
        if {$mc == 0} {
 
156
          set n 0
 
157
          set u 0
 
158
        } else {
 
159
          if {$n > $mc} {
 
160
            set n $mc
 
161
          }
 
162
 
 
163
          if {[catch {WPCmd PEMailbox uid $n} u]} {
 
164
            WPCmd PEInfo statmsg "Cannot get UID of $n: $u"
 
165
            set n 0
 
166
            set u 0
 
167
          }
 
168
        }
 
169
      }
 
170
    }
 
171
    ^move$ -
 
172
    ^copy$ {
 
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"
 
176
        } else {
 
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"
 
183
              } else {
 
184
                set mc [WPCmd PEMailbox messagecount]
 
185
                if {$mc == 0} {
 
186
                  set n 0
 
187
                  set u 0
 
188
                } else {
 
189
                  if {$n > $mc} {
 
190
                    set n $mc
 
191
                  }
 
192
 
 
193
                  if {[catch {WPCmd PEMailbox uid $n} u]} {
 
194
                    WPCmd PEInfo statmsg "Cannot get UID of $n: $u"
 
195
                    set n 0
 
196
                    set u 0
 
197
                  }
 
198
                }
 
199
              }
 
200
            } else {
 
201
              if {[catch {WPCmd PEMailbox expunge} blasted] || [string length $blasted]} {
 
202
                WPCmd PEInfo statmsg "Move Problem: $blasted"
 
203
              }
 
204
 
 
205
              next_message n u
 
206
            }
 
207
          }
 
208
 
 
209
          # feedback from alpined
 
210
          if {[string compare -nocase inbox $dfn]} {
 
211
            addSaveCache $dfn
 
212
            set savecachechange $dfn
 
213
          }
 
214
        }
 
215
      } else {
 
216
        WPCmd PEInfo statmsg "Cannot $op to $df"
 
217
      }
 
218
    }
 
219
    ^spam$ {
 
220
      if {[info exists _wp(spamsubj)]} {
 
221
        set spamsubj $_wp(spamsubj)
 
222
      } else {
 
223
        set spamsubj "Spam Report"
 
224
      }
 
225
 
 
226
      if {[info exists _wp(spamfolder)] && [string length $_wp(spamfolder)]
 
227
          && [catch {
 
228
            set defc [WPCmd PEFolder defaultcollection]
 
229
            if {[WPCmd PEFolder exists $defc $_wp(spamfolder)] == 0} {
 
230
              WPCmd PEFolder create $defc $_wp(spamfolder)
 
231
            }
 
232
 
 
233
            WPCmd PEMessage $u save $defc $_wp(spamfolder)
 
234
          } result]} {
 
235
        WPCmd PEInfo statmsg "Error spamifying message $message: $result"
 
236
 
 
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"
 
242
      } else {
 
243
        WPCmd PEInfo statmsg "Message $n reported as Spam and flagged for deletion"
 
244
        if {$n == 1} {
 
245
          next_message n u
 
246
          set n 1
 
247
        } elseif {$n == [WPCmd PEMailbox messagecount]} {
 
248
          next_message n u -1
 
249
        } else {
 
250
          set nnext $n
 
251
          next_message n u
 
252
          set n $nnext
 
253
        }
 
254
      }
 
255
    }
 
256
    ^$ -
 
257
    ^noop$ {
 
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]} {
 
262
        set showimg $img
 
263
      }
 
264
    }
 
265
    default {
 
266
      WPCmd PEInfo statmsg "Unrecognized option: $op"
 
267
    }
 
268
  }
 
269
}
 
270
 
 
271
if {$n > 0} {
 
272
  cgi_puts [WPCmd cgi_buffer "drawMessageText $c {$f} $u $showimg"]
 
273
  cgi_puts "<script>"
 
274
  if {0 == [catch {WPCmd PEMessage $u needpasswd}]} {
 
275
    cgi_put "getSmimePassphrase({sessid:'$_wp(sessid)',control:this,parms:{op:'noop',page:'new'}});"
 
276
  }
 
277
  if {[catch {WPCmd PEMailbox next $n 1} nnext]} {
 
278
    WPCmd PEInfo statmsg "Cannot get next message: $nnext"
 
279
  } else {
 
280
    if {[catch {WPCmd PEMailbox uid $nnext} unext]} {
 
281
      WPCmd PEInfo statmsg "Message $nnext has no UID: $unext"
 
282
      set unext 0
 
283
    }
 
284
  }
 
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
 
291
  }
 
292
  if {[info exists savecachechange]} {
 
293
    wpSaveMenuJavascript "view" $c $f [WPCmd PEFolder defaultcollection] morcInViewDone $savecachechange
 
294
  }
 
295
 
 
296
  cgi_puts "document.getElementById('alpineContent').scrollTop = 0;"
 
297
  wpStatusAndNewmailJavascript
 
298
  cgi_puts "setCheckMailFunction('gCheck', newMailCheck);"
 
299
  cgi_puts "setNewMailCheckInterval([WPCmd PEInfo inputtimeout]);"
 
300
  cgi_puts "</script>"
 
301
} else {
 
302
  cgi_puts "<script>"
 
303
  cgi_puts "updateViewLinksAndSuch({});"
 
304
  wpStatusAndNewmailJavascript
 
305
  cgi_puts "</script>"
 
306
}