Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 265316) +++ channels/chan_sip.c (working copy) @@ -23775,11 +23775,25 @@ while ((mbox = context = strsep(&next, ","))) { struct sip_mailbox *mailbox; + int duplicate = 0; - if (!(mailbox = ast_calloc(1, sizeof(*mailbox)))) + strsep(&context, "@"); + + /* Check whether the mailbox is already in the list */ + AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { + if (!strcmp(mailbox->mailbox, mbox) && !strcmp(S_OR(mailbox->context, ""), S_OR(context, ""))) { + duplicate = 1; + break; + } + } + if (duplicate) { continue; + } - strsep(&context, "@"); + if (!(mailbox = ast_calloc(1, sizeof(*mailbox)))) { + continue; + } + if (ast_strlen_zero(mbox)) { ast_free(mailbox); continue;