diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..c0e7203619b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + cs: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')" + + name: Coding Style + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.3" + extensions: mbstring + tools: composer:v2 + coverage: none + ini-values: error_reporting=E_ALL + + - name: Setup composer + run: | + cp composer.json-dist composer.json + + - name: Install dependencies + run: composer install --prefer-dist --no-interaction --no-progress + + - name: Check Coding Style + run: vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose + + - name: Check composer.json format + run: composer validate --strict --no-check-lock && composer normalize --dry-run --no-check-lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000000..a3317e06083 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,143 @@ +in([__DIR__]) + ->exclude(['vendor']); + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@PhpCsFixer' => true, + '@PHP74Migration' => true, + + // required by PSR-12 + 'concat_space' => [ + 'spacing' => 'one', + ], + + // disable some too strict rules + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last', + 'sort_algorithm' => 'none', + ], + 'single_line_throw' => false, + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + ], + 'native_constant_invocation' => true, + 'native_function_invocation' => false, + 'void_return' => false, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'exit'], + ], + 'combine_consecutive_issets' => false, + 'combine_consecutive_unsets' => false, + 'multiline_whitespace_before_semicolons' => false, + 'no_superfluous_elseif' => false, + 'ordered_class_elements' => false, + 'php_unit_internal_class' => false, + 'php_unit_test_class_requires_covers' => false, + 'phpdoc_add_missing_param_annotation' => false, + 'return_assignment' => false, + 'comment_to_phpdoc' => false, + 'general_phpdoc_annotation_remove' => [ + 'annotations' => ['author', 'copyright', 'throws'], + ], + 'nullable_type_declaration_for_default_null_value' => [ + 'use_nullable_type_declaration' => false, + ], + + // fn => without curly brackets is less readable, + // also prevent bounding of unwanted variables for GC + 'use_arrow_functions' => false, + + // disable too destructive formating for now + 'escape_implicit_backslashes' => false, + 'heredoc_to_nowdoc' => false, + 'no_useless_else' => false, + 'no_useless_return' => false, + 'phpdoc_no_empty_return' => false, + 'phpdoc_order' => false, + 'phpdoc_var_annotation_correct_order' => false, + 'protected_to_private' => false, + 'simple_to_complex_string_variable' => false, + 'single_line_comment_style' => false, + + // enable some safe rules from @PHP71Migration:risky + 'pow_to_exponentiation' => true, + 'is_null' => true, + 'modernize_types_casting' => true, + 'dir_constant' => true, + 'combine_nested_dirname' => true, + 'non_printable_character' => [ + 'use_escape_sequences_in_strings' => true, + ], + + // TODO + 'align_multiline_comment' => false, + 'array_indentation' => false, + 'array_syntax' => false, + 'backtick_to_shell_exec' => false, + 'binary_operator_spaces' => false, + 'blank_line_before_statement' => false, + 'class_attributes_separation' => false, + 'class_definition' => false, + 'class_reference_name_casing' => false, + 'class_reference_name_casing' => false, + 'concat_space' => false, + 'constant_case' => false, + 'control_structure_continuation_position' => false, + 'dir_constant' => false, + 'elseif' => false, + 'empty_loop_condition' => false, + 'explicit_indirect_variable' => false, + 'explicit_string_variable' => false, + 'function_declaration' => false, + 'general_phpdoc_annotation_remove' => false, + 'global_namespace_import' => false, + 'heredoc_indentation' => false, + 'increment_style' => false, + 'integer_literal_case' => false, + 'is_null' => false, + 'list_syntax' => false, + 'method_argument_space' => false, + 'method_chaining_indentation' => false, + 'modernize_types_casting' => false, + 'native_constant_invocation' => false, + 'native_type_declaration_casing' => false, + 'new_with_parentheses' => false, + 'no_alias_language_construct_call' => false, + 'no_blank_lines_after_phpdoc' => false, + 'no_break_comment' => false, + 'no_empty_statement' => false, + 'no_extra_blank_lines' => false, + 'no_null_property_initialization' => false, + 'no_superfluous_phpdoc_tags' => false, + 'no_unneeded_control_parentheses' => false, + 'no_useless_concat_operator' => false, + 'operator_linebreak' => false, + 'php_unit_method_casing' => false, + 'phpdoc_align' => false, + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_no_alias_tag' => false, + 'phpdoc_no_package' => false, + 'phpdoc_scalar' => false, + 'phpdoc_separation' => false, + 'phpdoc_single_line_var_spacing' => false, + 'phpdoc_summary' => false, + 'phpdoc_to_comment' => false, + 'phpdoc_trim' => false, + 'phpdoc_types_order' => false, + 'phpdoc_var_without_name' => false, + 'single_line_comment_spacing' => false, + 'single_quote' => false, + 'single_trait_insert_per_statement' => false, + 'standardize_increment' => false, + 'ternary_to_null_coalescing' => false, + 'trailing_comma_in_multiline' => false, + 'visibility_required' => false, + 'yoda_style' => false, + ]) + ->setFinder($finder) + ->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.' . md5(__DIR__) . '.cache'); diff --git a/composer.json-dist b/composer.json-dist index bb49143c7a3..aa23b690180 100644 --- a/composer.json-dist +++ b/composer.json-dist @@ -2,35 +2,38 @@ "name": "roundcube/roundcubemail", "description": "The Roundcube Webmail suite", "license": "GPL-3.0-or-later", - "repositories": [ - { - "type": "composer", - "url": "https://plugins.roundcube.net" - } - ], "require": { "php": ">=7.3.0", - "pear/pear-core-minimal": "~1.10.1", + "bacon/bacon-qr-code": "^2.0.0", + "guzzlehttp/guzzle": "^7.3.0", + "masterminds/html5": "~2.8.0", "pear/auth_sasl": "~1.1.0", - "pear/mail_mime": "~1.10.0", - "pear/net_smtp": "~1.10.0", "pear/crypt_gpg": "~1.6.3", + "pear/mail_mime": "~1.10.0", "pear/net_sieve": "~1.4.5", + "pear/net_smtp": "~1.10.0", + "pear/pear-core-minimal": "~1.10.1", "roundcube/plugin-installer": "~0.3.1", - "roundcube/rtf-html-php": "~2.1", - "masterminds/html5": "~2.8.0", - "bacon/bacon-qr-code": "^2.0.0", - "guzzlehttp/guzzle": "^7.3.0" + "roundcube/rtf-html-php": "^2.1" }, "require-dev": { + "ergebnis/composer-normalize": "^2.13", + "friendsofphp/php-cs-fixer": "^3.0", "phpunit/phpunit": "^9" }, "suggest": { - "kolab/net_ldap3": "~1.1.4 required for connecting to LDAP", - "bjeavons/zxcvbn-php": "^1.0 required for Zxcvbn password strength driver" + "bjeavons/zxcvbn-php": "^1.0 required for Zxcvbn password strength driver", + "kolab/net_ldap3": "~1.1.4 required for connecting to LDAP" }, + "repositories": [ + { + "type": "composer", + "url": "https://plugins.roundcube.net" + } + ], "config": { "allow-plugins": { + "ergebnis/composer-normalize": true, "roundcube/plugin-installer": true } } diff --git a/config/mimetypes.php b/config/mimetypes.php index efb4698e1e2..fb38f8cf774 100644 --- a/config/mimetypes.php +++ b/config/mimetypes.php @@ -1,6 +1,6 @@ '; } if (empty($found_db_driver)) { - $RCI->failures++; + $RCI->failures++; } ?> @@ -224,7 +224,7 @@ $RCI->pass($var); } else { - $RCI->fail($var, "is '$status', should be '$val'"); + $RCI->fail($var, "is '$status', should be '$val'"); } echo '
'; } @@ -264,7 +264,7 @@ $RCI->pass($var); } else { - $RCI->optfail($var, "is '$status', could be '$val'"); + $RCI->optfail($var, "is '$status', could be '$val'"); } echo '
'; } diff --git a/installer/config.php b/installer/config.php index 3deeac5091e..83fde1428a2 100644 --- a/installer/config.php +++ b/installer/config.php @@ -1,6 +1,6 @@ create_config(); - - if ($RCI->save_configfile($_SESSION['config'])) { - echo '

The config file was saved successfully into' - . ' '.RCMAIL_CONFIG_DIR.' directory of your Roundcube installation.'; - - if ($RCI->legacy_config) { - echo '

Afterwards, please remove the old configuration files' - . ' main.inc.php and db.inc.php from the config directory.'; - } - - echo '

'; - } - else { - $save_button = ''; - if (($dir = sys_get_temp_dir()) && @is_writable($dir)) { - echo ''; - echo ''; - - $button_txt = html::quote('Save in ' . $dir); - $save_button = ' '; - } - - echo '

Copy or download the following configuration and save it'; - echo ' as config.inc.php within the '.RCUBE_CONFIG_DIR.' directory of your Roundcube installation.
'; - echo ' Make sure that there are no characters before the <?php bracket when saving the file.'; - echo ' '; - echo $save_button; + $_SESSION['config'] = $RCI->create_config(); - if ($RCI->legacy_config) { - echo '

Afterwards, please remove the old configuration files' - . ' main.inc.php and db.inc.php from the config directory.'; - } + if ($RCI->save_configfile($_SESSION['config'])) { + echo '

The config file was saved successfully into' + . ' '.RCMAIL_CONFIG_DIR.' directory of your Roundcube installation.'; - echo '

'; + if ($RCI->legacy_config) { + echo '

Afterwards, please remove the old configuration files' + . ' main.inc.php and db.inc.php from the config directory.'; + } - $textbox = new html_textarea(['rows' => 16, 'cols' => 60, 'class' => 'configfile']); - echo $textbox->show(($_SESSION['config'])); - } + echo '

'; + } + else { + $save_button = ''; + if (($dir = sys_get_temp_dir()) && @is_writable($dir)) { + echo ''; + echo ''; + + $button_txt = html::quote('Save in ' . $dir); + $save_button = ' '; + } + + echo '

Copy or download the following configuration and save it'; + echo ' as config.inc.php within the '.RCUBE_CONFIG_DIR.' directory of your Roundcube installation.
'; + echo ' Make sure that there are no characters before the <?php bracket when saving the file.'; + echo ' '; + echo $save_button; + + if ($RCI->legacy_config) { + echo '

Afterwards, please remove the old configuration files' + . ' main.inc.php and db.inc.php from the config directory.'; + } + + echo '

'; + + $textbox = new html_textarea(['rows' => 16, 'cols' => 60, 'class' => 'configfile']); + echo $textbox->show(($_SESSION['config'])); + } - echo '

Of course there are more options to configure. + echo '

Of course there are more options to configure. Have a look at the defaults.inc.php file or visit Howto_Config to find out.

'; - echo '

'; + echo '

'; - // echo ''; - echo "\n
\n"; + // echo ''; + echo "\n
\n"; } ?> @@ -604,7 +604,7 @@ '_mime_param_folding', 'id' => 'cfgmimeparamfolding']); -$select_param_folding->add('Full RFC 2231 (Roundcube, Thunderbird)', '0'); +$select_param_folding->add('Full RFC 2231 (Roundcube, Thunderbird)', '0'); $select_param_folding->add('RFC 2047/2231 (MS Outlook, OE)', '1'); $select_param_folding->add('Full RFC 2047 (deprecated)', '2'); diff --git a/installer/index.php b/installer/index.php index 1a523d7ef7e..df68279c261 100644 --- a/installer/index.php +++ b/installer/index.php @@ -1,6 +1,6 @@ configured) { if (!empty($RCI->config['db_dsnw'])) { $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false); - $DB->set_debug((bool)$RCI->config['sql_debug']); + $DB->set_debug((bool) $RCI->config['sql_debug']); $DB->db_connect('w'); if (!($db_error_msg = $DB->is_error())) { @@ -455,7 +455,7 @@ $a_host = parse_url($imap_host); if ($a_host['host']) { $imap_host = $a_host['host']; - $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls'])) ? $a_host['scheme'] : null; + $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl', 'imaps', 'tls'])) ? $a_host['scheme'] : null; $imap_port = $a_host['port'] ?? ($imap_ssl && $imap_ssl != 'tls' ? 993 : 143); } diff --git a/plugins/acl/acl.php b/plugins/acl/acl.php index d418b9e771a..c7b0d0997ad 100644 --- a/plugins/acl/acl.php +++ b/plugins/acl/acl.php @@ -156,12 +156,12 @@ function folder_form($args) if (!strlen($mbox_imap)) { return $args; } -/* + /* // Do nothing on protected folders (?) if (!empty($args['options']['protected'])) { return $args; } -*/ + */ // Get MYRIGHTS if (empty($myrights)) { return $args; @@ -178,11 +178,12 @@ function folder_form($args) $this->include_stylesheet($this->local_skin_path() . '/acl.css'); // add Info fieldset if it doesn't exist - if (!isset($args['form']['props']['fieldsets']['info'])) + if (!isset($args['form']['props']['fieldsets']['info'])) { $args['form']['props']['fieldsets']['info'] = [ 'name' => $this->rc->gettext('info'), 'content' => [] ]; + } // Display folder rights to 'Info' fieldset $args['form']['props']['fieldsets']['info']['content']['myrights'] = [ @@ -462,9 +463,15 @@ private function list_rights($attrib = []) foreach ($items as $key => $right) { $in = $this->acl_compare($userrights, $right); switch ($in) { - case 2: $class = 'enabled'; break; - case 1: $class = 'partial'; break; - default: $class = 'disabled'; break; + case 2: + $class = 'enabled'; + break; + case 1: + $class = 'partial'; + break; + default: + $class = 'disabled'; + break; } $table->add('acl' . $key . ' ' . $class, ''); } @@ -584,7 +591,7 @@ private function action_delete() */ private function action_list() { - if (in_array('acl_advanced_mode', (array)$this->rc->config->get('dont_override'))) { + if (in_array('acl_advanced_mode', (array) $this->rc->config->get('dont_override'))) { return; } @@ -645,8 +652,12 @@ function acl2text($rights) */ function acl_compare($acl1, $acl2) { - if (!is_array($acl1)) $acl1 = str_split($acl1); - if (!is_array($acl2)) $acl2 = str_split($acl2); + if (!is_array($acl1)) { + $acl1 = str_split($acl1); + } + if (!is_array($acl2)) { + $acl2 = str_split($acl2); + } $rights = $this->rights_supported(); diff --git a/plugins/acl/tests/Acl.php b/plugins/acl/tests/Acl.php index 12064119002..0b326f4795c 100644 --- a/plugins/acl/tests/Acl.php +++ b/plugins/acl/tests/Acl.php @@ -21,4 +21,3 @@ function test_constructor() $plugin->init(); } } - diff --git a/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php b/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php index bd52496cd62..b3908944146 100644 --- a/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php +++ b/plugins/additional_message_headers/tests/AdditionalMessageHeaders.php @@ -33,4 +33,3 @@ function test_plugin() $this->assertSame("MIME-Version: 1.0\r\nX-Test: Test\r\n", $result['message']->txtHeaders()); } } - diff --git a/plugins/archive/archive.php b/plugins/archive/archive.php index fd099ab134a..c1a95bc9ba0 100644 --- a/plugins/archive/archive.php +++ b/plugins/archive/archive.php @@ -187,35 +187,35 @@ function move_messages() foreach ($messages as $message) { $subfolder = null; switch ($archive_type) { - case 'year': - $subfolder = $rcmail->format_date($message->timestamp, 'Y'); - break; - - case 'month': - $subfolder = $rcmail->format_date($message->timestamp, 'Y') - . $delimiter . $rcmail->format_date($message->timestamp, 'm'); - break; - - case 'tbmonth': - $subfolder = $rcmail->format_date($message->timestamp, 'Y') - . $delimiter . $rcmail->format_date($message->timestamp, 'Y') - . '-' . $rcmail->format_date($message->timestamp, 'm'); - break; - - case 'sender': - $subfolder = $this->sender_subfolder($message->get('from')); - break; - - case 'folderyear': - $subfolder = $rcmail->format_date($message->timestamp, 'Y') - . $delimiter . $mbox; - break; - - case 'foldermonth': - $subfolder = $rcmail->format_date($message->timestamp, 'Y') - . $delimiter . $rcmail->format_date($message->timestamp, 'm') - . $delimiter . $mbox; - break; + case 'year': + $subfolder = $rcmail->format_date($message->timestamp, 'Y'); + break; + + case 'month': + $subfolder = $rcmail->format_date($message->timestamp, 'Y') + . $delimiter . $rcmail->format_date($message->timestamp, 'm'); + break; + + case 'tbmonth': + $subfolder = $rcmail->format_date($message->timestamp, 'Y') + . $delimiter . $rcmail->format_date($message->timestamp, 'Y') + . '-' . $rcmail->format_date($message->timestamp, 'm'); + break; + + case 'sender': + $subfolder = $this->sender_subfolder($message->get('from')); + break; + + case 'folderyear': + $subfolder = $rcmail->format_date($message->timestamp, 'Y') + . $delimiter . $mbox; + break; + + case 'foldermonth': + $subfolder = $rcmail->format_date($message->timestamp, 'Y') + . $delimiter . $rcmail->format_date($message->timestamp, 'm') + . $delimiter . $mbox; + break; } // compose full folder path diff --git a/plugins/attachment_reminder/tests/AttachmentReminder.php b/plugins/attachment_reminder/tests/AttachmentReminder.php index 0e33fae5710..b4d595482dc 100644 --- a/plugins/attachment_reminder/tests/AttachmentReminder.php +++ b/plugins/attachment_reminder/tests/AttachmentReminder.php @@ -66,4 +66,3 @@ function test_prefs_save() $this->assertTrue($result['prefs']['attachment_reminder']); } } - diff --git a/plugins/autologon/tests/Autologon.php b/plugins/autologon/tests/Autologon.php index 206867f9b68..318a46e9fcb 100644 --- a/plugins/autologon/tests/Autologon.php +++ b/plugins/autologon/tests/Autologon.php @@ -23,4 +23,3 @@ function test_constructor() $plugin->authenticate([]); } } - diff --git a/plugins/autologout/tests/Autologout.php b/plugins/autologout/tests/Autologout.php index 20f3ede80b8..b9dfa9bab8f 100644 --- a/plugins/autologout/tests/Autologout.php +++ b/plugins/autologout/tests/Autologout.php @@ -22,4 +22,3 @@ function test_constructor() $plugin->startup([]); } } - diff --git a/plugins/database_attachments/database_attachments.php b/plugins/database_attachments/database_attachments.php index 18e77ef8ee9..5f7f4b71c36 100644 --- a/plugins/database_attachments/database_attachments.php +++ b/plugins/database_attachments/database_attachments.php @@ -1,6 +1,6 @@ assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/debug_logger/debug_logger.php b/plugins/debug_logger/debug_logger.php index c31dd06dbaf..308bd79013e 100644 --- a/plugins/debug_logger/debug_logger.php +++ b/plugins/debug_logger/debug_logger.php @@ -48,9 +48,9 @@ * [17-Feb-2009 16:51:37 -0500] sql: select * from example * [17-Feb-2009 16:51:37 -0500] sql: select * from example * [17-Feb-2009 16:51:37 -0500] sql: select * from example - * [17-Feb-2009 16:51:37 -0500] end: my sql calls - 0.0018 seconds shell exec: 1, sql: 3, - * [17-Feb-2009 16:51:37 -0500] end: my test - 0.0055 seconds shell exec: 1, sql: 3, - * [17-Feb-2009 16:51:38 -0500] end: Task: mail. - 0.8854 seconds shell exec: 1, sql: 3, + * [17-Feb-2009 16:51:37 -0500] end: my sql calls - 0.0018 seconds shell exec: 1, sql: 3, + * [17-Feb-2009 16:51:37 -0500] end: my test - 0.0055 seconds shell exec: 1, sql: 3, + * [17-Feb-2009 16:51:38 -0500] end: Task: mail. - 0.8854 seconds shell exec: 1, sql: 3, * * logs/sql (after reloading the main page): * @@ -64,7 +64,7 @@ class debug_logger extends rcube_plugin function init() { - require_once(__DIR__ . '/runlog/runlog.php'); + require_once __DIR__ . '/runlog/runlog.php'; $this->runlog = new runlog(); diff --git a/plugins/debug_logger/runlog/runlog.php b/plugins/debug_logger/runlog/runlog.php index f24b4cb4fa2..8b7765f7dfc 100644 --- a/plugins/debug_logger/runlog/runlog.php +++ b/plugins/debug_logger/runlog/runlog.php @@ -5,8 +5,8 @@ * * @author Ziba Scott */ -class runlog { - +class runlog +{ private $start_time = false; private $parent_stack = []; private $file_handles = []; @@ -71,7 +71,7 @@ public function end() $this->indent--; if ($this->run_log[$lastk]['duration'] >= $this->threshold) { $tag_report = ""; - foreach ($this->tag_count as $tag => $count){ + foreach ($this->tag_count as $tag => $count) { $tag_report .= "$tag: $count, "; } $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration']); @@ -92,7 +92,7 @@ public function increase_tag_count($tag) public function get_text() { $text = ""; - foreach ($this->run_log as $entry){ + foreach ($this->run_log as $entry) { $text .= str_repeat(" ", count($entry['parents'])); if ($entry['tag'] != 'text') { $text .= $entry['tag'] . ': '; @@ -163,7 +163,7 @@ public function print_to_file($msg, $tag = false) if (!empty($this->timestamp)) { $buffer = sprintf("[%s] %s", date($this->timestamp, time()), $buffer); } - if(strlen($buffer) > $this->max_line_size){ + if (strlen($buffer) > $this->max_line_size) { $buffer = substr($buffer,0,$this->max_line_size - 3) . "..."; } fwrite($this->file_handles['master'], $buffer."\n"); @@ -201,7 +201,7 @@ private function get_indent() return $buf; } - function __destruct() + function __destruct() { foreach ($this->file_handles as $handle) { fclose($handle); diff --git a/plugins/debug_logger/tests/DebugLogger.php b/plugins/debug_logger/tests/DebugLogger.php index 88752eb9bc1..c497e53263e 100644 --- a/plugins/debug_logger/tests/DebugLogger.php +++ b/plugins/debug_logger/tests/DebugLogger.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/emoticons/emoticons.php b/plugins/emoticons/emoticons.php index 5d15aed0d45..49e104b364e 100644 --- a/plugins/emoticons/emoticons.php +++ b/plugins/emoticons/emoticons.php @@ -143,18 +143,18 @@ protected static function text2icons($text) // map of emoticon replacements $map = [ - '/(? self::ico_tag('1f603', ':D' ), // laugh - '/:-?\(/' => self::ico_tag('1f626', ':(' ), // frown - '/'.$entity.';-?\)/' => self::ico_tag('1f609', ';)' ), // wink - '/8-?\)/' => self::ico_tag('1f60e', '8)' ), // cool - '/(? self::ico_tag('1f62e', ':O' ), // surprised - '/(? self::ico_tag('1f61b', ':P' ), // tongue out - '/(? self::ico_tag('1f631', ':-@' ), // yell - '/O:-?\)/i' => self::ico_tag('1f607', 'O:-)' ), // innocent - '/(? self::ico_tag('1f60a', ':-)' ), // smile - '/(? self::ico_tag('1f633', ':-$' ), // embarrassed - '/(? self::ico_tag('1f48b', ':-*' ), // kiss - '/(? self::ico_tag('1f615', ':-S' ), // undecided + '/(? self::ico_tag('1f603', ':D'), // laugh + '/:-?\(/' => self::ico_tag('1f626', ':('), // frown + '/'.$entity.';-?\)/' => self::ico_tag('1f609', ';)'), // wink + '/8-?\)/' => self::ico_tag('1f60e', '8)'), // cool + '/(? self::ico_tag('1f62e', ':O'), // surprised + '/(? self::ico_tag('1f61b', ':P'), // tongue out + '/(? self::ico_tag('1f631', ':-@'), // yell + '/O:-?\)/i' => self::ico_tag('1f607', 'O:-)'), // innocent + '/(? self::ico_tag('1f60a', ':-)'), // smile + '/(? self::ico_tag('1f633', ':-$'), // embarrassed + '/(? self::ico_tag('1f48b', ':-*'), // kiss + '/(? self::ico_tag('1f615', ':-S'), // undecided ]; return preg_replace(array_keys($map), array_values($map), $text); diff --git a/plugins/enigma/enigma.php b/plugins/enigma/enigma.php index e5c408bce1e..86b1b34649f 100644 --- a/plugins/enigma/enigma.php +++ b/plugins/enigma/enigma.php @@ -1,6 +1,6 @@ register_action('plugin.enigmakeys', [$this, 'preferences_ui']); -// $this->register_action('plugin.enigmacerts', [$this, 'preferences_ui']); + // $this->register_action('plugin.enigmacerts', [$this, 'preferences_ui']); $this->load_ui(); @@ -203,7 +203,7 @@ function settings_actions($args) 'title' => 'enigmakeys', 'domain' => 'enigma', ]; -/* + /* $args['actions'][] = [ 'action' => 'plugin.enigmacerts', 'class' => 'enigma certs', @@ -211,7 +211,7 @@ function settings_actions($args) 'title' => 'enigmacerts', 'domain' => 'enigma', ]; -*/ + */ return $args; } @@ -246,7 +246,7 @@ function preferences_list($p) return $p; } - $no_override = array_flip((array)$this->rc->config->get('dont_override')); + $no_override = array_flip((array) $this->rc->config->get('dont_override')); if (!isset($no_override['enigma_encryption'])) { if (!$p['current']) { diff --git a/plugins/enigma/lib/enigma_driver.php b/plugins/enigma/lib/enigma_driver.php index dde7f2c09a5..1970447f73f 100644 --- a/plugins/enigma/lib/enigma_driver.php +++ b/plugins/enigma/lib/enigma_driver.php @@ -1,6 +1,6 @@ rc->config->get('enigma_smime_homedir', INSTALL_PATH . '/plugins/enigma/home'); - if (!$homedir) + if (!$homedir) { return new enigma_error(enigma_error::INTERNAL, "Option 'enigma_smime_homedir' not specified"); + } // check if homedir exists (create it if not) and is readable - if (!file_exists($homedir)) + if (!file_exists($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Keys directory doesn't exists: $homedir"); - if (!is_writable($homedir)) + } + if (!is_writable($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Keys directory isn't writeable: $homedir"); + } $homedir = $homedir . '/' . $this->user; // check if user's homedir exists (create it if not) and is readable - if (!file_exists($homedir)) + if (!file_exists($homedir)) { mkdir($homedir, 0700); + } - if (!file_exists($homedir)) + if (!file_exists($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Unable to create keys directory: $homedir"); - if (!is_writable($homedir)) + } + if (!is_writable($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Unable to write to keys directory: $homedir"); + } $this->homedir = $homedir; } - function encrypt($text, $keys, $sign_key = null) - { - } + function encrypt($text, $keys, $sign_key = null) {} - function decrypt($text, $keys = [], &$signature = null) - { - } + function decrypt($text, $keys = [], &$signature = null) {} - function sign($text, $key, $mode = null) - { - } + function sign($text, $key, $mode = null) {} function verify($struct, $message) { @@ -120,29 +120,17 @@ function verify($struct, $message) return $sig; } - public function import($content, $isfile = false, $passwords = []) - { - } + public function import($content, $isfile = false, $passwords = []) {} - public function export($key, $with_private = false, $passwords = []) - { - } + public function export($key, $with_private = false, $passwords = []) {} - public function list_keys($pattern='') - { - } + public function list_keys($pattern='') {} - public function get_key($keyid) - { - } + public function get_key($keyid) {} - public function gen_key($data) - { - } + public function gen_key($data) {} - public function delete_key($keyid) - { - } + public function delete_key($keyid) {} /** * Returns a name of the hash algorithm used for the last @@ -150,9 +138,7 @@ public function delete_key($keyid) * * @return string Hash algorithm name e.g. sha1 */ - public function signature_algorithm() - { - } + public function signature_algorithm() {} /** * Converts Crypt_GPG_Key object into Enigma's key object @@ -161,9 +147,7 @@ public function signature_algorithm() * * @return enigma_key Key object */ - private function parse_key($key) - { - } + private function parse_key($key) {} private function get_openssl_error() { @@ -192,7 +176,7 @@ private function parse_sig_cert($file, $validity) $data->created = $cert['validFrom_time_t']; $data->expires = $cert['validTo_time_t']; $data->name = $cert['subject']['CN']; -// $data->comment = ''; + // $data->comment = ''; $data->email = $cert['subject']['emailAddress']; return $data; diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php index adae0cc6f87..d040313a0ec 100644 --- a/plugins/enigma/lib/enigma_engine.php +++ b/plugins/enigma/lib/enigma_engine.php @@ -1,6 +1,6 @@ isMultipart()) { + case self::SIGN_MODE_MIME: $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; - } - else { - $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; - } + break; + + default: + if ($mime->isMultipart()) { + $pgp_mode = Crypt_GPG::SIGN_MODE_DETACHED; + } + else { + $pgp_mode = Crypt_GPG::SIGN_MODE_CLEAR; + } } // get message body @@ -488,27 +488,27 @@ function parse_plain(&$p, $body = null) while (($line = fgets($fd)) !== false) { if (strlen($line) > 5 && $line[0] === '-' && $line[4] === '-' && preg_match($regexp, $line, $m)) { switch ($tokens[$m[1]]) { - case 'signed-start': - $body = $line; - $mode = 'signed'; - break; - - case 'signed-end': - if ($mode === 'signed') { - $body .= $line; - } - break 2; // ignore anything after this line + case 'signed-start': + $body = $line; + $mode = 'signed'; + break; - case 'encrypted-start': - $body = $line; - $mode = 'encrypted'; - break; + case 'signed-end': + if ($mode === 'signed') { + $body .= $line; + } + break 2; // ignore anything after this line - case 'encrypted-end': - if ($mode === 'encrypted') { - $body .= $line; - } - break 2; // ignore anything after this line + case 'encrypted-start': + $body = $line; + $mode = 'encrypted'; + break; + + case 'encrypted-end': + if ($mode === 'encrypted') { + $body .= $line; + } + break 2; // ignore anything after this line } continue; diff --git a/plugins/enigma/lib/enigma_error.php b/plugins/enigma/lib/enigma_error.php index c3dd3fb0d19..08667631920 100644 --- a/plugins/enigma/lib/enigma_error.php +++ b/plugins/enigma/lib/enigma_error.php @@ -1,6 +1,6 @@ algorithm) { - case 1: - case 2: - case 3: - return 'RSA'; - case 16: - case 20: - return 'Elgamal'; - case 17: - return 'DSA'; - case 18: - return 'Elliptic Curve'; - case 19: - return 'ECDSA'; - case 21: - return 'Diffie-Hellman'; - case 22: - return 'EdDSA'; + case 1: + case 2: + case 3: + return 'RSA'; + case 16: + case 20: + return 'Elgamal'; + case 17: + return 'DSA'; + case 18: + return 'Elliptic Curve'; + case 19: + return 'ECDSA'; + case 21: + return 'Diffie-Hellman'; + case 22: + return 'EdDSA'; } } diff --git a/plugins/enigma/lib/enigma_ui.php b/plugins/enigma/lib/enigma_ui.php index e2fa0fa7a60..589582577fa 100644 --- a/plugins/enigma/lib/enigma_ui.php +++ b/plugins/enigma/lib/enigma_ui.php @@ -1,6 +1,6 @@ key_delete(); break; -/* + /* case 'edit': $this->key_edit(); break; -*/ + */ case 'import': $this->key_import(); break; @@ -96,7 +96,7 @@ function init() $this->rc->output->set_pagetitle($this->enigma->gettext('enigmakeys')); $this->rc->output->send('enigma.keys'); } -/* + /* // Preferences UI else if ($this->rc->action == 'plugin.enigmacerts') { $this->rc->output->add_handlers([ @@ -109,7 +109,7 @@ function init() $this->rc->output->set_pagetitle($this->enigma->gettext('enigmacerts')); $this->rc->output->send('enigma.certs'); } -*/ + */ // Message composing UI else if ($this->rc->action == 'compose') { $this->compose_ui(); @@ -1243,7 +1243,7 @@ function message_ready($p) return $p; } - /** + /** * Handler for message_compose_body hook * Display error when the message cannot be encrypted * and provide a way to try again with a password. diff --git a/plugins/enigma/lib/enigma_userid.php b/plugins/enigma/lib/enigma_userid.php index d89e5a74b0b..91eabeb0e6f 100644 --- a/plugins/enigma/lib/enigma_userid.php +++ b/plugins/enigma/lib/enigma_userid.php @@ -1,6 +1,6 @@ assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/enigma/tests/EnigmaDriverGnupg.php b/plugins/enigma/tests/EnigmaDriverGnupg.php index 2e18d4d40ae..12677553b9b 100644 --- a/plugins/enigma/tests/EnigmaDriverGnupg.php +++ b/plugins/enigma/tests/EnigmaDriverGnupg.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('enigma_driver', $plugin); } } - diff --git a/plugins/enigma/tests/EnigmaEngine.php b/plugins/enigma/tests/EnigmaEngine.php index db70f25c9cf..0e4bf0996d7 100644 --- a/plugins/enigma/tests/EnigmaEngine.php +++ b/plugins/enigma/tests/EnigmaEngine.php @@ -35,4 +35,3 @@ function test_password_handler() $this->assertSame(['ABC' => '123456'], $engine->get_passwords()); } } - diff --git a/plugins/enigma/tests/EnigmaError.php b/plugins/enigma/tests/EnigmaError.php index de62c5f02d9..f3ce16a011b 100644 --- a/plugins/enigma/tests/EnigmaError.php +++ b/plugins/enigma/tests/EnigmaError.php @@ -21,4 +21,3 @@ function test_constructor() $this->assertSame(['test1' => 'test2'], $error->getData()); } } - diff --git a/plugins/enigma/tests/EnigmaKey.php b/plugins/enigma/tests/EnigmaKey.php index 2a5acd2b15c..163814b1396 100644 --- a/plugins/enigma/tests/EnigmaKey.php +++ b/plugins/enigma/tests/EnigmaKey.php @@ -25,4 +25,3 @@ function test_empty_key() // TODO: format_fingerprint(); } } - diff --git a/plugins/enigma/tests/EnigmaSignature.php b/plugins/enigma/tests/EnigmaSignature.php index 73929d1755b..6cdb416bc7c 100644 --- a/plugins/enigma/tests/EnigmaSignature.php +++ b/plugins/enigma/tests/EnigmaSignature.php @@ -17,4 +17,3 @@ function test_constructor() $this->assertInstanceOf('enigma_signature', $error); } } - diff --git a/plugins/enigma/tests/EnigmaSubkey.php b/plugins/enigma/tests/EnigmaSubkey.php index 05b61ebb4bd..139368c8bed 100644 --- a/plugins/enigma/tests/EnigmaSubkey.php +++ b/plugins/enigma/tests/EnigmaSubkey.php @@ -17,4 +17,3 @@ function test_constructor() $this->assertInstanceOf('enigma_subkey', $error); } } - diff --git a/plugins/enigma/tests/EnigmaUserid.php b/plugins/enigma/tests/EnigmaUserid.php index bb3bf7ff2ea..23eab4f8981 100644 --- a/plugins/enigma/tests/EnigmaUserid.php +++ b/plugins/enigma/tests/EnigmaUserid.php @@ -17,4 +17,3 @@ function test_constructor() $this->assertInstanceOf('enigma_userid', $error); } } - diff --git a/plugins/example_addressbook/example_addressbook.php b/plugins/example_addressbook/example_addressbook.php index 8f3b4f44373..0f006f9267a 100644 --- a/plugins/example_addressbook/example_addressbook.php +++ b/plugins/example_addressbook/example_addressbook.php @@ -1,6 +1,6 @@ assertSame('static', $result['sources']['static']['id']); } } - diff --git a/plugins/filesystem_attachments/tests/FilesystemAttachments.php b/plugins/filesystem_attachments/tests/FilesystemAttachments.php index 0fe6e4a2261..61073051242 100644 --- a/plugins/filesystem_attachments/tests/FilesystemAttachments.php +++ b/plugins/filesystem_attachments/tests/FilesystemAttachments.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/help/help.php b/plugins/help/help.php index 0162b5b3191..4cfc246d576 100644 --- a/plugins/help/help.php +++ b/plugins/help/help.php @@ -86,7 +86,7 @@ function action() function help_content($attrib) { $rcmail = rcmail::get_instance(); -// $rcmail->output->set_env('content', $content); + // $rcmail->output->set_env('content', $content); if (!empty($_GET['_content'])) { if ($rcmail->action == 'about') { @@ -145,7 +145,7 @@ function help_metadata() // resolve task/action for deep linking $rel = !empty($_REQUEST['_rel']) ? $_REQUEST['_rel'] : ''; - list($task, ) = explode('/', $rel); + list($task) = explode('/', $rel); if (!empty($index_map[$rel])) { $src .= $index_map[$rel]; } diff --git a/plugins/http_authentication/tests/HttpAuthentication.php b/plugins/http_authentication/tests/HttpAuthentication.php index ad102586242..b968daa7cec 100644 --- a/plugins/http_authentication/tests/HttpAuthentication.php +++ b/plugins/http_authentication/tests/HttpAuthentication.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/identicon/identicon_engine.php b/plugins/identicon/identicon_engine.php index bc85775baa9..bc59df8af0b 100644 --- a/plugins/identicon/identicon_engine.php +++ b/plugins/identicon/identicon_engine.php @@ -20,10 +20,10 @@ class identicon_engine '#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#795548', '#607D8B', ]; private $grid = [ - 0, 1, 2, 1, 0, - 3, 4, 5, 4, 3, - 6, 7, 8, 7, 6, - 9, 10, 11, 10, 9, + 0, 1, 2, 1, 0, + 3, 4, 5, 4, 3, + 6, 7, 8, 7, 6, + 9, 10, 11, 10, 9, 12, 13, 14, 13, 12, ]; diff --git a/plugins/identicon/tests/IdenticonEngine.php b/plugins/identicon/tests/IdenticonEngine.php index 88f3a8230f6..b92e1c10631 100644 --- a/plugins/identicon/tests/IdenticonEngine.php +++ b/plugins/identicon/tests/IdenticonEngine.php @@ -24,4 +24,3 @@ function test_icon_generation() $this->assertSame('image/png', $engine->getMimetype()); } } - diff --git a/plugins/krb_authentication/krb_authentication.php b/plugins/krb_authentication/krb_authentication.php index 9559a934ad4..76004443d0d 100644 --- a/plugins/krb_authentication/krb_authentication.php +++ b/plugins/krb_authentication/krb_authentication.php @@ -149,7 +149,7 @@ private function gssapi_context($protocol) $context = $rcmail->config->get('krb_authentication_context'); if (is_array($context) && isset($context[$protocol])) { - $context = $context[$protocol]; + $context = $context[$protocol]; } if (empty($context)) { diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php index 93b827e3b68..42e54f4bf3e 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php @@ -1,6 +1,6 @@ 2) { $this->errorLines[] = ['line' => $matches[1], 'msg' => $matches[2]]; } diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index d7d03b0679c..335434f2c86 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -248,7 +248,7 @@ protected function load_script($script_name = null) if ($script_name === null || $script_name === '') { // get (first) active script if (!empty($this->active)) { - $script_name = $this->active[0]; + $script_name = $this->active[0]; } else if ($list) { $script_name = $list[0]; @@ -574,7 +574,7 @@ function save() else if (mb_strlen($name) > 128) { $this->errors['name'] = $this->plugin->gettext('nametoolong'); } - else if (!empty($exceptions) && in_array($name, (array)$exceptions)) { + else if (!empty($exceptions) && in_array($name, (array) $exceptions)) { $this->errors['name'] = $this->plugin->gettext('namereserved'); } else if (!empty($kolab) && in_array($name_uc, ['MASTER', 'USER', 'MANAGEMENT'])) { @@ -698,11 +698,12 @@ function save() $this->errors['name'] = $this->plugin->gettext('cannotbeempty'); } else { - foreach ($this->script as $idx => $rule) + foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->plugin->gettext('ruleexist'); break; } + } } $i = 0; @@ -981,7 +982,7 @@ function save() if ($mod == 'address' || $mod == 'envelope') { $found = false; if (empty($this->errors['tests'][$i]['header'])) { - foreach ((array)$header as $hdr) { + foreach ((array) $header as $hdr) { if (!in_array(strtolower(trim($hdr)), $this->addr_headers)) { $found = true; } @@ -1045,192 +1046,193 @@ function save() $type = $this->strip_value($type); switch ($type) { - case 'fileinto': - case 'fileinto_copy': - $mailbox = $this->strip_value($mailboxes[$idx], false, false); - $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in'); - - if ($type == 'fileinto_copy') { - $type = 'fileinto'; - $this->form['actions'][$i]['copy'] = true; - } - break; + case 'fileinto': + case 'fileinto_copy': + $mailbox = $this->strip_value($mailboxes[$idx], false, false); + $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in'); + + if ($type == 'fileinto_copy') { + $type = 'fileinto'; + $this->form['actions'][$i]['copy'] = true; + } + break; - case 'reject': - case 'ereject': - $target = $this->strip_value($area_targets[$idx]); - $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target); + case 'reject': + case 'ereject': + $target = $this->strip_value($area_targets[$idx]); + $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target); - // if ($target == '') -// $this->errors['actions'][$i]['targetarea'] = $this->plugin->gettext('cannotbeempty'); - break; + // if ($target == '') { + // $this->errors['actions'][$i]['targetarea'] = $this->plugin->gettext('cannotbeempty'); + // } + break; - case 'redirect': - case 'redirect_copy': - $target = $this->strip_value($act_targets[$idx] ?? null); - $domain = $this->strip_value($domain_targets[$idx] ?? null); + case 'redirect': + case 'redirect_copy': + $target = $this->strip_value($act_targets[$idx] ?? null); + $domain = $this->strip_value($domain_targets[$idx] ?? null); - // force one of the configured domains - $domains = (array) $this->rc->config->get('managesieve_domains'); - if (!empty($domains) && !empty($target)) { - if (!$domain || !in_array($domain, $domains)) { - $domain = $domains[0]; - } + // force one of the configured domains + $domains = (array) $this->rc->config->get('managesieve_domains'); + if (!empty($domains) && !empty($target)) { + if (!$domain || !in_array($domain, $domains)) { + $domain = $domains[0]; + } - $target .= '@' . $domain; - } + $target .= '@' . $domain; + } - $this->form['actions'][$i]['target'] = $target; + $this->form['actions'][$i]['target'] = $target; - if ($target === '') { - $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); - } - else if (!rcube_utils::check_email($target)) { - $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning'); - } + if ($target === '') { + $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); + } + else if (!rcube_utils::check_email($target)) { + $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning'); + } - if ($type == 'redirect_copy') { - $type = 'redirect'; - $this->form['actions'][$i]['copy'] = true; - } + if ($type == 'redirect_copy') { + $type = 'redirect'; + $this->form['actions'][$i]['copy'] = true; + } - break; + break; - case 'addflag': - case 'setflag': - case 'removeflag': - $this->form['actions'][$i]['target'] = $this->strip_value($flags[$idx]); + case 'addflag': + case 'setflag': + case 'removeflag': + $this->form['actions'][$i]['target'] = $this->strip_value($flags[$idx]); - if (empty($this->form['actions'][$i]['target'])) { - $this->errors['actions'][$i]['flag'] = $this->plugin->gettext('noflagset'); - } + if (empty($this->form['actions'][$i]['target'])) { + $this->errors['actions'][$i]['flag'] = $this->plugin->gettext('noflagset'); + } - break; + break; - case 'addheader': - case 'deleteheader': - $this->form['actions'][$i]['name'] = trim($type == 'addheader' ? $addheader_name[$idx] : $delheader_name[$idx]); - $this->form['actions'][$i]['value'] = $type == 'addheader' ? $addheader_value[$idx] : $delheader_value[$idx]; - $this->form['actions'][$i]['last'] = ($type == 'addheader' ? $addheader_pos[$idx] : $delheader_pos[$idx]) == 'last'; + case 'addheader': + case 'deleteheader': + $this->form['actions'][$i]['name'] = trim($type == 'addheader' ? $addheader_name[$idx] : $delheader_name[$idx]); + $this->form['actions'][$i]['value'] = $type == 'addheader' ? $addheader_value[$idx] : $delheader_value[$idx]; + $this->form['actions'][$i]['last'] = ($type == 'addheader' ? $addheader_pos[$idx] : $delheader_pos[$idx]) == 'last'; - if (empty($this->form['actions'][$i]['name'])) { - $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty'); - } - else if (!preg_match('/^[0-9a-z_-]+$/i', $this->form['actions'][$i]['name'])) { - $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars'); - } + if (empty($this->form['actions'][$i]['name'])) { + $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty'); + } + else if (!preg_match('/^[0-9a-z_-]+$/i', $this->form['actions'][$i]['name'])) { + $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars'); + } - if ($type == 'deleteheader') { - foreach ((array) $this->form['actions'][$i]['value'] as $pidx => $pattern) { - if (empty($pattern)) { - unset($this->form['actions'][$i]['value'][$pidx]); + if ($type == 'deleteheader') { + foreach ((array) $this->form['actions'][$i]['value'] as $pidx => $pattern) { + if (empty($pattern)) { + unset($this->form['actions'][$i]['value'][$pidx]); + } } - } - $this->form['actions'][$i]['match-type'] = $delheader_op[$idx]; - $this->form['actions'][$i]['comparator'] = $delheader_comp[$idx]; - $this->form['actions'][$i]['index'] = $delheader_index[$idx]; + $this->form['actions'][$i]['match-type'] = $delheader_op[$idx]; + $this->form['actions'][$i]['comparator'] = $delheader_comp[$idx]; + $this->form['actions'][$i]['index'] = $delheader_index[$idx]; - if (empty($this->form['actions'][$i]['index'])) { - if (!empty($this->form['actions'][$i]['last'])) { - $this->errors['actions'][$i]['index'] = $this->plugin->gettext('lastindexempty'); + if (empty($this->form['actions'][$i]['index'])) { + if (!empty($this->form['actions'][$i]['last'])) { + $this->errors['actions'][$i]['index'] = $this->plugin->gettext('lastindexempty'); + } + } + else if (!preg_match('/^[0-9]+$/i', $this->form['actions'][$i]['index'])) { + $this->errors['actions'][$i]['index'] = $this->plugin->gettext('forbiddenchars'); } } - else if (!preg_match('/^[0-9]+$/i', $this->form['actions'][$i]['index'])) { - $this->errors['actions'][$i]['index'] = $this->plugin->gettext('forbiddenchars'); - } - } - else { - if (empty($this->form['actions'][$i]['value'])) { - $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty'); + else { + if (empty($this->form['actions'][$i]['value'])) { + $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty'); + } } - } - break; + break; - case 'vacation': - $reason = $this->strip_value($reasons[$idx], true); - $interval_type = $interval_types && $interval_types[$idx] == 'seconds' ? 'seconds' : 'days'; + case 'vacation': + $reason = $this->strip_value($reasons[$idx], true); + $interval_type = $interval_types && $interval_types[$idx] == 'seconds' ? 'seconds' : 'days'; - $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); - $this->form['actions'][$i]['from'] = $from[$idx]; - $this->form['actions'][$i]['subject'] = $subject[$idx]; - $this->form['actions'][$i]['addresses'] = $addresses[$idx]; - $this->form['actions'][$i][$interval_type] = $intervals[$idx]; + $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); + $this->form['actions'][$i]['from'] = $from[$idx]; + $this->form['actions'][$i]['subject'] = $subject[$idx]; + $this->form['actions'][$i]['addresses'] = $addresses[$idx]; + $this->form['actions'][$i][$interval_type] = $intervals[$idx]; - // @TODO: vacation :mime, :handle + // @TODO: vacation :mime, :handle - foreach ((array)$this->form['actions'][$i]['addresses'] as $aidx => $address) { - $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address); + foreach ((array) $this->form['actions'][$i]['addresses'] as $aidx => $address) { + $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address); - if (empty($address)) { - unset($this->form['actions'][$i]['addresses'][$aidx]); - } - else if (!rcube_utils::check_email($address)) { - $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning'); - break; + if (empty($address)) { + unset($this->form['actions'][$i]['addresses'][$aidx]); + } + else if (!rcube_utils::check_email($address)) { + $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning'); + break; + } } - } - if (!empty($this->form['actions'][$i]['from'])) { - // According to RFC5230 the :from string must specify a valid [RFC2822] mailbox-list - $this->action_email_input($i, 'from'); - } + if (!empty($this->form['actions'][$i]['from'])) { + // According to RFC5230 the :from string must specify a valid [RFC2822] mailbox-list + $this->action_email_input($i, 'from'); + } - if ($this->form['actions'][$i]['reason'] == '') { - $this->errors['actions'][$i]['reason'] = $this->plugin->gettext('cannotbeempty'); - } - if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type])) { - $this->errors['actions'][$i]['interval'] = $this->plugin->gettext('forbiddenchars'); - } - break; + if ($this->form['actions'][$i]['reason'] == '') { + $this->errors['actions'][$i]['reason'] = $this->plugin->gettext('cannotbeempty'); + } + if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type])) { + $this->errors['actions'][$i]['interval'] = $this->plugin->gettext('forbiddenchars'); + } + break; - case 'set': - $this->form['actions'][$i]['name'] = $varnames[$idx]; - $this->form['actions'][$i]['value'] = $varvalues[$idx]; - foreach ((array)$varmods[$idx] as $v_m) { - $this->form['actions'][$i][$v_m] = true; - } + case 'set': + $this->form['actions'][$i]['name'] = $varnames[$idx]; + $this->form['actions'][$i]['value'] = $varvalues[$idx]; + foreach ((array) $varmods[$idx] as $v_m) { + $this->form['actions'][$i][$v_m] = true; + } - if (empty($varnames[$idx])) { - $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty'); - } - else if (!preg_match('/^[0-9a-z_]+$/i', $varnames[$idx])) { - $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars'); - } + if (empty($varnames[$idx])) { + $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty'); + } + else if (!preg_match('/^[0-9a-z_]+$/i', $varnames[$idx])) { + $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars'); + } - if (!isset($varvalues[$idx]) || $varvalues[$idx] === '') { - $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty'); - } - break; + if (!isset($varvalues[$idx]) || $varvalues[$idx] === '') { + $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty'); + } + break; - case 'notify': - if (empty($notifymethods[$idx])) { - $this->errors['actions'][$i]['method'] = $this->plugin->gettext('cannotbeempty'); - } - if (empty($notifytargets[$idx])) { - $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); - } + case 'notify': + if (empty($notifymethods[$idx])) { + $this->errors['actions'][$i]['method'] = $this->plugin->gettext('cannotbeempty'); + } + if (empty($notifytargets[$idx])) { + $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); + } - // skip empty options - foreach ((array)$notifyoptions[$idx] as $opt_idx => $opt) { - if (!strlen(trim($opt))) { - unset($notifyoptions[$idx][$opt_idx]); + // skip empty options + foreach ((array) $notifyoptions[$idx] as $opt_idx => $opt) { + if (!strlen(trim($opt))) { + unset($notifyoptions[$idx][$opt_idx]); + } } - } - $this->form['actions'][$i]['method'] = $notifymethods[$idx] . ':' . $notifytargets[$idx]; - $this->form['actions'][$i]['options'] = $notifyoptions[$idx]; - $this->form['actions'][$i]['message'] = $notifymessages[$idx]; - $this->form['actions'][$i]['from'] = $notifyfrom[$idx]; - $this->form['actions'][$i]['importance'] = $notifyimp[$idx]; + $this->form['actions'][$i]['method'] = $notifymethods[$idx] . ':' . $notifytargets[$idx]; + $this->form['actions'][$i]['options'] = $notifyoptions[$idx]; + $this->form['actions'][$i]['message'] = $notifymessages[$idx]; + $this->form['actions'][$i]['from'] = $notifyfrom[$idx]; + $this->form['actions'][$i]['importance'] = $notifyimp[$idx]; - if (!empty($notifyfrom[$idx]) && stripos($this->form['actions'][$i]['method'], 'mailto:') === 0) { - // For mailto method :from string must specify a valid [RFC2822] mailbox-list - $this->action_email_input($i, 'from'); - } + if (!empty($notifyfrom[$idx]) && stripos($this->form['actions'][$i]['method'], 'mailto:') === 0) { + // For mailto method :from string must specify a valid [RFC2822] mailbox-list + $this->action_email_input($i, 'from'); + } - break; + break; } $this->form['actions'][$i]['type'] = $type; @@ -1399,9 +1401,9 @@ function filterset_editraw($attrib) $framed = !empty($_POST['_framed']) || !empty($_GET['_framed']); $hiddenfields = new html_hiddenfield(); - $hiddenfields->add(['name' => '_task', 'value' => $this->rc->task]); + $hiddenfields->add(['name' => '_task', 'value' => $this->rc->task]); $hiddenfields->add(['name' => '_action', 'value' => 'plugin.managesieve-saveraw']); - $hiddenfields->add(['name' => '_set', 'value' => $script_name]); + $hiddenfields->add(['name' => '_set', 'value' => $script_name]); $hiddenfields->add(['name' => '_seteditraw', 'value' => 1]); $hiddenfields->add(['name' => '_framed', 'value' => $framed ? 1 : 0]); @@ -1624,7 +1626,7 @@ function filter_form($attrib) $join = $any ? 'any' : 'allof'; if (isset($scr) && !$any) { - $join = !empty($scr['join']) ? 'allof' : 'anyof'; + $join = !empty($scr['join']) ? 'allof' : 'anyof'; } $out .= sprintf("\n" . '
' @@ -1687,7 +1689,7 @@ function filter_form($attrib) $label = $this->plugin->gettext($compact ? 'actions' : 'messagesactions'); $out .= '
' . rcube::Q($label) . "\n"; - $rows_num = isset($scr) ? count($scr['actions']) : 1; + $rows_num = isset($scr) ? count($scr['actions']) : 1; $out .= '
'; for ($x=0; $x<$rows_num; $x++) { @@ -2113,13 +2115,13 @@ function rule_div($fid, $id, $div = true, $compact = false) 'class' => $this->error_class($id, 'test', 'index', 'rule_index'), ]); $mout .= html::label('input-group-append', - html::tag('input', [ - 'type' => 'checkbox', - 'name' => "_rule_index_last[$id]", - 'id' => 'rule_index_last' . $id, - 'value' => 1, - 'checked' => !empty($rule['last']), - ]) . rcube::Q($this->plugin->gettext('indexlast'))); + html::tag('input', [ + 'type' => 'checkbox', + 'name' => "_rule_index_last[$id]", + 'id' => 'rule_index_last' . $id, + 'value' => 1, + 'checked' => !empty($rule['last']), + ]) . rcube::Q($this->plugin->gettext('indexlast'))); $mout .= '
'; } @@ -2210,12 +2212,24 @@ private static function rule_test(&$rule) $rule['not'] = false; switch ($m[2]) { - case 'gt': $rule['type'] = $m[1] . '-le'; break; - case 'ge': $rule['type'] = $m[1] . '-lt'; break; - case 'lt': $rule['type'] = $m[1] . '-ge'; break; - case 'le': $rule['type'] = $m[1] . '-gt'; break; - case 'eq': $rule['type'] = $m[1] . '-ne'; break; - case 'ne': $rule['type'] = $m[1] . '-eq'; break; + case 'gt': + $rule['type'] = $m[1] . '-le'; + break; + case 'ge': + $rule['type'] = $m[1] . '-lt'; + break; + case 'lt': + $rule['type'] = $m[1] . '-ge'; + break; + case 'le': + $rule['type'] = $m[1] . '-gt'; + break; + case 'eq': + $rule['type'] = $m[1] . '-ne'; + break; + case 'ne': + $rule['type'] = $m[1] . '-eq'; + break; } } else if (!empty($rule['not']) && !empty($rule['test']) && $rule['test'] == 'size') { @@ -2433,8 +2447,8 @@ function action_div($fid, $id, $div = true) ]); $out .= '
' .rcube::Q($this->plugin->gettext('vacationaddr')) . '
'; $out .= $this->list_input($id, 'action_addresses', $action['addresses'] ?? null, - 30, false, ['class' => $this->error_class($id, 'action', 'addresses', 'action_addresses')] - ) + 30, false, ['class' => $this->error_class($id, 'action', 'addresses', 'action_addresses')] + ) . html::a(['href' => '#', 'onclick' => rcmail_output::JS_OBJECT_NAME . ".managesieve_vacation_addresses($id)"], rcube::Q($this->plugin->gettext('filladdresses'))); $out .= '
' . rcube::Q($this->plugin->gettext('vacationinterval')) . '
'; @@ -2474,7 +2488,7 @@ function action_div($fid, $id, $div = true) $is_flag_action = preg_match('/^(set|add|remove)flag$/', (string) $action['type']); if ($is_flag_action) { - $custom_flags = array_filter($flags_target, function($v) use($flags) { + $custom_flags = array_filter($flags_target, function ($v) use ($flags) { return !in_array_nocase($v, $flags); }); } @@ -2999,7 +3013,7 @@ public function list_scripts() // Hide scripts from config $exceptions = $this->rc->config->get('managesieve_filename_exceptions'); if (!empty($exceptions)) { - $this->list = array_diff($this->list, (array)$exceptions); + $this->list = array_diff($this->list, (array) $exceptions); } } @@ -3170,8 +3184,9 @@ public function deactivate_script($name) } else { $result = $this->sieve->deactivate(); - if ($result) + if ($result) { $this->active = []; + } } return $result; diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php index a5d66096689..8be7e803121 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php @@ -210,7 +210,7 @@ public function as_text() $idx = 0; if (!empty($this->vars)) { - if (in_array('variables', (array)$this->supported)) { + if (in_array('variables', (array) $this->supported)) { $has_vars = true; array_push($exts, 'variables'); } @@ -248,145 +248,146 @@ public function as_text() foreach ($rule['tests'] as $test) { $tests[$i] = ''; switch ($test['test']) { - case 'size': - $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); - $tests[$i] .= 'size :' . ($test['type'] == 'under' ? 'under ' : 'over ') . $test['arg']; - break; + case 'size': + $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); + $tests[$i] .= 'size :' . ($test['type'] == 'under' ? 'under ' : 'over ') . $test['arg']; + break; - case 'spamtest': - array_push($exts, 'spamtest'); - $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); - $tests[$i] .= $test['test']; + case 'spamtest': + array_push($exts, 'spamtest'); + $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); + $tests[$i] .= $test['test']; - $this->add_operator($test, $tests[$i], $exts); + $this->add_operator($test, $tests[$i], $exts); - $tests[$i] .= ' ' . self::escape_string($test['arg']); - break; + $tests[$i] .= ' ' . self::escape_string($test['arg']); + break; - case 'true': - $tests[$i] .= !empty($test['not']) ? 'false' : 'true'; - break; + case 'true': + $tests[$i] .= !empty($test['not']) ? 'false' : 'true'; + break; - case 'exists': - $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . 'exists'; + case 'exists': + $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . 'exists'; - $this->add_mime($test, $tests[$i], $exts); + $this->add_mime($test, $tests[$i], $exts); - $tests[$i] .= ' ' . self::escape_string($test['arg']); - break; + $tests[$i] .= ' ' . self::escape_string($test['arg']); + break; - case 'header': - case 'string': - if ($test['test'] == 'string') { - array_push($exts, 'variables'); - } + case 'header': + case 'string': + if ($test['test'] == 'string') { + array_push($exts, 'variables'); + } - $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); - $tests[$i] .= $test['test']; + $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); + $tests[$i] .= $test['test']; - if ($test['test'] == 'header') { - $this->add_mime($test, $tests[$i], $exts); - } + if ($test['test'] == 'header') { + $this->add_mime($test, $tests[$i], $exts); + } - $this->add_index($test, $tests[$i], $exts); - $this->add_operator($test, $tests[$i], $exts); + $this->add_index($test, $tests[$i], $exts); + $this->add_operator($test, $tests[$i], $exts); - $tests[$i] .= ' ' . self::escape_string($test['arg1']); - $tests[$i] .= ' ' . self::escape_string($test['arg2']); - break; + $tests[$i] .= ' ' . self::escape_string($test['arg1']); + $tests[$i] .= ' ' . self::escape_string($test['arg2']); + break; - case 'address': - case 'envelope': - if ($test['test'] == 'envelope') { - array_push($exts, 'envelope'); - } + case 'address': + case 'envelope': + if ($test['test'] == 'envelope') { + array_push($exts, 'envelope'); + } - $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); - $tests[$i] .= $test['test']; + $tests[$i] .= (!empty($test['not']) ? 'not ' : ''); + $tests[$i] .= $test['test']; - if ($test['test'] == 'address') { - $this->add_mime($test, $tests[$i], $exts); - $this->add_index($test, $tests[$i], $exts); - } + if ($test['test'] == 'address') { + $this->add_mime($test, $tests[$i], $exts); + $this->add_index($test, $tests[$i], $exts); + } - // :all address-part is optional, skip it - if (!empty($test['part']) && $test['part'] != 'all') { - $tests[$i] .= ' :' . $test['part']; - if ($test['part'] == 'user' || $test['part'] == 'detail') { - array_push($exts, 'subaddress'); + // :all address-part is optional, skip it + if (!empty($test['part']) && $test['part'] != 'all') { + $tests[$i] .= ' :' . $test['part']; + if ($test['part'] == 'user' || $test['part'] == 'detail') { + array_push($exts, 'subaddress'); + } } - } - $this->add_operator($test, $tests[$i], $exts); + $this->add_operator($test, $tests[$i], $exts); - $tests[$i] .= ' ' . self::escape_string($test['arg1']); - $tests[$i] .= ' ' . self::escape_string($test['arg2']); - break; + $tests[$i] .= ' ' . self::escape_string($test['arg1']); + $tests[$i] .= ' ' . self::escape_string($test['arg2']); + break; - case 'body': - array_push($exts, 'body'); + case 'body': + array_push($exts, 'body'); - $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . 'body'; + $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . 'body'; - if (!empty($test['part'])) { - $tests[$i] .= ' :' . $test['part']; + if (!empty($test['part'])) { + $tests[$i] .= ' :' . $test['part']; - if (!empty($test['content']) && $test['part'] == 'content') { - $tests[$i] .= ' ' . self::escape_string($test['content']); + if (!empty($test['content']) && $test['part'] == 'content') { + $tests[$i] .= ' ' . self::escape_string($test['content']); + } } - } - $this->add_operator($test, $tests[$i], $exts); + $this->add_operator($test, $tests[$i], $exts); - $tests[$i] .= ' ' . self::escape_string($test['arg']); - break; + $tests[$i] .= ' ' . self::escape_string($test['arg']); + break; - case 'date': - case 'currentdate': - array_push($exts, 'date'); + case 'date': + case 'currentdate': + array_push($exts, 'date'); - $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . $test['test']; + $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . $test['test']; - $this->add_index($test, $tests[$i], $exts); + $this->add_index($test, $tests[$i], $exts); - if (!empty($test['originalzone']) && $test['test'] == 'date') { - $tests[$i] .= ' :originalzone'; - } - else if (!empty($test['zone'])) { - $tests[$i] .= ' :zone ' . self::escape_string($test['zone']); - } + if (!empty($test['originalzone']) && $test['test'] == 'date') { + $tests[$i] .= ' :originalzone'; + } + else if (!empty($test['zone'])) { + $tests[$i] .= ' :zone ' . self::escape_string($test['zone']); + } - $this->add_operator($test, $tests[$i], $exts); + $this->add_operator($test, $tests[$i], $exts); - if ($test['test'] == 'date') { - $tests[$i] .= ' ' . self::escape_string($test['header']); - } + if ($test['test'] == 'date') { + $tests[$i] .= ' ' . self::escape_string($test['header']); + } - $tests[$i] .= ' ' . self::escape_string($test['part']); - $tests[$i] .= ' ' . self::escape_string($test['arg']); + $tests[$i] .= ' ' . self::escape_string($test['part']); + $tests[$i] .= ' ' . self::escape_string($test['arg']); - break; + break; - case 'duplicate': - array_push($exts, 'duplicate'); + case 'duplicate': + array_push($exts, 'duplicate'); - $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . $test['test']; + $tests[$i] .= (!empty($test['not']) ? 'not ' : '') . $test['test']; - $tokens = ['handle', 'uniqueid', 'header']; - foreach ($tokens as $token) - if (isset($test[$token]) && $test[$token] !== '') { - $tests[$i] .= " :$token " . self::escape_string($test[$token]); + $tokens = ['handle', 'uniqueid', 'header']; + foreach ($tokens as $token) { + if (isset($test[$token]) && $test[$token] !== '') { + $tests[$i] .= " :$token " . self::escape_string($test[$token]); + } } - if (!empty($test['seconds'])) { - $tests[$i] .= ' :seconds ' . intval($test['seconds']); - } + if (!empty($test['seconds'])) { + $tests[$i] .= ' :seconds ' . intval($test['seconds']); + } - if (!empty($test['last'])) { - $tests[$i] .= ' :last'; - } + if (!empty($test['last'])) { + $tests[$i] .= ' :last'; + } - break; + break; } $i++; @@ -420,166 +421,172 @@ public function as_text() switch ($action['type']) { - case 'fileinto': - array_push($exts, 'fileinto'); - $action_script .= 'fileinto '; - if (!empty($action['copy'])) { - $action_script .= ':copy '; - array_push($exts, 'copy'); - } - $action_script .= self::escape_string($action['target']); - break; - - case 'redirect': - $action_script .= 'redirect '; - if (!empty($action['copy'])) { - $action_script .= ':copy '; - array_push($exts, 'copy'); - } - $action_script .= self::escape_string($action['target']); - break; - - case 'reject': - case 'ereject': - array_push($exts, $action['type']); - $action_script .= $action['type'] . ' ' . self::escape_string($action['target']); - break; - - case 'addflag': - case 'setflag': - case 'removeflag': - array_push($exts, $imapflags); - $action_script .= $action['type'] . ' ' . self::escape_string($action['target']); - break; - - case 'addheader': - case 'deleteheader': - array_push($exts, 'editheader'); - $action_script .= $action['type']; - if (!empty($action['index'])) { - $action_script .= " :index " . intval($action['index']); - } - if (!empty($action['last']) && (!empty($action['index']) || $action['type'] == 'addheader')) { - $action_script .= " :last"; - } - if ($action['type'] == 'deleteheader') { - $action['type'] = $action['match-type'] ?? null; - $this->add_operator($action, $action_script, $exts); - } - $action_script .= " " . self::escape_string($action['name']); - if ((is_string($action['value']) && strlen($action['value']) > 0) || (is_array($action['value']) && !empty($action['value']))) { - $action_script .= " " . self::escape_string($action['value']); - } - break; - - case 'keep': - case 'discard': - case 'stop': - $action_script .= $action['type']; - break; + case 'fileinto': + array_push($exts, 'fileinto'); + $action_script .= 'fileinto '; + if (!empty($action['copy'])) { + $action_script .= ':copy '; + array_push($exts, 'copy'); + } + $action_script .= self::escape_string($action['target']); + break; + + case 'redirect': + $action_script .= 'redirect '; + if (!empty($action['copy'])) { + $action_script .= ':copy '; + array_push($exts, 'copy'); + } + $action_script .= self::escape_string($action['target']); + break; + + case 'reject': + case 'ereject': + array_push($exts, $action['type']); + $action_script .= $action['type'] . ' ' . self::escape_string($action['target']); + break; + + case 'addflag': + case 'setflag': + case 'removeflag': + array_push($exts, $imapflags); + $action_script .= $action['type'] . ' ' . self::escape_string($action['target']); + break; + + case 'addheader': + case 'deleteheader': + array_push($exts, 'editheader'); + $action_script .= $action['type']; + if (!empty($action['index'])) { + $action_script .= " :index " . intval($action['index']); + } + if (!empty($action['last']) && (!empty($action['index']) || $action['type'] == 'addheader')) { + $action_script .= " :last"; + } + if ($action['type'] == 'deleteheader') { + $action['type'] = $action['match-type'] ?? null; + $this->add_operator($action, $action_script, $exts); + } + $action_script .= " " . self::escape_string($action['name']); + if ((is_string($action['value']) && strlen($action['value']) > 0) || (is_array($action['value']) && !empty($action['value']))) { + $action_script .= " " . self::escape_string($action['value']); + } + break; + + case 'keep': + case 'discard': + case 'stop': + $action_script .= $action['type']; + break; + + case 'include': + array_push($exts, 'include'); + $action_script .= 'include '; + foreach (array_diff(array_keys($action), ['target', 'type']) as $opt) { + $action_script .= ":$opt "; + } + $action_script .= self::escape_string($action['target']); + break; - case 'include': - array_push($exts, 'include'); - $action_script .= 'include '; - foreach (array_diff(array_keys($action), ['target', 'type']) as $opt) { - $action_script .= ":$opt "; - } - $action_script .= self::escape_string($action['target']); - break; + case 'set': + array_push($exts, 'variables'); + $action_script .= 'set '; + foreach (array_diff(array_keys($action), ['name', 'value', 'type']) as $opt) { + $action_script .= ":$opt "; + } + $action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']); + break; + + case 'replace': + array_push($exts, 'mime'); + $action_script .= 'replace'; + if (!empty($action['mime'])) { + $action_script .= " :mime"; + } + if (!empty($action['subject'])) { + $action_script .= " :subject " . self::escape_string($action['subject']); + } + if (!empty($action['from'])) { + $action_script .= " :from " . self::escape_string($action['from']); + } + $action_script .= ' ' . self::escape_string($action['replace']); + break; + + case 'notify': + array_push($exts, $notify); + $action_script .= 'notify'; + + $method = $action['method']; + unset($action['method']); + $action['options'] = (array) $action['options']; + + // Here we support draft-martin-sieve-notify-01 used by Cyrus + if ($notify == 'notify') { + if (!empty($action['importance'])) { + switch ($action['importance']) { + case 1: + $action_script .= " :high"; + break; + case 2: + // $action_script .= " :normal"; + break; + case 3: + $action_script .= " :low"; + break; + } + } - case 'set': - array_push($exts, 'variables'); - $action_script .= 'set '; - foreach (array_diff(array_keys($action), ['name', 'value', 'type']) as $opt) { - $action_script .= ":$opt "; - } - $action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']); - break; + // Old-draft way: :method "mailto" :options "email@address" + if (!empty($method)) { + $parts = explode(':', $method, 2); + $action['method'] = $parts[0]; + array_unshift($action['options'], $parts[1]); + } - case 'replace': - array_push($exts, 'mime'); - $action_script .= 'replace'; - if (!empty($action['mime'])) { - $action_script .= " :mime"; - } - if (!empty($action['subject'])) { - $action_script .= " :subject " . self::escape_string($action['subject']); - } - if (!empty($action['from'])) { - $action_script .= " :from " . self::escape_string($action['from']); - } - $action_script .= ' ' . self::escape_string($action['replace']); - break; + unset($action['importance']); + unset($action['from']); + unset($method); + } - case 'notify': - array_push($exts, $notify); - $action_script .= 'notify'; - - $method = $action['method']; - unset($action['method']); - $action['options'] = (array) $action['options']; - - // Here we support draft-martin-sieve-notify-01 used by Cyrus - if ($notify == 'notify') { - if (!empty($action['importance'])) { - switch ($action['importance']) { - case 1: $action_script .= " :high"; break; - //case 2: $action_script .= " :normal"; break; - case 3: $action_script .= " :low"; break; + foreach (['id', 'importance', 'method', 'options', 'from', 'message'] as $n_tag) { + if (!empty($action[$n_tag])) { + $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]); } } - // Old-draft way: :method "mailto" :options "email@address" if (!empty($method)) { - $parts = explode(':', $method, 2); - $action['method'] = $parts[0]; - array_unshift($action['options'], $parts[1]); + $action_script .= ' ' . self::escape_string($method); } - unset($action['importance']); - unset($action['from']); - unset($method); - } + break; - foreach (['id', 'importance', 'method', 'options', 'from', 'message'] as $n_tag) { - if (!empty($action[$n_tag])) { - $action_script .= " :$n_tag " . self::escape_string($action[$n_tag]); + case 'vacation': + array_push($exts, 'vacation'); + $action_script .= 'vacation'; + if (isset($action['seconds'])) { + array_push($exts, 'vacation-seconds'); + $action_script .= " :seconds " . intval($action['seconds']); } - } - - if (!empty($method)) { - $action_script .= ' ' . self::escape_string($method); - } - - break; - - case 'vacation': - array_push($exts, 'vacation'); - $action_script .= 'vacation'; - if (isset($action['seconds'])) { - array_push($exts, 'vacation-seconds'); - $action_script .= " :seconds " . intval($action['seconds']); - } - else if (!empty($action['days'])) { - $action_script .= " :days " . intval($action['days']); - } - if (!empty($action['addresses'])) { - $action_script .= " :addresses " . self::escape_string($action['addresses']); - } - if (!empty($action['subject'])) { - $action_script .= " :subject " . self::escape_string($action['subject']); - } - if (!empty($action['handle'])) { - $action_script .= " :handle " . self::escape_string($action['handle']); - } - if (!empty($action['from'])) { - $action_script .= " :from " . self::escape_string($action['from']); - } - if (!empty($action['mime'])) { - $action_script .= " :mime"; - } - $action_script .= " " . self::escape_string($action['reason']); - break; + else if (!empty($action['days'])) { + $action_script .= " :days " . intval($action['days']); + } + if (!empty($action['addresses'])) { + $action_script .= " :addresses " . self::escape_string($action['addresses']); + } + if (!empty($action['subject'])) { + $action_script .= " :subject " . self::escape_string($action['subject']); + } + if (!empty($action['handle'])) { + $action_script .= " :handle " . self::escape_string($action['handle']); + } + if (!empty($action['from'])) { + $action_script .= " :from " . self::escape_string($action['from']); + } + if (!empty($action['mime'])) { + $action_script .= " :mime"; + } + $action_script .= " " . self::escape_string($action['reason']); + break; } if ($action_script) { @@ -776,137 +783,137 @@ private function _tokenize_rule($content, &$position) } switch ($token) { - case 'allof': - $join = true; - $join_not = $not; - break; + case 'allof': + $join = true; + $join_not = $not; + break; - case 'anyof': - break; + case 'anyof': + break; - case 'size': - $test = ['test' => 'size', 'not' => $not]; + case 'size': + $test = ['test' => 'size', 'not' => $not]; - $test['arg'] = array_pop($tokens); + $test['arg'] = array_pop($tokens); - for ($i=0, $len=count($tokens); $i<$len; $i++) { - if (!is_array($tokens[$i]) - && preg_match('/^:(under|over)$/i', $tokens[$i]) - ) { - $test['type'] = strtolower(substr($tokens[$i], 1)); + for ($i=0, $len=count($tokens); $i<$len; $i++) { + if (!is_array($tokens[$i]) + && preg_match('/^:(under|over)$/i', $tokens[$i]) + ) { + $test['type'] = strtolower(substr($tokens[$i], 1)); + } } - } - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'spamtest': - $test = ['test' => 'spamtest', 'not' => $not]; + case 'spamtest': + $test = ['test' => 'spamtest', 'not' => $not]; - $test['arg'] = array_pop($tokens); + $test['arg'] = array_pop($tokens); - $test += $this->test_tokens($tokens); + $test += $this->test_tokens($tokens); - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'header': - case 'string': - case 'address': - case 'envelope': - $test = ['test' => $token, 'not' => $not]; + case 'header': + case 'string': + case 'address': + case 'envelope': + $test = ['test' => $token, 'not' => $not]; - $test['arg2'] = array_pop($tokens); - $test['arg1'] = array_pop($tokens); + $test['arg2'] = array_pop($tokens); + $test['arg1'] = array_pop($tokens); - $test += $this->test_tokens($tokens); + $test += $this->test_tokens($tokens); - if ($token != 'header' && $token != 'string' && !empty($tokens)) { - for ($i=0, $len=count($tokens); $i<$len; $i++) { - if (!is_array($tokens[$i]) && preg_match('/^:(localpart|domain|all|user|detail)$/i', $tokens[$i])) { - $test['part'] = strtolower(substr($tokens[$i], 1)); + if ($token != 'header' && $token != 'string' && !empty($tokens)) { + for ($i=0, $len=count($tokens); $i<$len; $i++) { + if (!is_array($tokens[$i]) && preg_match('/^:(localpart|domain|all|user|detail)$/i', $tokens[$i])) { + $test['part'] = strtolower(substr($tokens[$i], 1)); + } } } - } - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'body': - $test = ['test' => 'body', 'not' => $not]; + case 'body': + $test = ['test' => 'body', 'not' => $not]; - $test['arg'] = array_pop($tokens); + $test['arg'] = array_pop($tokens); - $test += $this->test_tokens($tokens); + $test += $this->test_tokens($tokens); - for ($i=0, $len=count($tokens); $i<$len; $i++) { - if (!is_array($tokens[$i]) && preg_match('/^:(raw|content|text)$/i', $tokens[$i])) { - $test['part'] = strtolower(substr($tokens[$i], 1)); + for ($i=0, $len=count($tokens); $i<$len; $i++) { + if (!is_array($tokens[$i]) && preg_match('/^:(raw|content|text)$/i', $tokens[$i])) { + $test['part'] = strtolower(substr($tokens[$i], 1)); - if ($test['part'] == 'content') { - $test['content'] = $tokens[++$i]; + if ($test['part'] == 'content') { + $test['content'] = $tokens[++$i]; + } } } - } - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'date': - case 'currentdate': - $test = ['test' => $token, 'not' => $not]; + case 'date': + case 'currentdate': + $test = ['test' => $token, 'not' => $not]; - $test['arg'] = array_pop($tokens); - $test['part'] = array_pop($tokens); + $test['arg'] = array_pop($tokens); + $test['part'] = array_pop($tokens); - if ($token == 'date') { - $test['header'] = array_pop($tokens); - } + if ($token == 'date') { + $test['header'] = array_pop($tokens); + } - $test += $this->test_tokens($tokens); + $test += $this->test_tokens($tokens); - for ($i=0, $len=count($tokens); $i<$len; $i++) { - if (!is_array($tokens[$i]) && preg_match('/^:zone$/i', $tokens[$i])) { - $test['zone'] = $tokens[++$i]; - } - else if (!is_array($tokens[$i]) && preg_match('/^:originalzone$/i', $tokens[$i])) { - $test['originalzone'] = true; + for ($i=0, $len=count($tokens); $i<$len; $i++) { + if (!is_array($tokens[$i]) && preg_match('/^:zone$/i', $tokens[$i])) { + $test['zone'] = $tokens[++$i]; + } + else if (!is_array($tokens[$i]) && preg_match('/^:originalzone$/i', $tokens[$i])) { + $test['originalzone'] = true; + } } - } - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'duplicate': - $test = ['test' => $token, 'not' => $not]; + case 'duplicate': + $test = ['test' => $token, 'not' => $not]; - for ($i=0, $len=count($tokens); $i<$len; $i++) { - if (!is_array($tokens[$i])) { - if (preg_match('/^:(handle|header|uniqueid|seconds)$/i', $tokens[$i], $m)) { - $test[strtolower($m[1])] = $tokens[++$i]; - } - else if (preg_match('/^:last$/i', $tokens[$i])) { - $test['last'] = true; + for ($i=0, $len=count($tokens); $i<$len; $i++) { + if (!is_array($tokens[$i])) { + if (preg_match('/^:(handle|header|uniqueid|seconds)$/i', $tokens[$i], $m)) { + $test[strtolower($m[1])] = $tokens[++$i]; + } + else if (preg_match('/^:last$/i', $tokens[$i])) { + $test['last'] = true; + } } } - } - $tests[] = $test; - break; + $tests[] = $test; + break; - case 'exists': - $test = ['test' => 'exists', 'not' => $not, 'arg' => array_pop($tokens)]; - $test += $this->test_tokens($tokens); - $tests[] = $test; - break; + case 'exists': + $test = ['test' => 'exists', 'not' => $not, 'arg' => array_pop($tokens)]; + $test += $this->test_tokens($tokens); + $tests[] = $test; + break; - case 'true': - $tests[] = ['test' => 'true', 'not' => $not]; - break; + case 'true': + $tests[] = ['test' => 'true', 'not' => $not]; + break; - case 'false': - $tests[] = ['test' => 'true', 'not' => !$not]; - break; + case 'false': + $tests[] = ['test' => 'true', 'not' => !$not]; + break; } // goto actions... @@ -951,120 +958,120 @@ private function _parse_actions($content, &$position, $end = '}') $token = !empty($tokens) ? array_shift($tokens) : $separator; switch ($token) { - case 'if': - case 'else': - case 'elsif': - // nested 'if' conditions, ignore the whole rule (#5540) - $this->_parse_actions($content, $position); - continue 2; - - case 'discard': - case 'keep': - case 'stop': - $result[] = ['type' => $token]; - break; + case 'if': + case 'else': + case 'elsif': + // nested 'if' conditions, ignore the whole rule (#5540) + $this->_parse_actions($content, $position); + continue 2; + + case 'discard': + case 'keep': + case 'stop': + $result[] = ['type' => $token]; + break; - case 'fileinto': - case 'redirect': - $action = ['type' => $token, 'target' => array_pop($tokens)]; - $args = ['copy']; - $action += $this->action_arguments($tokens, $args); + case 'fileinto': + case 'redirect': + $action = ['type' => $token, 'target' => array_pop($tokens)]; + $args = ['copy']; + $action += $this->action_arguments($tokens, $args); - $result[] = $action; - break; + $result[] = $action; + break; - case 'vacation': - $action = ['type' => 'vacation', 'reason' => array_pop($tokens)]; - $args = ['mime']; - $vargs = ['seconds', 'days', 'addresses', 'subject', 'handle', 'from']; - $action += $this->action_arguments($tokens, $args, $vargs); + case 'vacation': + $action = ['type' => 'vacation', 'reason' => array_pop($tokens)]; + $args = ['mime']; + $vargs = ['seconds', 'days', 'addresses', 'subject', 'handle', 'from']; + $action += $this->action_arguments($tokens, $args, $vargs); - $result[] = $action; - break; + $result[] = $action; + break; - case 'addheader': - case 'deleteheader': - $args = $this->test_tokens($tokens); - if ($token == 'deleteheader' && !empty($args['type'])) { - $args['match-type'] = $args['type']; - } - if (($index = array_search(':last', $tokens)) !== false) { - $args['last'] = true; - unset($tokens[$index]); - } - $action = ['type' => $token, 'name' => array_shift($tokens), 'value' => array_shift($tokens)]; + case 'addheader': + case 'deleteheader': + $args = $this->test_tokens($tokens); + if ($token == 'deleteheader' && !empty($args['type'])) { + $args['match-type'] = $args['type']; + } + if (($index = array_search(':last', $tokens)) !== false) { + $args['last'] = true; + unset($tokens[$index]); + } + $action = ['type' => $token, 'name' => array_shift($tokens), 'value' => array_shift($tokens)]; - $result[] = $action + $args; - break; + $result[] = $action + $args; + break; - case 'reject': - case 'ereject': - case 'setflag': - case 'addflag': - case 'removeflag': - $result[] = ['type' => $token, 'target' => array_pop($tokens)]; - break; + case 'reject': + case 'ereject': + case 'setflag': + case 'addflag': + case 'removeflag': + $result[] = ['type' => $token, 'target' => array_pop($tokens)]; + break; - case 'include': - $action = ['type' => 'include', 'target' => array_pop($tokens)]; - $args = ['once', 'optional', 'global', 'personal']; - $action += $this->action_arguments($tokens, $args); + case 'include': + $action = ['type' => 'include', 'target' => array_pop($tokens)]; + $args = ['once', 'optional', 'global', 'personal']; + $action += $this->action_arguments($tokens, $args); - $result[] = $action; - break; + $result[] = $action; + break; - case 'set': - $action = ['type' => 'set', 'value' => array_pop($tokens), 'name' => array_pop($tokens)]; - $args = ['lower', 'upper', 'lowerfirst', 'upperfirst', 'quotewildcard', 'length', 'encodeurl']; - $action += $this->action_arguments($tokens, $args); + case 'set': + $action = ['type' => 'set', 'value' => array_pop($tokens), 'name' => array_pop($tokens)]; + $args = ['lower', 'upper', 'lowerfirst', 'upperfirst', 'quotewildcard', 'length', 'encodeurl']; + $action += $this->action_arguments($tokens, $args); - $result[] = $action; - break; + $result[] = $action; + break; - case 'replace': - $action = ['type' => 'replace', 'replace' => array_pop($tokens)]; - $args = ['mime']; - $vargs = ['subject', 'from']; - $action += $this->action_arguments($tokens, $args, $vargs); + case 'replace': + $action = ['type' => 'replace', 'replace' => array_pop($tokens)]; + $args = ['mime']; + $vargs = ['subject', 'from']; + $action += $this->action_arguments($tokens, $args, $vargs); - $result[] = $action; - break; + $result[] = $action; + break; - case 'require': - // skip, will be build according to used commands - // $result[] = ['type' => 'require', 'target' => array_pop($tokens)]; - break; + case 'require': + // skip, will be build according to used commands + // $result[] = ['type' => 'require', 'target' => array_pop($tokens)]; + break; - case 'notify': - $action = ['type' => 'notify']; - $priorities = ['high' => 1, 'normal' => 2, 'low' => 3]; - $vargs = ['from', 'id', 'importance', 'options', 'message', 'method']; - $args = array_keys($priorities); - $action += $this->action_arguments($tokens, $args, $vargs); - - // Here we'll convert draft-martin-sieve-notify-01 into RFC 5435 - if (!isset($action['importance'])) { - foreach ($priorities as $key => $val) { - if (isset($action[$key])) { - $action['importance'] = $val; - unset($action[$key]); + case 'notify': + $action = ['type' => 'notify']; + $priorities = ['high' => 1, 'normal' => 2, 'low' => 3]; + $vargs = ['from', 'id', 'importance', 'options', 'message', 'method']; + $args = array_keys($priorities); + $action += $this->action_arguments($tokens, $args, $vargs); + + // Here we'll convert draft-martin-sieve-notify-01 into RFC 5435 + if (!isset($action['importance'])) { + foreach ($priorities as $key => $val) { + if (isset($action[$key])) { + $action['importance'] = $val; + unset($action[$key]); + } } } - } - $action['options'] = isset($action['options']) ? (array) $action['options'] : []; + $action['options'] = isset($action['options']) ? (array) $action['options'] : []; - // Old-draft way: :method "mailto" :options "email@address" - if (!empty($action['method']) && !empty($action['options'])) { - $action['method'] .= ':' . array_shift($action['options']); - } - // unnamed parameter is a :method in enotify extension - else if (!isset($action['method'])) { - $action['method'] = array_pop($tokens); - } + // Old-draft way: :method "mailto" :options "email@address" + if (!empty($action['method']) && !empty($action['options'])) { + $action['method'] .= ':' . array_shift($action['options']); + } + // unnamed parameter is a :method in enotify extension + else if (!isset($action['method'])) { + $action['method'] = array_pop($tokens); + } - $result[] = $action; - break; + $result[] = $action; + break; } if ($separator == $end) { @@ -1308,155 +1315,155 @@ static function tokenize($str, $num = 0, &$position = 0) switch ($str[$position]) { - // Quoted string - case '"': - for ($pos = $position + 1; $pos < $length; $pos++) { - if ($str[$pos] == '"') { - break; - } - if ($str[$pos] == "\\") { - if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { - $pos++; + // Quoted string + case '"': + for ($pos = $position + 1; $pos < $length; $pos++) { + if ($str[$pos] == '"') { + break; + } + if ($str[$pos] == "\\") { + if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { + $pos++; + } } } - } - if ($str[$pos] != '"') { - // error - } - - // we need to strip slashes for a quoted string - $result[] = stripslashes(substr($str, $position + 1, $pos - $position - 1)); - $position = $pos + 1; - break; - - // Parenthesized list - case '[': - $position++; - $result[] = self::tokenize($str, 0, $position); - break; - case ']': - $position++; - return $result; - break; - - // list/test separator - case ',': - // command separator - case ';': - // block/tests-list - case '(': - case ')': - case '{': - case '}': - $sep = $str[$position]; - $position++; - if ($num === true) { - $result[] = $sep; - break 2; - } - break; - - // bracket-comment - case '/': - if ($str[$position + 1] == '*') { - if ($end_pos = strpos($str, '*/', $position + 2)) { - $position = $end_pos + 2; - } - else { + if ($str[$pos] != '"') { // error - $position = $length; } - } - break; - // hash-comment - case '#': - if ($lf_pos = strpos($str, "\n", $position)) { - $position = $lf_pos + 1; + // we need to strip slashes for a quoted string + $result[] = stripslashes(substr($str, $position + 1, $pos - $position - 1)); + $position = $pos + 1; break; - } - else { - $position = $length; - } - // String atom - default: - // empty or one character - if ($position == $length) { - break 2; - } - if ($length - $position < 2) { - $result[] = substr($str, $position); - $position = $length; + // Parenthesized list (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '[': + $position++; + $result[] = self::tokenize($str, 0, $position); + break; + case ']': + $position++; + return $result; break; - } - - // tag/identifier/number - if (preg_match('/[a-zA-Z0-9:_]+/', $str, $m, PREG_OFFSET_CAPTURE, $position) - && $m[0][1] == $position - ) { - $atom = $m[0][0]; - $position += strlen($atom); - if ($atom != 'text:') { - $result[] = $atom; + // list/test separator (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case ',': + // command separator (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case ';': + // block/tests-list (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '(': + case ')': + case '{': + case '}': + $sep = $str[$position]; + $position++; + if ($num === true) { + $result[] = $sep; + break 2; } - // multiline string - else { - // skip whitespace chars (except \r\n) - $position = self::ltrim_position($str, $position, false); + break; - // possible hash-comment after "text:" - if ($str[$position] === '#') { - $endl = strpos($str, "\n", $position); - $position = $endl ?: $length; + // bracket-comment (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '/': + if ($str[$position + 1] == '*') { + if ($end_pos = strpos($str, '*/', $position + 2)) { + $position = $end_pos + 2; } - - // skip \n or \r\n - if ($str[$position] == "\n") { - $position++; - } - else if ($str[$position] == "\r" && $str[$position + 1] == "\n") { - $position += 2; + else { + // error + $position = $length; } + } + break; - $text = ''; + // hash-comment (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '#': + if ($lf_pos = strpos($str, "\n", $position)) { + $position = $lf_pos + 1; + break; + } + else { + $position = $length; + } - // get text until alone dot in a line - while ($position < $length) { - $pos = strpos($str, "\n.", $position); - if ($pos === false) { - break; - } + // String atom (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + default: + // empty or one character + if ($position == $length) { + break 2; + } + if ($length - $position < 2) { + $result[] = substr($str, $position); + $position = $length; + break; + } - $text .= substr($str, $position, $pos - $position); - $position = $pos + 2; + // tag/identifier/number + if (preg_match('/[a-zA-Z0-9:_]+/', $str, $m, PREG_OFFSET_CAPTURE, $position) + && $m[0][1] == $position + ) { + $atom = $m[0][0]; + $position += strlen($atom); - if ($str[$position] == "\n") { - break; + if ($atom != 'text:') { + $result[] = $atom; + } + // multiline string + else { + // skip whitespace chars (except \r\n) + $position = self::ltrim_position($str, $position, false); + + // possible hash-comment after "text:" + if ($str[$position] === '#') { + $endl = strpos($str, "\n", $position); + $position = $endl ?: $length; } - if ($str[$position] == "\r" && $str[$position + 1] == "\n") { + // skip \n or \r\n + if ($str[$position] == "\n") { $position++; - break; + } + else if ($str[$position] == "\r" && $str[$position + 1] == "\n") { + $position += 2; } - $text .= "\n."; - } + $text = ''; - // remove dot-stuffing - $text = str_replace("\n..", "\n.", $text); + // get text until alone dot in a line + while ($position < $length) { + $pos = strpos($str, "\n.", $position); + if ($pos === false) { + break; + } + + $text .= substr($str, $position, $pos - $position); + $position = $pos + 2; + + if ($str[$position] == "\n") { + break; + } - $result[] = rtrim($text, "\r\n"); + if ($str[$position] == "\r" && $str[$position + 1] == "\n") { + $position++; + break; + } + + $text .= "\n."; + } + + // remove dot-stuffing + $text = str_replace("\n..", "\n.", $text); + + $result[] = rtrim($text, "\r\n"); + $position++; + } + } + // fallback, skip one character as infinite loop prevention + else { $position++; } - } - // fallback, skip one character as infinite loop prevention - else { - $position++; - } - break; + break; } } diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index 7c91c29b817..11705a99980 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -272,7 +272,7 @@ function managesieve_saveraw() } // load localization - $this->add_texts('localization/', ['filters','managefilters']); + $this->add_texts('localization/', ['filters', 'managefilters']); $engine->saveraw(); } diff --git a/plugins/managesieve/tests/Managesieve.php b/plugins/managesieve/tests/Managesieve.php index c671bb14a56..3c518d703ce 100644 --- a/plugins/managesieve/tests/Managesieve.php +++ b/plugins/managesieve/tests/Managesieve.php @@ -2,7 +2,6 @@ class Managesieve_Plugin extends PHPUnit\Framework\TestCase { - static function setUpBeforeClass(): void { include_once __DIR__ . '/../managesieve.php'; diff --git a/plugins/markasjunk/drivers/amavis_blacklist.php b/plugins/markasjunk/drivers/amavis_blacklist.php index 6199045d12b..2e3ed7151ef 100644 --- a/plugins/markasjunk/drivers/amavis_blacklist.php +++ b/plugins/markasjunk/drivers/amavis_blacklist.php @@ -1,6 +1,6 @@ $mailto, 'dsn_enabled' => false, 'charset' => 'UTF-8', - 'error_handler' => function(...$args) use ($OUTPUT) { + 'error_handler' => function (...$args) use ($OUTPUT) { call_user_func_array([$OUTPUT, 'show_message'], $args); $OUTPUT->send(); } diff --git a/plugins/markasjunk/tests/Browser/MailTest.php b/plugins/markasjunk/tests/Browser/MailTest.php index b72e34f660c..0f7c053dd34 100644 --- a/plugins/markasjunk/tests/Browser/MailTest.php +++ b/plugins/markasjunk/tests/Browser/MailTest.php @@ -2,8 +2,6 @@ namespace Tests\Browser\Plugins\Markasjunk; -use Tests\Browser\Components\Popupmenu; - class MailTest extends \Tests\Browser\TestCase { public static function setUpBeforeClass(): void diff --git a/plugins/new_user_dialog/tests/NewUserDialog.php b/plugins/new_user_dialog/tests/NewUserDialog.php index 992df325243..84a24c5f758 100644 --- a/plugins/new_user_dialog/tests/NewUserDialog.php +++ b/plugins/new_user_dialog/tests/NewUserDialog.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/new_user_identity/new_user_identity.php b/plugins/new_user_identity/new_user_identity.php index c79bf029357..b409c30dbc2 100644 --- a/plugins/new_user_identity/new_user_identity.php +++ b/plugins/new_user_identity/new_user_identity.php @@ -129,7 +129,7 @@ private function init_ldap($host, $user) $this->load_config(); $addressbook = $this->rc->config->get('new_user_identity_addressbook'); - $ldap_config = (array)$this->rc->config->get('ldap_public'); + $ldap_config = (array) $this->rc->config->get('ldap_public'); $match = $this->rc->config->get('new_user_identity_match'); if (empty($addressbook) || empty($match) || empty($ldap_config[$addressbook])) { diff --git a/plugins/new_user_identity/tests/NewUserIdentity.php b/plugins/new_user_identity/tests/NewUserIdentity.php index 463b9a1fcb4..8cb60940c6c 100644 --- a/plugins/new_user_identity/tests/NewUserIdentity.php +++ b/plugins/new_user_identity/tests/NewUserIdentity.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php index 2066747e4a4..3fb5ef5eaf6 100644 --- a/plugins/newmail_notifier/newmail_notifier.php +++ b/plugins/newmail_notifier/newmail_notifier.php @@ -76,7 +76,7 @@ function init() $this->add_hook('new_messages', [$this, 'notify']); } - } + } } } diff --git a/plugins/newmail_notifier/tests/NewmailNotifier.php b/plugins/newmail_notifier/tests/NewmailNotifier.php index 6d646dd8745..f579cbf79b7 100644 --- a/plugins/newmail_notifier/tests/NewmailNotifier.php +++ b/plugins/newmail_notifier/tests/NewmailNotifier.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/password/drivers/directadmin.php b/plugins/password/drivers/directadmin.php index 54f4f03e8b8..dbec51c9147 100644 --- a/plugins/password/drivers/directadmin.php +++ b/plugins/password/drivers/directadmin.php @@ -44,7 +44,7 @@ public function save($curpass, $passwd) $da_host = str_replace('%h', $_SESSION['imap_host'], $da_host); $da_host = str_replace('%d', $rcmail->user->get_username('domain'), $da_host); - $Socket->connect($da_host,$da_port); + $Socket->connect($da_host,$da_port); $Socket->set_method('POST'); $Socket->query('/CMD_CHANGE_EMAIL_PASSWORD', [ 'email' => $da_user, @@ -190,7 +190,7 @@ function query($request, $content = '') $this->set_login($location['user'], $location['pass']); $request = $location['path']; - + if ($content == '') { $content = $location['query']; } @@ -413,7 +413,9 @@ function fetch_header($header = '') unset($array_headers[0]); foreach ($array_headers as $pair) { - if ($pair == '' || $pair == "\r\n") continue; + if ($pair == '' || $pair == "\r\n") { + continue; + } list($key,$value) = preg_split("/: /", $pair, 2); $array_return[strtolower($key)] = $value; } diff --git a/plugins/password/drivers/ldap_exop.php b/plugins/password/drivers/ldap_exop.php index 5c33d5b7953..a9f44587850 100644 --- a/plugins/password/drivers/ldap_exop.php +++ b/plugins/password/drivers/ldap_exop.php @@ -1,6 +1,6 @@ _debug('Policy result: ' . $result); switch ($result) { - case "OK": - return PASSWORD_SUCCESS; - case "Password is in history of old passwords": - return PASSWORD_IN_HISTORY; - case "Cannot connect to any server": - return PASSWORD_CONNECT_ERROR; - default: - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Failed to execute command: $cmd. Output: $result. Error: $stderr" - ], true, false); + case "OK": + return PASSWORD_SUCCESS; + case "Password is in history of old passwords": + return PASSWORD_IN_HISTORY; + case "Cannot connect to any server": + return PASSWORD_CONNECT_ERROR; + default: + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Failed to execute command: $cmd. Output: $result. Error: $stderr" + ], true, false); } } diff --git a/plugins/password/drivers/ldap_samba_ad.php b/plugins/password/drivers/ldap_samba_ad.php index caee865c03f..096755e0104 100644 --- a/plugins/password/drivers/ldap_samba_ad.php +++ b/plugins/password/drivers/ldap_samba_ad.php @@ -1,6 +1,6 @@ config->get('password_ldap_method')) { - case 'sasl': - $binddn = $rcmail->config->get('password_ldap_adminDN'); - $bindpw = $rcmail->config->get('password_ldap_adminPW'); - $bindmech = $rcmail->config->get('password_ldap_mech'); - $bindrealm = $rcmail->config->get('password_ldap_realm'); - break; - case 'admin': - $binddn = $rcmail->config->get('password_ldap_adminDN'); - $bindpw = $rcmail->config->get('password_ldap_adminPW'); - break; - case 'user': - default: - $binddn = $user_dn; - $bindpw = $curpass; - break; + case 'sasl': + $binddn = $rcmail->config->get('password_ldap_adminDN'); + $bindpw = $rcmail->config->get('password_ldap_adminPW'); + $bindmech = $rcmail->config->get('password_ldap_mech'); + $bindrealm = $rcmail->config->get('password_ldap_realm'); + break; + case 'admin': + $binddn = $rcmail->config->get('password_ldap_adminDN'); + $bindpw = $rcmail->config->get('password_ldap_adminPW'); + break; + case 'user': + default: + $binddn = $user_dn; + $bindpw = $curpass; + break; } $this->_debug("C: Bind $binddn, pass: **** [" . strlen($bindpw) . "]"); @@ -240,27 +240,27 @@ function search_userdn($rcmail, $ds) $this->_debug("C: Bind " . ($search_user ? $search_user : '[anonymous]')); switch ($rcmail->config->get('password_ldap_bind_method')) { - case 'sasl': - $search_mech = $rcmail->config->get('password_ldap_mech'); - $search_realm = $rcmail->config->get('password_ldap_realm'); - - // Bind - if (!ldap_sasl_bind($ds, $search_user, $search_pass, $search_mech, $search_realm)) { - $this->_debug("S: ".ldap_error($ds)); - return false; - } - - break; - case 'bind': - default: - - // Bind - if (!ldap_bind($ds, $search_user, $search_pass)) { - $this->_debug("S: ".ldap_error($ds)); - return false; - } - - break; + case 'sasl': + $search_mech = $rcmail->config->get('password_ldap_mech'); + $search_realm = $rcmail->config->get('password_ldap_realm'); + + // Bind + if (!ldap_sasl_bind($ds, $search_user, $search_pass, $search_mech, $search_realm)) { + $this->_debug("S: ".ldap_error($ds)); + return false; + } + + break; + case 'bind': + default: + + // Bind + if (!ldap_bind($ds, $search_user, $search_pass)) { + $this->_debug("S: ".ldap_error($ds)); + return false; + } + + break; } $this->_debug("S: OK"); diff --git a/plugins/password/drivers/mailcow.php b/plugins/password/drivers/mailcow.php index 1aa2536790c..ed388fd50a4 100644 --- a/plugins/password/drivers/mailcow.php +++ b/plugins/password/drivers/mailcow.php @@ -1,6 +1,6 @@ $passwd, 'password2' => $passwd ], - 'items' => [ $username ] + 'items' => [$username] ]; if (!strpos($host, '://')) { diff --git a/plugins/password/drivers/modoboa.php b/plugins/password/drivers/modoboa.php index 8ef4a26cd08..e9275b20ea6 100644 --- a/plugins/password/drivers/modoboa.php +++ b/plugins/password/drivers/modoboa.php @@ -24,7 +24,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * - * The driver need modoboa core 1.10.6 or later + * The driver need modoboa core 1.10.6 or later * * You need to define theses variables in plugin/password/config.inc.php * diff --git a/plugins/password/drivers/plesk.php b/plugins/password/drivers/plesk.php index 898bf1b512f..ec5b28a56a5 100644 --- a/plugins/password/drivers/plesk.php +++ b/plugins/password/drivers/plesk.php @@ -1,6 +1,6 @@ config->get('password_smb_host', 'localhost'); diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php index 919da077816..6599688fd6b 100644 --- a/plugins/password/drivers/sql.php +++ b/plugins/password/drivers/sql.php @@ -43,7 +43,7 @@ function save($curpass, $passwd) if ($dsn = $rcmail->config->get('password_db_dsn')) { $db = rcube_db::factory(self::parse_dsn($dsn), '', false); - $db->set_debug((bool)$rcmail->config->get('sql_debug')); + $db->set_debug((bool) $rcmail->config->get('sql_debug')); } else { $db = $rcmail->get_dbh(); diff --git a/plugins/password/drivers/tinycp.php b/plugins/password/drivers/tinycp.php index 9c5f41b85ea..49a0bc15a24 100644 --- a/plugins/password/drivers/tinycp.php +++ b/plugins/password/drivers/tinycp.php @@ -8,7 +8,7 @@ * * @version 1.2 * @author Ricky Mendoza (HelloWorld@rickymendoza.dev) - * + * * Copyright (C) 2020 Ricky Mendoza * * This program is free software: you can redistribute it and/or modify diff --git a/plugins/password/drivers/vpopmaild.php b/plugins/password/drivers/vpopmaild.php index 5de5c438c73..d61e6a2f8e0 100644 --- a/plugins/password/drivers/vpopmaild.php +++ b/plugins/password/drivers/vpopmaild.php @@ -41,7 +41,7 @@ function save($curpass, $passwd, $username) $vpopmaild->setTimeout($rcmail->config->get('password_vpopmaild_timeout'),0); $result = $vpopmaild->readLine(); - if(!preg_match('/^\+OK/', $result)) { + if (!preg_match('/^\+OK/', $result)) { $vpopmaild->disconnect(); return PASSWORD_CONNECT_ERROR; } @@ -49,7 +49,7 @@ function save($curpass, $passwd, $username) $vpopmaild->writeLine("slogin ". $username . " " . $curpass); $result = $vpopmaild->readLine(); - if(!preg_match('/^\+OK/', $result) ) { + if (!preg_match('/^\+OK/', $result)) { $vpopmaild->writeLine("quit"); $vpopmaild->disconnect(); return PASSWORD_ERROR; diff --git a/plugins/password/drivers/ximss.php b/plugins/password/drivers/ximss.php index bea1c86accc..2ab880c74c3 100644 --- a/plugins/password/drivers/ximss.php +++ b/plugins/password/drivers/ximss.php @@ -1,6 +1,6 @@ '."\0"); fwrite($sock, ''."\0"); - //example responses - // \0 - // \0 - // \0 - // \0 - // or an error: - // \0 + //example responses + // \0 + // \0 + // \0 + // \0 + // or an error: + // \0 $responseblob = ''; while (!feof($sock)) { @@ -64,7 +64,7 @@ function save($pass, $newpass, $username) fclose($sock); - foreach (explode( "\0", $responseblob) as $response) { + foreach (explode("\0", $responseblob) as $response) { $resp = simplexml_load_string("".$response.""); $id = $resp && !empty($resp->response[0]['id']) ? $resp->response[0]['id'] : null; diff --git a/plugins/password/drivers/xmail.php b/plugins/password/drivers/xmail.php index 64078394ce5..34dd2a55e3f 100644 --- a/plugins/password/drivers/xmail.php +++ b/plugins/password/drivers/xmail.php @@ -75,7 +75,8 @@ function save($currpass, $newpass) } } -class XMail { +class XMail +{ var $socket; var $hostname = 'localhost'; var $username = 'xmail'; @@ -94,8 +95,9 @@ function send($msg) function connect() { $this->socket = socket_create(AF_INET, SOCK_STREAM, 0); - if ($this->socket < 0) + if ($this->socket < 0) { return false; + } $result = socket_connect($this->socket, $this->hostname, $this->port); if ($result < 0) { diff --git a/plugins/password/password.php b/plugins/password/password.php index a29dc8510d8..a543a982659 100644 --- a/plugins/password/password.php +++ b/plugins/password/password.php @@ -1,6 +1,6 @@ @@ -332,14 +332,14 @@ private function _compare($curpwd, $newpwd, $type) } else { switch ($type) { - case PASSWORD_COMPARE_CURRENT: - $result = $curpwd != $newpwd ? $this->gettext('passwordincorrect') : null; - break; - case PASSWORD_COMPARE_NEW: - $result = $curpwd == $newpwd ? $this->gettext('samepasswd') : null; - break; - default: - $result = $this->gettext('internalerror'); + case PASSWORD_COMPARE_CURRENT: + $result = $curpwd != $newpwd ? $this->gettext('passwordincorrect') : null; + break; + case PASSWORD_COMPARE_NEW: + $result = $curpwd == $newpwd ? $this->gettext('samepasswd') : null; + break; + default: + $result = $this->gettext('internalerror'); } } @@ -537,257 +537,257 @@ public static function hash_password($password, $method = '', $prefixed = true) } switch ($method) { - case 'des': - case 'des-crypt': - $crypted = crypt($password, rcube_utils::random_bytes(2)); - $prefix = '{CRYPT}'; - break; - - case 'ext_des': // for BC - case 'ext-des-crypt': - $crypted = crypt($password, '_' . rcube_utils::random_bytes(8)); - $prefix = '{CRYPT}'; - break; - - case 'md5crypt': // for BC - case 'md5-crypt': - $crypted = crypt($password, '$1$' . rcube_utils::random_bytes(9)); - $prefix = '{MD5-CRYPT}'; - break; - - case 'sha256-crypt': - $rounds = (int) $rcmail->config->get('password_crypt_rounds'); - $prefix = '$5$'; - - if ($rounds > 1000) { - $prefix .= 'rounds=' . $rounds . '$'; - } + case 'des': + case 'des-crypt': + $crypted = crypt($password, rcube_utils::random_bytes(2)); + $prefix = '{CRYPT}'; + break; - $crypted = crypt($password, $prefix . rcube_utils::random_bytes(16)); - $prefix = '{SHA256-CRYPT}'; - break; + case 'ext_des': // for BC + case 'ext-des-crypt': + $crypted = crypt($password, '_' . rcube_utils::random_bytes(8)); + $prefix = '{CRYPT}'; + break; - case 'sha512-crypt': - $rounds = (int) $rcmail->config->get('password_crypt_rounds'); - $prefix = '$6$'; + case 'md5crypt': // for BC + case 'md5-crypt': + $crypted = crypt($password, '$1$' . rcube_utils::random_bytes(9)); + $prefix = '{MD5-CRYPT}'; + break; - if ($rounds > 1000) { - $prefix .= 'rounds=' . $rounds . '$'; - } + case 'sha256-crypt': + $rounds = (int) $rcmail->config->get('password_crypt_rounds'); + $prefix = '$5$'; - $crypted = crypt($password, $prefix . rcube_utils::random_bytes(16)); - $prefix = '{SHA512-CRYPT}'; - break; + if ($rounds > 1000) { + $prefix .= 'rounds=' . $rounds . '$'; + } - case 'blowfish': // for BC - case 'blowfish-crypt': - $cost = (int) ($options['cost'] ?? $rcmail->config->get('password_blowfish_cost')); - $cost = $cost < 4 || $cost > 31 ? 12 : $cost; - $prefix = sprintf('$2y$%02d$', $cost); + $crypted = crypt($password, $prefix . rcube_utils::random_bytes(16)); + $prefix = '{SHA256-CRYPT}'; + break; - $crypted = crypt($password, $prefix . rcube_utils::random_bytes(22)); - $prefix = '{BLF-CRYPT}'; - break; + case 'sha512-crypt': + $rounds = (int) $rcmail->config->get('password_crypt_rounds'); + $prefix = '$6$'; - case 'md5': - $crypted = base64_encode(pack('H*', md5($password))); - $prefix = '{MD5}'; - break; + if ($rounds > 1000) { + $prefix .= 'rounds=' . $rounds . '$'; + } - case 'sha': - if (function_exists('sha1')) { - $crypted = pack('H*', sha1($password)); - } - else if (function_exists('hash')) { - $crypted = hash('sha1', $password, true); - } - else { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Your PHP installation does not have the hash() nor sha1() function" - ], true, true - ); - } + $crypted = crypt($password, $prefix . rcube_utils::random_bytes(16)); + $prefix = '{SHA512-CRYPT}'; + break; - $crypted = base64_encode($crypted); - $prefix = '{SHA}'; - break; + case 'blowfish': // for BC + case 'blowfish-crypt': + $cost = (int) ($options['cost'] ?? $rcmail->config->get('password_blowfish_cost')); + $cost = $cost < 4 || $cost > 31 ? 12 : $cost; + $prefix = sprintf('$2y$%02d$', $cost); - case 'ssha': - $salt = rcube_utils::random_bytes(8); + $crypted = crypt($password, $prefix . rcube_utils::random_bytes(22)); + $prefix = '{BLF-CRYPT}'; + break; - if (function_exists('sha1')) { - $salt = substr(pack("H*", sha1($salt . $password)), 0, 4); - $crypted = sha1($password . $salt, true); - } - else if (function_exists('hash')) { - $salt = substr(pack("H*", hash('sha1', $salt . $password)), 0, 4); - $crypted = hash('sha1', $password . $salt, true); - } - else { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Your PHP installation does not have the hash() nor sha1() function" - ], true, true - ); - } + case 'md5': + $crypted = base64_encode(pack('H*', md5($password))); + $prefix = '{MD5}'; + break; - $crypted = base64_encode($crypted . $salt); - $prefix = '{SSHA}'; - break; + case 'sha': + if (function_exists('sha1')) { + $crypted = pack('H*', sha1($password)); + } + else if (function_exists('hash')) { + $crypted = hash('sha1', $password, true); + } + else { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Your PHP installation does not have the hash() nor sha1() function" + ], true, true + ); + } - // base64 encoded ssha256 for mailcow - case 'ssha256': - $salt = rcube_utils::random_bytes(8); + $crypted = base64_encode($crypted); + $prefix = '{SHA}'; + break; - if (function_exists('hash')) { - $salt = substr(pack("H*", hash('sha256', $salt . $password)), 0, 4); - $crypted = hash('sha256', $password . $salt, true); - } - else { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Your PHP installation does not have the hash() function" - ], true, true - ); - } + case 'ssha': + $salt = rcube_utils::random_bytes(8); - $crypted = base64_encode($crypted . $salt); - $prefix = '{SSHA256}'; - break; + if (function_exists('sha1')) { + $salt = substr(pack("H*", sha1($salt . $password)), 0, 4); + $crypted = sha1($password . $salt, true); + } + else if (function_exists('hash')) { + $salt = substr(pack("H*", hash('sha1', $salt . $password)), 0, 4); + $crypted = hash('sha1', $password . $salt, true); + } + else { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Your PHP installation does not have the hash() nor sha1() function" + ], true, true + ); + } - case 'ssha512': - $salt = rcube_utils::random_bytes(8); + $crypted = base64_encode($crypted . $salt); + $prefix = '{SSHA}'; + break; - if (function_exists('hash')) { - $salt = substr(pack("H*", hash('sha512', $salt . $password)), 0, 4); - $crypted = hash('sha512', $password . $salt, true); - } - else { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Your PHP installation does not have the hash() function" - ], true, true - ); - } + // base64 encoded ssha256 for mailcow (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'ssha256': + $salt = rcube_utils::random_bytes(8); - $crypted = base64_encode($crypted . $salt); - $prefix = '{SSHA512}'; - break; + if (function_exists('hash')) { + $salt = substr(pack("H*", hash('sha256', $salt . $password)), 0, 4); + $crypted = hash('sha256', $password . $salt, true); + } + else { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Your PHP installation does not have the hash() function" + ], true, true + ); + } - case 'smd5': - $salt = rcube_utils::random_bytes(8); + $crypted = base64_encode($crypted . $salt); + $prefix = '{SSHA256}'; + break; - if (function_exists('hash')) { - $salt = substr(pack("H*", hash('md5', $salt . $password)), 0, 4); - $crypted = hash('md5', $password . $salt, true); - } - else { - $salt = substr(pack("H*", md5($salt . $password)), 0, 4); - $crypted = md5($password . $salt, true); - } + case 'ssha512': + $salt = rcube_utils::random_bytes(8); - $crypted = base64_encode($crypted . $salt); - $prefix = '{SMD5}'; - break; + if (function_exists('hash')) { + $salt = substr(pack("H*", hash('sha512', $salt . $password)), 0, 4); + $crypted = hash('sha512', $password . $salt, true); + } + else { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Your PHP installation does not have the hash() function" + ], true, true + ); + } - case 'samba': - if (function_exists('hash')) { - $crypted = hash('md4', rcube_charset::convert($password, RCUBE_CHARSET, 'UTF-16LE')); - $crypted = strtoupper($crypted); - } - else { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Your PHP installation does not have hash() function" - ], true, true - ); - } - break; + $crypted = base64_encode($crypted . $salt); + $prefix = '{SSHA512}'; + break; - case 'ad': - $crypted = rcube_charset::convert('"' . $password . '"', RCUBE_CHARSET, 'UTF-16LE'); - break; + case 'smd5': + $salt = rcube_utils::random_bytes(8); - case 'dovecot': - if (!($dovecotpw = $rcmail->config->get('password_dovecotpw'))) { - $dovecotpw = 'dovecotpw'; - } - if (!($method = $rcmail->config->get('password_dovecotpw_method'))) { - $method = 'CRAM-MD5'; - } + if (function_exists('hash')) { + $salt = substr(pack("H*", hash('md5', $salt . $password)), 0, 4); + $crypted = hash('md5', $password . $salt, true); + } + else { + $salt = substr(pack("H*", md5($salt . $password)), 0, 4); + $crypted = md5($password . $salt, true); + } - $command = "$dovecotpw -s '$method'"; + $crypted = base64_encode($crypted . $salt); + $prefix = '{SMD5}'; + break; - $spec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; - $pipe = proc_open($command, $spec, $pipes); + case 'samba': + if (function_exists('hash')) { + $crypted = hash('md4', rcube_charset::convert($password, RCUBE_CHARSET, 'UTF-16LE')); + $crypted = strtoupper($crypted); + } + else { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Your PHP installation does not have hash() function" + ], true, true + ); + } + break; - if (!$pipe) { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Failed to execute command: $command" - ], true, false); - return false; - } + case 'ad': + $crypted = rcube_charset::convert('"' . $password . '"', RCUBE_CHARSET, 'UTF-16LE'); + break; - fwrite($pipes[0], $password . "\n", 1+strlen($password)); - usleep(1000); - fwrite($pipes[0], $password . "\n", 1+strlen($password)); + case 'dovecot': + if (!($dovecotpw = $rcmail->config->get('password_dovecotpw'))) { + $dovecotpw = 'dovecotpw'; + } + if (!($method = $rcmail->config->get('password_dovecotpw_method'))) { + $method = 'CRAM-MD5'; + } - $crypted = trim(stream_get_contents($pipes[1]), "\n"); - $stderr = trim(stream_get_contents($pipes[2])); + $command = "$dovecotpw -s '$method'"; - fclose($pipes[0]); - fclose($pipes[1]); - fclose($pipes[2]); - proc_close($pipe); + $spec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; + $pipe = proc_open($command, $spec, $pipes); - if (!preg_match('/^\{' . $method . '\}/', $crypted)) { - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Failed to execute command: $command. Error: $stderr" - ], true, false); + if (!$pipe) { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Failed to execute command: $command" + ], true, false); + return false; + } - return false; - } + fwrite($pipes[0], $password . "\n", 1+strlen($password)); + usleep(1000); + fwrite($pipes[0], $password . "\n", 1+strlen($password)); - if (!$prefixed) { - $prefixed = (bool) $rcmail->config->get('password_dovecotpw_with_method'); - } + $crypted = trim(stream_get_contents($pipes[1]), "\n"); + $stderr = trim(stream_get_contents($pipes[2])); - if (!$prefixed) { - $crypted = trim(str_replace('{' . $method . '}', '', $crypted)); - } + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + proc_close($pipe); - $prefixed = false; + if (!preg_match('/^\{' . $method . '\}/', $crypted)) { + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Failed to execute command: $command. Error: $stderr" + ], true, false); - break; + return false; + } - case 'hash-bcrypt': - $crypted = password_hash($password, PASSWORD_BCRYPT, $options); - $prefix = '{BLF-CRYPT}'; - break; + if (!$prefixed) { + $prefixed = (bool) $rcmail->config->get('password_dovecotpw_with_method'); + } - case 'hash-argon2i': - $crypted = password_hash($password, PASSWORD_ARGON2I, $options); - $prefix = '{ARGON2I}'; - break; + if (!$prefixed) { + $crypted = trim(str_replace('{' . $method . '}', '', $crypted)); + } - case 'hash-argon2id': - $crypted = password_hash($password, PASSWORD_ARGON2ID, $options); - $prefix = '{ARGON2ID}'; - break; + $prefixed = false; - case 'clear': - $crypted = $password; - break; + break; - default: - rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: Hash method not supported." - ], true, true - ); + case 'hash-bcrypt': + $crypted = password_hash($password, PASSWORD_BCRYPT, $options); + $prefix = '{BLF-CRYPT}'; + break; + + case 'hash-argon2i': + $crypted = password_hash($password, PASSWORD_ARGON2I, $options); + $prefix = '{ARGON2I}'; + break; + + case 'hash-argon2id': + $crypted = password_hash($password, PASSWORD_ARGON2ID, $options); + $prefix = '{ARGON2ID}'; + break; + + case 'clear': + $crypted = $password; + break; + + default: + rcube::raise_error([ + 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: Hash method not supported." + ], true, true + ); } if ($crypted === null || $crypted === false) { diff --git a/plugins/reconnect/reconnect.php b/plugins/reconnect/reconnect.php index 11050dd222a..7a5a9154804 100644 --- a/plugins/reconnect/reconnect.php +++ b/plugins/reconnect/reconnect.php @@ -38,11 +38,11 @@ function storage_connect($args) $storage = rcmail::get_instance()->get_storage(); switch ($storage->get_error_code()) { - case rcube_imap_generic::ERROR_NO: - case rcube_imap_generic::ERROR_BAD: - case rcube_imap_generic::ERROR_BYE: - $args['retry'] = false; - break; + case rcube_imap_generic::ERROR_NO: + case rcube_imap_generic::ERROR_BAD: + case rcube_imap_generic::ERROR_BYE: + $args['retry'] = false; + break; } if ($args['retry']) { diff --git a/plugins/redundant_attachments/redundant_attachments.php b/plugins/redundant_attachments/redundant_attachments.php index ede540aad49..a196f91bda6 100644 --- a/plugins/redundant_attachments/redundant_attachments.php +++ b/plugins/redundant_attachments/redundant_attachments.php @@ -1,6 +1,6 @@ assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php index 8dca2be9e7a..d5834fab11e 100644 --- a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php +++ b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php @@ -169,7 +169,7 @@ private function read_squirrel_prefs($uname) { $rcmail = rcmail::get_instance(); - /**** File based backend ****/ + /* File based backend */ if ($rcmail->config->get('squirrelmail_driver') == 'file' && ($srcdir = $rcmail->config->get('squirrelmail_data_dir'))) { if (($hash_level = $rcmail->config->get('squirrelmail_data_dir_hash_level')) > 0) { $srcdir = slashify($srcdir).chunk_split(substr(base_convert(crc32($uname), 10, 16), 0, $hash_level), 1, '/'); @@ -246,7 +246,7 @@ private function read_squirrel_prefs($uname) $sql_result = $db->query('SELECT * FROM ' . $db->quote_identifier($userprefs_table) .' WHERE `user` = ?', $uname); // ? is replaced with emailaddress - while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result + while ($sql_array = $db->fetch_assoc($sql_result)) { // fetch one row from result $this->prefs[$sql_array['prefkey']] = rcube_charset::convert(rtrim($sql_array['prefval']), $db_charset); } @@ -255,7 +255,7 @@ private function read_squirrel_prefs($uname) .' WHERE `owner` = ?', $uname); // ? is replaced with emailaddress // parse address book - while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result + while ($sql_array = $db->fetch_assoc($sql_result)) { // fetch one row from result $rec['name'] = rcube_charset::convert(rtrim($sql_array['nickname']), $db_charset); $rec['firstname'] = rcube_charset::convert(rtrim($sql_array['firstname']), $db_charset); $rec['surname'] = rcube_charset::convert(rtrim($sql_array['lastname']), $db_charset); diff --git a/plugins/subscriptions_option/subscriptions_option.php b/plugins/subscriptions_option/subscriptions_option.php index 444d3cdd656..b3fb9f076df 100644 --- a/plugins/subscriptions_option/subscriptions_option.php +++ b/plugins/subscriptions_option/subscriptions_option.php @@ -102,7 +102,7 @@ function mailboxes_list($args) $storage = $rcmail->get_storage(); if ($folders = $storage->list_folders_direct($args['root'], $args['name'])) { - $folders = array_filter($folders, function($folder) use ($storage) { + $folders = array_filter($folders, function ($folder) use ($storage) { $attrs = $storage->folder_attributes($folder); return !in_array_nocase('\\Noselect', $attrs); }); diff --git a/plugins/userinfo/tests/Userinfo.php b/plugins/userinfo/tests/Userinfo.php index 49d02019db5..bc39fa7f765 100644 --- a/plugins/userinfo/tests/Userinfo.php +++ b/plugins/userinfo/tests/Userinfo.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/vcard_attachments/vcard_attachments.php b/plugins/vcard_attachments/vcard_attachments.php index 5443f3765ea..1ba50f3cbb1 100644 --- a/plugins/vcard_attachments/vcard_attachments.php +++ b/plugins/vcard_attachments/vcard_attachments.php @@ -296,10 +296,10 @@ private static function is_vcard($part) $part->mimetype == 'text/x-vcard' || // Content-Type: text/directory; profile=vCard; ($part->mimetype == 'text/directory' && ( - (!empty($part->ctype_parameters['profile']) && strtolower($part->ctype_parameters['profile']) == 'vcard') + (!empty($part->ctype_parameters['profile']) && strtolower($part->ctype_parameters['profile']) == 'vcard') // Content-Type: text/directory; (with filename=*.vcf) - || (!empty($part->filename) && preg_match('/\.vcf$/i', $part->filename)) - ) + || (!empty($part->filename) && preg_match('/\.vcf$/i', $part->filename)) + ) ) ); } diff --git a/plugins/virtuser_file/tests/VirtuserFile.php b/plugins/virtuser_file/tests/VirtuserFile.php index 7d575a5f7c1..1ed763ebb04 100644 --- a/plugins/virtuser_file/tests/VirtuserFile.php +++ b/plugins/virtuser_file/tests/VirtuserFile.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/virtuser_query/tests/VirtuserQuery.php b/plugins/virtuser_query/tests/VirtuserQuery.php index d8ccb7b4187..2a36d8eb309 100644 --- a/plugins/virtuser_query/tests/VirtuserQuery.php +++ b/plugins/virtuser_query/tests/VirtuserQuery.php @@ -19,4 +19,3 @@ function test_constructor() $this->assertInstanceOf('rcube_plugin', $plugin); } } - diff --git a/plugins/virtuser_query/virtuser_query.php b/plugins/virtuser_query/virtuser_query.php index 11698c34aba..3812c33d846 100644 --- a/plugins/virtuser_query/virtuser_query.php +++ b/plugins/virtuser_query/virtuser_query.php @@ -151,7 +151,7 @@ function get_dbh() if ($dsn = $this->app->config->get('virtuser_query_dsn')) { // connect to the virtuser database $this->db = rcube_db::factory($dsn); - $this->db->set_debug((bool)$this->app->config->get('sql_debug')); + $this->db->set_debug((bool) $this->app->config->get('sql_debug')); $this->db->db_connect('r'); // connect in read mode } else { diff --git a/plugins/zipdownload/config.inc.php.dist b/plugins/zipdownload/config.inc.php.dist index 019cc8de531..3b41bbc9a3c 100644 --- a/plugins/zipdownload/config.inc.php.dist +++ b/plugins/zipdownload/config.inc.php.dist @@ -1,6 +1,6 @@ click('.header-links a.zipdownload'); }); - $filename = 'Lines.zip'; - $files = $this->getFilesFromZip($filename); - $browser->removeDownloadedFile($filename); - $expected = ['lines.txt', 'lines_lf.txt']; - $this->assertSame($expected, $files); + $filename = 'Lines.zip'; + $files = $this->getFilesFromZip($filename); + $browser->removeDownloadedFile($filename); + $expected = ['lines.txt', 'lines_lf.txt']; + $this->assertSame($expected, $files); }); } diff --git a/program/actions/contacts/copy.php b/program/actions/contacts/copy.php index c04d1f2ab27..93d506bac06 100644 --- a/program/actions/contacts/copy.php +++ b/program/actions/contacts/copy.php @@ -1,6 +1,6 @@ output->command($prefix . 'add_contact_row', $row['ID'], $a_row_cols, join(' ', $classes), - array_intersect_key($row, ['ID' => 1,'readonly' => 1, '_type' => 1, 'email' => 1,'name' => 1]) + array_intersect_key($row, ['ID' => 1, 'readonly' => 1, '_type' => 1, 'email' => 1, 'name' => 1]) ); } } @@ -787,7 +787,7 @@ public static function contact_form($form, $record, $attrib = null) // group fields $head_fields = [ 'source' => ['source'], - 'names' => ['prefix','firstname','middlename','surname','suffix'], + 'names' => ['prefix', 'firstname', 'middlename', 'surname', 'suffix'], 'displayname' => ['name'], 'nickname' => ['nickname'], 'organization' => ['organization'], @@ -832,7 +832,7 @@ public static function contact_form($form, $record, $attrib = null) if (!empty($prop['subtypes'])) { // re-order subtypes, so 'work' is before 'home' if ($business_mode) { - $work_opts = array_filter($prop['subtypes'], function($var) { return strpos($var, 'work') !== false; }); + $work_opts = array_filter($prop['subtypes'], function ($var) { return strpos($var, 'work') !== false; }); if (!empty($work_opts)) { $coltypes[$col]['subtypes'] = $prop['subtypes'] = array_merge( $work_opts, diff --git a/program/actions/contacts/list.php b/program/actions/contacts/list.php index 0a65f4605f9..99bf1082217 100644 --- a/program/actions/contacts/list.php +++ b/program/actions/contacts/list.php @@ -1,6 +1,6 @@ group_id)) { $group_data = ['ID' => $contacts->group_id] - + array_intersect_key((array) $contacts->get_group($contacts->group_id), ['name' => 1,'email' => 1]); + + array_intersect_key((array) $contacts->get_group($contacts->group_id), ['name' => 1, 'email' => 1]); } } diff --git a/program/actions/contacts/mailto.php b/program/actions/contacts/mailto.php index 7be89c66fe8..167ab075de3 100644 --- a/program/actions/contacts/mailto.php +++ b/program/actions/contacts/mailto.php @@ -1,6 +1,6 @@ 1,'email' => 1,'name' => 1]); + $record = array_intersect_key($record, ['ID' => 1, 'email' => 1, 'name' => 1]); $record['_type'] = 'person'; // update the changed col in list diff --git a/program/actions/contacts/search.php b/program/actions/contacts/search.php index 70ff418ba9d..636a8490909 100644 --- a/program/actions/contacts/search.php +++ b/program/actions/contacts/search.php @@ -1,6 +1,6 @@ rcmail_sendmail::MODE_FORWARD], [ 'sendmail' => true, - 'error_handler' => function(...$args) use ($rcmail) { + 'error_handler' => function (...$args) use ($rcmail) { call_user_func_array([$rcmail->output, 'show_message'], $args); $rcmail->output->send('iframe'); } diff --git a/program/actions/mail/check_recent.php b/program/actions/mail/check_recent.php index 3b3609f356a..2c725d8e3da 100644 --- a/program/actions/mail/check_recent.php +++ b/program/actions/mail/check_recent.php @@ -1,6 +1,6 @@ get_parameters('MAILBOX')) + && in_array($mbox_name, (array) $_SESSION['search'][1]->get_parameters('MAILBOX')) ); if ($is_current) { diff --git a/program/actions/mail/compose.php b/program/actions/mail/compose.php index eee09db10d2..ecca2cfe0b9 100644 --- a/program/actions/mail/compose.php +++ b/program/actions/mail/compose.php @@ -1,6 +1,6 @@ session->reload(); if ($_SESSION['compose_data_' . self::$COMPOSE_ID]) { - self::$COMPOSE =& $_SESSION['compose_data_' . self::$COMPOSE_ID]; + self::$COMPOSE =&$_SESSION['compose_data_' . self::$COMPOSE_ID]; } } @@ -78,7 +78,7 @@ public function run($args = []) ? $params['mbox'] : $rcmail->storage->get_folder(), ]; - self::$COMPOSE =& $_SESSION['compose_data_' . self::$COMPOSE_ID]; + self::$COMPOSE =&$_SESSION['compose_data_' . self::$COMPOSE_ID]; self::process_compose_params(self::$COMPOSE); // check if folder for saving sent messages exists and is subscribed (#1486802) diff --git a/program/actions/mail/copy.php b/program/actions/mail/copy.php index b4dd5a7198e..5fec9a737d8 100644 --- a/program/actions/mail/copy.php +++ b/program/actions/mail/copy.php @@ -1,6 +1,6 @@ gettext('loadingdata'); header('Content-Type: text/html; charset=' . RCUBE_CHARSET); - print "\n\n" + echo "\n\n" . '' . "\n" . '' . "\n" . "\n\n$message\n\n"; @@ -135,7 +135,7 @@ public function run($args = []) $file_extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); // 1. compare filename suffix with expected suffix derived from mimetype - $valid = $file_extension && in_array($file_extension, (array)$extensions) + $valid = $file_extension && in_array($file_extension, (array) $extensions) || empty($extensions) || !empty($_REQUEST['_mimeclass']); @@ -163,7 +163,7 @@ public function run($args = []) else { // get valid file extensions $extensions = rcube_mime::get_mime_extensions($real_mimetype); - $valid_extension = !$file_extension || empty($extensions) || in_array($file_extension, (array)$extensions); + $valid_extension = !$file_extension || empty($extensions) || in_array($file_extension, (array) $extensions); } if ( diff --git a/program/actions/mail/getunread.php b/program/actions/mail/getunread.php index 1272797ddd1..853d21334c3 100644 --- a/program/actions/mail/getunread.php +++ b/program/actions/mail/getunread.php @@ -1,6 +1,6 @@ gettext('flagged')); - break; - case 'attachment': - case 'priority': - $col_name = html::span($col, $rcmail->gettext($col)); - break; - case 'status': - $col_name = html::span($col, $rcmail->gettext('readstatus')); - break; - case 'threads': - $col_name = !empty($list_menu) ? $list_menu : ''; - break; - case 'fromto': - $label = $rcmail->gettext($smart_col); - $col_name = rcube::Q($label); - break; - default: - $label = $rcmail->gettext($col); - $col_name = rcube::Q($label); + case 'flag': + $col_name = html::span('flagged', $rcmail->gettext('flagged')); + break; + case 'attachment': + case 'priority': + $col_name = html::span($col, $rcmail->gettext($col)); + break; + case 'status': + $col_name = html::span($col, $rcmail->gettext('readstatus')); + break; + case 'threads': + $col_name = !empty($list_menu) ? $list_menu : ''; + break; + case 'fromto': + $label = $rcmail->gettext($smart_col); + $col_name = rcube::Q($label); + break; + default: + $label = $rcmail->gettext($col); + $col_name = rcube::Q($label); } // make sort links @@ -883,26 +883,26 @@ public static function check_safe($message) && $message->has_html_part() ) { switch ($show_images) { - case 3: // trusted senders only - case 1: // all my contacts - if (!empty($message->sender['mailto'])) { - $type = rcube_addressbook::TYPE_TRUSTED_SENDER; + case 3: // trusted senders only + case 1: // all my contacts + if (!empty($message->sender['mailto'])) { + $type = rcube_addressbook::TYPE_TRUSTED_SENDER; - if ($show_images == 1) { - $type |= rcube_addressbook::TYPE_RECIPIENT | rcube_addressbook::TYPE_WRITEABLE; - } + if ($show_images == 1) { + $type |= rcube_addressbook::TYPE_RECIPIENT | rcube_addressbook::TYPE_WRITEABLE; + } - if ($rcmail->contact_exists($message->sender['mailto'], $type)) { - $message->set_safe(true); + if ($rcmail->contact_exists($message->sender['mailto'], $type)) { + $message->set_safe(true); + } } - } - $rcmail->plugins->exec_hook('message_check_safe', ['message' => $message]); - break; + $rcmail->plugins->exec_hook('message_check_safe', ['message' => $message]); + break; - case 2: // always - $message->set_safe(true); - break; + case 2: // always + $message->set_safe(true); + break; } } @@ -957,10 +957,10 @@ public static function wash_html($html, $p, $cid_replaces = []) ]; if (empty($p['inline_html'])) { - $wash_opts['html_elements'] = ['html','head','title','body','link']; + $wash_opts['html_elements'] = ['html', 'head', 'title', 'body', 'link']; } if (!empty($p['safe'])) { - $wash_opts['html_attribs'] = ['rel','type']; + $wash_opts['html_attribs'] = ['rel', 'type']; } // overwrite washer options with options from plugins @@ -1103,30 +1103,30 @@ public static function washtml_callback($tagname, $attrib, $content, $washtml) $out = ''; switch ($tagname) { - case 'form': - $out = html::div('form', $content); - break; - - case 'style': - // Crazy big styles may freeze the browser (#1490539) - // remove content with more than 5k lines - if (substr_count($content, "\n") > 5000) { + case 'form': + $out = html::div('form', $content); break; - } - - // decode all escaped entities and reduce to ascii strings - $decoded = rcube_utils::xss_entity_decode($content); - $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', $decoded); - // now check for evil strings like expression, behavior or url() - if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) { - if (!$washtml->get_config('allow_remote') && preg_match('/url\((?!data:image)/', $stripped)) { - $washtml->extlinks = true; + case 'style': + // Crazy big styles may freeze the browser (#1490539) + // remove content with more than 5k lines + if (substr_count($content, "\n") > 5000) { + break; } - else { - $out = html::tag('style', ['type' => 'text/css'], $decoded); + + // decode all escaped entities and reduce to ascii strings + $decoded = rcube_utils::xss_entity_decode($content); + $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', $decoded); + + // now check for evil strings like expression, behavior or url() + if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) { + if (!$washtml->get_config('allow_remote') && preg_match('/url\((?!data:image)/', $stripped)) { + $washtml->extlinks = true; + } + else { + $out = html::tag('style', ['type' => 'text/css'], $decoded); + } } - } } return $out; @@ -1371,8 +1371,8 @@ public static function washtml_link_callback($tag, $attribs, $content, $washtml) } // allowed attributes for a|link|area tags - $allow = ['href','name','target','onclick','id','class','style','title', - 'rel','type','media','alt','coords','nohref','hreflang','shape']; + $allow = ['href', 'name', 'target', 'onclick', 'id', 'class', 'style', 'title', + 'rel', 'type', 'media', 'alt', 'coords', 'nohref', 'hreflang', 'shape']; return html::tag($tag, $attrib, $content, $allow); } diff --git a/program/actions/mail/list.php b/program/actions/mail/list.php index 81374f1c41b..44cf88e557e 100644 --- a/program/actions/mail/list.php +++ b/program/actions/mail/list.php @@ -1,6 +1,6 @@ $group['ID'], 'name' => $group['name'], 'virtual' => true] ); diff --git a/program/actions/mail/mark.php b/program/actions/mail/mark.php index 9029eb5a889..df33bba5217 100644 --- a/program/actions/mail/mark.php +++ b/program/actions/mail/mark.php @@ -1,6 +1,6 @@ 'UNSEEN', - 'read' => 'SEEN', - 'unseen' => 'UNSEEN', - 'seen' => 'SEEN', - 'flagged' => 'FLAGGED', - 'unflagged' => 'UNFLAGGED', - 'deleted' => 'DELETED', - 'undeleted' => 'UNDELETED', - 'answered' => 'ANSWERED', - 'unanswered' => 'UNANSWERED', - ]; - - $value = strtolower($value); - if (isset($map[$value])) { - return $map[$value]; - } + break; + + case 'is': + $map = [ + 'unread' => 'UNSEEN', + 'read' => 'SEEN', + 'unseen' => 'UNSEEN', + 'seen' => 'SEEN', + 'flagged' => 'FLAGGED', + 'unflagged' => 'UNFLAGGED', + 'deleted' => 'DELETED', + 'undeleted' => 'UNDELETED', + 'answered' => 'ANSWERED', + 'unanswered' => 'UNANSWERED', + ]; + + $value = strtolower($value); + if (isset($map[$value])) { + return $map[$value]; + } - break; + break; - case 'has': - if ($value == 'attachment') { - // Content-Type values of messages with attachments - // the same as in app.js:add_message_row() - $ctypes = ['application/', 'multipart/m', 'multipart/signed', 'multipart/report']; + case 'has': + if ($value == 'attachment') { + // Content-Type values of messages with attachments + // the same as in app.js:add_message_row() + $ctypes = ['application/', 'multipart/m', 'multipart/signed', 'multipart/report']; - // Build search string of "with attachment" filter - $result = str_repeat(' OR', count($ctypes) - 1); - foreach ($ctypes as $type) { - $result .= ' HEADER Content-Type ' . rcube_imap_generic::escape($type); + // Build search string of "with attachment" filter + $result = str_repeat(' OR', count($ctypes) - 1); + foreach ($ctypes as $type) { + $result .= ' HEADER Content-Type ' . rcube_imap_generic::escape($type); + } + + return trim($result); } - return trim($result); - } + break; + + case 'older_than': // GMail alias + $option = 'before'; + case 'newer_than': // GMail alias + $option = 'since'; + case 'since': + case 'before': + if (preg_match('/^[0-9]+[WMY]$/i', $value)) { + if ($option == 'before') { + $value = "-{$value}"; + } - break; - - case 'older_than': // GMail alias - $option = 'before'; - case 'newer_than': // GMail alias - $option = 'since'; - case 'since': - case 'before': - if (preg_match('/^[0-9]+[WMY]$/i', $value)) { - if ($option == 'before') { - $value = "-{$value}"; + if ($search_interval = self::search_interval_criteria(strtoupper($value))) { + return $search_interval; + } } - - if ($search_interval = self::search_interval_criteria(strtoupper($value))) { - return $search_interval; + else if (preg_match('|^([0-9]{4})[-/]([0-9]{1,2})[-/]([0-9]{1,2})$|i', $value, $m)) { + $dt = new DateTime(sprintf('%04d-%02d-%02d', $m[1], $m[2], $m[3]) . 'T00:00:00Z'); + return strtoupper($option) . ' ' . $dt->format('j-M-Y'); } - } - else if (preg_match('|^([0-9]{4})[-/]([0-9]{1,2})[-/]([0-9]{1,2})$|i', $value, $m)) { - $dt = new DateTime(sprintf('%04d-%02d-%02d', $m[1], $m[2], $m[3]) . 'T00:00:00Z'); - return strtoupper($option) . ' ' . $dt->format('j-M-Y'); - } - break; + break; - default: - if (in_array($option, $supported)) { - $header = strtoupper($option); - return "HEADER {$header} {$escaped}"; - } + default: + if (in_array($option, $supported)) { + $header = strtoupper($option); + return "HEADER {$header} {$escaped}"; + } } return null; diff --git a/program/actions/mail/search_contacts.php b/program/actions/mail/search_contacts.php index 996213c98d9..7f5168037b6 100644 --- a/program/actions/mail/search_contacts.php +++ b/program/actions/mail/search_contacts.php @@ -1,6 +1,6 @@ output->framed = true; $COMPOSE_ID = rcube_utils::get_input_string('_id', rcube_utils::INPUT_GPC); - $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID]; + $COMPOSE =&$_SESSION['compose_data_'.$COMPOSE_ID]; // Sanity checks if (!isset($COMPOSE['id'])) { @@ -56,7 +56,7 @@ public function run($args = []) 'sendmail' => true, 'saveonly' => $saveonly, 'savedraft' => $savedraft, - 'error_handler' => function(...$args) use ($rcmail) { + 'error_handler' => function (...$args) use ($rcmail) { call_user_func_array([$rcmail->output, 'show_message'], $args); $rcmail->output->send('iframe'); }, diff --git a/program/actions/mail/sendmdn.php b/program/actions/mail/sendmdn.php index af0c72db3a3..a388e81c059 100644 --- a/program/actions/mail/sendmdn.php +++ b/program/actions/mail/sendmdn.php @@ -1,6 +1,6 @@ size)) { $li_class .= ' no-menu'; $link_attrs['onclick'] = sprintf('%s.alert_dialog(%s.get_label(\'emptyattachment\')); return false', - rcmail_output::JS_OBJECT_NAME, rcmail_output::JS_OBJECT_NAME); + rcmail_output::JS_OBJECT_NAME, rcmail_output::JS_OBJECT_NAME); $rcmail->output->add_label('emptyattachment'); } diff --git a/program/actions/mail/viewsource.php b/program/actions/mail/viewsource.php index 029128e3dec..5ccb84c33a9 100644 --- a/program/actions/mail/viewsource.php +++ b/program/actions/mail/viewsource.php @@ -1,6 +1,6 @@ output->add_handlers([ 'supportlink' => [$this, 'supportlink'], 'pluginlist' => [$this, 'plugins_list'], - 'copyright' => function() { + 'copyright' => function () { return 'Copyright © 2005-2023, The Roundcube Dev Team'; }, - 'license' => function() { + 'license' => function () { return 'This program is free software; you can redistribute it and/or modify it under the terms ' . 'of the
GNU General Public License ' . 'as published by the Free Software Foundation, either version 3 of the License, ' diff --git a/program/actions/settings/folder_create.php b/program/actions/settings/folder_create.php index f765c24e136..d851b44dae4 100644 --- a/program/actions/settings/folder_create.php +++ b/program/actions/settings/folder_create.php @@ -1,6 +1,6 @@ add($rcmail->gettext('all'), '---'); foreach (array_keys($namespace) as $type) { - foreach ((array)$namespace[$type] as $ns) { + foreach ((array) $namespace[$type] as $ns) { $root = rtrim($ns[0], $ns[1]); $label = $rcmail->gettext('namespace.' . $type); diff --git a/program/actions/settings/identities.php b/program/actions/settings/identities.php index d0b76584eb0..8c50cd49d5b 100644 --- a/program/actions/settings/identities.php +++ b/program/actions/settings/identities.php @@ -1,6 +1,6 @@ $value){ + foreach ($form['addressing']['content'] as $formfield => $value) { $form['addressing']['content'][$formfield]['disabled'] = true; $form['addressing']['content'][$formfield]['class'] = 'disabled'; } diff --git a/program/actions/settings/identity_save.php b/program/actions/settings/identity_save.php index a7756f8c6eb..d48a6f53359 100644 --- a/program/actions/settings/identity_save.php +++ b/program/actions/settings/identity_save.php @@ -1,6 +1,6 @@ 'general', 'section' => $rcmail->gettext('uisettings')]; $sections['mailbox'] = ['id' => 'mailbox', 'section' => $rcmail->gettext('mailboxview')]; - $sections['mailview'] = ['id' => 'mailview','section' => $rcmail->gettext('messagesdisplaying')]; + $sections['mailview'] = ['id' => 'mailview', 'section' => $rcmail->gettext('messagesdisplaying')]; $sections['compose'] = ['id' => 'compose', 'section' => $rcmail->gettext('messagescomposition')]; - $sections['addressbook'] = ['id' => 'addressbook','section' => $rcmail->gettext('contacts')]; + $sections['addressbook'] = ['id' => 'addressbook', 'section' => $rcmail->gettext('contacts')]; $sections['folders'] = ['id' => 'folders', 'section' => $rcmail->gettext('specialfolders')]; - $sections['server'] = ['id' => 'server', 'section' => $rcmail->gettext('serversettings')]; + $sections['server'] = ['id' => 'server', 'section' => $rcmail->gettext('serversettings')]; $sections['encryption'] = ['id' => 'encryption', 'section' => $rcmail->gettext('encryption')]; // hook + define list cols @@ -127,1390 +127,1390 @@ public static function user_prefs($current = null) switch ($sect['id']) { - // general - case 'general': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'skin' => ['name' => rcube::Q($rcmail->gettext('skin'))], - 'browser' => ['name' => rcube::Q($rcmail->gettext('browseroptions'))], - 'advanced'=> ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; + // general + case 'general': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'skin' => ['name' => rcube::Q($rcmail->gettext('skin'))], + 'browser' => ['name' => rcube::Q($rcmail->gettext('browseroptions'))], + 'advanced'=> ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], + ]; - // language selection - if (!isset($no_override['language'])) { - if (!$current) { - continue 2; - } + // language selection + if (!isset($no_override['language'])) { + if (!$current) { + continue 2; + } - $a_lang = $rcmail->list_languages(); - asort($a_lang); + $a_lang = $rcmail->list_languages(); + asort($a_lang); - $field_id = 'rcmfd_lang'; - $select = new html_select([ - 'name' => '_language', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + $field_id = 'rcmfd_lang'; + $select = new html_select([ + 'name' => '_language', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $select->add(array_values($a_lang), array_keys($a_lang)); + $select->add(array_values($a_lang), array_keys($a_lang)); - $blocks['main']['options']['language'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('language'))), - 'content' => $select->show($rcmail->user->language), - ]; - } - - // timezone selection - if (!isset($no_override['timezone'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['language'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('language'))), + 'content' => $select->show($rcmail->user->language), + ]; } - $field_id = 'rcmfd_timezone'; - $select = new html_select([ - 'name' => '_timezone', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // timezone selection + if (!isset($no_override['timezone'])) { + if (!$current) { + continue 2; + } + + $field_id = 'rcmfd_timezone'; + $select = new html_select([ + 'name' => '_timezone', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $select->add($rcmail->gettext('autodetect'), 'auto'); + $select->add($rcmail->gettext('autodetect'), 'auto'); - $zones = []; - foreach (DateTimeZone::listIdentifiers() as $i => $tzs) { - if ($data = self::timezone_standard_time_data($tzs)) { - $zones[$data['key']] = [$tzs, $data['offset']]; + $zones = []; + foreach (DateTimeZone::listIdentifiers() as $i => $tzs) { + if ($data = self::timezone_standard_time_data($tzs)) { + $zones[$data['key']] = [$tzs, $data['offset']]; + } } - } - ksort($zones); + ksort($zones); + + foreach ($zones as $zone) { + list($tzs, $offset) = $zone; + $select->add('(GMT ' . $offset . ') ' . self::timezone_label($tzs), $tzs); + } - foreach ($zones as $zone) { - list($tzs, $offset) = $zone; - $select->add('(GMT ' . $offset . ') ' . self::timezone_label($tzs), $tzs); + $blocks['main']['options']['timezone'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('timezone'))), + 'content' => $select->show((string) $config['timezone']), + ]; } - $blocks['main']['options']['timezone'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('timezone'))), - 'content' => $select->show((string)$config['timezone']), - ]; - } + // date/time formatting + if (!isset($no_override['time_format'])) { + if (!$current) { + continue 2; + } - // date/time formatting - if (!isset($no_override['time_format'])) { - if (!$current) { - continue 2; - } + $reftime = mktime(7,30,0); + $defaults = ['G:i', 'H:i', 'g:i a', 'h:i A']; + $formats = (array) $rcmail->config->get('time_formats', $defaults); + $field_id = 'rcmfd_time_format'; + $select = new html_select([ + 'name' => '_time_format', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $reftime = mktime(7,30,0); - $defaults = ['G:i', 'H:i', 'g:i a', 'h:i A']; - $formats = (array) $rcmail->config->get('time_formats', $defaults); - $field_id = 'rcmfd_time_format'; - $select = new html_select([ - 'name' => '_time_format', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + foreach ($formats as $choice) { + $select->add(date($choice, $reftime), $choice); + } - foreach ($formats as $choice) { - $select->add(date($choice, $reftime), $choice); + $blocks['main']['options']['time_format'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('timeformat'))), + 'content' => $select->show($rcmail->config->get('time_format')), + ]; } - $blocks['main']['options']['time_format'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('timeformat'))), - 'content' => $select->show($rcmail->config->get('time_format')), - ]; - } + if (!isset($no_override['date_format'])) { + if (!$current) { + continue 2; + } - if (!isset($no_override['date_format'])) { - if (!$current) { - continue 2; - } + $refdate = mktime(12,30,0,7,24); + $defaults = ['Y-m-d', 'd-m-Y', 'Y/m/d', 'm/d/Y', 'd/m/Y', 'd.m.Y', 'j.n.Y']; + $formats = (array) $rcmail->config->get('date_formats', $defaults); + $field_id = 'rcmfd_date_format'; + $select = new html_select([ + 'name' => '_date_format', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $refdate = mktime(12,30,0,7,24); - $defaults = ['Y-m-d','d-m-Y','Y/m/d','m/d/Y','d/m/Y','d.m.Y','j.n.Y']; - $formats = (array) $rcmail->config->get('date_formats', $defaults); - $field_id = 'rcmfd_date_format'; - $select = new html_select([ - 'name' => '_date_format', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + foreach ($formats as $choice) { + $select->add(date($choice, $refdate), $choice); + } - foreach ($formats as $choice) { - $select->add(date($choice, $refdate), $choice); + $blocks['main']['options']['date_format'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('dateformat'))), + 'content' => $select->show($config['date_format']), + ]; } - $blocks['main']['options']['date_format'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('dateformat'))), - 'content' => $select->show($config['date_format']), - ]; - } + // Show checkbox for toggling 'pretty dates' + if (!isset($no_override['prettydate'])) { + if (!$current) { + continue 2; + } - // Show checkbox for toggling 'pretty dates' - if (!isset($no_override['prettydate'])) { - if (!$current) { - continue 2; + $field_id = 'rcmfd_prettydate'; + $input = new html_checkbox([ + 'name' => '_pretty_date', + 'id' => $field_id, + 'value' => 1 + ]); + + $blocks['main']['options']['prettydate'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('prettydate'))), + 'content' => $input->show($config['prettydate'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_prettydate'; - $input = new html_checkbox([ - 'name' => '_pretty_date', - 'id' => $field_id, - 'value' => 1 - ]); + // "display after delete" checkbox + if (!isset($no_override['display_next'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['prettydate'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('prettydate'))), - 'content' => $input->show($config['prettydate']?1:0), - ]; - } + $field_id = 'rcmfd_displaynext'; + $input = new html_checkbox([ + 'name' => '_display_next', + 'id' => $field_id, + 'value' => 1 + ]); - // "display after delete" checkbox - if (!isset($no_override['display_next'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['display_next'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('displaynext'))), + 'content' => $input->show($config['display_next'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_displaynext'; - $input = new html_checkbox([ - 'name' => '_display_next', - 'id' => $field_id, - 'value' => 1 - ]); + if (!isset($no_override['refresh_interval'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['display_next'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('displaynext'))), - 'content' => $input->show($config['display_next']?1:0), - ]; - } + $field_id = 'rcmfd_refresh_interval'; + $select = new html_select([ + 'name' => '_refresh_interval', + 'id' => $field_id, + 'class' => 'custom-select' + ]); + + $select->add($rcmail->gettext('never'), 0); + foreach ([1, 3, 5, 10, 15, 30, 60] as $min) { + if (!$config['min_refresh_interval'] || $config['min_refresh_interval'] <= $min * 60) { + $label = $rcmail->gettext(['name' => 'everynminutes', 'vars' => ['n' => $min]]); + $select->add($label, $min); + } + } - if (!isset($no_override['refresh_interval'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['refresh_interval'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('refreshinterval'))), + 'content' => $select->show($config['refresh_interval']/60), + ]; } - $field_id = 'rcmfd_refresh_interval'; - $select = new html_select([ - 'name' => '_refresh_interval', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // show drop-down for available skins + if (!isset($no_override['skin'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('never'), 0); - foreach ([1, 3, 5, 10, 15, 30, 60] as $min) { - if (!$config['min_refresh_interval'] || $config['min_refresh_interval'] <= $min * 60) { - $label = $rcmail->gettext(['name' => 'everynminutes', 'vars' => ['n' => $min]]); - $select->add($label, $min); + $skins = self::get_skins(); + + if (count($skins) > 1) { + sort($skins); + + $field_id = 'rcmfd_skin'; + $input = new html_radiobutton(['name' => '_skin']); + + foreach ($skins as $skin) { + $skinname = ucfirst($skin); + $author_link = ''; + $license_link = ''; + $meta = @json_decode(@file_get_contents(INSTALL_PATH . "skins/$skin/meta.json"), true); + + if (is_array($meta) && !empty($meta['name'])) { + $skinname = $meta['name']; + $author_link = !empty($meta['url']) ? html::a(['href' => $meta['url'], 'target' => '_blank'], rcube::Q($meta['author'])) : rcube::Q($meta['author']); + $license_link = !empty($meta['license-url']) ? html::a(['href' => $meta['license-url'], 'target' => '_blank', 'tabindex' => '-1'], rcube::Q($meta['license'])) : rcube::Q($meta['license']); + } + + $img = html::img([ + 'src' => $rcmail->output->asset_url("skins/$skin/thumbnail.png"), + 'class' => 'skinthumbnail', + 'alt' => $skin, + 'width' => 64, + 'height' => 64, + 'onerror' => "this.onerror = null; this.src = 'data:image/gif;base64," . rcmail_output::BLANK_GIF ."';", + ]); + + $blocks['skin']['options'][$skin]['content'] = html::label(['class' => 'skinselection'], + html::span('skinitem', $input->show($config['skin'], ['value' => $skin, 'id' => $field_id.$skin])) . + html::span('skinitem', $img) . + html::span('skinitem', html::span('skinname', rcube::Q($skinname)) . html::br() . + html::span('skinauthor', $author_link ? 'by ' . $author_link : '') . html::br() . + html::span('skinlicense', $license_link ? $rcmail->gettext('license').': ' . $license_link : '')) + ); + } } } - $blocks['main']['options']['refresh_interval'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('refreshinterval'))), - 'content' => $select->show($config['refresh_interval']/60), - ]; - } + // standard_windows option decides if new windows should be + // opened as popups or standard windows (which can be handled by browsers as tabs) + if (!isset($no_override['standard_windows'])) { + if (!$current) { + continue 2; + } - // show drop-down for available skins - if (!isset($no_override['skin'])) { - if (!$current) { - continue 2; + $field_id = 'rcmfd_standard_windows'; + $checkbox = new html_checkbox([ + 'name' => '_standard_windows', + 'id' => $field_id, + 'value' => 1 + ]); + + $blocks['browser']['options']['standard_windows'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('standardwindows'))), + 'content' => $checkbox->show($config['standard_windows'] ? 1 : 0), + ]; } - $skins = self::get_skins(); + if ($current) { + $product_name = $rcmail->config->get('product_name', 'Roundcube Webmail'); + $rcmail->output->add_script(sprintf("%s.check_protocol_handler('%s', '#mailtoprotohandler');", + rcmail_output::JS_OBJECT_NAME, rcube::JQ($product_name)), 'docready'); + } - if (count($skins) > 1) { - sort($skins); + $blocks['browser']['options']['mailtoprotohandler'] = [ + 'content' => html::a(['href' => '#', 'id' => 'mailtoprotohandler'], + rcube::Q($rcmail->gettext('mailtoprotohandler'))) . + html::span('mailtoprotohandler-status', ''), + ]; - $field_id = 'rcmfd_skin'; - $input = new html_radiobutton(['name' => '_skin']); + break; - foreach ($skins as $skin) { - $skinname = ucfirst($skin); - $author_link = ''; - $license_link = ''; - $meta = @json_decode(@file_get_contents(INSTALL_PATH . "skins/$skin/meta.json"), true); + // Mailbox view (mail screen) (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'mailbox': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'new_message' => ['name' => rcube::Q($rcmail->gettext('newmessage'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], + ]; - if (is_array($meta) && !empty($meta['name'])) { - $skinname = $meta['name']; - $author_link = !empty($meta['url']) ? html::a(['href' => $meta['url'], 'target' => '_blank'], rcube::Q($meta['author'])) : rcube::Q($meta['author']); - $license_link = !empty($meta['license-url']) ? html::a(['href' => $meta['license-url'], 'target' => '_blank', 'tabindex' => '-1'], rcube::Q($meta['license'])) : rcube::Q($meta['license']); - } + if (!isset($no_override['layout']) && count($config['supported_layouts']) > 1) { + if (!$current) { + continue 2; + } - $img = html::img([ - 'src' => $rcmail->output->asset_url("skins/$skin/thumbnail.png"), - 'class' => 'skinthumbnail', - 'alt' => $skin, - 'width' => 64, - 'height' => 64, - 'onerror' => "this.onerror = null; this.src = 'data:image/gif;base64," . rcmail_output::BLANK_GIF ."';", - ]); + $field_id = 'rcmfd_layout'; + $select = new html_select([ + 'name' => '_layout', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['skin']['options'][$skin]['content'] = html::label(['class' => 'skinselection'], - html::span('skinitem', $input->show($config['skin'], ['value' => $skin, 'id' => $field_id.$skin])) . - html::span('skinitem', $img) . - html::span('skinitem', html::span('skinname', rcube::Q($skinname)) . html::br() . - html::span('skinauthor', $author_link ? 'by ' . $author_link : '') . html::br() . - html::span('skinlicense', $license_link ? $rcmail->gettext('license').': ' . $license_link : '')) - ); + $layouts = [ + 'widescreen' => 'layoutwidescreendesc', + 'desktop' => 'layoutdesktopdesc', + 'list' => 'layoutlistdesc' + ]; + + $available_layouts = array_intersect_key($layouts, array_flip($config['supported_layouts'])); + foreach ($available_layouts as $val => $label) { + $select->add($rcmail->gettext($label), $val); } - } - } - // standard_windows option decides if new windows should be - // opened as popups or standard windows (which can be handled by browsers as tabs) - if (!isset($no_override['standard_windows'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['layout'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('layout'))), + 'content' => $select->show($config['layout'] ?: 'widescreen'), + ]; } - $field_id = 'rcmfd_standard_windows'; - $checkbox = new html_checkbox([ - 'name' => '_standard_windows', - 'id' => $field_id, - 'value' => 1 - ]); - - $blocks['browser']['options']['standard_windows'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('standardwindows'))), - 'content' => $checkbox->show($config['standard_windows']?1:0), - ]; - } + // show config parameter for auto marking the previewed message as read + if (!isset($no_override['mail_read_time'])) { + if (!$current) { + continue 2; + } - if ($current) { - $product_name = $rcmail->config->get('product_name', 'Roundcube Webmail'); - $rcmail->output->add_script(sprintf("%s.check_protocol_handler('%s', '#mailtoprotohandler');", - rcmail_output::JS_OBJECT_NAME, rcube::JQ($product_name)), 'docready'); - } + // apply default if config option is not set at all + $config['mail_read_time'] = intval($rcmail->config->get('mail_read_time')); - $blocks['browser']['options']['mailtoprotohandler'] = [ - 'content' => html::a(['href' => '#', 'id' => 'mailtoprotohandler'], - rcube::Q($rcmail->gettext('mailtoprotohandler'))) . - html::span('mailtoprotohandler-status', ''), - ]; - - break; - - // Mailbox view (mail screen) - case 'mailbox': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'new_message' => ['name' => rcube::Q($rcmail->gettext('newmessage'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; - - if (!isset($no_override['layout']) && count($config['supported_layouts']) > 1) { - if (!$current) { - continue 2; - } - - $field_id = 'rcmfd_layout'; - $select = new html_select([ - 'name' => '_layout', - 'id' => $field_id, - 'class' => 'custom-select' - ]); - - $layouts = [ - 'widescreen' => 'layoutwidescreendesc', - 'desktop' => 'layoutdesktopdesc', - 'list' => 'layoutlistdesc' - ]; + $field_id = 'rcmfd_mail_read_time'; + $select = new html_select([ + 'name' => '_mail_read_time', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $available_layouts = array_intersect_key($layouts, array_flip($config['supported_layouts'])); - foreach ($available_layouts as $val => $label) { - $select->add($rcmail->gettext($label), $val); - } + $select->add($rcmail->gettext('never'), -1); + $select->add($rcmail->gettext('immediately'), 0); - $blocks['main']['options']['layout'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('layout'))), - 'content' => $select->show($config['layout'] ?: 'widescreen'), - ]; - } + foreach ([5, 10, 20, 30] as $sec) { + $label = $rcmail->gettext(['name' => 'afternseconds', 'vars' => ['n' => $sec]]); + $select->add($label, $sec); + } - // show config parameter for auto marking the previewed message as read - if (!isset($no_override['mail_read_time'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['mail_read_time'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('automarkread'))), + 'content' => $select->show($config['mail_read_time']), + ]; } - // apply default if config option is not set at all - $config['mail_read_time'] = intval($rcmail->config->get('mail_read_time')); - - $field_id = 'rcmfd_mail_read_time'; - $select = new html_select([ - 'name' => '_mail_read_time', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + if (!isset($no_override['autoexpand_threads'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('never'), -1); - $select->add($rcmail->gettext('immediately'), 0); + $storage = $rcmail->get_storage(); + $supported = $storage->get_capability('THREAD'); - foreach ([5, 10, 20, 30] as $sec) { - $label = $rcmail->gettext(['name' => 'afternseconds', 'vars' => ['n' => $sec]]); - $select->add($label, $sec); - } + if ($supported) { + $field_id = 'rcmfd_autoexpand_threads'; + $select = new html_select([ + 'name' => '_autoexpand_threads', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['mail_read_time'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('automarkread'))), - 'content' => $select->show($config['mail_read_time']), - ]; - } + $select->add($rcmail->gettext('never'), 0); + $select->add($rcmail->gettext('do_expand'), 1); + $select->add($rcmail->gettext('expand_only_unread'), 2); - if (!isset($no_override['autoexpand_threads'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['autoexpand_threads'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autoexpand_threads'))), + 'content' => $select->show($config['autoexpand_threads']), + ]; + } } - $storage = $rcmail->get_storage(); - $supported = $storage->get_capability('THREAD'); + // show page size selection + if (!isset($no_override['mail_pagesize'])) { + if (!$current) { + continue 2; + } - if ($supported) { - $field_id = 'rcmfd_autoexpand_threads'; - $select = new html_select([ - 'name' => '_autoexpand_threads', + $size = intval($config['mail_pagesize'] ?: $config['pagesize']); + $field_id = 'rcmfd_mail_pagesize'; + $input = new html_inputfield([ + 'name' => '_mail_pagesize', 'id' => $field_id, - 'class' => 'custom-select' + 'size' => 5, + 'class' => 'form-control' ]); - $select->add($rcmail->gettext('never'), 0); - $select->add($rcmail->gettext('do_expand'), 1); - $select->add($rcmail->gettext('expand_only_unread'), 2); - - $blocks['main']['options']['autoexpand_threads'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autoexpand_threads'))), - 'content' => $select->show($config['autoexpand_threads']), + $blocks['main']['options']['pagesize'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('pagesize'))), + 'content' => $input->show($size ?: 50), ]; } - } - - // show page size selection - if (!isset($no_override['mail_pagesize'])) { - if (!$current) { - continue 2; - } - $size = intval($config['mail_pagesize'] ?: $config['pagesize']); - $field_id = 'rcmfd_mail_pagesize'; - $input = new html_inputfield([ - 'name' => '_mail_pagesize', - 'id' => $field_id, - 'size' => 5, - 'class' => 'form-control' - ]); + if (!isset($no_override['check_all_folders'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['pagesize'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('pagesize'))), - 'content' => $input->show($size ?: 50), - ]; - } + $field_id = 'rcmfd_check_all_folders'; + $input = new html_checkbox([ + 'name' => '_check_all_folders', + 'id' => $field_id, + 'value' => 1 + ]); - if (!isset($no_override['check_all_folders'])) { - if (!$current) { - continue 2; + $blocks['new_message']['options']['check_all_folders'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('checkallfolders'))), + 'content' => $input->show($config['check_all_folders'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_check_all_folders'; - $input = new html_checkbox([ - 'name' => '_check_all_folders', - 'id' => $field_id, - 'value' => 1 - ]); + break; - $blocks['new_message']['options']['check_all_folders'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('checkallfolders'))), - 'content' => $input->show($config['check_all_folders']?1:0), + // Message viewing (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'mailview': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - break; + // show checkbox to open message view in new window + if (!isset($no_override['message_extwin'])) { + if (!$current) { + continue 2; + } - // Message viewing - case 'mailview': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; + $field_id = 'rcmfd_message_extwin'; + $input = new html_checkbox(['name' => '_message_extwin', 'id' => $field_id, 'value' => 1]); - // show checkbox to open message view in new window - if (!isset($no_override['message_extwin'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['message_extwin'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showinextwin'))), + 'content' => $input->show($config['message_extwin'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_message_extwin'; - $input = new html_checkbox(['name' => '_message_extwin', 'id' => $field_id, 'value' => 1]); + // show checkbox to show email instead of name + if (!isset($no_override['message_show_email'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['message_extwin'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showinextwin'))), - 'content' => $input->show($config['message_extwin']?1:0), - ]; - } + $field_id = 'rcmfd_message_show_email'; + $input = new html_checkbox(['name' => '_message_show_email', 'id' => $field_id, 'value' => 1]); - // show checkbox to show email instead of name - if (!isset($no_override['message_show_email'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['message_show_email'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showemail'))), + 'content' => $input->show($config['message_show_email'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_message_show_email'; - $input = new html_checkbox(['name' => '_message_show_email', 'id' => $field_id, 'value' => 1]); + // show checkbox for HTML/plaintext messages + if (!isset($no_override['prefer_html'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['message_show_email'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showemail'))), - 'content' => $input->show($config['message_show_email']?1:0), - ]; - } + $field_id = 'rcmfd_htmlmsg'; + $input = new html_checkbox([ + 'name' => '_prefer_html', + 'id' => $field_id, + 'value' => 1, + 'onchange' => "$('#rcmfd_show_images').prop('disabled', !this.checked).val(0)" + ]); - // show checkbox for HTML/plaintext messages - if (!isset($no_override['prefer_html'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['prefer_html'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('preferhtml'))), + 'content' => $input->show($config['prefer_html'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_htmlmsg'; - $input = new html_checkbox([ - 'name' => '_prefer_html', - 'id' => $field_id, - 'value' => 1, - 'onchange' => "$('#rcmfd_show_images').prop('disabled', !this.checked).val(0)" - ]); + if (!isset($no_override['default_charset'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['prefer_html'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('preferhtml'))), - 'content' => $input->show($config['prefer_html']?1:0), - ]; - } + $field_id = 'rcmfd_default_charset'; - if (!isset($no_override['default_charset'])) { - if (!$current) { - continue 2; + $blocks['advanced']['options']['default_charset'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultcharset'))), + 'content' => $rcmail->output->charset_selector([ + 'id' => $field_id, + 'name' => '_default_charset', + 'selected' => $config['default_charset'], + 'class' => 'custom-select', + ]) + ]; } - $field_id = 'rcmfd_default_charset'; + if (!isset($no_override['show_images'])) { + if (!$current) { + continue 2; + } - $blocks['advanced']['options']['default_charset'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultcharset'))), - 'content' => $rcmail->output->charset_selector([ + $field_id = 'rcmfd_show_images'; + $input = new html_select([ + 'name' => '_show_images', 'id' => $field_id, - 'name' => '_default_charset', - 'selected' => $config['default_charset'], 'class' => 'custom-select', - ]) - ]; - } + 'disabled' => empty($config['prefer_html']) + ]); + + $input->add($rcmail->gettext('never'), 0); + $input->add($rcmail->gettext('frommycontacts'), 1); + $input->add($rcmail->gettext('fromtrustedsenders'), 3); + $input->add($rcmail->gettext('always'), 2); - if (!isset($no_override['show_images'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['show_images'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('allowremoteresources'))), + 'content' => $input->show(!empty($config['prefer_html']) ? $config['show_images'] : 0), + ]; } - $field_id = 'rcmfd_show_images'; - $input = new html_select([ - 'name' => '_show_images', - 'id' => $field_id, - 'class' => 'custom-select', - 'disabled' => empty($config['prefer_html']) - ]); + if (!isset($no_override['mdn_requests'])) { + if (!$current) { + continue 2; + } - $input->add($rcmail->gettext('never'), 0); - $input->add($rcmail->gettext('frommycontacts'), 1); - $input->add($rcmail->gettext('fromtrustedsenders'), 3); - $input->add($rcmail->gettext('always'), 2); + $field_id = 'rcmfd_mdn_requests'; + $select = new html_select([ + 'name' => '_mdn_requests', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['show_images'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('allowremoteresources'))), - 'content' => $input->show(!empty($config['prefer_html']) ? $config['show_images'] : 0), - ]; - } + $select->add($rcmail->gettext('askuser'), 0); + $select->add($rcmail->gettext('autosend'), 1); + $select->add($rcmail->gettext('autosendknown'), 3); + $select->add($rcmail->gettext('autosendknownignore'), 4); + $select->add($rcmail->gettext('autosendtrusted'), 5); + $select->add($rcmail->gettext('autosendtrustedignore'), 6); + $select->add($rcmail->gettext('ignorerequest'), 2); + + $blocks['main']['options']['mdn_requests'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mdnrequests'))), + 'content' => $select->show($config['mdn_requests']), + ]; + } - if (!isset($no_override['mdn_requests'])) { - if (!$current) { - continue 2; - } - - $field_id = 'rcmfd_mdn_requests'; - $select = new html_select([ - 'name' => '_mdn_requests', - 'id' => $field_id, - 'class' => 'custom-select' - ]); - - $select->add($rcmail->gettext('askuser'), 0); - $select->add($rcmail->gettext('autosend'), 1); - $select->add($rcmail->gettext('autosendknown'), 3); - $select->add($rcmail->gettext('autosendknownignore'), 4); - $select->add($rcmail->gettext('autosendtrusted'), 5); - $select->add($rcmail->gettext('autosendtrustedignore'), 6); - $select->add($rcmail->gettext('ignorerequest'), 2); - - $blocks['main']['options']['mdn_requests'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mdnrequests'))), - 'content' => $select->show($config['mdn_requests']), - ]; - } + if (!isset($no_override['inline_images'])) { + if (!$current) { + continue 2; + } + + $field_id = 'rcmfd_inline_images'; + $input = new html_checkbox(['name' => '_inline_images', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['inline_images'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['inline_images'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showinlineimages'))), + 'content' => $input->show($config['inline_images'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_inline_images'; - $input = new html_checkbox(['name' => '_inline_images', 'id' => $field_id, 'value' => 1]); + break; - $blocks['main']['options']['inline_images'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('showinlineimages'))), - 'content' => $input->show($config['inline_images']?1:0), + // Mail composition (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'compose': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'sig' => ['name' => rcube::Q($rcmail->gettext('signatureoptions'))], + 'spellcheck' => ['name' => rcube::Q($rcmail->gettext('spellcheckoptions'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - break; + // show checkbox to compose messages in a new window + if (!isset($no_override['compose_extwin'])) { + if (!$current) { + continue 2; + } - // Mail composition - case 'compose': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'sig' => ['name' => rcube::Q($rcmail->gettext('signatureoptions'))], - 'spellcheck' => ['name' => rcube::Q($rcmail->gettext('spellcheckoptions'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; + $field_id = 'rcmfdcompose_extwin'; + $input = new html_checkbox(['name' => '_compose_extwin', 'id' => $field_id, 'value' => 1]); - // show checkbox to compose messages in a new window - if (!isset($no_override['compose_extwin'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['compose_extwin'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('composeextwin'))), + 'content' => $input->show($config['compose_extwin'] ? 1 : 0), + ]; } - $field_id = 'rcmfdcompose_extwin'; - $input = new html_checkbox(['name' => '_compose_extwin', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['htmleditor'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['compose_extwin'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('composeextwin'))), - 'content' => $input->show($config['compose_extwin']?1:0), - ]; - } + $field_id = 'rcmfd_htmleditor'; + $select = new html_select([ + 'name' => '_htmleditor', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - if (!isset($no_override['htmleditor'])) { - if (!$current) { - continue 2; + $select->add($rcmail->gettext('never'), 0); + $select->add($rcmail->gettext('htmlonreply'), 2); + $select->add($rcmail->gettext('htmlonreplyandforward'), 3); + $select->add($rcmail->gettext('always'), 1); + $select->add($rcmail->gettext('alwaysbutplain'), 4); + + $blocks['main']['options']['htmleditor'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('htmleditor'))), + 'content' => $select->show(intval($config['htmleditor'])), + ]; } - $field_id = 'rcmfd_htmleditor'; - $select = new html_select([ - 'name' => '_htmleditor', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + if (!isset($no_override['draft_autosave'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('never'), 0); - $select->add($rcmail->gettext('htmlonreply'), 2); - $select->add($rcmail->gettext('htmlonreplyandforward'), 3); - $select->add($rcmail->gettext('always'), 1); - $select->add($rcmail->gettext('alwaysbutplain'), 4); + $field_id = 'rcmfd_autosave'; + $select = new html_select([ + 'name' => '_draft_autosave', + 'id' => $field_id, + 'class' => 'custom-select', + 'disabled' => empty($config['drafts_mbox']) + ]); - $blocks['main']['options']['htmleditor'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('htmleditor'))), - 'content' => $select->show(intval($config['htmleditor'])), - ]; - } + $select->add($rcmail->gettext('never'), 0); + foreach ([1, 3, 5, 10] as $i => $min) { + $label = $rcmail->gettext(['name' => 'everynminutes', 'vars' => ['n' => $min]]); + $select->add($label, $min * 60); + } - if (!isset($no_override['draft_autosave'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['draft_autosave'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autosavedraft'))), + 'content' => $select->show($config['draft_autosave']), + ]; } - $field_id = 'rcmfd_autosave'; - $select = new html_select([ - 'name' => '_draft_autosave', - 'id' => $field_id, - 'class' => 'custom-select', - 'disabled' => empty($config['drafts_mbox']) - ]); + if (!isset($no_override['mime_param_folding'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('never'), 0); - foreach ([1, 3, 5, 10] as $i => $min) { - $label = $rcmail->gettext(['name' => 'everynminutes', 'vars' => ['n' => $min]]); - $select->add($label, $min * 60); - } + $field_id = 'rcmfd_param_folding'; + $select = new html_select([ + 'name' => '_mime_param_folding', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['draft_autosave'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autosavedraft'))), - 'content' => $select->show($config['draft_autosave']), - ]; - } + $select->add($rcmail->gettext('2231folding'), 0); + $select->add($rcmail->gettext('miscfolding'), 1); + $select->add($rcmail->gettext('2047folding'), 2); - if (!isset($no_override['mime_param_folding'])) { - if (!$current) { - continue 2; + $blocks['advanced']['options']['mime_param_folding'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mimeparamfolding'))), + 'content' => $select->show($config['mime_param_folding']), + ]; } - $field_id = 'rcmfd_param_folding'; - $select = new html_select([ - 'name' => '_mime_param_folding', - 'id' => $field_id, - 'class' => 'custom-select' - ]); - - $select->add($rcmail->gettext('2231folding'), 0); - $select->add($rcmail->gettext('miscfolding'), 1); - $select->add($rcmail->gettext('2047folding'), 2); + if (!isset($no_override['force_7bit'])) { + if (!$current) { + continue 2; + } - $blocks['advanced']['options']['mime_param_folding'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mimeparamfolding'))), - 'content' => $select->show($config['mime_param_folding']), - ]; - } + $field_id = 'rcmfd_force_7bit'; + $input = new html_checkbox(['name' => '_force_7bit', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['force_7bit'])) { - if (!$current) { - continue 2; + $blocks['advanced']['options']['force_7bit'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('force7bit'))), + 'content' => $input->show($config['force_7bit'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_force_7bit'; - $input = new html_checkbox(['name' => '_force_7bit', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['mdn_default'])) { + if (!$current) { + continue 2; + } - $blocks['advanced']['options']['force_7bit'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('force7bit'))), - 'content' => $input->show($config['force_7bit']?1:0), - ]; - } + $field_id = 'rcmfd_mdn_default'; + $input = new html_checkbox(['name' => '_mdn_default', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['mdn_default'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['mdn_default'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('reqmdn'))), + 'content' => $input->show($config['mdn_default'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_mdn_default'; - $input = new html_checkbox(['name' => '_mdn_default', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['dsn_default'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['mdn_default'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('reqmdn'))), - 'content' => $input->show($config['mdn_default']?1:0), - ]; - } + $field_id = 'rcmfd_dsn_default'; + $input = new html_checkbox(['name' => '_dsn_default', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['dsn_default'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['dsn_default'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('reqdsn'))), + 'content' => $input->show($config['dsn_default'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_dsn_default'; - $input = new html_checkbox(['name' => '_dsn_default', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['reply_same_folder'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['dsn_default'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('reqdsn'))), - 'content' => $input->show($config['dsn_default']?1:0), - ]; - } + $field_id = 'rcmfd_reply_same_folder'; + $input = new html_checkbox(['name' => '_reply_same_folder', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['reply_same_folder'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['reply_same_folder'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replysamefolder'))), + 'content' => $input->show($config['reply_same_folder'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_reply_same_folder'; - $input = new html_checkbox(['name' => '_reply_same_folder', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['reply_mode'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['reply_same_folder'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replysamefolder'))), - 'content' => $input->show($config['reply_same_folder']?1:0), - ]; - } + $field_id = 'rcmfd_reply_mode'; + $select = new html_select(['name' => '_reply_mode', 'id' => $field_id, 'class' => 'custom-select']); - if (!isset($no_override['reply_mode'])) { - if (!$current) { - continue 2; - } + $select->add($rcmail->gettext('replyempty'), -1); + $select->add($rcmail->gettext('replybottomposting'), 0); + $select->add($rcmail->gettext('replytopposting'), 1); + $select->add($rcmail->gettext('replytoppostingnoindent'), 2); - $field_id = 'rcmfd_reply_mode'; - $select = new html_select(['name' => '_reply_mode', 'id' => $field_id, 'class' => 'custom-select']); + $blocks['main']['options']['reply_mode'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('whenreplying'))), + 'content' => $select->show(intval($config['reply_mode'])), + ]; + } - $select->add($rcmail->gettext('replyempty'), -1); - $select->add($rcmail->gettext('replybottomposting'), 0); - $select->add($rcmail->gettext('replytopposting'), 1); - $select->add($rcmail->gettext('replytoppostingnoindent'), 2); + if (!isset($no_override['spellcheck_before_send']) && $config['enable_spellcheck']) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['reply_mode'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('whenreplying'))), - 'content' => $select->show(intval($config['reply_mode'])), - ]; - } + $field_id = 'rcmfd_spellcheck_before_send'; + $input = new html_checkbox([ + 'name' => '_spellcheck_before_send', + 'id' => $field_id, + 'value' => 1 + ]); - if (!isset($no_override['spellcheck_before_send']) && $config['enable_spellcheck']) { - if (!$current) { - continue 2; + $blocks['spellcheck']['options']['spellcheck_before_send'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('spellcheckbeforesend'))), + 'content' => $input->show($config['spellcheck_before_send'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_spellcheck_before_send'; - $input = new html_checkbox([ - 'name' => '_spellcheck_before_send', - 'id' => $field_id, - 'value' => 1 - ]); + if ($config['enable_spellcheck']) { + if (!$current) { + continue 2; + } - $blocks['spellcheck']['options']['spellcheck_before_send'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('spellcheckbeforesend'))), - 'content' => $input->show($config['spellcheck_before_send']?1:0), - ]; - } + foreach (['syms', 'nums', 'caps'] as $key) { + $key = 'spellcheck_ignore_' . $key; + if (!isset($no_override[$key])) { + $input = new html_checkbox(['name' => '_' . $key, 'id' => 'rcmfd_' . $key, 'value' => 1]); - if ($config['enable_spellcheck']) { - if (!$current) { - continue 2; + $blocks['spellcheck']['options'][$key] = [ + 'title' => html::label('rcmfd_' . $key, rcube::Q($rcmail->gettext(str_replace('_', '', $key)))), + 'content' => $input->show($config[$key] ? 1 : 0), + ]; + } + } } - foreach (['syms', 'nums', 'caps'] as $key) { - $key = 'spellcheck_ignore_' . $key; - if (!isset($no_override[$key])) { - $input = new html_checkbox(['name' => '_' . $key, 'id' => 'rcmfd_' . $key, 'value' => 1]); - - $blocks['spellcheck']['options'][$key] = [ - 'title' => html::label('rcmfd_' . $key, rcube::Q($rcmail->gettext(str_replace('_', '', $key)))), - 'content' => $input->show($config[$key]?1:0), - ]; + if (!isset($no_override['show_sig'])) { + if (!$current) { + continue 2; } - } - } - if (!isset($no_override['show_sig'])) { - if (!$current) { - continue 2; - } + $field_id = 'rcmfd_show_sig'; + $select = new html_select([ + 'name' => '_show_sig', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $field_id = 'rcmfd_show_sig'; - $select = new html_select([ - 'name' => '_show_sig', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + $select->add($rcmail->gettext('never'), 0); + $select->add($rcmail->gettext('always'), 1); + $select->add($rcmail->gettext('newmessageonly'), 2); + $select->add($rcmail->gettext('replyandforwardonly'), 3); - $select->add($rcmail->gettext('never'), 0); - $select->add($rcmail->gettext('always'), 1); - $select->add($rcmail->gettext('newmessageonly'), 2); - $select->add($rcmail->gettext('replyandforwardonly'), 3); + $blocks['sig']['options']['show_sig'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autoaddsignature'))), + 'content' => $select->show($rcmail->config->get('show_sig', 1)), + ]; + } - $blocks['sig']['options']['show_sig'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autoaddsignature'))), - 'content' => $select->show($rcmail->config->get('show_sig', 1)), - ]; - } + if (!isset($no_override['sig_below'])) { + if (!$current) { + continue 2; + } + + $field_id = 'rcmfd_sig_below'; + $input = new html_checkbox(['name' => '_sig_below', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['sig_below'])) { - if (!$current) { - continue 2; + $blocks['sig']['options']['sig_below'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('sigbelow'))), + 'content' => $input->show($rcmail->config->get('sig_below') ? 1 : 0), + ]; } - $field_id = 'rcmfd_sig_below'; - $input = new html_checkbox(['name' => '_sig_below', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['strip_existing_sig'])) { + if (!$current) { + continue 2; + } - $blocks['sig']['options']['sig_below'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('sigbelow'))), - 'content' => $input->show($rcmail->config->get('sig_below') ? 1 : 0), - ]; - } + $field_id = 'rcmfd_strip_existing_sig'; + $input = new html_checkbox([ + 'name' => '_strip_existing_sig', + 'id' => $field_id, + 'value' => 1 + ]); - if (!isset($no_override['strip_existing_sig'])) { - if (!$current) { - continue 2; + $blocks['sig']['options']['strip_existing_sig'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replyremovesignature'))), + 'content' => $input->show($config['strip_existing_sig'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_strip_existing_sig'; - $input = new html_checkbox([ - 'name' => '_strip_existing_sig', - 'id' => $field_id, - 'value' => 1 - ]); + if (!isset($no_override['sig_separator'])) { + if (!$current) { + continue 2; + } - $blocks['sig']['options']['strip_existing_sig'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replyremovesignature'))), - 'content' => $input->show($config['strip_existing_sig']?1:0), - ]; - } + $field_id = 'rcmfd_sig_separator'; + $input = new html_checkbox(['name' => '_sig_separator', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['sig_separator'])) { - if (!$current) { - continue 2; + $blocks['sig']['options']['sig_separator'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('sigseparator'))), + 'content' => $input->show($rcmail->config->get('sig_separator') ? 1 : 0), + ]; } - $field_id = 'rcmfd_sig_separator'; - $input = new html_checkbox(['name' => '_sig_separator', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['forward_attachment'])) { + if (!$current) { + continue 2; + } - $blocks['sig']['options']['sig_separator'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('sigseparator'))), - 'content' => $input->show($rcmail->config->get('sig_separator') ? 1 : 0), - ]; - } + $field_id = 'rcmfd_forward_attachment'; + $select = new html_select([ + 'name' => '_forward_attachment', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - if (!isset($no_override['forward_attachment'])) { - if (!$current) { - continue 2; + $select->add($rcmail->gettext('inline'), 0); + $select->add($rcmail->gettext('asattachment'), 1); + + $blocks['main']['options']['forward_attachment'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('forwardmode'))), + 'content' => $select->show(intval($config['forward_attachment'])), + ]; } - $field_id = 'rcmfd_forward_attachment'; - $select = new html_select([ - 'name' => '_forward_attachment', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // Font settings are made up of 2 parts, font name and font size + // Compute the settings first to discover is anything to display to the user + $font_settings = ''; - $select->add($rcmail->gettext('inline'), 0); - $select->add($rcmail->gettext('asattachment'), 1); + // Default font + if (!isset($no_override['default_font'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['forward_attachment'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('forwardmode'))), - 'content' => $select->show(intval($config['forward_attachment'])), - ]; - } + $fonts = self::font_defs(); + if (count($fonts) > 1) { + $field_id = 'rcmfd_default_font'; + $select_font = new html_select([ + 'name' => '_default_font', + 'id' => $field_id, + 'class' => 'custom-select' + ]); + + $select_font->add('', ''); - // Font settings are made up of 2 parts, font name and font size - // Compute the settings first to discover is anything to display to the user - $font_settings = ''; + foreach (array_keys($fonts) as $fname) { + $select_font->add($fname, $fname); + } - // Default font - if (!isset($no_override['default_font'])) { - if (!$current) { - continue 2; + $font_settings .= $select_font->show($rcmail->config->get('default_font', 1)); + } } - $fonts = self::font_defs(); - if (count($fonts) > 1) { - $field_id = 'rcmfd_default_font'; - $select_font = new html_select([ - 'name' => '_default_font', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // Default font size + if (!isset($no_override['default_font_size'])) { + if (!$current) { + continue 2; + } - $select_font->add('', ''); + $fontsizes = self::fontsize_defs(); + if (count($fontsizes) > 1) { + $field_id = 'rcmfd_default_font_size'; + $select_size = new html_select([ + 'name' => '_default_font_size', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - foreach (array_keys($fonts) as $fname) { - $select_font->add($fname, $fname); - } + $select_size->add('', ''); - $font_settings .= $select_font->show($rcmail->config->get('default_font', 1)); + foreach ($fontsizes as $size) { + $select_size->add($size, $size); + } + + $font_settings .= $select_size->show($rcmail->config->get('default_font_size', 1)); + } } - } - // Default font size - if (!isset($no_override['default_font_size'])) { - if (!$current) { - continue 2; + // Include font settings in the display only if at least one setting exists + if (!empty($font_settings)) { + $blocks['main']['options']['default_font'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultfont'))), + 'content' => html::div('input-group', $font_settings) + ]; } - $fontsizes = self::fontsize_defs(); - if (count($fontsizes) > 1) { - $field_id = 'rcmfd_default_font_size'; - $select_size = new html_select([ - 'name' => '_default_font_size', + if (!isset($no_override['reply_all_mode'])) { + if (!$current) { + continue 2; + } + + $field_id = 'rcmfd_reply_all_mode'; + $select = new html_select([ + 'name' => '_reply_all_mode', 'id' => $field_id, 'class' => 'custom-select' ]); - $select_size->add('', ''); - - foreach ($fontsizes as $size) { - $select_size->add($size, $size); - } - - $font_settings .= $select_size->show($rcmail->config->get('default_font_size', 1)); - } - } - - // Include font settings in the display only if at least one setting exists - if (!empty($font_settings)) { - $blocks['main']['options']['default_font'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultfont'))), - 'content' => html::div('input-group', $font_settings) - ]; - } + $select->add($rcmail->gettext('replyalldefault'), 0); + $select->add($rcmail->gettext('replyalllist'), 1); - if (!isset($no_override['reply_all_mode'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['reply_all_mode'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replyallmode'))), + 'content' => $select->show(intval($config['reply_all_mode'])), + ]; } - $field_id = 'rcmfd_reply_all_mode'; - $select = new html_select([ - 'name' => '_reply_all_mode', - 'id' => $field_id, - 'class' => 'custom-select' - ]); - - $select->add($rcmail->gettext('replyalldefault'), 0); - $select->add($rcmail->gettext('replyalllist'), 1); + if (!isset($no_override['compose_save_localstorage'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['reply_all_mode'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('replyallmode'))), - 'content' => $select->show(intval($config['reply_all_mode'])), - ]; - } + $field_id = 'rcmfd_compose_save_localstorage'; + $input = new html_checkbox([ + 'name' => '_compose_save_localstorage', + 'id' => $field_id, + 'value' => 1 + ]); - if (!isset($no_override['compose_save_localstorage'])) { - if (!$current) { - continue 2; + $blocks['advanced']['options']['compose_save_localstorage'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('savelocalstorage'))), + 'content' => $input->show($config['compose_save_localstorage'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_compose_save_localstorage'; - $input = new html_checkbox([ - 'name' => '_compose_save_localstorage', - 'id' => $field_id, - 'value' => 1 - ]); + break; - $blocks['advanced']['options']['compose_save_localstorage'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('savelocalstorage'))), - 'content' => $input->show($config['compose_save_localstorage']?1:0), + // Addressbook config (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'addressbook': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'collected' => ['name' => rcube::Q($rcmail->gettext('collectedaddresses'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - break; - - // Addressbook config - case 'addressbook': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'collected' => ['name' => rcube::Q($rcmail->gettext('collectedaddresses'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; - - if (!isset($no_override['default_addressbook']) - && (!$current || ($books = $rcmail->get_address_sources(true, true))) - ) { - if (!$current) { - continue 2; - } + if (!isset($no_override['default_addressbook']) + && (!$current || ($books = $rcmail->get_address_sources(true, true))) + ) { + if (!$current) { + continue 2; + } - $field_id = 'rcmfd_default_addressbook'; - $select = new html_select([ - 'name' => '_default_addressbook', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + $field_id = 'rcmfd_default_addressbook'; + $select = new html_select([ + 'name' => '_default_addressbook', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - if (!empty($books)) { - foreach ($books as $book) { - $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); + if (!empty($books)) { + foreach ($books as $book) { + $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); + } } - } - $blocks['main']['options']['default_addressbook'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultabook'))), - 'content' => $select->show($config['default_addressbook']), - ]; - } - - // show addressbook listing mode selection - if (!isset($no_override['addressbook_name_listing'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['default_addressbook'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultabook'))), + 'content' => $select->show($config['default_addressbook']), + ]; } - $field_id = 'rcmfd_addressbook_name_listing'; - $select = new html_select([ - 'name' => '_addressbook_name_listing', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // show addressbook listing mode selection + if (!isset($no_override['addressbook_name_listing'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('name'), 0); - $select->add($rcmail->gettext('firstname') . ' ' . $rcmail->gettext('surname'), 1); - $select->add($rcmail->gettext('surname') . ' ' . $rcmail->gettext('firstname'), 2); - $select->add($rcmail->gettext('surname') . ', ' . $rcmail->gettext('firstname'), 3); + $field_id = 'rcmfd_addressbook_name_listing'; + $select = new html_select([ + 'name' => '_addressbook_name_listing', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['list_name_listing'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('listnamedisplay'))), - 'content' => $select->show($config['addressbook_name_listing']), - ]; - } + $select->add($rcmail->gettext('name'), 0); + $select->add($rcmail->gettext('firstname') . ' ' . $rcmail->gettext('surname'), 1); + $select->add($rcmail->gettext('surname') . ' ' . $rcmail->gettext('firstname'), 2); + $select->add($rcmail->gettext('surname') . ', ' . $rcmail->gettext('firstname'), 3); - // show addressbook sort column - if (!isset($no_override['addressbook_sort_col'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['list_name_listing'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('listnamedisplay'))), + 'content' => $select->show($config['addressbook_name_listing']), + ]; } - $field_id = 'rcmfd_addressbook_sort_col'; - $select = new html_select([ - 'name' => '_addressbook_sort_col', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + // show addressbook sort column + if (!isset($no_override['addressbook_sort_col'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('name'), 'name'); - $select->add($rcmail->gettext('firstname'), 'firstname'); - $select->add($rcmail->gettext('surname'), 'surname'); + $field_id = 'rcmfd_addressbook_sort_col'; + $select = new html_select([ + 'name' => '_addressbook_sort_col', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['sort_col'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('listsorting'))), - 'content' => $select->show($config['addressbook_sort_col']), - ]; - } + $select->add($rcmail->gettext('name'), 'name'); + $select->add($rcmail->gettext('firstname'), 'firstname'); + $select->add($rcmail->gettext('surname'), 'surname'); - // show addressbook page size selection - if (!isset($no_override['addressbook_pagesize'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['sort_col'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('listsorting'))), + 'content' => $select->show($config['addressbook_sort_col']), + ]; } - $size = intval($config['addressbook_pagesize'] ?: $config['pagesize']); - $field_id = 'rcmfd_addressbook_pagesize'; - $input = new html_inputfield([ - 'name' => '_addressbook_pagesize', - 'id' => $field_id, - 'size' => 5, - 'class' => 'form-control' - ]); + // show addressbook page size selection + if (!isset($no_override['addressbook_pagesize'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['pagesize'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('pagesize'))), - 'content' => $input->show($size ?: 50), - ]; - } + $size = intval($config['addressbook_pagesize'] ?: $config['pagesize']); + $field_id = 'rcmfd_addressbook_pagesize'; + $input = new html_inputfield([ + 'name' => '_addressbook_pagesize', + 'id' => $field_id, + 'size' => 5, + 'class' => 'form-control' + ]); - if (!isset($no_override['contact_form_mode'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['pagesize'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('pagesize'))), + 'content' => $input->show($size ?: 50), + ]; } - $mode = $config['contact_form_mode'] == 'business' ? 'business' : 'private'; - $field_id = 'rcmfd_contact_form_mode'; - $select = new html_select([ - 'name' => '_contact_form_mode', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + if (!isset($no_override['contact_form_mode'])) { + if (!$current) { + continue 2; + } - $select->add($rcmail->gettext('privatemode'), 'private'); - $select->add($rcmail->gettext('businessmode'), 'business'); + $mode = $config['contact_form_mode'] == 'business' ? 'business' : 'private'; + $field_id = 'rcmfd_contact_form_mode'; + $select = new html_select([ + 'name' => '_contact_form_mode', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - $blocks['main']['options']['contact_form_mode'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('contactformmode'))), - 'content' => $select->show($mode), - ]; - } + $select->add($rcmail->gettext('privatemode'), 'private'); + $select->add($rcmail->gettext('businessmode'), 'business'); - if (!isset($no_override['autocomplete_single'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['contact_form_mode'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('contactformmode'))), + 'content' => $select->show($mode), + ]; } - $field_id = 'rcmfd_autocomplete_single'; - $checkbox = new html_checkbox(['name' => '_autocomplete_single', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['autocomplete_single'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['autocomplete_single'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autocompletesingle'))), - 'content' => $checkbox->show($config['autocomplete_single']?1:0), - ]; - } + $field_id = 'rcmfd_autocomplete_single'; + $checkbox = new html_checkbox(['name' => '_autocomplete_single', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['collected_recipients'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['autocomplete_single'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('autocompletesingle'))), + 'content' => $checkbox->show($config['autocomplete_single'] ? 1 : 0), + ]; } - if (!isset($books)) { - $books = $rcmail->get_address_sources(true, true); - } + if (!isset($no_override['collected_recipients'])) { + if (!$current) { + continue 2; + } - $field_id = 'rcmfd_collected_recipients'; - $select = new html_select([ - 'name' => '_collected_recipients', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + if (!isset($books)) { + $books = $rcmail->get_address_sources(true, true); + } - $select->add('---', ''); - $select->add($rcmail->gettext('collectedrecipients'), (string) rcube_addressbook::TYPE_RECIPIENT); + $field_id = 'rcmfd_collected_recipients'; + $select = new html_select([ + 'name' => '_collected_recipients', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - foreach ($books as $book) { - $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); - } + $select->add('---', ''); + $select->add($rcmail->gettext('collectedrecipients'), (string) rcube_addressbook::TYPE_RECIPIENT); - $selected = $config['collected_recipients']; - if (is_bool($selected)) { - $selected = $selected ? rcube_addressbook::TYPE_RECIPIENT : ''; - } + foreach ($books as $book) { + $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); + } - $blocks['collected']['options']['collected_recipients'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('collectedrecipientsopt'))), - 'content' => $select->show((string) $selected), - ]; - } + $selected = $config['collected_recipients']; + if (is_bool($selected)) { + $selected = $selected ? rcube_addressbook::TYPE_RECIPIENT : ''; + } - if (!isset($no_override['collected_senders'])) { - if (!$current) { - continue 2; + $blocks['collected']['options']['collected_recipients'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('collectedrecipientsopt'))), + 'content' => $select->show((string) $selected), + ]; } - if (!isset($books)) { - $books = $rcmail->get_address_sources(true, true); - } + if (!isset($no_override['collected_senders'])) { + if (!$current) { + continue 2; + } - $field_id = 'rcmfd_collected_senders'; - $select = new html_select([ - 'name' => '_collected_senders', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + if (!isset($books)) { + $books = $rcmail->get_address_sources(true, true); + } - $select->add($rcmail->gettext('trustedsenders'), (string) rcube_addressbook::TYPE_TRUSTED_SENDER); + $field_id = 'rcmfd_collected_senders'; + $select = new html_select([ + 'name' => '_collected_senders', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - foreach ($books as $book) { - $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); - } + $select->add($rcmail->gettext('trustedsenders'), (string) rcube_addressbook::TYPE_TRUSTED_SENDER); - $selected = $config['collected_senders']; - if (is_bool($selected)) { - $selected = $selected ? rcube_addressbook::TYPE_TRUSTED_SENDER : ''; + foreach ($books as $book) { + $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']); + } + + $selected = $config['collected_senders']; + if (is_bool($selected)) { + $selected = $selected ? rcube_addressbook::TYPE_TRUSTED_SENDER : ''; + } + + $blocks['collected']['options']['collected_senders'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('collectedsendersopt'))), + 'content' => $select->show((string) $selected), + ]; } - $blocks['collected']['options']['collected_senders'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('collectedsendersopt'))), - 'content' => $select->show((string) $selected), + break; + + // Special IMAP folders (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'folders': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - break; + if (!isset($no_override['show_real_foldernames'])) { + if (!$current) { + continue 2; + } - // Special IMAP folders - case 'folders': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; + $field_id = 'show_real_foldernames'; + $input = new html_checkbox(['name' => '_show_real_foldernames', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['show_real_foldernames'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['show_real_foldernames'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('show_real_foldernames'))), + 'content' => $input->show($config['show_real_foldernames'] ? 1 : 0), + ]; } - $field_id = 'show_real_foldernames'; - $input = new html_checkbox(['name' => '_show_real_foldernames', 'id' => $field_id, 'value' => 1]); + // Configure special folders + $set = ['drafts_mbox', 'sent_mbox', 'junk_mbox', 'trash_mbox']; - $blocks['main']['options']['show_real_foldernames'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('show_real_foldernames'))), - 'content' => $input->show($config['show_real_foldernames']?1:0), - ]; - } + if ($current && count(array_intersect($no_override, $set)) < 4) { + $select = self::folder_selector([ + 'noselection' => '---', + 'realnames' => true, + 'maxlength' => 30, + 'folder_filter' => 'mail', + 'folder_rights' => 'w', + 'class' => 'custom-select', + ]); - // Configure special folders - $set = ['drafts_mbox', 'sent_mbox', 'junk_mbox', 'trash_mbox']; - - if ($current && count(array_intersect($no_override, $set)) < 4) { - $select = self::folder_selector([ - 'noselection' => '---', - 'realnames' => true, - 'maxlength' => 30, - 'folder_filter' => 'mail', - 'folder_rights' => 'w', - 'class' => 'custom-select', - ]); - - // #1486114, #1488279, #1489219 - $onchange = "if ($(this).val() == 'INBOX') $(this).val('')"; - } - else { - $onchange = null; - $select = new html_select(); - } + // #1486114, #1488279, #1489219 + $onchange = "if ($(this).val() == 'INBOX') $(this).val('')"; + } + else { + $onchange = null; + $select = new html_select(); + } - if (!isset($no_override['drafts_mbox'])) { - if (!$current) { - continue 2; + if (!isset($no_override['drafts_mbox'])) { + if (!$current) { + continue 2; + } + + $attrs = ['id' => '_drafts_mbox', 'name' => '_drafts_mbox', 'onchange' => $onchange]; + $blocks['main']['options']['drafts_mbox'] = [ + 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('drafts'))), + 'content' => $select->show($config['drafts_mbox'], $attrs), + ]; } - $attrs = ['id' => '_drafts_mbox', 'name' => '_drafts_mbox', 'onchange' => $onchange]; - $blocks['main']['options']['drafts_mbox'] = [ - 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('drafts'))), - 'content' => $select->show($config['drafts_mbox'], $attrs), - ]; - } + if (!isset($no_override['sent_mbox'])) { + if (!$current) { + continue 2; + } - if (!isset($no_override['sent_mbox'])) { - if (!$current) { - continue 2; + $attrs = ['id' => '_sent_mbox', 'name' => '_sent_mbox', 'onchange' => '']; + $blocks['main']['options']['sent_mbox'] = [ + 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('sent'))), + 'content' => $select->show($config['sent_mbox'], $attrs), + ]; } - $attrs = ['id' => '_sent_mbox', 'name' => '_sent_mbox', 'onchange' => '']; - $blocks['main']['options']['sent_mbox'] = [ - 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('sent'))), - 'content' => $select->show($config['sent_mbox'], $attrs), - ]; - } + if (!isset($no_override['junk_mbox'])) { + if (!$current) { + continue 2; + } - if (!isset($no_override['junk_mbox'])) { - if (!$current) { - continue 2; + $attrs = ['id' => '_junk_mbox', 'name' => '_junk_mbox', 'onchange' => $onchange]; + $blocks['main']['options']['junk_mbox'] = [ + 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('junk'))), + 'content' => $select->show($config['junk_mbox'], $attrs), + ]; } - $attrs = ['id' => '_junk_mbox', 'name' => '_junk_mbox', 'onchange' => $onchange]; - $blocks['main']['options']['junk_mbox'] = [ - 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('junk'))), - 'content' => $select->show($config['junk_mbox'], $attrs), - ]; - } + if (!isset($no_override['trash_mbox'])) { + if (!$current) { + continue 2; + } - if (!isset($no_override['trash_mbox'])) { - if (!$current) { - continue 2; + $attrs = ['id' => '_trash_mbox', 'name' => '_trash_mbox', 'onchange' => $onchange]; + $blocks['main']['options']['trash_mbox'] = [ + 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('trash'))), + 'content' => $select->show($config['trash_mbox'], $attrs), + ]; } - $attrs = ['id' => '_trash_mbox', 'name' => '_trash_mbox', 'onchange' => $onchange]; - $blocks['main']['options']['trash_mbox'] = [ - 'title' => html::label($attrs['id'], rcube::Q($rcmail->gettext('trash'))), - 'content' => $select->show($config['trash_mbox'], $attrs), + break; + + // Server settings (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'server': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'maintenance' => ['name' => rcube::Q($rcmail->gettext('maintenance'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - break; + if (!isset($no_override['read_when_deleted'])) { + if (!$current) { + continue 2; + } - // Server settings - case 'server': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'maintenance' => ['name' => rcube::Q($rcmail->gettext('maintenance'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; + $field_id = 'rcmfd_read_deleted'; + $input = new html_checkbox(['name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['read_when_deleted'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['read_when_deleted'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('readwhendeleted'))), + 'content' => $input->show($config['read_when_deleted'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_read_deleted'; - $input = new html_checkbox(['name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['flag_for_deletion'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['read_when_deleted'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('readwhendeleted'))), - 'content' => $input->show($config['read_when_deleted']?1:0), - ]; - } + $field_id = 'rcmfd_flag_for_deletion'; + $input = new html_checkbox(['name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['flag_for_deletion'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['flag_for_deletion'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('flagfordeletion'))), + 'content' => $input->show($config['flag_for_deletion'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_flag_for_deletion'; - $input = new html_checkbox(['name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1]); + // don't show deleted messages + if (!isset($no_override['skip_deleted'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['flag_for_deletion'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('flagfordeletion'))), - 'content' => $input->show($config['flag_for_deletion']?1:0), - ]; - } + $field_id = 'rcmfd_skip_deleted'; + $input = new html_checkbox(['name' => '_skip_deleted', 'id' => $field_id, 'value' => 1]); - // don't show deleted messages - if (!isset($no_override['skip_deleted'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['skip_deleted'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('skipdeleted'))), + 'content' => $input->show($config['skip_deleted'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_skip_deleted'; - $input = new html_checkbox(['name' => '_skip_deleted', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['delete_junk'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['skip_deleted'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('skipdeleted'))), - 'content' => $input->show($config['skip_deleted']?1:0), - ]; - } + $field_id = 'rcmfd_delete_junk'; + $input = new html_checkbox(['name' => '_delete_junk', 'id' => $field_id, 'value' => 1]); - if (!isset($no_override['delete_junk'])) { - if (!$current) { - continue 2; + $blocks['main']['options']['delete_junk'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('deletejunk'))), + 'content' => $input->show($config['delete_junk'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_delete_junk'; - $input = new html_checkbox(['name' => '_delete_junk', 'id' => $field_id, 'value' => 1]); + // Trash purging on logout + if (!isset($no_override['logout_purge'])) { + if (!$current) { + continue 2; + } - $blocks['main']['options']['delete_junk'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('deletejunk'))), - 'content' => $input->show($config['delete_junk']?1:0), - ]; - } + $field_id = 'rcmfd_logout_purge'; + $select = new html_select([ + 'name' => '_logout_purge', + 'id' => $field_id, + 'class' => 'custom-select' + ]); - // Trash purging on logout - if (!isset($no_override['logout_purge'])) { - if (!$current) { - continue 2; - } + $select->add($rcmail->gettext('never'), 'never'); + $select->add($rcmail->gettext('allmessages'), 'all'); - $field_id = 'rcmfd_logout_purge'; - $select = new html_select([ - 'name' => '_logout_purge', - 'id' => $field_id, - 'class' => 'custom-select' - ]); + foreach ([30, 60, 90] as $days) { + $select->add($rcmail->gettext(['name' => 'olderxdays', 'vars' => ['x' => $days]]), (string) $days); + } - $select->add($rcmail->gettext('never'), 'never'); - $select->add($rcmail->gettext('allmessages'), 'all'); + $purge = $config['logout_purge']; + if (!is_numeric($purge)) { + $purge = empty($purge) ? 'never' : 'all'; + } - foreach ([30, 60, 90] as $days) { - $select->add($rcmail->gettext(['name' => 'olderxdays', 'vars' => ['x' => $days]]), (string) $days); + $blocks['maintenance']['options']['logout_purge'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('logoutclear'))), + 'content' => $select->show((string) $purge), + ]; } - $purge = $config['logout_purge']; - if (!is_numeric($purge)) { - $purge = empty($purge) ? 'never' : 'all'; - } + // INBOX compacting on logout + if (!isset($no_override['logout_expunge'])) { + if (!$current) { + continue 2; + } - $blocks['maintenance']['options']['logout_purge'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('logoutclear'))), - 'content' => $select->show((string) $purge), - ]; - } + $field_id = 'rcmfd_logout_expunge'; + $input = new html_checkbox(['name' => '_logout_expunge', 'id' => $field_id, 'value' => 1]); - // INBOX compacting on logout - if (!isset($no_override['logout_expunge'])) { - if (!$current) { - continue 2; + $blocks['maintenance']['options']['logout_expunge'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('logoutcompact'))), + 'content' => $input->show($config['logout_expunge'] ? 1 : 0), + ]; } - $field_id = 'rcmfd_logout_expunge'; - $input = new html_checkbox(['name' => '_logout_expunge', 'id' => $field_id, 'value' => 1]); + break; - $blocks['maintenance']['options']['logout_expunge'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('logoutcompact'))), - 'content' => $input->show($config['logout_expunge']?1:0), + // Server settings (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case 'encryption': + $blocks = [ + 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], + 'mailvelope' => ['name' => rcube::Q($rcmail->gettext('mailvelopeoptions'))], + 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], ]; - } - - break; - - // Server settings - case 'encryption': - $blocks = [ - 'main' => ['name' => rcube::Q($rcmail->gettext('mainoptions'))], - 'mailvelope' => ['name' => rcube::Q($rcmail->gettext('mailvelopeoptions'))], - 'advanced' => ['name' => rcube::Q($rcmail->gettext('advancedoptions'))], - ]; - - if (!isset($no_override['mailvelope_main_keyring'])) { - if (!$current) { - continue 2; - } - $field_id = 'rcmfd_mailvelope_main_keyring'; - $input = new html_checkbox(['name' => '_mailvelope_main_keyring', 'id' => $field_id, 'value' => 1]); + if (!isset($no_override['mailvelope_main_keyring'])) { + if (!$current) { + continue 2; + } - $blocks['mailvelope']['options']['mailvelope_status'] = [ - 'content' => html::div( - ['style' => 'display:none', 'class' => 'boxwarning', 'id' => 'mailvelope-warning'], - str_replace( - 'Mailvelope', 'Mailvelope', - rcube::Q($rcmail->gettext('mailvelopenotfound')) + $field_id = 'rcmfd_mailvelope_main_keyring'; + $input = new html_checkbox(['name' => '_mailvelope_main_keyring', 'id' => $field_id, 'value' => 1]); + + $blocks['mailvelope']['options']['mailvelope_status'] = [ + 'content' => html::div( + ['style' => 'display:none', 'class' => 'boxwarning', 'id' => 'mailvelope-warning'], + str_replace( + 'Mailvelope', 'Mailvelope', + rcube::Q($rcmail->gettext('mailvelopenotfound')) + ) + . html::script([], "if (!parent.mailvelope) \$('#mailvelope-warning').show()") ) - . html::script([], "if (!parent.mailvelope) \$('#mailvelope-warning').show()") - ) - ]; + ]; - $blocks['mailvelope']['options']['mailvelope_main_keyring'] = [ - 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mailvelopemainkeyring'))), - 'content' => $input->show(!empty($config['mailvelope_main_keyring']) ? 1 : 0), - ]; - } + $blocks['mailvelope']['options']['mailvelope_main_keyring'] = [ + 'title' => html::label($field_id, rcube::Q($rcmail->gettext('mailvelopemainkeyring'))), + 'content' => $input->show(!empty($config['mailvelope_main_keyring']) ? 1 : 0), + ]; + } - break; + break; } $found = false; @@ -1612,9 +1612,9 @@ public static function settings_tabs($attrib) $default_actions = [ ['action' => 'preferences', 'type' => 'link', 'label' => 'preferences', 'title' => 'editpreferences'], - ['action' => 'folders', 'type' => 'link', 'label' => 'folders', 'title' => 'managefolders'], - ['action' => 'identities', 'type' => 'link', 'label' => 'identities', 'title' => 'manageidentities'], - ['action' => 'responses', 'type' => 'link', 'label' => 'responses', 'title' => 'manageresponses'], + ['action' => 'folders', 'type' => 'link', 'label' => 'folders', 'title' => 'managefolders'], + ['action' => 'identities', 'type' => 'link', 'label' => 'identities', 'title' => 'manageidentities'], + ['action' => 'responses', 'type' => 'link', 'label' => 'responses', 'title' => 'manageresponses'], ]; $disabled_actions = (array) $rcmail->config->get('disabled_actions'); diff --git a/program/actions/settings/prefs_edit.php b/program/actions/settings/prefs_edit.php index 7417885ae47..bf5efa47602 100644 --- a/program/actions/settings/prefs_edit.php +++ b/program/actions/settings/prefs_edit.php @@ -1,6 +1,6 @@ output->set_pagetitle($rcmail->gettext('preferences')); self::$section = rcube_utils::get_input_string('_section', rcube_utils::INPUT_GPC); - list(self::$sections,) = self::user_prefs(self::$section); + list(self::$sections) = self::user_prefs(self::$section); // register UI objects $rcmail->output->add_handlers([ diff --git a/program/actions/settings/prefs_save.php b/program/actions/settings/prefs_save.php index b65a2777116..bdc27306c4e 100644 --- a/program/actions/settings/prefs_save.php +++ b/program/actions/settings/prefs_save.php @@ -1,6 +1,6 @@ self::prefs_input('language', '/^[a-zA-Z0-9_-]+$/'), - 'timezone' => self::prefs_input('timezone', '/^[a-zA-Z_\/-]+$/'), - 'date_format' => self::prefs_input('date_format', '/^[a-zA-Z_.\/ -]+$/'), - 'time_format' => self::prefs_input('time_format', '/^[a-zA-Z0-9: ]+$/'), - 'prettydate' => isset($_POST['_pretty_date']), - 'display_next' => isset($_POST['_display_next']), - 'refresh_interval' => self::prefs_input_int('refresh_interval') * 60, - 'standard_windows' => isset($_POST['_standard_windows']), - 'skin' => self::prefs_input('skin', '/^[a-zA-Z0-9_.-]+$/'), - ]; - - // compose derived date/time format strings - if ( - (isset($_POST['_date_format']) || isset($_POST['_time_format'])) - && !empty($a_user_prefs['date_format']) - && !empty($a_user_prefs['time_format']) - ) { - $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format']; - $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format']; - } - - break; - - case 'mailbox': - $a_user_prefs = [ - 'layout' => self::prefs_input('layout', '/^[a-z]+$/'), - 'mail_read_time' => self::prefs_input_int('mail_read_time'), - 'autoexpand_threads' => self::prefs_input_int('autoexpand_threads'), - 'check_all_folders' => isset($_POST['_check_all_folders']), - 'mail_pagesize' => max(2, self::prefs_input_int('mail_pagesize')), - ]; - - break; - - case 'mailview': - $a_user_prefs = [ - 'message_extwin' => self::prefs_input_int('message_extwin'), - 'message_show_email' => isset($_POST['_message_show_email']), - 'prefer_html' => isset($_POST['_prefer_html']), - 'inline_images' => isset($_POST['_inline_images']), - 'show_images' => self::prefs_input_int('show_images'), - 'mdn_requests' => self::prefs_input_int('mdn_requests'), - 'default_charset' => self::prefs_input('default_charset', '/^[a-zA-Z0-9-]+$/'), - ]; - - break; - - case 'compose': - $a_user_prefs = [ - 'compose_extwin' => self::prefs_input_int('compose_extwin'), - 'htmleditor' => self::prefs_input_int('htmleditor'), - 'draft_autosave' => self::prefs_input_int('draft_autosave'), - 'mime_param_folding' => self::prefs_input_int('mime_param_folding'), - 'force_7bit' => isset($_POST['_force_7bit']), - 'mdn_default' => isset($_POST['_mdn_default']), - 'dsn_default' => isset($_POST['_dsn_default']), - 'reply_same_folder' => isset($_POST['_reply_same_folder']), - 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']), - 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']), - 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']), - 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']), - 'show_sig' => self::prefs_input_int('show_sig'), - 'reply_mode' => self::prefs_input_int('reply_mode'), - 'sig_below' => isset($_POST['_sig_below']), - 'strip_existing_sig' => isset($_POST['_strip_existing_sig']), - 'sig_separator' => isset($_POST['_sig_separator']), - 'default_font' => self::prefs_input('default_font', '/^[a-zA-Z ]+$/'), - 'default_font_size' => self::prefs_input('default_font_size', '/^[0-9]+pt$/'), - 'reply_all_mode' => self::prefs_input_int('reply_all_mode'), - 'forward_attachment' => !empty($_POST['_forward_attachment']), - 'compose_save_localstorage' => self::prefs_input_int('compose_save_localstorage'), - ]; - - break; - - case 'addressbook': - $a_user_prefs = [ - 'default_addressbook' => rcube_utils::get_input_string('_default_addressbook', rcube_utils::INPUT_POST, true), - 'collected_recipients' => rcube_utils::get_input_string('_collected_recipients', rcube_utils::INPUT_POST, true), - 'collected_senders' => rcube_utils::get_input_string('_collected_senders', rcube_utils::INPUT_POST, true), - 'autocomplete_single' => isset($_POST['_autocomplete_single']), - 'addressbook_sort_col' => self::prefs_input('addressbook_sort_col', '/^[a-z_]+$/'), - 'addressbook_name_listing' => self::prefs_input_int('addressbook_name_listing'), - 'addressbook_pagesize' => max(2, self::prefs_input_int('addressbook_pagesize')), - 'contact_form_mode' => self::prefs_input('contact_form_mode', '/^(private|business)$/'), - ]; - - break; - - case 'server': - $a_user_prefs = [ - 'read_when_deleted' => isset($_POST['_read_when_deleted']), - 'skip_deleted' => isset($_POST['_skip_deleted']), - 'flag_for_deletion' => isset($_POST['_flag_for_deletion']), - 'delete_junk' => isset($_POST['_delete_junk']), - 'logout_purge' => self::prefs_input('logout_purge', '/^(all|never|30|60|90)$/'), - 'logout_expunge' => isset($_POST['_logout_expunge']), - ]; - - break; - - case 'folders': - $a_user_prefs = [ - 'show_real_foldernames' => isset($_POST['_show_real_foldernames']), - // stop using SPECIAL-USE (#4782) - 'lock_special_folders' => !in_array('lock_special_folders', $dont_override), - ]; - - foreach (rcube_storage::$folder_types as $type) { - $a_user_prefs[$type . '_mbox'] = rcube_utils::get_input_string('_' . $type . '_mbox', rcube_utils::INPUT_POST, true); - }; - - break; - - case 'encryption': - $a_user_prefs = [ - 'mailvelope_main_keyring' => isset($_POST['_mailvelope_main_keyring']), - ]; - - break; + case 'general': + $a_user_prefs = [ + 'language' => self::prefs_input('language', '/^[a-zA-Z0-9_-]+$/'), + 'timezone' => self::prefs_input('timezone', '/^[a-zA-Z_\/-]+$/'), + 'date_format' => self::prefs_input('date_format', '/^[a-zA-Z_.\/ -]+$/'), + 'time_format' => self::prefs_input('time_format', '/^[a-zA-Z0-9: ]+$/'), + 'prettydate' => isset($_POST['_pretty_date']), + 'display_next' => isset($_POST['_display_next']), + 'refresh_interval' => self::prefs_input_int('refresh_interval') * 60, + 'standard_windows' => isset($_POST['_standard_windows']), + 'skin' => self::prefs_input('skin', '/^[a-zA-Z0-9_.-]+$/'), + ]; + + // compose derived date/time format strings + if ( + (isset($_POST['_date_format']) || isset($_POST['_time_format'])) + && !empty($a_user_prefs['date_format']) + && !empty($a_user_prefs['time_format']) + ) { + $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format']; + $a_user_prefs['date_long'] = $a_user_prefs['date_format'] . ' ' . $a_user_prefs['time_format']; + } + + break; + + case 'mailbox': + $a_user_prefs = [ + 'layout' => self::prefs_input('layout', '/^[a-z]+$/'), + 'mail_read_time' => self::prefs_input_int('mail_read_time'), + 'autoexpand_threads' => self::prefs_input_int('autoexpand_threads'), + 'check_all_folders' => isset($_POST['_check_all_folders']), + 'mail_pagesize' => max(2, self::prefs_input_int('mail_pagesize')), + ]; + + break; + + case 'mailview': + $a_user_prefs = [ + 'message_extwin' => self::prefs_input_int('message_extwin'), + 'message_show_email' => isset($_POST['_message_show_email']), + 'prefer_html' => isset($_POST['_prefer_html']), + 'inline_images' => isset($_POST['_inline_images']), + 'show_images' => self::prefs_input_int('show_images'), + 'mdn_requests' => self::prefs_input_int('mdn_requests'), + 'default_charset' => self::prefs_input('default_charset', '/^[a-zA-Z0-9-]+$/'), + ]; + + break; + + case 'compose': + $a_user_prefs = [ + 'compose_extwin' => self::prefs_input_int('compose_extwin'), + 'htmleditor' => self::prefs_input_int('htmleditor'), + 'draft_autosave' => self::prefs_input_int('draft_autosave'), + 'mime_param_folding' => self::prefs_input_int('mime_param_folding'), + 'force_7bit' => isset($_POST['_force_7bit']), + 'mdn_default' => isset($_POST['_mdn_default']), + 'dsn_default' => isset($_POST['_dsn_default']), + 'reply_same_folder' => isset($_POST['_reply_same_folder']), + 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']), + 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']), + 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']), + 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']), + 'show_sig' => self::prefs_input_int('show_sig'), + 'reply_mode' => self::prefs_input_int('reply_mode'), + 'sig_below' => isset($_POST['_sig_below']), + 'strip_existing_sig' => isset($_POST['_strip_existing_sig']), + 'sig_separator' => isset($_POST['_sig_separator']), + 'default_font' => self::prefs_input('default_font', '/^[a-zA-Z ]+$/'), + 'default_font_size' => self::prefs_input('default_font_size', '/^[0-9]+pt$/'), + 'reply_all_mode' => self::prefs_input_int('reply_all_mode'), + 'forward_attachment' => !empty($_POST['_forward_attachment']), + 'compose_save_localstorage' => self::prefs_input_int('compose_save_localstorage'), + ]; + + break; + + case 'addressbook': + $a_user_prefs = [ + 'default_addressbook' => rcube_utils::get_input_string('_default_addressbook', rcube_utils::INPUT_POST, true), + 'collected_recipients' => rcube_utils::get_input_string('_collected_recipients', rcube_utils::INPUT_POST, true), + 'collected_senders' => rcube_utils::get_input_string('_collected_senders', rcube_utils::INPUT_POST, true), + 'autocomplete_single' => isset($_POST['_autocomplete_single']), + 'addressbook_sort_col' => self::prefs_input('addressbook_sort_col', '/^[a-z_]+$/'), + 'addressbook_name_listing' => self::prefs_input_int('addressbook_name_listing'), + 'addressbook_pagesize' => max(2, self::prefs_input_int('addressbook_pagesize')), + 'contact_form_mode' => self::prefs_input('contact_form_mode', '/^(private|business)$/'), + ]; + + break; + + case 'server': + $a_user_prefs = [ + 'read_when_deleted' => isset($_POST['_read_when_deleted']), + 'skip_deleted' => isset($_POST['_skip_deleted']), + 'flag_for_deletion' => isset($_POST['_flag_for_deletion']), + 'delete_junk' => isset($_POST['_delete_junk']), + 'logout_purge' => self::prefs_input('logout_purge', '/^(all|never|30|60|90)$/'), + 'logout_expunge' => isset($_POST['_logout_expunge']), + ]; + + break; + + case 'folders': + $a_user_prefs = [ + 'show_real_foldernames' => isset($_POST['_show_real_foldernames']), + // stop using SPECIAL-USE (#4782) + 'lock_special_folders' => !in_array('lock_special_folders', $dont_override), + ]; + + foreach (rcube_storage::$folder_types as $type) { + $a_user_prefs[$type . '_mbox'] = rcube_utils::get_input_string('_' . $type . '_mbox', rcube_utils::INPUT_POST, true); + }; + + break; + + case 'encryption': + $a_user_prefs = [ + 'mailvelope_main_keyring' => isset($_POST['_mailvelope_main_keyring']), + ]; + + break; } $plugin = rcmail::get_instance()->plugins->exec_hook('preferences_save', @@ -173,78 +173,78 @@ public function run($args = []) // verify some options switch ($CURR_SECTION) { - case 'general': - // switch UI language - if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) { - $rcmail->load_language($a_user_prefs['language']); - $rcmail->output->command('reload', 500); - } - - // switch skin (if valid, otherwise unset the pref and fall back to default) - if (!empty($a_user_prefs['skin'])) { - if (!$rcmail->output->check_skin($a_user_prefs['skin'])) { - unset($a_user_prefs['skin']); - } - else if ($rcmail->config->get('skin') != $a_user_prefs['skin']) { + case 'general': + // switch UI language + if (isset($_POST['_language']) && $a_user_prefs['language'] != $_SESSION['language']) { + $rcmail->load_language($a_user_prefs['language']); $rcmail->output->command('reload', 500); } - } - $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone']; + // switch skin (if valid, otherwise unset the pref and fall back to default) + if (!empty($a_user_prefs['skin'])) { + if (!$rcmail->output->check_skin($a_user_prefs['skin'])) { + unset($a_user_prefs['skin']); + } + else if ($rcmail->config->get('skin') != $a_user_prefs['skin']) { + $rcmail->output->command('reload', 500); + } + } + + $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone']; - $min_refresh_interval = (int) $rcmail->config->get('min_refresh_interval'); - if (!empty($a_user_prefs['refresh_interval']) && $min_refresh_interval) { - if ($a_user_prefs['refresh_interval'] < $min_refresh_interval) { - $a_user_prefs['refresh_interval'] = $min_refresh_interval; + $min_refresh_interval = (int) $rcmail->config->get('min_refresh_interval'); + if (!empty($a_user_prefs['refresh_interval']) && $min_refresh_interval) { + if ($a_user_prefs['refresh_interval'] < $min_refresh_interval) { + $a_user_prefs['refresh_interval'] = $min_refresh_interval; + } } - } - break; + break; - case 'mailbox': - // force min size - if ($a_user_prefs['mail_pagesize'] < 1) { - $a_user_prefs['mail_pagesize'] = 10; - } + case 'mailbox': + // force min size + if ($a_user_prefs['mail_pagesize'] < 1) { + $a_user_prefs['mail_pagesize'] = 10; + } - $max_pagesize = (int) $rcmail->config->get('max_pagesize'); - if ($max_pagesize && ($a_user_prefs['mail_pagesize'] > $max_pagesize)) { - $a_user_prefs['mail_pagesize'] = $max_pagesize; - } + $max_pagesize = (int) $rcmail->config->get('max_pagesize'); + if ($max_pagesize && ($a_user_prefs['mail_pagesize'] > $max_pagesize)) { + $a_user_prefs['mail_pagesize'] = $max_pagesize; + } - break; + break; - case 'addressbook': - // force min size - if ($a_user_prefs['addressbook_pagesize'] < 1) { - $a_user_prefs['addressbook_pagesize'] = 10; - } + case 'addressbook': + // force min size + if ($a_user_prefs['addressbook_pagesize'] < 1) { + $a_user_prefs['addressbook_pagesize'] = 10; + } - $max_pagesize = (int) $rcmail->config->get('max_pagesize'); - if ($max_pagesize && ($a_user_prefs['addressbook_pagesize'] > $max_pagesize)) { - $a_user_prefs['addressbook_pagesize'] = $max_pagesize; - } + $max_pagesize = (int) $rcmail->config->get('max_pagesize'); + if ($max_pagesize && ($a_user_prefs['addressbook_pagesize'] > $max_pagesize)) { + $a_user_prefs['addressbook_pagesize'] = $max_pagesize; + } - break; + break; - case 'folders': - $storage = $rcmail->get_storage(); - $specials = []; + case 'folders': + $storage = $rcmail->get_storage(); + $specials = []; - foreach (rcube_storage::$folder_types as $type) { - $specials[$type] = $a_user_prefs[$type . '_mbox']; - } + foreach (rcube_storage::$folder_types as $type) { + $specials[$type] = $a_user_prefs[$type . '_mbox']; + } - $storage->set_special_folders($specials); + $storage->set_special_folders($specials); - break; + break; - case 'server': - if (isset($a_user_prefs['logout_purge']) && !is_numeric($a_user_prefs['logout_purge'])) { - $a_user_prefs['logout_purge'] = $a_user_prefs['logout_purge'] !== 'never'; - } + case 'server': + if (isset($a_user_prefs['logout_purge']) && !is_numeric($a_user_prefs['logout_purge'])) { + $a_user_prefs['logout_purge'] = $a_user_prefs['logout_purge'] !== 'never'; + } - break; + break; } // Save preferences diff --git a/program/actions/settings/response_create.php b/program/actions/settings/response_create.php index 7440d332af3..38003f230ad 100644 --- a/program/actions/settings/response_create.php +++ b/program/actions/settings/response_create.php @@ -1,6 +1,6 @@ plugins->is_plugin_task($task)) { - if (!$this->action) $this->action = 'index'; + if (!$this->action) { + $this->action = 'index'; + } $this->plugins->exec_action("{$task}.{$this->action}"); break; } diff --git a/program/include/rcmail_action.php b/program/include/rcmail_action.php index 4544512cd2a..78a9dd528f1 100644 --- a/program/include/rcmail_action.php +++ b/program/include/rcmail_action.php @@ -1,6 +1,6 @@ storage->get_error_code(); switch ($err_code) { - // Not all are really fatal, but these should catch - // connection/authentication errors the best we can - case rcube_imap_generic::ERROR_NO: - case rcube_imap_generic::ERROR_BAD: - case rcube_imap_generic::ERROR_BYE: - self::display_server_error(); + // Not all are really fatal, but these should catch + // connection/authentication errors the best we can + case rcube_imap_generic::ERROR_NO: + case rcube_imap_generic::ERROR_BAD: + case rcube_imap_generic::ERROR_BYE: + self::display_server_error(); } } diff --git a/program/include/rcmail_attachment_handler.php b/program/include/rcmail_attachment_handler.php index 8f34781fbc6..1e6228ed815 100644 --- a/program/include/rcmail_attachment_handler.php +++ b/program/include/rcmail_attachment_handler.php @@ -1,6 +1,6 @@ 'LOG_AUTH', 80 => 'LOG_AUTHPRIV', 72 => ' LOG_CRON', - 24 => 'LOG_DAEMON', 0 => 'LOG_KERN', 128 => 'LOG_LOCAL0', - 136 => 'LOG_LOCAL1', 144 => 'LOG_LOCAL2', 152 => 'LOG_LOCAL3', - 160 => 'LOG_LOCAL4', 168 => 'LOG_LOCAL5', 176 => 'LOG_LOCAL6', - 184 => 'LOG_LOCAL7', 48 => 'LOG_LPR', 16 => 'LOG_MAIL', - 56 => 'LOG_NEWS', 40 => 'LOG_SYSLOG', 8 => 'LOG_USER', 64 => 'LOG_UUCP' - ]; + case 'syslog_facility': + $list = [ + 32 => 'LOG_AUTH', 80 => 'LOG_AUTHPRIV', 72 => ' LOG_CRON', + 24 => 'LOG_DAEMON', 0 => 'LOG_KERN', 128 => 'LOG_LOCAL0', + 136 => 'LOG_LOCAL1', 144 => 'LOG_LOCAL2', 152 => 'LOG_LOCAL3', + 160 => 'LOG_LOCAL4', 168 => 'LOG_LOCAL5', 176 => 'LOG_LOCAL6', + 184 => 'LOG_LOCAL7', 48 => 'LOG_LPR', 16 => 'LOG_MAIL', + 56 => 'LOG_NEWS', 40 => 'LOG_SYSLOG', 8 => 'LOG_USER', 64 => 'LOG_UUCP' + ]; - if (!empty($list[$var])) { - return $list[$var]; - } + if (!empty($list[$var])) { + return $list[$var]; + } - break; + break; } if (is_array($var)) { diff --git a/program/include/rcmail_oauth.php b/program/include/rcmail_oauth.php index bcce3f25633..47dd9f8b083 100644 --- a/program/include/rcmail_oauth.php +++ b/program/include/rcmail_oauth.php @@ -1,6 +1,6 @@ message) { if ($this->app->text_exists($message)) { if (!empty($vars)) { - $vars = array_map(['rcube','Q'], $vars); + $vars = array_map(['rcube', 'Q'], $vars); } $msgtext = $this->app->gettext(['name' => $message, 'vars' => $vars]); @@ -975,7 +975,7 @@ public function asset_url($path, $abs_url = false) } - /***** Template parsing methods *****/ + /* Template parsing methods */ /** * Replace all strings ($varname) @@ -1128,51 +1128,51 @@ protected function parse_conditions($input) $tag_name = strtolower($matches[1][0]); switch ($tag_name) { - case 'if': - $level++; - break; - - case 'endif': - if (!$level--) { - $endif = $tag_end; - if ($content_end === null) { - $content_end = $tag_start; - } - break 2; - } - break; + case 'if': + $level++; + break; - case 'elseif': - if (!$level) { - if ($condmet) { + case 'endif': + if (!$level--) { + $endif = $tag_end; if ($content_end === null) { $content_end = $tag_start; } + break 2; } - else { - // Process the 'condition' attribute - $attrib = html::parse_attrib_string($matches[2][0]); - $condmet = isset($attrib['condition']) && $this->check_condition($attrib['condition']); + break; + case 'elseif': + if (!$level) { if ($condmet) { - $content_start = $tag_end; + if ($content_end === null) { + $content_end = $tag_start; + } } - } - } - break; + else { + // Process the 'condition' attribute + $attrib = html::parse_attrib_string($matches[2][0]); + $condmet = isset($attrib['condition']) && $this->check_condition($attrib['condition']); - case 'else': - if (!$level) { - if ($condmet) { - if ($content_end === null) { - $content_end = $tag_start; + if ($condmet) { + $content_start = $tag_end; + } } } - else { - $content_start = $tag_end; + break; + + case 'else': + if (!$level) { + if ($condmet) { + if ($content_end === null) { + $content_end = $tag_start; + } + } + else { + $content_start = $tag_end; + } } - } - break; + break; } $n = $tag_end; @@ -1357,12 +1357,12 @@ protected function xml_command($matches) } break; - // frame + // frame (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'frame': return $this->frame($attrib); break; - // show a label + // show a label (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'label': if (!empty($attrib['expression'])) { $attrib['name'] = $this->eval_expression($attrib['expression']); @@ -1408,7 +1408,7 @@ protected function xml_command($matches) $this->add_label($attrib['name']); break; - // include a file + // include a file (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'include': if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) { break; @@ -1448,7 +1448,7 @@ protected function xml_command($matches) $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib + ['content' => '']); return $hook['content']; - // define a container block + // define a container block (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'container': if (!empty($attrib['name']) && !empty($attrib['id'])) { $this->command('gui_container', $attrib['name'], $attrib['id']); @@ -1458,7 +1458,7 @@ protected function xml_command($matches) } break; - // return code for a specific application object + // return code for a specific application object (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'object': $object = strtolower($attrib['name']); $content = ''; @@ -1534,15 +1534,16 @@ protected function xml_command($matches) $ver = (string) RCMAIL_VERSION; if (is_file(RCUBE_INSTALL_PATH . '.svn/entries')) { if (function_exists('shell_exec')) { - if (preg_match('/Revision:\s(\d+)/', (string)@shell_exec('svn info'), $regs)) + if (preg_match('/Revision:\s(\d+)/', (string) @shell_exec('svn info'), $regs)) { $ver .= ' [SVN r' . $regs[1] . ']'; + } } else { $ver .= ' [SVN]'; } } else if (is_file(RCUBE_INSTALL_PATH . '.git/index')) { if (function_exists('shell_exec')) { - if (preg_match('/Date:\s+([^\n]+)/', (string)@shell_exec('git log -1'), $regs)) { + if (preg_match('/Date:\s+([^\n]+)/', (string) @shell_exec('git log -1'), $regs)) { if ($date = date('Ymd.Hi', strtotime($regs[1]))) { $ver .= ' [GIT ' . $date . ']'; } @@ -1630,7 +1631,7 @@ protected function xml_command($matches) return $hook['content']; - // return element + // return element (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'link': if ($attrib['condition'] && !$this->check_condition($attrib['condition'])) { break; @@ -1641,11 +1642,11 @@ protected function xml_command($matches) return html::tag('link', $attrib); - // return code for a specified eval expression + // return code for a specified eval expression (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'exp': return html::quote($this->eval_expression($attrib['expression'])); - // return variable + // return variable (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) case 'var': $var = explode(':', $attrib['name']); $value = $this->parse_variable($var[0], $var[1]); @@ -1848,7 +1849,7 @@ public function button($attrib) $attrib['href'] = $this->app->url(['action' => $attrib['command']]); } else if (($attrib['command'] == 'permaurl' || $attrib['command'] == 'extwin') && !empty($this->env['permaurl'])) { - $attrib['href'] = $this->env['permaurl']; + $attrib['href'] = $this->env['permaurl']; } } @@ -2021,11 +2022,11 @@ protected function _write($output = '') $is_empty = true; } - $merge_script_files = function($output, $script) { + $merge_script_files = function ($output, $script) { return $output . html::script($script); }; - $merge_scripts = function($output, $script) { + $merge_scripts = function ($output, $script) { return $output . html::script([], $script); }; diff --git a/program/include/rcmail_output_json.php b/program/include/rcmail_output_json.php index 8dccbc85527..978511bf09f 100644 --- a/program/include/rcmail_output_json.php +++ b/program/include/rcmail_output_json.php @@ -1,6 +1,6 @@ options['sendmail_delay'] = (int) $this->rcmail->config->get('sendmail_delay'); if (empty($options['error_handler'])) { - $this->options['error_handler'] = function() { return false; }; + $this->options['error_handler'] = function () { return false; }; } if (empty($this->data['mode'])) { @@ -902,7 +902,7 @@ public static function draftinfo_decode($str) */ public function headers_output($attrib) { - list($form_start,) = $this->form_tags($attrib); + list($form_start) = $this->form_tags($attrib); $out = ''; $part = strtolower($attrib['part']); @@ -912,33 +912,33 @@ public function headers_output($attrib) $param = $part; switch ($part) { - case 'from': - return $form_start . $this->compose_header_from($attrib); - - case 'to': - case 'cc': - case 'bcc': - $fname = '_' . $part; - - $allow_attrib = ['id', 'class', 'style', 'cols', 'rows', 'tabindex']; - $field_type = 'html_textarea'; - break; - - case 'replyto': - case 'reply-to': - $fname = '_replyto'; - $param = 'replyto'; - - case 'followupto': - case 'followup-to': - if (!$fname) { - $fname = '_followupto'; - $param = 'followupto'; - } + case 'from': + return $form_start . $this->compose_header_from($attrib); + + case 'to': + case 'cc': + case 'bcc': + $fname = '_' . $part; + + $allow_attrib = ['id', 'class', 'style', 'cols', 'rows', 'tabindex']; + $field_type = 'html_textarea'; + break; + + case 'replyto': + case 'reply-to': + $fname = '_replyto'; + $param = 'replyto'; + + case 'followupto': + case 'followup-to': + if (!$fname) { + $fname = '_followupto'; + $param = 'followupto'; + } - $allow_attrib = ['id', 'class', 'style', 'size', 'tabindex']; - $field_type = 'html_inputfield'; - break; + $allow_attrib = ['id', 'class', 'style', 'size', 'tabindex']; + $field_type = 'html_inputfield'; + break; } if ($fname && $field_type) { @@ -1222,7 +1222,7 @@ public static function reply_subject($subject) { $subject = trim($subject); - // Add config options for subject prefixes (#7929) + // Add config options for subject prefixes (#7929) $subject = rcube_utils::remove_subject_prefix($subject, 'reply'); $subject = rcmail::get_instance()->config->get('response_prefix', 'Re:') . ' ' . $subject; @@ -1260,7 +1260,7 @@ public function compose_subject($attrib) } // create a forward-subject else if ($this->data['mode'] == self::MODE_FORWARD) { - // Add config options for subject prefixes (#7929) + // Add config options for subject prefixes (#7929) $subject = rcube_utils::remove_subject_prefix($this->options['message']->subject, 'forward'); $subject = trim($this->rcmail->config->get('forward_prefix', 'Fwd:') . ' ' . $subject); } @@ -1323,7 +1323,7 @@ public function form_tags($attrib) */ public function form_head($attrib) { - list($form_start,) = $this->form_tags($attrib); + list($form_start) = $this->form_tags($attrib); return $form_start; } diff --git a/program/include/rcmail_string_replacer.php b/program/include/rcmail_string_replacer.php index 483d553f31b..dfdceef9dc4 100644 --- a/program/include/rcmail_string_replacer.php +++ b/program/include/rcmail_string_replacer.php @@ -1,6 +1,6 @@ config->get('db_dsnw')); - $db->set_debug((bool)$rc->config->get('sql_debug')); + $db->set_debug((bool) $rc->config->get('sql_debug')); // Connect to database $db->db_connect('w'); @@ -112,7 +112,7 @@ public static function db_update($dir, $package, $ver = null, $opts = []) $db = self::db(); // Read DB schema version from database (if 'system' table exists) - if (in_array($db->table_name('system'), (array)$db->list_tables())) { + if (in_array($db->table_name('system'), (array) $db->list_tables())) { $version = self::db_version($package); } diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php index 4e65b3219ff..73f03e8b6c6 100644 --- a/program/lib/Roundcube/bootstrap.php +++ b/program/lib/Roundcube/bootstrap.php @@ -1,6 +1,6 @@ db->query( - "SELECT `data`, `cache_key` FROM {$this->table} WHERE " - . ($this->userid ? "`user_id` = {$this->userid} AND " : "") - ."`cache_key` = ?", - $this->prefix . '.' . $key); + "SELECT `data`, `cache_key` FROM {$this->table} WHERE " + . ($this->userid ? "`user_id` = {$this->userid} AND " : "") + ."`cache_key` = ?", + $this->prefix . '.' . $key); $data = null; diff --git a/program/lib/Roundcube/cache/memcache.php b/program/lib/Roundcube/cache/memcache.php index b6924524688..f00b1093174 100644 --- a/program/lib/Roundcube/cache/memcache.php +++ b/program/lib/Roundcube/cache/memcache.php @@ -1,6 +1,6 @@ config->get('memcache_hosts') as $host) { if (substr($host, 0, 7) != 'unix://') { list($host, $port) = explode(':', $host); - if (!$port) $port = 11211; + if (!$port) { + $port = 11211; + } } else { $port = 0; diff --git a/program/lib/Roundcube/cache/memcached.php b/program/lib/Roundcube/cache/memcached.php index 77b4f4e11b1..c791eef7362 100644 --- a/program/lib/Roundcube/cache/memcached.php +++ b/program/lib/Roundcube/cache/memcached.php @@ -1,6 +1,6 @@ quote($i); }, $keys)); + $vals = implode(', ', array_map(function ($i) { return $this->quote($i); }, $keys)); $vals .= ', ' . rtrim(str_repeat('?, ', count($columns)), ', '); - $update = implode(', ', array_map(function($i) { return "$i = VALUES($i)"; }, $columns)); + $update = implode(', ', array_map(function ($i) { return "$i = VALUES($i)"; }, $columns)); return $this->query("INSERT INTO $table ($cols) VALUES ($vals)" . " ON DUPLICATE KEY UPDATE $update", $values); diff --git a/program/lib/Roundcube/db/param.php b/program/lib/Roundcube/db/param.php index fe0a4027314..6a48663cfa5 100644 --- a/program/lib/Roundcube/db/param.php +++ b/program/lib/Roundcube/db/param.php @@ -1,6 +1,6 @@ quote($i); }, $keys)); + $vals = implode(', ', array_map(function ($i) { return $this->quote($i); }, $keys)); $vals .= ', ' . rtrim(str_repeat('?, ', count($columns)), ', '); - $update = implode(', ', array_map(function($i) { return "$i = EXCLUDED.$i"; }, $columns)); + $update = implode(', ', array_map(function ($i) { return "$i = EXCLUDED.$i"; }, $columns)); return $this->query("INSERT INTO $table ($cols) VALUES ($vals)" . " ON CONFLICT ($target) DO UPDATE SET $update", $values); diff --git a/program/lib/Roundcube/db/sqlite.php b/program/lib/Roundcube/db/sqlite.php index 87e9c83847b..723e48db82e 100644 --- a/program/lib/Roundcube/db/sqlite.php +++ b/program/lib/Roundcube/db/sqlite.php @@ -1,6 +1,6 @@ tagname, $this->attrib, $this->content, array_merge(self::$common_attrib, $this->allowed)); } - /****** STATIC METHODS *******/ + /* STATIC METHODS */ /** * Generic method to create a HTML tag @@ -163,7 +163,7 @@ public static function img($attr = null) $attr = ['src' => $attr]; } - $allowed = ['src','alt','width','height','border','usemap','onclick','onerror','onload']; + $allowed = ['src', 'alt', 'width', 'height', 'border', 'usemap', 'onclick', 'onerror', 'onload']; return self::tag('img', $attr + ['alt' => ''], null, array_merge(self::$common_attrib, $allowed)); } @@ -183,7 +183,7 @@ public static function a($attr, $cont) $attr = ['href' => $attr]; } - $allowed = ['href','target','name','rel','onclick','onmouseover','onmouseout','onmousedown','onmouseup']; + $allowed = ['href', 'target', 'name', 'rel', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup']; return self::tag('a', $attr, $cont, array_merge(self::$common_attrib, $allowed)); } @@ -221,7 +221,7 @@ public static function label($attr, $cont) $attr = ['for' => $attr]; } - return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, ['for','onkeypress'])); + return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, ['for', 'onkeypress'])); } /** @@ -239,7 +239,7 @@ public static function iframe($attr = null, $cont = null) $attr = ['src' => $attr]; } - $allowed = ['src','name','width','height','border','frameborder','onload','allowfullscreen']; + $allowed = ['src', 'name', 'width', 'height', 'border', 'frameborder', 'onload', 'allowfullscreen']; return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib, $allowed)); } @@ -406,10 +406,10 @@ class html_inputfield extends html protected $tagname = 'input'; protected $type = 'text'; protected $allowed = [ - 'type','name','value','size','tabindex','autocapitalize','required', - 'autocomplete','checked','onchange','onclick','disabled','readonly', - 'spellcheck','results','maxlength','src','multiple','accept', - 'placeholder','autofocus','pattern','oninput' + 'type', 'name', 'value', 'size', 'tabindex', 'autocapitalize', 'required', + 'autocomplete', 'checked', 'onchange', 'onclick', 'disabled', 'readonly', + 'spellcheck', 'results', 'maxlength', 'src', 'multiple', 'accept', + 'placeholder', 'autofocus', 'pattern', 'oninput' ]; /** @@ -475,7 +475,7 @@ class html_hiddenfield extends html { protected $tagname = 'input'; protected $type = 'hidden'; - protected $allowed = ['type','name','value','onchange','disabled','readonly']; + protected $allowed = ['type', 'name', 'value', 'onchange', 'disabled', 'readonly']; protected $fields = []; /** @@ -601,8 +601,8 @@ public function show($content = '', $attrib = null) class html_textarea extends html { protected $tagname = 'textarea'; - protected $allowed = ['name','rows','cols','wrap','tabindex', - 'onchange','disabled','readonly','spellcheck']; + protected $allowed = ['name', 'rows', 'cols', 'wrap', 'tabindex', + 'onchange', 'disabled', 'readonly', 'spellcheck']; /** * Get HTML code for this object @@ -662,8 +662,8 @@ class html_select extends html { protected $tagname = 'select'; protected $options = []; - protected $allowed = ['name','size','tabindex','autocomplete', - 'multiple','onchange','disabled','rel']; + protected $allowed = ['name', 'size', 'tabindex', 'autocomplete', + 'multiple', 'onchange', 'disabled', 'rel']; /** * Add a new option to this drop-down @@ -716,7 +716,7 @@ public function show($select = [], $attrib = null) $option_content = self::quote($option_content); } - $allowed = ['value','label','class','style','title','disabled','selected']; + $allowed = ['value', 'label', 'class', 'style', 'title', 'disabled', 'selected']; $this->content .= self::tag('option', $attr + $option, $option_content, $allowed); } @@ -734,8 +734,8 @@ public function show($select = [], $attrib = null) class html_table extends html { protected $tagname = 'table'; - protected $allowed = ['id','class','style','width','summary', - 'cellpadding','cellspacing','border']; + protected $allowed = ['id', 'class', 'style', 'width', 'summary', + 'cellpadding', 'cellspacing', 'border']; private $header = null; private $rows = []; @@ -753,8 +753,8 @@ public function __construct($attrib = []) $this->attrib = array_merge($attrib, $default_attrib); if (!empty($attrib['tagname']) && $attrib['tagname'] != 'table') { - $this->tagname = $attrib['tagname']; - $this->allowed = self::$common_attrib; + $this->tagname = $attrib['tagname']; + $this->allowed = self::$common_attrib; } } diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 8c076ca98f5..c616610c71d 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -1,6 +1,6 @@ config->get('db_persistent') ); - $this->db->set_debug((bool)$this->config->get('sql_debug')); + $this->db->set_debug((bool) $this->config->get('sql_debug')); } return $this->db; @@ -832,7 +832,7 @@ protected function language_prop($lang) } if (empty($rcube_languages)) { - @include(RCUBE_LOCALIZATION_DIR . 'index.inc'); + @include RCUBE_LOCALIZATION_DIR . 'index.inc'; } // check if we have an alias for that language @@ -870,7 +870,7 @@ public function list_languages() static $sa_languages = []; if (!count($sa_languages)) { - @include(RCUBE_LOCALIZATION_DIR . 'index.inc'); + @include RCUBE_LOCALIZATION_DIR . 'index.inc'; if ($dh = @opendir(RCUBE_LOCALIZATION_DIR)) { while (($name = readdir($dh)) !== false) { @@ -1247,7 +1247,7 @@ public static function exec($cmd, ...$args) $parts[] = $value ? $key : ""; } else { - foreach ((array)$value as $val) { + foreach ((array) $value as $val) { $parts[] = "$key " . escapeshellarg($val); } } @@ -1590,7 +1590,7 @@ public function set_user($user) $this->user = $user; // overwrite config with user preferences - $this->config->set_user_prefs((array)$this->user->get_prefs()); + $this->config->set_user_prefs((array) $this->user->get_prefs()); } } diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 6b58f3fb00d..398941cc34d 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -1,6 +1,6 @@ plugins->exec_hook('contact_listname', ['contact' => $contact]); - $fn = $plugin['fn']; + break; + case 1: + $keys = ['firstname', 'middlename', 'surname']; + $fn = implode(' ', $get_names($contact, $keys)); + break; + case 0: + if (!empty($contact['name'])) { + $fn = $contact['name']; + } + else { + $keys = ['prefix', 'firstname', 'middlename', 'surname', 'suffix']; + $fn = implode(' ', $get_names($contact, $keys)); + } + break; + default: + $plugin = rcube::get_instance()->plugins->exec_hook('contact_listname', ['contact' => $contact]); + $fn = $plugin['fn']; } $fn = trim($fn, ', '); @@ -779,20 +779,20 @@ public static function compose_search_name($contact, $email = null, $name = null $value = ''; switch ($key) { - case 'name': - $value = $name ?: self::compose_list_name($contact); + case 'name': + $value = $name ?: self::compose_list_name($contact); - // If name(s) are undefined compose_list_name() may return an email address - // here we prevent from returning the same name and email - if ($name === $email && strpos($result, '{email}') !== false) { - $value = ''; - } + // If name(s) are undefined compose_list_name() may return an email address + // here we prevent from returning the same name and email + if ($name === $email && strpos($result, '{email}') !== false) { + $value = ''; + } - break; + break; - case 'email': - $value = $email; - break; + case 'email': + $value = $email; + break; } if (empty($value)) { @@ -831,7 +831,7 @@ public static function compose_contact_key($contact, $sort_col) // add email to a key to not skip contacts with the same name (#1488375) if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) { - $key .= ':' . implode(':', (array)$email); + $key .= ':' . implode(':', (array) $email); } // Make the key really unique (as we e.g. support contacts with no email) diff --git a/program/lib/Roundcube/rcube_addresses.php b/program/lib/Roundcube/rcube_addresses.php index 4b261f558f1..1d245fbf615 100644 --- a/program/lib/Roundcube/rcube_addresses.php +++ b/program/lib/Roundcube/rcube_addresses.php @@ -1,6 +1,6 @@ 100 * 1024 ? substr($str, 0, 100 * 1024) : $str; // Add dehault charset, system charset and easily detectable charset to the list - if (substr($chunk, 0, 4) == "\0\0\xFE\xFF") $charsets[] = 'UTF-32BE'; - if (substr($chunk, 0, 4) == "\xFF\xFE\0\0") $charsets[] = 'UTF-32LE'; - if (substr($chunk, 0, 2) == "\xFE\xFF") $charsets[] = 'UTF-16BE'; - if (substr($chunk, 0, 2) == "\xFF\xFE") $charsets[] = 'UTF-16LE'; + if (substr($chunk, 0, 4) == "\0\0\xFE\xFF") { + $charsets[] = 'UTF-32BE'; + } + if (substr($chunk, 0, 4) == "\xFF\xFE\0\0") { + $charsets[] = 'UTF-32LE'; + } + if (substr($chunk, 0, 2) == "\xFE\xFF") { + $charsets[] = 'UTF-16BE'; + } + if (substr($chunk, 0, 2) == "\xFF\xFE") { + $charsets[] = 'UTF-16LE'; + } // heuristics - if (preg_match('/\x00\x00\x00[^\x00]/', $chunk)) $charsets[] = 'UTF-32BE'; - if (preg_match('/[^\x00]\x00\x00\x00/', $chunk)) $charsets[] = 'UTF-32LE'; - if (preg_match('/\x00[^\x00]\x00[^\x00]/', $chunk)) $charsets[] = 'UTF-16BE'; - if (preg_match('/[^\x00]\x00[^\x00]\x00/', $chunk)) $charsets[] = 'UTF-16LE'; + if (preg_match('/\x00\x00\x00[^\x00]/', $chunk)) { + $charsets[] = 'UTF-32BE'; + } + if (preg_match('/[^\x00]\x00\x00\x00/', $chunk)) { + $charsets[] = 'UTF-32LE'; + } + if (preg_match('/\x00[^\x00]\x00[^\x00]/', $chunk)) { + $charsets[] = 'UTF-16BE'; + } + if (preg_match('/[^\x00]\x00[^\x00]\x00/', $chunk)) { + $charsets[] = 'UTF-16LE'; + } $charsets[] = RCUBE_CHARSET; $charsets[] = (string) rcube::get_instance()->config->get('default_charset'); @@ -472,18 +488,36 @@ public static function utf8_to_utf7imap($str) */ public static function detect($string, $failover = null, $language = null) { - if (substr($string, 0, 4) == "\0\0\xFE\xFF") return 'UTF-32BE'; // Big Endian - if (substr($string, 0, 4) == "\xFF\xFE\0\0") return 'UTF-32LE'; // Little Endian - if (substr($string, 0, 2) == "\xFE\xFF") return 'UTF-16BE'; // Big Endian - if (substr($string, 0, 2) == "\xFF\xFE") return 'UTF-16LE'; // Little Endian - if (substr($string, 0, 3) == "\xEF\xBB\xBF") return 'UTF-8'; + if (substr($string, 0, 4) == "\0\0\xFE\xFF") { // Big Endian + return 'UTF-32BE'; + } + if (substr($string, 0, 4) == "\xFF\xFE\0\0") { // Little Endian + return 'UTF-32LE'; + } + if (substr($string, 0, 2) == "\xFE\xFF") { // Big Endian + return 'UTF-16BE'; + } + if (substr($string, 0, 2) == "\xFF\xFE") { // Little Endian + return 'UTF-16LE'; + } + if (substr($string, 0, 3) == "\xEF\xBB\xBF") { + return 'UTF-8'; + } // heuristics if (strlen($string) >= 4) { - if ($string[0] == "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-32BE'; - if ($string[0] != "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] == "\0") return 'UTF-32LE'; - if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-16BE'; - if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") return 'UTF-16LE'; + if ($string[0] == "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] != "\0") { + return 'UTF-32BE'; + } + if ($string[0] != "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] == "\0") { + return 'UTF-32LE'; + } + if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") { + return 'UTF-16BE'; + } + if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") { + return 'UTF-16LE'; + } } if (empty($language)) { @@ -494,30 +528,30 @@ public static function detect($string, $failover = null, $language = null) // Prioritize charsets according to the current language (#1485669) $prio = null; switch ($language) { - case 'ja_JP': - $prio = ['ISO-2022-JP', 'JIS', 'UTF-8', 'EUC-JP', 'eucJP-win', 'SJIS']; - break; - - case 'zh_CN': - case 'zh_TW': - $prio = ['UTF-8', 'BIG-5', 'EUC-TW', 'GB18030']; - break; - - case 'ko_KR': - $prio = ['UTF-8', 'EUC-KR', 'ISO-2022-KR']; - break; - - case 'ru_RU': - $prio = ['UTF-8', 'WINDOWS-1251', 'KOI8-R']; - break; - - case 'tr_TR': - $prio = ['UTF-8', 'ISO-8859-9', 'WINDOWS-1254']; - break; - - case 'sl_SI': - $prio = ['UTF-8', 'ISO-8859-2', 'WINDOWS-1251']; - break; + case 'ja_JP': + $prio = ['ISO-2022-JP', 'JIS', 'UTF-8', 'EUC-JP', 'eucJP-win', 'SJIS']; + break; + + case 'zh_CN': + case 'zh_TW': + $prio = ['UTF-8', 'BIG-5', 'EUC-TW', 'GB18030']; + break; + + case 'ko_KR': + $prio = ['UTF-8', 'EUC-KR', 'ISO-2022-KR']; + break; + + case 'ru_RU': + $prio = ['UTF-8', 'WINDOWS-1251', 'KOI8-R']; + break; + + case 'tr_TR': + $prio = ['UTF-8', 'ISO-8859-9', 'WINDOWS-1254']; + break; + + case 'sl_SI': + $prio = ['UTF-8', 'ISO-8859-2', 'WINDOWS-1251']; + break; } // mb_detect_encoding() is not reliable for some charsets (#1490135) diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php index 969f7f21789..ab7b88a7705 100644 --- a/program/lib/Roundcube/rcube_config.php +++ b/program/lib/Roundcube/rcube_config.php @@ -1,6 +1,6 @@ parse_env($string, $this->guess_type($string)); @@ -317,7 +317,7 @@ public function load_from_file($file) if ($fpath && is_file($fpath) && is_readable($fpath)) { // use output buffering, we don't need any output here ob_start(); - include($fpath); + include $fpath; ob_end_clean(); if (isset($config) && is_array($config)) { @@ -699,7 +699,9 @@ private function client_timezone() $tz = new DateTimeZone($props['timezone']); return $this->client_tz = $tz->getName(); } - catch (Exception $e) { /* gracefully ignore */ } + catch (Exception $e) { + // gracefully ignore + } } // fallback to server's timezone diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php index 9d6da8ea572..bafe17eb31f 100644 --- a/program/lib/Roundcube/rcube_contacts.php +++ b/program/lib/Roundcube/rcube_contacts.php @@ -1,6 +1,6 @@ name; - } + } /** * Save a search string for future listings @@ -650,9 +650,10 @@ function insert($save_data, $check = false) if ($check) { foreach ($save_data as $col => $values) { if (strpos($col, 'email') === 0) { - foreach ((array)$values as $email) { - if ($existing = $this->search('email', $email, false, false)) + foreach ((array) $values as $email) { + if ($existing = $this->search('email', $email, false, false)) { break 2; + } } } } diff --git a/program/lib/Roundcube/rcube_content_filter.php b/program/lib/Roundcube/rcube_content_filter.php index abe1d707678..0b55bb6295c 100644 --- a/program/lib/Roundcube/rcube_content_filter.php +++ b/program/lib/Roundcube/rcube_content_filter.php @@ -1,6 +1,6 @@ csv2vcard_map); - }); + $elements = array_filter($elements, function ($val) { + return in_array($val, $this->csv2vcard_map); + }); $this->map = $elements; } @@ -626,7 +626,7 @@ protected function csv_to_vcard($data) $contact[$name][] = $value; } else { - $contact[$name] = $value; + $contact[$name] = $value; } } } diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php index f7c18ee8f53..656221cfa1e 100644 --- a/program/lib/Roundcube/rcube_db.php +++ b/program/lib/Roundcube/rcube_db.php @@ -1,6 +1,6 @@ db_dsnr) && $this->db_dsnw != $this->db_dsnr; + return !empty($this->db_dsnr) && $this->db_dsnw != $this->db_dsnr; } /** @@ -594,11 +590,11 @@ protected function handle_error($query) */ public function insert_or_update($table, $keys, $columns, $values) { - $columns = array_map(function($i) { return "`$i`"; }, $columns); - $sets = array_map(function($i) { return "$i = ?"; }, $columns); + $columns = array_map(function ($i) { return "`$i`"; }, $columns); + $sets = array_map(function ($i) { return "$i = ?"; }, $columns); $where = $keys; - array_walk($where, function(&$val, $key) { + array_walk($where, function (&$val, $key) { $val = $this->quote_identifier($key) . " = " . $this->quote($val); }); @@ -608,9 +604,9 @@ public function insert_or_update($table, $keys, $columns, $values) // if UPDATE fails use INSERT if ($result && !$this->affected_rows($result)) { - $cols = implode(', ', array_map(function($i) { return "`$i`"; }, array_keys($keys))); + $cols = implode(', ', array_map(function ($i) { return "`$i`"; }, array_keys($keys))); $cols .= ', ' . implode(', ', $columns); - $vals = implode(', ', array_map(function($i) { return $this->quote($i); }, $keys)); + $vals = implode(', ', array_map(function ($i) { return $this->quote($i); }, $keys)); $vals .= ', ' . rtrim(str_repeat('?, ', count($columns)), ', '); $result = $this->query("INSERT INTO $table ($cols) VALUES ($vals)", $values); diff --git a/program/lib/Roundcube/rcube_enriched.php b/program/lib/Roundcube/rcube_enriched.php index 6cf4844ce5a..92b1c5cd839 100644 --- a/program/lib/Roundcube/rcube_enriched.php +++ b/program/lib/Roundcube/rcube_enriched.php @@ -1,6 +1,6 @@ ' => '', '' => '', - '' => '', '' => '', - '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', '' => '', ''=> '', '' => '', '' => '', '' => '', '' => '', - '' => '', '' => '', - '' => '', '' => '', - '' => '', '' => '', - '' => '', '' => '', - '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', + '' => '', '' => '', ]; return str_ireplace(array_keys($replace), array_values($replace), $body); diff --git a/program/lib/Roundcube/rcube_html2text.php b/program/lib/Roundcube/rcube_html2text.php index 7b964a985fd..a2efb9143f1 100644 --- a/program/lib/Roundcube/rcube_html2text.php +++ b/program/lib/Roundcube/rcube_html2text.php @@ -1,6 +1,6 @@ get_text(); + echo $this->get_text(); } /** @@ -704,7 +704,9 @@ protected function _convert_blockquotes(&$text) // adjust text wrapping width $p_width = $this->width; - if ($this->width > 0) $this->width -= 2; + if ($this->width > 0) { + $this->width -= 2; + } // replace content with inner blockquotes $this->_converter($body); @@ -751,14 +753,14 @@ public function blockquote_citation_callback($m) public function tags_preg_callback($matches) { switch (strtolower($matches[1])) { - case 'th': - return $this->_toupper("\t\t". $matches[3] ."\n"); - case 'h': - return $this->_toupper("\n\n". $matches[3] ."\n\n"); - case 'a': - // Remove spaces in URL (#1487805) - $url = str_replace(' ', '', $matches[3]); - return $this->_handle_link($url, $matches[4]); + case 'th': + return $this->_toupper("\t\t". $matches[3] ."\n"); + case 'h': + return $this->_toupper("\n\n". $matches[3] ."\n\n"); + case 'a': + // Remove spaces in URL (#1487805) + $url = str_replace(' ', '', $matches[3]); + return $this->_handle_link($url, $matches[4]); } } diff --git a/program/lib/Roundcube/rcube_image.php b/program/lib/Roundcube/rcube_image.php index 94e75764359..079504a4954 100644 --- a/program/lib/Roundcube/rcube_image.php +++ b/program/lib/Roundcube/rcube_image.php @@ -1,6 +1,6 @@ conn->connect($data['host'], $data['user'], $pass, $data); - } while(!$this->conn->connected() && $data['retry']); + } while (!$this->conn->connected() && $data['retry']); $config = [ 'host' => $data['host'], @@ -1139,7 +1139,7 @@ protected function list_search_messages($folder, $page, $slice = 0) } // Re-sort the result according to the original search set order - usort($a_msg_headers, function($a, $b) use ($index) { + usort($a_msg_headers, function ($a, $b) use ($index) { return array_search($a->uid . '-' . $a->folder, $index) - array_search($b->uid . '-' . $b->folder, $index); }); } @@ -1438,7 +1438,7 @@ public function index($folder = '', $sort_field = null, $sort_order = null, if ($this->search_set instanceof rcube_result_multifolder) { $index = $this->search_set; $index->folder = $folder; - // TODO: handle changed sorting + // TODO: handle changed sorting (>> reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7497 is fixed) } // search result is an index with the same sorting? else if (($this->search_set instanceof rcube_result_index) @@ -2042,13 +2042,13 @@ public function get_message($uid, $folder = null) protected function structure_part($part, $count = 0, $parent = '', $mime_headers = null) { $struct = new rcube_message_part; - $struct->mime_id = empty($parent) ? (string)$count : "$parent.$count"; + $struct->mime_id = empty($parent) ? (string) $count : "$parent.$count"; // multipart if (is_array($part[0])) { $struct->ctype_primary = 'multipart'; - /* RFC3501: BODYSTRUCTURE fields of multipart part + /* RFC3501: BODYSTRUCTURE fields of multipart part part1 array part2 array part3 array @@ -2058,7 +2058,7 @@ protected function structure_part($part, $count = 0, $parent = '', $mime_headers 3. description (optional) 4. language (optional) 5. location (optional) - */ + */ // find first non-array entry for ($i=1; $ifolder; } - list($uids, ) = $this->parse_uids($uids); + list($uids) = $this->parse_uids($uids); // exit if no message uids are specified if (empty($uids)) { @@ -3135,12 +3135,12 @@ protected function list_folders_filter(&$result, $root, $update_type = null) // Remove hidden folders if ($config->get('imap_skip_hidden_folders')) { - $result = array_filter($result, function($v) { return $v[0] != '.'; }); + $result = array_filter($result, function ($v) { return $v[0] != '.'; }); } // Remove folders in shared namespaces (if configured, see self::set_env()) if ($root === '*' && !empty($this->list_excludes)) { - $result = array_filter($result, function($v) { + $result = array_filter($result, function ($v) { foreach ($this->list_excludes as $prefix) { if (strpos($v, $prefix) === 0) { return false; @@ -3165,7 +3165,7 @@ protected function list_folders_update(&$result, $type = null) $search = []; // build list of namespace prefixes - foreach ((array)$namespace as $ns) { + foreach ((array) $namespace as $ns) { if (is_array($ns)) { foreach ($ns as $ns_data) { if (strlen($ns_data[0])) { @@ -3222,7 +3222,7 @@ protected function filter_rights($a_folders, $rights) continue; } - $myrights = implode('', (array)$this->my_rights($folder)); + $myrights = implode('', (array) $this->my_rights($folder)); if ($myrights !== null && !preg_match($regex, $myrights)) { unset($a_folders[$idx]); @@ -3491,7 +3491,7 @@ public function get_special_folders($forced = false) return $result; } - $types = array_map(function($value) { return "\\" . ucfirst($value); }, rcube_storage::$folder_types); + $types = array_map(function ($value) { return "\\" . ucfirst($value); }, rcube_storage::$folder_types); $special = []; // request \Subscribed flag in LIST response as performance improvement for folder_exists() @@ -4068,7 +4068,7 @@ public function set_metadata($folder, $entries) } if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { - foreach ((array)$entries as $entry => $value) { + foreach ((array) $entries as $entry => $value) { list($ent, $attr) = $this->md2annotate($entry); $entries[$entry] = [$ent, $attr, $value]; } @@ -4103,7 +4103,7 @@ public function delete_metadata($folder, $entries) } if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { - foreach ((array)$entries as $idx => $entry) { + foreach ((array) $entries as $idx => $entry) { list($ent, $attr) = $this->md2annotate($entry); $entries[$idx] = [$ent, $attr, null]; } diff --git a/program/lib/Roundcube/rcube_imap_cache.php b/program/lib/Roundcube/rcube_imap_cache.php index 5bb3e213db9..407d8abb5fa 100644 --- a/program/lib/Roundcube/rcube_imap_cache.php +++ b/program/lib/Roundcube/rcube_imap_cache.php @@ -1,6 +1,6 @@ 2592000) $ttl = 2592000; + if ($ttl > 2592000) { + $ttl = 2592000; + } $this->db = $db; $this->imap = $imap; @@ -423,7 +425,7 @@ function get_message($mailbox, $uid, $update = true, $cache = true) ." WHERE `user_id` = ?" ." AND `mailbox` = ?" ." AND `uid` = ?", - $this->userid, $mailbox, (int)$uid); + $this->userid, $mailbox, (int) $uid); if ($sql_arr = $this->db->fetch_assoc($sql_result)) { $message = $this->build_message($sql_arr); @@ -590,7 +592,7 @@ function remove_message($mailbox = null, $uids = null) "DELETE FROM {$this->messages_table}" ." WHERE `user_id` = ?" ." AND `mailbox` = ?" - .($uids !== null ? " AND `uid` IN (".$this->db->array2list((array)$uids, 'integer').")" : ""), + .($uids !== null ? " AND `uid` IN (".$this->db->array2list((array) $uids, 'integer').")" : ""), $this->userid, $mailbox ); } @@ -1018,7 +1020,7 @@ function synchronize($mailbox) $mbox_data = $this->imap->folder_data($mailbox); if (empty($mbox_data)) { - return; + return; } // Check UIDVALIDITY @@ -1155,7 +1157,7 @@ private function build_message($sql_arr) if (($sql_arr['flags'] & $idx) == $idx) { $message->flags[$flag] = true; } - } + } } return $message; diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index bfb2a55c74e..90812f678cd 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -1,6 +1,6 @@ fp, $proxy_protocol_header); } } - + if ($this->prefs['timeout'] > 0) { stream_set_timeout($this->fp, $this->prefs['timeout']); } @@ -1162,7 +1162,7 @@ protected function set_prefs($prefs) // disabled capabilities if (!empty($this->prefs['disabled_caps'])) { - $this->prefs['disabled_caps'] = array_map('strtoupper', (array)$this->prefs['disabled_caps']); + $this->prefs['disabled_caps'] = array_map('strtoupper', (array) $this->prefs['disabled_caps']); } // additional message flags @@ -1241,54 +1241,54 @@ public function select($mailbox, $qresync_data = null) $pos += 7; switch ($token) { - case 'UIDNEXT': - case 'UIDVALIDITY': - case 'UNSEEN': - if ($len = strspn($line, '0123456789', $pos)) { - $this->data[$token] = (int) substr($line, $pos, $len); - } - break; + case 'UIDNEXT': + case 'UIDVALIDITY': + case 'UNSEEN': + if ($len = strspn($line, '0123456789', $pos)) { + $this->data[$token] = (int) substr($line, $pos, $len); + } + break; - case 'HIGHESTMODSEQ': - if ($len = strspn($line, '0123456789', $pos)) { - $this->data[$token] = (string) substr($line, $pos, $len); - } - break; + case 'HIGHESTMODSEQ': + if ($len = strspn($line, '0123456789', $pos)) { + $this->data[$token] = (string) substr($line, $pos, $len); + } + break; - case 'NOMODSEQ': - $this->data[$token] = true; - break; + case 'NOMODSEQ': + $this->data[$token] = true; + break; - case 'PERMANENTFLAGS': - $start = strpos($line, '(', $pos); - $end = strrpos($line, ')'); - if ($start && $end) { - $flags = substr($line, $start + 1, $end - $start - 1); - $this->data[$token] = explode(' ', $flags); - } - break; + case 'PERMANENTFLAGS': + $start = strpos($line, '(', $pos); + $end = strrpos($line, ')'); + if ($start && $end) { + $flags = substr($line, $start + 1, $end - $start - 1); + $this->data[$token] = explode(' ', $flags); + } + break; } } else if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT|FETCH)/i', $line, $match)) { $token = strtoupper($match[2]); switch ($token) { - case 'EXISTS': - case 'RECENT': - $this->data[$token] = (int) $match[1]; - break; + case 'EXISTS': + case 'RECENT': + $this->data[$token] = (int) $match[1]; + break; - case 'FETCH': - // QRESYNC FETCH response (RFC5162) - $line = substr($line, strlen($match[0])); - $fetch_data = $this->tokenizeResponse($line, 1); - $data = ['id' => $match[1]]; + case 'FETCH': + // QRESYNC FETCH response (RFC5162) + $line = substr($line, strlen($match[0])); + $fetch_data = $this->tokenizeResponse($line, 1); + $data = ['id' => $match[1]]; - for ($i=0, $size=count($fetch_data); $i<$size; $i+=2) { - $data[strtolower($fetch_data[$i])] = $fetch_data[$i+1]; - } + for ($i=0, $size=count($fetch_data); $i<$size; $i+=2) { + $data[strtolower($fetch_data[$i])] = $fetch_data[$i+1]; + } - $this->data['QRESYNC'][$data['uid']] = $data; - break; + $this->data['QRESYNC'][$data['uid']] = $data; + break; } } // QRESYNC VANISHED response (RFC5162) @@ -1886,7 +1886,7 @@ public function enable($extension) $response = substr($response, 10); // remove prefix "* ENABLED " $result = (array) $this->tokenizeResponse($response); - $this->extensions_enabled = array_unique(array_merge((array)$this->extensions_enabled, $result)); + $this->extensions_enabled = array_unique(array_merge((array) $this->extensions_enabled, $result)); return $this->extensions_enabled; } @@ -2550,7 +2550,7 @@ public function fetch($mailbox, $message_set, $is_uid = false, $query_items = [] } else if ($name == 'FLAGS') { if (!empty($value)) { - foreach ((array)$value as $flag) { + foreach ((array) $value as $flag) { $flag = str_replace(['$', "\\"], '', $flag); $flag = strtoupper($flag); @@ -2616,58 +2616,58 @@ public function fetch($mailbox, $message_set, $is_uid = false, $query_items = [] $string = preg_replace('/\n[\t\s]*/', ' ', trim($string)); switch ($field) { - case 'date'; - $string = substr($string, 0, 128); - $result[$id]->date = $string; - $result[$id]->timestamp = rcube_utils::strtotime($string); - break; - case 'to': - $result[$id]->to = preg_replace('/undisclosed-recipients:[;,]*/', '', $string); - break; - case 'from': - case 'subject': - $string = substr($string, 0, 2048); - case 'cc': - case 'bcc': - case 'references': - $result[$id]->{$field} = $string; - break; - case 'reply-to': - $result[$id]->replyto = $string; - break; - case 'content-transfer-encoding': - $result[$id]->encoding = substr($string, 0, 32); - break; - case 'content-type': - $ctype_parts = preg_split('/[; ]+/', $string); - $result[$id]->ctype = strtolower(array_first($ctype_parts)); - if (preg_match('/charset\s*=\s*"?([a-z0-9\-\.\_]+)"?/i', $string, $regs)) { - $result[$id]->charset = $regs[1]; - } - break; - case 'in-reply-to': - $result[$id]->in_reply_to = str_replace(["\n", '<', '>'], '', $string); - break; - case 'disposition-notification-to': - case 'x-confirm-reading-to': - $result[$id]->mdn_to = substr($string, 0, 2048); - break; - case 'message-id': - $result[$id]->messageID = substr($string, 0, 2048); - break; - case 'x-priority': - if (preg_match('/^(\d+)/', $string, $matches)) { - $result[$id]->priority = intval($matches[1]); - } - break; - default: - if (strlen($field) < 3) { + case 'date': + $string = substr($string, 0, 128); + $result[$id]->date = $string; + $result[$id]->timestamp = rcube_utils::strtotime($string); break; - } - if (!empty($result[$id]->others[$field])) { - $string = array_merge((array) $result[$id]->others[$field], (array) $string); - } - $result[$id]->others[$field] = $string; + case 'to': + $result[$id]->to = preg_replace('/undisclosed-recipients:[;,]*/', '', $string); + break; + case 'from': + case 'subject': + $string = substr($string, 0, 2048); + case 'cc': + case 'bcc': + case 'references': + $result[$id]->{$field} = $string; + break; + case 'reply-to': + $result[$id]->replyto = $string; + break; + case 'content-transfer-encoding': + $result[$id]->encoding = substr($string, 0, 32); + break; + case 'content-type': + $ctype_parts = preg_split('/[; ]+/', $string); + $result[$id]->ctype = strtolower(array_first($ctype_parts)); + if (preg_match('/charset\s*=\s*"?([a-z0-9\-\.\_]+)"?/i', $string, $regs)) { + $result[$id]->charset = $regs[1]; + } + break; + case 'in-reply-to': + $result[$id]->in_reply_to = str_replace(["\n", '<', '>'], '', $string); + break; + case 'disposition-notification-to': + case 'x-confirm-reading-to': + $result[$id]->mdn_to = substr($string, 0, 2048); + break; + case 'message-id': + $result[$id]->messageID = substr($string, 0, 2048); + break; + case 'x-priority': + if (preg_match('/^(\d+)/', $string, $matches)) { + $result[$id]->priority = intval($matches[1]); + } + break; + default: + if (strlen($field) < 3) { + break; + } + if (!empty($result[$id]->others[$field])) { + $string = array_merge((array) $result[$id]->others[$field], (array) $string); + } + $result[$id]->others[$field] = $string; } } } @@ -2759,29 +2759,29 @@ public static function sortHeaders($messages, $field, $order = 'ASC') // Create an index foreach ($messages as $key => $headers) { switch ($field) { - case 'arrival': - $field = 'internaldate'; - // no-break - case 'date': - case 'internaldate': - case 'timestamp': - $value = rcube_utils::strtotime($headers->$field); - if (!$value && $field != 'timestamp') { - $value = $headers->timestamp; - } + case 'arrival': + $field = 'internaldate'; + // no-break + case 'date': + case 'internaldate': + case 'timestamp': + $value = rcube_utils::strtotime($headers->$field); + if (!$value && $field != 'timestamp') { + $value = $headers->timestamp; + } - break; + break; - default: - // @TODO: decode header value, convert to UTF-8 - $value = $headers->$field; - if (is_string($value)) { - $value = str_replace('"', '', $value); + default: + // @TODO: decode header value, convert to UTF-8 + $value = $headers->$field; + if (is_string($value)) { + $value = str_replace('"', '', $value); - if ($field == 'subject') { - $value = rcube_utils::remove_subject_prefix($value); + if ($field == 'subject') { + $value = rcube_utils::remove_subject_prefix($value); + } } - } } $index[$key] = $value; @@ -2878,20 +2878,20 @@ public function handlePartBody($mailbox, $id, $is_uid = false, $part = '', $enco do { if (!$initiated) { switch ($encoding) { - case 'base64': - $mode = 1; - break; - case 'quoted-printable': - $mode = 2; - break; - case 'x-uuencode': - case 'x-uue': - case 'uue': - case 'uuencode': - $mode = 3; - break; - default: - $mode = $formatted ? 4 : 0; + case 'base64': + $mode = 1; + break; + case 'quoted-printable': + $mode = 2; + break; + case 'x-uuencode': + case 'x-uue': + case 'uue': + case 'uuencode': + $mode = 3; + break; + default: + $mode = $formatted ? 4 : 0; } // Use BINARY extension when possible (and safe) @@ -2980,33 +2980,35 @@ public function handlePartBody($mailbox, $id, $is_uid = false, $part = '', $enco else if (!$mode && !$file && !$print) { $result = $this->readBytes($bytes); } - else while ($bytes > 0) { - $chunk = $this->readBytes($bytes > $chunkSize ? $chunkSize : $bytes); - - if ($chunk === '') { - break; - } + else { + while ($bytes > 0) { + $chunk = $this->readBytes($bytes > $chunkSize ? $chunkSize : $bytes); - $len = strlen($chunk); + if ($chunk === '') { + break; + } - if ($len > $bytes) { - $chunk = substr($chunk, 0, $bytes); $len = strlen($chunk); - } - $bytes -= $len; - $chunk = $this->decodeContent($chunk, $mode, $bytes <= 0, $prev); + if ($len > $bytes) { + $chunk = substr($chunk, 0, $bytes); + $len = strlen($chunk); + } + $bytes -= $len; - if ($file) { - if (fwrite($file, $chunk) === false) { - break; + $chunk = $this->decodeContent($chunk, $mode, $bytes <= 0, $prev); + + if ($file) { + if (fwrite($file, $chunk) === false) { + break; + } + } + else if ($print) { + echo $chunk; + } + else { + $result .= $chunk; } - } - else if ($print) { - echo $chunk; - } - else { - $result .= $chunk; } } } @@ -3827,7 +3829,7 @@ public static function getStructurePartData($structure, $part) // charset if (is_array($part_a[2])) { - foreach ($part_a[2] as $key => $val) { + foreach ($part_a[2] as $key => $val) { if (strcasecmp($val, 'charset') == 0) { $data['charset'] = $part_a[2][$key+1]; break; @@ -3988,59 +3990,59 @@ public static function tokenizeResponse(&$str, $num=0) switch ($str[0]) { - // String literal - case '{': - if (($epos = strpos($str, "}\r\n", 1)) == false) { - // error - } - if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) { - // error - } + // String literal + case '{': + if (($epos = strpos($str, "}\r\n", 1)) == false) { + // error + } + if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) { + // error + } - $result[] = $bytes ? substr($str, $epos + 3, $bytes) : ''; - $str = substr($str, $epos + 3 + $bytes); - break; + $result[] = $bytes ? substr($str, $epos + 3, $bytes) : ''; + $str = substr($str, $epos + 3 + $bytes); + break; - // Quoted string - case '"': - $len = strlen($str); + // Quoted string (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '"': + $len = strlen($str); - for ($pos=1; $pos<$len; $pos++) { - if ($str[$pos] == '"') { - break; - } - if ($str[$pos] == "\\") { - if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { - $pos++; + for ($pos=1; $pos<$len; $pos++) { + if ($str[$pos] == '"') { + break; + } + if ($str[$pos] == "\\") { + if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { + $pos++; + } } } - } - // we need to strip slashes for a quoted string - $result[] = stripslashes(substr($str, 1, $pos - 1)); - $str = substr($str, $pos + 1); - break; + // we need to strip slashes for a quoted string + $result[] = stripslashes(substr($str, 1, $pos - 1)); + $str = substr($str, $pos + 1); + break; - // Parenthesized list - case '(': - $str = substr($str, 1); - $result[] = self::tokenizeResponse($str); - break; + // Parenthesized list (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + case '(': + $str = substr($str, 1); + $result[] = self::tokenizeResponse($str); + break; - case ')': - $str = substr($str, 1); - return $result; + case ')': + $str = substr($str, 1); + return $result; - // String atom, number, astring, NIL, *, % - default: - // excluded chars: SP, CTL, ), DEL - // we do not exclude [ and ] (#1489223) - if (preg_match('/^([^\x00-\x20\x29\x7F]+)/', $str, $m)) { - $result[] = $m[1] == 'NIL' ? null : $m[1]; - $str = substr($str, strlen($m[1])); - } + // String atom, number, astring, NIL, *, % (<< reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7179 is fixed) + default: + // excluded chars: SP, CTL, ), DEL + // we do not exclude [ and ] (#1489223) + if (preg_match('/^([^\x00-\x20\x29\x7F]+)/', $str, $m)) { + $result[] = $m[1] == 'NIL' ? null : $m[1]; + $str = substr($str, strlen($m[1])); + } - break; + break; } } diff --git a/program/lib/Roundcube/rcube_imap_search.php b/program/lib/Roundcube/rcube_imap_search.php index 32a1c00ac2c..3a117346590 100644 --- a/program/lib/Roundcube/rcube_imap_search.php +++ b/program/lib/Roundcube/rcube_imap_search.php @@ -1,6 +1,6 @@ prop = $p; @@ -160,8 +160,12 @@ function __construct($p, $debug = false, $mail_domain = null) } // first argument is a limit else if ($idx === 0) { - if ($param == '*') $limit = null; - else $limit = max(1, intval($param)); + if ($param == '*') { + $limit = null; + } + else { + $limit = max(1, intval($param)); + } } // second is a composite field separator else if ($idx === 1 && $param) { @@ -194,7 +198,7 @@ function __construct($p, $debug = false, $mail_domain = null) ), ] + (array) ($this->coltypes['address'] ?? []); - foreach (['street','locality','zipcode','region','country'] as $childcol) { + foreach (['street', 'locality', 'zipcode', 'region', 'country'] as $childcol) { if (!empty($this->coltypes[$childcol])) { $this->coltypes['address']['childs'][$childcol] = ['type' => 'text']; $this->coltypes['address']['attributes'] = array_merge( @@ -843,7 +847,7 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r // use VLV pseudo-search for autocompletion if (!empty($this->prop['vlv_search']) && $this->ready - && implode(',', (array)$fields) == implode(',', $list_fields) + && implode(',', (array) $fields) == implode(',', $list_fields) ) { $this->result = new rcube_result_set(0); @@ -862,7 +866,7 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r $rec = $this->_ldap2result($entry); foreach ($fields as $f) { if (!empty($rec[$f])) { - foreach ((array)$rec[$f] as $val) { + foreach ((array) $rec[$f] as $val) { if ($this->compare_search_value($f, $val, $search, $mode)) { $this->result->add($rec); $this->result->count++; @@ -1636,7 +1640,7 @@ private function _ldap2result($rec) // assign object type from object class mapping if (!empty($this->prop['class_type_map'])) { - foreach (array_map('strtolower', (array)$rec['objectclass']) as $objcls) { + foreach (array_map('strtolower', (array) $rec['objectclass']) as $objcls) { if (!empty($this->prop['class_type_map'][$objcls])) { $out['_type'] = $this->prop['class_type_map'][$objcls]; break; @@ -1715,7 +1719,7 @@ private function _map_data($save_cols) foreach ($this->get_col_values($col, $save_cols, false) as $subtype => $childs) { $subtype = $subtype ? ':'.$subtype : ''; foreach ($childs as $i => $child_values) { - foreach ((array)$child_values as $childcol => $value) { + foreach ((array) $child_values as $childcol => $value) { $save_cols[$childcol.$subtype][$i] = $value; } } @@ -1724,13 +1728,13 @@ private function _map_data($save_cols) // if addresses are to be saved as serialized string, do so if (!empty($colprop['serialized']) && is_array($colprop['serialized'])) { - foreach ($colprop['serialized'] as $subtype => $delim) { - $key = $col.':'.$subtype; - foreach ((array)$save_cols[$key] as $i => $val) { - $values = [$val['street'], $val['locality'], $val['zipcode'], $val['country']]; - $save_cols[$key][$i] = count(array_filter($values)) ? implode($delim, $values) : null; - } - } + foreach ($colprop['serialized'] as $subtype => $delim) { + $key = $col.':'.$subtype; + foreach ((array) $save_cols[$key] as $i => $val) { + $values = [$val['street'], $val['locality'], $val['zipcode'], $val['country']]; + $save_cols[$key][$i] = count(array_filter($values)) ? implode($delim, $values) : null; + } + } } } @@ -1765,11 +1769,11 @@ private function _map_data($save_cols) } switch ($format['type']) { - case 'date': - if ($dt = rcube_utils::anytodatetime($ldap_data[$fld])) { - $ldap_data[$fld] = $dt->format($format['format']); - } - break; + case 'date': + if ($dt = rcube_utils::anytodatetime($ldap_data[$fld])) { + $ldap_data[$fld] = $dt->format($format['format']); + } + break; } } @@ -1811,7 +1815,7 @@ private function is_group_entry($entry) return false; } - $classes = array_map('strtolower', (array)$entry['objectclass']); + $classes = array_map('strtolower', (array) $entry['objectclass']); return count(array_intersect(array_keys($this->group_types), $classes)) > 0; } @@ -1979,8 +1983,9 @@ private function _fetch_groups($search = null, $mode = 0, $vlv_page = null) // list email attributes of a group for ($j=0; $entry[$email_attr] && $j < $entry[$email_attr]['count']; $j++) { - if (strpos($entry[$email_attr][$j], '@') > 0) + if (strpos($entry[$email_attr][$j], '@') > 0) { $groups[$group_id]['email'][] = $entry[$email_attr][$j]; + } } $group_sortnames[] = mb_strtolower($entry[$sort_attr][0]); @@ -2026,7 +2031,7 @@ private function get_group_entry($group_id) if (!isset($group_cache[$group_id])) { $name_attr = $this->prop['groups']['name_attr']; $dn = self::dn_decode($group_id); - $attrs = ['dn','objectClass','member','uniqueMember','memberURL',$name_attr,$this->fieldmap['email']]; + $attrs = ['dn', 'objectClass', 'member', 'uniqueMember', 'memberURL', $name_attr, $this->fieldmap['email']]; if ($list = $this->ldap->read_entries($dn, '(objectClass=*)', $attrs)) { $entry = $list[0]; diff --git a/program/lib/Roundcube/rcube_ldap_generic.php b/program/lib/Roundcube/rcube_ldap_generic.php index a603229fd46..c411727f250 100644 --- a/program/lib/Roundcube/rcube_ldap_generic.php +++ b/program/lib/Roundcube/rcube_ldap_generic.php @@ -1,6 +1,6 @@ config['debug'])) { - rcube::write_log('ldap', $msg); - } - break; - - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - rcube::raise_error($msg, true, true); - break; - - case LOG_ERR: - case LOG_WARNING: - $this->error = $msg; - rcube::raise_error($msg, true, false); - break; + case LOG_DEBUG: + case LOG_INFO: + case LOG_NOTICE: + if (!empty($this->config['debug'])) { + rcube::write_log('ldap', $msg); + } + break; + + case LOG_EMERG: + case LOG_ALERT: + case LOG_CRIT: + rcube::raise_error($msg, true, true); + break; + + case LOG_ERR: + case LOG_WARNING: + $this->error = $msg; + rcube::raise_error($msg, true, false); + break; } } @@ -260,7 +260,7 @@ public function read_entries($dn, $filter, $attributes = null) $this->_debug("C: Read $dn [{$filter}]"); if ($this->conn && $dn) { - $result = @ldap_read($this->conn, $dn, $filter, $attributes, 0, (int)$this->config['sizelimit'], (int)$this->config['timelimit']); + $result = @ldap_read($this->conn, $dn, $filter, $attributes, 0, (int) $this->config['sizelimit'], (int) $this->config['timelimit']); if ($result === false) { $this->_error("ldap_read() failed with " . ldap_error($this->conn)); return false; diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php index e61d1d74720..18aa758ab94 100644 --- a/program/lib/Roundcube/rcube_message.php +++ b/program/lib/Roundcube/rcube_message.php @@ -1,6 +1,6 @@ mimetype == 'message/rfc822') { - if (in_array($part, (array)$att_part->parts)) { + if (in_array($part, (array) $att_part->parts)) { return true; } } @@ -593,7 +593,7 @@ private function parse_structure($structure, $recursive = false) // parse headers from message/rfc822 part if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) { $part_body = $this->get_part_body($structure->mime_id, false, 32768); - list($headers, ) = rcube_utils::explode("\r\n\r\n", $part_body, 2); + list($headers) = rcube_utils::explode("\r\n\r\n", $part_body, 2); $structure->headers = rcube_mime::parse_headers($headers); if ($this->context === $structure->mime_id) { @@ -671,7 +671,7 @@ private function parse_structure($structure, $recursive = false) // Parse simple (plain text) message body if ($message_ctype_secondary == 'plain') { - foreach ((array)$this->uu_decode($structure) as $uupart) { + foreach ((array) $this->uu_decode($structure) as $uupart) { $this->mime_parts[$uupart->mime_id] = $uupart; $this->add_part($uupart, 'attachment'); } @@ -1060,9 +1060,15 @@ private function add_part($part, $type = null) // It may happen that we add the same part to the array many times // use part ID index to prevent from duplicates switch ($type) { - case 'inline': $this->inline_parts[(string) $part->mime_id] = $part; break; - case 'attachment': $this->attachments[(string) $part->mime_id] = $part; break; - default: $this->parts[] = $part; break; + case 'inline': + $this->inline_parts[(string) $part->mime_id] = $part; + break; + case 'attachment': + $this->attachments[(string) $part->mime_id] = $part; + break; + default: + $this->parts[] = $part; + break; } } } diff --git a/program/lib/Roundcube/rcube_message_header.php b/program/lib/Roundcube/rcube_message_header.php index 28b95fa69b3..fb9030e4995 100644 --- a/program/lib/Roundcube/rcube_message_header.php +++ b/program/lib/Roundcube/rcube_message_header.php @@ -1,6 +1,6 @@ config->resolve_paths('mimetypes.php') as $fpath) { - $mime_ext = array_merge($mime_ext, (array) @include($fpath)); + $mime_ext = array_merge($mime_ext, (array) @include ($fpath)); } } @@ -859,7 +859,7 @@ public static function get_mime_extensions($mimetype = null) } foreach ($lines as $line) { - // skip comments or mime types w/o any extensions + // skip comments or mime types w/o any extensions if ($line[0] == '#' || !preg_match($regex, $line, $matches)) { continue; } @@ -876,7 +876,7 @@ public static function get_mime_extensions($mimetype = null) // fallback to some well-known types most important for daily emails if (empty($mime_types)) { foreach (rcube::get_instance()->config->resolve_paths('mimetypes.php') as $fpath) { - $mime_extensions = array_merge($mime_extensions, (array) @include($fpath)); + $mime_extensions = array_merge($mime_extensions, (array) @include ($fpath)); } foreach ($mime_extensions as $ext => $mime) { @@ -932,10 +932,18 @@ public static function get_mime_extensions($mimetype = null) public static function image_content_type($data) { $type = 'jpeg'; - if (preg_match('/^\x89\x50\x4E\x47/', $data)) $type = 'png'; - else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; - else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; - // else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; + if (preg_match('/^\x89\x50\x4E\x47/', $data)) { + $type = 'png'; + } + else if (preg_match('/^\x47\x49\x46\x38/', $data)) { + $type = 'gif'; + } + else if (preg_match('/^\x00\x00\x01\x00/', $data)) { + $type = 'ico'; + } + // else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) { + // $type = 'jpeg'; + // } return 'image/' . $type; } diff --git a/program/lib/Roundcube/rcube_mime_decode.php b/program/lib/Roundcube/rcube_mime_decode.php index 662962c7463..69f076d38a0 100644 --- a/program/lib/Roundcube/rcube_mime_decode.php +++ b/program/lib/Roundcube/rcube_mime_decode.php @@ -1,6 +1,6 @@ parseHeaderValue($value['value']); + case 'content-type': + $content_type = $this->parseHeaderValue($value['value']); - if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) { - $return->ctype_primary = $regs[1]; - $return->ctype_secondary = $regs[2]; - } + if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) { + $return->ctype_primary = $regs[1]; + $return->ctype_secondary = $regs[2]; + } - if (!empty($content_type['other'])) { - $return->ctype_parameters = array_merge((array) $return->ctype_parameters, (array) $content_type['other']); - } + if (!empty($content_type['other'])) { + $return->ctype_parameters = array_merge((array) $return->ctype_parameters, (array) $content_type['other']); + } - break; + break; - case 'content-disposition'; - $content_disposition = $this->parseHeaderValue($value['value']); - $return->disposition = $content_disposition['value']; + case 'content-disposition': + $content_disposition = $this->parseHeaderValue($value['value']); + $return->disposition = $content_disposition['value']; - if (!empty($content_disposition['other'])) { - $return->d_parameters = array_merge((array) $return->d_parameters, (array) $content_disposition['other']); - } + if (!empty($content_disposition['other'])) { + $return->d_parameters = array_merge((array) $return->d_parameters, (array) $content_disposition['other']); + } - break; + break; - case 'content-transfer-encoding': - $content_transfer_encoding = $this->parseHeaderValue($value['value']); - break; + case 'content-transfer-encoding': + $content_transfer_encoding = $this->parseHeaderValue($value['value']); + break; } } @@ -154,62 +154,62 @@ protected function do_decode($headers, $body, $default_ctype = 'text/plain') $ctype = strtolower($content_type['value']); switch ($ctype) { - case 'text/plain': - $encoding = $content_transfer_encoding['value'] ?? '7bit'; + case 'text/plain': + $encoding = $content_transfer_encoding['value'] ?? '7bit'; - if ($this->params['include_bodies']) { - $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; - } + if ($this->params['include_bodies']) { + $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; + } - break; + break; - case 'text/html': - $encoding = $content_transfer_encoding['value'] ?? '7bit'; + case 'text/html': + $encoding = $content_transfer_encoding['value'] ?? '7bit'; - if ($this->params['include_bodies']) { - $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; - } + if ($this->params['include_bodies']) { + $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; + } - break; + break; - case 'multipart/digest': - case 'multipart/alternative': - case 'multipart/related': - case 'multipart/mixed': - case 'multipart/signed': - case 'multipart/encrypted': - if (!isset($content_type['other']['boundary'])) { - return false; - } + case 'multipart/digest': + case 'multipart/alternative': + case 'multipart/related': + case 'multipart/mixed': + case 'multipart/signed': + case 'multipart/encrypted': + if (!isset($content_type['other']['boundary'])) { + return false; + } - $default_ctype = $ctype === 'multipart/digest' ? 'message/rfc822' : 'text/plain'; - $parts = $this->boundarySplit($body, $content_type['other']['boundary']); + $default_ctype = $ctype === 'multipart/digest' ? 'message/rfc822' : 'text/plain'; + $parts = $this->boundarySplit($body, $content_type['other']['boundary']); - for ($i = 0; $i < count($parts); $i++) { - list($part_header, $part_body) = $this->splitBodyHeader($parts[$i]); - $return->parts[] = $this->do_decode($part_header, $part_body, $default_ctype); - } + for ($i = 0; $i < count($parts); $i++) { + list($part_header, $part_body) = $this->splitBodyHeader($parts[$i]); + $return->parts[] = $this->do_decode($part_header, $part_body, $default_ctype); + } - break; + break; - case 'message/rfc822': - $obj = new rcube_mime_decode($this->params); - $return->parts[] = $obj->decode($body, false); - unset($obj); + case 'message/rfc822': + $obj = new rcube_mime_decode($this->params); + $return->parts[] = $obj->decode($body, false); + unset($obj); - if ($this->params['include_bodies']) { - $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body) : $body; - } + if ($this->params['include_bodies']) { + $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body) : $body; + } - break; + break; - default: - if ($this->params['include_bodies']) { - $encoding = !empty($content_transfer_encoding['value']) ? $content_transfer_encoding['value'] : '7bit'; - $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; - } + default: + if ($this->params['include_bodies']) { + $encoding = !empty($content_transfer_encoding['value']) ? $content_transfer_encoding['value'] : '7bit'; + $return->body = $this->params['decode_bodies'] ? rcube_mime::decode($body, $encoding) : $body; + } - break; + break; } } else { @@ -380,7 +380,7 @@ protected function decodeHeader($input) protected function structure_part($part, $count = 0, $parent = '') { $struct = new rcube_message_part; - $struct->mime_id = $part->mime_id ?: (empty($parent) ? (string)$count : "$parent.$count"); + $struct->mime_id = $part->mime_id ?: (empty($parent) ? (string) $count : "$parent.$count"); $struct->headers = $part->headers; $struct->mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; $struct->ctype_primary = $part->ctype_primary; diff --git a/program/lib/Roundcube/rcube_output.php b/program/lib/Roundcube/rcube_output.php index 46e8ff76041..cee403fde30 100644 --- a/program/lib/Roundcube/rcube_output.php +++ b/program/lib/Roundcube/rcube_output.php @@ -1,6 +1,6 @@ output->skins); + $skins = array_keys((array) $rcube->output->skins); $skin_path = ''; if (empty($skins)) { diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index 19e6ae2b41b..f5f6be22160 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -1,6 +1,6 @@ meta = []; - $data = explode('*', (string)$data); + $data = explode('*', (string) $data); // ...skip unilateral untagged server responses for ($i=0, $len=count($data); $i<$len; $i++) { @@ -100,8 +100,8 @@ public function init($data = null) } } -// @TODO: Implement compression using compressMessageSet() in __sleep() and __wakeup() ? -// @TODO: work with compressed result?! + // @TODO: Implement compression using compressMessageSet() in __sleep() and __wakeup() ? + // @TODO: work with compressed result?! if (isset($this->params['ALL'])) { $data_item = implode(self::SEPARATOR_ELEMENT, rcube_imap_generic::uncompressMessageSet($this->params['ALL'])); @@ -304,7 +304,7 @@ public function exists($msgid, $get_index = false) $idx = 1 + substr_count($this->raw_data, self::SEPARATOR_ELEMENT, 0, $m[0][1]); } // cache position of this element, so we can use it in get_element() - $this->meta['pos'][$idx] = (int)$m[0][1]; + $this->meta['pos'][$idx] = (int) $m[0][1]; return $idx; } diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php index aa26b81b608..3581e68584a 100644 --- a/program/lib/Roundcube/rcube_result_multifolder.php +++ b/program/lib/Roundcube/rcube_result_multifolder.php @@ -1,6 +1,6 @@ get_parameters('MAILBOX'); - $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); + $index = array_map(function ($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); $this->index = array_merge($this->index, $index); } diff --git a/program/lib/Roundcube/rcube_result_set.php b/program/lib/Roundcube/rcube_result_set.php index 633a85f7f3c..192267a48ec 100644 --- a/program/lib/Roundcube/rcube_result_set.php +++ b/program/lib/Roundcube/rcube_result_set.php @@ -1,6 +1,6 @@ current = $i; } - /*** Implement PHP ArrayAccess interface ***/ + /* Implement PHP ArrayAccess interface */ public function offsetSet($offset, $value): void { @@ -114,7 +114,7 @@ public function offsetGet($offset) return $this->records[$offset]; } - /*** PHP 5 Iterator interface ***/ + /* PHP 5 Iterator interface */ public function rewind(): void { diff --git a/program/lib/Roundcube/rcube_result_thread.php b/program/lib/Roundcube/rcube_result_thread.php index 05e33474ac8..a2d10476816 100644 --- a/program/lib/Roundcube/rcube_result_thread.php +++ b/program/lib/Roundcube/rcube_result_thread.php @@ -1,6 +1,6 @@ raw_data, self::SEPARATOR_ITEM, 0, $m[0][1]+1); } // cache position of this element, so we can use it in get_element() - $this->meta['pos'][$idx] = (int)$m[0][1]; + $this->meta['pos'][$idx] = (int) $m[0][1]; return $idx; } @@ -549,7 +549,7 @@ public function get_thread_data() */ protected function build_thread_data($data, &$depth, &$children, $level = 0) { - foreach ((array)$data as $key => $val) { + foreach ((array) $data as $key => $val) { $empty = empty($val) || !is_array($val); $children[$key] = !$empty; $depth[$key] = $level; diff --git a/program/lib/Roundcube/rcube_session.php b/program/lib/Roundcube/rcube_session.php index afe5fd46809..93d0bed5a53 100644 --- a/program/lib/Roundcube/rcube_session.php +++ b/program/lib/Roundcube/rcube_session.php @@ -1,6 +1,6 @@ unsets as $var) { + foreach ((array) $this->unsets as $var) { if (isset($a_oldvars[$var])) { unset($a_oldvars[$var]); } @@ -250,7 +250,7 @@ protected function fixvars($vars, $oldvars) } $newvars = $this->serialize(array_merge( - (array)$a_oldvars, (array)$this->unserialize($vars))); + (array) $a_oldvars, (array) $this->unserialize($vars))); } else { $newvars = $vars; @@ -485,8 +485,9 @@ protected function serialize($vars) $data = ''; if (is_array($vars)) { - foreach ($vars as $var => $value) + foreach ($vars as $var => $value) { $data .= $var.'|'.serialize($value); + } } else { $data = 'b:0;'; @@ -515,9 +516,11 @@ public static function unserialize($str) while ($p < $endptr) { $q = $p; - while ($str[$q] != '|') - if (++$q >= $endptr) + while ($str[$q] != '|') { + if (++$q >= $endptr) { break 2; + } + } if ($str[$p] == '!') { $p++; @@ -536,59 +539,63 @@ public static function unserialize($str) for (;;) { $p = $q; switch (strtolower($str[$q])) { - case 'n': // null - case 'b': // boolean - case 'i': // integer - case 'd': // decimal - do $q++; - while (($q < $endptr) && ($str[$q] != ';')); - $q++; - $serialized .= substr($str, $p, $q - $p); - if ($level == 0) { - break 2; - } - break; - case 'r': // reference - $q+= 2; - for ($id = ''; ($q < $endptr) && ($str[$q] != ';'); $q++) { - $id .= $str[$q]; - } - $q++; - // increment pointer because of outer array - $serialized .= 'R:' . ($id + 1) . ';'; - if ($level == 0) { - break 2; - } - break; - case 's': // string - $q+=2; - for ($length=''; ($q < $endptr) && ($str[$q] != ':'); $q++) { - $length .= $str[$q]; - } - $q+=2; - $q+= (int)$length + 2; - $serialized .= substr($str, $p, $q - $p); - if ($level == 0) { - break 2; - } - break; - case 'a': // array - case 'o': // object - do $q++; - while ($q < $endptr && $str[$q] != '{'); - $q++; - $level++; - $serialized .= substr($str, $p, $q - $p); - break; - case '}': // end of array|object - $q++; - $serialized .= substr($str, $p, $q - $p); - if (--$level == 0) { - break 2; - } - break; - default: - return false; + case 'n': // null + case 'b': // boolean + case 'i': // integer + case 'd': // decimal + do { + $q++; + } + while (($q < $endptr) && ($str[$q] != ';')); + $q++; + $serialized .= substr($str, $p, $q - $p); + if ($level == 0) { + break 2; + } + break; + case 'r': // reference + $q+= 2; + for ($id = ''; ($q < $endptr) && ($str[$q] != ';'); $q++) { + $id .= $str[$q]; + } + $q++; + // increment pointer because of outer array + $serialized .= 'R:' . ($id + 1) . ';'; + if ($level == 0) { + break 2; + } + break; + case 's': // string + $q+=2; + for ($length=''; ($q < $endptr) && ($str[$q] != ':'); $q++) { + $length .= $str[$q]; + } + $q+=2; + $q+= (int) $length + 2; + $serialized .= substr($str, $p, $q - $p); + if ($level == 0) { + break 2; + } + break; + case 'a': // array + case 'o': // object + do { + $q++; + } + while ($q < $endptr && $str[$q] != '{'); + $q++; + $level++; + $serialized .= substr($str, $p, $q - $p); + break; + case '}': // end of array|object + $q++; + $serialized .= substr($str, $p, $q - $p); + if (--$level == 0) { + break 2; + } + break; + default: + return false; } } } diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php index ea1bd8cd0ec..834cbc0beb4 100644 --- a/program/lib/Roundcube/rcube_smtp.php +++ b/program/lib/Roundcube/rcube_smtp.php @@ -1,6 +1,6 @@ response; + return $this->response; } /** diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php index 62061aad5a4..ca113b41b46 100644 --- a/program/lib/Roundcube/rcube_spellchecker.php +++ b/program/lib/Roundcube/rcube_spellchecker.php @@ -1,6 +1,6 @@ mailto_pattern, [$this, 'mailto_callback'], $str); // resolve link references -/* + /* This code requires PHP 7.4 and could be used instead of the two if() statements below, when we get there. @@ -240,7 +240,7 @@ public function replace($str) $str = preg_replace_callback($this->linkref_pattern, [$this, 'linkref_callback'], $str, -1, $count, PREG_OFFSET_CAPTURE ); -*/ + */ if (preg_match_all($this->linkref_index, $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $diff = 0; foreach ($matches as $m) { diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php index 86cfc14057d..c913e3543a8 100644 --- a/program/lib/Roundcube/rcube_text2html.php +++ b/program/lib/Roundcube/rcube_text2html.php @@ -1,6 +1,6 @@ get_html(); + echo $this->get_html(); } /** diff --git a/program/lib/Roundcube/rcube_tnef_decoder.php b/program/lib/Roundcube/rcube_tnef_decoder.php index 822f2e67948..5e131b3580f 100644 --- a/program/lib/Roundcube/rcube_tnef_decoder.php +++ b/program/lib/Roundcube/rcube_tnef_decoder.php @@ -1,6 +1,6 @@ 0) { switch ($this->_geti($data, 8)) { - case self::LVL_MESSAGE: - $this->_decodeMessage($data, $message); - break; + case self::LVL_MESSAGE: + $this->_decodeMessage($data, $message); + break; - case self::LVL_ATTACHMENT: - $this->_decodeAttachment($data, $attachments); - break; + case self::LVL_ATTACHMENT: + $this->_decodeAttachment($data, $attachments); + break; } } } @@ -293,20 +293,20 @@ protected function _extractMapiAttributes($data, &$result) $named_type = $this->_geti($data, 32); switch ($named_type) { - case self::MAPI_NAMED_TYPE_ID: - $attr_name = $this->_geti($data, 32); - break; + case self::MAPI_NAMED_TYPE_ID: + $attr_name = $this->_geti($data, 32); + break; - case self::MAPI_NAMED_TYPE_STRING: - $attr_name = 0x9999; - $idlen = $this->_geti($data, 32); - $name = $this->_getx($data, $idlen + ((4 - ($idlen % 4)) % 4)); - // $name = $this->convertString(substr($name, 0, $idlen)); - break; + case self::MAPI_NAMED_TYPE_STRING: + $attr_name = 0x9999; + $idlen = $this->_geti($data, 32); + $name = $this->_getx($data, $idlen + ((4 - ($idlen % 4)) % 4)); + // $name = $this->convertString(substr($name, 0, $idlen)); + break; - case self::MAPI_NAMED_TYPE_NONE: - default: - continue 2; + case self::MAPI_NAMED_TYPE_NONE: + default: + continue 2; } } @@ -315,99 +315,99 @@ protected function _extractMapiAttributes($data, &$result) } switch ($attr_type) { - case self::MAPI_NULL: - case self::MAPI_TYPE_UNSET: - break; + case self::MAPI_NULL: + case self::MAPI_TYPE_UNSET: + break; - case self::MAPI_SHORT: - $value = $this->_geti($data, 16); - $this->_geti($data, 16); - break; + case self::MAPI_SHORT: + $value = $this->_geti($data, 16); + $this->_geti($data, 16); + break; - case self::MAPI_INT: - case self::MAPI_BOOLEAN: - for ($i = 0; $i < $num_mval; $i++) { - $value = $this->_geti($data, 32); - } - break; + case self::MAPI_INT: + case self::MAPI_BOOLEAN: + for ($i = 0; $i < $num_mval; $i++) { + $value = $this->_geti($data, 32); + } + break; - case self::MAPI_FLOAT: - case self::MAPI_ERROR: - $value = $this->_getx($data, 4); - break; + case self::MAPI_FLOAT: + case self::MAPI_ERROR: + $value = $this->_getx($data, 4); + break; - case self::MAPI_DOUBLE: - case self::MAPI_APPTIME: - case self::MAPI_CURRENCY: - case self::MAPI_INT8BYTE: - case self::MAPI_SYSTIME: - $value = $this->_getx($data, 8); - break; + case self::MAPI_DOUBLE: + case self::MAPI_APPTIME: + case self::MAPI_CURRENCY: + case self::MAPI_INT8BYTE: + case self::MAPI_SYSTIME: + $value = $this->_getx($data, 8); + break; - case self::MAPI_STRING: - case self::MAPI_UNICODE_STRING: - case self::MAPI_BINARY: - case self::MAPI_OBJECT: - $num_vals = $have_mval ? $num_mval : $this->_geti($data, 32); - for ($i = 0; $i < $num_vals; $i++) { - $length = $this->_geti($data, 32); + case self::MAPI_STRING: + case self::MAPI_UNICODE_STRING: + case self::MAPI_BINARY: + case self::MAPI_OBJECT: + $num_vals = $have_mval ? $num_mval : $this->_geti($data, 32); + for ($i = 0; $i < $num_vals; $i++) { + $length = $this->_geti($data, 32); - // Pad to next 4 byte boundary. - $datalen = $length + ((4 - ($length % 4)) % 4); + // Pad to next 4 byte boundary. + $datalen = $length + ((4 - ($length % 4)) % 4); - // Read and truncate to length. - $value = $this->_getx($data, $datalen); - } + // Read and truncate to length. + $value = $this->_getx($data, $datalen); + } - if ($attr_type == self::MAPI_UNICODE_STRING) { - $value = $this->convertString($value); - } + if ($attr_type == self::MAPI_UNICODE_STRING) { + $value = $this->convertString($value); + } - break; + break; } // Store any interesting attributes. switch ($attr_name) { - case self::MAPI_RTF_COMPRESSED: - $result['type'] = 'application'; - $result['subtype'] = 'rtf'; - $result['name'] = (!empty($result['name']) ? $result['name'] : 'Untitled') . '.rtf'; - $result['stream'] = $this->_decodeRTF($value); - $result['size'] = strlen($result['stream']); - break; + case self::MAPI_RTF_COMPRESSED: + $result['type'] = 'application'; + $result['subtype'] = 'rtf'; + $result['name'] = (!empty($result['name']) ? $result['name'] : 'Untitled') . '.rtf'; + $result['stream'] = $this->_decodeRTF($value); + $result['size'] = strlen($result['stream']); + break; - case self::MAPI_BODY: - case self::MAPI_BODY_HTML: - $result['type'] = 'text'; - $result['subtype'] = $attr_name == self::MAPI_BODY ? 'plain' : 'html'; - $result['name'] = (!empty($result['name']) ? $result['name'] : 'Untitled') - . ($attr_name == self::MAPI_BODY ? '.txt' : '.html'); - $result['stream'] = $value; - $result['size'] = strlen($value); - break; + case self::MAPI_BODY: + case self::MAPI_BODY_HTML: + $result['type'] = 'text'; + $result['subtype'] = $attr_name == self::MAPI_BODY ? 'plain' : 'html'; + $result['name'] = (!empty($result['name']) ? $result['name'] : 'Untitled') + . ($attr_name == self::MAPI_BODY ? '.txt' : '.html'); + $result['stream'] = $value; + $result['size'] = strlen($value); + break; - case self::MAPI_ATTACH_LONG_FILENAME: - // Used in preference to AFILENAME value. - $result['name'] = trim(preg_replace('/.*[\/](.*)$/', '\1', $value)); - break; + case self::MAPI_ATTACH_LONG_FILENAME: + // Used in preference to AFILENAME value. + $result['name'] = trim(preg_replace('/.*[\/](.*)$/', '\1', $value)); + break; - case self::MAPI_ATTACH_MIME_TAG: - // Is this ever set, and what is format? - $value = explode('/', trim($value)); - $result['type'] = $value[0]; - $result['subtype'] = $value[1]; - break; + case self::MAPI_ATTACH_MIME_TAG: + // Is this ever set, and what is format? + $value = explode('/', trim($value)); + $result['type'] = $value[0]; + $result['subtype'] = $value[1]; + break; - case self::MAPI_ATTACH_CONTENT_ID: - $result['content-id'] = $value; - break; + case self::MAPI_ATTACH_CONTENT_ID: + $result['content-id'] = $value; + break; - case self::MAPI_ATTACH_DATA: - $this->_getx($value, 16); - $att = new rcube_tnef_decoder; - $res = $att->decompress($value); - $result = array_merge($result, $res['message']); - break; + case self::MAPI_ATTACH_DATA: + $this->_getx($value, 16); + $att = new rcube_tnef_decoder; + $res = $att->decompress($value); + $result = array_merge($result, $res['message']); + break; } } } @@ -424,24 +424,24 @@ protected function _decodeMessage(&$data, &$message) $value = $this->_decodeAttribute($data); switch ($attribute) { - case self::AOEMCODEPAGE: - // Find codepage of the message - $value = unpack('V', $value); - $this->codepage = $value[1]; - break; - - case self::AMCLASS: - $value = trim(str_replace('Microsoft Mail v3.0 ', '', $value)); - // Normal message will be that with prefix 'IPM.Microsoft Mail. - break; - - case self::ASUBJECT: - $message['name'] = $value; - break; - - case self::AMAPIPROPS: - $this->_extractMapiAttributes($value, $message); - break; + case self::AOEMCODEPAGE: + // Find codepage of the message + $value = unpack('V', $value); + $this->codepage = $value[1]; + break; + + case self::AMCLASS: + $value = trim(str_replace('Microsoft Mail v3.0 ', '', $value)); + // Normal message will be that with prefix 'IPM.Microsoft Mail. + break; + + case self::ASUBJECT: + $message['name'] = $value; + break; + + case self::AMAPIPROPS: + $this->_extractMapiAttributes($value, $message); + break; } } @@ -460,33 +460,33 @@ protected function _decodeAttachment(&$data, &$attachment) $this->_geti($data, 16); // checksum switch ($attribute) { - case self::ARENDDATA: - // Add a new default data block to hold details of this - // attachment. Reverse order is easier to handle later! - array_unshift($attachment, [ - 'type' => 'application', - 'subtype' => 'octet-stream', - 'name' => 'unknown', - 'stream' => '' - ]); - - break; - - case self::AFILENAME: - $value = $this->convertString($value, true); - // Strip path - $attachment[0]['name'] = trim(preg_replace('/.*[\/](.*)$/', '\1', $value)); - break; - - case self::ATTACHDATA: - // The attachment itself - $attachment[0]['size'] = $size; - $attachment[0]['stream'] = $value; - break; - - case self::AMAPIATTRS: - $this->_extractMapiAttributes($value, $attachment[0]); - break; + case self::ARENDDATA: + // Add a new default data block to hold details of this + // attachment. Reverse order is easier to handle later! + array_unshift($attachment, [ + 'type' => 'application', + 'subtype' => 'octet-stream', + 'name' => 'unknown', + 'stream' => '' + ]); + + break; + + case self::AFILENAME: + $value = $this->convertString($value, true); + // Strip path + $attachment[0]['name'] = trim(preg_replace('/.*[\/](.*)$/', '\1', $value)); + break; + + case self::ATTACHDATA: + // The attachment itself + $attachment[0]['size'] = $size; + $attachment[0]['stream'] = $value; + break; + + case self::AMAPIATTRS: + $this->_extractMapiAttributes($value, $attachment[0]); + break; } } @@ -552,7 +552,7 @@ protected function _decompressRTF($data, $size) $length = ord($data[$in++]); $offset = ($offset << 4) | ($length >> 4); $length = ($length & 0xF) + 2; - $offset = ((int)($out / 4096)) * 4096 + $offset; + $offset = ((int) ($out / 4096)) * 4096 + $offset; if ($offset >= $out) { $offset -= 4096; @@ -592,187 +592,187 @@ public static function rtf2text($text) for ($i = 0, $len = strlen($text); $i < $len; $i++) { $c = $text[$i]; switch ($c) { - case "\\": - // Key Word - $nextChar = $text[$i + 1]; - // If it is another backslash or nonbreaking space or hyphen, - // then the character is plain text and add it to the output stream. - if ($nextChar == "\\" && self::_rtfIsPlain($stack[$j])) { - $document .= "\\"; - } - elseif ($nextChar == '~' && self::_rtfIsPlain($stack[$j])) { - $document .= ' '; - } - elseif ($nextChar == '_' && self::_rtfIsPlain($stack[$j])) { - $document .= '-'; - } - elseif ($nextChar == '*') { - // Add to the stack. - $stack[$j]['*'] = true; - } - elseif ($nextChar == "'") { - // If it is a single quote, read next two characters that - // are the hexadecimal notation of a character we should add - // to the output stream. - $hex = substr($text, $i + 2, 2); - - if (self::_rtfIsPlain($stack[$j])) { - $document .= html_entity_decode('&#' . hexdec($hex) .';'); + case "\\": + // Key Word + $nextChar = $text[$i + 1]; + // If it is another backslash or nonbreaking space or hyphen, + // then the character is plain text and add it to the output stream. + if ($nextChar == "\\" && self::_rtfIsPlain($stack[$j])) { + $document .= "\\"; + } + elseif ($nextChar == '~' && self::_rtfIsPlain($stack[$j])) { + $document .= ' '; + } + elseif ($nextChar == '_' && self::_rtfIsPlain($stack[$j])) { + $document .= '-'; + } + elseif ($nextChar == '*') { + // Add to the stack. + $stack[$j]['*'] = true; } + elseif ($nextChar == "'") { + // If it is a single quote, read next two characters that + // are the hexadecimal notation of a character we should add + // to the output stream. + $hex = substr($text, $i + 2, 2); + + if (self::_rtfIsPlain($stack[$j])) { + $document .= html_entity_decode('&#' . hexdec($hex) .';'); + } - //Shift the pointer. - $i += 2; - } - elseif ($nextChar >= 'a' && $nextChar <= 'z' || $nextChar >= 'A' && $nextChar <= 'Z') { - // Since, we’ve found the alphabetic character, the next - // characters are control words and, possibly, some digit - // parameter. - $word = ''; - $param = null; - - // Start reading characters after the backslash. - for ($k = $i + 1, $m = 0; $k < strlen($text); $k++, $m++) { - $nextChar = $text[$k]; - // If the current character is a letter and there were - // no digits before it, then we’re still reading the - // control word. If there were digits, we should stop - // since we reach the end of the control word. - if ($nextChar >= 'a' && $nextChar <= 'z' - || $nextChar >= 'A' && $nextChar <= 'Z') { - if (!empty($param)) { - break; + //Shift the pointer. + $i += 2; + } + elseif ($nextChar >= 'a' && $nextChar <= 'z' || $nextChar >= 'A' && $nextChar <= 'Z') { + // Since, we’ve found the alphabetic character, the next + // characters are control words and, possibly, some digit + // parameter. + $word = ''; + $param = null; + + // Start reading characters after the backslash. + for ($k = $i + 1, $m = 0; $k < strlen($text); $k++, $m++) { + $nextChar = $text[$k]; + // If the current character is a letter and there were + // no digits before it, then we’re still reading the + // control word. If there were digits, we should stop + // since we reach the end of the control word. + if ($nextChar >= 'a' && $nextChar <= 'z' + || $nextChar >= 'A' && $nextChar <= 'Z') { + if (!empty($param)) { + break; + } + $word .= $nextChar; } - $word .= $nextChar; - } - elseif ($nextChar >= '0' && $nextChar <= '9') { - // If it is a digit, store the parameter. - $param .= $nextChar; - } - elseif ($nextChar == '-') { - // Since minus sign may occur only before a digit - // parameter, check whether $param is empty. - // Otherwise, we reach the end of the control word. - if (!empty($param)) { + elseif ($nextChar >= '0' && $nextChar <= '9') { + // If it is a digit, store the parameter. + $param .= $nextChar; + } + elseif ($nextChar == '-') { + // Since minus sign may occur only before a digit + // parameter, check whether $param is empty. + // Otherwise, we reach the end of the control word. + if (!empty($param)) { + break; + } + $param .= $nextChar; + } + else { break; } - $param .= $nextChar; } - else { - break; - } - } - // Shift the pointer on the number of read characters. - $i += $m - 1; - - // Start analyzing.We are interested mostly in control words - $toText = ''; - - switch (strtolower($word)) { - // If the control word is "u", then its parameter is - // the decimal notation of the Unicode character that - // should be added to the output stream. We need to - // check whether the stack contains \ucN control word. - // If it does, we should remove the N characters from - // the output stream. - case 'u': - $toText .= html_entity_decode('&#x' . dechex($param) .';'); - $ucDelta = @$stack[$j]['uc']; - if ($ucDelta > 0) { - $i += $ucDelta; + // Shift the pointer on the number of read characters. + $i += $m - 1; + + // Start analyzing.We are interested mostly in control words + $toText = ''; + + switch (strtolower($word)) { + // If the control word is "u", then its parameter is + // the decimal notation of the Unicode character that + // should be added to the output stream. We need to + // check whether the stack contains \ucN control word. + // If it does, we should remove the N characters from + // the output stream. + case 'u': + $toText .= html_entity_decode('&#x' . dechex($param) .';'); + $ucDelta = @$stack[$j]['uc']; + if ($ucDelta > 0) { + $i += $ucDelta; + } + break; + case 'par': + case 'page': + case 'column': + case 'line': + case 'lbr': + $toText .= "\n"; + break; + case 'emspace': + case 'enspace': + case 'qmspace': + $toText .= ' '; + break; + case 'tab': + $toText .= "\t"; + break; + case 'chdate': + $toText .= date('m.d.Y'); + break; + case 'chdpl': + $toText .= date('l, j F Y'); + break; + case 'chdpa': + $toText .= date('D, j M Y'); + break; + case 'chtime': + $toText .= date('H:i:s'); + break; + case 'emdash': + $toText .= html_entity_decode('—'); + break; + case 'endash': + $toText .= html_entity_decode('–'); + break; + case 'bullet': + $toText .= html_entity_decode('•'); + break; + case 'lquote': + $toText .= html_entity_decode('‘'); + break; + case 'rquote': + $toText .= html_entity_decode('’'); + break; + case 'ldblquote': + $toText .= html_entity_decode('«'); + break; + case 'rdblquote': + $toText .= html_entity_decode('»'); + break; + default: + $stack[$j][strtolower($word)] = empty($param) ? true : $param; + break; } - break; - case 'par': - case 'page': - case 'column': - case 'line': - case 'lbr': - $toText .= "\n"; - break; - case 'emspace': - case 'enspace': - case 'qmspace': - $toText .= ' '; - break; - case 'tab': - $toText .= "\t"; - break; - case 'chdate': - $toText .= date('m.d.Y'); - break; - case 'chdpl': - $toText .= date('l, j F Y'); - break; - case 'chdpa': - $toText .= date('D, j M Y'); - break; - case 'chtime': - $toText .= date('H:i:s'); - break; - case 'emdash': - $toText .= html_entity_decode('—'); - break; - case 'endash': - $toText .= html_entity_decode('–'); - break; - case 'bullet': - $toText .= html_entity_decode('•'); - break; - case 'lquote': - $toText .= html_entity_decode('‘'); - break; - case 'rquote': - $toText .= html_entity_decode('’'); - break; - case 'ldblquote': - $toText .= html_entity_decode('«'); - break; - case 'rdblquote': - $toText .= html_entity_decode('»'); - break; - default: - $stack[$j][strtolower($word)] = empty($param) ? true : $param; - break; - } - // Add data to the output stream if required. - if (self::_rtfIsPlain($stack[$j])) { - $document .= $toText; + // Add data to the output stream if required. + if (self::_rtfIsPlain($stack[$j])) { + $document .= $toText; + } } - } - $i++; - break; + $i++; + break; - case '{': - // New subgroup starts, add new stack element and write the data - // from previous stack element to it. - if (!empty($stack[$j])) { - array_push($stack, $stack[$j++]); - } - else { - $j++; - } - break; + case '{': + // New subgroup starts, add new stack element and write the data + // from previous stack element to it. + if (!empty($stack[$j])) { + array_push($stack, $stack[$j++]); + } + else { + $j++; + } + break; - case '}': - array_pop($stack); - $j--; - break; + case '}': + array_pop($stack); + $j--; + break; - case '\0': - case '\r': - case '\f': - case '\n': - // Junk - break; + case '\0': + case '\r': + case '\f': + case '\n': + // Junk + break; - default: - // Add other data to the output stream if required. - if (!empty($stack[$j]) && self::_rtfIsPlain($stack[$j])) { - $document .= $c; - } - break; + default: + // Add other data to the output stream if required. + if (!empty($stack[$j]) && self::_rtfIsPlain($stack[$j])) { + $document .= $c; + } + break; } } diff --git a/program/lib/Roundcube/rcube_uploads.php b/program/lib/Roundcube/rcube_uploads.php index 4f913328071..af067eb7de6 100644 --- a/program/lib/Roundcube/rcube_uploads.php +++ b/program/lib/Roundcube/rcube_uploads.php @@ -1,6 +1,6 @@ rc->plugins->exec_hook('preferences_update', [ 'userid' => $this->ID, 'prefs' => $a_user_prefs, - 'old' => (array)$this->get_prefs() + 'old' => (array) $this->get_prefs() ]); if (!empty($plugin['abort'])) { diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 15519f9f933..09bd0d7b65a 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -1,6 +1,6 @@ pattern, 1, -1) . ')'; $regexp = '/(^\s*|,\s*|\}\s*|\{\s*)(' . $excl . ':?[a-z0-9\._#\*\[][a-z0-9\._:\(\)#=~ \[\]"\|\>\+\$\^-]*)/im'; - $callback = function($matches) use ($container_id, $prefix) { + $callback = function ($matches) use ($container_id, $prefix) { $replace = $matches[2]; if (stripos($replace, ':root') === 0) { @@ -630,7 +630,7 @@ public static function file2class($mimetype, $filename) */ public static function xss_entity_decode($content) { - $callback = function($matches) { return chr(hexdec($matches[1])); }; + $callback = function ($matches) { return chr(hexdec($matches[1])); }; $out = html_entity_decode(html_entity_decode($content)); $out = trim(preg_replace('/(^$)/', '', trim($out))); @@ -692,7 +692,8 @@ public static function https_check($port = null, $use_https = true) /** * Check if the reported REMOTE_ADDR is in the 'proxy_whitelist' config option */ - public static function check_proxy_whitelist_ip() { + public static function check_proxy_whitelist_ip() + { return in_array($_SERVER['REMOTE_ADDR'], (array) rcube::get_instance()->config->get('proxy_whitelist', [])); } @@ -1236,7 +1237,7 @@ public static function normalize_string($str, $as_array = false, $minlen = 2) $arr = self::tokenize_string($str, $minlen); // detect character set - if (rcube_charset::convert(rcube_charset::convert($str, 'UTF-8', 'ISO-8859-1'), 'ISO-8859-1', 'UTF-8') == $str) { + if (rcube_charset::convert(rcube_charset::convert($str, 'UTF-8', 'ISO-8859-1'), 'ISO-8859-1', 'UTF-8') == $str) { // ISO-8859-1 (or ASCII) preg_match_all('/./u', 'äâàåáãæçéêëèïîìíñöôòøõóüûùúýÿ', $keys); preg_match_all('/./', 'aaaaaaaceeeeiiiinoooooouuuuyy', $values); @@ -1655,10 +1656,10 @@ public static function temp_filename($file_name, $unique = true, $create = true) /** * Clean the subject from reply and forward prefix - * + * * @param string $subject Subject to clean * @param string $mode Mode of cleaning : reply, forward or both - * + * * @return string Cleaned subject */ public static function remove_subject_prefix($subject, $mode = 'both') @@ -1681,7 +1682,7 @@ public static function remove_subject_prefix($subject, $mode = 'both') } // replace Re:, Re[x]:, Re-x (#1490497) - $pieces = array_map(function($prefix) { + $pieces = array_map(function ($prefix) { $prefix = strtolower(str_replace(':', '', $prefix)); return "$prefix:|$prefix\[\d\]:|$prefix-\d:"; }, $prefixes); @@ -1699,7 +1700,7 @@ public static function remove_subject_prefix($subject, $mode = 'both') * into the TCP stream, if configured. * * http://www.haproxy.org/download/1.6/doc/proxy-protocol.txt - * + * * PROXY protocol headers must be sent before any other data is sent on the TCP socket. * * @param array $options Preferences array which may contain proxy_protocol (generally {driver}_conn_options) diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php index dce8afe32c1..fce068cbb50 100644 --- a/program/lib/Roundcube/rcube_vcard.php +++ b/program/lib/Roundcube/rcube_vcard.php @@ -1,6 +1,6 @@ [], - 'N' => [['','','','','']], + 'N' => [['', '', '', '', '']], ]; private static $fieldmap = [ 'phone' => 'TEL', @@ -332,7 +332,7 @@ public function reset($fields = []) } if (empty($this->raw['N'])) { - $this->raw['N'] = [['','','','','']]; + $this->raw['N'] = [['', '', '', '', '']]; } if (empty($this->raw['FN'])) { @@ -355,116 +355,116 @@ public function set($field, $value, $type = 'HOME') $type_uc = strtoupper((string) $type); switch ($field) { - case 'name': - case 'displayname': - $this->raw['FN'][0][0] = $this->displayname = $value; - break; - - case 'surname': - $this->raw['N'][0][0] = $this->surname = $value; - break; - - case 'firstname': - $this->raw['N'][0][1] = $this->firstname = $value; - break; - - case 'middlename': - $this->raw['N'][0][2] = $this->middlename = $value; - break; - - case 'prefix': - $this->raw['N'][0][3] = $value; - break; - - case 'suffix': - $this->raw['N'][0][4] = $value; - break; - - case 'nickname': - $this->raw['NICKNAME'][0][0] = $this->nickname = $value; - break; - - case 'organization': - $this->raw['ORG'][0][0] = $this->organization = $value; - break; - - case 'photo': - if (strpos($value, 'http:') === 0) { - // TODO: fetch file from URL and save it locally? - $this->raw['PHOTO'][0] = [0 => $value, 'url' => true]; - } - else { - $this->raw['PHOTO'][0] = [0 => $value, 'base64' => (bool) preg_match('![^a-z0-9/=+-]!i', $value)]; - } - break; - - case 'email': - $this->raw['EMAIL'][] = [0 => $value, 'type' => array_filter(['INTERNET', $type_uc])]; - $this->email[] = $value; - break; - - case 'im': - // save IM subtypes into extension fields - $typemap = array_flip($this->immap); - if (!empty($typemap[strtolower($type)])) { - $field = $typemap[strtolower($type)]; - $this->raw[$field][] = [$value]; - } - break; + case 'name': + case 'displayname': + $this->raw['FN'][0][0] = $this->displayname = $value; + break; - case 'birthday': - case 'anniversary': - if (($val = rcube_utils::anytodatetime($value)) && !empty(self::$fieldmap[$field])) { - $fn = self::$fieldmap[$field]; - $this->raw[$fn][] = [0 => $val->format('Y-m-d'), 'value' => ['date']]; - } - break; + case 'surname': + $this->raw['N'][0][0] = $this->surname = $value; + break; - case 'address': - if (!empty($this->addresstypemap[$type_uc])) { - $type = $this->addresstypemap[$type_uc]; - } + case 'firstname': + $this->raw['N'][0][1] = $this->firstname = $value; + break; - if (empty($value[0])) { - $value = [ - '', - '', - $value['street'] ?? '', - $value['locality'] ?? '', - $value['region'] ?? '', - $value['zipcode'] ?? '', - $value['country'] ?? '', - ]; - } + case 'middlename': + $this->raw['N'][0][2] = $this->middlename = $value; + break; - // fall through if not empty - if (!strlen(@implode('', $value))) { + case 'prefix': + $this->raw['N'][0][3] = $value; break; - } - default: - if ($field == 'phone' && !empty($this->phonetypemap[$type_uc])) { - $type = $this->phonetypemap[$type_uc]; - } + case 'suffix': + $this->raw['N'][0][4] = $value; + break; - if (!empty(self::$fieldmap[$field])) { - $tag = self::$fieldmap[$field]; + case 'nickname': + $this->raw['NICKNAME'][0][0] = $this->nickname = $value; + break; - if (is_array($value) || (is_string($value) && strlen($value))) { - $this->raw[$tag][] = (array) $value; - if ($type) { - $index = count($this->raw[$tag]) - 1; - $typemap = array_flip($this->typemap); - $type_val = !empty($typemap[$type_uc]) ? $typemap[$type_uc] : $type; - $this->raw[$tag][$index]['type'] = explode(',', $type_val); - } + case 'organization': + $this->raw['ORG'][0][0] = $this->organization = $value; + break; + + case 'photo': + if (strpos($value, 'http:') === 0) { + // TODO: fetch file from URL and save it locally? + $this->raw['PHOTO'][0] = [0 => $value, 'url' => true]; } else { - unset($this->raw[$tag]); + $this->raw['PHOTO'][0] = [0 => $value, 'base64' => (bool) preg_match('![^a-z0-9/=+-]!i', $value)]; } - } + break; + + case 'email': + $this->raw['EMAIL'][] = [0 => $value, 'type' => array_filter(['INTERNET', $type_uc])]; + $this->email[] = $value; + break; - break; + case 'im': + // save IM subtypes into extension fields + $typemap = array_flip($this->immap); + if (!empty($typemap[strtolower($type)])) { + $field = $typemap[strtolower($type)]; + $this->raw[$field][] = [$value]; + } + break; + + case 'birthday': + case 'anniversary': + if (($val = rcube_utils::anytodatetime($value)) && !empty(self::$fieldmap[$field])) { + $fn = self::$fieldmap[$field]; + $this->raw[$fn][] = [0 => $val->format('Y-m-d'), 'value' => ['date']]; + } + break; + + case 'address': + if (!empty($this->addresstypemap[$type_uc])) { + $type = $this->addresstypemap[$type_uc]; + } + + if (empty($value[0])) { + $value = [ + '', + '', + $value['street'] ?? '', + $value['locality'] ?? '', + $value['region'] ?? '', + $value['zipcode'] ?? '', + $value['country'] ?? '', + ]; + } + + // fall through if not empty + if (!strlen(@implode('', $value))) { + break; + } + + default: + if ($field == 'phone' && !empty($this->phonetypemap[$type_uc])) { + $type = $this->phonetypemap[$type_uc]; + } + + if (!empty(self::$fieldmap[$field])) { + $tag = self::$fieldmap[$field]; + + if (is_array($value) || (is_string($value) && strlen($value))) { + $this->raw[$tag][] = (array) $value; + if ($type) { + $index = count($this->raw[$tag]) - 1; + $typemap = array_flip($this->typemap); + $type_val = !empty($typemap[$type_uc]) ? $typemap[$type_uc] : $type; + $this->raw[$tag][$index]['type'] = explode(',', $type_val); + } + } + else { + unset($this->raw[$tag]); + } + } + + break; } } @@ -811,17 +811,17 @@ private static function vcard_decode($vcard) private static function decode_value($value, $encoding) { switch (strtolower($encoding)) { - case 'quoted-printable': - self::$values_decoded = true; - return quoted_printable_decode($value); + case 'quoted-printable': + self::$values_decoded = true; + return quoted_printable_decode($value); - case 'base64': - case 'b': - self::$values_decoded = true; - return base64_decode($value); + case 'base64': + case 'b': + self::$values_decoded = true; + return base64_decode($value); - default: - return $value; + default: + return $value; } } @@ -851,8 +851,8 @@ static function vcard_encode($data) $data['N'][0][] = ''; } - foreach ((array)$data as $type => $entries) { - foreach ((array)$entries as $entry) { + foreach ((array) $data as $type => $entries) { + foreach ((array) $entries as $entry) { $attr = ''; if (is_array($entry)) { $value = []; @@ -876,7 +876,7 @@ static function vcard_encode($data) } } else { - foreach ((array)$attrvalues as $attrvalue) { + foreach ((array) $attrvalues as $attrvalue) { $attrname = strtoupper($attrname); // TYPE=OTHER is non-standard, TYPE=INTERNET is redundant, remove these if ($attrname == 'TYPE') { @@ -925,7 +925,7 @@ public static function vcard_quote($str, $sep = ';') $r[] = self::vcard_quote($part, $sep); } - return(implode($sep, $r)); + return (implode($sep, $r)); } return strtr($str, ["\\" => "\\\\", "\r" => '', "\n" => '\n', $sep => "\\$sep"]); diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php index 542174588fa..a7f543d42cb 100644 --- a/program/lib/Roundcube/rcube_washtml.php +++ b/program/lib/Roundcube/rcube_washtml.php @@ -1,6 +1,6 @@ _css_prefix . '\1', $value); } else if ($key) { - $out = $value; + $out = $value; } if ($out !== null && $out !== '') { @@ -587,79 +587,79 @@ private function dumpHtml($node, $level = 20) do { switch ($node->nodeType) { - case XML_ELEMENT_NODE: //Check element - $tagName = strtolower($node->nodeName); + case XML_ELEMENT_NODE: //Check element + $tagName = strtolower($node->nodeName); + + if ($tagName == 'link') { + $uri = $this->wash_uri($node->getAttribute('href'), false, false); + if (!$uri) { + $dump .= ''; + break; + } - if ($tagName == 'link') { - $uri = $this->wash_uri($node->getAttribute('href'), false, false); - if (!$uri) { - $dump .= ''; + $node->setAttribute('href', (string) $uri); + } + else if (in_array($tagName, ['animate', 'animatecolor', 'set', 'animatetransform']) + && self::attribute_value($node, 'attributename', 'href') + ) { + // Insecure svg tags + $dump .= ""; break; } - $node->setAttribute('href', (string) $uri); - } - else if (in_array($tagName, ['animate', 'animatecolor', 'set', 'animatetransform']) - && self::attribute_value($node, 'attributename', 'href') - ) { - // Insecure svg tags - $dump .= ""; - break; - } - - if (!empty($this->handlers[$tagName])) { - $callback = $this->handlers[$tagName]; - $dump .= call_user_func($callback, $tagName, - $this->wash_attribs($node), $this->dumpHtml($node, $level), $this); - } - else if (isset($this->_html_elements[$tagName])) { - $content = $this->dumpHtml($node, $level); - $dump .= '<' . $node->nodeName; - - if ($tagName == 'svg') { - $xpath = new DOMXPath($node->ownerDocument); - foreach ($xpath->query('namespace::*') as $ns) { - if ($ns->nodeName != 'xmlns:xml') { - $dump .= sprintf(' %s="%s"', - $ns->nodeName, - htmlspecialchars($ns->nodeValue, ENT_QUOTES, $this->config['charset']) - ); + if (!empty($this->handlers[$tagName])) { + $callback = $this->handlers[$tagName]; + $dump .= call_user_func($callback, $tagName, + $this->wash_attribs($node), $this->dumpHtml($node, $level), $this); + } + else if (isset($this->_html_elements[$tagName])) { + $content = $this->dumpHtml($node, $level); + $dump .= '<' . $node->nodeName; + + if ($tagName == 'svg') { + $xpath = new DOMXPath($node->ownerDocument); + foreach ($xpath->query('namespace::*') as $ns) { + if ($ns->nodeName != 'xmlns:xml') { + $dump .= sprintf(' %s="%s"', + $ns->nodeName, + htmlspecialchars($ns->nodeValue, ENT_QUOTES, $this->config['charset']) + ); + } } } - } - else if ($tagName == 'textarea' && strpos($content, '<') !== false) { - $content = htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, $this->config['charset']); - } + else if ($tagName == 'textarea' && strpos($content, '<') !== false) { + $content = htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, $this->config['charset']); + } - $dump .= $this->wash_attribs($node); + $dump .= $this->wash_attribs($node); - if ($content === '' && ($this->is_xml || isset($this->_void_elements[$tagName]))) { - $dump .= ' />'; + if ($content === '' && ($this->is_xml || isset($this->_void_elements[$tagName]))) { + $dump .= ' />'; + } + else { + $dump .= '>' . $content . 'nodeName . '>'; + } + } + else if (isset($this->_ignore_elements[$tagName])) { + $dump .= ''; } else { - $dump .= '>' . $content . 'nodeName . '>'; + $dump .= ''; + $dump .= $this->dumpHtml($node, $level); // ignore tags not its content } - } - else if (isset($this->_ignore_elements[$tagName])) { - $dump .= ''; - } - else { - $dump .= ''; - $dump .= $this->dumpHtml($node, $level); // ignore tags not its content - } - break; + break; - case XML_CDATA_SECTION_NODE: - case XML_TEXT_NODE: - $dump .= htmlspecialchars($node->nodeValue, ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE, $this->config['charset']); - break; + case XML_CDATA_SECTION_NODE: + case XML_TEXT_NODE: + $dump .= htmlspecialchars($node->nodeValue, ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE, $this->config['charset']); + break; - case XML_HTML_DOCUMENT_NODE: - $dump .= $this->dumpHtml($node, $level); - break; + case XML_HTML_DOCUMENT_NODE: + $dump .= $this->dumpHtml($node, $level); + break; } } - while($node = $node->nextSibling); + while ($node = $node->nextSibling); return $dump; } diff --git a/program/lib/Roundcube/session/db.php b/program/lib/Roundcube/session/db.php index df0e16387e6..dc1f4c3994d 100644 --- a/program/lib/Roundcube/session/db.php +++ b/program/lib/Roundcube/session/db.php @@ -1,6 +1,6 @@ db->query("INSERT INTO {$this->table_name}" . " (`sess_id`, `vars`, `ip`, `changed`)" . " VALUES (?, ?, ?, $now)", - $key, base64_encode($vars), (string)$this->ip + $key, base64_encode($vars), (string) $this->ip ); return true; diff --git a/program/lib/Roundcube/session/memcache.php b/program/lib/Roundcube/session/memcache.php index b6fe20cbdaf..092db3f75b6 100644 --- a/program/lib/Roundcube/session/memcache.php +++ b/program/lib/Roundcube/session/memcache.php @@ -1,6 +1,6 @@ plugins->register_hook('attachment_upload', function($att) use ($file) { + $rcmail->plugins->register_hook('attachment_upload', function ($att) use ($file) { $att['status'] = true; $att['id'] = $file['id']; return $att; @@ -229,7 +229,7 @@ protected function fileUpload($group) // Attachments handling plugins use move_uploaded_file() which does not work // here. We'll add a fake hook handler for our purposes. $rcmail = rcmail::get_instance(); - $rcmail->plugins->register_hook('attachment_upload', function($att) use ($file) { + $rcmail->plugins->register_hook('attachment_upload', function ($att) use ($file) { $att['status'] = true; $att['id'] = $file['id']; return $att; diff --git a/tests/Actions/Contacts/Edit.php b/tests/Actions/Contacts/Edit.php index 96ff745524a..880efa25d27 100644 --- a/tests/Actions/Contacts/Edit.php +++ b/tests/Actions/Contacts/Edit.php @@ -100,6 +100,6 @@ function test_photo_drop_area() $this->assertSame('upload-photo', $filedrop['action']); $this->assertSame('_photo', $filedrop['fieldname']); $this->assertSame(1, $filedrop['single']); - $this->assertSame( '^image/.+', $filedrop['filter']); + $this->assertSame('^image/.+', $filedrop['filter']); } } diff --git a/tests/Actions/Mail/AttachmentDelete.php b/tests/Actions/Mail/AttachmentDelete.php index c75a604c223..70858d8c6a1 100644 --- a/tests/Actions/Mail/AttachmentDelete.php +++ b/tests/Actions/Mail/AttachmentDelete.php @@ -30,7 +30,7 @@ function test_run() // This is needed so upload deletion works $rcmail = rcmail::get_instance(); unset($rcmail->plugins->handlers['attachment_delete']); - $rcmail->plugins->register_hook('attachment_delete', function($att) { + $rcmail->plugins->register_hook('attachment_delete', function ($att) { $att['status'] = true; $att['break'] = true; return $att; diff --git a/tests/Actions/Mail/Index.php b/tests/Actions/Mail/Index.php index f7197932a69..7f8736e8612 100644 --- a/tests/Actions/Mail/Index.php +++ b/tests/Actions/Mail/Index.php @@ -341,7 +341,7 @@ function test_html() $this->assertMatchesRegularExpression('/Subscription form/', $html, "Include
contents"); $this->assertMatchesRegularExpression('//', $html, "No external links allowed"); $this->assertMatchesRegularExpression('/]+ target="_blank"/', $html, "Set target to _blank"); -// $this->assertTrue($GLOBALS['REMOTE_OBJECTS'], "Remote object detected"); + // $this->assertTrue($GLOBALS['REMOTE_OBJECTS'], "Remote object detected"); // render HTML in safe mode $body = rcmail_action_mail_index::print_body($part->body, $part, ['safe' => true]); diff --git a/tests/Actions/Mail/Search.php b/tests/Actions/Mail/Search.php index 1c94456bce7..43b252c8514 100644 --- a/tests/Actions/Mail/Search.php +++ b/tests/Actions/Mail/Search.php @@ -72,7 +72,7 @@ function test_search_non_empty_result() self::initStorage() ->registerFunction('set_page') ->registerFunction('set_search_set') - ->registerFunction('search',) + ->registerFunction('search') ->registerFunction('get_search_set', ['SEARCH HEADER SUBJECT test', $index, 'UTF-8', '', false]) ->registerFunction('get_search_set', ['SEARCH HEADER SUBJECT test', $index, 'UTF-8', '', false]) ->registerFunction('get_pagesize', 10) diff --git a/tests/Browser/Browser.php b/tests/Browser/Browser.php index afc726b4072..523953ba3d7 100644 --- a/tests/Browser/Browser.php +++ b/tests/Browser/Browser.php @@ -4,7 +4,6 @@ use Facebook\WebDriver\WebDriverKeys; use PHPUnit\Framework\Assert; -use Tests\Browser\Components; /** * Laravel Dusk Browser extensions @@ -280,7 +279,7 @@ public function waitUntilMissingOrStale($selector, $seconds = null) return $this->waitUsing($seconds, 100, function () use ($selector) { try { - $missing = ! $this->resolver->findOrFail($selector)->isDisplayed(); + $missing = !$this->resolver->findOrFail($selector)->isDisplayed(); } catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) { $missing = true; } catch (\Facebook\WebDriver\Exception\StaleElementReferenceException $e) { diff --git a/tests/Browser/Components/Dialog.php b/tests/Browser/Components/Dialog.php index 6a26044e2f4..cc91f8ab1c4 100644 --- a/tests/Browser/Components/Dialog.php +++ b/tests/Browser/Components/Dialog.php @@ -2,8 +2,8 @@ namespace Tests\Browser\Components; -use Tests\Browser\Browser; use Laravel\Dusk\Component; +use Tests\Browser\Browser; class Dialog extends Component { diff --git a/tests/Browser/Components/HtmlEditor.php b/tests/Browser/Components/HtmlEditor.php index 0a3cc8cb2f4..6851862e339 100644 --- a/tests/Browser/Components/HtmlEditor.php +++ b/tests/Browser/Components/HtmlEditor.php @@ -2,9 +2,8 @@ namespace Tests\Browser\Components; -use App; -use Tests\Browser\Browser; use Laravel\Dusk\Component; +use Tests\Browser\Browser; class HtmlEditor extends Component { diff --git a/tests/Browser/Components/Popupmenu.php b/tests/Browser/Components/Popupmenu.php index a412c9f5dbe..f86d2f9679e 100644 --- a/tests/Browser/Components/Popupmenu.php +++ b/tests/Browser/Components/Popupmenu.php @@ -2,8 +2,8 @@ namespace Tests\Browser\Components; -use Tests\Browser\Browser; use Laravel\Dusk\Component; +use Tests\Browser\Browser; class Popupmenu extends Component { diff --git a/tests/Browser/Components/RecipientInput.php b/tests/Browser/Components/RecipientInput.php index d851252d1a7..be992b9ea71 100644 --- a/tests/Browser/Components/RecipientInput.php +++ b/tests/Browser/Components/RecipientInput.php @@ -2,9 +2,9 @@ namespace Tests\Browser\Components; -use Tests\Browser\Browser; -use PHPUnit\Framework\Assert; use Laravel\Dusk\Component; +use PHPUnit\Framework\Assert; +use Tests\Browser\Browser; class RecipientInput extends Component { diff --git a/tests/Browser/Components/Taskmenu.php b/tests/Browser/Components/Taskmenu.php index 3ea67f1582b..ca19f64c1e1 100644 --- a/tests/Browser/Components/Taskmenu.php +++ b/tests/Browser/Components/Taskmenu.php @@ -2,8 +2,8 @@ namespace Tests\Browser\Components; -use Tests\Browser\Browser; use Laravel\Dusk\Component; +use Tests\Browser\Browser; class Taskmenu extends Component { diff --git a/tests/Browser/Components/Toolbarmenu.php b/tests/Browser/Components/Toolbarmenu.php index ffb610b0c91..09562ac2750 100644 --- a/tests/Browser/Components/Toolbarmenu.php +++ b/tests/Browser/Components/Toolbarmenu.php @@ -2,8 +2,8 @@ namespace Tests\Browser\Components; -use Tests\Browser\Browser; use Laravel\Dusk\Component; +use Tests\Browser\Browser; class Toolbarmenu extends Component { diff --git a/tests/Browser/Contacts/ImportTest.php b/tests/Browser/Contacts/ImportTest.php index b8c5868c9ce..6a553e2df15 100644 --- a/tests/Browser/Contacts/ImportTest.php +++ b/tests/Browser/Contacts/ImportTest.php @@ -79,8 +79,8 @@ public function testImportProcess() $browser->with(new Dialog(), function ($browser) { $browser->withinDialogFrame(function ($browser) { - $browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf'); - }) + $browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf'); + }) ->clickButton('import') ->withinDialogFrame(function ($browser) { $browser->waitForText('Successfully imported 2 contacts:'); diff --git a/tests/Browser/Mail/ListTest.php b/tests/Browser/Mail/ListTest.php index f9c405675c3..d26e6c675d5 100644 --- a/tests/Browser/Mail/ListTest.php +++ b/tests/Browser/Mail/ListTest.php @@ -115,7 +115,7 @@ public function testListSelection() // Popup menu content $browser->waitFor('#listselect-menu'); - $browser->with('#listselect-menu', function($browser) { + $browser->with('#listselect-menu', function ($browser) { $browser->assertVisible('a.selection:not(.disabled)'); $browser->assertVisible('a.select.all:not(.disabled)'); $browser->assertVisible('a.select.page:not(.disabled)'); diff --git a/tests/Browser/Mail/PreviewTest.php b/tests/Browser/Mail/PreviewTest.php index d9edb10194e..2234e3b9e14 100644 --- a/tests/Browser/Mail/PreviewTest.php +++ b/tests/Browser/Mail/PreviewTest.php @@ -2,9 +2,7 @@ namespace Tests\Browser\Mail; -use Tests\Browser\Components\App; use Tests\Browser\Components\Dialog; -use Tests\Browser\Components\Popupmenu; class PreviewTest extends \Tests\Browser\TestCase { @@ -101,7 +99,7 @@ public function testPreview() $browser->assertVisible('a.extwin:not(.disabled)') ->assertVisible('a.download:not(.disabled)') ->click('a.download'); - }); + }); } }); diff --git a/tests/Browser/Settings/FoldersTest.php b/tests/Browser/Settings/FoldersTest.php index 45f3985cfb6..af34aa290b1 100644 --- a/tests/Browser/Settings/FoldersTest.php +++ b/tests/Browser/Settings/FoldersTest.php @@ -87,7 +87,7 @@ public function testFolderCreate() $browser->clickToolbarMenuItem('create'); } - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form') ->with('form fieldset', function ($browser) { $browser->assertVisible('input[name=_name]') @@ -136,7 +136,7 @@ public function testFolderCreate() $browser->waitFor('#preferences-frame'); } - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form'); // TODO }); diff --git a/tests/Browser/Settings/IdentitiesTest.php b/tests/Browser/Settings/IdentitiesTest.php index 328c1d7feb6..4441f07a54b 100644 --- a/tests/Browser/Settings/IdentitiesTest.php +++ b/tests/Browser/Settings/IdentitiesTest.php @@ -4,7 +4,6 @@ use Tests\Browser\Components\App; use Tests\Browser\Components\Dialog; -use Tests\Browser\Components\Popupmenu; class IdentitiesTest extends \Tests\Browser\TestCase { @@ -60,7 +59,7 @@ public function testIdentityCreate() $browser->clickToolbarMenuItem('create'); } - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form') ->with('form fieldset:nth-of-type(1)', function ($browser) { $browser->assertSeeIn('legend', 'Settings') @@ -111,7 +110,7 @@ public function testIdentityCreate() ->closeMessage('confirmation') ->waitFor('#preferences-frame'); - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->whenAvailable('form', function ($browser) { $browser->assertValue('input[name=_name]', 'My Test') ->assertValue('input[name=_email]', 'mynew@identity.com') @@ -165,7 +164,7 @@ public function testIdentityDelete() ->closeMessage('confirmation'); // Preview frame should reset to the watermark page - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitUntilMissing('> div'); }); @@ -191,7 +190,7 @@ public function testIdentityUpdate() ->waitFor('#preferences-frame') ->waitUntilMissing('#messagestack div.loading'); - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->whenAvailable('form', function ($browser) { $browser->type('[name=_name]', 'Default') ->type('[name=_organization]', 'Default Org'); diff --git a/tests/Browser/Settings/PreferencesTest.php b/tests/Browser/Settings/PreferencesTest.php index e8998358dd4..424e911bf64 100644 --- a/tests/Browser/Settings/PreferencesTest.php +++ b/tests/Browser/Settings/PreferencesTest.php @@ -24,7 +24,7 @@ public function testPreferences() ->waitFor('#sections-table'); } // Preferences actions - $browser->with('#sections-table', function($browser) { + $browser->with('#sections-table', function ($browser) { $browser->assertSeeIn('tr.general', 'User Interface') ->assertSeeIn('tr.mailbox', 'Mailbox View') ->assertSeeIn('tr.mailview', 'Displaying Messages') diff --git a/tests/Browser/Settings/ResponsesTest.php b/tests/Browser/Settings/ResponsesTest.php index 2dab5abf476..bb175ff5811 100644 --- a/tests/Browser/Settings/ResponsesTest.php +++ b/tests/Browser/Settings/ResponsesTest.php @@ -66,7 +66,7 @@ public function testResponseCreate() $browser->clickToolbarMenuItem('create'); } - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form') ->with('form', function ($browser) { $browser->assertVisible('input[name=_name]') @@ -93,7 +93,7 @@ public function testResponseCreate() ->closeMessage('confirmation') ->waitFor('#preferences-frame'); - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form') ->with('form', function ($browser) { $browser->assertVisible('input[name=_name]') @@ -147,7 +147,7 @@ public function testResponseDelete() ->closeMessage('confirmation'); // Preview frame should reset to the watermark page - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitUntilMissing('> div'); }); @@ -231,7 +231,7 @@ public function testResponseUpdate() ->click('#responses-table tbody tr:first-child') ->waitFor('#preferences-frame'); - $browser->withinFrame('#preferences-frame', function($browser) { + $browser->withinFrame('#preferences-frame', function ($browser) { $browser->waitFor('form') ->with('form', function ($browser) { $browser->assertValue('[name=_name]', 'response 1') diff --git a/tests/Browser/Settings/SettingsTest.php b/tests/Browser/Settings/SettingsTest.php index ad6995be393..2353894481b 100644 --- a/tests/Browser/Settings/SettingsTest.php +++ b/tests/Browser/Settings/SettingsTest.php @@ -19,7 +19,7 @@ public function testSettings() $browser->assertSeeIn('#layout-sidebar .header', 'Settings'); // Sidebar menu - $browser->with('#settings-menu', function($browser) { + $browser->with('#settings-menu', function ($browser) { $browser->assertSeeIn('li.preferences', 'Preferences'); $browser->assertSeeIn('li.folders', 'Folders'); $browser->assertSeeIn('li.identities', 'Identities'); diff --git a/tests/Browser/TestCase.php b/tests/Browser/TestCase.php index 664426b204b..dbcf2e02b8f 100644 --- a/tests/Browser/TestCase.php +++ b/tests/Browser/TestCase.php @@ -2,12 +2,12 @@ namespace Tests\Browser; -use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Facebook\WebDriver\Chrome\ChromeOptions; -use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\DesiredCapabilities; +use Facebook\WebDriver\Remote\RemoteWebDriver; use Laravel\Dusk\Chrome\SupportsChrome; use Laravel\Dusk\Concerns\ProvidesBrowser; +use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Process; diff --git a/tests/Browser/bootstrap.php b/tests/Browser/bootstrap.php index 8bbe6ae5b68..08422cf4522 100644 --- a/tests/Browser/bootstrap.php +++ b/tests/Browser/bootstrap.php @@ -23,10 +23,10 @@ } if (!defined('INSTALL_PATH')) { - define('INSTALL_PATH', realpath(__DIR__ . '/../../') . '/' ); + define('INSTALL_PATH', realpath(__DIR__ . '/../../') . '/'); } -require_once(INSTALL_PATH . 'program/include/iniset.php'); +require_once INSTALL_PATH . 'program/include/iniset.php'; $rcmail = rcmail::get_instance(0, 'test'); @@ -34,15 +34,15 @@ define('TESTS_USER', $rcmail->config->get('tests_username')); define('TESTS_PASS', $rcmail->config->get('tests_password')); -require_once(__DIR__ . '/Browser.php'); -require_once(__DIR__ . '/TestCase.php'); -require_once(__DIR__ . '/Components/App.php'); -require_once(__DIR__ . '/Components/Dialog.php'); -require_once(__DIR__ . '/Components/HtmlEditor.php'); -require_once(__DIR__ . '/Components/Popupmenu.php'); -require_once(__DIR__ . '/Components/RecipientInput.php'); -require_once(__DIR__ . '/Components/Taskmenu.php'); -require_once(__DIR__ . '/Components/Toolbarmenu.php'); +require_once __DIR__ . '/Browser.php'; +require_once __DIR__ . '/TestCase.php'; +require_once __DIR__ . '/Components/App.php'; +require_once __DIR__ . '/Components/Dialog.php'; +require_once __DIR__ . '/Components/HtmlEditor.php'; +require_once __DIR__ . '/Components/Popupmenu.php'; +require_once __DIR__ . '/Components/RecipientInput.php'; +require_once __DIR__ . '/Components/Taskmenu.php'; +require_once __DIR__ . '/Components/Toolbarmenu.php'; /** @@ -160,7 +160,7 @@ public static function connect_imap($username, $password) if (!empty($a_host['host'])) { $imap_host = $a_host['host']; - $imap_ssl = isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls']) ? $a_host['scheme'] : false; + $imap_ssl = isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl', 'imaps', 'tls']) ? $a_host['scheme'] : false; $imap_port = $a_host['port'] ?? ($imap_ssl && $imap_ssl != 'tls' ? 993 : 143); } @@ -275,7 +275,7 @@ public static function get_prefs() // Create a separate connection to the DB, otherwise // we hit some strange and hard to investigate locking issues $db = rcube_db::factory($rcmail->config->get('db_dsnw'), $rcmail->config->get('db_dsnr'), false); - $db->set_debug((bool)$rcmail->config->get('sql_debug')); + $db->set_debug((bool) $rcmail->config->get('sql_debug')); $query = $db->query("SELECT preferences FROM users WHERE username = ?", TESTS_USER); $record = $db->fetch_assoc($query); diff --git a/tests/Browser/install.php b/tests/Browser/install.php index 7788fb210f9..6c81e16c7d1 100644 --- a/tests/Browser/install.php +++ b/tests/Browser/install.php @@ -22,10 +22,10 @@ } if (!defined('INSTALL_PATH')) { - define('INSTALL_PATH', realpath(__DIR__ . '/../../') . '/' ); + define('INSTALL_PATH', realpath(__DIR__ . '/../../') . '/'); } -require_once(INSTALL_PATH . 'program/include/iniset.php'); +require_once INSTALL_PATH . 'program/include/iniset.php'; class Installer extends Laravel\Dusk\Console\ChromeDriverCommand { diff --git a/tests/ExitException.php b/tests/ExitException.php index e092f20605b..cd7639acc1e 100644 --- a/tests/ExitException.php +++ b/tests/ExitException.php @@ -1,6 +1,6 @@ $data) { - foreach($keys as $key) { + foreach ($keys as $key) { $extracted[$data['useragent']][] = $data[$key]; } } diff --git a/tests/Framework/Config.php b/tests/Framework/Config.php index 700e8f3f8f0..a720c4e8bd7 100644 --- a/tests/Framework/Config.php +++ b/tests/Framework/Config.php @@ -7,7 +7,6 @@ */ class Framework_Config extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ContentFilter.php b/tests/Framework/ContentFilter.php index a5fb25e2a7a..59a3c6c5bcf 100644 --- a/tests/Framework/ContentFilter.php +++ b/tests/Framework/ContentFilter.php @@ -7,7 +7,6 @@ */ class Framework_ContentFilter extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php index 2f08686da53..430204c5532 100644 --- a/tests/Framework/Csv2vcard.php +++ b/tests/Framework/Csv2vcard.php @@ -7,7 +7,6 @@ */ class Framework_Csv2vcard extends PHPUnit\Framework\TestCase { - function test_import_generic() { $csv = new rcube_csv2vcard; diff --git a/tests/Framework/DB.php b/tests/Framework/DB.php index 09d40eac1dc..9979131c4c9 100644 --- a/tests/Framework/DB.php +++ b/tests/Framework/DB.php @@ -291,9 +291,7 @@ public function is_connected() return true; } - protected function debug($data) - { - } + protected function debug($data) {} } class rcube_db_test_dbh diff --git a/tests/Framework/DBMysql.php b/tests/Framework/DBMysql.php index 1d5a3fc9a40..20b747d1a19 100644 --- a/tests/Framework/DBMysql.php +++ b/tests/Framework/DBMysql.php @@ -9,7 +9,6 @@ */ class Framework_DBMysql extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/DBSqlite.php b/tests/Framework/DBSqlite.php index 7f33cec099b..3140fe0aeff 100644 --- a/tests/Framework/DBSqlite.php +++ b/tests/Framework/DBSqlite.php @@ -9,7 +9,6 @@ */ class Framework_DBSqlite extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Enriched.php b/tests/Framework/Enriched.php index e85d47b2fb8..a7f39df28bb 100644 --- a/tests/Framework/Enriched.php +++ b/tests/Framework/Enriched.php @@ -7,7 +7,6 @@ */ class Framework_Enriched extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Html.php b/tests/Framework/Html.php index b7bba9d4900..618a1be4097 100644 --- a/tests/Framework/Html.php +++ b/tests/Framework/Html.php @@ -7,7 +7,6 @@ */ class Framework_Html extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php index b5e780e3519..cd154241f6f 100644 --- a/tests/Framework/Html2text.php +++ b/tests/Framework/Html2text.php @@ -7,7 +7,6 @@ */ class rc_html2text extends PHPUnit\Framework\TestCase { - function data_html2text() { return [ diff --git a/tests/Framework/HtmlCheckbox.php b/tests/Framework/HtmlCheckbox.php index e8d5b39c1bc..2cc80f2fcae 100644 --- a/tests/Framework/HtmlCheckbox.php +++ b/tests/Framework/HtmlCheckbox.php @@ -7,7 +7,6 @@ */ class Framework_HtmlCheckbox extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Imap.php b/tests/Framework/Imap.php index 858f1c7b393..3b58a8739f1 100644 --- a/tests/Framework/Imap.php +++ b/tests/Framework/Imap.php @@ -7,7 +7,6 @@ */ class Framework_Imap extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ImapCache.php b/tests/Framework/ImapCache.php index 074ebd281fa..62c03679a49 100644 --- a/tests/Framework/ImapCache.php +++ b/tests/Framework/ImapCache.php @@ -7,7 +7,6 @@ */ class Framework_ImapCache extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ImapGeneric.php b/tests/Framework/ImapGeneric.php index 82c8b98399f..927a3f8b433 100644 --- a/tests/Framework/ImapGeneric.php +++ b/tests/Framework/ImapGeneric.php @@ -7,7 +7,6 @@ */ class Framework_ImapGeneric extends PHPUnit\Framework\TestCase { - /** * Class constructor */ @@ -68,10 +67,10 @@ function test_sortHeaders() */ function test_compressMessageSet() { - $result = rcube_imap_generic::compressMessageSet([5,4,3]); + $result = rcube_imap_generic::compressMessageSet([5, 4, 3]); $this->assertSame('3:5', $result); - $result = rcube_imap_generic::compressMessageSet([5,4,3,10,12,13]); + $result = rcube_imap_generic::compressMessageSet([5, 4, 3, 10, 12, 13]); $this->assertSame('3:5,10,12:13', $result); $result = rcube_imap_generic::compressMessageSet('1'); diff --git a/tests/Framework/ImapSearch.php b/tests/Framework/ImapSearch.php index 458fefc8236..611a09c2e62 100644 --- a/tests/Framework/ImapSearch.php +++ b/tests/Framework/ImapSearch.php @@ -7,7 +7,6 @@ */ class Framework_ImapSearch extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Ldap.php b/tests/Framework/Ldap.php index 5034a83d780..3875b4b411a 100644 --- a/tests/Framework/Ldap.php +++ b/tests/Framework/Ldap.php @@ -7,7 +7,6 @@ */ class Framework_Ldap extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/MessageHeader.php b/tests/Framework/MessageHeader.php index 8ba0ab2ad64..0112d487302 100644 --- a/tests/Framework/MessageHeader.php +++ b/tests/Framework/MessageHeader.php @@ -7,7 +7,6 @@ */ class Framework_MessageHeader extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/MessagePart.php b/tests/Framework/MessagePart.php index dc3cc759759..2136762bfa0 100644 --- a/tests/Framework/MessagePart.php +++ b/tests/Framework/MessagePart.php @@ -7,7 +7,6 @@ */ class Framework_MessagePart extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php index abe9939c2c4..7641cf32f64 100644 --- a/tests/Framework/Mime.php +++ b/tests/Framework/Mime.php @@ -7,7 +7,6 @@ */ class Framework_Mime extends PHPUnit\Framework\TestCase { - /** * Test decoding of single e-mail address strings * Uses rcube_mime::decode_address_list() @@ -122,7 +121,7 @@ function test_decode_address_groups() 5 => [ 1 => ['name' => 'TEST1', 'mailto' => 'test1@email.com', 'string' => 'TEST1 '], 2 => ['name' => 'TEST2', 'mailto' => 'test2@email.com', 'string' => 'TEST2 '], - 3 => ['name' => '', 'mailto' => 'test3@email.com', 'string' => 'test3@email.com'], + 3 => ['name' => '', 'mailto' => 'test3@email.com', 'string' => 'test3@email.com'], ], ]; diff --git a/tests/Framework/PluginApi.php b/tests/Framework/PluginApi.php index 99bd712ec5c..0cd8dda8b52 100644 --- a/tests/Framework/PluginApi.php +++ b/tests/Framework/PluginApi.php @@ -30,7 +30,7 @@ function test_hooks() $api = rcube_plugin_api::get_instance(); $var = 0; - $hook_handler = function($args) use (&$var) { $var++; }; + $hook_handler = function ($args) use (&$var) { $var++; }; $api->register_hook('test', $hook_handler); diff --git a/tests/Framework/Rcube.php b/tests/Framework/Rcube.php index 66cfcc958f0..5b3f974be21 100644 --- a/tests/Framework/Rcube.php +++ b/tests/Framework/Rcube.php @@ -7,7 +7,6 @@ */ class Framework_Rcube extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ResultIndex.php b/tests/Framework/ResultIndex.php index 0807a53e2d9..c1dd147f8cf 100644 --- a/tests/Framework/ResultIndex.php +++ b/tests/Framework/ResultIndex.php @@ -7,7 +7,6 @@ */ class Framework_ResultIndex extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ResultMultifolder.php b/tests/Framework/ResultMultifolder.php index b7045d590b3..1deca4bb5b7 100644 --- a/tests/Framework/ResultMultifolder.php +++ b/tests/Framework/ResultMultifolder.php @@ -7,7 +7,6 @@ */ class Framework_ResultMultifolder extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ResultSet.php b/tests/Framework/ResultSet.php index 886c017745f..27c05acc742 100644 --- a/tests/Framework/ResultSet.php +++ b/tests/Framework/ResultSet.php @@ -7,7 +7,6 @@ */ class Framework_ResultSet extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/ResultThread.php b/tests/Framework/ResultThread.php index f290545b3ee..fd17c174c75 100644 --- a/tests/Framework/ResultThread.php +++ b/tests/Framework/ResultThread.php @@ -7,7 +7,6 @@ */ class Framework_ResultThread extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/SpellcheckerAtd.php b/tests/Framework/SpellcheckerAtd.php index eb8f1233803..923ae78cca6 100644 --- a/tests/Framework/SpellcheckerAtd.php +++ b/tests/Framework/SpellcheckerAtd.php @@ -7,7 +7,6 @@ */ class Framework_SpellcheckerAtd extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/SpellcheckerGoogie.php b/tests/Framework/SpellcheckerGoogie.php index 8c1f1734c61..d2390ca795d 100644 --- a/tests/Framework/SpellcheckerGoogie.php +++ b/tests/Framework/SpellcheckerGoogie.php @@ -7,7 +7,6 @@ */ class Framework_SpellcheckerGoogie extends PHPUnit\Framework\TestCase { - /** * Class constructor */ diff --git a/tests/Framework/SpellcheckerPspell.php b/tests/Framework/SpellcheckerPspell.php index e10e160b68d..e8d986bf565 100644 --- a/tests/Framework/SpellcheckerPspell.php +++ b/tests/Framework/SpellcheckerPspell.php @@ -99,7 +99,7 @@ function test_get_suggestions() $object = new rcube_spellchecker(); - $expected = ['ON','on','Ont','only','onya','NY','onyx','Ono','any','one']; + $expected = ['ON', 'on', 'Ont', 'only', 'onya', 'NY', 'onyx', 'Ono', 'any', 'one']; $result = $object->get_suggestions('ony'); sort($expected); diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index ba30e595b42..a41b4b25c5e 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -421,7 +421,7 @@ function test_explode_quoted_string() { $data = [ '"a,b"' => ['"a,b"'], - '"a,b","c,d"' => ['"a,b"','"c,d"'], + '"a,b","c,d"' => ['"a,b"', '"c,d"'], '"a,\\"b",d' => ['"a,\\"b"', 'd'], 'a,' => ['a', ''], '"a,' => ['"a,'], @@ -611,7 +611,10 @@ function test_anytodatetime_timezone() foreach ($test as $datetime => $ts) { $result = rcube_utils::anytodatetime($datetime, $tz); - if ($result) $result->setTimezone($tz); // move to target timezone for comparison + if ($result) { + // move to target timezone for comparison + $result->setTimezone($tz); + } $this->assertSame($ts, $result ? $result->format('Y-m-d H:i') : false, "Error parsing date: $datetime"); } } @@ -642,8 +645,8 @@ function test_tokenize_string() $test = [ '' => [], 'abc d' => ['abc'], - 'abc de' => ['abc','de'], - 'äàé;êöü-xyz' => ['äàé','êöü','xyz'], + 'abc de' => ['abc', 'de'], + 'äàé;êöü-xyz' => ['äàé', 'êöü', 'xyz'], '日期格式' => ['日期格式'], ]; @@ -861,13 +864,14 @@ function test_parse_host_uri($args, $result) /** * Test-Cases for test_remove_subject_prefix() */ - function data_remove_subject_prefix() { + function data_remove_subject_prefix() + { return [ - ['both', 'Fwd: Re: Test subject both', 'Test subject both'], - ['both', 'Re: Fwd: Test subject both', 'Test subject both'], - ['reply', 'Fwd: Re: Test subject reply', 'Fwd: Re: Test subject reply'], - ['reply', 'Re: Fwd: Test subject reply', 'Fwd: Test subject reply'], - ['reply', 'Re: Fwd: Test subject reply (was: other test)', 'Fwd: Test subject reply'], + ['both', 'Fwd: Re: Test subject both', 'Test subject both'], + ['both', 'Re: Fwd: Test subject both', 'Test subject both'], + ['reply', 'Fwd: Re: Test subject reply', 'Fwd: Re: Test subject reply'], + ['reply', 'Re: Fwd: Test subject reply', 'Fwd: Test subject reply'], + ['reply', 'Re: Fwd: Test subject reply (was: other test)', 'Fwd: Test subject reply'], ['forward', 'Re: Fwd: Test subject forward', 'Re: Fwd: Test subject forward'], ['forward', 'Fwd: Re: Test subject forward', 'Re: Test subject forward'], ['forward', 'Fw: Re: Test subject forward', 'Re: Test subject forward'], @@ -876,10 +880,11 @@ function data_remove_subject_prefix() { /** * Test remove_subject_prefix - * + * * @dataProvider data_remove_subject_prefix */ - function test_remove_subject_prefix($mode, $subject, $result) { + function test_remove_subject_prefix($mode, $subject, $result) + { $this->assertEquals(rcube_utils::remove_subject_prefix($subject, $mode), $result); } diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php index 9917c7eda43..0784b527b91 100644 --- a/tests/Framework/VCard.php +++ b/tests/Framework/VCard.php @@ -7,7 +7,6 @@ */ class Framework_VCard extends PHPUnit\Framework\TestCase { - function _srcpath($fn) { return realpath(__DIR__ . '/../src/' . $fn); diff --git a/tests/OutputHtmlMock.php b/tests/OutputHtmlMock.php index 53bdc2526e2..83681299e93 100644 --- a/tests/OutputHtmlMock.php +++ b/tests/OutputHtmlMock.php @@ -1,6 +1,6 @@ '1:2,56', ]; $result = rcmail_action::get_uids(null, null, $is_multifolder); - $this->assertSame(['INBOX' => ['1:2','56']], $result); + $this->assertSame(['INBOX' => ['1:2', '56']], $result); $this->assertFalse($is_multifolder); } diff --git a/tests/Rcmail/AttachmentHandler.php b/tests/Rcmail/AttachmentHandler.php index 089ad9348b3..9977a5fa783 100644 --- a/tests/Rcmail/AttachmentHandler.php +++ b/tests/Rcmail/AttachmentHandler.php @@ -7,7 +7,6 @@ */ class Rcmail_RcmailAttachmentHandler extends ActionTestCase { - /** * Test rcmail_action::svg_filter() */ diff --git a/tests/Rcmail/Rcmail.php b/tests/Rcmail/Rcmail.php index e6b1dc861d6..fb80e5c7a39 100644 --- a/tests/Rcmail/Rcmail.php +++ b/tests/Rcmail/Rcmail.php @@ -285,7 +285,7 @@ function test_format_date() && version_compare(INTL_ICU_VERSION, '72.1', '>=')) { // Starting with ICU 72.1, a NARROW NO-BREAK SPACE (NNBSP) // is used instead of an ASCII space before the meridian. - $date_x = '6/1/20, 12:20 PM'; + $date_x = "6/1/20, 12:20\u{202f}PM"; } $this->assertSame($date_x, $rcmail->format_date($date, 'x')); $this->assertSame('1591014030', $rcmail->format_date($date, 'U')); diff --git a/tests/StderrMock.php b/tests/StderrMock.php index ac8df52f434..15b647b7e25 100644 --- a/tests/StderrMock.php +++ b/tests/StderrMock.php @@ -1,6 +1,6 @@ config->set('devel_mode', false); @@ -47,12 +49,12 @@ die("Fatal error: ini_set/set_include_path does not work."); } -require_once(TESTS_DIR . 'ActionTestCase.php'); -require_once(TESTS_DIR . 'ExitException.php'); -require_once(TESTS_DIR . 'OutputHtmlMock.php'); -require_once(TESTS_DIR . 'OutputJsonMock.php'); -require_once(TESTS_DIR . 'StderrMock.php'); -require_once(TESTS_DIR . 'StorageMock.php'); +require_once TESTS_DIR . 'ActionTestCase.php'; +require_once TESTS_DIR . 'ExitException.php'; +require_once TESTS_DIR . 'OutputHtmlMock.php'; +require_once TESTS_DIR . 'OutputJsonMock.php'; +require_once TESTS_DIR . 'StderrMock.php'; +require_once TESTS_DIR . 'StorageMock.php'; // Initialize database and environment ActionTestCase::init();