Browse Source

Fix some PHP8 warnings (#8239)

pull/8247/head
Aleksander Machniak 4 years ago
parent
commit
38f519659c
  1. 1
      CHANGELOG.md
  2. 2
      program/include/rcmail_attachment_handler.php
  3. 24
      program/lib/Roundcube/rcube_addressbook.php
  4. 4
      program/lib/Roundcube/rcube_mime.php
  5. 62
      tests/Framework/Addressbook.php

1
CHANGELOG.md

@ -25,6 +25,7 @@
- Fix locked SQLite database for the CLI tools (#8035)
- Fix importing contacts with no email address (#8227)
- Fix so session's search scope is not used if search is not active (#8199)
- Fix some PHP8 warnings (#8239)
## Release 1.5.0

2
program/include/rcmail_attachment_handler.php

@ -229,7 +229,7 @@ class rcmail_attachment_handler
}
}
else {
$data = $attachment['data'];
$data = $attachment['data'] ?? '';
if (!$data && $attachment['path']) {
$data = file_get_contents($attachment['path']);
}

24
program/lib/Roundcube/rcube_addressbook.php

@ -685,20 +685,34 @@ abstract class rcube_addressbook
static $compose_mode;
if (!isset($compose_mode)) {
$compose_mode = rcube::get_instance()->config->get('addressbook_name_listing', 0);
$compose_mode = (int) rcube::get_instance()->config->get('addressbook_name_listing', 0);
}
$get_names = function ($contact, $fields) {
$result = [];
foreach ($fields as $field) {
if (!empty($contact[$field])) {
$result[] = $contact[$field];
}
}
return $result;
};
switch ($compose_mode) {
case 3:
$fn = implode(' ', [$contact['surname'] . ',', $contact['firstname'], $contact['middlename']]);
$names = $get_names($contact, ['firstname', 'middlename']);
if (!empty($contact['surname'])) {
array_unshift($names, $contact['surname'] . ',');
}
$fn = implode(' ', $names);
break;
case 2:
$keys = ['surname', 'firstname', 'middlename'];
$fn = implode(' ', array_filter(array_intersect_key($contact, array_flip($keys))));
$fn = implode(' ', $get_names($contact, $keys));
break;
case 1:
$keys = ['firstname', 'middlename', 'surname'];
$fn = implode(' ', array_filter(array_intersect_key($contact, array_flip($keys))));
$fn = implode(' ', $get_names($contact, $keys));
break;
case 0:
if (!empty($contact['name'])) {
@ -706,7 +720,7 @@ abstract class rcube_addressbook
}
else {
$keys = ['prefix', 'firstname', 'middlename', 'surname', 'suffix'];
$fn = implode(' ', array_filter(array_intersect_key($contact, array_flip($keys))));
$fn = implode(' ', $get_names($contact, $keys));
}
break;
default:

4
program/lib/Roundcube/rcube_mime.php

@ -494,7 +494,9 @@ class rcube_mime
// remove quote chars
$line = substr($line, $q);
// remove (optional) space-staffing
if ($line[0] === ' ') $line = substr($line, 1);
if (isset($line[0]) && $line[0] === ' ') {
$line = substr($line, 1);
}
// The same paragraph (We join current line with the previous one) when:
// - the same level of quoting

62
tests/Framework/Addressbook.php

@ -27,4 +27,66 @@ class Framework_Addressbook extends PHPUnit\Framework\TestCase
$this->assertSame(['home' => ['test@test.com']], $result);
}
/**
* Test for compose_list_name() method
*/
function test_compose_list_name()
{
$contact = [];
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('', $result);
$contact = ['email' => 'email@address.tld'];
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('email@address.tld', $result);
$contact = ['email' => 'email@address.tld', 'organization' => 'Org'];
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('Org', $result);
$contact['firstname'] = 'First';
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('First', $result);
$contact['surname'] = 'Last';
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('First Last', $result);
$contact['name'] = 'Name';
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('Name', $result);
unset($contact['name']);
$contact['prefix'] = 'Dr.';
$contact['suffix'] = 'Jr.';
$contact['middlename'] = 'M.';
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('Dr. First M. Last Jr.', $result);
// TODO: Test different modes
/*
rcube::get_instance()->config->set('addressbook_name_listing', 3);
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('Last, First M.', $result);
rcube::get_instance()->config->set('addressbook_name_listing', 2);
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('Last First M.', $result);
rcube::get_instance()->config->set('addressbook_name_listing', 1);
$result = rcube_addressbook::compose_list_name($contact);
$this->assertSame('First M. Last', $result);
*/
}
}
Loading…
Cancel
Save