}
private String sendEmailToIdentity(Identity identity,HashMap identityRepositoryList, MailTemplate template,
boolean isTemplateChanged, String keyEmailSubject, String keyEmailBody, Identity sender, Translator pT) {
MailerWithTemplate mailer = MailerWithTemplate.getInstance();
template.addToContext("responseTo", emailResponseTo);
if (!isTemplateChanged) {
// Email template has NOT changed => take translated version of subject and body text
Translator identityTranslator = new PackageTranslator(PACKAGE, I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage()));
template.setSubjectTemplate(identityTranslator.translate(keyEmailSubject));
template.setBodyTemplate(identityTranslator.translate(keyEmailBody));
}
// loop over all repositoriesOfIdentity to build email message
StringBuilder buf = new StringBuilder();
for (Iterator repoIterator = ((List)identityRepositoryList.get(identity)).iterator(); repoIterator.hasNext();) {
RepositoryEntry repositoryEntry = (RepositoryEntry) repoIterator.next();
buf.append("\n ").append( repositoryEntry.getDisplayname() ).append(" / ").append(trimDescription(repositoryEntry.getDescription(), 60));
}
template.addToContext("repositoryList", buf.toString());
template.putVariablesInMailContext(template.getContext(), identity);
Tracing.logDebug(" Try to send Delete-email to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null), this.getClass());
List<Identity> ccIdentities = new ArrayList<Identity>();
if(template.getCpfrom()) {
ccIdentities.add(sender);
} else {
ccIdentities = null;
}
MailerResult mailerResult = mailer.sendMailUsingTemplateContext(identity, ccIdentities, null, template, sender);
if (mailerResult.getReturnCode() == MailerResult.OK) {
// Email sended ok => set deleteEmailDate
for (Iterator repoIterator = ((List)identityRepositoryList.get(identity)).iterator(); repoIterator.hasNext();) {
RepositoryEntry repositoryEntry = (RepositoryEntry) repoIterator.next();
Tracing.logAudit("Repository-Deletion: Delete-email for repositoryEntry=" + repositoryEntry + "send to identity=" + identity.getName(), this.getClass());