Piler 1.4.3 RT Index + error on webui while browsing results

Issue #1269 resolved
Leszek Piatek created an issue

@Janos SUTO any clues what can be wrong, while navigating through results (different pages) I get:

nginx_1       | PHP message: PHP Warning:  Undefined array key 14 in /var/piler/www/model/search/search.php on line 558PHP message: PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/piler/www/model/search/search.php:608
nginx_1       | Stack trace:
nginx_1       | #0 /var/piler/www/model/search/search.php(558): ModelSearchSearch->get_preferred_recipient()
nginx_1       | #1 /var/piler/www/model/search/search.php(56): ModelSearchSearch->get_meta_data()
nginx_1       | #2 /var/piler/www/controller/search/helper.php(62): ModelSearchSearch->search_messages()
nginx_1       | #3 /var/piler/www/system/front.php(36): ControllerSearchHelper->index()
nginx_1       | #4 /var/piler/www/system/front.php(14): Front->execute()
nginx_1       | #5 /var/piler/www/index.php(114): Front->dispatch()
nginx_1       | #6 {main}
nginx_1       |   thrown in /var/piler/www/model/search/search.php on line 608

I’ve checked and this is here I guess something with this code is wrong (generating rcpt array).

What would be sane default result for this function? I guess some rcpt headers are broken or empt? Make it sense to fix it like this:

private function get_preferred_recipient($arr = []) {
      if (!is_array($arr)) $arr = []; // fix

      $result = '';

      $session = Registry::get('session');
      $group_emails = $session->get('group_emails');
      $user_emails = $session->get('user_emails');

      if(count($arr) < 2 || (!$group_emails && !$user_emails) ) { return $arr[0]; }

      foreach ($arr as $a) {
         if($result == '' && in_array($a, $group_emails)) { $result = $a; }
         if(in_array($a, $user_emails)) { $result = $a; }
      }

      if($result == '') { $result = $arr[0]; }

      return $result;
   }

I have the same behaviour on two instances with different messages.

Comments (6)

  1. Janos SUTO repo owner

    The get_preferred_recipient($arr = []) should always return a string with one of your email addresses. You may add some debugging to syslog the returned value to verify it’s really the case.

    However, another user also reported a similar issue, and Frank was kind enough to provide a patch as well, see below. I encourage you to test it. I’d appreaciate your feedback (and Frank’s fix as well)

    --- webui/model/search/search.php.orig  2023-01-13 13:13:49.060000000 +0100
    +++ webui/model/search/search.php   2023-01-13 13:13:48.028000000 +0100
    @@ -554,8 +554,8 @@
                 $m['shortfrom'] = make_short_string($m['from'], MAX_CGI_FROM_SUBJ_LEN);
                 $m['from'] = escape_gt_lt_quote_symbols($m['from']);
    
    -            isset($rcpt[$m['id']]) ? $m['to'] = $rcpt[$m['id']] : $m['to'] = '';
    -            $m['shortto'] = make_short_string($this->get_preferred_recipient($rcpt[$m['id']]), MAX_CGI_FROM_SUBJ_LEN);
    +            isset($rcpt[$m['id']]) ? $m['to'] = $rcpt[$m['id']] : $m['to'] = array('');
    +            $m['shortto'] = make_short_string($this->get_preferred_recipient($m['to']), MAX_CGI_FROM_SUBJ_LEN);
                 $m['to'] = escape_gt_lt_quote_symbols($m['to']);
    

  2. Leszek Piatek reporter

    @Janos SUTO it fixed my errors, this change make more sense = You can merge it to master

  3. Leszek Piatek reporter

    Ouh, and @Janos SUTO as I assumed there is no email adress in some edge case of “To:” header

    To: undisclosed-recipients: ;
    

    That was the case…

  4. Log in to comment