Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 136885) +++ apps/app_voicemail.c (working copy) @@ -178,6 +178,7 @@ #define VOICEMAIL_DIR_MODE 0777 #define VOICEMAIL_FILE_MODE 0666 #define CHUNKSIZE 65536 +#define MAX_FORWARD_MESSAGE_RECEIVER_STRING 1024 #define VOICEMAIL_CONFIG "voicemail.conf" #define ASTERISK_USERNAME "asterisk" @@ -5999,7 +6000,11 @@ int curmsg; char urgent_str[7] = ""; char tmptxtfile[PATH_MAX]; - + int num_receivers = 0; + int add_recipient = 0; + char recipients[MAX_FORWARD_MESSAGE_RECEIVER_STRING]; + + bzero(recipients,MAX_FORWARD_MESSAGE_RECEIVER_STRING); ast_copy_string(urgent_str, urgent ? "Urgent" : "", sizeof(urgent_str)); if (vms == NULL) return -1; @@ -6009,6 +6014,7 @@ tmptxtfile[0] = '\0'; while (!res && !valid_extensions) { int use_directory = 0; + add_recipient = 0; if (ast_test_flag((&globalflags), VM_DIRECFORWARD)) { int done = 0; int retries = 0; @@ -6086,6 +6092,26 @@ 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->mailbox, vmu->context); + 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); + if (res) + return res; + } } /* start all over if no username */ @@ -6122,23 +6148,116 @@ s = strsep(&stringp, "*"); } /* break from the loop of reading the extensions */ - if (valid_extensions) + if (valid_extensions) { + + + + /* for send message to multiple receivers*/ + + + 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. */ + } + 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 (is_new_message == 1) { struct leave_vm_options leave_options; - char mailbox[AST_MAX_EXTENSION * 2 + 2]; - snprintf(mailbox, sizeof(mailbox), "%s@%s", username, context); /* 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;