Retrieve mailbox password

Now that I have used AMI a little bit, I was trying to use it to get the mailbox password of a mailbox. In the dialplan, this is fairly easy: just use the VMINFO application. Unlike other things where there is no way to do something in the dialplan, there doesn’t seem to be a way to do this using the CLI, and it seems like there might not be through AMI, either. Based on looking at the events, it seems like sending VoicemailUserStatus to get VoicemailUserDetail would be the right thing. And it seems to return everything about the mailbox… except the PIN!

Is there a way to retrieve this programatically outside of the dialplan? Or would my best bet be writing a bash script to grep voicemail.conf and do this?

For instance, the following shell command will retrieve the mailbox PIN of USER in CONTEXT:

sed -n -e '/\[CONTEXT\]/,/\[/ p' /etc/asterisk/voicemail.conf | grep "USER =>" | awk '{ print $3 }' | cut -d ',' -f1

But this kind of thing seems discouraged so is there a better way?

Action: VoicemailUserStatus
ActionID: 002
Context: redacted
Mailbox: redacted

Response: Success
ActionID: 002
EventList: start
Message: Voicemail user detail will follow

Event: VoicemailUserDetail
ActionID: 002
VMContext: redacted
VoiceMailbox: redacted
Fullname: redacted
Email: redacted
ServerEmail: redacted
FromString: Voicemail
MailCommand: /usr/sbin/sendmail -t
TimeZone: central
SayDurationMinimum: 2
SayEnvelope: Yes
SayCID: No
AttachMessage: No
DeleteMessage: No
VolumeGain: 0.00
CanReview: Yes
CallOperator: No
MaxMessageCount: 100
MaxMessageLength: 0
NewMessageCount: 0
OldMessageCount: 0

Event: VoicemailUserDetailComplete
ActionID: 002
EventList: Complete
ListItems: 1

I don’t see any issue running an script as the above to get the VM password, usually you use AMI when you want to retrieve information through a TCP connection. Other way using AMI could be using Action Getvar to retrieve the value , but this will need a piece of dial plan to invoke the channel variable and also a local channel where the VM_INFO will be executed