Apps Mail - error loading mail messages (Argument 1 passed to OCA Mail Controller MessagesController::index() must be of the type int, null given)

Nextcloud version: 20.0.2.2
Operating system and version: Ubuntu 20.04
Apache or nginx version : nginx/1.14.0 (Ubuntu)
PHP version: PHP 7.4.13

The issue you are facing: Mail messages don’t load in the interface. The /apps/mail/api/messages?mailboxId=7&limit=20 XHR returns 500 error code but I can’t find it anywhere in the FPM or Nginx error.log

Is this the first time you’ve seen this error? Yes

Steps to replicate it:

  1. Clean Install
  2. Add email account manual TLS IMAP port 143 and STARTTLS SMTP on 587 (getting 500 error code as well but the mail account is added).
  3. Go to apps/mail. Folders are present but can’t see messages list

The output of your Nextcloud log in Admin > Logging:

nextcloud log
TypeError: Argument 1 passed to InterfaSys\LogNormalizer\Normalizer::normalizeException() must be an instance of Exception, instance of TypeError given, called in /var/www/clients/client2/web2/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php on line 294

0. /var/www/clients/client2/web2/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php - line 294:InterfaSys\LogNormalizer\Normalizer->normalizeException()
1. /var/www/clients/client2/web2/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php - line 256:InterfaSys\LogNormalizer\Normalizer->normalizeException()
2. <<closure>>InterfaSys\LogNormalizer\Normalizer->normalizeObject()
3. /var/www/clients/client2/web2/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php - line 100:call_user_func_array()
4. /var/www/clients/client2/web2/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php - line 68:InterfaSys\LogNormalizer\Normalizer->normalize()
5. <<closure>>InterfaSys\LogNormalizer\Normalizer->format()
6. /var/www/clients/client2/web2/cloud/lib/private/Log.php - line 324:array_walk()
7. /var/www/clients/client2/web2/cloud/lib/private/Log/PsrLoggerAdapter.php - line 136:OC\Log->logException()
8. /var/www/clients/client2/web2/cloud/lib/private/AppFramework/ScopedPsrLogger.php - line 89:OC\Log\PsrLoggerAdapter->error()
9. /var/www/clients/client2/web2/cloud/apps/mail/lib/Http/Middleware/ErrorMiddleware.php - line 101:OC\AppFramework\ScopedPsrLogger->error()
10. /var/www/clients/client2/web2/cloud/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php - line 122:OCA\Mail\Http\Middleware\ErrorMiddleware->afterException()
11. /var/www/clients/client2/web2/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 112:OC\AppFramework\Middleware\MiddlewareDispatcher->afterException()
12. /var/www/clients/client2/web2/cloud/lib/private/AppFramework/App.php - line 152:OC\AppFramework\Http\Dispatcher->dispatch()
13. /var/www/clients/client2/web2/cloud/lib/private/Route/Router.php - line 308:OC\AppFramework\App::main()
14. /var/www/clients/client2/web2/cloud/lib/base.php - line 1008:OC\Route\Router->match()
15. /var/www/clients/client2/web2/cloud/index.php - line 37:OC::handleRequest()

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

config
$CONFIG = array (
  'instanceid' => 'xxxxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxx',
  'trusted_domains' =>
  array (
    0 => 'xxxxxxxxxxxx'
  ),
  'datadirectory' => 'xxxxxxxxxxxx/data',
  'dbtype' => 'mysql',
  'version' => '20.0.2.2',
  'overwrite.cli.url' => 'https://xxxxxxxxxxxx',
  'dbname' => 'xxxxxxxxxxxx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'xxxxxxxxxxxx',
  'dbpassword' => 'xxxxxxxxxxxx',
  'installed' => true,
  'debug' => true,
  'loglevel' => 1
);

The output of your Apache/nginx/system log in /var/log/____:
No error logs from nginx or upstream.
Just the one line in access log with 500 response code

"GET /apps/mail/api/messages?mailboxId=7&limit=20 HTTP/2.0" 500 1852 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"

Horde IMAP log doesn’t catch anything for that 500 error code but here are some outputs of other actions.

Horde IMAP log - Folder list
>> Connection to: imap://localhost/
>> Server connection took 0.0002 seconds.
S: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot (Ubuntu) ready.
C: 1 STARTTLS
S: 1 OK Begin TLS negotiation now.
>> Command 1 took 0.0001 seconds.
>> Successfully completed TLS negotiation.
C: 2 CAPABILITY
S: * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN AUTH=LOGIN
S: 2 OK Pre-login capabilities listed, post-login capabilities have more.
>> Command 2 took 0.0003 seconds.
C: 3 AUTHENTICATE PLAIN [INITIAL CLIENT RESPONSE (username: xxxxxxxxx)]
S: 3 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE QUOTA] Logged in
>> Command 3 took 0.0098 seconds.
C: 4 NAMESPACE
S: * NAMESPACE (("" ".")) NIL NIL
S: 4 OK Namespace completed (0.001 + 0.000 secs).
>> Command 4 took 0.0037 seconds.
C: 5 LIST () "" (*) RETURN (SUBSCRIBED)
S: * LIST (\Subscribed) "." Junk
S: * LIST (\Subscribed) "." Archives
S: * LIST (\Subscribed) "." Trash
S: * LIST (\Subscribed) "." Sent
S: * LIST (\Subscribed) "." Drafts
S: * LIST () "." INBOX
S: 5 OK List completed (0.001 + 0.000 secs).
>> Command 5 took 0.0009 seconds.
C: 6 LIST () "" (Junk Archives Trash Sent Drafts INBOX) RETURN (STATUS (MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN))
S: * LIST () "." Junk
S: * STATUS Junk (MESSAGES 77 RECENT 7 UIDNEXT 1124 UIDVALIDITY 1581522430 UNSEEN 77)
S: * LIST () "." Archives
S: * STATUS Archives (MESSAGES 0 RECENT 0 UIDNEXT 1 UIDVALIDITY 1581522433 UNSEEN 0)
S: * LIST () "." Trash
S: * STATUS Trash (MESSAGES 3 RECENT 0 UIDNEXT 2645 UIDVALIDITY 1581522429 UNSEEN 0)
S: * LIST () "." Sent
S: * STATUS Sent (MESSAGES 25 RECENT 0 UIDNEXT 26 UIDVALIDITY 1581522427 UNSEEN 0)
S: * LIST () "." Drafts
S: * STATUS Drafts (MESSAGES 1 RECENT 0 UIDNEXT 7 UIDVALIDITY 1606510806 UNSEEN 0)
S: * LIST () "." INBOX
S: * STATUS INBOX (MESSAGES 1161 RECENT 0 UIDNEXT 3629 UIDVALIDITY 1581522426 UNSEEN 1)
S: 6 OK List completed (0.002 + 0.000 + 0.001 secs).
>> Command 6 took 0.0047 seconds.
C: 7 LOGOUT
S: * BYE Logging out
S: 7 OK Logout completed (0.001 + 0.000 secs).
>> Command 7 took 0.0007 seconds.
Horde IMAP log - STATUS command
>> Connection to: imap://localhost/
>> Server connection took 0.0002 seconds.
S: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot (Ubuntu) ready.
C: 1 STARTTLS
S: 1 OK Begin TLS negotiation now.
>> Command 1 took 0.0002 seconds.
>> Successfully completed TLS negotiation.
C: 2 CAPABILITY
S: * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN AUTH=LOGIN
S: 2 OK Pre-login capabilities listed, post-login capabilities have more.
>> Command 2 took 0.0005 seconds.
C: 3 AUTHENTICATE PLAIN [INITIAL CLIENT RESPONSE (username: xxxxxxxxx)]
S: 3 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE QUOTA] Logged in
>> Command 3 took 0.0107 seconds.
C: 4 STATUS INBOX (MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)
S: * STATUS INBOX (MESSAGES 1162 RECENT 0 UIDNEXT 3630 UIDVALIDITY 1581522426 UNSEEN 2)
S: 4 OK Status completed (0.001 + 0.000 secs).
>> Command 4 took 0.0009 seconds.
C: 5 LOGOUT
S: * BYE Logging out
S: 5 OK Logout completed (0.001 + 0.000 secs).
>> Command 5 took 0.0003 seconds.

Browser console log has only 1 error repeating in Apps -> Mail

Browser console log
GET https://xxxxxxxxxx/apps/mail/api/messages?mailboxId=7&limit=20 500
[ERROR] mail: Could not fetch envelopes

Error: Request failed with status code 500
    at e.exports (https://xxxxxxxxxx/apps/mail/js/mail.js:76:84208)
    at e.exports (https://xxxxxxxxxx/apps/mail/js/mail.js:326:5161)
    at XMLHttpRequest.f.onreadystatechange (https://xxxxxxxxxx/apps/mail/js/mail.js:76:83073)

Mail sending works

Horde SMTP log
>> Connection to: smtp://localhost:587
S: 220 xxxxxxxxxxxx ESMTP Postfix (Ubuntu)
C: EHLO xxxxxxxxxxxx
S: 250-xxxxxxxxxxxx
S: 250-PIPELINING
S: 250-SIZE
S: 250-VRFY
S: 250-ETRN
S: 250-STARTTLS
S: 250-ENHANCEDSTATUSCODES
S: 250-8BITMIME
S: 250-DSN
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
>> Successfully completed TLS negotiation.
C: EHLO xxxxxxxxxxxx
S: 250-xxxxxxxxxxxx
S: 250-PIPELINING
S: 250-SIZE
S: 250-VRFY
S: 250-ETRN
S: 250-AUTH PLAIN LOGIN
S: 250-AUTH=PLAIN LOGIN
S: 250-ENHANCEDSTATUSCODES
S: 250-8BITMIME
S: 250-DSN
S: 250 SMTPUTF8
[AUTH Command - method: PLAIN; username: xxxxxxxxxxxx]
S: 235 2.7.0 Authentication successful
C: MAIL FROM:<xxxxxxxxxxxx> SIZE=711 BODY=7BIT
C: RCPT TO:<xxxxxxxxxxxx>
S: 250 2.1.0 Ok
S: 250 2.1.5 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Alexandru Podaru <xxxxxxxxxxxx>
To: xxxxxxxxxxxx
Cc:
Subject: Test
Message-ID: <20201129221139.Horde.Lvc9DLj2K1r9ccKdzbfwv_F@xxxxxxxxxxxx>
User-Agent: Horde Application Framework 5
Date: Sun, 29 Nov 2020 22:11:39 +0000
Content-Type: multipart/alternative; boundary="=_DGKZPq9UHERtsfvrtBPncWv"
MIME-Version: 1.0

This message is in MIME format.

--=_DGKZPq9UHERtsfvrtBPncWv
Content-Type: text/plain; charset=utf-8
Content-Description: Plaintext Version of Message

test nextcloud
--=_DGKZPq9UHERtsfvrtBPncWv
Content-Type: text/html; charset=utf-8
Content-Description: HTML Version of Message

<p style="margin:0;">test nextcloud</p>
--=_DGKZPq9UHERtsfvrtBPncWv--

C: .
S: 250 2.0.0 Ok: queued as 9EDCC60E3B
C: QUIT
S: 221 2.0.0 Bye

Could you get me that entry from the nextcloud.log files so I get the full details as json?

Also please double check if your Nextcloud really runs on php7.4. I think your web server might use 7.2, at least that would explain this error that we saw in a similar fashion in another ticket. https://github.com/nextcloud/mail/pull/4150 for context.

Sure, here you go

nextcloud.log
{
   "reqId":"APoApKeQY4igZ9PJFEfm",
   "level":3,
   "time":"2020-11-30T14:04:10+00:00",
   "remoteAddr":"xxxxxxxxxx",
   "user":"alex.podaru",
   "app":"index",
   "method":"GET",
   "url":"/apps/mail/api/messages?mailboxId=7&limit=20",
   "message":{
      "Exception":"TypeError",
      "Message":"Argument 1 passed to InterfaSys\\LogNormalizer\\Normalizer::normalizeException() must be an instance of Exception, instance of TypeError given, called in /cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php on line 294",
      "Code":0,
      "Trace":[
         {
            "file":"/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php",
            "line":294,
            "function":"normalizeException",
            "class":"InterfaSys\\LogNormalizer\\Normalizer",
            "type":"->"
         },
         {
            "file":"/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php",
            "line":256,
            "function":"normalizeException",
            "class":"InterfaSys\\LogNormalizer\\Normalizer",
            "type":"->"
         },
         {
            "function":"normalizeObject",
            "class":"InterfaSys\\LogNormalizer\\Normalizer",
            "type":"->"
         },
         {
            "file":"/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php",
            "line":100,
            "function":"call_user_func_array"
         },
         {
            "file":"/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php",
            "line":68,
            "function":"normalize",
            "class":"InterfaSys\\LogNormalizer\\Normalizer",
            "type":"->"
         },
         {
            "function":"format",
            "class":"InterfaSys\\LogNormalizer\\Normalizer",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/Log.php",
            "line":324,
            "function":"array_walk"
         },
         {
            "file":"/cloud/lib/private/Log/PsrLoggerAdapter.php",
            "line":136,
            "function":"logException",
            "class":"OC\\Log",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/AppFramework/ScopedPsrLogger.php",
            "line":89,
            "function":"error",
            "class":"OC\\Log\\PsrLoggerAdapter",
            "type":"->"
         },
         {
            "file":"/cloud/apps/mail/lib/Http/Middleware/ErrorMiddleware.php",
            "line":101,
            "function":"error",
            "class":"OC\\AppFramework\\ScopedPsrLogger",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php",
            "line":122,
            "function":"afterException",
            "class":"OCA\\Mail\\Http\\Middleware\\ErrorMiddleware",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/AppFramework/Http/Dispatcher.php",
            "line":112,
            "function":"afterException",
            "class":"OC\\AppFramework\\Middleware\\MiddlewareDispatcher",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/AppFramework/App.php",
            "line":152,
            "function":"dispatch",
            "class":"OC\\AppFramework\\Http\\Dispatcher",
            "type":"->"
         },
         {
            "file":"/cloud/lib/private/Route/Router.php",
            "line":308,
            "function":"main",
            "class":"OC\\AppFramework\\App",
            "type":"::"
         },
         {
            "file":"/cloud/lib/base.php",
            "line":1008,
            "function":"match",
            "class":"OC\\Route\\Router",
            "type":"->"
         },
         {
            "file":"/cloud/index.php",
            "line":37,
            "function":"handleRequest",
            "class":"OC",
            "type":"::"
         }
      ],
      "File":"/cloud/3rdparty/interfasys/lognormalizer/src/Normalizer.php",
      "Line":282,
      "CustomMessage":"--"
   },
   "userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36",
   "version":"20.0.2.2"
}

PHP version is 7.4.13

Also, the config file I posted initially wasn’t complete. I also have these instructions in there:

'app.mail.verify-tls-peer' => false,
'mail_smtpstreamoptions' => array(
	'ssl' => array(
		'allow_self_signed' => true,
		'verify_peer' => false,
		'verify_peer_name' => false
	)
),

I have to fix the log normalizer in order to get the real trace: https://github.com/interfasys/lognormalizer/pull/2

Sorry for the late answer. Had a hell of a day.
Here’s the log after making the same changes in 3rdparty/interfasys/lognormalizer/src/Normalizer.php

{
   "reqId":"wXfoGYNT9cCGRmoIfkaC",
   "level":3,
   "time":"2020-12-01T15:32:13+00:00",
   "remoteAddr":"xxxxxxxxxxxxx",
   "user":"alex.podaru",
   "app":"mail",
   "method":"GET",
   "url":"/apps/mail/api/messages?mailboxId=13&limit=20",
   "message":{
      "Exception":"Exception",
      "Message":"Argument 1 passed to OCA\\Mail\\Controller\\MessagesController::index() must be of the type int, null given, called in cloud/lib/private/AppFramework/Http/Dispatcher.php on line 169",
      "Code":0,
      "Trace":[
         {
            "file":"cloud/lib/private/AppFramework/App.php",
            "line":152,
            "function":"dispatch",
            "class":"OC\\AppFramework\\Http\\Dispatcher",
            "type":"->"
         },
         {
            "file":"cloud/lib/private/Route/Router.php",
            "line":308,
            "function":"main",
            "class":"OC\\AppFramework\\App",
            "type":"::"
         },
         {
            "file":"cloud/lib/base.php",
            "line":1008,
            "function":"match",
            "class":"OC\\Route\\Router",
            "type":"->"
         },
         {
            "file":"cloud/index.php",
            "line":37,
            "function":"handleRequest",
            "class":"OC",
            "type":"::"
         }
      ],
      "File":"cloud/lib/private/AppFramework/Http/Dispatcher.php",
      "Line":110,
      "Previous":{
         "Exception":"TypeError",
         "Message":"Argument 1 passed to OCA\\Mail\\Controller\\MessagesController::index() must be of the type int, null given, called in cloud/lib/private/AppFramework/Http/Dispatcher.php on line 169",
         "Code":0,
         "Trace":[
            {
               "file":"cloud/lib/private/AppFramework/Http/Dispatcher.php",
               "line":169,
               "function":"index",
               "class":"OCA\\Mail\\Controller\\MessagesController",
               "type":"->"
            },
            {
               "file":"cloud/lib/private/AppFramework/Http/Dispatcher.php",
               "line":100,
               "function":"executeController",
               "class":"OC\\AppFramework\\Http\\Dispatcher",
               "type":"->"
            },
            {
               "file":"cloud/lib/private/AppFramework/App.php",
               "line":152,
               "function":"dispatch",
               "class":"OC\\AppFramework\\Http\\Dispatcher",
               "type":"->"
            },
            {
               "file":"cloud/lib/private/Route/Router.php",
               "line":308,
               "function":"main",
               "class":"OC\\AppFramework\\App",
               "type":"::"
            },
            {
               "file":"cloud/lib/base.php",
               "line":1008,
               "function":"match",
               "class":"OC\\Route\\Router",
               "type":"->"
            },
            {
               "file":"cloud/index.php",
               "line":37,
               "function":"handleRequest",
               "class":"OC",
               "type":"::"
            }
         ],
         "File":"cloud/apps/mail/lib/Controller/MessagesController.php",
         "Line":152
      },
      "CustomMessage":"Argument 1 passed to OCA\\Mail\\Controller\\MessagesController::index() must be of the type int, null given, called in cloud/lib/private/AppFramework/Http/Dispatcher.php on line 169"
   },
   "userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36",
   "version":"20.0.2.2"
}
1 Like

Thanks a lot @AlexPodaru. Now at least we know the original error.

this is strange. The URL contains the mailboxId but it’s somehow lost when the controller method is invoked at https://github.com/nextcloud/mail/blob/stable1.7/lib/Controller/MessagesController.php#L152.

I’m not sure how that could happen. Sounds almost like a bug in Nextcloud.

Thanks @ChristophWurst. Should I move the topic to a different category? If so which one do you think best?

PS: Gonna change the title to the original error as well

No the topic is fine. But I think we can take this to Github as it’s possibly a bug. Mind opening a ticket at https://github.com/nextcloud/mail/ with your system info from above?

Sure thing. Here it is: https://github.com/nextcloud/mail/issues/4168

1 Like