summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2013-05-03 12:09:57 +0200
committerThomas Bruederli <thomas@roundcube.net>2013-05-03 12:09:57 +0200
commitb15cc7d6f4c77fb941c74670eb58fb07bd9c7d9c (patch)
tree8ff58cb843fd4c00a8e58603a80122e25f018930
parent517dae3e74e39aceabaf2c5da330849a21e82d81 (diff)
Check Google spell check service response for errors and report them accordingly
-rw-r--r--program/lib/Roundcube/rcube_spellchecker.php15
-rw-r--r--program/steps/utils/spell.inc7
2 files changed, 17 insertions, 5 deletions
diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php
index 816bcad2f..2b48fca92 100644
--- a/program/lib/Roundcube/rcube_spellchecker.php
+++ b/program/lib/Roundcube/rcube_spellchecker.php
@@ -314,11 +314,6 @@ class rcube_spellchecker
if (!$this->plink) {
if (!extension_loaded('pspell')) {
$this->error = "Pspell extension not available";
- rcube::raise_error(array(
- 'code' => 500, 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => $this->error), true, false);
-
return;
}
@@ -372,9 +367,19 @@ class rcube_spellchecker
fclose($fp);
}
+ // parse HTTP response
+ if (preg_match('!^HTTP/1.\d (\d+)(.+)!', $store, $m)) {
+ $http_status = $m[1];
+ if ($http_status != '200')
+ $this->error = 'HTTP ' . $m[1] . $m[2];
+ }
+
if (!$store) {
$this->error = "Empty result from spelling engine";
}
+ else if (preg_match('/<spellresult error="([^"]+)"/', $store, $m)) {
+ $this->error = "Error code $m[1] returned";
+ }
preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $store, $matches, PREG_SET_ORDER);
diff --git a/program/steps/utils/spell.inc b/program/steps/utils/spell.inc
index a0dd35d27..b59fe7998 100644
--- a/program/steps/utils/spell.inc
+++ b/program/steps/utils/spell.inc
@@ -42,6 +42,13 @@ else {
$result = $spellchecker->get_xml();
}
+if ($err = $spellchecker->error()) {
+ raise_error(array('code' => 500, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => sprintf("Spell check engine error: " . $err)),
+ true, false);
+}
+
// set response length
header("Content-Length: " . strlen($result));