#!/usr/bin/perl

## We assume you have uudeview installed. 
## We assume you have a public_html directory which your webserver has been
## properly configured to see. 

### This perl script is not properly secured since it is possible to make
### a weird configuration for the name of the fax file, which in theory
### could mess up the command line statements. Use at your own risk.   

my $User = "Mu_Username";
my $Temp = "/home/$User/Temp/fax";

system "cp /var/spool/mail/$User /home/$User/Temp/";
system "cp /dev/null /var/spool/mail/$User";
system "/usr/bin/uudeview -o -i -d -p /home/$User/tiff/ /home/$User/Temp/fax";
system "cp /dev/null /home/$User/Temp/fax";

my @Old_Pdfs = <;/home/$User/public_html/pdf/*.pdf>;; 
my $No = @Old_Pdfs;

foreach my $File (<;/home/$User/tiff/*.tif>;)
  {
  $No++;
  my $Ps = $File;
  $Ps =~ s/\.tif/\.ps/g;
  $Ps =~ s/tiff/ps/; 
  system "/usr/bin/tiff2ps $File >; $Ps";

  ### If you want to print this, uncomment
  #   system "lpr $Ps";

  my $Pdf = $Ps;
  $Pdf =~ s/\.ps/\.pdf/g;
  system "/usr/bin/ps2pdf $Ps $Pdf";

  ### Either choose to keep the default name of the file or number it
#  system "mv $Pdf /home/$User/public_html/pdf/";
  system "mv $Pdf /home/$User/public_html/pdf/$No.pdf";

  system "rm $Ps $File;";
  }

