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

« back to all changes in this revision

Viewing changes to web/cgi/alpine/post.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: post.tcl 391 2007-01-25 03:53:59Z mikes@u.washington.edu $
 
2
# ========================================================================
 
3
# Copyright 2006 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
#  post.tcl
 
14
#
 
15
#  Purpose:  CGI script to perform message posting via compose.tcl
 
16
#            generated form
 
17
 
 
18
#  Input: 
 
19
set post_vars {
 
20
  {cid          "Missing Command ID"}
 
21
  {action       {}      ""}
 
22
  {send         {}      0}
 
23
  {postpone     {}      0}
 
24
  {cancel       {}      0}
 
25
  {check        {}      0}
 
26
  {br_to        {}      0}
 
27
  {br_cc        {}      0}
 
28
  {br_bcc       {}      0}
 
29
  {br_reply_to  {}      0}
 
30
  {br_fcc       {}      0}
 
31
  {ex_to        {}      ""}
 
32
  {ex_cc        {}      ""}
 
33
  {ex_bcc       {}      ""}
 
34
  {ex_reply_to  {}      ""}
 
35
  {sendop       {}      ""}
 
36
  {queryattach  {}      0}
 
37
  {attach       {}      0}
 
38
  {detach       {}      0}
 
39
  {extrahdrs    {}      ""}
 
40
  {help         {}      ""}
 
41
  {postpost     {}      "main.tcl"}
 
42
  {fccattach    {}      0}
 
43
  {form_charset {}      ""}
 
44
  {form_flowed  {}      ""}
 
45
}
 
46
 
 
47
# NOT Input
 
48
catch {
 
49
  unset src
 
50
}
 
51
 
 
52
#  Output: 
 
53
#
 
54
 
 
55
proc fieldname {name} {
 
56
  regsub -all -- {-} [string tolower $name] {_} fieldname
 
57
  return $fieldname
 
58
}
 
59
 
 
60
proc expand_address_field {field _msgdata} {
 
61
  upvar 1 $_msgdata msgdata
 
62
 
 
63
  set fn [fieldname $field]
 
64
  for {set i 0} {$i < [llength $msgdata]} {incr i} {
 
65
    if {[string length [lindex [lindex $msgdata $i] 1]]} {
 
66
      set fld [lindex $msgdata $i]
 
67
      if {[string compare [fieldname [lindex $fld 0]] $fn] == 0} {
 
68
        if {[catch {WPCmd PEAddress expand [lindex $fld 1] fcc} expaddr]} {
 
69
          WPCmd PEInfo statmsg "Can't expand $field: $expaddr"
 
70
        } else {
 
71
          if {[lindex $expaddr 1] != 0} {
 
72
            if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
73
              # addresses and ldapaddrs should be set at this point
 
74
              upvar 1 addresses a
 
75
              upvar 1 ldapquery l
 
76
              upvar 1 field f
 
77
              set a [lindex $expaddr 0]
 
78
              set l [lindex $expaddr 1]
 
79
              set f $fn
 
80
              return 1
 
81
            } else {
 
82
              # else fall thru back into composer
 
83
              WPCmd PEInfo statmsg "Compose Error: $errstr"
 
84
              break
 
85
            }
 
86
          } elseif {[string compare [lindex $expaddr 0] [lindex $fld 1]]} {
 
87
            set msgdata [lreplace $msgdata $i $i [list [lindex $fld 0] [lindex $expaddr 0]]]
 
88
 
 
89
            # set fcc?
 
90
            set fccfn [lindex $expaddr 2]
 
91
            if {[string compare to [string tolower $fn]] == 0 && [string length $fccfn]} {
 
92
              for {set j 0} {$j < [llength $msgdata]} {incr j} {
 
93
                if {[string compare fcc [fieldname [lindex [lindex $msgdata $j] 0]]] == 0} {
 
94
                  set fcc_index $j
 
95
                  break
 
96
                }
 
97
              }
 
98
 
 
99
              set savedef [WPTFSaveDefault 0]
 
100
              set colid [lindex $savedef 0]
 
101
              if {[info exists fcc_index]} {
 
102
                if {[string compare $fccfn [lindex [lindex [lindex $msgdata $fcc_index] 1] 1]]} {
 
103
                  lappend msgdata [list postoption [list fcc-set-by-addrbook 1]]
 
104
                }
 
105
 
 
106
                set msgdata [lreplace $msgdata $fcc_index $fcc_index [list Fcc [list $colid $fccfn]]]
 
107
              } else {
 
108
                lappend msgdata [list Fcc [list $colid $fccfn]]
 
109
                lappend msgdata [list postoption [list fcc-set-by-addrbook 1]]
 
110
              }
 
111
 
 
112
              set has_fcc 1
 
113
            }
 
114
          }
 
115
        }
 
116
      }
 
117
    }
 
118
  }
 
119
 
 
120
  return 0
 
121
}
 
122
 
 
123
proc chartest_value {entity} {
 
124
  global _cgi
 
125
 
 
126
  if {[catch {cgi_import_as ke_${entity} tc}] == 0} {
 
127
    set tcval ""
 
128
    if {[set j [string length $tc]]} {
 
129
      for {set i 0} {$i < $j} {incr i} {
 
130
        binary scan [string index $tc $i] c x
 
131
        set x [expr ($x & 0xff)]
 
132
        lappend tcval [format {%o} $x]
 
133
      }
 
134
    }
 
135
 
 
136
    return $tcval
 
137
  } else {
 
138
    error "Unset testchar_$entity"
 
139
  }
 
140
}
 
141
 
 
142
## read vars
 
143
foreach item $post_vars {
 
144
  if {[catch {cgi_import [lindex $item 0].x}]} {
 
145
    if {[catch {eval WPImport $item} errstr]} {
 
146
      error [list _action "Impart Variable" $errstr]
 
147
    }
 
148
  } else {
 
149
    set [lindex $item 0] 1
 
150
  }
 
151
}
 
152
 
 
153
if {$cid != [WPCmd PEInfo key]} {
 
154
  error [list _action Postpone "Invalid Operation ID" "Click Back button to try again."]
 
155
}
 
156
 
 
157
# collect message data
 
158
 
 
159
# For now the input headers have to match the postheaders
 
160
# list.  Any outside the list are ignored (and probably should
 
161
# be to avoid hostile input).  Note, postheaders is a
 
162
# super-set of composeheaders as not all headers are meant
 
163
# to be shown the user for composition
 
164
if {[catch {WPCmd PECompose userhdrs} headers]} {
 
165
  error [list _action "User Headers" $headers "Click browser's Back button to try again."]
 
166
}
 
167
 
 
168
if {[catch {WPCmd PECompose syshdrs} otherhdrs]} {
 
169
  error [list _action "System Headers" $otherhdrs "Click browser's Back button to try again."]
 
170
} else {
 
171
  eval "lappend headers $otherhdrs"
 
172
}
 
173
 
 
174
foreach field $headers {
 
175
  set hdr [string tolower [lindex $field 0]]
 
176
  regsub -all -- {-} $hdr {_} hdr
 
177
  WPLoadCGIVarAs $hdr val
 
178
  switch -- $hdr {
 
179
    attach {
 
180
      # disregard: u/i convenience (attachments marshalled below)
 
181
    }
 
182
    fcc {
 
183
      if {[string length $val]} {
 
184
        WPLoadCGIVar colid
 
185
        lappend msgdata [list Fcc [list $colid $val]]
 
186
        set has_fcc 1
 
187
      }
 
188
    }
 
189
    default {
 
190
      if {[string length $val] || [lsearch -exact {subject} $hdr] >= 0} {
 
191
        set hdrvals($hdr) $val
 
192
        lappend msgdata [list [lindex $field 0] $val]
 
193
        if {[lsearch -exact {to cc bcc} $hdr] >= 0} {
 
194
          set has_$hdr 1
 
195
        }
 
196
      }
 
197
    }
 
198
  }
 
199
}
 
200
 
 
201
if {[info exists env(REMOTE_ADDR)]} {
 
202
  lappend msgdata [list x-auth-received "from \[$env(REMOTE_ADDR)\] by [info hostname] via HTTP; [clock format [clock seconds] -format "%a, %d %b %Y %H:%M:%S %Z"]"]
 
203
}
 
204
 
 
205
if {[catch {cgi_import attachments}] == 0} {
 
206
  foreach id [split $attachments ","] {
 
207
    lappend msgdata [list attach $id]
 
208
  }
 
209
}
 
210
 
 
211
WPLoadCGIVar body
 
212
lappend msgdata [list body [split $body "\n"]]
 
213
 
 
214
 
 
215
switch -exact -- $fccattach {
 
216
  0 -
 
217
  1 {
 
218
    lappend msgdata [list postoption [list fcc-without-attachments [expr {!$fccattach}]]]
 
219
  }
 
220
}
 
221
 
 
222
# pass on form's charset?
 
223
# TURNED OFF since all compose form interaction BETTER be UTF-8
 
224
if {0 && [string length $form_charset]} {
 
225
  # messy charset heuristics
 
226
  # idea is to look for planted HTML entities and see if known
 
227
  # encoding transliterations have occured. inspired by:
 
228
  # <http://www.cs.tut.fi/~jkorpela/chars.html#encinfo>
 
229
 
 
230
  # test for:
 
231
  #  entity        values
 
232
  # euro (#8364)
 
233
  # cyrillic shcha (#1060)
 
234
  # iso-8859-15 (Latin0): euro IS 200
 
235
  # iso-8859-1 (Latin1): thorn IS 376 or U+C3BE BUT NOT &#8220; &#254; OR &thorn;
 
236
  # Unicode literal full width yen: U+FFE5 IS 215F (ISO-2022-JP), A1EF (EUC-JP), or 818F (Shift-JIS) and so on
 
237
 
 
238
  # remember, the first element of each group MUST appear in compose.tcl, too
 
239
  set cstests {}
 
240
  set xcstests {
 
241
    {#8364      {{{40 254} ISO-10646} {{342 202 254} UTF-8} {244 ISO-8859-15} {325 IBM-850}} {}}
 
242
    {#1066      {{{377} KOI8-R} {312 ISO-8859-5}} {}}
 
243
    {thorn      {{376 ISO-8859-1}} {{303 276} UTF-8} {iso-8859-1 {{46 43 70 62 62 60 73} {46 43 62 65 64 73} {46 164 150 157 162 156 73}}}}
 
244
    {tcedil     {{376 ISO-8859-2}} {{46 164 143 145 144 151 154 73}}}
 
245
    {#65509     {{{302 245} UTF-8} {{241 315} EUC-KR} {{243 244} GB2312} {{242 104} BIG5} {{241 357} EUC-JP} {{201 217} Shift-JIS} {{33 44 102 41 157 33 50 102} ISO-2022-JP}} {}}
 
246
  }
 
247
 
 
248
  catch {unset test_charset}
 
249
  foreach cs $cstests {
 
250
    # asked for test entity available?
 
251
    if {[catch {chartest_value [lindex $cs 0]} ctest] == 0} {
 
252
      # test for positive [re]encoding assertions
 
253
      foreach testpos [lindex $cs 1] {
 
254
        if {[regexp "^[lindex $testpos 0]\$" $ctest]} {
 
255
          set test_charset [lindex $testpos 1]
 
256
          break
 
257
        }
 
258
      }
 
259
 
 
260
      if {![info exists test_charset]} {
 
261
        set csneg [lindex [lindex $cs 2] 0]
 
262
        foreach testneg [lindex [lindex $cs 2] 1] {
 
263
          if {[regexp "^$testneg\$" $ctest]} {
 
264
            if {[info exists form_charset]
 
265
                && [string compare [string tolower $form_charset] $csneg] == 0} {
 
266
              unset form_charset
 
267
              break
 
268
            }
 
269
          }
 
270
        }
 
271
      } else {
 
272
        break
 
273
      }
 
274
    }
 
275
  }
 
276
 
 
277
  if {[info exists test_charset]} {
 
278
    lappend msgdata [list postoption [list charset $test_charset]]
 
279
  } elseif {[info exists form_charset]} {
 
280
    lappend msgdata [list postoption [list charset $form_charset]]
 
281
  } else {
 
282
    lappend msgdata [list postoption [list charset "X-UNKNOWN"]]
 
283
  }
 
284
} else {
 
285
  lappend msgdata [list postoption [list charset "UTF-8"]]
 
286
}
 
287
 
 
288
# pass on text fomat=flowed?
 
289
if {[string length $form_flowed]} {
 
290
  lappend msgdata [list postoption [list flowed yes]]
 
291
}
 
292
 
 
293
# figure out what to do with data
 
294
if {[string compare OK [string trim $action]] == 0 && ($send || [string compare $sendop send] == 0)} {
 
295
  if {[info exists has_to] || [info exists has_cc] || [info exists has_bcc] || [info exists has_fcc]} {
 
296
    # expand any nicknames
 
297
    if {[catch {
 
298
      for {set i 0} {$i < [llength $msgdata]} {incr i} {
 
299
        if {[string length [lindex [lindex $msgdata $i] 1]]} {
 
300
          set fld [lindex $msgdata $i]
 
301
          set fn [string tolower [lindex $fld 0]]
 
302
          switch -- $fn {
 
303
            [Ff]cc {
 
304
              if {[string length [lindex [lindex $fld 1] 1]]} {
 
305
                # setup for send confirmation
 
306
                set colidval [lindex [lindex $fld 1] 0]
 
307
                set fccval [lindex [lindex $fld 1] 1]
 
308
              }
 
309
            }
 
310
            to -
 
311
            cc -
 
312
            bcc -
 
313
            reply-to {
 
314
              set expaddr [WPCmd PEAddress expand [lindex $fld 1] {}]
 
315
              if {[string compare [lindex $expaddr 0] [lindex $fld 1]]} {
 
316
                set msgdata [lreplace $msgdata $i $i [list [lindex $fld 0] [lindex $expaddr 0]]]
 
317
 
 
318
                # if expanded, update fcc?
 
319
                if {[string compare to $fn] == 0 && [string length $fn]} {
 
320
                  set expanded_fcc [lindex $expaddr 2]
 
321
                }
 
322
              }
 
323
            }
 
324
            body {
 
325
              if {[string length $form_flowed]} {
 
326
                set ws "\[ \t]"
 
327
                set nws "\[^ \t]"
 
328
 
 
329
                set nextline [lindex [lindex $fld 1] 0]
 
330
                for {set j 1} {$j <= [llength [lindex $fld 1]]} {incr j} {
 
331
                  set line $nextline
 
332
                  # space stuff?
 
333
                  if {[regexp "^${ws}+" $line]} {
 
334
                    set line " $line"
 
335
                  }
 
336
 
 
337
                  set nextline [lindex [lindex $fld 1] $j]
 
338
                  if {[regexp {^-- $} $line] == 0} {
 
339
                    catch {unset linetext}
 
340
                    # trim trailing WS from lines preceding those with LWS (space-stuff as needed)
 
341
                    if {[string length $nextline] == 0 || [regexp "^${ws}+(${nws}?.*)\$" $nextline dummy linetext]} {
 
342
                      set line [string trimright $line]
 
343
                      if {[info exists linetext] == 0 || [string length $linetext] == 0} {
 
344
                        set nextline ""
 
345
                      }
 
346
                    }
 
347
 
 
348
                    # break overly long lines in a flowed way
 
349
                    if {[regexp {^[^>]} $line] && [string length $line] > 1000} {
 
350
                      while {[regexp "^(${ws}*${nws}+${ws}+)$nws" [string range $line 900 end] dummy linex]} {
 
351
                        set cliplen [expr {900 + [string length $linex]}]
 
352
                        lappend newbody [string range $line 0 [expr {$cliplen - 1}]]
 
353
                        set line [string range $line $cliplen end]
 
354
                      }
 
355
                    }
 
356
                  }
 
357
 
 
358
                  lappend newbody $line
 
359
                }
 
360
 
 
361
                set msgdata [lreplace $msgdata $i $i [list body $newbody]]
 
362
              }
 
363
            }
 
364
            default {
 
365
            }
 
366
          }
 
367
        }
 
368
      }
 
369
    } result]} {
 
370
      WPCmd PEInfo statmsg "Address problem: $result"
 
371
    } else {
 
372
      # update fcc?
 
373
      if {[info exists expanded_fcc]} {
 
374
        for {set j 0} {$j < [llength $msgdata]} {incr j} {
 
375
          if {[string compare fcc [fieldname [lindex [lindex $msgdata $j] 0]]] == 0} {
 
376
            set fcc_index $j
 
377
            break
 
378
          }
 
379
        }
 
380
 
 
381
        set savedef [WPTFSaveDefault 0]
 
382
        set colid [lindex $savedef 0]
 
383
        if {[info exists fcc_index]} {
 
384
          set msgdata [lreplace $msgdata $fcc_index $fcc_index [list Fcc [list $colid $expanded_fcc]]]
 
385
        } else {
 
386
          lappend msgdata [list Fcc [list $colid $expanded_fcc]]
 
387
        }
 
388
      }
 
389
 
 
390
      # do the sending...
 
391
      set verb Send
 
392
      set verbpast Sent
 
393
      set postcmd PECompose
 
394
      set postcmdopt post
 
395
    }
 
396
  } else {
 
397
    WPCmd PEInfo statmsg "Send MUST include Recipients (To, Cc, Bcc, or Fcc)"
 
398
  }
 
399
} elseif {[string compare OK [string trim $action]] == 0 && ($postpone || [string compare $sendop postpone] == 0)} {
 
400
  set verb Postpone
 
401
  set verbpast Postponed
 
402
  set postcmd PEPostpone
 
403
  set postcmdopt append
 
404
} elseif {$help == 1 || [string compare "get help" [string tolower $help]] == 0} {
 
405
  # save msgdata to servlet
 
406
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
407
    # fake cgi input for script
 
408
    _cgi_set_uservar oncancel "compose&restore=1"
 
409
    set src help
 
410
  } else {
 
411
    # else fall thru back into composer
 
412
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
413
  }
 
414
} elseif {$check == 1 || [string compare spell [string tolower [string range $check 0 4]]] == 0} {
 
415
  # save msgdata to servlet
 
416
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
417
    set src spell
 
418
  } else {
 
419
    # else fall thru back into composer
 
420
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
421
  }
 
422
} elseif {$queryattach == 1 || [string compare "add attachment" [string tolower $queryattach]] == 0 || [string compare "attach" [string tolower $queryattach]] == 0} {
 
423
  # save msgdata to servlet
 
424
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
425
    # fake cgi input for script
 
426
    set src askattach
 
427
  } else {
 
428
    # else fall thru back into composer
 
429
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
430
  }
 
431
} elseif {$br_to == 1 || [string compare browse [string tolower $br_to]] == 0 || [string compare to [string tolower $br_to]] == 0} {
 
432
  # save msgdata to servlet
 
433
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
434
    # fake cgi input for script
 
435
    set oncancel compose
 
436
    _cgi_set_uservar op browse
 
437
    _cgi_set_uservar field to
 
438
    set src addrbrowse
 
439
  } else {
 
440
    # else fall thru back into composer
 
441
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
442
  }
 
443
} elseif {$br_cc == 1 || [string compare browse [string tolower $br_cc]] == 0 || [string compare cc [string tolower $br_cc]] == 0} {
 
444
  # save msgdata to servlet
 
445
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
446
    # fake cgi input for script
 
447
    set oncancel compose
 
448
    _cgi_set_uservar op browse
 
449
    _cgi_set_uservar field cc
 
450
    set src addrbrowse
 
451
  } else {
 
452
    # else fall thru back into composer
 
453
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
454
  }
 
455
} elseif {$br_bcc == 1 || [string compare browse [string tolower $br_bcc]] == 0 || [string compare bcc [string tolower $br_bcc]] == 0} {
 
456
  # save msgdata to servlet
 
457
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
458
    # fake cgi input for script
 
459
    set oncancel compose
 
460
    _cgi_set_uservar op browse
 
461
    _cgi_set_uservar field bcc
 
462
    set src addrbrowse
 
463
  } else {
 
464
    # else fall thru back into composer
 
465
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
466
  }
 
467
} elseif {$br_reply_to == 1 || [string compare browse [string tolower $br_reply_to]] == 0 || [string compare "reply_to" [string tolower $br_reply_to]] == 0} {
 
468
  # save msgdata to servlet
 
469
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
470
    # fake cgi input for script
 
471
    set oncancel compose
 
472
    _cgi_set_uservar op browse
 
473
    _cgi_set_uservar field reply-to
 
474
    set src addrbrowse
 
475
  } else {
 
476
    # else fall thru back into composer
 
477
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
478
  }
 
479
} elseif {$br_fcc == 1 || ($br_fcc > 0 && [string length $br_fcc] > 0)} {
 
480
  # save msgdata to servlet
 
481
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
482
    # fake cgi input for script
 
483
    _cgi_set_uservar onselect compose
 
484
    _cgi_set_uservar oncancel compose
 
485
    set src fldrbrowse
 
486
  } else {
 
487
    # else fall thru back into composer
 
488
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
489
  }
 
490
} elseif {[string compare expand [string tolower $ex_to]] == 0} {
 
491
  if {[expand_address_field To msgdata]} {
 
492
    set src ldapbrowse
 
493
  }
 
494
} elseif {[string compare expand [string tolower $ex_cc]] == 0} {
 
495
  if {[expand_address_field Cc msgdata]} {
 
496
    set src ldapbrowse
 
497
  }
 
498
} elseif {[string compare expand [string tolower $ex_bcc]] == 0} {
 
499
  if {[expand_address_field Bcc msgdata]} {
 
500
    set src ldapbrowse
 
501
  }
 
502
} elseif {[string compare expand [string tolower $ex_reply_to]] == 0} {
 
503
  if {[expand_address_field Reply-To msgdata]} {
 
504
    set src ldapbrowse
 
505
  }
 
506
} elseif {[string length $extrahdrs] > 0} {
 
507
  # save msgdata to servlet
 
508
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
509
    if {[catch {WPCmd PEInfo set wp_extra_hdrs} extras] || $extras == 1} {
 
510
      set toggle 0
 
511
    } else {
 
512
      set toggle 1
 
513
    }
 
514
 
 
515
    catch {WPCmd PEInfo set wp_extra_hdrs $toggle}
 
516
 
 
517
    _cgi_set_uservar restore 1
 
518
    set src compose
 
519
  } else {
 
520
    # else fall thru back into composer
 
521
    WPCmd PEInfo statmsg "Compose Error: $errstr"
 
522
  }
 
523
} elseif {[string compare OK [string trim $action]] == 0 && ($cancel || [string compare $sendop cancel] == 0)} {
 
524
  # clean up attachments
 
525
  WPCmd PEInfo statmsg "Message cancelled"
 
526
  catch {WPCmd PEInfo unset suspended_composition}
 
527
  catch {WPCmd PEInfo unset wp_extra_hdrs}
 
528
  set src ""
 
529
} else {
 
530
  # check for per-attachment ops
 
531
  if {[info exists attachments]} {
 
532
    set a [split $attachments ","]
 
533
    for {set i 0} {$i < [llength $a]} {incr i} {
 
534
      if {[catch {cgi_import detach_[lindex $a $i].x}] == 0} {
 
535
        if {[catch {WPCmd PECompose unattach [lindex $a $i]} result]} {
 
536
          WPCmd PEInfo statmsg "Unattach: $result"
 
537
        } else {
 
538
          set attachment_deleted [lindex $a $i]
 
539
 
 
540
          set a [lreplace $a $i $i]
 
541
          set attachments [join $a ","]
 
542
 
 
543
          for {set i 0} {$i < [llength $msgdata]} {incr i} {
 
544
            if {[string compare attach [lindex [lindex $msgdata $i] 0]] == 0 && [lindex [lindex $msgdata $i] 1] == $attachment_deleted} {
 
545
              set msgdata [lreplace $msgdata $i $i]
 
546
              break
 
547
            }
 
548
          }
 
549
 
 
550
          WPCmd PEInfo statmsg "Attachment Removed"
 
551
        }
 
552
 
 
553
        break
 
554
      }
 
555
    }
 
556
  }
 
557
 
 
558
  if {![info exists attachment_deleted]} {
 
559
    WPCmd PEInfo statmsg "Unrecognized Action"
 
560
  }
 
561
}
 
562
 
 
563
#do what was asked
 
564
if {[info exists postcmd]} {
 
565
  if {[info exists msgdata]} {
 
566
    if {[catch {WPCmd $postcmd $postcmdopt $msgdata} errstr]} {
 
567
      # if auth problem, save msgdata for after we ask for credentials
 
568
      if {([string compare $errstr NOPASSWD] == 0 || [string compare $errstr BADPASSWD] == 0)
 
569
          && [catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
570
 
 
571
        if {[catch {WPCmd PEInfo authrequestor} server]} {
 
572
          append reason "Unknown server asking for authentication.  Press cancel to abort if you think this message is in error."
 
573
        } else {
 
574
          append reason "[cgi_nl]Enter Username and Password to connect to [cgi_bold $server]"
 
575
          lappend params [list server $server]
 
576
        }
 
577
 
 
578
        if {[catch {WPCmd PESession creds 0 "{$server}"} creds] == 0 && $creds != 0} {
 
579
          catch {WPCmd PEInfo statmsg "Invalid Username or Password"}
 
580
          WPCmd PESession nocred 0 "{$server}"
 
581
        }
 
582
 
 
583
        WPCmd set reason "The server ($server) used to send this message requires authentication.[cgi_nl]"
 
584
 
 
585
        WPCmd set cid [WPCmd PEInfo key]
 
586
        WPCmd set authcol 0
 
587
        WPCmd set authfolder "{$server}"
 
588
        WPCmd set authpage [WPPercentQuote "[cgi_root]/$_wp(appdir)/wp.tcl?page=dosend"]
 
589
        WPCmd set authcancel [WPPercentQuote "[cgi_root]/$_wp(appdir)/wp.tcl?page=compose&restore=1&cid=$cid"]
 
590
 
 
591
        set src auth
 
592
 
 
593
      } else {
 
594
        # regurgitate the compose window
 
595
        set style ""
 
596
        set title "$verb Error: [cgi_font class=notice "$errstr"]"
 
597
        if {[string length $errstr]} {
 
598
          set notice "$verb FAILED: $errstr"
 
599
        } else {
 
600
          set notice "$verb FAILED: [WPCmd PEInfo statmsg]"
 
601
        }
 
602
 
 
603
        WPCmd PEInfo statmsg "$notice"
 
604
 
 
605
        # regurgitate the compose window
 
606
        if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
607
          _cgi_set_uservar restore 1
 
608
          set src compose
 
609
 
 
610
          unset body
 
611
        } else {
 
612
        }
 
613
 
 
614
        set src compose
 
615
      }
 
616
    } else {
 
617
      catch {WPCmd PEInfo unset suspended_composition}
 
618
      WPCmd PEInfo statmsg "Message $verbpast!"
 
619
    }
 
620
  } else {
 
621
    WPCmd PEInfo statmsg "No Message $verbpast!"
 
622
  }
 
623
 
 
624
  if {[info exists delete_me]} {
 
625
    foreach i $delete_me {
 
626
      catch {file delete $i}
 
627
    }
 
628
  }
 
629
} elseif {![info exists src]} {
 
630
  set style ""
 
631
  set title "Compose Message"
 
632
  catch {unset attachments}
 
633
 
 
634
  # regurgitate the compose window
 
635
  if {[catch {WPCmd PEInfo set suspended_composition $msgdata} errstr] == 0} {
 
636
    _cgi_set_uservar restore 1
 
637
    set src compose
 
638
 
 
639
    unset body
 
640
  }
 
641
}
 
642
 
 
643
if {[info exists src] && [string length $src]} {
 
644
  source [WPTFScript $src]
 
645
} else {
 
646
  cgi_redirect "[cgi_root]/$_wp(appdir)/wp.tcl?page=$postpost"
 
647
}