Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

managesieve turning a long regex into multi-line text literal #6143

Closed
ss-17 opened this issue Jan 22, 2018 · 5 comments
Closed

managesieve turning a long regex into multi-line text literal #6143

ss-17 opened this issue Jan 22, 2018 · 5 comments

Comments

@ss-17
Copy link

ss-17 commented Jan 22, 2018

Hi.

The file plugins/managesieve/lib/Roundcube/rcube_sieve_script.php has this section:

// multi-line string
if (preg_match('/[\r\n\0]/', $str) || strlen($str) > 1024) {
    return sprintf("text:\n%s\n.\n", self::escape_multiline_string($str));
}
// quoted-string
else {
    return '"' . addcslashes($str, '\\"') . '"';
}

which is converting my long regex to:

:regex "from" text:
"my long regex"
.

which should actually be saved as:

:regex "from" "my long regex"

in order to get evaluated correctly. Why the 1024 limit?

@philipwhiuk
Copy link

Probably an interpretation of:

  quoted                = DQUOTE *1024QUOTED-CHAR DQUOTE
                            ;; limited to 1024 octets between the <">s

in https://tools.ietf.org/html/draft-martin-managesieve-12

@ss-17
Copy link
Author

ss-17 commented Jan 22, 2018

Ahh ok. But does that mean we cannot have a regex longer that 1024 chars in sieve?

@alecpl
Copy link
Member

alecpl commented Jan 22, 2018

I don't remember. You might be right that it comes from managesieve rfc. That would mean the limit is irrelevant and should be removed.

@alecpl alecpl added this to the 1.3.5 milestone Jan 22, 2018
@ss-17
Copy link
Author

ss-17 commented Jan 22, 2018

As a quick workaround, I have replaced the line:

return $output;

in the script with:

if (preg_match_all('/:regex.*?(text:\r?\n(.+?)\r?\n\.\r?\n)\)?/is', $output, $a)) {
	array_walk($a[2], function(&$b) {$b='"'.addcslashes($b, '\\"').'"';});
	return str_replace($a[1], $a[2], $output);        	
}
else {
	return $output;
}

@alecpl
Copy link
Member

alecpl commented Jan 24, 2018

Fixed.

@alecpl alecpl closed this as completed Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants