This what I got.
update to the index.lua script
````
-- Save the message to voicemail messages
if (message_length ~= nil and tonumber(message_length) > 2) then
    caller_id_name = string.gsub(caller_id_name, "'", "''");
    local sql = {}
    table.insert(sql, "INSERT INTO v_voicemail_messages ");
    table.insert(sql, "(");
    table.insert(sql, "voicemail_message_uuid, ");
    table.insert(sql, "domain_uuid, ");
    table.insert(sql, "voicemail_uuid, ");
    table.insert(sql, "created_epoch, ");
    table.insert(sql, "caller_id_name, ");
    table.insert(sql, "caller_id_number, ");
    table.insert(sql, "message_status, ");  -- Add this line to set message status
    if (storage_type == "base64") then
        table.insert(sql, "message_base64, ");
    end
    table.insert(sql, "message_length ");
    table.insert(sql, ") VALUES ( ");
    table.insert(sql, ":voicemail_message_uuid, ");
    table.insert(sql, ":domain_uuid, ");
    table.insert(sql, ":voicemail_uuid, ");
    table.insert(sql, ":start_epoch, ");
    table.insert(sql, ":caller_id_name, ");
    table.insert(sql, ":caller_id_number, ");
    table.insert(sql, "'saved', ");  -- Set status to saved
    if (storage_type == "base64") then
        table.insert(sql, ":message_base64, ");
    end
    table.insert(sql, ":message_length ");
    table.insert(sql, ")");
    sql = table.concat(sql, "\n");
    ````
    
    cleanup_vm.sh
    ````
#!/bin/bash
# Voicemail cleanup script for FusionPBX
# This script deletes voicemails older than a specified number of days unless tagged as saved in the database.
# Set default directory where voicemails are stored
VM_DIR="/var/lib/freeswitch/storage/voicemail/default"
# Set default retention period in days (modifiable)
DAYS_TO_KEEP=${1:-14}
# Database connection details
DB_USER="fusionpbx"        # Database user
DB_NAME="fusionpbx"        # Database name
DB_HOST="localhost"        # Database host (adjust if remote)
# Function to get saved voicemail files from the database
get_saved_voicemails() {
    psql -U "$DB_USER" -d "$DB_NAME" -h "$DB_HOST" -t -c "
        SELECT CONCAT('/default/', domain_name, '/', voicemail_id, '/msg_', voicemail_message_uuid, '.wav')
        FROM v_voicemail_messages
        JOIN v_voicemails ON v_voicemail_messages.voicemail_uuid = v_voicemails.voicemail_uuid
        JOIN v_domains ON v_voicemails.domain_uuid = v_domains.domain_uuid
        WHERE message_status = 'saved';"
}
# Get list of saved voicemails to exclude from deletion
saved_voicemails=($(get_saved_voicemails))
# Find and delete voicemails older than specified days if they are not saved
find "$VM_DIR" -type f -name "msg_*.wav" -mtime +$DAYS_TO_KEEP | while read -r vm_file; do
    # Check if the voicemail is in the saved list
    if [[ ! " ${saved_voicemails[*]} " =~ " ${vm_file#"$VM_DIR"} " ]]; then
        echo "Deleting old voicemail: $vm_file"
        rm -f "$vm_file"
    else
        echo "Skipping saved voicemail: $vm_file"
    fi
done
````