-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 22-Jul-2002/09:09 -0400, Chris Mason <[EMAIL PROTECTED]> wrote:
>I have a RH7.3 email server and a windows 2000 workstation with a HP
>4100 printer attached which functions as the network's printer. I have
>an email arrive everyday with an attached PDF. I would like the PDF to
>print on the windows printer automatically.
>
>I can procmail filter the email to make sure that only that email
>arrives, how can I process the PDF and how can I mount the windows
>printer on the server?
>BTW, there is no other printer on the Linux server.

Setup an SMB printer on the linux box using printconf:

  printconf-gui
or
  printconf-tui

The following perl script is quick, dirty, and untested. but it should be
enough to give some ideas. Just use the procmail filter to pipe the
message into this script:


#!/usr/bin/perl
#
# Detach a PDF document from an email message and print it.
#

$pid = $$;
$scriptname = `basename $0`;
chomp $scriptname;
$temppdf = "/tmp/$scriptname_$pid.pdf";
$tempps  = "/tmp/$scriptname_$pid.ps";
$printer = 'lp';

$foundbody    = 0;
$foundpdfpart = 0;
$foundpdf     = 0;
$pdfdone      = 0;

while ($line = <STDIN>) {
  if (! $foundbody) {
    chomp $line;
    if (length($line) == 0) {
      $foundbody = 1;
    }
    if ($foundbody) {
      if ($line =~ /^Content-Type: application\/pdf/) {
        $foundpdfpart = 1;
      }
      if ($foundpdfpart) {
        if (length($line) == 0) {
          $foundpdf = 1;
          open(PDF,"| mmencode -u > $temppdf");
        }
        if (($foundpdf) && (! $pdfdone)) {
          print "$line\n";
          if ($line =~ /^--/) {
            $pdfdone == 1;
            close(PDF);
            system("pdf2ps $temppdf $tempps");
            $result = system("lpr -P $printer $tempps");
            unlink($temppdf);
            unlink($tempps);
          }
        }
      }
    }
  }
}

exit $result;


- -- 
Anthony E. Greene <mailto:[EMAIL PROTECTED]%3E>
OpenPGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26  C484 A42A 60DD 6C94 239D
AOL/Yahoo Messenger: TonyG05    HomePage: <http://www.pobox.com/~agreene/>
Linux. The choice of a GNU generation <http://www.linux.org/>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Anthony E. Greene <mailto:[EMAIL PROTECTED]> 0x6C94239D

iD8DBQE9PMKBpCpg3WyUI50RAiLjAJ9XQcQcdwqaDwousgqwFBqXn/Z4RACgj+Xb
uHhM6FMAOVRFcFLWt4H0nIQ=
=bfGX
-----END PGP SIGNATURE-----



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to