Controller/AzineEmailTemplateController.php
private function userIsAllowedToSeeThisMail(SentEmail $mail)
    {
        $recipients = $mail->getRecipients();

        // it is a public email
        if (null === $recipients) {
            return true;
        }

        // get the current user
        $currentUser = null;
        if (!$this->has('security.token_storage')) {
            // @codeCoverageIgnoreStart
            throw new \LogicException('The SecurityBundle is not registered in your application.');
            // @codeCoverageIgnoreEnd
        }
        $token = $this->get('security.token_storage')->getToken();

        // check if the token is not null and the user in the token an object
        if ($token instanceof TokenInterface && is_object($token->getUser())) {
            $currentUser = $token->getUser();
        }

        // it is not a public email, and a user is logged in
        if (null !== $currentUser) {
            // the user is among the recipients
            if (false !== array_search($currentUser->getEmail(), $recipients)) {
                return true;
            }

            // the user is admin
            if ($currentUser->hasRole('ROLE_ADMIN')) {
                return true;
            }
        }

        // not public email, but
        // 		- there is no user, or
        //		- the user is not among the recipients and
        //		- the user not an admin-user either
        return false;
    }
private function userIsAllowedToSeeThisMail(SentEmail $mail)
    {
        $recipients = $mail->getRecipients();

        // it is a public email
        if (null === $recipients) {
            return true;
        }

        // get the current user
        $currentUser = null;
        if (!$this->has('security.token_storage')) {
            // @codeCoverageIgnoreStart
            throw new \LogicException('The SecurityBundle is not registered in your application.');
            // @codeCoverageIgnoreEnd
        }
        $token = $this->get('security.token_storage')->getToken();

        // check if the token is not null and the user in the token an object
        if ($token instanceof TokenInterface && is_object($token->getUser())) {
            $currentUser = $token->getUser();
        }

        // it is not a public email, and a user is logged in
        if (null !== $currentUser) {
            // the user is among the recipients
            if (false !== array_search($currentUser->getEmail(), $recipients)) {
                return true;
            }

            // the user is admin
            if ($currentUser->hasRole('ROLE_ADMIN')) {
                return true;
            }
        }

        // not public email, but
        // 		- there is no user, or
        //		- the user is not among the recipients and
        //		- the user not an admin-user either
        return false;
    }
private function userIsAllowedToSeeThisMail ( SentEmail $ mail ) { $ recipients = $ mail -> getRecipients ( ) ; // it is a public email if ( null === $ recipients ) { return true ; } // get the current user $ currentUser = null ; if ( ! $ this -> has ( 'security.token_storage' ) ) { // @codeCoverageIgnoreStart throw new \ LogicException ( 'The SecurityBundle is not registered in your application.' ) ; // @codeCoverageIgnoreEnd } $ token = $ this -> get ( 'security.token_storage' ) -> getToken ( ) ; // check if the token is not null and the user in the token an object if ( $ token instanceof TokenInterface && is_object ( $ token -> getUser ( ) ) ) { $ currentUser = $ token -> getUser ( ) ; } // it is not a public email, and a user is logged in if ( null !== $ currentUser ) { // the user is among the recipients if ( false !== array_search ( $ currentUser -> getEmail ( ) , $ recipients ) ) { return true ; } // the user is admin if ( $ currentUser -> hasRole ( 'ROLE_ADMIN' ) ) { return true ; } } // not public email, but // 		- there is no user, or //		- the user is not among the recipients and //		- the user not an admin-user either return false ; }
Check if the user is allowed to see the email.
=> the mail is public or the user is among the recipients or the user is an admin.

@param SentEmail $mail

@return bool
Check if the user is allowed to see the email . = > the mail is public or the user is among the recipients or the user is an admin .