Managing full voicemail inboxes

We’re trying to figure out what exactly to do with users that receive vm to email but will not allow us to have the system delete them after emailing them. Deleting recordings without the client’s permission is not an option. I see this happening in two steps:

  1. At the very least I’d like to have the system send out an email informing the user that his/her mailbox is almost full (say 80% or 90%) and when it is completely full. Maybe even every time the voicemail isn’t saved because of a full mailbox.

  2. This one is open to suggestions but I thought maybe just moving the messages from the inbox to the “old” folder after the message gets emailed would suffice. Would probably couple this with another email informing the user that they X many voicemails taking up space (once above some threshold like 20 messages). This one is probably equally important because of the bug that assumes an inbox is full because it has a message 99 in it (or maxmsg - 1).

All suggestions welcome. Thanks.

in /etc/asterisk/voicemail.conf

you can increase the number of messages with

maxmsg = 1000

do that in:-

https://yourbox/admin/config.php?display=voicemail&action=settings

I temporarily upped one of the worst offenders to 200 but that’s not a permanent solution as these people will keep ignoring the inbox. I’ve mentioned to several people that they can manage the voicemails online, which they already should know by the email that gets sent with each VM. They all agree that they do need some prodding occasionally to clean up the inbox and was hoping to have the system do that for me.

If there are no simple turn key solutions for this (I can’t be the only one that has this issue) then can someone point me towards some resources for learning about how the system monitors voicemail and how it sends out the emails?

The message info is saved in the following file
/var/spool/asterisk/voicemail/default/{EXTEN}/INBOX/msg{NUMBER}.txt
I am not an expert on VM but I believe if there is no TXT file then the message doesn’t exist as far as vm is concerned.

So you could do

/var/spool/asterisk/voicemail/default/{EXTEN}/INBOX/msg{NUMBER}.txt | wc -l 

To get a mailbox count then do some math count/max*100
Then if the math result is > 75 then email

Thanks, that’s easier than what I was imagining. I was thinking of pulling the info directly from the MySQL database but this could work just as well. Basically set up a recursive function that maybe once a week goes through each inbox and if it’s over the threshold send out an email to that user with how many messages are in the inbox and while we’re at it the saved and old folders as well.

How about getting the system renumber the messages so that the presence of msg0099.txt doesn’t automatically make the mailbox full? I think the system has the ability to do that since when you dial into vm it tells you the actual number of messages in the folder, and when you delete msg0055.txt it will say “message 3 deleted” (If msg0055 is only the third message in there).

Quick update: as a temporary solution until I get this script properly written I’ve changed the body of the email that gets sent out for voicemails to include the number of messages in the inbox. It was pointed out to me that the file /etc/asterisk/vm_email.inc has some handy functions in it that you might not be aware of that aren’t used by default.

VM_NAME is the name on the extension
VM_DUR is the length of the message
VM_MAILBOX is the extension number
and
VM_DATE is the time and date of the message

but there’s also a function VM_MSGNUM that returns the total amount of voicemails in the inbox. So for now I’m just having the system mention first that the user has X many voicemails that they should manage before saying there is a new message and spitting out the CID, length, and date.

Two questions:

  1. where are those functions defined?
  2. where and in what database is maxmsg stored?

Noting with VM is saved in a DB. Its all part of voicemail.conf for all voicemail settings.

Sorry, I should have clarified. I looked at the voicemail.conf file and didn’t see it, because it’s default no doubt. At the bottom there is a line that says [default] implying that it’s getting defaults from somewhere. Do I need to go look through the asterisk code to find the defaults or should I have my script search voicemail.conf for the presence of maxmsg and return 100 if nothing is found?

I thought about adding the variable to the voicemail.conf file but I have this feeling that it will be removed if anything changes in the GUI in voicemail admin.

[default] is the default vm context, by default all extensions should be in there, [dept1] and [dept2] would be created if an extension’s vm context was so changed, only extensions in the same context can transfer to each other etc.

I gave you a link as to where to set maxmsg in FreePBX.

There is a handy script in the source of asterisk (/contrib/scripts/message-expire.pl) that you could use as a base for properly deleting old read and/or unread messages, you could easily modify it let your clients know where they are at , from the asterisk cli

voicemail show users [for [default|dept1|dept2]]

for example from bash:-

rasterisk -x “voicemail show users”

Thanks for the help on the asterisk commands. I’ll have to do some more reading on that. As for the location of maxmsg, I know where that is in the vm admin page in the GUI but my issue was what to do if it’s set as default (the line is not in the file). I’ll have to dig through the asterisk commands, or I’ll just set maxmsg to 100 if it’s not found in the voicemail.conf file.

Here’s what I’ve done so far, though it looks like that asterisk command could make some of my script obsolete:

#!/bin/bash

maxmsg=100
userlist=`find /var/spool/asterisk/voicemail/default -maxdepth 1 -type d -regex '.*/[0-9]*' -exec basename {} .*/[0-9] \;`

for user in $userlist
do
	msgcount=`find /var/spool/asterisk/voicemail/default/$user/INBOX/*.wav -maxdepth 1 -type f | wc -l`
	vmratio=$((100*$msgcount/$maxmsg))
	vmaddr=`grep "$user =" /etc/asterisk/voicemail.conf | cut -d "," -f3`
	if ((vmratio >= 75)) ; then
		echo "Your mailbox is $(vmratio) % full. Please go through your voicemail. You can manage it online by opening the following link in your internet browser: /n/n http://$pbxaddr/recordings" | mail -s "Your mailbox is almost full, action is required" $vmaddr  
	fi
done

Obivously I still need to do something with maxmsg and with pbxaddr. Also, while the email sends properly the CLI seems to hang and I have to do a ctrl C if an email is sent. Also need to figure out how to get the mail command to use severemail so it matches the one that sends voicemail recordings.

I don’t now why maxmsg is not written to your voicemail.conf, IWFM.

you need a line break or a ; before vmratio in

wc -l vmratio=$((100*$msgcount/$maxmsg))

and

before if in

vmaddr=grep “$user =” /etc/asterisk/voicemail.conf | cut -d “,” -f3 if ((vmratio >= 75))

maybe just a formatting thing though but it might expalin the “hang” :smile:

to get a sorted list of msgcount:-

rasterisk -x ‘voicemail show users’|awk ‘{print $NF, $2, $3 }’|sort -n

is probably less resource needy.

Yeah, the formatting got butchered when pasting in the code. The issue is with the syntax in the email function. This seems to work better for email, and it actually sends the right from address:

#!/bin/bash
cat - t << EOF | sendmail -t
to:$vmaddr
from:voicemail@$pbxaddr
subject: Your mailbox is almost full, action is required
Your mailbox is $vmratio % full. Please go through your voicemail. You can manage it online by opening the following link in your internet browser:

http://$pbxaddr/recordings/

EOF
```

It's not elegant but feeding it a garbage (non existent) file makes it work. 

A PSA on sendmail vs mail: do NOT indent any part of the sendmail as it wont work. Also, sendmail doesn't like the line break codes (just hit enter for a line break) and there is no need for the parenthesis around the variables. 

As to voicemail.conf, if I put in the value 100 into the GUI it will write that line even if it's equal to the default. Deleting it from the GUI deletes it from the file. Again, not the most elegant solution but I counted instances of "maxmsg" in /etc/asterisk/voicemail.conf and if it was 0 I set maxmsg to 100 and if it was 1 I made it whatever the value is. 

The last piece (I think) is to create a variable for pbxaddr and get that from somewhere (/etc/asterisk/vm_email.inc, /etc/sysconfig/network, or anywhere really).

*edit: duh. 
```
pbxaddr=`hostname`
```