Index: app_voicemail.c =================================================================== --- app_voicemail.c (revision 67018) +++ app_voicemail.c (working copy) @@ -4395,6 +4395,8 @@ char category[32]; char todir[PATH_MAX]; int res = 0; + char *attachedfilename; + char *attachedfilefmt; char *temp; vms->starting = 0; @@ -4416,7 +4418,20 @@ make_gsm_file(vms->fn, vms->imapuser, todir, vms->curmsg); mail_fetchstructure (vms->mailstream,vms->msgArray[vms->curmsg],&body); - save_body(body,vms,"3","gsm"); + + /* We have the body, now we extract the file name of the first attachment. */ + if (((body->nested.part->next) != NIL) && ((body->nested.part->next->body.parameter->value) != NIL) ) { + attachedfilename = body->nested.part->next->body.parameter->value; + } else { + ast_log(LOG_ERROR, "There is no file attached to this IMAP message.\n"); + return -1; + } + + /* Find the format of the attached file */ + attachedfilefmt = strchr(attachedfilename, '.'); + *attachedfilefmt++ = '\0'; + + save_body(body,vms,"2",attachedfilefmt); adsi_message(chan, vms); if (!vms->curmsg)