mirror of https://github.com/sipwise/vmnotify.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.7 KiB
70 lines
1.7 KiB
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Config::Any;
|
|
use DBI;
|
|
|
|
my $CONF_FILE = '/etc/ngcp-vmnotify/vmnotify.conf';
|
|
|
|
my %CONFIG = %{
|
|
Config::Any->load_files({
|
|
files => [ $CONF_FILE ],
|
|
use_ext => 1
|
|
})->[0]->{$CONF_FILE}
|
|
or die("$0 error: Cannot load config $CONF_FILE: $!");
|
|
};
|
|
|
|
# pass-through mode
|
|
if (($CONFIG{TRANSCRIBE} // 'no') ne 'yes') {
|
|
exec(@ARGV);
|
|
die("$0 error: exec '@ARGV' failed: $!");
|
|
}
|
|
|
|
# read in email body
|
|
my $email;
|
|
{
|
|
local $/ = undef;
|
|
$email = <STDIN>;
|
|
}
|
|
|
|
my ($uuid) = $email =~ /^X-Asterisk-VM-Extension: (\S+)\r?$/m;
|
|
my ($msgnum) = $email =~ /^X-Asterisk-VM-Message-Num: (\d+)\r?$/m;
|
|
|
|
# transcript replacement wanted?
|
|
if ($email =~ /^(.*)\@\@\@TRANSCRIPT\@\@\@(.*)$/s) {
|
|
my ($head, $tail) = ($1, $2);
|
|
my $transcript = '(unavailable)';
|
|
|
|
my $dsn = "DBI:mysql:database=kamailio;host=$CONFIG{DB_HOST};port=$CONFIG{DB_PORT}";
|
|
my $dbh = DBI->connect($dsn, $CONFIG{DB_USER}, $CONFIG{DB_PASS});
|
|
|
|
if ($dbh && $uuid && defined($msgnum)) {
|
|
my $sth = $dbh->prepare('select transcript, transcript_status from voicemail_spool where mailboxuser=? and msgnum=?');
|
|
|
|
my $end = time() + ($CONFIG{TRANSCRIPT_POLL_LIMIT} || 120);
|
|
while (time() < $end) {
|
|
$sth->execute($uuid, $msgnum - 1);
|
|
my $row = $sth->fetchrow_arrayref();
|
|
$sth->finish();
|
|
if ($row && $row->[1] eq 'done') {
|
|
$transcript = $row->[0];
|
|
last;
|
|
}
|
|
sleep($CONFIG{TRANSCRIPT_POLL_INTERVAL} || 5);
|
|
}
|
|
}
|
|
|
|
$email = $head . $transcript . $tail;
|
|
}
|
|
|
|
# spawn process and feed in email
|
|
my $fh;
|
|
if (!open($fh, '|-', @ARGV)) {
|
|
die("$0 error: exec '@ARGV' failed: $!");
|
|
}
|
|
|
|
print $fh $email;
|
|
close($fh);
|
|
exit($?);
|