X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=a7cd471760ebbc4ae0cd9a46ef83988daf131ce3;hp=71fe7e712f8df260709625d351e5afb2c1651cf3;hb=18c025613fa052cf4ba8d484f1296cc2a1719a24;hpb=30189fa2e5987bafeb4714a83b7f130c568b221c diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 71fe7e712..a7cd47176 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -5,7 +5,7 @@ use vars qw ( @ISA @EXPORT_OK ); use Exporter; @ISA = qw( Exporter ); -@EXPORT_OK = qw( send_email ); +@EXPORT_OK = qw( send_email send_fax ); =head1 NAME @@ -50,6 +50,7 @@ use Date::Format; use Mail::Header; use Mail::Internet 1.44; use MIME::Entity; +use Fax::Hylafax::Client; use FS::UID; FS::UID->install_callback( sub { @@ -111,6 +112,77 @@ sub send_email { } +=item send_fax OPTION => VALUE ... + +Options: + +I - (required) 10-digit phone number w/ area code + +I - (required) Array ref containing PostScript or TIFF Class F document + +-or- + +I - (required) Filename of PostScript TIFF Class F document + +...any other options will be passed to L + + +=cut + +sub send_fax { + + my %options = @_; + + die 'HylaFAX support has not been configured.' + unless $conf->exists('hylafax'); + + my %hylafax_opts = map { split /\s+/ } $conf->config('hylafax'); + + die 'Called send_fax without a \'dialstring\'.' + unless exists($options{'dialstring'}); + + if (exists($options{'docdata'}) and ref($options{'docdata'}) eq 'ARRAY') { + my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $fh = new File::Temp( + TEMPLATE => 'faxdoc.'. $options{'dialstring'} . '.XXXXXXXX', + DIR => $dir, + UNLINK => 0, + ) or die "can't open temp file: $!\n"; + + $options{docfile} = $fh->filename; + + print $fh @{$options{'docdata'}}; + close $fh; + + delete $options{'docdata'}; + } + + die 'Called send_fax without a \'docfile\' or \'docdata\'.' + unless exists($options{'docfile'}); + + #FIXME: Need to send canonical dialstring to HylaFAX, but this only + # works in the US. + + $options{'dialstring'} =~ s/[^\d\+]//g; + if ($options{'dialstring'} =~ /^\d{10}$/) { + $options{dialstring} = '+1' . $options{'dialstring'}; + } else { + return 'Invalid dialstring ' . $options{'dialstring'} . '.'; + } + + my $faxjob = &Fax::Hylafax::Client::sendfax(%options, %hylafax_opts); + + if ($faxjob->success) { + warn "Successfully queued fax to '$options{dialstring}' with jobid " . + $faxjob->jobid; + } else { + return 'Error while sending FAX: ' . $faxjob->trace; + } + + return ''; + +} + package Mail::Internet; use Mail::Address; @@ -191,6 +263,8 @@ This package exists. L, L, L, the base documentation. +L + =cut 1;