#!/usr/bin/perl use strict; use MIME::Lite; require "/local/freeswitch/bin/hook-libs.pl"; our $env; our $session; my $addr = $session->getVariable("fax_notify_address"); my $to = $session->getVariable("destination_number"); my $from = $session->getVariable("caller_id_number"); my $fromname = $session->getVariable("caller_id_name"); my $debug = 0; if ($debug) { my $sid = $session->getVariable("session_id"); if ( int($sid) eq $sid ) { open( my $out, "|sort > /tmp/notify-${sid}.txt" ); print $out $env->serialize; close($out); } } my $direction = $session->getVariable("direction"); my $cause = $session->getVariable("hangup_cause"); if ( $direction eq "inbound" || $cause eq "NORMAL_UNSPECIFIED" ) { # ignore } else { my $time = scalar( localtime(time) ); my $fax_status = $session->getVariable("fax_success"); my $status_msg = "Sent OK"; if ( $fax_status != 1 ) { $status_msg = "Failed"; } my $result = $session->getVariable("fax_result_text"); freeswitch::console_log( "info", "sending fax status notify ($status_msg) for call from $from to $to to address $addr\n" ); my $msg = MIME::Lite->new( From => "freeswitch\@mst.edu", To => $addr, Subject => "Fax status ($status_msg) for fax to ($to) at ($time)", Type => "multipart/mixed" ); if ( !$result ) { $result = "Hangup Cause (" . $session->getVariable("hangup_cause") . ")"; } my $content = <getVariable($var); }; $content .= "Variable($var): " . $tmp . "\n"; freeswitch::console_log( "info", "fax status notify ($var => $tmp)\n" ); } $msg->attach( Type => 'TEXT', Data => $content, ); &stack_max(); $msg->send(); &stack_restore(); freeswitch::console_log( "info", "done sending fax status notify for call from $from to $to to address $addr\n" ); } # Finish with a true status 1;