Code

Replaced print_red with msg_dialog, for testing
[gosa.git] / include / sieve / class_sieve.inc
index bdbf7d6fdbea70af45a0fa4b34dc92128a00b9f4..c45d0f18e2da2878bac90b0441461aa487eaf8fa 100644 (file)
@@ -1,4 +1,4 @@
-<?
+<?php
 
 /*
  * $Id: class_sieve.inc,v 1.1 2005/02/21 09:33:01 cajus Exp $ 
@@ -104,34 +104,36 @@ class sieve
     $this->line=fgets($this->fp,1024);
     $this->token = split(" ", $this->line, 2);
 
-    if($this->token[0] == "NO"){
-        /* we need to try and extract the error code from here.  There are two possibilites: one, that it will take the form of:
-           NO ("yyyyy") "zzzzzzz" or, two, NO {yyyyy} "zzzzzzzzzzz" */
-        $this->x = 0;
-        list($this->ltoken, $this->mtoken, $this->rtoken) = split(" ", $this->line." ", 3);
-        if($this->mtoken[0] == "{"){
-            while($this->mtoken[$this->x] != "}" or $this->err_len < 1){
-                $this->err_len = substr($this->mtoken, 1, $this->x);
-                $this->x++;    
-            }
-            //print "<br>Trying to receive $this->err_len bytes for result<br>";
-            $this->line = fgets($this->fp,$this->err_len);
-            $this->error_raw[]=substr($this->line, 0, strlen($this->line) -2);    //we want to be nice and strip crlf's
-            $this->err_recv = strlen($this->line);
-
-            while($this->err_recv < $this->err_len){
-                //print "<br>Trying to receive ".($this->err_len-$this->err_recv)." bytes for result<br>";
-                $this->line = fgets($this->fp, ($this->err_len-$this->err_recv));
-                $this->error_raw[]=substr($this->line, 0, strlen($this->line) -2);    //we want to be nice and strip crlf's
-                $this->err_recv += strlen($this->line);
-            } /* end while */
-            $this->line = fgets($this->fp, 1024);      //we need to grab the last crlf, i think.  this may be a bug...
-            $this->error=EC_UNKNOWN;
-      
-        } /* end if */
-        elseif($this->mtoken[0] == "("){
-            switch($this->mtoken){
-                case "(\"QUOTA\")":
+       if($this->token[0] == "NO"){
+               /* we need to try and extract the error code from here.  There are two possibilites: one, that it will take the form of:
+                  NO ("yyyyy") "zzzzzzz" or, two, NO {yyyyy} "zzzzzzzzzzz" */
+               $this->x = 0;
+               list($this->ltoken, $this->mtoken, $this->rtoken) = split(" ", $this->line." ", 3);
+               if($this->mtoken[0] == "{"){
+                       while($this->mtoken[$this->x] != "}" or $this->err_len < 1){
+                               $this->err_len = substr($this->mtoken, 1, $this->x);
+                               $this->x++;    
+                       }
+                       #print "<br>Trying to receive $this->err_len bytes for result<br>";
+                       $this->line = fgets($this->fp,$this->err_len);
+                       $this->error_raw[]=substr($this->line, 0, strlen($this->line) -2);    //we want to be nice and strip crlf's
+                       $this->err_recv = strlen($this->line);
+
+                       /* Ensure max loop of 1000, to keep the ui from freezing */
+                       $max = 1000;
+                       $cur = 0;
+
+                       while($this->err_recv < ($this->err_len) && ($cur < $max)){
+
+                               $cur ++;
+                               $this->line      = fgets($this->fp,4096);
+                               $this->err_recv += strlen($this->line);
+                               $this->error_raw[]=preg_replace("/\r\n/","",$this->line);    //we want to be nice and strip crlf'
+                       } 
+               } /* end if */
+               elseif($this->mtoken[0] == "("){
+                       switch($this->mtoken){
+                               case "(\"QUOTA\")":
                     $this->error = EC_QUOTA;
                     $this->error_raw=$this->rtoken;
                     break;
@@ -278,7 +280,7 @@ class sieve
   function sieve_login()
   {
 
-    $this->fp=fsockopen($this->host,$this->port);
+    $this->fp=@fsockopen($this->host,$this->port);
     if($this->fp == false)
         return false;