gunnar: server/kolab-webadmin/kolab-webadmin/lib/KolabAdmin Sieve.php, 1.1, 1.2

cvs at kolab.org cvs at kolab.org
Thu Apr 1 11:12:33 CEST 2010


Author: gunnar

Update of /kolabrepository/server/kolab-webadmin/kolab-webadmin/lib/KolabAdmin
In directory doto:/tmp/cvs-serv9222/kolab-webadmin/lib/KolabAdmin

Modified Files:
	Sieve.php 
Log Message:
Add a first draft of the segment machinery to support the combined script. The logic is still somewhat to complex but refactoring comes later.

Index: Sieve.php
===================================================================
RCS file: /kolabrepository/server/kolab-webadmin/kolab-webadmin/lib/KolabAdmin/Sieve.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Sieve.php	31 Mar 2010 22:32:22 -0000	1.1
+++ Sieve.php	1 Apr 2010 09:12:30 -0000	1.2
@@ -29,6 +29,11 @@
 class KolabAdmin_Sieve
 {
 
+    const SCRIPT = 'kolab.siv';
+
+    const OLD_SCRIPT_DELIVERY = 'kolab-deliver.siv';
+
+
     /**
      * The sieve connection.
      */
@@ -41,6 +46,8 @@
 
     /**
      * Constructor.
+     *
+     * @param Net_Sieve $sieve The sieve connection.
      */
     public function __construct(Net_Sieve $sieve)
     {
@@ -50,7 +57,44 @@
     private function _init()
     {
         if ($this->_segments === null) {
-            $this->_segments['delivery'] = new KolabAdmin_Sieve_Segment_Delivery();
+            $scripts = $this->_sieve->listScripts();
+
+            if (!empty($scripts)) {
+                if (in_array(self::SCRIPT, $scripts)) {
+                    $this->_segments = $this->_splitSegments(
+                        $this->_sieve->getScript(self::SCRIPT)
+                    );
+                } else {
+                    if (in_array(self::OLD_SCRIPT_DELIVERY, $scripts)) {
+                        $this->_segments['delivery'] = new KolabAdmin_Sieve_Segment_Delivery(
+                            $this->_sieve->getScript(self::OLD_SCRIPT_DELIVERY)
+                        );
+                        if ($this->_sieve->getActive() == self::OLD_SCRIPT_DELIVERY) {
+                            $this->_segments['delivery']->setActive();
+                        }
+                    }
+                }
+            }
+            if (!isset($this->_segments['delivery'])) {
+                $this->_segments['delivery'] = new KolabAdmin_Sieve_Segment_Delivery();
+            }
+        }
+    }
+
+    private function _splitSegments($script)
+    {
+        preg_match('/^\\(### SEGMENT START [^#]*.*?### SEGMENT END [^#]*\\)/', $script, $matches);
+        foreach ($matches as $match) {
+            preg_match('/^### SEGMENT START \\([^#]*\\)/', $match, $id);
+            if (!empty($id[0])) {
+                $class = 'KolabAdmin_Sieve_Segment_' . ucfirst($id[0]);
+                $this->_segments[$id[0]] = new $class($match);
+                if (preg_match('/^### SEGMENT START \\([^ ]* ENABLED\\)/', $match)) {
+                    $this->_segments[$id[0]]->setActive();
+                }
+            } else {
+                throw new Exception('Unknown segment type.');
+            }
         }
     }
 





More information about the commits mailing list