--- mail2sap.pl 2002/11/18 14:23:39 1.1 +++ mail2sap.pl 2002/11/19 08:34:40 1.2 @@ -8,9 +8,9 @@ use strict; use vars qw($Msgno); +use SAP::Rfc; use Digest::MD5 qw(md5_hex); use MIME::Parser; -use SAP::Rfc; # configuration @@ -21,6 +21,12 @@ my $msgdir = "/var/autofs/data/export_sigma/mime$$"; # temp my $log = "/data/sap_sigma/orders.log"; +# 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', @@ -31,18 +37,12 @@ TRACE => '0' ) || die "new: $!"; -my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; - -$it->FILEPATH( "ZSIGMA" ); -$it->PORT( "ZIDOC" ); # no user editable content beyond this point umask 022; # world readable -open(LOG,">> $log") || warn "log $log: $!"; - -$rfc->is_connected || die "not connected"; +$rfc->is_connected || die "SAP rfc: not connected"; #------------------------------------------------------------ # dump_entity - dump an entity's file info @@ -67,12 +67,23 @@ $new=~s/ +/_/g; $new=~s/^.*\/([^\/]+)$/$1/g; $new=~s/[^a-zA-Z._0-9]//g; + + # never try to overwrite file + my $suffix = ""; + while (-e "$outdir/$new$suffix") { $suffix++; } + $new .= $suffix; + rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; print LOG scalar localtime," $new\n"; # now, call SAP rfc - $it->FILENAME( "$new" ); + my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; + + $it->FILEPATH( "ZSIGMA" ); + $it->FILENAME( $new ); + $it->PORT( "ZIDOC" ); + $rfc->callrfc( $it ); } }