default String determineEmailSubject(final EmailMessageRequest emailRequest,
                                         final MessageSource messageSource) {
        val substitutor = new StringSubstitutor(emailRequest.getContext(), "${", "}");
        var subject = substitutor.replace(emailRequest.getEmailProperties().getSubject());

        val pattern = RegexUtils.createPattern("#\\{(.+)\\}");
        val matcher = pattern.matcher(subject);
        if (matcher.find()) {
            val args = new ArrayList<>();
            if (emailRequest.getPrincipal() != null) {
                args.add(emailRequest.getPrincipal().getId());
            }
            return messageSource.getMessage(matcher.group(1), args.toArray(),
                "Email Subject", ObjectUtils.defaultIfNull(emailRequest.getLocale(), Locale.getDefault()));
        }
        return SpringExpressionLanguageValueResolver.getInstance().resolve(subject);
    }
Determine email subject using a given message source.

@param emailRequest  the email request
@param messageSource the message source
@return the string
core/cas-server-core-notifications-api/src/main/java/org/apereo/cas/notifications/mail/EmailSender.java