/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { $code = 'header ' . ':comparator "' . $this->_vars['comparator'] . '" ' . $this->_vars['match-type'] . ' '; $headers = preg_split('(\\r\\n|\\n|\\r)', $this->_vars['headers']); $headers = array_filter($headers); if (count($headers) > 1) { $code .= "["; $headerstr = ''; foreach ($headers as $header) { $headerstr .= empty($headerstr) ? '"' : ', "'; $headerstr .= Ingo_Script_Sieve::escapeString($header, $this->_vars['match-type'] == ':regex') . '"'; } $code .= $headerstr . "] "; } elseif (count($headers) == 1) { $code .= '"' . $headers[0] . '" '; } else { return _("No headers specified"); } $strings = preg_split('(\\r\\n|\\n|\\r)', $this->_vars['strings']); $strings = array_filter($strings); if (count($strings) > 1) { $code .= "["; $stringlist = ''; foreach ($strings as $str) { $stringlist .= empty($stringlist) ? '"' : ', "'; $stringlist .= Ingo_Script_Sieve::escapeString($str, $this->_vars['match-type'] == ':regex') . '"'; } $code .= $stringlist . "] "; } elseif (count($strings) == 1) { $code .= '"' . Ingo_Script_Sieve::escapeString(reset($strings), $this->_vars['match-type'] == ':regex') . '" '; } else { return _("No strings specified"); } return $code; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { $code = 'header :value "' . $this->_vars['comparison'] . '" ' . ':comparator "i;ascii-numeric" '; $headers = preg_split('(\\r\\n|\\n|\\r)', $this->_vars['headers']); $header_count = count($headers); if ($header_count > 1) { $code .= "["; $headerstr = ''; foreach ($headers as $val) { $headerstr .= (empty($headerstr) ? '"' : ', "') . Ingo_Script_Sieve::escapeString($val) . '"'; } $code .= $headerstr . '] '; $headerstr = '[' . $headerstr . ']'; } elseif ($header_count == 1) { $code .= '"' . Ingo_Script_Sieve::escapeString($headers[0]) . '" '; $headerstr = Ingo_Script_Sieve::escapeString($headers[0]); } $code .= '["' . $this->_vars['value'] . '"]'; // Add workarounds for negative numbers - works only if the comparison // value is positive. Sieve doesn't support comparisons of negative // numbers at all so this is the best we can do. switch ($this->_vars['comparison']) { case 'gt': case 'ge': case 'eq': // Greater than, greater or equal, equal: number must be // non-negative. return 'allof ( not header :comparator "i;ascii-casemap" :contains "' . $headerstr . '" "-", ' . $code . ' )'; case 'lt': case 'le': case 'ne': // Less than, less or equal, nonequal: also match negative numbers return 'anyof ( header :comparator "i;ascii-casemap" :contains "' . $headerstr . '" "-", ' . $code . ' )'; } }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { $addr = Ingo_Script_Sieve::escapeString($this->_vars['address']); if ($this->_vars['notify']) { return 'notify :method "mailto" :options "' . $addr . '" :message "' . _("You have received a new message") . "\n" . _("From:") . " \$from\$ \n" . _("Subject:") . " \$subject\$ \n" . _("Rule:") . ' ' . $this->_vars['name'] . '";'; } // RFC 5436 defines mailto: behavior. Use the default // server-defined notification message. return 'notify "mailto:' . $addr . '";'; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @param string $mode The sieve flag command to use. Either: * - addflag * - removeflag * * @return string A Sieve script snippet. */ protected function _generate($mode) { if (empty($this->_vars['flags'])) { return ''; } $flist = array(); foreach ($this->_vars['flags'] as $flag) { $flist[] = '"' . Ingo_Script_Sieve::escapeString($flag) . '"'; } /* Use string list since it is supported by both imap4flags and * imapflags. */ return $mode . ' [' . implode(', ', $flist) . '];'; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { $code = 'exists '; $headers = preg_split('(\\r\\n|\\n|\\r)', $this->_vars['headers']); if (count($headers) > 1) { $code .= "["; $headerstr = ''; foreach ($headers as $header) { $headerstr .= (empty($headerstr) ? '"' : ', "') . Ingo_Script_Sieve::escapeString($header) . '"'; } $code .= $headerstr . "] "; } elseif (count($headers) == 1) { $code .= '"' . Ingo_Script_Sieve::escapeString($headers[0]) . '" '; } else { return "**error** No Headers Specified"; } return $code; }
/** */ public function generate($depth = 0) { return str_repeat(' ', $depth * 4) . 'redirect ' . '"' . Ingo_Script_Sieve::escapeString($this->_vars['address']) . '";'; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { return 'fileinto "' . Ingo_Script_Sieve::escapeString($this->_vars['folder']) . '";'; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { return 'reject "' . Ingo_Script_Sieve::escapeString($this->_vars['reason']) . '";'; }
/** */ protected function _vacationCode() { $code = 'vacation :days ' . $this->_vars['days'] . ' '; $addresses = $this->_vars['addresses']; $stringlist = ''; if (count($addresses) > 1) { foreach ($addresses as $address) { $address = trim($address); if (!empty($address)) { $stringlist .= empty($stringlist) ? '"' : ', "'; $stringlist .= Ingo_Script_Sieve::escapeString($address) . '"'; } } $stringlist = "[" . $stringlist . "] "; } elseif (count($addresses) == 1) { $stringlist = '"' . Ingo_Script_Sieve::escapeString($addresses[0]) . '" '; } if (!empty($stringlist)) { $code .= ':addresses ' . $stringlist; } if (!empty($this->_vars['subject'])) { $code .= ':subject "' . Horde_Mime::encode(Ingo_Script_Sieve::escapeString($this->_vars['subject'])) . '" '; } return $code . '"' . Ingo_Script_Sieve::escapeString(Ingo_Script_Util::vacationReason($this->_vars['reason'], $this->_vars['start'], $this->_vars['end'])) . '";'; }
/** * Returns a script snippet representing this rule and any sub-rules. * * @return string A Sieve script snippet. */ public function generate() { $code = 'address ' . $this->_vars['address-part'] . ' ' . ':comparator "' . $this->_vars['comparator'] . '" ' . $this->_vars['match-type'] . ' '; $headers = preg_split('(\\r\\n|\\n|\\r|,)', $this->_vars['headers']); $headers = array_filter($headers); if (count($headers) > 1) { $code .= "["; $headerstr = ''; foreach ($headers as $header) { $header = trim($header); if (!empty($header)) { $headerstr .= empty($headerstr) ? '"' : ', "'; $headerstr .= Ingo_Script_Sieve::escapeString($header, $this->_vars['match-type'] == ':regex') . '"'; } } $code .= $headerstr . "] "; } elseif (count($headers) == 1) { $code .= '"' . Ingo_Script_Sieve::escapeString($headers[0], $this->_vars['match-type'] == ':regex') . '" '; } else { return "No Headers Specified"; } $addresses = preg_split('(\\r\\n|\\n|\\r)', $this->_vars['addresses']); $addresses = array_filter($addresses); if (count($addresses) > 1) { $code .= "["; $addressstr = ''; foreach ($addresses as $addr) { $addr = trim($addr); if (!empty($addr)) { $addressstr .= empty($addressstr) ? '"' : ', "'; $addressstr .= Ingo_Script_Sieve::escapeString($addr, $this->_vars['match-type'] == ':regex') . '"'; } } $code .= $addressstr . "] "; } elseif (count($addresses) == 1) { $code .= '"' . Ingo_Script_Sieve::escapeString($addresses[0], $this->_vars['match-type'] == ':regex') . '" '; } else { return "No Addresses Specified"; } return $code; }
function _writeSieveScript() { $this->_setupStorage(); $script = new Ingo_Script_Sieve(array('date_format' => '%x', 'time_format' => '%R', 'spam_compare' => 'string', 'spam_header' => 'X-Spam-Level', 'spam_char' => '*')); $this->sieve = tempnam('/tmp', 'sieve'); $fh = fopen($this->sieve, 'w'); $this->sieve_text = $script->generate(); fwrite($fh, $this->sieve_text); fclose($fh); }