Simple hylafax client
use Fax::Hylafax::Client qw(sendfax); my $fax = sendfax( dialstring => '5555555555', docfile => '/usr/home/test/document.ps', );
This is a simple Perl client for HylaFAX fax server (www.hylafax.org). It communicates with the server directly through FTP-like protocol and thus does not require any HylaFAX software components to be installed on the client machine.
This method sends a fax job to the server. Returns \*(L"Client::Queued\*(R" object. Takes a hash of the following attributes:
Hostname of the server. Defaults to \*(L"localhost\*(R". [\s-1OPTIONAL\s0]
Connection port of the server. Defaults to \*(L"4559\*(R". [\s-1OPTIONAL\s0]
Username of the client. Defaults to \*(L"anonymous\*(R". [\s-1MAY\s0 \s-1BE\s0 \s-1REQUIRED\s0]
Password of the client. Defaults to \*(L"anonymous\*(R". [\s-1MAY\s0 \s-1BE\s0 \s-1REQUIRED\s0]
Destination string (number) to dial. [\s-1REQUIRED\s0]
Full pathname of the document file. This attribute takes a single filename (scalar) or a reference to an array of filenames. Document files must be in one of the native HylaFAX formats, i.e. Plain Text, PostScript, \s-1TIFF\s0 Class F, or \s-1PDF\s0. [\s-1REQUIRED\s0 unless you use \*(L"poll\*(R" option]
Full pathname of the cover page file. All notes about \*(L"docfile\*(R" apply, except it only takes one filename as scalar. [\s-1OPTIONAL\s0]
E-mail address of the person to be notified about the status of the job. Defaults to \*(L"user@hostname\*(R". [\s-1OPTIONAL\s0]
Controls the email notification messages from the server. Possible values: \*(L"none\*(R" - notify if error only, \*(L"done\*(R" - notify when done, \*(L"requeue\*(R" - notify if job is re-queued, \*(L"done+requeue\*(R". Defaults to \*(L"none\*(R". [\s-1OPTIONAL\s0]
If set to \*(L"1\*(R" connects to server in \s-1PASSIVE\s0 mode. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
Time when the fax should be sent. Possible values: \*(L"now\*(R" or date in format \*(L"\s-1YYYYMMDDHHMM\s0\*(R". It looks like this value must be in \s-1GMT\s0 time zone. Defaults to \*(L"now\*(R". [\s-1OPTIONAL\s0]
Kill the job if not successfully sent after this much time. Format \*(L"\s-1DDHHSS\s0\*(R". Defaults to \*(L"000259\*(R" (3 hours). [\s-1OPTIONAL\s0]
The maximum number of times to dial the phone. Defaults to \*(L"12\*(R". [\s-1OPTIONAL\s0]
The maximum number of times to retry sending a job once connection is established. Defaults to \*(L"3\*(R". [\s-1OPTIONAL\s0]
Set the transmitted page width in millimeters. Defaults to \*(L"216\*(R" (Letter size). [\s-1OPTIONAL\s0]
Set the transmitted page length in millimeters. Defaults to \*(L"279\*(R" (Letter size). [\s-1OPTIONAL\s0]
Set the vertical resolution in lines/inch to use when transmitting facsimile. High resolution equals to \*(L"196\*(R", low resolution equals to \*(L"98\*(R". Defaults to \*(L"196\*(R". [\s-1OPTIONAL\s0]
The amount of white space, in inches, that must be present at the bottom of a page before HylaFAX will attempt to truncate the page transmission. Defaults to \*(L"3\*(R". [\s-1OPTIONAL\s0]
The scheduling priority to assign to the job. Defaults to \*(L"127\*(R" (Normal). [\s-1OPTIONAL\s0]
Try to poll a fax from remote machine. Value can be an empty string or \*(L"selector [passwd]\*(R". [\s-1OPTIONAL\s0]
Sends \s-1SNPP\s0 page job to the server. Returns \*(L"Client::Queued\*(R" object. Takes a hash of the following attributes:
Same as in \*(L"sendfax\*(R".
Connection port of the server. Defaults to \*(L"444\*(R". [\s-1OPTIONAL\s0]
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Pager Identification Number as defined in \*(L"pagermap\*(R" file on the server. [\s-1REQUIRED\s0]
Text message to be sent (alfa-numeric pagers only). [\s-1OPTIONAL\s0]
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Priority level to assign to the job. Values can be \*(L"0-7\*(R" (0 being the highest). Defaults to \*(L"1\*(R" (Normal). [\s-1OPTIONAL\s0]
Request the status of a particular job. Returns \*(L"Client::Instant\*(R" object. Can take only the number of the job as an attribute or a hash of the following attributes:
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
\s-1ID\s0 of the job. [\s-1REQUIRED\s0]
Same as in \*(L"sendfax\*(R".
Remove job from the server (kill it). Returns \*(L"Client::Instant\*(R" object. Behaves like and has the same attributes as \*(L"faxinfo\*(R".
Request statistics from the server. Returns \*(L"Client::Instant\*(R" object. Takes a hash of the following attributes:
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
Same as in \*(L"sendfax\*(R".
If set to \*(L"1\*(R" displays additional status information for the server. This status typically has information such as the HylaFAX version, the physical location of the server machine, and an administrative contact for the server. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
If set to \*(L"1\*(R" displays the status of document files located in the docq directory on the server machine. The \*(L"filefmt\*(R" attribute defines the content and format of information reported with this option. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
If set to \*(L"1\*(R" displays the status of jobs in the send queue on the server machine. The \*(L"jobjmt\*(R" attribute defines the content and format of information reported with this option. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
If set to \*(L"1\*(R" displays the status of all jobs that have completed; i.e. those jobs located in the doneq directory on the server machine. The \*(L"jobfmt\*(R" attribute defines the content and format of information reported with this option. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
If set to \*(L"1\*(R" displays the receive queue status. The \*(L"rcvfmt\*(R" attribute defines the content and format of information reported with this option. Defaults to \*(L"0\*(R". [\s-1OPTIONAL\s0]
The format string to use when returning file status information. See \*(L"faxstat\*(R" man pages for details. [\s-1OPTIONAL\s0]
The format string to use when returning job status information. See \*(L"faxstat\*(R" man pages for details. [\s-1OPTIONAL\s0]
The format string to use when returning status information about received jobs. See \*(L"faxstat\*(R" man pages for details. [\s-1OPTIONAL\s0]
Returns true if the task was accepted. This only means the task request was successfully processed by the server. This does not always mean the task itself was successfully completed. Use \*(L"faxinfo\*(R" to check for that.
Returns responses from the last communication with the server. Userful for debugging.
Returns the status of the job at this particular moment.
Kills the job.
Returns the \s-1ID\s0 assigned to the job by the server.
Returns content returned by the server.
Specifies hostname of the server. Used in place of \*(L"host\*(R" attribute. Specifies connection port of the server. Used in place of \*(L"port\*(R" attribute. Username of the client. Used in place of \*(L"user\*(R" attribute. Password of the client. Used in place of \*(L"password\*(R" attribute. Specifies if \s-1PASSIVE\s0 connections should be used. Used in place of \*(L"passive\*(R" attribute. E-mail address where server notifications will be sent. Used in place of \*(L"notifyaddr\*(R" attribute.
Send a fax
use Fax::Hylafax::Client qw(sendfax);
my $fax = sendfax( host => 'remote.host.name', dialstring => '14151234567', docfile => '/usr/home/test/document.ps', coverfile => '/usr/home/test/cover.ps', notifyaddr => '[email protected]', );
if ($fax->success) { print "We are OK"; } else { print $fax->trace; }
Misc. examples
use Fax::Hylafax::Client qw(sendfax sendpage faxstat faxinfo faxrm);
$Fax::Hylafax::Client::Host = 'remote.server.hostname'; $Fax::Hylafax::Client::User = 'faxuser'; $Fax::Hylafax::Client::Password = '*password*'; $Fax::Hylafax::Client::NotifyAddr = '[email protected]';
my $fax = sendfax( dialstring => '14151234567', docfile => [ '/usr/home/test/document1.ps', '/usr/home/test/document2.ps', ], );
my $task_succeded = $fax->success ? "YES" : "NO"; my $server_responses = $fax->trace; my $job_id = $fax->jobid; my $current_job_status = $fax->faxinfo;
my $server_stats = faxstat( info => 1, active => 1 )->content; if (faxinfo($job_id)->content ne 'DONE') { print "We're not done yet";
$fax->faxrm;
# or
faxrm($job_id);
# or
my $task = faxrm( host => 'remote.server.hostname', user => 'faxuser', password => '*password*', jobid => $job_id, ); print $task->success ? "We killed it!" : "Server didn't like it: " . $task->trace; }
my $other_server_task = faxstats( host => 'other.server.host', user => 'bob', password => 'whatever' ); if ($other_server_task->success) { print $other_server_task->content; } else { print "Doh! We failed to get stats from the server: ", $other_server_task->trace; }
my $page = sendpage( pin => 'bob', message => 'Time to wake up', ); my $task_succeded = $page->success ? "YES" : "NO";
Alex Rak [email protected]
Copyright (c) 2003,2006 Alex Rak. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HylaFAX man pages <http://www.hylafax.org/>