diff options
author | Hugues Hiegel <root@paranoid> | 2014-08-05 16:46:22 +0200 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2014-08-05 16:46:22 +0200 |
commit | 59478e06c25303a790a0840ab2ac30662c4ef781 (patch) | |
tree | 8d5e964a8f94adaef41efebb0597629f11495c42 /plugins/sieverules/importFilters/ingo.php | |
parent | 7c494b677f9e470ee0d32e62cfa8dc709f39e748 (diff) |
c'est la merde..working
Diffstat (limited to 'plugins/sieverules/importFilters/ingo.php')
-rw-r--r-- | plugins/sieverules/importFilters/ingo.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/plugins/sieverules/importFilters/ingo.php b/plugins/sieverules/importFilters/ingo.php new file mode 100644 index 000000000..8d85ce6e1 --- /dev/null +++ b/plugins/sieverules/importFilters/ingo.php @@ -0,0 +1,52 @@ +<?php + +/** + * SieveRules import filter for INGO + * + * The class should be named 'srimport_[filename]' + * Each import filter must have: + * An attribute called name + * A pubic function called detector + * A pubic function called importer + * The importer function can return either a string to be parsed by the SieveRules parser + * or an array, similar to the one created by the SieveRules parser + */ +class srimport_ingo +{ + public $name = 'Horde (INGO)'; + + public function detector($script) + { + return preg_match('/# [a-z0-9\ ]+/i', $script) ? True : False; + } + + public function importer($script) + { + $i = 0; + $name = array(); + // tokenize rules + if ($tokens = preg_split('/(# .+)\r?\n/i', $script, -1, PREG_SPLIT_DELIM_CAPTURE)) { + // unset first token, its the ingo header + $tokens[1] = ""; + + foreach($tokens as $token) { + if (preg_match('/^# (.+)/i', $token, $matches)) { + $name[$i] = $matches[1]; + $content .= "# rule:[" . $name[$i] . "]\n"; + } + elseif (isset($name[$i])) { + $token = str_replace(":comparator \"i;ascii-casemap\" ", "", $token); + $content .= $token . "\n"; + $i++; + } + elseif (preg_match('/^\r?\n?require/i', $token)) { + $content .= $token . "\n"; + } + } + } + + return $content; + } +} + +?>
\ No newline at end of file |