#!/usr/bin/perl -w
# Interfax Namespace
$NS = "http://www.interfax.cc";
# Interfax Gateway
$HOST = "http://ws.interfax.net/dfs.asmx";
# We require SOAP, obviously.
use SOAP::Lite;
use File::stat;
# Instantiate a new SOAP instance,
#
# on_action is overloaded to fixup differences between SOAP::Lite
# (our Perl client) and Microsoft .NET namespace (the Interfax server)
# differences in SOAPAction header.
#
# SOAP::Lite (our client) defaults to http://www.interfax.cc#SendCharFax
# .NET (server) requires http://www.interfax.cc/SendCharFax (without the #)
my $interfax = SOAP::Lite -> uri($NS)
-> on_action( sub { join "/", @_ } )
-> proxy($HOST);
# Need newer schema to support base64 binary
$interfax ->xmlschema('2001');
# SendCharFax needs xmlns attribute set to the namespace
# (http://www.interfax.cc) to make the Interfax gateway happy.
# Note the lowercase f in the word fax for the server identifier
my $method = SOAP::Data->name('SendfaxEx_2') -> attr({xmlns =>
$NS});
# Interfax Authentication Parameters
# Username, Interfax Account Name
$Username = "";
# Password, Interfax Account Password
$Password = "";
# Create a list (array) of fax recipient numbers
$Recipient[0] = "";
#$Recipient[1] = "";
# FaxNumbers, semi-colon delimited list of recipient fax numbers
$FaxNumbers = join ";", @Recipient;
# Create a list (array) of filenames to send
$File[0] = "";
#$File[1] = "";
#$File[0] = "bicycle.jpg";
# FileTypes, semi-colon delimited list of file types of FilesData item
$count = 0;
foreach $Filename (@File) {
if(-r $Filename) {
$Size = stat($Filename)->size;
# Determine the file's size
print "File $Filename is $Size bytes long, ";
# Determine the file's Extension
($Dot, $Ext) = $Filename =~ m/(\.)([^.]*$)/;
$Dot = "is ignored";
print "and has $Ext Extention\n";
open FILE, "<$Filename";
binmode FILE;
$FileData[$count] = "";
$Length = read FILE, $FileData[$count], $Size;
if($Length != $Size) {
$FileData[$count] = "";
print "Problem reading $Filename, skipping.\n";
}
else {
push @FileSize, $Size;
push @Extensions, $Ext;
$count++;
}
close FILE;
}
else {
print "File $Filename doesn't exist, skipping.\n";
}
}
# FileSizes, semi-colon delimited list of length of each FilesData item
$FileSizes = join ";", @FileSize;
$FileTypes = join ";", @Extensions;
$FilesData = join "", @FileData;
# Postpone, Schedule faxing for a specified date/time
# For immediate faxing use 2000-01-01T00:00:00-00:00
$Postpone = "2000-01-01T00:00:00-00:00"; # for example, 2003-12-18T10:00:00-05:00
# CSID, fax identifier of 23 characters maximum
$CSID = '';
# Subject, 60 characters maximum, not sent, informational purposes only
$Subject = '';
# Email address to receive confirmation (optional)
$ReplyAddress = '';
# Miscellaneous Fax Options
$PageSize = "A4";
$PageOrientation = "Portrait";
$IsHighResolution = "0";
$IsFineRendering = "0";
# Set our SendCharFax parameters including our fax message (Data)
# and its file type of TXT for text.
my @params = ( SOAP::Data->name(Username => SOAP::Data->type(string
=> $Username)),
SOAP::Data->name(Password => SOAP::Data->type(string => $Password)),
SOAP::Data->name(FaxNumbers => SOAP::Data->type(string => $FaxNumbers)),
# SOAP::Data->name(Contacts => SOAP::Data->type(string => "")),
SOAP::Data->name(FilesData => SOAP::Data->type(base64 => $FilesData)),
SOAP::Data->name(FileTypes => SOAP::Data->type(string => $FileTypes)),
SOAP::Data->name(FileSizes => SOAP::Data->type(string => $FileSizes)),
SOAP::Data->name(Postpone => SOAP::Data->type(string => $Postpone)),
# SOAP::Data->name(RetriesToPerform => SOAP::Data->type(string =>
"3")),
SOAP::Data->name(CSID => SOAP::Data->type(string => $CSID)),
# SOAP::Data->name(PageHeader => SOAP::Data->type(string => "1")),
# SOAP::Data->name(JobID => SOAP::Data->type(string => "1")),
SOAP::Data->name(Subject => SOAP::Data->type(string => $Subject)),
SOAP::Data->name(ReplyAddress => SOAP::Data->type(string => $ReplyAddress)),
SOAP::Data->name(PageSize => SOAP::Data->type(string => $PageSize)),
SOAP::Data->name(PageOrientation => SOAP::Data->type(string => $PageOrientation)),
SOAP::Data->name(IsHighResolution => SOAP::Data->type(boolean =>
$IsHighResolution)),
SOAP::Data->name(IsFineRendering => SOAP::Data->type(boolean =>
$IsFineRendering)) );
# Dispatch and save result
# This actually does the transaction with the gateway server
my $result = $interfax->call($method => @params)->result;
# Hash of possible error messages
$error{'-112'} = "No valid recipients added";
$error{'-123'} = "No valid documents attached";
$error{'-150'} = "Internal system error";
$error{'-1002'} = "Number of types does not match "
. "number of document sizes string";
$error{'-1003'} = "Authentication error";
$error{'-1005'} = "Transaction does not exist";
$error{'-1007'} = "Size value is not numeric or not greater than 0";
$error{'-1008'} = "Total size does not match filesdata length";
$error{'-1009'} = "Image not available";
# If the fax was submitted successfully, display its ID
# else, print out the error message for the result code
if($result > 0) {
print "Success. Fax submitted and given a transaction ID of $result.\n";
}
else {
if($error{$result}) {
$message = $error{"$result"};
}
else {
$message = "Unknown error returned from server.";
}
print "Error [$result] $message\n";
}
# end of file