diff --git a/src/UnicaenZimbra/Service/ZimbraAccountService.php b/src/UnicaenZimbra/Service/ZimbraAccountService.php index 40197fe724a2bbd788a4f88666f5de4e4e4da366..30dd388658089bd5f6441ae6236aae11803d8b35 100644 --- a/src/UnicaenZimbra/Service/ZimbraAccountService.php +++ b/src/UnicaenZimbra/Service/ZimbraAccountService.php @@ -180,7 +180,7 @@ class ZimbraAccountService extends AbstractService } /** - * Créé un nouveau compte + * Crée un nouveau compte * * @param string|AccountEntity $value nom du compte ou objet AccountEntity * @param array $params @@ -233,7 +233,7 @@ class ZimbraAccountService extends AbstractService } /** - * Supprimer un compte + * Supprime un compte * * @param AccountEntity|string $id * @return bool @@ -330,7 +330,7 @@ class ZimbraAccountService extends AbstractService /** - * Supprimer un alias de messagerie + * Supprime un alias de messagerie * * @param string|AccountEntity $id * @param string $alias @@ -385,7 +385,7 @@ class ZimbraAccountService extends AbstractService } /** - * Supprimer une adresse de redirection + * Supprime une adresse de redirection * * @param string|AccountEntity $id * @param string $forward @@ -408,4 +408,39 @@ class ZimbraAccountService extends AbstractService return $this; } + + /** + * Change l'adresse mail principale du compte + * NB : l'ancien nom est conservé comme alias + * + * @param string|AccountEntity $id + * @param string $newName + * @return AccountEntity + * @throws \UnicaenZimbra\Exception + */ + public function changePrimaryEmail($id, $newName): AccountEntity + { + if ($id instanceof AccountEntity) { + $aid = $id->getId(); + $account = $id; + } else { + $aid = $id; + $account = new AccountEntity; + } + + $params = array( + 'account' => array( + '@content' => $aid, + '@attributes' => array('by' => 'id') + ), + 'newName' => $newName + ); + + $response = $this->getZimbra()->request('ChangePrimaryEmailRequest', [], $params); + $accounts = $response->children()->ChangePrimaryEmailResponse->children(); + $account->populate($accounts[0]); + $this->count = 1; + + return $account; + } } \ No newline at end of file