--- apps/app_voicemail.c.2013-07-24 2013-07-24 17:04:57.000000000 -0400 +++ apps/app_voicemail.c 2013-07-24 17:39:31.000000000 -0400 @@ -5138,20 +5138,50 @@ char tmpcmd[256]; int tmpfd = -1; int soxstatus = 0; + char altfname[256]; + int altused = 0; + char altformat[80]=""; + char *c; + FILE *fi; + + snprintf(fname, sizeof(fname), "%s.%s", attach, format); + if (!(fi = fopen(fname, "rb"))) { + ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s ... trying first (alternate) format from voicemail.conf: %s\n", fname, strerror(errno), altformat); + ast_copy_string(altformat, vmfmts, sizeof(altformat)); + c = strchr(altformat, '|'); + if (c) + *c = '\0'; + snprintf(altfname, sizeof(altfname), "%s.%s", attach, altformat); + if (!(fi = fopen(altfname, "rb"))) { + ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s - alternate format %s failure\n", altfname, strerror(errno), altformat); + } else { + altused = 1; + snprintf(fname, sizeof(fname), "%s.%s", attach, altformat); + } + } /* Eww. We want formats to tell us their own MIME type */ char *ctype = (!strcasecmp(format, "ogg")) ? "application/" : "audio/x-"; - if (vmu->volgain < -.001 || vmu->volgain > .001) { + if (vmu->volgain < -.001 || vmu->volgain > .001 || altused) { create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp"); snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir); tmpfd = mkstemp(newtmp); chmod(newtmp, VOICEMAIL_FILE_MODE & ~my_umask); ast_debug(3, "newtmp: %s\n", newtmp); if (tmpfd > -1) { - snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, format, newtmp, format); + if (!altused) { + snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, format, newtmp, format); + } else { + if (vmu->volgain < -.001 || vmu->volgain > .001) { + snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, altformat, newtmp, format); + } else { + snprintf(tmpcmd, sizeof(tmpcmd), "sox %s.%s %s.%s", attach, altformat, newtmp, format); + } + } if ((soxstatus = ast_safe_system(tmpcmd)) == 0) { attach = newtmp; + snprintf(fname, sizeof(fname), "%s.%s", attach, format); ast_debug(3, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volgain, mailbox); } else { ast_log(LOG_WARNING, "Sox failed to re-encode %s.%s: %s (have you installed support for all sox file formats?)\n", attach, format, @@ -5171,7 +5201,6 @@ fprintf(p, "Content-Disposition: attachment; filename=\"%s\"" ENDL ENDL, filename); else fprintf(p, "Content-Disposition: attachment; filename=\"%s.%s\"" ENDL ENDL, greeting_attachment, format); - snprintf(fname, sizeof(fname), "%s.%s", attach, format); base_encode(fname, p); if (last) fprintf(p, ENDL ENDL "--%s--" ENDL "." ENDL, bound); @@ -7655,6 +7684,9 @@ #ifdef IMAP_STORAGE *vms->introfn = '\0'; #endif +#ifdef ODBC_STORAGE + STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, *duration, vms, NULL); +#endif cmd = 't'; break; case '*':