protected function parse_conditions($input)
    {
        $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE);
        if ($matches && count($matches) == 4) {
            if (preg_match('/^(else|endif)$/i', $matches[1])) {
                return $matches[0] . $this->parse_conditions($matches[3]);
            }

            $attrib = html::parse_attrib_string($matches[2]);

            if (isset($attrib['condition'])) {
                $condmet    = $this->check_condition($attrib['condition']);
                $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE);

                if ($condmet) {
                    $result = $submatches[0];
                    if ($submatches[1] != 'endif') {
                        $result .= preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1);
                    }
                    else {
                        $result .= $submatches[3];
                    }
                }
                else {
                    $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3];
                }

                return $matches[0] . $this->parse_conditions($result);
            }

            rcube::raise_error(array(
                    'code' => 500, 'line' => __LINE__, 'file' => __FILE__,
                    'message' => "Unable to parse conditional tag " . $matches[2]
                ), true, false);
        }

        return $input;
    }