diff options
Diffstat (limited to 'apps/app_voicemail.c')
-rw-r--r-- | apps/app_voicemail.c | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 646eec316..d4f647264 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -703,6 +703,22 @@ static int is_valid_dtmf(const char *key); static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit); #endif +static char *strip_control(const char *input, char *buf, size_t buflen) +{ + char *bufptr = buf; + for (; *input; input++) { + if (*input < 32) { + continue; + } + *bufptr++ = *input; + if (bufptr == buf + buflen - 1) { + break; + } + } + *bufptr = '\0'; + return buf; +} + /*! * \brief Sets default voicemail system options to a voicemail user. @@ -2405,6 +2421,7 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in char bound[256]; char dur[256]; struct ast_tm tm; + char enc_cidnum[256], enc_cidname[256]; char *passdata2; size_t len_passdata; char *greeting_attachment; @@ -2416,7 +2433,9 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in #define ENDL "\n" #endif - gethostname(host, sizeof(host)-1); + strip_control(cidnum, enc_cidnum, sizeof(enc_cidnum)); + strip_control(cidname, enc_cidname, sizeof(enc_cidname)); + gethostname(host, sizeof(host) - 1); if (strchr(srcemail, '@')) ast_copy_string(who, srcemail, sizeof(who)); @@ -2441,16 +2460,18 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in int vmlen = strlen(fromstring)*3 + 200; passdata = alloca(vmlen); memset(passdata, 0, vmlen); - prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag); + prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, enc_cidnum, enc_cidname, dur, date, passdata, vmlen, category, flag); pbx_substitute_variables_helper(ast, fromstring, passdata, vmlen); len_passdata = strlen(passdata) * 2 + 3; passdata2 = alloca(len_passdata); fprintf(p, "From: %s <%s>" ENDL, quote(passdata, passdata2, len_passdata), who); ast_channel_free(ast); - } else + } else { ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); - } else + } + } else { fprintf(p, "From: Asterisk PBX <%s>" ENDL, who); + } len_passdata = strlen(vmu->fullname) * 2 + 3; passdata2 = alloca(len_passdata); fprintf(p, "To: %s <%s>" ENDL, quote(vmu->fullname, passdata2, len_passdata), vmu->email); @@ -2461,12 +2482,13 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in int vmlen = strlen(emailsubject) * 3 + 200; passdata = alloca(vmlen); memset(passdata, 0, vmlen); - prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag); + prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, enc_cidnum, enc_cidname, dur, date, passdata, vmlen, category, flag); pbx_substitute_variables_helper(ast, emailsubject, passdata, vmlen); fprintf(p, "Subject: %s" ENDL, passdata); ast_channel_free(ast); - } else + } else { ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); + } } else if (ast_test_flag((&globalflags), VM_PBXSKIP)) { if (ast_strlen_zero(flag)) { fprintf(p, "Subject: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox); @@ -2493,19 +2515,22 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in fprintf(p, "X-Asterisk-VM-Flag: %s" ENDL, flag); fprintf(p, "X-Asterisk-VM-Priority: %d" ENDL, chan->priority); fprintf(p, "X-Asterisk-VM-Caller-channel: %s" ENDL, chan->name); - fprintf(p, "X-Asterisk-VM-Caller-ID-Num: %s" ENDL, cidnum); - fprintf(p, "X-Asterisk-VM-Caller-ID-Name: %s" ENDL, cidname); + fprintf(p, "X-Asterisk-VM-Caller-ID-Num: %s" ENDL, enc_cidnum); + fprintf(p, "X-Asterisk-VM-Caller-ID-Name: %s" ENDL, enc_cidname); fprintf(p, "X-Asterisk-VM-Duration: %d" ENDL, duration); - if (!ast_strlen_zero(category)) + if (!ast_strlen_zero(category)) { fprintf(p, "X-Asterisk-VM-Category: %s" ENDL, category); + } fprintf(p, "X-Asterisk-VM-Message-Type: %s" ENDL, msgnum > -1 ? "Message" : greeting_attachment); fprintf(p, "X-Asterisk-VM-Orig-date: %s" ENDL, date); fprintf(p, "X-Asterisk-VM-Orig-time: %ld" ENDL, (long)time(NULL)); } - if (!ast_strlen_zero(cidnum)) - fprintf(p, "X-Asterisk-CallerID: %s" ENDL, cidnum); - if (!ast_strlen_zero(cidname)) - fprintf(p, "X-Asterisk-CallerIDName: %s" ENDL, cidname); + if (!ast_strlen_zero(cidnum)) { + fprintf(p, "X-Asterisk-CallerID: %s" ENDL, enc_cidnum); + } + if (!ast_strlen_zero(cidname)) { + fprintf(p, "X-Asterisk-CallerIDName: %s" ENDL, enc_cidname); + } fprintf(p, "MIME-Version: 1.0" ENDL); if (attach_user_voicemail) { /* Something unique. */ |