From: Olaf Titz Date: Thu, 15 Jun 2023 15:36:26 +0000 (+0200) Subject: app_voicemail_imap: Fix message count when IMAP server is unavailable X-Git-Tag: 18.19.0-rc1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f33d5c2f1e2289f73edc4ab701880ee71bd6eca3;p=thirdparty%2Fasterisk.git app_voicemail_imap: Fix message count when IMAP server is unavailable Some callers of __messagecount did not correctly handle error return, instead returning a -1 message count. This caused a notification with "Messages-Waiting: yes" and "Voice-Message: -1/0 (0/0)" if the IMAP server was unavailable. Fixes: #64 (cherry picked from commit 3b23ee42033842bfb991ee66cfe2e9a450e5ca55) --- diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 88dc342ee1..5564181f14 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -2598,11 +2598,13 @@ static int messagecount(const char *mailbox_id, const char *folder) return 0; } + int count; if (ast_strlen_zero(folder) || !strcmp(folder, "INBOX")) { - return __messagecount(context, mailbox, "INBOX") + __messagecount(context, mailbox, "Urgent"); + count = __messagecount(context, mailbox, "INBOX") + __messagecount(context, mailbox, "Urgent"); } else { - return __messagecount(context, mailbox, folder); + count = __messagecount(context, mailbox, folder); } + return count < 0 ? 0 : count; } 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, const char *msg_id) @@ -2764,6 +2766,7 @@ static int inboxcount2(const char *mailbox_context, int *urgentmsgs, int *newmsg char *context; char *mb; char *cur; + int count = 0; if (newmsgs) *newmsgs = 0; if (oldmsgs) @@ -2813,21 +2816,24 @@ static int inboxcount2(const char *mailbox_context, int *urgentmsgs, int *newmsg ast_log(AST_LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailboxnc, context); return -1; } - if ((*newmsgs = __messagecount(context, mailboxnc, vmu->imapfolder)) < 0) { + if ((count = __messagecount(context, mailboxnc, vmu->imapfolder)) < 0) { free_user(vmu); return -1; } + *newmsgs = count; free_user(vmu); } if (oldmsgs) { - if ((*oldmsgs = __messagecount(context, mailboxnc, "Old")) < 0) { + if ((count = __messagecount(context, mailboxnc, "Old")) < 0) { return -1; } + *oldmsgs = count; } if (urgentmsgs) { - if ((*urgentmsgs = __messagecount(context, mailboxnc, "Urgent")) < 0) { + if ((count = __messagecount(context, mailboxnc, "Urgent")) < 0) { return -1; } + *urgentmsgs = count; } return 0; } @@ -2861,7 +2867,7 @@ static int has_voicemail(const char *mailbox, const char *folder) } else { context = "default"; } - return __messagecount(context, tmp, folder) ? 1 : 0; + return __messagecount(context, tmp, folder) > 0 ? 1 : 0; } /*!