/**
  * login
  *
  * Use this method to login to a Zimbra server after you create an instance of this class
  *
  * Login parameters must be specified when calling the constructor
  */
 function login()
 {
     $result = null;
     $n = 0;
     while (true) {
         try {
             $this->setSoapHeader();
             $result = $this->client->__soapCall("AuthRequest", $this->params, null, $this->getSoapHeader());
             //$result = $this->client->__getLastResponse();
             //print_var($result);
             // Save the soapHeader with token
             $this->setSoapHeader($result['authToken']);
             break;
         } catch (SoapFault $exception) {
             // if $retryAttempts>0 retry after a random time using exponential backoff
             // for user logins retries just once
             $n++;
             if ($this->retryAttempts > 0 && $n <= $this->retryAttempts && ($this->context == "admin" || $n == 1)) {
                 $minT = 1 + $n * 1000000 / 10;
                 $maxT = pow(2, $n - 1) * 1000000;
                 $waitT = rand($minT, $maxT);
                 // wait times are shorter on login
                 $waitT = $waitT / 5;
                 usleep($waitT);
             } else {
                 $result = $exception;
                 break;
             }
         }
     }
     return $result;
 }
 /**
  * getCosId
  * @param string $name the COS name
  * @return string COS id
  */
 function getCosId($name)
 {
     $result = null;
     $params = array(new SoapVar('<cos by="name">' . $name . '</cos>', XSD_ANYXML));
     try {
         $result = $this->auth->execSoapCall("GetCosRequest", $params);
         $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETCOSRESPONSE']['COS']['ID'];
     } catch (SoapFault $exception) {
         $result = $exception;
     }
     return $result;
 }
 /**
  * modifyUserPrefs
  * @param string $userName user name
  * @param array $prefs an array containing the user prefs to be set
  * @return array informations
  */
 function modifyUserPrefs($userName, $prefs = array())
 {
     $result = null;
     $params = array(new SoapParam($userName, "account"));
     foreach ($prefs as $key => $value) {
         $params[] = new SoapVar('<pref name="' . $key . '">' . $value . '</pref>', XSD_ANYXML);
     }
     try {
         $result = $this->auth->execSoapCall("ModifyPrefsRequest", $params);
     } catch (SoapFault $exception) {
         $result = $exception;
     }
     return $result;
 }
 /**
  * deleteServer
  * @param string $idOrNameServer server id or server name
  * @param string $type value of the server (auto, name, id)
  * @return array informations
  */
 function deleteServer($idOrNameServer, $type = "auto")
 {
     if ($type == "auto") {
         $realType = getServerType($idOrNameServer);
     } else {
         $realType = $type;
     }
     if ($realType == "name") {
         $serverId = $this->getServerId($idOrNameServer);
     } else {
         $serverId = $idOrNameServer;
     }
     $result = null;
     $params = array(new SoapParam($serverId, "id"));
     try {
         $result = $this->auth->execSoapCall("DeleteServerRequest", $params);
     } catch (SoapFault $exception) {
         $result = $exception;
     }
     return $result;
 }
 /**
  * deleteDomain
  * @param string $idOrNameDomain domain id or domain name
  * @param string $type value of the domain (auto, name, id)
  * @return array informations
  */
 function deleteDomain($idOrNameDomain, $type = "auto")
 {
     if ($type == "auto") {
         $realType = getDomainType($idOrNameDomain);
     } else {
         $realType = $type;
     }
     if ($realType == "name") {
         $domainId = $this->getDomainId($idOrNameDomain);
     } else {
         $domainId = $idOrNameDomain;
     }
     $result = null;
     $params = array(new SoapParam($domainId, "id"));
     try {
         $result = $this->auth->execSoapCall("DeleteDomainRequest", $params);
     } catch (SoapFault $exception) {
         $result = $exception;
     }
     return $result;
 }
    exit(-1);
}
if (isset($args["str"])) {
    $user_name = $args["str"] . "@" . $domain;
}
if (isset($args["onam"])) {
    $nam_opt = $args["onam"];
}
if (isset($args["oval"])) {
    $val_opt = $args["oval"];
}
///////////
// Login //
///////////
$userpassword = "******";
$auth = new Zm_Auth($zimbraserver, $user_name, $userpassword, "user");
$l = $auth->login();
if (is_a($l, "Exception")) {
    echo "Error : cannot login to {$zimbraserver} :-(\n";
    print_exception($l);
    exit;
}
//////////
// User //
//////////
$userManager = new Zm_User($auth);
// User Exists
if ($action == "gux") {
    print_var($user_name, "Check User Existence");
    $r = $userManager->userExists($user_name);
    if (!$r) {