PHP Error when trying to open mail with empty message body (example PDF attachment from a Canon scanner)

Issue #1313 closed
Clemens Martin created an issue

Piler Version: 1.4.1 build 1001 on Ubuntu Linux 22.04.3 with nginx and php8.1

Fresh install.

2023/09/04 09:22:13 [error] 937#937: *833 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/piler/www/model/search/message.php:183
Stack trace:
#0 /var/piler/www/controller/message/view.php(83): ModelSearchMessage->extract_message()
#1 /var/piler/www/system/front.php(36): ControllerMessageView->index()
#2 /var/piler/www/system/front.php(14): Front->execute()
#3 /var/piler/www/index.php(114): Front->dispatch()
#4 {main}
thrown in /var/piler/www/model/search/message.php on line 183" while reading response header from upstream, client: 192.168.100.61, server: piler.baufeld.local, request: "POST /message.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "piler.baufeld.local", referrer: "http://xxx.yyy.zzz/search.php"

Possible fix in /var/piler/www/model/search/message.php line 183:

      /* null check $parts */
      if(!is_null($parts)) {
          for($i=0; $i<count($parts); $i++) {

             $body = Piler_Mime_Decode::fixMimeBodyPart($parts[$i]['headers'], $parts[$i]['body']);

             if($parts[$i]['headers']['content-type']['type'] == 'text/html') {
                $this->message['text/html'] .= $purifier->purify($body);
             }
             else {
                $this->message['text/plain'] .= $body;
             }

          }
      }

Comments (5)

  1. Clemens Martin reporter

    Upgraded to v1.4.4 (Web-UI health monitor showing 1.4.4 build 1001)

    System is up and running, but the bug still exists in the Web-UI when trying to open an empty message with just an attachment file in it.

    Added the if-Block from above to message.php again, then it is working.

  2. Janos SUTO repo owner

    It seems to happen when the message has no body at all. I’ve just fixed this issue on the master branch.

  3. Log in to comment