Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 137054) +++ apps/app_voicemail.c (working copy) @@ -160,6 +160,8 @@ #define VOICEMAIL_FILE_MODE 0666 #define CHUNKSIZE 65536 +#define MAX_FORWARD_MESSAGE_RECEIVER_STRING 1024 + #define VOICEMAIL_CONFIG "voicemail.conf" #define ASTERISK_USERNAME "asterisk" @@ -3697,7 +3699,8 @@ char fmt[80]; char *context; char ecodes[16] = "#"; - char tmp[1024] = "", *tmpptr; + char tmp[MAX_FORWARD_MESSAGE_RECEIVER_STRING] = ""; + char *tmpptr; struct ast_vm_user *vmu; struct ast_vm_user svm; const char *category = NULL; @@ -4845,6 +4848,8 @@ struct vm_state *dstvms; #endif char username[70]=""; + char fn[PATH_MAX]; /* for playback of name greeting */ + char ecodes[16] = "#"; int res = 0, cmd = 0; struct ast_vm_user *receiver = NULL, *vmtmp; AST_LIST_HEAD_NOLOCK_STATIC(extensions, ast_vm_user); @@ -4854,12 +4859,18 @@ int valid_extensions = 0; char *dir; int curmsg; + int num_receivers = 0; + int add_recipient = 0; + char recipients[MAX_FORWARD_MESSAGE_RECEIVER_STRING]; + + bzero(recipients,MAX_FORWARD_MESSAGE_RECEIVER_STRING); if (vms == NULL) return -1; dir = vms->curdir; curmsg = vms->curmsg; while (!res && !valid_extensions) { + add_recipient = 0; int use_directory = 0; if (ast_test_flag((&globalflags), VM_DIRECFORWARD)) { int done = 0; @@ -4887,7 +4898,7 @@ if (!cmd) cmd = ast_waitfordigit(chan,3000); if (!cmd) - retries++; + retries++; if (retries > 3) { cmd = 't'; @@ -4939,6 +4950,28 @@ break; if ((res = ast_readstring(chan, username, sizeof(username) - 1, 2000, 10000, "#") < 0)) break; + + /* play name if available, else play extension number */ + snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, receiver->context, username); + ast_log(LOG_DEBUG, "looking for greeting file %s\n", fn); + RETRIEVE(fn, -1, vmu); + if (ast_fileexists(fn, NULL, NULL) > 0) { + ast_log(LOG_DEBUG, "playing greeting file %s\n", fn); + res = ast_play_and_wait(chan, fn); + if (res) { + DISPOSE(fn, -1); + return res; + } + } else { + /* Dispose just in case */ + DISPOSE(fn, -1); + ast_log(LOG_DEBUG, "no greeting file saying digits %s instead\n", username); + res = ast_say_digit_str(chan, username, ecodes, chan->language); +// res = ast_play_and_wait(chan, fn); + if (res) { + return res; + } + } } /* start all over if no username */ @@ -4960,27 +4993,129 @@ s = strsep(&stringp, "*"); } /* break from the loop of reading the extensions */ - if (valid_extensions) + if (valid_extensions) { + + + + /* for send message to multiple receivers*/ + + if (flag == 1) { + /* we are interested in multiple recipients only for 3->5 option */ + + int done = 0; + int retries = 0; + + while ((cmd >= 0) && !done) { + cmd = 0; + while ((cmd >= 0) && !done ) { + if (cmd) + retries = 0; + + switch (cmd) { + case '1': + add_recipient = 0; + done = 1; + break; + + case '2': + add_recipient = 1; + done=1; + break; + + case '*': + cmd = 't'; + done = 1; + break; + + default: + /* Press 1 to enter an send message, press 2 add another recipient */ + cmd = ast_play_and_wait(chan,"patches/vm-forward-multiple"); + if (!cmd) + cmd = ast_waitfordigit(chan,3000); + + if (!cmd) + retries++; + + if (retries > 3) { + cmd = 't'; + done = 1; + } + } /* switch */ + + } /* while reading multiple receiver prompt */ + + if (cmd == 't') { + valid_extensions = 1; + break; + } + + /* make sure we can actually add another recipient, play an error message if adding this recipient would be too large */ + if (strlen(recipients) + 40 >= MAX_FORWARD_MESSAGE_RECEIVER_STRING && add_recipient == 1) { + res = ast_play_and_wait(chan, "patches/vm-forward-multiple-too-many"); + + //valid_extensions = 0; + done = 0; + + ast_log(LOG_DEBUG, "adding another recipient would exceed max length of recipient buffer of %d (current size is %d)\n", MAX_FORWARD_MESSAGE_RECEIVER_STRING, strlen(recipients)); + } + else { + /* append the user to the recipients string. */ + char mailbox[AST_MAX_EXTENSION * 2 + 2]; + + if ( strlen(recipients) > 0) + strcat(recipients, "&"); + + /* Make sure that context doesn't get set as a literal "(null)" (or else find_user won't find it) */ + if (context) + snprintf(mailbox, sizeof(mailbox), "%s@%s", username, context); + else + ast_copy_string(mailbox, username, sizeof(mailbox)); + + + strcat(recipients, mailbox); + + num_receivers++; + if (add_recipient == 1) { + valid_extensions = 0; + + ast_log(LOG_DEBUG, "adding recipient %s and returing to add another. num_receivers=%d\n", username, num_receivers); + } + else { + valid_extensions = 1; + ast_log(LOG_DEBUG, "adding recipient %s and continuing to record message. num_receivers=%d\n", username, num_receivers); + + } + done = 1; + } + } /* while !done reading multiple recipients. */ + + } + else { + /* this is to forward the message (option 8). */ + /* currently we do not need the multiple-recipients functionality */ + /* so we just do the what this block used to do */ + valid_extensions = 1; + ast_log(LOG_DEBUG, "option 8, not processing multiple recipients.\n"); + } + } + if (valid_extensions) break; + /* "I am sorry, that's not a valid extension. Please try again." */ - res = ast_play_and_wait(chan, "pbx-invalid"); + if (!add_recipient) + res = ast_play_and_wait(chan, "pbx-invalid"); + } /* check if we're clear to proceed */ if (AST_LIST_EMPTY(&extensions) || !valid_extensions) return res; if (flag==1) { struct leave_vm_options leave_options; - char mailbox[AST_MAX_EXTENSION * 2 + 2]; - /* Make sure that context doesn't get set as a literal "(null)" (or else find_user won't find it) */ - if (context) - snprintf(mailbox, sizeof(mailbox), "%s@%s", username, context); - else - ast_copy_string(mailbox, username, sizeof(mailbox)); /* Send VoiceMail */ memset(&leave_options, 0, sizeof(leave_options)); leave_options.record_gain = record_gain; - cmd = leave_voicemail(chan, mailbox, &leave_options); + cmd = leave_voicemail(chan, recipients, &leave_options); } else { /* Forward VoiceMail */ long duration = 0;