return sender.getSentMessageCount();
}
private void sendByPolicy(MessageSender sender, Recipient recipient) throws Exception, UserDatabaseException {
UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(recipient.getRealmName());
PolicyDatabase policyDatabase = PolicyDatabaseFactory.getInstance();
Realm realm = userDatabase.getRealm();
Policy policy = policyDatabase.getPolicyByName(recipient.getRecipientAlias(), realm.getResourceId());
int everyonePolicyId = policyDatabase.getEveryonePolicyIDForRealm(realm);
if (everyonePolicyId == policy.getResourceId()) {
sendToPrincipals(sender, userDatabase, userDatabase.allRoles());
sendToPrincipals(sender, userDatabase, userDatabase.allUsers());
} else {
List<Principal> principals = policyDatabase.getPrincipalsGrantedPolicy(policy, realm);
sendToPrincipals(sender, userDatabase, principals);
}
}