<?php
/*
* Copyright (c) 2004 Andre Nathan <andre@digirati.com.br>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
include_once "Net/Sieve.php";
include_once "sievectl_config.php";
/*
* Wrappers for Net_Sieve Pear functions
*/
function pr_capabilities($sieve)
{
$ret = $sieve->getExtensions();
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
foreach($ret as $cap)
$ret = $sieve->getAuthMechs();
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
print "Authentication methods:\n";
foreach($ret as $ext)
}
function list_scripts($sieve)
{
$ret = $sieve->listScripts();
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
return $ret;
}
function pr_scripts($sieve)
{
$ret = list_scripts($sieve);
print "Available scripts:\n";
foreach ($ret as $script)
$ret = $sieve->getActive();
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
if ($ret != "")
print "Active script: " .
$ret .
"\n";
else
print "No active scripts found.\n";
}
function get_script($sieve, $name)
{
$ret = $sieve->getScript($name);
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
return $ret;
}
function upload_script($sieve, $name, $script, $active=false)
{
$ret = $sieve->installScript($name, $script, $active);
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
}
function delete_script($sieve, $name)
{
$ret = $sieve->removeScript($name);
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
}
function set_active($sieve, $name)
{
$ret = $sieve->setActive($name);
if (PEAR::isError($ret))
die("Error: " .
$ret->
getMessage() .
"\n");
}
/*
* Other useful functions
*/
function usage()
{
print "Usage: " .
$argv[0] .
"<caps|list|show|activate|add|addactive|delete> [script name]\n";
}
function read_stdin()
{
$data = "";
while ($line =
fgets(STDIN,
1024))
$data .= $line;
return $data;
}
/*
* Main
*/
$sieve = new Net_Sieve($user, $passwd, $server, $port, $auth, $user);
$ret = $sieve->getError();
if (PEAR::isError($err))
die("Login failed: " .
$ret->
getMessage() .
"\n");
switch ($argv[1]) {
case "caps":
pr_capabilities($sieve);
break;
case "list":
pr_scripts($sieve);
break;
case "show":
usage();
print get_script
($sieve,
$argv[2]);
break;
case "activate":
usage();
set_active($sieve, $argv[2]);
break;
case add:
usage();
$script = read_stdin();
upload_script($sieve, $argv[2], $script);
break;
case addactive:
usage();
$script = read_stdin();
upload_script($sieve, $argv[2], $script, true);
break;
case "delete":
usage();
delete_script($sieve, $argv[2]);
break;
default:
usage();
}
$ret = $sieve->disconnect();
if (PEAR::isError($ret))
die("Logout failed: " .
$ret->
getMessage() .
"\n");
?>