Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (révision 285637) +++ apps/app_voicemail.c (copie de travail) @@ -382,7 +382,7 @@ AST_THREADSTORAGE(ts_vmstate); /* Forward declarations for IMAP */ -static int init_mailstream(struct vm_state *vms, int box); +static int init_mailstream(struct vm_state *vms, struct ast_vm_user *vmu, int box); static void write_file(char *filename, char *buffer, unsigned long len); static char *get_header_by_tag(char *header, char *tag, char *buf, size_t len); static void vm_imap_delete(char *file, int msgnum, struct ast_vm_user *vmu); @@ -397,7 +397,7 @@ static int save_body(BODY *body, struct vm_state *vms, char *section, char *format, int is_intro); static void get_mailbox_delimiter(MAILSTREAM *stream); static void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota); -static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, int box, int target); +static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, struct ast_vm_user *vmu, int box, int target); static int imap_store_file(const char *dir, const char *mailboxuser, const char *mailboxcontext, int msgnum, struct ast_channel *chan, struct ast_vm_user *vmu, char *fmt, int duration, struct vm_state *vms, const char *flag); static void update_messages_by_imapuser(const char *user, unsigned long number); static int vm_delete(char *file); @@ -655,6 +655,7 @@ char imappassword[80]; /*!< IMAP server password if authpassword not defined */ char imapfolder[64]; /*!< IMAP voicemail folder */ char imapvmshareid[80]; /*!< Shared mailbox ID to use rather than the dialed one */ + char imapserver[48]; int imapversion; /*!< If configuration changes, use the new values */ #endif double volgain; /*!< Volume gain for voicemails sent via email */ @@ -697,6 +698,7 @@ int vmArrayIndex; char imapuser[80]; /*!< IMAP server login */ char imapfolder[64]; /*!< IMAP voicemail folder */ + char imapserver[48]; int imapversion; int interactive; char introfn[PATH_MAX]; /*!< Name of prepended file */ @@ -1015,6 +1017,7 @@ vmu->emailbody = NULL; #ifdef IMAP_STORAGE ast_copy_string(vmu->imapfolder, imapfolder, sizeof(vmu->imapfolder)); + ast_copy_string(vmu->imapserver, imapserver, sizeof(vmu->imapserver)); #endif } @@ -1053,6 +1056,10 @@ } else if (!strcasecmp(var, "imapvmshareid")) { ast_copy_string(vmu->imapvmshareid, value, sizeof(vmu->imapvmshareid)); vmu->imapversion = imapversion; + } else if (!strcasecmp(var, "imapserver")) { + ast_copy_string(vmu->imapserver, value, sizeof(vmu->imapserver)); + vmu->imapversion = imapversion; + #endif } else if (!strcasecmp(var, "delete") || !strcasecmp(var, "deletevoicemail")) { ast_set2_flag(vmu, ast_true(value), VM_DELETE); @@ -1312,6 +1319,10 @@ } else if (!strcasecmp(var->name, "imapvmshareid")) { ast_copy_string(retval->imapvmshareid, var->value, sizeof(retval->imapvmshareid)); retval->imapversion = imapversion; + } else if (!strcasecmp(var->name, "imapserver")) { + ast_copy_string(retval->imapserver, var->value, sizeof(retval->imapserver)); + retval->imapversion = imapversion; + #endif } else apply_option(retval, var->name, var->value); @@ -1773,7 +1784,7 @@ *vms_p->introfn = '\0'; ast_mutex_lock(&vms_p->lock); - ret = init_mailstream(vms_p, GREETINGS_FOLDER); + ret = init_mailstream(vms_p, vmu, GREETINGS_FOLDER); if (!vms_p->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream is NULL\n"); ast_mutex_unlock(&vms_p->lock); @@ -2030,7 +2041,7 @@ if (!vms_p) { vms_p = create_vm_state_from_user(vmu); } - ret = init_mailstream(vms_p, fold); + ret = init_mailstream(vms_p, vmu, fold); if (!vms_p->mailstream) { ast_log(AST_LOG_ERROR, "Houston we have a problem - IMAP mailstream is NULL\n"); return -1; @@ -2198,7 +2209,7 @@ } if (msgnum < 0 && imapgreetings) { - if ((ret = init_mailstream(vms, GREETINGS_FOLDER))) { + if ((ret = init_mailstream(vms, vmu, GREETINGS_FOLDER))) { ast_log(AST_LOG_WARNING, "Unable to open mailstream.\n"); return -1; } @@ -2227,9 +2238,9 @@ } ((char *) buf)[len] = '\0'; INIT(&str, mail_string, buf, len); - ret = init_mailstream(vms, NEW_FOLDER); + ret = init_mailstream(vms, vmu, NEW_FOLDER); if (ret == 0) { - imap_mailbox_name(mailbox, sizeof(mailbox), vms, NEW_FOLDER, 1); + imap_mailbox_name(mailbox, sizeof(mailbox), vms, vmu, NEW_FOLDER, 1); ast_mutex_lock(&vms->lock); if(!mail_append_full(vms->mailstream, mailbox, imap_flags, NIL, &str)) ast_log(LOG_ERROR, "Error while sending the message to %s\n", mailbox); @@ -2413,7 +2424,8 @@ return -1; } -static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, int box, int use_folder) +static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, struct ast_vm_user *vmu, int box, int use_folder) +/*static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box)*/ { char tmp[256], *t = tmp; size_t left = sizeof(tmp); @@ -2431,7 +2443,8 @@ } /* Build up server information */ - ast_build_string(&t, &left, "{%s:%s/imap", imapserver, imapport); + /*ast_build_string(&t, &left, "{%s:%s/imap", imapserver, imapport);*/ + ast_build_string(&t, &left, "{%s:%s/imap", vmu->imapserver, imapport); /* Add authentication user if present */ if (!ast_strlen_zero(authuser)) @@ -2461,7 +2474,7 @@ } } -static int init_mailstream(struct vm_state *vms, int box) +static int init_mailstream(struct vm_state *vms, struct ast_vm_user *vmu, int box) { MAILSTREAM *stream = NIL; long debug; @@ -2492,7 +2505,7 @@ #include "linkage.c" #endif /* Connect to INBOX first to get folders delimiter */ - imap_mailbox_name(tmp, sizeof(tmp), vms, 0, 1); + imap_mailbox_name(tmp, sizeof(tmp), vms, vmu, 0, 1); ast_mutex_lock(&vms->lock); stream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL); ast_mutex_unlock(&vms->lock); @@ -2507,7 +2520,7 @@ *cp = delimiter; } /* Now connect to the target folder */ - imap_mailbox_name(tmp, sizeof(tmp), vms, box, 1); + imap_mailbox_name(tmp, sizeof(tmp), vms, vmu, box, 1); if (option_debug > 2) ast_log(LOG_DEBUG, "Before mail_open, server: %s, box:%d\n", tmp, box); ast_mutex_lock(&vms->lock); @@ -2534,10 +2547,11 @@ ast_copy_string(vms->imapuser, vmu->imapuser, sizeof(vms->imapuser)); ast_copy_string(vms->imapfolder, vmu->imapfolder, sizeof(vms->imapfolder)); + ast_copy_string(vms->imapserver, vmu->imapserver, sizeof(vms->imapserver)); vms->imapversion = vmu->imapversion; ast_debug(3, "Before init_mailstream, user is %s\n", vmu->imapuser); - if ((ret = init_mailstream(vms, box)) || !vms->mailstream) { + if ((ret = init_mailstream(vms, vmu, box)) || !vms->mailstream) { ast_log(AST_LOG_ERROR, "Could not initialize mailstream\n"); return -1; } @@ -5995,7 +6009,7 @@ return 0; } /* Create the folder if it don't exist */ - imap_mailbox_name(mailbox, sizeof(mailbox), vms, box, 1); /* Get the full mailbox name */ + imap_mailbox_name(mailbox, sizeof(mailbox), vms, vmu, box, 1); /* Get the full mailbox name */ ast_debug(5, "Checking if folder exists: %s\n", mailbox); if (mail_create(vms->mailstream, mailbox) == NIL) ast_debug(5, "Folder exists.\n"); @@ -7086,7 +7100,7 @@ dstvms = create_vm_state_from_user(vmtmp); } if (dstvms) { - init_mailstream(dstvms, 0); + init_mailstream(dstvms, sender, 0); if (!dstvms->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream for %s is NULL\n", vmtmp->mailbox); } else { @@ -10560,6 +10574,11 @@ ast_test_status_update(test, "Parse failure for imapvmshareid option\n"); res = 1; } + if (strcasecmp(vmu->imapserver, "imapserver")) { + ast_test_status_update(test, "Parse failure for imapserver option\n"); + res = 1; + } + #endif free_user(vmu);