#!/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; print "Content-type: text/html\n\n"; my $auth = cookie('mn.mail.auth'); ($user, $pass) = split (" ", $auth); $id = param("id"); 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", ); $stat="0"; $stat1="0"; $stat2="0"; $crlf = sprintf ("\n"); while ( <$serv> ) { $line = $_; ($q, $p) = split (" ", $line); if ($stat eq "0" and $q eq "+OK") { print $serv "USER $user\n"; $stat = "101"; } if ($stat eq "1" and $q eq "+OK") { print $serv "PASS $pass\n"; $stat = "102"; } if ($stat eq "2" and $q eq "+OK") { print $serv "RETR $id\n"; $stat = "103"; } if ($stat eq "3" and $q eq "+OK") { $stat="104"; } if ($stat eq "4" and $q eq ".") { print $serv "QUIT\n"; $stat="105"; } if ($stat eq "4") { $q = length($line); # get From if ($stat1 eq "0" and $from eq "") { ($nl, $from) = split("From:", $line); ($from1, $from2) = split("<",$from); $fr = sprintf("(%s", $from2); ($from1, $from2) = split(">",$fr); $fr = sprintf("%s)%s", $from1, $from2); if (index ($from,"\=\?")<0) {from_to($from, "cp1251", "koi8-r") foreach $from;} else {$from = autodec($from);} # $from = sprintf("%s %s", $from, $fr); } # get Subject if ($stat1 eq "0" and $subj eq "") { ($nl, $subj) = split("Subject:", $line); if (index ($subj,"\=\?")<0) {from_to($subj, "cp1251", "koi8-r") foreach $subj;} else {$subj = autodec($subj);} } # get Date if ($stat1 eq "0" and $date eq "") { ($nl, $date) = split("Date:", $line); } # get Content-Type if ($stat1 eq "0" and $type eq "") { ($nl, $type) = split("Content-Type:", $line); } if ($stat1 eq "0" and $type eq "") { ($nl, $type) = split("Content-type:", $line); } # get Charset if ($stat1 eq "0" and $char eq "") { ($nl, $char) = split("charset=", $line); ($nl, $tc, $nl) = split("\"", $char); if ($tc ne "") {$char = $tc;} ($char,$nl) = split(" ", $char); } # get Boundary if ($stat1 eq "0" and $boun eq "") { ($nl, $boun) = split("boundary=", $line); ($nl, $tb, $nl) = split("\"", $boun); if ($tb ne "") {$boun = $tb;} } # get Encoding if ($stat1 eq "0" and $enc eq "") { ($nl, $enc) = split("Content-Transfer-Encoding:", $line); $fenc = $enc; $qw1 = index($enc, "quoted-printable"); $qw2 = index($enc, "base64"); if ($qw1 > 0) {$enc = "Q";} if ($qw2 > 0) {$enc = "B";} if ($enc ne "Q" and $enc ne "B" and $fenc ne "") {$enc = " ";} } if ($q eq "2" and $stat1 eq "0" ) {$stat1 = "102";} # if ($q eq "2" and $stat1 eq "1" ) {$stat1 = "102";} if ($stat1 eq "2" ) { $date = autodec($date); $stat1 = "3"; print "
"; print ""; print ""; print ""; # if ($type ne "") {print "";} # if ($char ne "") {print "";} # if ($enc ne "") {print "";} print "
οΤ: $from
τΕΝΑ: $subj
δΑΤΑ: $date
Content-Type: $type
Charset: $char
Encoding: $enc

"; } if ($stat1 eq "3") { # Body ---------------------------------------------------------------------------------- if (index($type,";")>0) {($type,$nl) = split(";",$type);} if (index ($type,"multipart/alternative") > 0) { $stop = "------";} if (index ($type,"multipart/related") > 0) { $stop = "------";} if ($boun eq "" and $stat2 eq "0") { $stat2="4"; print "
"; $flg = "1"; if ($ntype eq "") {$ntype = $type;}}
	if ($boun ne "" and $stat2 eq "0") { $fl = index ($line, $boun);}
	if ($fl > "0" and $stat2 eq "0") 
	    {
	    if (index ($type,"multipart/alternative") > 0) { $stat2="103"; $stop = "------";}
	    if (index ($type,"multipart/related") > 0) { $stat2="101"; $stop = "------";}
	    }
#	if ($q eq "2" and $stat2 eq "0") {$stat2 = "103";}

	if ($stat2 eq "11")
	    {
	    $fl = index ($line, $boun);
	    if ($fl > "0") { $stat2 = "102";}
	    }

	if ($stat2 eq "1")
	    {
	    ($nl, $boun) = split("boundary=", $line); 
    	    ($nl, $tb, $nl) = split("\"", $boun); 
	    if ($tb ne "") {$boun = $tb; $stat2 = "110";}
#	    print "$line
$boun
"; } if ($stat2 eq "10") { $fl = index ($line, $boun); if ($fl >= "0") { $stat2 = "103";} } if ($boun ne "" and $stat2 eq "2") { $fl = index ($line, $boun);} if ($fl > "0" and $stat2 eq "2") { $stat2 = "103"; } if (index($line,"Type: image/")>0) { ($nl,$ntype) = split("Content-Type: ", $line); # ($ntype,$nl) = split(";", $ntype); $type1 = $ntype; $type = $ntype; # print "--$ntype--"; $stat2="103"; } if ($stat2 eq "3") { $q = length($line); ($nl, $nnm) = split("name=", $line); if ($nnm ne "") {($nl,$name,$nl) = split("\"", $nnm);} if ($char eq "") { ($nl, $char) = split("charset=", $line); ($nl, $tc, $nl) = split("\"", $char); if ($tc ne "") {$char = $tc;} ($char,$nl) = split(" ", $char); } if ($ntype eq "") { ($nl, $ntype) = split("Content-Type:", $line); } if ($ntype eq "") { ($nl, $ntype) = split("Content-type:", $line); } if ($ext eq "") { ($type1,$nl) = split(";", $type1); ($nl,$ext) = split("/", $type1); } # get Content-Type if ($type1 eq "") { ($nl, $type1) = split("Content-Type:", $line); } if ($type1 eq "") { ($nl, $type1) = split("Content-type:", $line); } if ($enc eq "") { ($nl, $enc) = split("Content-Transfer-Encoding:", $line); $fenc = $enc; $qw1 = index($enc, "quoted-printable"); $qw2 = index($enc, "base64"); if ($qw1 > 0) {$enc = "Q";} if ($qw2 > 0) {$enc = "B";} if ($enc ne "Q" and $enc ne "B" and $fenc ne "") {$enc = " ";} } if ($char ne "") { ($nl, $tc, $nl) = split("\"", $char); if ($tc ne "") {$char = $tc;} } if ($q < "3") { $stat2="104"; print ""; if (index($type1,"text/html")>0) { print "
$type1
"; $html="1";} else {print "
";} if ($ntype eq "") {$ntype = $type;} ($ntype, $nl) = split(";", $ntype); if (index($ntype, "text/plain")>0) {if ($flg eq "") {print "
"; $flg = "1";}}
		}
	    }

	# Print Body
	if ($stat2 eq "4" and $stop ne "" and index($line, $stop) eq "0")
	    { 
	    $stat2 = "11";
	    if (index($type1, "text/html")>0 or $html ne "") {print ""; $html="";}
	    }
	if ($stat2 eq "5" and $stop ne "" and index($line, $stop) eq "0"){ $stat2 = "11"; close(FILE); print "
";} # print "-= $stat2 -- " . index($type1, "image") . "=-"; if ($stat2 eq "4" and index($type1, "image") ne "-1") { $stat2="5"; # my @table=('A'..'Z','1'..'9','a'..'z');$name="";for($ii=0;$ii<8;$ii++){$name.=$table[int(rand(scalar@table))]} open(FILE,">./images/$name"); } if ($stat2 eq "5") { $enc = "B"; $char="koi8-r"; $line = sprintf("=?%s?%s?%s", $char, $enc, $line); $line = autodec($line); print (FILE "$line"); } if ($stat2 eq "4") { if (index ($enc, "7bit") > 0 or index ($enc, "8bit") > 0) {$enc = " ";} if ($enc eq "") {$enc = " ";} if (index($char,";")>0) {($char,$nl) = split(";", $char);} if ($enc eq " " and $char ne "") { from_to($line, $char, "koi8-r") foreach $line ;} if ($enc ne " ") { $line = sprintf("=?%s?%s?%s", $char, $enc, $line); $line = autodec($line); if (index($line, chr(10)) > 0 and index($ntype, "text/plain")<0) { ($l1, $l2) = split (chr(10), $line, 1); $line = sprintf("%s
%s",$l1, $l2); } } if (index($line,"http://--") ne "-1") { ($l1, $l2) = split("http://", $line); ($l3, $l4) = split(" ", $l2, 1); $line = sprintf("%shttp://%s%s", $l1, $l3, $l3, $l4); } if ($enc eq " " and index($ntype, "text/plain") < 0) {print "$line
";} else {print "$line";} } if ($stat2 eq "11") { $fl = index ($line, $boun); if ($fl >= "0") { $stat2 = "103";} $type1 = ""; $ext = ""; } # inc stats -------------------------------------------------------------- if ($stat2 > "100") {$stat2 = $stat2 - 100;} } if ($stat1 > "100") {$stat1 = $stat1 - 100;} } if ($stat > 100) {$stat = $stat - 100;} } print "
"; open(patt,"<./patt_n2.html")||die "Pattern file 2 not found"; while() { print; } close(patt); 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; }