gunnar: utils/admin kolab_vacation_tool,1.4,1.5

cvs at kolab.org cvs at kolab.org
Wed Apr 14 00:38:04 CEST 2010


Author: gunnar

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv15661/admin

Modified Files:
	kolab_vacation_tool 
Log Message:
Adapt to the new backend classes.

Index: kolab_vacation_tool
===================================================================
RCS file: /kolabrepository/utils/admin/kolab_vacation_tool,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- kolab_vacation_tool	16 Mar 2006 12:26:23 -0000	1.4
+++ kolab_vacation_tool	13 Apr 2010 22:38:02 -0000	1.5
@@ -23,10 +23,16 @@
 ini_set( 'include_path',
          '.:/kolab/var/kolab/php:/kolab/var/kolab/php/pear:'.$include_path);
 
-require_once 'admin/include/sieveutils.class.php';
 require_once 'PEAR.php';
 
-include_once 'admin/include/Sieve.php';
+include_once 'Net/Sieve.php';
+require_once 'Horde/String.php';
+require_once 'KolabAdmin/Sieve.php';
+require_once 'KolabAdmin/Sieve/Script.php';
+require_once 'KolabAdmin/Sieve/Segment.php';
+require_once 'KolabAdmin/Sieve/Segment/Delivery.php';
+require_once 'KolabAdmin/Sieve/Segment/Forward.php';
+require_once 'KolabAdmin/Sieve/Segment/Vacation.php';
 
 include ("Console/Getopt.php");
 
@@ -116,58 +122,22 @@
     return $errors;
   }
 
-  $addresses = $days = $text = false;
-  if( PEAR::isError( $scripts = $sieve->listScripts() ) ) {
-    $errors[] = $scripts->getMessage();
-    /* try to disconnect anyway (without recording further errors) */
-    $sieve->disconnect();
-    return $errors;
-  }
-  if( in_array( $scriptname, $scripts ) ) {
-    $script = $sieve->getScript($scriptname);
-    $old_maildomain = SieveUtils::getMailDomain( $script );
-    $old_dontreacttospam = SieveUtils::getReactToSpam( $script );
-    $addresses = SieveUtils::getVacationAddresses( $script );
-    $days = SieveUtils::getVacationDays( $script );
-    $text = SieveUtils::getVacationText( $script );
-  } else $old_dontreacttospam = true;
-  if( $addresses === false ) $addresses = array( "" );
-  $active = ( $sieve->getActive() === $scriptname );
-
-  if(is_null($maildomain))
-    $new_maildomain = $old_maildomain;
-  else
-    $new_maildomain = $maildomain;
-
-  if(is_null($dontreacttospam))
-    $new_dontreacttospam = $old_dontreacttospam;
-  else
-    $new_dontreacttospam = $dontreacttospam;
-
-  if( $new_maildomain != $old_maildomain ||
-      $new_dontreacttospam != $old_dontreacttospam ) {
-
-    $script =
-      "require \"vacation\";\r\n\r\n".
-      (!empty($new_maildomain)?"if not address :domain :contains \"From\" \"".$new_maildomain."\" { keep; stop; }\r\n":"").
-      ($new_dontreacttospam?"if header :contains \"X-Spam-Flag\" \"YES\" { keep; stop; }\r\n":"").
-      ($addresses && $text && $days ?
-      "vacation :addresses [ \"".join('", "', $addresses )."\" ] :days ".$days." text:\r\n".
-      SieveUtils::dotstuff($text).".\r\n;":"")."\r\n\r\n";
+  try {
+    $handler = new KolabAdmin_Sieve($sieve);
 
-    if( PEAR::isError( $res = $sieve->installScript( $scriptname, $script, $active ) ) ) {
-      $errors[] = $res->getMessage();
-      $errors[] = 'Script was:';
-      $errors[] = $script;
-      /* try to disconnect anyway (without recording further errors) */
-      $sieve->disconnect();
-      return $errors;
-    }
+    $handler->fetchVacationSegment()->setDomain(trim($maildomain));
+    $handler->fetchVacationSegment()->setReactToSpam(!$dontreacttospam);
 
+    $handler->store();
+  } catch (Exception $e) {
+    $errors[] = $e->getMessage();
+    $errors[] = 'Script was:';
+    $errors[] = '<pre>' . $handler->getScript() . '</pre>';
+    return $errors;
+  }
 
-    if ($verbosity == 0) {
-      fwrite(STDOUT, "$user on $host: updated\n");
-    }
+  if ($verbosity == 0) {
+    fwrite(STDOUT, "$user on $host: updated\n");
   }
 
   if ($verbosity > 0) {





More information about the commits mailing list