4 $Id: md,v 1.3 2003/06/10 11:02:47 kripke Exp $
8 namespace import ::mime::*;
10 # return list file from date subject size content-type
12 array set a {from {} date {} subject {} content-type {}}
14 # for quick scan, ignore continuation lines and repeated headers
15 while {[gets $fid line]} {
16 if [regexp {^([\w\-]+):\s*(.*)} $line - key val] {
17 set a([string tolower $key]) $val
21 list $file $a(from) $a(date) $a(subject) [file size $file] $a(content-type)
24 # return list file from date subject size encoding content params parts msg
27 set msg [initialize -file $file]
28 # mime want's whole messages
31 foreach key {From Date Subject} {
32 if [catch {getheader $msg $key} value] {
38 # properties (parsed content-* headers)
39 foreach key {size encoding content params parts} {
40 if [catch {getproperty $msg $key} value] {
51 # request standard tags
57 # 1 move destination (checkbox)
64 # foreach e [array names env] { ::puts stderr "$e\t$env($e)" }
65 ::puts stderr [request serialize]
67 set script [lindex [request get -10] 0]
68 set path [lindex [request get -11] 0]
69 set user [lindex [request get -12] 0]
70 set body [lindex [request get 5] 0]
72 if {"" == $user} return
73 set l [string length $user]
74 set fid [open /var/qmail/users/popasswd]
75 while {[gets $fid line]} {
76 if ![string match "$user:*" $line] continue
77 set upignh [split $line :]
78 set name [lindex $upignh 4]
79 set base [lindex $upignh 5]/Maildir
86 if ![regexp {^/(\w+)(/\d+[\w.:,]*)?$} $path - dir file] {
90 } elseif {"" == $file} {
95 if ![file isdirectory $dir] return
97 set dirs {} ;# dirs to list
98 set mvdirs {} ;# dirs to move to
99 foreach d [glob ???] {
100 if ![file isdirectory $d] continue
101 switch -- $d tmp {} default { lappend dirs $d }
102 switch -- $d new - tmp - uns - out - $dir {} default { lappend mvdirs $d }
104 if {"" != $body && [catch { # send
105 set to [lindex [request get 3] 0]
106 set subject [lindex [request get 4] 0]
107 if {"" == $to} { # get from message
108 set msg [initialize -file $dir$file]
109 if [catch {getheader $msg Reply-To} to] {
110 set to [getheader $msg From]
112 set to [lindex $to 0]
113 if {"" == $subject} {
114 set subject "Re: [lindex [getheader $msg Subject] 0]"
118 set tim [clock seconds]
119 set gtf [clock format $tim -format %Y%m%d%H%M%S -gmt 1]
120 set rfc [clock format $tim -format {%a, %d %b %Y %H:%M:%S %Z}]
121 set fid [open uns/$gtf.[pid] w]
122 set msg [initialize -canonical text/plain \
123 -header [list Return-Path $name] \
124 -header [list From $name] \
125 -header [list To $to] \
126 -header [list Date $rfc] \
127 -header [list Subject $subject] \
128 -encoding quoted-printable \
130 copymessage $msg $fid
134 ::puts stderr $errorInfo
145 <a href="<%=$rel$d%>"><%=d%></a>
149 <%-- main display --%>
150 <form action="<%=$rel$dir$file%>" method="POST">
158 foreach d $mvdirs { %><%=d%> <% }
168 foreach mv [request get 1] {
170 if [regexp {^(\w\w\w)/(\S*)$} $mv - dest file] {
171 file rename $dir/$file $dest
184 # file from date subject size content-type
192 <input type="checkbox" name="1" value="<%=d%>/<%?lindex $l 0%>"/>
197 <td><%"lindex $l 1%></td>
198 <td><%"lindex $l 2%></td>
199 <td><%"lindex $l 4%></td>
200 <td><a href="<%=dir%>/<%?lindex $l 0%>"><%"lindex $l 3%></a></td>
205 set msg [initialize -file $dir$file]
206 foreach h [getheader $msg -names] {
207 foreach v [getheader $msg $h] {
217 if {"text/plain" == [getproperty $msg content]} {
219 } elseif {![catch {set parts [getproperty $msg parts]}]} {
221 set ct [getproperty $p content]
228 if {"text/plain" == $ct} {
235 <tr><td colspan="2"><pre>
243 <input type="submit" name="2" value="ok"/>
246 <tr><td>to</td><td><input type="text" name="3" size="64"/></td></tr>
247 <tr><td>subject</td><td><input type="text" name="4" size="64"/></td></tr>
249 <textarea name="5" width="78" rows="20" cols="78"></textarea>