--- mail2sap.pl 2002/11/19 09:24:55 1.4 +++ mail2sap.pl 2003/04/02 07:16:44 1.11 @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/suidperl # read e-mail from stdit (pipe from /etc/aliases) and call SAP rfc function # @@ -22,12 +22,14 @@ # temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) # for extraction of *ALL* attachements my $msgdir = $config->{msgdir} || die "config: no defined"; +my $mntdir = $msgdir; +$msgdir .="/mime"; $msgdir .= "$$"; # append PID to make it unique my $log = $config->{log} || die "config: no defined"; # open log and redirect die to it... open(LOG,">> $log") || warn "open log $log: $!"; -local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; +local $SIG{__DIE__} = sub { print LOG scalar localtime,$_[0] ; die $_[0] }; umask 022; # world readable @@ -42,9 +44,8 @@ if (@parts) { # multipart... map { dump_entity($_) } @parts; } else { # single part... -# print " Part: ", $ent->bodyhandle->path, -# " (", scalar($ent->head->mime_type), ")\n"; - if ($ent->head->mime_type =~ m,text/plain,i) { + print LOG scalar localtime," Att: ", $ent->bodyhandle->path, " (", scalar($ent->head->mime_type), ")\n"; + if ($ent->head->mime_type =~ m,text/plain,i && $ent->bodyhandle->path !~ m/(Orders|edi)/i) { # open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!"; # while() { print LOG $_; } # close(I); @@ -62,7 +63,6 @@ $new .= $suffix; rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; - print LOG scalar localtime," $new\n"; # now, call SAP rfc @@ -80,12 +80,17 @@ $rfc->is_connected || die "SAP rfc: not connected"; - my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; + my $it = $rfc->discover($config->{sap}->{discover}) || die "discover: $!"; + + foreach my $p ($config->{sap}->{params}) { + foreach my $p_name (keys %{$p}) { + $it->$p_name($p->{$p_name}); + } + } - $it->FILEPATH( "ZSIGMA" ); $it->FILENAME( $new ); - $it->PORT( "ZIDOC" ); + print LOG scalar localtime," RFC: $new\n"; $rfc->callrfc( $it ); $rfc->close(); @@ -100,8 +105,9 @@ sub main { my $file; my $entity; - - mkdir $msgdir,0755 || die "can't create $msgdir: $!"; + + chdir ($mntdir) || die "can't chdir to $mntdir: $!"; + mkdir ($msgdir,0755) || die `id`."can't create $msgdir: $!"; die "problems with creation of directory $msgdir: $!" if (! -w $msgdir); my $parser = new MIME::Parser;