Browse Source

Fix handling of spellcheck connection errors (#8172)

pull/8503/head
Aleksander Machniak 4 years ago
parent
commit
6718c0d6ba
  1. 1
      CHANGELOG.md
  2. 36
      program/actions/mail/send.php
  3. 4
      program/actions/utils/spell.php
  4. 7
      program/actions/utils/spell_html.php
  5. 24
      program/lib/Roundcube/spellchecker/googie.php

1
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

36
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');
}
}

4
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

7
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;
}

24
program/lib/Roundcube/spellchecker/googie.php

@ -80,17 +80,23 @@ class rcube_spellchecker_googie extends rcube_spellchecker_engine
.'<text>' . htmlspecialchars($text, ENT_QUOTES, RCUBE_CHARSET) . '</text>'
.'</spellrequest>';
$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();

Loading…
Cancel
Save