1 <?php
3 define("SIEVE_INDENT_TAB"," ");
5 /* This class is inherited from the original 'Parser'
6 * class written by Heiko Hund
7 */
8 class My_Parser extends Parser
9 {
11 function execute()
12 {
13 /* Create dump of current sieve script */
14 if(isset($_POST['Save_Copy'])){
16 /* force download dialog */
17 header("Content-type: application/tiff\n");
18 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
19 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
20 header('Content-Disposition: filename="dump.script"');
21 } else {
22 header('Content-Disposition: attachment; filename="dump.script"');
23 }
24 header("Content-transfer-encoding: binary\n");
25 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
26 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
27 header("Cache-Control: no-cache");
28 header("Pragma: no-cache");
29 header("Cache-Control: post-check=0, pre-check=0");
30 echo $this->get_sieve_script();
31 exit();
32 }
34 $ret = $this->dumpParseTree();
35 return($ret);
36 }
39 /* Check if there are errors, collect them and return them */
40 function check()
41 {
42 return($this->tree_->check());
43 }
46 /* Initiate parser, but use some other
47 * classes, that are rewritten.
48 */
49 function parse($script)
50 {
51 $this->status_text = "incomplete";
52 $this->script_ = $script;
53 $this->tree_ = new My_Tree(@Scanner::scriptStart());
54 $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
55 $this->scanner_ = new Scanner($this->script_);
56 $this->scanner_->setCommentFunc(array($this, 'comment_'));
58 if ($this->commands_($this->tree_->getRoot()) &&
59 $this->scanner_->nextTokenIs('script-end'))
60 {
61 return $this->success_('success');
62 }
64 return $this->status_;
65 }
68 function get_sieve_script()
69 {
70 return($this->tree_->get_sieve_script());
71 }
74 function save_object()
75 {
76 $this->tree_->save_object();
77 }
80 /* Should be obsolete in the end. */
81 function dumpToken_(&$token)
82 {
83 if (is_array($token))
84 {
85 $str = "<" . $token['text'] . "> ";
86 foreach ($token as $k => $v)
87 {
88 $str .= " $k:$v";
89 }
90 return $str;
91 }
92 return strval($token);
93 }
96 function dumpParseTree()
97 {
98 return $this->tree_->execute();
99 }
100 }
101 ?>