diff --git a/CHANGELOG.md b/CHANGELOG.md index 656577de6..5cccab8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Fix bug where vertical scrollbar in new HTML message bounced back on scroll (#8046) - Fix displaying inline images with incorrectly declared content-type (#8158) - Fix so addr-spec with missing closing angle bracket can be parsed (#8164) +- Fix handling of spellcheck connection errors (#8172) ## Release 1.5-rc diff --git a/program/actions/mail/send.php b/program/actions/mail/send.php index 31f52b838..6c5027c28 100644 --- a/program/actions/mail/send.php +++ b/program/actions/mail/send.php @@ -156,20 +156,30 @@ class rcmail_action_mail_send extends rcmail_action $spellchecker = new rcube_spellchecker($language); $spell_result = $spellchecker->check($message_body, $isHtml); - $COMPOSE['spell_checked'] = true; - - if (!$spell_result) { - if ($isHtml) { - $result['words'] = $spellchecker->get(); - $result['dictionary'] = (bool) $rcmail->config->get('spellcheck_dictionary'); - } - else { - $result = $spellchecker->get_xml(); + if ($error = $spellchecker->error()) { + rcube::raise_error([ + 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Spellcheck error: " . $error + ], + true, false + ); + } + else { + $COMPOSE['spell_checked'] = true; + + if (!$spell_result) { + if ($isHtml) { + $result['words'] = $spellchecker->get(); + $result['dictionary'] = (bool) $rcmail->config->get('spellcheck_dictionary'); + } + else { + $result = $spellchecker->get_xml(); + } + + $rcmail->output->show_message('mispellingsfound', 'error'); + $rcmail->output->command('spellcheck_resume', $result); + $rcmail->output->send('iframe'); } - - $rcmail->output->show_message('mispellingsfound', 'error'); - $rcmail->output->command('spellcheck_resume', $result); - $rcmail->output->send('iframe'); } } diff --git a/program/actions/utils/spell.php b/program/actions/utils/spell.php index 47e20b02f..4d5809e3c 100644 --- a/program/actions/utils/spell.php +++ b/program/actions/utils/spell.php @@ -55,12 +55,12 @@ class rcmail_action_utils_spell extends rcmail_action $result = $spellchecker->get_xml(); } - if ($err = $spellchecker->error()) { + if ($error = $spellchecker->error()) { rcube::raise_error([ 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Spell check engine error: " . trim($err) + 'message' => "Spellcheck error: " . $error ], true, false diff --git a/program/actions/utils/spell_html.php b/program/actions/utils/spell_html.php index 7044228bc..18663023d 100644 --- a/program/actions/utils/spell_html.php +++ b/program/actions/utils/spell_html.php @@ -52,23 +52,24 @@ class rcmail_action_utils_spell_html extends rcmail_action } } + header("Content-Type: application/json; charset=" . RCUBE_CHARSET); + if ($error = $spellchecker->error()) { rcube::raise_error([ 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, - 'message' => sprintf("Spell check engine error: " . $error) + 'message' => "Spellcheck error: " . $error ], true, false ); - echo json_encode(['error' => $error]); + echo json_encode(['error' => $rcmail->gettext('internalerror')]); exit; } // send output - header("Content-Type: application/json; charset=".RCUBE_CHARSET); echo json_encode($result); exit; } diff --git a/program/lib/Roundcube/spellchecker/googie.php b/program/lib/Roundcube/spellchecker/googie.php index 53e957591..8bab2b633 100644 --- a/program/lib/Roundcube/spellchecker/googie.php +++ b/program/lib/Roundcube/spellchecker/googie.php @@ -80,17 +80,23 @@ class rcube_spellchecker_googie extends rcube_spellchecker_engine .'' . htmlspecialchars($text, ENT_QUOTES, RCUBE_CHARSET) . '' .''; - $response = $client->post($url, [ - 'headers' => [ - 'User-Agent' => "Roundcube Webmail/" . RCUBE_VERSION . " (Googiespell Wrapper)", - 'Content-type' => 'text/xml' - ], - 'body' => $gtext - ] - ); + try { + $response = $client->post($url, [ + 'connect_timeout' => 5, // seconds + 'headers' => [ + 'User-Agent' => "Roundcube Webmail/" . RCUBE_VERSION . " (Googiespell Wrapper)", + 'Content-type' => 'text/xml' + ], + 'body' => $gtext + ] + ); + } + catch (Exception $e) { + // Do nothing, the error set below should be logged by the caller + } if (empty($response)) { - $this->error = "Empty result from spelling engine"; + $this->error = $e ? $e->getMessage() : "Spelling engine failure"; } else if ($response->getStatusCode() != 200) { $this->error = 'HTTP ' . $response->getReasonPhrase();