Skip to content

Instantly share code, notes, and snippets.

@chrisramakers
Created May 18, 2015 08:43
Show Gist options
  • Select an option

  • Save chrisramakers/512a344c6e7b565556b8 to your computer and use it in GitHub Desktop.

Select an option

Save chrisramakers/512a344c6e7b565556b8 to your computer and use it in GitHub Desktop.
<?php
include_once './vendor/autoload.php';
function accountExists($name){
$soapClient = new \Zimbra\ZCS\SoapClient("host", "port", "username", "password");
$admin = new \Zimbra\ZCS\Admin\Account($soapClient);
try {
// Fetch account by name, if it exists return it
$accountEntity = $admin->getAccount($name, 'name');
return $accountEntity;
} catch(\Zimbra\ZCS\Exception $e){
// If an exception is thrown check the message, if it matches to NO_SUCH_ACCOUNT message
// it means there isn't an account with that name thus return false
// If it's another message something else went wrong, thus throw the exception again
// so we can catch it later or just log it and die
if($e->getMessage() == 'account.NO_SUCH_ACCOUNT') {
return false;
} else {
throw $e;
}
}
}
var_dump(accountExists('info@foo.com'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment