Created
May 18, 2015 08:43
-
-
Save chrisramakers/512a344c6e7b565556b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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