/[sap_import]/mail2sap.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /mail2sap.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dpavlin, Tue Nov 19 12:16:02 2002 UTC revision 1.11 by dpavlin, Wed Apr 2 07:16:44 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/suidperl -w  #!/usr/bin/suidperl
2    
3  # read e-mail from stdit (pipe from /etc/aliases) and call SAP rfc function  # read e-mail from stdit (pipe from /etc/aliases) and call SAP rfc function
4  #  #
# Line 22  my $outdir = $config->{outdir} || die "c Line 22  my $outdir = $config->{outdir} || die "c
22  # temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!)  # temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!)
23  # for extraction of *ALL* attachements  # for extraction of *ALL* attachements
24  my $msgdir = $config->{msgdir} || die "config: no <msgdir> defined";  my $msgdir = $config->{msgdir} || die "config: no <msgdir> defined";
25    my $mntdir = $msgdir;
26    $msgdir .="/mime";
27  $msgdir .= "$$";        # append PID to make it unique  $msgdir .= "$$";        # append PID to make it unique
28  my $log = $config->{log} || die "config: no <log> defined";  my $log = $config->{log} || die "config: no <log> defined";
29    
30  # open log and redirect die to it...  # open log and redirect die to it...
31  open(LOG,">> $log") || warn "open log $log: $!";  open(LOG,">> $log") || warn "open log $log: $!";
32  local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] };  local $SIG{__DIE__} = sub { print LOG scalar localtime,$_[0] ; die $_[0] };
33    
34  umask 022;      # world readable  umask 022;      # world readable
35    
# Line 42  sub dump_entity { Line 44  sub dump_entity {
44      if (@parts) {       # multipart...      if (@parts) {       # multipart...
45          map { dump_entity($_) } @parts;          map { dump_entity($_) } @parts;
46      } else {            # single part...      } else {            # single part...
47  #       print "    Part: ", $ent->bodyhandle->path,          print LOG scalar localtime," Att: ", $ent->bodyhandle->path, " (", scalar($ent->head->mime_type), ")\n";
48  #             " (", scalar($ent->head->mime_type), ")\n";          if ($ent->head->mime_type =~ m,text/plain,i && $ent->bodyhandle->path !~ m/(Orders|edi)/i) {
         if ($ent->head->mime_type =~ m,text/plain,i) {  
49  #               open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!";  #               open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!";
50  #               while(<I>) { print LOG $_; }  #               while(<I>) { print LOG $_; }
51  #               close(I);  #               close(I);
# Line 62  sub dump_entity { Line 63  sub dump_entity {
63                  $new .= $suffix;                  $new .= $suffix;
64    
65                  rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!";                  rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!";
                 print LOG scalar localtime," $new\n";  
66    
67                  # now, call SAP rfc                  # now, call SAP rfc
68    
# Line 82  sub dump_entity { Line 82  sub dump_entity {
82    
83                  my $it = $rfc->discover($config->{sap}->{discover}) || die "discover: $!";                  my $it = $rfc->discover($config->{sap}->{discover}) || die "discover: $!";
84    
85                  $it->FILEPATH( $config->{sap}->{filepath} );                  foreach my $p ($config->{sap}->{params}) {
86                            foreach my $p_name (keys %{$p}) {
87                                    $it->$p_name($p->{$p_name});
88                            }
89                    }
90    
91                  $it->FILENAME( $new );                  $it->FILENAME( $new );
                 $it->PORT( $config->{sap}->{port} );  
92    
93                    print LOG scalar localtime," RFC: $new\n";
94                  $rfc->callrfc( $it );                  $rfc->callrfc( $it );
95    
96                  $rfc->close();                  $rfc->close();
# Line 100  sub dump_entity { Line 105  sub dump_entity {
105  sub main {  sub main {
106          my $file;          my $file;
107          my $entity;          my $entity;
108            
109          mkdir $msgdir,0755 || die "can't create $msgdir: $!";          chdir ($mntdir) || die "can't chdir to $mntdir: $!";
110            mkdir ($msgdir,0755) || die `id`."can't create $msgdir: $!";
111          die "problems with creation of directory $msgdir: $!" if (! -w $msgdir);          die "problems with creation of directory $msgdir: $!" if (! -w $msgdir);
112    
113          my $parser = new MIME::Parser;          my $parser = new MIME::Parser;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.26