#!/usr/bin/perl use DBI(); use CGI qw(:standard); use IO::Socket; use MIME::Base64(); use MIME::QuotedPrint(); use Encode; use Encode qw/from_to/; use CGI::Cookie; $user = param("name"); $pass = param("pass"); $page = param("page"); $par1 = $ARGV[0]; if ($page eq "all") {$page = "0"; $page1 = "all";} if ($user ne "") { ### $pass = MIME::Base64::encode($pass); $auth=sprintf("%s %s", $user, $pass); my $cook = cookie( -name => 'mn.mail.auth', -value => $auth, -expires => '0', -domain => 'miranet.lan', -path => '/', ); $cook = sprintf header(-cookie=>$cook); ($cook) = split("charset=", $cook); $cook = sprintf ("%s charset=KOI8-R\n\n", $cook); print "$cook"; } else { if ($par1 ne "quit") {print "Content-type: text/html\n\n";} my $auth = cookie('mn.mail.auth'); ($user, $pass) = split (" ", $auth); ### $pass = MIME::Base64::decode($pass); } if ($par1 ne "quit") { open(patt,"<./patt_n1.html")||die "Pattern file 1 not found"; while() { print; } close(patt); } $serv = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost", #PeerAddr => "pop.mail.ru", PeerPort => "110", ); $cnt = 0; $stat1 = ""; $stat2 = ""; $c = 0; $zv = "?"; $clr = "0060a0"; $clr = "005090"; $start = "0"; $mpp = "30"; $crnt = "0"; if ($page ne "") {$start = $page;} if ($par1 eq "quit") {print $serv "QUIT\n";} while ( <$serv> ) { ($q, $p) = split (" "); ($nl, $dt1) = split ("From:"); ($nl, $dt2) = split ("Subject:"); ($nl, $dt3) = split ("Return-Path:"); if ( $q eq "+OK" and $stat1 eq "" ) {$cnt=$cnt+1;} if ( $cnt eq "1" ) { print $serv "USER $user\n";} if ( $cnt eq "2" ) { print $serv "PASS $pass\n"; } if ( $stat1 eq "list" ) { $msg = $p; $fs = $start * $mpp + 1; $ls = $start * $mpp + $mpp; if ($ls > $msg) {$ls=$msg;} if ($page1 eq "all") {$ls = $msg;} print "

Сообщений: $msg ( $fs - $ls )


\n"; $stat1="headq"; $stat2=$msg-($start*$mpp); if ($page1 eq "all") {$stat2 = $msg;} } if ( $cnt eq "3" ) { $stat1 = "list"; print $serv "STAT\n"; $cnt="4"; print "";} if ( $stat1 eq "headw" ) { if ( $q eq "From:" ) { if (index ($dt1,"\=\?")<0) {from_to($dt1, "cp1251", "koi8-r") foreach $dt1; $from = $dt1;} else {$from = autodec($dt1);} } if ( $q eq "Subject:" ) { if (index ($dt2,"\=\?")<0) {from_to($dt2, "cp1251", "koi8-r") foreach $dt2; $subj = $dt2;} else {$subj = autodec($dt2);} } if ( $q eq "Return-Path:" ) { $ret = $dt3; ($nl, $ret) = split("<", $ret); ($ret) = split(">", $ret); } if ( $q eq "." ) { # $cid=$start*$mpp+$crnt; $cid=$stat2; if ($subj eq "") {$subj = "[Нет темы]";} print "\n"; $stat2 = $stat2 - 1; $stat1 = "headq"; $subj = ""; $from = ""; $ret = ""; $crnt = $crnt + 1; if ( $clr eq "0060a0" ) {$clr="005090"; $clr1="004080";} else {$clr="0060a0"; $clr1="005090";} } } if ( $stat2 eq "0"or $crnt eq $mpp and $page1 ne "all") { $pgs = ($msg / $mpp); if (int($pgs) ne $pgs) {$pgs = $pgs + 1;} $pgs = int($pgs); $pg = 0; $pgstr = "Страницы"; while ( $pg ne $pgs ) { if ($pg eq $start) {$clr = "#ffff00";} else {$clr = "#ffffff";} $pg = $pg + 1; $pgstr = sprintf ("%s %s", $pgstr, $pg-1, $pg); } $pgstr = sprintf ("%s Все",$pgstr); $stat1 = "end"; } if ( $stat1 eq "headq" ) { $stat1 = "headw"; print $serv "TOP $stat2 0\n"; } if ( $stat1 eq "end" ) { print "
$from ($ret)$subj

\n"; print "$pgstr
\n"; print "Выход
"; print $serv "QUIT\n"; exit 0; } if ( $par1 eq "quit" ) { my $cook = cookie( -name => 'mn.mail.auth', -value => 'null', -expires => '0', -domain => 'miranet.lan', -path => '/', ); #print "Content-type: text/html\n\n"; print header(-cookie=>$cook); print ""; } } sub autodec { my $dt2 = shift; ($edt1, $edt2) = split("=", $dt2); ($is, $cp, $t, $dat, $ie) = split (/\?/, $edt2); if ( $t eq "B" or $t eq "b") { $t = "B"; $dt2 = MIME::Base64::decode($dat); if ($cp ne "" ) {from_to($dt2, $cp, "koi8-r") foreach ($dt2);} } if ( $t eq "Q" or $t eq "q") { $t = "Q"; ($nl, $nl, $nl, $dat, $nl) = split (/\?/, $dt2); $dt2 = MIME::QuotedPrint::decode($dat); if ($cp ne "") {from_to($dt2, $cp, "koi8-r") foreach ($dt2);} } if ( $t ne "B" and $t ne "Q" and $cp ne "") {from_to($dt2, $cp, "koi8-r") foreach ($dt2);} return $dt2; }