app_voicemail_imap failure, Asterisk 22.7.0 local build, stopped working after OS upgrade and Asterisk rebuild

I recently upgraded my home server from Ubuntu 24.04 LTS to Ubuntu 26.04 LTS. Under 24.04, I ran Asterisk 22.7.0 (which I built locally) without issue. The relevant functionality was to pick up SIP calls (from an Obihai OBI-110 SIP/POTS bridge) from inbound calls to my house POTS line, ring IAX2 clients (Zoiper) on our mobile phones, then transfer to voicemail if we did not answer. Voicemail was delivered to IMAP (Dovecot 2.3 running on the same server). This all worked flawlessly for years, over many versions of Asterisk and Ubuntu, with the same configuration files I have today.

After the OS upgrade, Asterisk segfaulted immediately (missing libxml2), which was no surprise. I went back to my build directory, ran make uninstall, then make clean, followed the recommendations of contrib/scripts/install_prereq test, then did the full configure, menuselect, build, and install process.

The OS upgrade pushed Dovecot from 2.3 to 2.4, which requires a lot of configuration syntax changes in Dovecot. That is all working now (ditto for Postfix), email is flowing as it should in all directions. The rebuilt Asterisk 22.7.0 seems to be having difficulties dealing with the IMAP service, and the errors are somewhat misleading.

In testing the rebuilt Asterisk 22.7.0, which was built with only app_voicemail_imap and not app_voicemail or app_voicemail_odbc (I know that’s a common mistake, I’ll save you asking me), and using exactly the same configuration files I was using with Asterisk 22.7.0 under Ubuntu 24.04 LTS, I get the following error running asterisk -vvvc:

[Oct 17 10:50:36] ERROR[171092]: app_voicemail_imap.c:3146 inboxcount2: Couldn't find mailbox 200 in context default
    -- No voicemail provider registered.

Mailbox 200 is very much present in the default context of voicemail.conf, always has been.

Since I built from code, I elected to inspect app_voicemail_imap.c to get a sense of what it is trying (and failing) to do at this point:

	if (newmsgs) {
		struct ast_vm_user *vmu = find_user(NULL, context, mailboxnc);
		if (!vmu) {
			ast_log(AST_LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailboxnc, context);

This code wouldn’t get called at all unless it had actually read voicemail.conf, found the entry, and was trying to process it, which is not what the language of the error message implies.

The default context of voicemail.conf:

[default]
; Note: The rest of the system must reference mailboxes defined here as mailbox@default.
200 => 1234,Redacted Name,redacted@email.addr,,|attach=yes|delete=yes

This lead me to see what Asterisk was getting out of voicemail.conf, if anything:

*CLI> voicemail show users
Context    Mbox  User                      Zone       NewMsg
default    200   Redacted Name                             0
1 voicemail users configured.
*CLI> [Oct 17 10:51:14] ERROR[171092]: app_voicemail_imap.c:3146 inboxcount2: Couldn't find mailbox 200 in context default

…and there it is again!

Clearly, the problem is not in voicemail.conf, but is some problem that Asterisk is encountering while trying to access the IMAP service that has crept in with changes to Dovecot or Ubuntu itself.

Needless to say, I am going to have to do some tracing or debugging of something, but could use the advice of people who understand in mechanics of app_voicemail_imap and can tell me where I need to look. I am no stranger to C development, debugging, or networking, so lay it on me. Where do I need to focus my troubleshooting efforts at this point?

This problem is specific to my environment, but may also happen to others performing similar system upgrades.

While my overall problem is not an Asterisk problem per se, the log message it generates is a bit misleading in cases such as this one. The specified mailbox was found in the specified context, but the log message is implying otherwise. I would respectfully suggest the responsible developer(s) consider revisiting this portion of the code, at least in terms of accurate error descriptions.

That said, what/where do I need to diagnose from here?

Thanks in advance!

The second line is the real clue. “No voicemail provider registered” comes from the Asterisk core, not from app_voicemail_imap. It means the module never finished loading. The “Couldn’t find mailbox 200” error is a side effect of that. Something is asking for a message count before the module has a working user list, so it comes back empty even though voicemail.conf is fine.

If the config or provider registration fails, the module unloads itself, so the error that matters is probably printed a bit earlier in startup. Some things to check:

  1. module show like voicemail: is app_voicemail_imap.so actually listed as running?
  2. Unload it if needed, then run module load app_voicemail_imap.so with core set verbose 5 and core set debug 5. Look at what it prints just before it declines.
  3. Check the c-client (UW IMAP) library you built against. On newer distros that package has been changing or going away, so the module can compile fine and still fail at runtime. Run ldd /usr/lib/asterisk/modules/app_voicemail_imap.so | grep -i c-client and check that it resolves.
  4. Newer Dovecot changed a lot of defaults. Try connecting by hand with the same imapserver, imapport, imapflags and login from voicemail.conf (e.g. openssl s_client or telnet localhost 143). If your imapflags include /novalidate-cert or /notls, make sure they still match how Dovecot listens now.

Also, if any mailboxes set imapuser, imapserver or imapflags per user, check those too, since they override [general].

Once the module loads cleanly, the “Couldn’t find mailbox” error should go away on its own.

(Drafted with AI assistance, reviewed by me.)

Surprisingly, yes:

*CLI> module show like voicemail
Module                         Description                              Use Count  Status      Support Level
app_voicemail_imap.so          Comedian Mail (Voicemail System) with IM 0          Running              core
res_pjsip_send_to_voicemail.so PJSIP REFER Send to Voicemail Support    0          Running              core
2 modules loaded

Wasn’t expecting res_pjsip module, but I don’t suspect that being my problem here.

Sadly, nothing additional that’s helpful:

*CLI> module unload app_voicemail_imap.so 
Unloaded app_voicemail_imap.so
*CLI> core set verbose 5
Console verbose was 3 and is now 5.
*CLI> core set debug 5
Core debug was OFF and is now 5.
*CLI> module load app_voicemail_imap.so
[Oct 20 10:31:00] ERROR[71137]: app_voicemail_imap.c:3146 inboxcount2: Couldn't find mailbox 200 in context default
        > Registered application 'VoiceMail'
        > Registered application 'VoiceMailMain'
        > Registered application 'VMAuthenticate'
        > Registered application 'VoiceMailPlayMsg'
        > Registered application 'VMSayName'
        > Registered custom function 'VM_INFO'
        > Manager registered action VoicemailUsersList
        > Manager registered action VoicemailUserStatus
        > Manager registered action VoicemailRefresh
        > Manager registered action VoicemailBoxSummary
        > Manager registered action VoicemailMove
        > Manager registered action VoicemailRemove
        > Manager registered action VoicemailForward
Loaded app_voicemail_imap.so
*CLI>        > Loaded app_voicemail_imap.so => (Comedian Mail (Voicemail System) with IMAP Storage)

It appears to:

# ldd /usr/lib/asterisk/modules/app_voicemail_imap.so | grep -i c-client
	libc-client.so.2007e => /lib/libc-client.so.2007e (0x000074ad2dcca000)

Ain’t that the truth! :face_with_symbols_on_mouth:

This is probably where my problem really is, because all my imap* settings are at Asterisk default values, and have been right along.

Dovecot greets me with the following capabilities via telnet:

# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LOGIN-REFERRALS ID ENABLE IDLE SASL-IR LITERAL+ STARTTLS AUTH=PLAIN] Dovecot ready.
^]
telnet> quit
Connection closed.

As far as openssl, it seems to succeed (for TLS, anyway) without specifying any flags at all, unless I am reading this wrong:

# openssl s_client localhost:143
Connecting to 127.0.0.1
CONNECTED(00000003)
40E74DCE9F790000:error:0A0000C6:SSL routines:tls_get_more_records:packet length too long:../ssl/record/methods/tls_common.c:660:
40E74DCE9F790000:error:0A000139:SSL routines::record layer failure:../ssl/record/rec_layer_s3.c:698:
---
no peer certificate available
---
No client certificate CA names sent
Negotiated TLS1.3 group: <NULL>
---
SSL handshake has read 5 bytes and written 1540 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Protocol: TLSv1.3
This TLS version forbids renegotiation.
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

Now I just need to try again with the flags that Asterisk 22.7.0 uses as default to see what that yields. The config files I am using have been carried over for so many Asterisk versions now (off the top of my head, I want to say I started with Asterisk 16 way back when) that I don’t want to assume the hints in the config files are still applicable. I will have to run through the code in order to see what defaults are being applied in Asterisk 22.7.0 and repeat the tests with those before I can get much further.

That said, this is exactly what I was looking for, thank you! Even though the problem isn’t solved yet, you have at least got me much closer to the actual problem than I was a few days ago.

Let me know if I’ve misread something in this output (I’m only on my second cup of coffee), otherwise I will continue openssl testing with the default imap* flags I am able to glean from the code.

Thanks again!