Skip to content

Commit

Permalink
Managesieve: error checking and RC 0.8.x support
Browse files Browse the repository at this point in the history
 - Checked with RC 0.8.4
 - Fixes Issue arodier#5 & arodier#6
  • Loading branch information
gms-chris committed Jun 21, 2013
1 parent 90602bd commit 8a99429
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions plugins/vacation_sieve/transfer/managesieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,61 @@ private function GetManagesieve()

// try to connect to managesieve server
$this->managesieve = new rcube_sieve(
$this->app->get_user_name(),
$this->app->get_user_password(),
method_exists($this->app, get_user_name) ? $this->app->get_user_name() : $_SESSION['username'],
method_exists($this->app, get_user_password) ? $this->app->get_user_password() : $this->app->decrypt($_SESSION['password']),
$this->params['host'],
$this->params['port'],
null,
$this->params['usetls']
);

if ($error = $this->managesieve->error()) {
$this->ShowError($error);
}

return $error;

}

private function ShowError($error)
{
if ($error) {
switch ($error) {
case SIEVE_ERROR_CONNECTION:
case SIEVE_ERROR_LOGIN:
$this->app->output->show_message('Managesieve: Connection error', 'error');
break;
case SIEVE_ERROR_NOT_EXISTS:
$this->app->output->show_message('Managesieve: Script does not exist', 'error');
break;
case SIEVE_ERROR_INSTALL:
$this->app->output->show_message('Managesieve: Script failed to install', 'error');
break;
case SIEVE_ERROR_ACTIVATE:
case SIEVE_ERROR_DEACTIVATE:
$this->app->output->show_message('Managesieve: Activation change failed', 'error');
break;
default:
$this->app->output->show_message('Managesieve: Unknown error', 'error');
break;
}
}
}

public function LoadScript($script_name)
{
$script = '';

if (!$this->managesieve) {
$this->GetManagesieve();
if($this->GetManagesieve()) { return 0; }
}

if ($script_name) {
$script = $this->managesieve->get_script($script_name);
if($error = $this->managesieve->error()) {
$this->ShowError($error);
return 0;
}
}

return $script;
Expand All @@ -57,11 +92,15 @@ public function SaveScript($script_name,$script)
$success_activate = false;

if (!$this->managesieve) {
$this->GetManagesieve();
if($this->GetManagesieve()) { return 0; }
}

if ($script_name) {
$success_save = $this->managesieve->save_script($script_name,$script);
if($error = $this->managesieve->error()) {
$this->ShowError($error);
return 0;
}
if($this->params['enable'] && $this->params['ms_activate_script'])
{
$success_activate = $this->managesieve->activate($script_name);
Expand Down

0 comments on commit 8a99429

Please sign in to comment.