Voicemails will get deleted when moving them between folders using the ARI interface in the following circumstance:
I use Serge Mankovski's "Voicemail RSS" contribution which allows voicemails to be podcast. That contribution will iterate through the recordings in the voicemail directories and create mp3 files in the format below...
msg0000.7025f35d463ebbafa101db8a88c71b681aa8443d.mp3
msg0001.9a2755d835707fbfa72f41005d378e3d488c991b.mp3
Once those files are out there, the moving of files between folders will end up in one file getting moved and the rest getting deleted or overwritten because the algorithm that does the moving doesn't account for the long file name with the msg???? prefix. Even the wav and txt files are affected. If I move files from one folder to a destination folder using the interface, the destination folder will end up with files that have the following format:
msg00.b00a00e00da00d00c00b00f00c00b00ca00.mp00
msg00.b00ae00ed00cfa00fcf00a00f00a00b00b00b00f00.mp00
msg00.gsm
msg00.txt
msg00.WAV
msg00.wav
I believe since all the files are being copied over as msg00 the files are overwriting each other when they are copied. Since they get deleted from the source directory, the recordings are unrecoverable.
I believe the applicable code is in voicemail.module in the moveVoicemailData function. Even if you determine that you can't fix this in FreePBX, I'd appreciate some direction on what I'd need to change to fix it for me (I'm not that good with PHP), as the RSS component is critical. I've copied the unaltered FreePBX applicable code from voicemail.module below.
Thank you.
function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx) {
global $ASTERISK_VOICEMAIL_PATH;
$perm = fileperms($ASTERISK_VOICEMAIL_PATH);
$uid = fileowner($ASTERISK_VOICEMAIL_PATH);
$gid = filegroup($ASTERISK_VOICEMAIL_PATH);
// recieving path
$paths = split(';',$ASTERISK_VOICEMAIL_PATH);
$path_rx = appendPath($paths[0],$context_rx);
if (!is_dir($path_rx)) {
mkdir($path_rx, $perm);
chown($path_rx,intval($uid));
chgrp($path_rx,intval($gid));
}
$path_rx = appendPath($path_rx,$extension_rx);
if (!is_dir($path_rx)) {
mkdir($path_rx, $perm);
chown($path_rx,intval($uid));
chgrp($path_rx,intval($gid));
}
$path_rx = appendPath($path_rx,$folder_rx);
if (!is_dir($path_rx)) {
mkdir($path_rx, $perm);
chown($path_rx,intval($uid));
chgrp($path_rx,intval($gid));
}
// get recieving folder last message number
if (is_dir($path_rx)) {
$lastNum = -1;
$lastNumLen = 4;
$dh = opendir($path_rx);
while (false != ($filename = readdir($dh))) {
if($filename!="." && $filename!="..") {
$msg_path = $path_rx;
$msg_path = appendPath($msg_path,$filename);
if (is_file($msg_path)) {
$path_parts = pathinfo($msg_path);
$num = preg_replace("/[a-zA-Z]|\./",'', $path_parts['basename']);
if ($num > $lastNum) {
$lastNum = $num;
$lastNumLen = strlen($lastNum);
}
}
}
}
}
else {
$_SESSION['ari_error'] = sprintf(_("Could not create folder %s on the server"),$folder_rx);
return;
}
// copy files to new location, incrementing each message number
asort($files);
foreach($files as $key => $path) {
// get file parts for search
$path_parts = pathinfo($path);
$path = $path_parts['dirname'];
$path = fixPathSlash($path);
list($name,$ext) = split("\.",$path_parts['basename']);
if (is_dir($path)) {
$lastNum++;
$hdl = opendir($path);
while ($fn = readdir($hdl)) {
if (preg_match("/" . $name . "/",$fn)) {
$src = $path . $fn;
$path_parts = pathinfo($src);
$folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$path_parts['basename']);
$dst = appendPath($path_rx,$folder_rx);
if (is_writable($src) && is_writable($path_rx)) {
$perm = fileperms($src);
$uid = fileowner($src);
$gid = filegroup($src);
copy($src,$dst);
if (is_writable($dst)) {
chmod($dst, $perm);
chown($dst,intval($uid));
chgrp($dst,intval($gid));
}
unlink($src);
}
else {
$_SESSION['ari_error'] = sprintf(_("Permission denied on folder %s or %s"),$src,$path_rx);
return;
}
}
}
closedir($hdl);
}
}
}
/*