sub single {
my @mess1 = @_;
my %param = ();
my $head = 1;
my($par,$val,$last);
my @mess = ();
while($mess1[0] eq \'\'){shift(@mess1);}
foreach(@mess1){
if($_ ne \'\' && $head){
if($_ !~ /^\\s{2,}/ && $_ !~ /^\\t/){
($par,$val) = split(/: /,$_,2);
$param{"\\L$par"} = $val;
$last = "\\L$par";
} else {
$_ =~ s/^\\s+//;
$_ =~ s/^\\t+//;
$param{$last}.=$_;
}
} else {
$head = 0;
push(@mess,$_);
}
}
while($mess[0] eq \'\'){shift(@mess);}
if(exists $param{\'content-type\'} && defined $param{\'content-type\'}){
if($param{\'content-type\'} =~ /^text\\/([^;]+)/){
$param{\'type\'} = $1;
($param{\'charset\'}) = ($param{\'content-type\'} =~ /charset=\\"?([^"]+)\\"?/);
$param{\'charset\'} = defined $param{\'charset\'}?$param{\'charset\'}:\'koi8-\';
if($param{\'charset\'} =~ /us-ascii/i || $param{\'charset\'} =~ /koi8-/i){
$param{\'charset\'} = \'koi\';
} elsif ($param{\'charset\'} =~ /windows/i){
$param{\'charset\'} = \'win\';
} elsif ($param{\'charset\'} =~ /iso/i){
$param{\'charset\'} = \'iso\';
} elsif ($param{\'charset\'} =~ /alt/i){
$param{\'charset\'} = \'alt\';
} else {
$param{\'charset\'} = \'koi\';
}
$param{\'tr_enc\'} = defined $param{\'content-transfer-encoding\'}?$param{\'content-transfer-encoding\'}:\'8bit\';
if($param{\'tr_enc\'} =~ /quoted-printable/i){
my @xtemp_mess = @mess;
@mess = ();
my $offs = -1;
for(my $t = 0; $t < scalar(@xtemp_mess); $t++){
if(defined $xtemp_mess[($t-1)] && $xtemp_mess[($t-1)] !~ /=$/){
$offs++;
}
$xtemp_mess[$t] =~ tr/_/ /;
$xtemp_mess[$t] =~ s/=([a-zA-Z0-9]{2})/pack("C",hex($1))/eg;
$mess[$offs].= $xtemp_mess[$t];
$mess[$offs] =~ s/=$//;
}
} elsif($param{\'tr_enc\'} =~ /base64/i){
@mess = dbase64(join(\'\',@mess));
}
@mess = translate($param{\'charset\'},\'win\',@mess);
if($param{\'type\'} eq \'html\'){
foreach(@mess){
if($_ =~ /\\ $_ =~ s/charset=[^"]+/charset=Windows-1251/;
}
}
}
open(X,">$tempfile") || die "Can\'t write $tempfile: $!\\n";
shift(@mess) until $mess[0] ne \'\';
foreach(@mess){
print X "$_\\n";
}
close X;
} elsif ($param{\'content-type\'} =~ /^multipart\\/([^;]+)/){
$param{\'type\'} = $1;
($param{\'bound\'}) = ($param{\'content-type\'} =~ /boundary=\\"([^"]+)\\"/);
my @temp_lines = ();
while($mess[0] !~ /^--$param{\'bound\'}/){shift(@mess);}
shift(@mess);
foreach(@mess){
if($_ =~ /^--$param{\'bound\'}/){
single(@temp_lines);
@temp_lines = ();
if($_ =~ /^--$param{\'bound\'}--/){last;}
} else {
push(@temp_lines,$_);
}
}
}
}
}
sub send_letter {
my($email,$from,$to,$subj) = @_;
$from = translit($from);
$subj = translit($subj);
$to = translit($to);
local $/ = \'\';
open(X,"$tempfile");
binmode(X);
my $text = ;
my $text2;
close X;
$text = clear_html($text);
$text = translit($text);
$text = "(F:$from T:$to S:$subj) ".$text;
if(length($text) > 160){$text2 = substr($text,160,160);}
$text = substr($text,0,160);
open(SENDMAIL,"|$sendmail");
print SENDMAIL <<"EOF";
From: $mail_as
To: $email
Subject: SMS part1
$text
EOF
close(SENDMAIL);
if(defined $text2 && $text2 ne \'\'){
open(SENDMAIL,"|$sendmail");
print SENDMAIL <<"EOF";
From: $mail_as
To: $email
Subject: SMS part2
$text2
EOF
close(SENDMAIL);
}
}
read_conf();
until($time_to_die){
foreach $user(sort keys(%users)){
if((stat("$mail_dir/$user"))[7] ne $size{$user}){
if((stat("$mail_dir/$user"))[7] > $size{$user}){
open(X,"$mail_dir/$user");
binmode(X);
seek(X,$size{$user},0);
@lines = ();
while(){
$_ =~ s/\\n//;
$_ =~ s/\\r//;
push(@lines,$_);
}
close X;
until($lines[0] ne \'\'){shift(@lines);}
shift(@lines);
($from,$to,$subj) = read_letter(@lines);
send_letter($users{$user},$from,$to,$subj);
}
$size{$user} = (stat("$mail_dir/$user"))[7];
}
}
sleep($timerate);
}