mirror of https://github.com/sipwise/vmnotify.git
parent
fcedd54255
commit
2d0c676243
@ -0,0 +1,68 @@
|
||||
#!/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=?');
|
||||
|
||||
while (1) {
|
||||
$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($?);
|
||||
Loading…
Reference in new issue