function proc($params)
 {
     require_once "MailGrabber.php";
     print "<pre>";
     if (str::isempty($params["id"])) {
         die("<b>Ошибка: Фильтр не выбран</b>\n");
     }
     set_time_limit(0);
     $json = new Services_JSON();
     $mailgrabber = new MailGrabber();
     $mailgrabber->run($json->decode(file::load("data/config.ini")), true, $params["id"]);
 }
 function parse($msg, $rule)
 {
     $items = array();
     if (!preg_match("{\\[text(=[^]]+)*\\]\\s*\\[list(=[^]]+)*\\](.+?)\\[list/\\]}si", $rule, $m)) {
         print "Shit rule\n";
         return $items;
     }
     $text = isset($m[1]) ? trim(substr($m[1], 1)) : "";
     list($min, $max) = isset($m[2]) ? explode("..", trim(substr($m[2], 1))) : array(0, 0);
     if (!preg_match_all($f = "{\\[(.+?)(=([^]]+))*\\]}si", $sfields = $m[3], $fields)) {
         print "Fields is empty\n";
         return $items;
     }
     //print $sfields . "\n";
     //print_r(array($rule, $msg));
     //$pattern = preg_replace("{FIELD_TAG}s", "(.+?)",
     //	"{" . preg_replace("{\s+}si", "\s+", preg_quote(preg_replace($f, "FIELD_TAG", $m[2]))) . "\n}si");
     $pattern = preg_replace("{\r\n{1}}", "\n", $pattern);
     $pattern = preg_replace("{FIELD_TAG}s", "(.+?)", "{" . preg_quote(preg_replace($f, "FIELD_TAG", $sfields)) . "}si");
     //print $pattern . "\n";
     $content = $this->cutContent($msg, $text);
     $content = preg_replace("{\r\n{1}}", "\n", $content);
     $content = preg_replace("{[ ]+}si", " ", $content);
     //print $content;
     preg_match_all($pattern, $content, $res, PREG_SET_ORDER);
     foreach ($res as $r) {
         $match = true;
         $a = $r;
         array_shift($a);
         // Check contains values in fields
         foreach ($a as $i => $f) {
             if (!str::isempty($sf = trim($fields[3][$i])) && strpos(strtolower($f), strtolower($sf)) === false) {
                 $match = false;
                 break;
             }
         }
         if (!$match) {
             continue;
         }
         $a = array_combine($fields[1], $a);
         // Process items
         if (isset($a["thumb"])) {
             $a["thumb"] = trim(preg_replace("{\\s+}si", "", $a["thumb"]));
         }
         if (isset($a["url"])) {
             $a["url"] = trim(preg_replace("{\\s+}si", "", $a["url"]));
             $p = strpos($a["url"], "http://");
             if ($p === false || $p > 0) {
                 unset($a["url"]);
             }
         }
         if (sizeof($a) > 0) {
             $items[] = $a;
         }
     }
     if ($min == "") {
         $min = 0;
     }
     if ($max == 0 || $max == "") {
         $max = sizeof($items);
     }
     return array_slice($items, $min, $max - $min + 1);
 }