// TODO Not sure who have priority, the ovars of the {}[] from the dial string.. But one of the problem I saw is when the call is transfered to the dialplan, FS does a CID flipping... So if you dialled with loopback/5145551212/domain/XML it would set XML as the caller id. Using origination_caller_id_number fix this issue... But if you want to override it, not sure if it work or not...
//switch_event_add_header(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_number", h->user); // TODO I'm also not a super fan of hard coding this... But if it can be overriden from the dial string, I guess it better than getting the XML from the loopback which is probably what most people will use
if(profile->profile_enabled==SWITCH_FALSE){
sql=switch_mprintf("DELETE FROM voicemail_originate WHERE c_user = '%q' and c_domain = '%q';",h->user,h->domain);
char*sql=switch_mprintf("SELECT c_user, c_domain, attempt_count FROM voicemail_originate where next_attempt <= '%"SWITCH_TIME_T_FMT"' AND (c_state='WAIT_FOR_NEXT_ATTEMPT' OR c_status='NEW')",local_epoch_time_now(NULL));