1 |
#! /usr/local/bin/perl |
2 |
|
3 |
BEGIN { $APP_PATH="/home/httpd/html/webmail/cgi-bin/"; } |
4 |
|
5 |
# @ ---------------------------------------------------------------------------------------------------------- |
6 |
# @ This code is (c) 1999 Alexandre Aufrere and NikoSoft. |
7 |
# @ Published under NPL rights, meaning you have the right |
8 |
# @ to use and modify this code freely, provided it |
9 |
# @ remains available and free. Any modified code should be |
10 |
# @ submitted to Nikopol Software Corp. or Alexandre Aufrere. |
11 |
# @ This code is protected by the French laws on Copyright. |
12 |
# @ Please note that there it comes with NO WARRANTY of any kind, |
13 |
# @ and especially for any damagbe it could cause to your computer |
14 |
# @ or network. |
15 |
# @ Using this code means you agree to this license agreement. |
16 |
# @ Further information at http://aufrere.citeweb.net/nsc/ |
17 |
# @ ---------------------------------------------------------------------------------------------------------- |
18 |
# @ |
19 |
# @ Project NS WebMail |
20 |
# @ |
21 |
# @ Filename sendform.pl |
22 |
# @ |
23 |
# @ Description build a form for sending mail |
24 |
# @ |
25 |
# @ Version 1.0 |
26 |
# @ |
27 |
# @ ---------------------------------------------------------------------------------------------------------- |
28 |
|
29 |
use Socket; |
30 |
require $APP_PATH."config.pl"; |
31 |
|
32 |
#obtain the FORM information that has been passed by using |
33 |
#the param() method of the cgi object. |
34 |
&ReadParse; |
35 |
$loginname = $in{'loginname'}; |
36 |
$password = $in{'password'}; |
37 |
$POPserver = $in{'POPserver'}; |
38 |
$to = $in{'to'}; |
39 |
$subject = $in{'subject'} or ""; |
40 |
$body = $in{'body'} or ""; |
41 |
$cache = $in{'cache'}; |
42 |
|
43 |
# Put the ">" befor the quoted body |
44 |
@bodylines=split("\n",$body); |
45 |
$body=""; |
46 |
foreach (@bodylines) { |
47 |
$body.="> $_\n"; |
48 |
} |
49 |
|
50 |
$sender = $loginname."\@".$POPserver; |
51 |
$addrvrfyed=$sender; |
52 |
if ($verifysmtp==1) { |
53 |
$addrvrfyed=sendmailvrfy($sender,$SMTPserver); |
54 |
if ($addrvrfyed=~ m/^\-[0-9]/) { $addrvrfyed=$sender; } |
55 |
$addrvrfyed=~s/^2\.1\.5 //g; # nuke sendmail 8.10.x vrfy feature |
56 |
if (defined($masquarade)) { |
57 |
$addrvrfyed=~s/\@([^>^ ]+)/\@$masquarade/; |
58 |
} |
59 |
$from_html=$addrvrfyed; |
60 |
$from_html =~ s/</<\;/; |
61 |
$from_html =~ s/>/>\;/; |
62 |
} |
63 |
|
64 |
print "Content-type: text/html\n\n"; |
65 |
print "<HTML><HEAD><TITLE>NSWM"; |
66 |
if ($cache eq "No") { print "<META HTTP-EQUIV='Pragma' CONTENT='no-cache,no-store'>"; } |
67 |
print "</TITLE></HEAD>"; |
68 |
print "<BODY BGCOLOR='FFFFFF'>\n"; |
69 |
|
70 |
#This calculation determines the width of the text entry boxes. |
71 |
#The minimum length will either be 36 spaces or 20% larger than the |
72 |
#largest of the three field entries which are already known. |
73 |
#Note that depending on how this routine is called, not all |
74 |
#of the fields are known in advance. |
75 |
$width = 30; |
76 |
$width = ($width>length($sender) ? $width : length($sender)); |
77 |
$width = ($width>length($to) ? $width : length($to)); |
78 |
$width = ($width>length($subject)? $width : length($subject)); |
79 |
$width *= 1.2; #fudge factor to avoid visual cramping. |
80 |
|
81 |
print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."inbox.pl' name=inboxForm>\n"; |
82 |
print " <INPUT TYPE='hidden' NAME='loginname' VALUE='$loginname' SIZE=$width>\n"; |
83 |
print " <INPUT TYPE='hidden' NAME='password' VALUE='$password' >\n"; |
84 |
print " <INPUT TYPE='hidden' NAME='POPserver' VALUE='$POPserver' >\n"; |
85 |
print " <INPUT TYPE='hidden' NAME='cache' VALUE='$cache' >\n"; |
86 |
print "</form>"; |
87 |
|
88 |
print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."sentmail.pl' name=sentForm>\n"; |
89 |
print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname>\n"; |
90 |
print "<INPUT TYPE='hidden' NAME='password' VALUE=$password>\n"; |
91 |
print "<INPUT TYPE='hidden' NAME='POPserver' VALUE=$POPserver>\n"; |
92 |
print "<INPUT TYPE='hidden' NAME='cache' VALUE=$cache>\n"; |
93 |
print "</FORM>"; |
94 |
|
95 |
print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."sendform.pl' name=newMailForm>\n"; |
96 |
print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname>\n"; |
97 |
print "<INPUT TYPE='hidden' NAME='password' VALUE=$password>\n"; |
98 |
print "<INPUT TYPE='hidden' NAME='POPserver' VALUE=$POPserver>\n"; |
99 |
print "<INPUT TYPE='hidden' NAME='cache' VALUE=$cache>\n"; |
100 |
print "<INPUT TYPE='hidden' NAME='to' VALUE=''>\n"; |
101 |
print "<INPUT TYPE='hidden' NAME='subject' VALUE=''>\n"; |
102 |
print "</FORM>"; |
103 |
|
104 |
print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."send.pl'>\n"; |
105 |
print "<TABLE BORDER=0><TR><TD>\n"; |
106 |
print ""; |
107 |
print "$fromtext: </td><td> <INPUT TYPE='hidden' NAME='sender' VALUE='$addrvrfyed' SIZE=$width> $from_html\n"; |
108 |
print "</TD><TD WIDTH=100 valign='middle' rowspan=3>\n"; |
109 |
print "</td></tr>\n"; |
110 |
print "<tr><td>"; |
111 |
print "$totext: </td><td> <INPUT TYPE='text' NAME='to' VALUE=\"$to\" SIZE=$width></td></tr>\n"; |
112 |
print "<tr><td>Cc: </td><td> <INPUT TYPE='text' NAME='cc' VALUE=\"\" SIZE=$width></td></tr>\n"; |
113 |
print "<tr><td>"; |
114 |
print "$subjecttext: </td><td> <INPUT TYPE='text' NAME='subject' VALUE=\"$subject\" SIZE=$width>\n"; |
115 |
print " <INPUT TYPE='hidden' NAME='loginname' VALUE='$loginname' SIZE=$width>\n"; |
116 |
print " <INPUT TYPE='hidden' NAME='password' VALUE='$password' >\n"; |
117 |
print " <INPUT TYPE='hidden' NAME='POPserver' VALUE='$POPserver' >\n"; |
118 |
print " <INPUT TYPE='hidden' NAME='cache' VALUE='$cache' >\n"; |
119 |
print "</TD></TR></TABLE>\n"; |
120 |
|
121 |
print "$messagetext<br>\n"; |
122 |
print "<textarea rows=14 cols=75 name='message' wrap='virtual'>\n"; |
123 |
print $body; |
124 |
print "</textarea><br>"; |
125 |
print "<ul><ul><ul><INPUT TYPE=submit value='$sendtext'></ul></ul></ul>"; |
126 |
print "</FORM>"; |
127 |
|
128 |
#send the ending html code (/body and /head tags) |
129 |
print "</BODY></HTML>\n"; |
130 |
exit; |
131 |
|
132 |
|
133 |
#-----------------------------SUBROUTINES------------------------ |
134 |
|
135 |
|
136 |
|
137 |
sub ReadParse { |
138 |
local(*in)=@_ if @_; |
139 |
local ($i,$key,$val); |
140 |
|
141 |
if ($ENV{'REQUEST_METHOD'} eq "GET") { |
142 |
$in=$ENV{'QUERY_STRING'}; |
143 |
} |
144 |
elsif ($ENV{'REQUEST_METHOD'} eq "POST") { |
145 |
read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); |
146 |
} |
147 |
|
148 |
@in=split(/&/,$in); |
149 |
|
150 |
foreach $i (0 .. $#in) { |
151 |
$in[$i] =~ s/\+/ /g; |
152 |
($key,$val)=split(/=/,$in[$i],2); |
153 |
$key =~ s/%(..)/pack("c",hex($1))/ge; |
154 |
$val =~ s/%(..)/pack("c",hex($1))/ge; |
155 |
$in{$key} .= "\0" if (defined($in{$key})); |
156 |
$in{$key} .=$val; |
157 |
} |
158 |
return length($in); |
159 |
} |
160 |
|
161 |
################################################################ |
162 |
### sendmailvrfy ############################################### |
163 |
################################################################ |
164 |
sub sendmailvrfy { |
165 |
|
166 |
my ($addr,$smtp) = @_; |
167 |
|
168 |
$addr =~ s/[ \t]+/ /g; # pack spaces |
169 |
$smtp =~ s/^\s+//g; # remove spaces around $smtp |
170 |
$smtp =~ s/\s+$//g; |
171 |
|
172 |
my $addrresolved=""; |
173 |
|
174 |
if (!$addr) { return -8; } |
175 |
|
176 |
my($proto) = (getprotobyname('tcp'))[2]; |
177 |
my($port) = (getservbyname('smtp', 'tcp'))[2]; |
178 |
|
179 |
my($smtpaddr) = ($smtp =~ |
180 |
/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) |
181 |
? pack('C4',$1,$2,$3,$4) |
182 |
: (gethostbyname($smtp))[4]; |
183 |
|
184 |
if (!defined($smtpaddr)) { return -1; } |
185 |
|
186 |
if (!socket(S, AF_INET, SOCK_STREAM, $proto)) { return -2; } |
187 |
if (!connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return -3; } |
188 |
|
189 |
my($oldfh) = select(S); $| = 1; select($oldfh); |
190 |
|
191 |
$_ = <S>; if (/^[45]/) { close S; return -4; } |
192 |
|
193 |
print S "helo localhost\r\n"; |
194 |
$_ = <S>; if (/^[45]/) { close S; return -5; } |
195 |
|
196 |
print S "vrfy $addr\r\n"; |
197 |
$_ = <S>; |
198 |
if (/^[45]/) { close S; return -5; } |
199 |
else { $addrresolved=$_; } |
200 |
|
201 |
print S "quit\r\n"; |
202 |
$_ = <S>; |
203 |
|
204 |
close S; |
205 |
|
206 |
$addrresolved=~ s/^[0-9]*\s(.*)/$1/; |
207 |
|
208 |
return $addrresolved; |
209 |
} |