
| Current Path : /var/www/web-klick.de/dsh/50_dev2017/1300__perllib/DivBasicF/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_dev2017/1300__perllib/DivBasicF/MailComSimple.pm |
package DivBasicF::MailComSimple;
use strict;
use vars qw(@ISA);
use DivBasicF::COM;
use DivBasicF::Mailbox;
use Server::frezthaw;
use MIME::Entity;
use Data::Dumper;
@ISA = qw(DivBasicF::COM);
#******************************************************************
sub init {
my $self = shift;
my $pars = $self->{'PARS'};
$self->{'MAILBOX'} = shift(@$pars);
if ($self->{'MAILBOX'} =~ /^(.*?)\,(.*)$/) {
$self->{'FROM'} = $2;
$self->{'MAILBOX'} = $1;
}
if ($self->{'FROM'} =~ /^(.*)\,(.*)/) {
$self->{'SIGNATURE'} = $2;
$self->{'FROM'} = $1;
}
$self->connection(shift(@$pars));
$self->{'WAIT_TIME'} = shift(@$pars); # Maximale Antwort-Wartezeit in Minuten
$self->{'FREQUENZ'} = shift(@$pars); # Abfrageintervall pro Sekunde
$self->{'SERIAL'} = shift(@$pars); # Optionaler Serialisierer/Deserialisierer
}
#******************************************************************
sub msg {
my $self = shift;
my $text = shift;
my $o = time();
my $msg_id = sprintf("%04u",(localtime($o))[5]+1900) .
sprintf("%02u",(localtime($o))[4]+1) .
sprintf("%02u",(localtime($o))[3]) .
sprintf("%02u",(localtime($o))[2]) .
sprintf("%02u",(localtime($o))[1]) .
sprintf("%02u",(localtime($o))[0]) . "." . int rand(99999999);
print "MSG: " . $self->get_connection() . "\n";
$o = [split(/,/,$self->get_connection())];
my $pars = [ 'Type' => "multipart/mixed",
'From' => $self->{'FROM'},
'To' => $o->[0],
'Message-ID' => $msg_id,
'Subject' => "MailComSimple-Request"];
if ($o->[1]) {
push(@$pars,'In-Reply-To:');
push(@$pars,$o->[1]);
}
$msg_id = $o->[0] . "," . $msg_id;
my $signature = $self->{'SIGNATURE'};
my $files = [];
foreach $o (@$text) {
if (-f $o) {
push(@$files,$o);
if ($o =~ /^(.*)[\/\\](.*)$/) { $o = $2; }
push(@$files,$o);
}
elsif ($o =~ s/^From\://) {
$pars->[3] = $o;
}
elsif ($o =~ s/^To\://) {
$pars->[5] = $o;
}
elsif ($o =~ s/^Subject\://) {
$pars->[9] = $o;
}
elsif ($o =~ s/^Signature\://) {
$signature = $o;
}
else {
push(@$files,[$o]);
}
}
my $message = MIME::Entity->build(@$pars);
while (@$files) {
if (ref($files->[0])) {
$message->attach(Data => $files->[0]->[0]);
shift(@$files);
} else {
$message->attach(Path => shift(@$files), Filename => shift(@$files));
}
}
# $message->sign(); --> $signature
$message->send();
$self->connection($msg_id);
}
#*********************************************************************
sub get {
my $self = shift;
my $wait_time = shift;
my $frequenz = shift;
my ($cycles,$interval) = $self->cycles_interval();
my $msg_id;
if ($self->get_connection() =~ /,(.*)$/) {
$msg_id = $1;
}
print "GET: " . $self->get_connection() . "\n";
$self->lock() if (!($self->{'READ'}));
my $zaehler = 0;
my $message; my @parts; my $o1;
my $o = DivBasicF::Mailbox->new($self->{'MAILBOX'});
#print "look for ... $msg_id\n";
# print "MMM: $msg_id\n";
while (0 == 0) {
$message = $o->message("In-Reply-To",$msg_id);
if ($message) {
@parts = $message->parts("ALL");
foreach $o1 (@parts) {
$o1 = join("",@{$o1->body()});
}
$o1 = $message->head();
$self->connection($o1->get("From") . "," . $o1->get("Message-ID"));
$self->unlock();
return([@parts]);
}
$zaehler = $zaehler + 1;
return("___WAIT_UNKNOWN___") if ($zaehler > $cycles);
select(undef,undef,undef,$interval); # sleep 1;
}
}
#*********************************************************************
1;