MT#62544 add vmemailnotify wrapper

Change-Id: Id6e4b091889538a086fbd2e6709137c819b5c984
mr13.4
Richard Fuchs 1 year ago
parent fcedd54255
commit 2d0c676243

@ -13,3 +13,4 @@ install:
$(INSTALL_PROGRAM) vmnotify $(DESTDIR)/usr/bin/ngcp-vmnotify
$(INSTALL_PROGRAM) vmsmsnotify $(DESTDIR)/usr/bin/ngcp-vmsmsnotify
$(INSTALL_PROGRAM) recnotify $(DESTDIR)/usr/bin/ngcp-recnotify
$(INSTALL_PROGRAM) vmemailnotify $(DESTDIR)/usr/bin/ngcp-vmemailnotify

@ -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…
Cancel
Save