*** /home/hubertm/asterisk-1.8.0-beta2/apps/app_voicemail.c Wed Jul 21 00:40:19 2010 --- app_voicemail.c Mon Aug 2 19:13:51 2010 *************** *** 381,387 **** AST_THREADSTORAGE(ts_vmstate); /* Forward declarations for IMAP */ ! static int init_mailstream(struct vm_state *vms, 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); --- 381,387 ---- AST_THREADSTORAGE(ts_vmstate); /* Forward declarations for IMAP */ ! 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); *************** *** 396,402 **** 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 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); --- 396,402 ---- 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, 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); *************** *** 654,659 **** --- 654,660 ---- 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 */ *************** *** 696,701 **** --- 697,703 ---- 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 */ *************** *** 1014,1019 **** --- 1016,1022 ---- 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 } *************** *** 1052,1057 **** --- 1055,1064 ---- } 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); *************** *** 1311,1316 **** --- 1318,1327 ---- } 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); *************** *** 1771,1777 **** *vms_p->introfn = '\0'; ast_mutex_lock(&vms_p->lock); ! ret = init_mailstream(vms_p, GREETINGS_FOLDER); if (!vms_p->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream is NULL\n"); ast_mutex_unlock(&vms_p->lock); --- 1782,1788 ---- *vms_p->introfn = '\0'; ast_mutex_lock(&vms_p->lock); ! 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); *************** *** 2028,2034 **** if (!vms_p) { vms_p = create_vm_state_from_user(vmu); } ! ret = init_mailstream(vms_p, fold); if (!vms_p->mailstream) { ast_log(AST_LOG_ERROR, "Houston we have a problem - IMAP mailstream is NULL\n"); return -1; --- 2039,2045 ---- if (!vms_p) { vms_p = create_vm_state_from_user(vmu); } ! 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; *************** *** 2196,2202 **** } if (msgnum < 0 && imapgreetings) { ! if ((ret = init_mailstream(vms, GREETINGS_FOLDER))) { ast_log(AST_LOG_WARNING, "Unable to open mailstream.\n"); return -1; } --- 2207,2213 ---- } if (msgnum < 0 && imapgreetings) { ! if ((ret = init_mailstream(vms, vmu, GREETINGS_FOLDER))) { ast_log(AST_LOG_WARNING, "Unable to open mailstream.\n"); return -1; } *************** *** 2225,2233 **** } ((char *) buf)[len] = '\0'; INIT(&str, mail_string, buf, len); ! ret = init_mailstream(vms, NEW_FOLDER); if (ret == 0) { ! imap_mailbox_name(mailbox, sizeof(mailbox), vms, 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); --- 2236,2244 ---- } ((char *) buf)[len] = '\0'; INIT(&str, mail_string, buf, len); ! ret = init_mailstream(vms, vmu, NEW_FOLDER); if (ret == 0) { ! 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); *************** *** 2411,2417 **** return -1; } ! static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, int box, int use_folder) { char tmp[256], *t = tmp; size_t left = sizeof(tmp); --- 2422,2429 ---- return -1; } ! 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); *************** *** 2429,2435 **** } /* Build up server information */ ! ast_build_string(&t, &left, "{%s:%s/imap", imapserver, imapport); /* Add authentication user if present */ if (!ast_strlen_zero(authuser)) --- 2441,2448 ---- } /* Build up server information */ ! /*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)) *************** *** 2459,2465 **** } } ! static int init_mailstream(struct vm_state *vms, int box) { MAILSTREAM *stream = NIL; long debug; --- 2472,2478 ---- } } ! static int init_mailstream(struct vm_state *vms, struct ast_vm_user *vmu, int box) { MAILSTREAM *stream = NIL; long debug; *************** *** 2490,2496 **** #include "linkage.c" #endif /* Connect to INBOX first to get folders delimiter */ ! imap_mailbox_name(tmp, sizeof(tmp), vms, 0, 1); ast_mutex_lock(&vms->lock); stream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL); ast_mutex_unlock(&vms->lock); --- 2503,2509 ---- #include "linkage.c" #endif /* Connect to INBOX first to get folders delimiter */ ! 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); *************** *** 2505,2511 **** *cp = delimiter; } /* Now connect to the target folder */ ! imap_mailbox_name(tmp, sizeof(tmp), vms, 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); --- 2518,2524 ---- *cp = delimiter; } /* Now connect to the target folder */ ! 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); *************** *** 2532,2541 **** ast_copy_string(vms->imapuser, vmu->imapuser, sizeof(vms->imapuser)); ast_copy_string(vms->imapfolder, vmu->imapfolder, sizeof(vms->imapfolder)); vms->imapversion = vmu->imapversion; ast_debug(3, "Before init_mailstream, user is %s\n", vmu->imapuser); ! if ((ret = init_mailstream(vms, box)) || !vms->mailstream) { ast_log(AST_LOG_ERROR, "Could not initialize mailstream\n"); return -1; } --- 2545,2555 ---- 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, vmu, box)) || !vms->mailstream) { ast_log(AST_LOG_ERROR, "Could not initialize mailstream\n"); return -1; } *************** *** 5993,5999 **** return 0; } /* Create the folder if it don't exist */ ! imap_mailbox_name(mailbox, sizeof(mailbox), vms, 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"); --- 6007,6013 ---- return 0; } /* Create the folder if it don't exist */ ! 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"); *************** *** 7084,7090 **** dstvms = create_vm_state_from_user(vmtmp); } if (dstvms) { ! init_mailstream(dstvms, 0); if (!dstvms->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream for %s is NULL\n", vmtmp->mailbox); } else { --- 7098,7104 ---- dstvms = create_vm_state_from_user(vmtmp); } if (dstvms) { ! init_mailstream(dstvms, sender, 0); if (!dstvms->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream for %s is NULL\n", vmtmp->mailbox); } else { *************** *** 10558,10563 **** --- 10572,10582 ---- 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);