Skip to content

Commit

Permalink
do not send emails without content
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaszott authored Jul 26, 2023
1 parent 6e7b327 commit 926b242
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ public void notifyForSubscriptions(Context context, EPerson ePerson,
Locale supportedLocale = I18nUtil.getEPersonLocale(ePerson);
Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "subscriptions_content"));
email.addRecipient(ePerson.getEmail());
email.addArgument(generateBodyMail(context, indexableComm));
email.addArgument(generateBodyMail(context, indexableColl));

String bodyCommunitites = generateBodyMail(context, indexableComm);
String bodyCollections = generateBodyMail(context, indexableColl);
if (bodyCommunitites.equals(EMPTY) && bodyCollections.equals(EMPTY)) {
log.debug("subscription(s) of eperson {} do(es) not match any new items: nothing to send - exit silently", ePerson::getID);
return;
}
email.addArgument(bodyCommunitites);
email.addArgument(bodyCollections);

email.send();
}
} catch (Exception e) {
Expand All @@ -70,7 +78,7 @@ private String generateBodyMail(Context context, List<IndexableObject> indexable
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write("\n".getBytes(UTF_8));
if (indexableObjects.size() > 0) {
if (indexableObjects != null && !indexableObjects.isEmpty()) {
for (IndexableObject indexableObject : indexableObjects) {
out.write("\n".getBytes(UTF_8));
Item item = (Item) indexableObject.getIndexedObject();
Expand All @@ -80,10 +88,7 @@ private String generateBodyMail(Context context, List<IndexableObject> indexable
.disseminate(context, item, out);
}
return out.toString();
} else {
out.write("No items".getBytes(UTF_8));
}
return out.toString();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down

0 comments on commit 926b242

Please sign in to comment.