--- mail2sap.pl 2002/11/19 08:34:40 1.2 +++ mail2sap.pl 2003/02/04 13:03:07 1.8 @@ -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 # @@ -11,38 +11,28 @@ use SAP::Rfc; use Digest::MD5 qw(md5_hex); use MIME::Parser; +use XML::Simple; +use Data::Dumper; -# configuration +# read configuration from xml file +my $config = XMLin(); # directory in which attachemnts will be left -my $outdir = "/var/autofs/data/export_sigma"; +my $outdir = $config->{outdir} || die "config: on defined"; # temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) # for extraction of *ALL* attachements -my $msgdir = "/var/autofs/data/export_sigma/mime$$"; # temp -my $log = "/data/sap_sigma/orders.log"; +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] }; -# init SAP rfc -# -my $rfc = new SAP::Rfc( - ASHOST => 'cipkg', - USER => 'rfctest', - PASSWD => 'dinamo', - LANG => 'HR', - CLIENT => '200', - SYSNR => '20', - TRACE => '0' - ) || die "new: $!"; - - -# no user editable content beyond this point - umask 022; # world readable -$rfc->is_connected || die "SAP rfc: not connected"; #------------------------------------------------------------ # dump_entity - dump an entity's file info @@ -74,22 +64,43 @@ $new .= $suffix; rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; - print LOG scalar localtime," $new\n"; + my $prog = $0; + $prog =~ s/^.*\/([^\/])+$/$1/g; + print LOG scalar localtime," $prog $new\n"; # now, call SAP rfc - my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; + # init SAP rfc + # + my $rfc = new SAP::Rfc( + ASHOST => $config->{sap}->{ashost}, + USER => $config->{sap}->{user}, + PASSWD => $config->{sap}->{passwd}, + LANG => $config->{sap}->{lang}, + CLIENT => $config->{sap}->{client}, + SYSNR => $config->{sap}->{sysnr}, + TRACE => $config->{sap}->{trace} + ) || die "new: $!"; + + $rfc->is_connected || die "SAP rfc: not connected"; + + 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" ); $rfc->callrfc( $it ); + + $rfc->close(); } } } -$rfc->close(); #------------------------------------------------------------ # main @@ -97,8 +108,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;