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 {
15 /* Add Element requested */
16 if(isset($_POST['Add_Element'])){
17 $this->tree_->Add_Element();
18 echo "Move this into Management";
19 }
21 /* Create dump of current sieve script */
22 if(isset($_POST['Save_Copy'])){
23 echo "Move this into Management";
25 /* force download dialog */
26 header("Content-type: application/tiff\n");
27 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
28 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
29 header('Content-Disposition: filename="dump.txt"');
30 } else {
31 header('Content-Disposition: attachment; filename="dump.txt"');
32 }
33 header("Content-transfer-encoding: binary\n");
34 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
35 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
36 header("Cache-Control: no-cache");
37 header("Pragma: no-cache");
38 header("Cache-Control: post-check=0, pre-check=0");
39 echo $this->get_sieve_script();
40 exit();
41 }
43 $ret = $this->dumpParseTree();
44 return($ret);
45 }
48 /* Initiate parser, but use some other
49 * classes, that are rewritten.
50 */
51 function parse($script)
52 {
53 $this->status_text = "incomplete";
54 $this->script_ = $script;
55 $this->tree_ = new My_Tree(@Scanner::scriptStart());
56 $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
57 $this->scanner_ = new Scanner($this->script_);
58 $this->scanner_->setCommentFunc(array($this, 'comment_'));
60 if ($this->commands_($this->tree_->getRoot()) &&
61 $this->scanner_->nextTokenIs('script-end'))
62 {
63 return $this->success_('success');
64 }
66 return $this->status_;
67 }
70 function get_sieve_script()
71 {
72 return($this->tree_->get_sieve_script());
73 }
76 function save_object()
77 {
78 $this->tree_->save_object();
79 }
82 /* Should be obsolete in the end. */
83 function dumpToken_(&$token)
84 {
85 if (is_array($token))
86 {
87 $str = "<" . $token['text'] . "> ";
88 foreach ($token as $k => $v)
89 {
90 $str .= " $k:$v";
91 }
92 return $str;
93 }
94 return strval($token);
95 }
96 }
97 ?>