/[webmail]/cgi-bin/sendform.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /cgi-bin/sendform.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Feb 28 09:34:40 2000 UTC (24 years, 1 month ago) by dpavlin
Branch: MAIN
Branch point for: NikoSoft
File MIME type: text/plain
Initial revision

1 dpavlin 1.1 #! /usr/local/bin/perl
2    
3     BEGIN { $APP_PATH="foo/bar"; }
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.="> ".$_;
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     }
56    
57     print "Content-type: text/html\n\n";
58     print "<HTML><HEAD><TITLE>NSWM";
59     if ($cache eq "No") { print "<META HTTP-EQUIV='Pragma' CONTENT='no-cache,no-store'>"; }
60     print "</TITLE></HEAD>";
61     print "<BODY BGCOLOR='FFFFFF'>\n";
62    
63     #This calculation determines the width of the text entry boxes.
64     #The minimum length will either be 36 spaces or 20% larger than the
65     #largest of the three field entries which are already known.
66     #Note that depending on how this routine is called, not all
67     #of the fields are known in advance.
68     $width = 30;
69     $width = ($width>length($sender) ? $width : length($sender));
70     $width = ($width>length($to) ? $width : length($to));
71     $width = ($width>length($subject)? $width : length($subject));
72     $width *= 1.2; #fudge factor to avoid visual cramping.
73    
74     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."inbox.pl' name=inboxForm>\n";
75     print " <INPUT TYPE='hidden' NAME='loginname' VALUE='$loginname' SIZE=$width>\n";
76     print " <INPUT TYPE='hidden' NAME='password' VALUE='$password' >\n";
77     print " <INPUT TYPE='hidden' NAME='POPserver' VALUE='$POPserver' >\n";
78     print " <INPUT TYPE='hidden' NAME='cache' VALUE='$cache' >\n";
79     print "</form>";
80    
81     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."sentmail.pl' name=sentForm>\n";
82     print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname>\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."sendform.pl' name=newMailForm>\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 "<INPUT TYPE='hidden' NAME='to' VALUE=''>\n";
94     print "<INPUT TYPE='hidden' NAME='subject' VALUE=''>\n";
95     print "</FORM>";
96    
97     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."send.pl'>\n";
98     print "<TABLE BORDER=0><TR><TD>\n";
99     print "";
100     print "$fromtext: </td><td> <INPUT TYPE='text' NAME='sender' VALUE='$addrvrfyed' SIZE=$width>\n";
101     print "</TD><TD WIDTH=100 valign='middle' rowspan=3>\n";
102     print "</td></tr>\n";
103     print "<tr><td>";
104     print "$totext: </td><td> <INPUT TYPE='text' NAME='to' VALUE=\"$to\" SIZE=$width></td></tr>\n";
105     print "<tr><td>Cc: </td><td> <INPUT TYPE='text' NAME='cc' VALUE=\"\" SIZE=$width></td></tr>\n";
106     print "<tr><td>";
107     print "$subjecttext: </td><td> <INPUT TYPE='text' NAME='subject' VALUE=\"$subject\" SIZE=$width>\n";
108     print " <INPUT TYPE='hidden' NAME='loginname' VALUE='$loginname' SIZE=$width>\n";
109     print " <INPUT TYPE='hidden' NAME='password' VALUE='$password' >\n";
110     print " <INPUT TYPE='hidden' NAME='POPserver' VALUE='$POPserver' >\n";
111     print " <INPUT TYPE='hidden' NAME='cache' VALUE='$cache' >\n";
112     print "</TD></TR></TABLE>\n";
113    
114     print "$messagetext<br>\n";
115     print "<textarea rows=14 cols=75 name='message' wrap='virtual'>\n";
116     print $body;
117     print "</textarea><br>";
118     print "<ul><ul><ul><INPUT TYPE=submit value='$sendtext'></ul></ul></ul>";
119     print "</FORM>";
120    
121     #send the ending html code (/body and /head tags)
122     print "</BODY></HTML>\n";
123     exit;
124    
125    
126     #-----------------------------SUBROUTINES------------------------
127    
128    
129    
130     sub ReadParse {
131     local(*in)=@_ if @_;
132     local ($i,$key,$val);
133    
134     if ($ENV{'REQUEST_METHOD'} eq "GET") {
135     $in=$ENV{'QUERY_STRING'};
136     }
137     elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
138     read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
139     }
140    
141     @in=split(/&/,$in);
142    
143     foreach $i (0 .. $#in) {
144     $in[$i] =~ s/\+/ /g;
145     ($key,$val)=split(/=/,$in[$i],2);
146     $key =~ s/%(..)/pack("c",hex($1))/ge;
147     $val =~ s/%(..)/pack("c",hex($1))/ge;
148     $in{$key} .= "\0" if (defined($in{$key}));
149     $in{$key} .=$val;
150     }
151     return length($in);
152     }
153    
154     ################################################################
155     ### sendmailvrfy ###############################################
156     ################################################################
157     sub sendmailvrfy {
158    
159     my ($addr,$smtp) = @_;
160    
161     $addr =~ s/[ \t]+/ /g; # pack spaces
162     $smtp =~ s/^\s+//g; # remove spaces around $smtp
163     $smtp =~ s/\s+$//g;
164    
165     my $addrresolved="";
166    
167     if (!$addr) { return -8; }
168    
169     my($proto) = (getprotobyname('tcp'))[2];
170     my($port) = (getservbyname('smtp', 'tcp'))[2];
171    
172     my($smtpaddr) = ($smtp =~
173     /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
174     ? pack('C4',$1,$2,$3,$4)
175     : (gethostbyname($smtp))[4];
176    
177     if (!defined($smtpaddr)) { return -1; }
178    
179     if (!socket(S, AF_INET, SOCK_STREAM, $proto)) { return -2; }
180     if (!connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return -3; }
181    
182     my($oldfh) = select(S); $| = 1; select($oldfh);
183    
184     $_ = <S>; if (/^[45]/) { close S; return -4; }
185    
186     print S "helo localhost\r\n";
187     $_ = <S>; if (/^[45]/) { close S; return -5; }
188    
189     print S "vrfy $addr\r\n";
190     $_ = <S>;
191     if (/^[45]/) { close S; return -5; }
192     else { $addrresolved=$_; }
193    
194     print S "quit\r\n";
195     $_ = <S>;
196    
197     close S;
198    
199     $addrresolved=~ s/^[0-9]*\s(.*)/$1/;
200    
201     return $addrresolved;
202     }

  ViewVC Help
Powered by ViewVC 1.1.26