/**
  * Helper function for #applyMailAccountsToFolder.
  *
  * @param Array $accounts
  * @param \Conjoon\Data\Entity\Mail\MailFolderEntity $folderEntity
  */
 protected function applyAccounts(array $accounts, \Conjoon\Data\Entity\Mail\MailFolderEntity $folderEntity)
 {
     // inspect accounts
     $orgMailAccounts = $folderEntity->getMailAccounts();
     $oldIds = array();
     foreach ($orgMailAccounts as $orgAccount) {
         $oldIds[] = $orgAccount->getId();
     }
     foreach ($accounts as $applyAccount) {
         if (!in_array($applyAccount->getId(), $oldIds)) {
             $folderEntity->addMailAccount($applyAccount);
             // prevent dups
             $oldIds[] = $applyAccount->getId();
         }
     }
     try {
         $this->folderRepository->register($folderEntity);
     } catch (\Exception $e) {
         throw new FolderServiceException("Exception thrown by previous exception", 0, $e);
     }
     try {
         $folders = $this->folderRepository->getChildFolders($folderEntity);
     } catch (\Exception $e) {
         throw new FolderServiceException("Exception thrown by previous exception", 0, $e);
     }
     foreach ($folders as $folder) {
         $this->applyAccounts($accounts, $folder);
     }
 }