--- asterisk-1.8.7.0/apps/app_voicemail.c 2011-09-06 14:48:03.000000000 +0100 +++ asterisk-1.8.7.0.vmi/apps/app_voicemail.c 2011-10-19 00:53:44.282000000 +0100 @@ -356,6 +356,46 @@ context. + + + Returns the selected attribute from a mailbox + + + + + + + + + + + + + + + + + + + + + Returns the selected attribute from the specified mailbox. + If context is not specified, defaults to the default + context. + + List All Voicemail User Information. @@ -11013,11 +11053,83 @@ return 0; } +static int acf_vm_info(struct ast_channel *chan, const char *cmd, char *args, char *buf, size_t len) +{ + struct ast_vm_user *vmu = NULL; + char *tmp, *mbox, *context; + int res = 0, newmsgs = 0, oldmsgs = 0; + + AST_DECLARE_APP_ARGS(arg, + AST_APP_ARG(mailbox_context); + AST_APP_ARG(attribute); + ); + + buf[0] = '\0'; + + AST_STANDARD_APP_ARGS(arg, args); + + if (ast_strlen_zero(arg.mailbox_context) || ast_strlen_zero(arg.attribute)) { + ast_log(LOG_ERROR, "VM_INFO requires an argument ([@],attribute)\n"); + return -1; + } + + tmp = ast_strdupa(arg.mailbox_context); + mbox = strsep(&tmp, "@"); + context = strsep(&tmp, ""); + + if (ast_strlen_zero(context)) { + context = "default"; + } + + vmu = find_user(NULL, context, mbox); + + if (vmu) { + if ((!strncasecmp(arg.attribute, "new_msg", 7)) || (!strncasecmp(arg.attribute, "old_msg", 7))) { + res = inboxcount(arg.mailbox_context, &newmsgs, &oldmsgs); + if (res < 0) { + ast_log(LOG_ERROR, "Unable to retrieve message count for mailbox %s\n", arg.mailbox_context); + return -1; + } + else { + if (!strncasecmp(arg.attribute, "new_msg", 7)) { + snprintf(buf, len, "%d", newmsgs); + } + else if (!strncasecmp(arg.attribute, "old_msg",7)){ + snprintf(buf, len, "%d", oldmsgs); + } + } + } + else if (!strncasecmp(arg.attribute, "password", 8)) { + ast_copy_string(buf, vmu->password, len); + } + else if (!strncasecmp(arg.attribute, "fullname",8)){ + ast_copy_string(buf, vmu->fullname, len); + } + else if (!strncasecmp(arg.attribute, "email",5)){ + ast_copy_string(buf, vmu->email, len); + } + else if (!strncasecmp(arg.attribute, "pager",5)){ + ast_copy_string(buf, vmu->pager, len); + } + else { + ast_log(LOG_ERROR, "Unknown attribute '%s' for VM_INFO\n", arg.attribute); + return -1; + } + } + + return 0; +} + static struct ast_custom_function mailbox_exists_acf = { .name = "MAILBOX_EXISTS", .read = acf_mailbox_exists, }; +static struct ast_custom_function vm_info_acf = { + .name = "VM_INFO", + .read = acf_vm_info, +}; + static int vmauthenticate(struct ast_channel *chan, const char *data) { char *s, *user = NULL, *context = NULL, mailbox[AST_MAX_EXTENSION] = ""; @@ -12925,6 +13037,7 @@ res |= ast_unregister_application(app4); res |= ast_unregister_application(sayname_app); res |= ast_custom_function_unregister(&mailbox_exists_acf); + res |= ast_custom_function_unregister(&vm_info_acf); res |= ast_manager_unregister("VoicemailUsersList"); res |= ast_data_unregister(NULL); #ifdef TEST_FRAMEWORK @@ -12975,6 +13088,7 @@ res |= ast_register_application_xml(app4, vmauthenticate); res |= ast_register_application_xml(sayname_app, vmsayname_exec); res |= ast_custom_function_register(&mailbox_exists_acf); + res |= ast_custom_function_register(&vm_info_acf); res |= ast_manager_register_xml("VoicemailUsersList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, manager_list_voicemail_users); #ifdef TEST_FRAMEWORK res |= AST_TEST_REGISTER(test_voicemail_vmsayname);