#!/usr/bin/perl
# -------------------------------------------------------------------
# "/usr/lib/cups/pdf/sendpdf":
# Parameter: Username, PDF File
# -------------------------------------------------------------------
use MIME::Entity;

# Get the ARGS
$to = $ARGV[0];
$pdffile = $ARGV[1];

# Set some variables
$mailpipe = '| /usr/sbin/sendmail -t -oi';
$from = "pdfprinter";
$subject ="PDF File";
$content = "Your PDF print";

# create the mail
my $mail = MIME::Entity->build(
		Type	=> 'text/plain',
		From	=> $from,
		To	=> $to,
		Subject	=> $subject,
		Data	=> $content
);

# Attach the pdf file
$mail->attach(	Path	=> $pdffile,
		Type	=> 'application/pdf',
		Encoding => 'base64'
);

# Open mailpipe and send the mail
open( MAIL, "$mailpipe" ) or die "Could not open mailpipe \"$mailpipe\" !\n";
$mail->print(\*MAIL);
close( MAIL );

exit( 0 );
