diff -urN plugins.orig/managesieve/config.inc.php.dist plugins/managesieve/config.inc.php.dist --- plugins.orig/managesieve/config.inc.php.dist 2013-03-27 22:51:27.000000000 +0200 +++ plugins/managesieve/config.inc.php.dist 2013-07-27 13:53:43.000000000 +0300 @@ -34,6 +34,12 @@ // The name of the script which will be used when there's no user script $rcmail_config['managesieve_script_name'] = 'managesieve'; +// The sieve script header (comments) +//$rcmail_config['managesieve_script_prefix'] = '# roundcube sieve script'; + +// The sieve script top commands +//$rcmail_config['managesieve_script_top_commands'] = 'require ["include"]; include :global "global-spam";'."\n"; + // Sieve RFC says that we should use UTF-8 endcoding for mailbox names, // but some implementations does not covert UTF-8 to modified UTF-7. // Defaults to UTF7-IMAP diff -urN plugins.orig/managesieve/lib/rcube_sieve_script.php plugins/managesieve/lib/rcube_sieve_script.php --- plugins.orig/managesieve/lib/rcube_sieve_script.php 2013-03-27 22:51:27.000000000 +0200 +++ plugins/managesieve/lib/rcube_sieve_script.php 2013-07-27 15:25:22.000000000 +0300 @@ -29,6 +29,7 @@ private $vars = array(); // "global" variables private $prefix = ''; // script header (comments) + private $top_commands = ''; // script top commands private $supported = array( // Sieve extensions supported by class 'fileinto', // RFC5228 'envelope', // RFC5228 @@ -173,6 +174,16 @@ } /** + * Sets script top commands + * + * @param string $text top commands + */ + public function set_top_commands($text) + { + $this->top_commands = $text; + } + + /** * Returns script as text */ public function as_text() @@ -438,6 +449,17 @@ } } + if (!empty($this->top_commands)) { + if (substr($output, 0, strlen($this->top_commands)) != $this->top_commands) { + $top_commands_without_require = trim(preg_replace('/^(\s*require.+;\s*\r?\n?\s*)+/', '', $this->top_commands)); + if (substr($output, 0, strlen($top_commands_without_require)) != $top_commands_without_require) { + $output = $this->top_commands . $output; + } else { + $output = preg_replace('/^(\s*require.+;\s*\r?\n?\s*)+.*/', '$1', $this->top_commands) . $output; + } + } + } + // requires if (!empty($exts)) $output = 'require ["' . implode('","', array_unique($exts)) . "\"];\n" . $output; diff -urN plugins.orig/managesieve/managesieve.php plugins/managesieve/managesieve.php --- plugins.orig/managesieve/managesieve.php 2013-03-27 22:51:28.000000000 +0200 +++ plugins/managesieve/managesieve.php 2013-07-27 13:43:46.000000000 +0300 @@ -273,6 +273,8 @@ if ($script_name) { $this->sieve->load($script_name); + $this->sieve->script->set_prefix($this->rc->config->get('managesieve_script_prefix')); + $this->sieve->script->set_top_commands($this->rc->config->get('managesieve_script_top_commands')); } $error = $this->sieve->error();