diff --git a/plugins/managesieve/codemirror/initeditor.js b/plugins/managesieve/codemirror/initeditor.js index 54a4ac65c..315303f09 100644 --- a/plugins/managesieve/codemirror/initeditor.js +++ b/plugins/managesieve/codemirror/initeditor.js @@ -1,4 +1,14 @@ var cmeditor; + +function createErrorElem(msg) +{ + var marker = document.createElement("div"); + marker.style.color = "#822"; + marker.innerHTML = "●"; + marker.title = msg; + return marker; +} + if (window.rcmail) { rcmail.addEventListener('init', function(evt) { var textArea = document.getElementById('rawfiltersettxt'); @@ -6,17 +16,20 @@ if (window.rcmail) { cmeditor = CodeMirror.fromTextArea(textArea, { mode: 'sieve', lineNumbers: true, + gutters: ["CodeMirror-linenumbers", "errorGutter"], styleActiveLine: true }); - console.log("init done."); - - // fetching error line number from environment and setting the line background accordingly - var errLine = Number(rcmail.env.sieve_error_line); - if (errLine !== NaN && errLine > 0) { - console.log("Fehler in " + rcmail.env.sieve_error_line); - cmeditor.addLineClass(errLine - 1, 'background', 'line-error'); + // fetching errors from environment and setting the line background + // and a gutter element with the error message accordingly + var errors = rcmail.env.sieve_errors; + if (errors !== undefined) { + errors.forEach(function(err) { + var lineNo = Number(err.line) - 1; + cmeditor.addLineClass(lineNo, 'background', 'line-error'); + cmeditor.setGutterMarker(lineNo, 'errorGutter', createErrorElem(err.msg)); + }); } } }); -} \ No newline at end of file +} diff --git a/plugins/managesieve/codemirror/overrides.css b/plugins/managesieve/codemirror/overrides.css index 215abfcca..bca349307 100644 --- a/plugins/managesieve/codemirror/overrides.css +++ b/plugins/managesieve/codemirror/overrides.css @@ -5,3 +5,7 @@ .CodeMirror-linebackground.line-error { background-color: #f66; } + +.errorGutter { + width: 0.8em; +} \ No newline at end of file diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php index 43f93e6a9..b6ffe2b61 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php @@ -26,7 +26,7 @@ class rcube_sieve { private $sieve; // Net_Sieve object private $error = false; // error flag - private $errorLine = -1; // line number within sieve script which raised an error + private $errorLines = array(); // array of line numbers within sieve script which raised an error private $list = array(); // scripts list public $script; // rcube_sieve_script object @@ -162,13 +162,25 @@ class rcube_sieve $result = $this->sieve->installScript($name, $content); if (is_a($result, 'PEAR_Error')) { - $errorMsg = $result->getMessage(); - $matches = array(); - $res = preg_match('/line (\d+):/i', $errorMsg, $matches); - - if ($res === 1 && count($matches) > 1) { - $this->errorLine = $matches[1]; + $rawErrorMessage = $result->getMessage(); + $errMessages = preg_split("/$name:/", $rawErrorMessage); + + if (sizeof($errMessages) > 0) { + foreach ($errMessages as $singleError) { + $matches = array(); + $res = preg_match('/line (\d+):(.*)/i', $singleError, $matches); + + if ($res === 1 ) { + if (count($matches) > 2) { + $this->errorLines[] = array("line" => $matches[1], "msg" => $matches[2]); + } + else { + $this->errorLines[] = array("line" => $matches[1], "msg" => null); + } + } + } } + return $this->_set_error(self::ERROR_INSTALL); } @@ -178,9 +190,9 @@ class rcube_sieve /** * Returns the current error line within the saved sieve script */ - public function get_error_line() + public function get_error_lines() { - return $this->errorLine; + return $this->errorLines; } /** diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index f4af19967..df3e77fe8 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -505,9 +505,9 @@ class rcube_sieve_engine if ($result === false) { $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); - $errorLine = $this->sieve->get_error_line(); - if ($errorLine > 0) { - $this->rc->output->set_env("sieve_error_line", $errorLine); + $errorLines = $this->sieve->get_error_lines(); + if (sizeof($errorLines) > 0) { + $this->rc->output->set_env("sieve_errors", $errorLines); } } else {