--- asterisk-1.8.4.2/channels/chan_sip.c.orig 2011-06-12 01:03:58.000000000 -0400 +++ asterisk-1.8.4.2/channels/chan_sip.c 2011-06-12 01:05:09.000000000 -0400 @@ -24546,12 +24546,14 @@ if (event) { newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); oldmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS); - } else if (!cache_only) { /* Fall back to manually checking the mailbox */ + } else if (!get_cached_mwi(peer, &newmsgs, &oldmsgs)) { + /* got it! Don't keep looking. */ + } else if (cache_only) { + return 0; + } else { /* Fall back to manually checking the mailbox */ struct ast_str *mailbox_str = ast_str_alloca(512); peer_mailboxes_to_str(&mailbox_str, peer); ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs); - } else { - get_cached_mwi(peer, &newmsgs, &oldmsgs); } if (peer->mwipvt) {