/[webmail]/cgi-bin/send.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/send.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Fri Apr 28 08:14:01 2000 UTC (24 years ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/plain
again EOL fix

1 dpavlin 1.1 #!/usr/local/bin/perl
2    
3 dpavlin 1.2 BEGIN { $APP_PATH="/home/httpd/html/webmail/cgi-bin/"; }
4 dpavlin 1.1
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 send.pl
22     # @
23     # @ Description sends mail using SMTP protocol. the mail sender
24     # @ is authentified through POP, preventing this script
25     # @ from beeing used for bomb mailing and so on.
26     # @
27     # @ Version 1.0
28     # @
29     # @ ----------------------------------------------------------------------------------------------------------
30    
31     use Socket;
32     use Mail::POP3Client;
33     require $APP_PATH."config.pl";
34    
35     #obtain the FORM information that has been passed by using
36     #the param() method of the cgi object.
37     &ReadParse;
38     $loginname = $in{'loginname'};
39     $password = $in{'password'};
40     $POPserver = $in{'POPserver'};
41     $sender = $in{'sender'};
42     $to = $in{'to'};
43     $cc = $in{'cc'};
44     $subject = $in{'subject'};
45     $message = $in{'message'};
46     $cache = $in{'cache'};
47    
48     # POP connexion to authentify sender
49     $pop = new Mail::POP3Client($loginname, $password, $POPserver);
50     $MessageCount = $pop->Count;
51     $pop->Close();
52     if ($MessageCount == -1) {
53     print "<font size=+1>$POPserver: $loginname, $incorrectlogin";
54     exit;
55     }
56    
57     # sending the mail using sendmail function
58     # the apparently-from field is made using login and POP server, but the
59     # from and reply-to fields are specified by the sender in the from field
60     $status = sendmail($loginname."\@".$POPserver, $sender, $sender, $to, $cc, $SMTPserver, $subject, $message);
61     $date=localtime();
62    
63     #output the header to the client browser (DO NOT DELETE).
64     #lack of this will result in an error 500.
65     print "Content-type: text/html\n\n";
66     print "<HTML><HEAD><TITLE>NSWM - Message sent</TITLE>";
67     if ($cache eq "No") { print "<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>"; }
68    
69    
70     print "<SCRIPT LANGUAGE='JavaScript'>\n";
71     print "function closeThisWindow() { \n";
72     print "window.close()\n";
73     print "}\n";
74     print "</SCRIPT>\n";
75    
76     print "</HEAD><BODY BGCOLOR='FFFFFF'>";
77    
78     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."sendform.pl' name=newMailForm>\n";
79     print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname>\n";
80     print "<INPUT TYPE='hidden' NAME='password' VALUE=$password>\n";
81     print "<INPUT TYPE='hidden' NAME='POPserver' VALUE=$POPserver>\n";
82     print "<INPUT TYPE='hidden' NAME='cache' VALUE=$cache>\n";
83     print "<INPUT TYPE='hidden' NAME='to' VALUE=''>\n";
84     print "<INPUT TYPE='hidden' NAME='subject' VALUE=''>\n";
85     print "</FORM>";
86    
87     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."sentmail.pl' name=sentForm>\n";
88     print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname>\n";
89     print "<INPUT TYPE='hidden' NAME='password' VALUE=$password>\n";
90     print "<INPUT TYPE='hidden' NAME='POPserver' VALUE=$POPserver>\n";
91     print "<INPUT TYPE='hidden' NAME='cache' VALUE=$cache>\n";
92     print "</FORM>";
93    
94     print "<h3>";
95    
96     if ($status == 1) {
97     $logfilename=$LOG_PATH.$loginname."\@".$POPserver.".log";
98     print $messagesent;
99     open (f, ">>$logfilename");
100     print f $date.";".$to.";".$subject."\n";
101     close (f);
102     }
103     elsif ($status == -1) {print " $smtp : $smtphostunkown";}
104     elsif ($status == -2) {print $createsocketfailed;}
105     elsif ($status == -3) {print $connectionfailed;}
106     elsif ($status == -4) {print $servicena;}
107     elsif ($status == -5) {print $commerror;}
108     elsif ($status == -6) {print " $to ($smtp): $userunkown.";}
109     elsif ($status == -7) {print " $transfailed.";}
110     elsif ($status == -8) {print " $notofield";}
111     else {print " $errorunkown.";}
112    
113     print "</h3><br>";
114     print "<FORM METHOD='POST' ACTION='".$CGI_PATH_NSWM."inbox.pl' name=inboxForm >\n";
115     print "<INPUT TYPE='SUBMIT' VALUE='OK' >\n";
116     print "<INPUT TYPE='hidden' NAME='loginname' VALUE=$loginname >\n";
117     print "<INPUT TYPE='hidden' NAME='password' VALUE=$password >\n";
118     print "<INPUT TYPE='hidden' NAME='POPserver' VALUE=$POPserver >\n";
119     print "<INPUT TYPE='hidden' NAME='cache' VALUE=$cache >\n";
120    
121     print "</FORM>";
122    
123    
124     #send the ending html code (/body and /head tags)
125     print "</BODY></HTML>";
126     exit;
127    
128    
129     #-----------------------------SUBROUTINES------------------------
130    
131     sub ReadParse {
132     local(*in)=@_ if @_;
133     local ($i,$key,$val);
134    
135     if ($ENV{'REQUEST_METHOD'} eq "GET") {
136     $in=$ENV{'QUERY_STRING'};
137     }
138     elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
139     read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
140     }
141    
142     @in=split(/&/,$in);
143    
144     foreach $i (0 .. $#in) {
145     $in[$i] =~ s/\+/ /g;
146     ($key,$val)=split(/=/,$in[$i],2);
147     $key =~ s/%(..)/pack("c",hex($1))/ge;
148     $val =~ s/%(..)/pack("c",hex($1))/ge;
149     $in{$key} .= "\0" if (defined($in{$key}));
150     $in{$key} .=$val;
151     }
152     return length($in);
153     }
154    
155    
156     #------------------------------------------------------------
157     # sub sendmail()
158     #
159     # send/fake email around the world ...
160     #
161     # Version : 1.21
162     # Environment: Hip Perl Build 105 NT 3.51 Server SP4
163     # Environment: Hip Perl Build 110 NT 4.00
164     #
165     # arguments:
166     #
167     # $afrom apparently-from email address of sender
168     # $from email address of sender
169     # $reply email address for replying mails
170     # $to email address of reciever
171     # (multiple recievers can be given separated with space)
172     # $smtp name of smtp server (name or IP)
173     # $subject subject line
174     # $message (multiline) message
175     #
176     # return codes:
177     #
178     # 1 success
179     # -1 $smtphost unknown
180     # -2 socket() failed
181     # -3 connect() failed
182     # -4 service not available
183     # -5 unspecified communication error
184     # -6 local user $to unknown on host $smtp
185     # -7 transmission of message failed
186     # -8 argument $to empty
187     #
188     # usage examples:
189     #
190     # print
191     # sendmail("Alice <alice\@company.com>",
192     # "alice\@company.com",
193     # "joe\@agency.com charlie\@agency.com",
194     # $smtp, $subject, $message );
195     #
196     # or
197     #
198     # print
199     # sendmail($from, $reply, $to, $smtp, $subject, $message );
200     #
201     # (sub changes $_)
202     #
203     #------------------------------------------------------------
204    
205     ################################################################
206     ### sendmail ###################################################
207     ################################################################
208     sub sendmail {
209    
210     my ($afrom,$from, $reply, $to, $cc, $smtp, $subject, $message) = @_;
211    
212     $date=localtime();
213    
214 dpavlin 1.4 my $fromaddr = $from; chomp $fromaddr; chomp $from;
215     my $replyaddr = $reply; chomp $replyaddr;
216 dpavlin 1.1
217     $to =~ s/[ \t]+/, /g; # pack spaces and add comma
218     $cc =~ s/[ \t]+/, /g; # pack spaces and add comma
219     $fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address
220     $replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
221     $replyaddr =~ s/^([^\s]+).*/$1/; # use first address
222     $message =~ s/^\./\.\./gm; # handle . as first character
223     $message =~ s/\r\n/\n/g; # handle line ending
224     $message =~ s/\n/\r\n/g;
225     $smtp =~ s/^\s+//g; # remove spaces around $smtp
226     $smtp =~ s/\s+$//g;
227    
228     if (!$to) { return -8; }
229    
230     my($proto) = (getprotobyname('tcp'))[2];
231     my($port) = (getservbyname('smtp', 'tcp'))[2];
232    
233     my($smtpaddr) = ($smtp =~
234     /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
235     ? pack('C4',$1,$2,$3,$4)
236     : (gethostbyname($smtp))[4];
237    
238     if (!defined($smtpaddr)) { return -1; }
239    
240     if (!socket(S, AF_INET, SOCK_STREAM, $proto)) { return -2; }
241     if (!connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return -3; }
242    
243     my($oldfh) = select(S); $| = 1; select($oldfh);
244    
245     $_ = <S>; if (/^[45]/) { close S; return -4; }
246    
247     print S "helo localhost\r\n";
248     $_ = <S>; if (/^[45]/) { close S; return -5; }
249    
250     print S "mail from: <$fromaddr>\r\n";
251     $_ = <S>; if (/^[45]/) { close S; return -5; }
252    
253 dpavlin 1.3 foreach (split(/, */, $to)) {
254     chomp;
255     print S "rcpt to: <$_>\r\n";
256     $_ = <S>; if (/^[45]/) { close S; return -6; }
257 dpavlin 1.1 }
258 dpavlin 1.3 foreach (split(/, */, $cc)) {
259     chomp;
260     print S "rcpt to: <$_>\r\n";
261     $_ = <S>; if (/^[45]/) { close S; return -6; }
262 dpavlin 1.1 }
263     print S "data\r\n";
264     $_ = <S>; if (/^[45]/) { close S; return -5; }
265    
266     print S "To: $to\r\n";
267     if ($cc ne "") { print S "CC: $cc\r\n"; }
268     print S "From: $from\r\n";
269     print S "Reply-to: $replyaddr\r\n" if $replyaddr;
270     print S "Apparently-from: $afrom\r\n";
271     print S "X-Mailer: NikoSoft WebMail Perl from Alexandre Aufrere\r\n";
272     print S "Date: $date\r\n";
273     print S "Subject: $subject\r\n\r\n";
274     print S "$message";
275     print S "\r\n.\r\n";
276    
277     $_ = <S>; if (/^[45]/) { close S; return -7; }
278    
279     print S "quit\r\n";
280     $_ = <S>;
281    
282     close S;
283     return 1;
284 dpavlin 1.3 }

  ViewVC Help
Powered by ViewVC 1.1.26