Source:
private void queueMail(final Collection<SingularityEmailDestination> destination, final SingularityRequest request, final SingularityEmailType emailType, final Optional<String> actionTaker, String subject, String body) { RateLimitResult result = checkRateLimitForMail(request, emailType); if (result == RateLimitResult.DONT_SEND_MAIL_IN_COOLDOWN) { return; } if (result == RateLimitResult.SEND_COOLDOWN_STARTED_MAIL) { subject = String.format("%s notifications for %s are being rate limited", emailType.name(), request.getId()); body = Jade4J.render(rateLimitedTemplate, getRateLimitTemplateProperties(request, emailType)); } final Set<String> toList = new HashSet<>(); final Set<String> ccList = new HashSet<>(); if (destination.contains(SingularityEmailDestination.OWNERS) && request.getOwners().isPresent() && !request.getOwners().get().isEmpty()) { toList.addAll(request.getOwners().get()); } if (destination.contains(SingularityEmailDestination.ADMINS) && !smtpConfiguration.getAdmins().isEmpty()) { if (toList.isEmpty()) { toList.addAll(smtpConfiguration.getAdmins()); } else { ccList.addAll(smtpConfiguration.getAdmins()); } } Set<String> emailBlacklist = Sets.newHashSet(notificationsManager.getBlacklist()); toList.removeAll(emailBlacklist); ccList.removeAll(emailBlacklist); if (actionTaker.isPresent() && !Strings.isNullOrEmpty(actionTaker.get())) { if (destination.contains(SingularityEmailDestination.ACTION_TAKER) && !emailBlacklist.contains(actionTaker.get())) { toList.add(actionTaker.get()); } else { final Iterator<String> i = toList.iterator(); while (i.hasNext()) { if (actionTaker.get().equalsIgnoreCase(i.next())) { i.remove(); } } } } smtpSender.queueMail(Lists.newArrayList(toList), Lists.newArrayList(ccList), subject, body); }

Target:
private void queueMail(final Collection<SingularityEmailDestination> destination, final SingularityRequest request, final SingularityEmailType emailType, final Optional<String> actionTaker, String subject, String body) { RateLimitResult result = checkRateLimitForMail(request, emailType); if (result == RateLimitResult.DONT_SEND_MAIL_IN_COOLDOWN) { return; } if (result == RateLimitResult.SEND_COOLDOWN_STARTED_MAIL) { subject = String.format("%s notifications for %s are being rate limited", emailType.name(), request.getId()); body = Jade4J.render(rateLimitedTemplate, getRateLimitTemplateProperties(request, emailType)); } final Set<String> toList = new HashSet<>(); final Set<String> ccList = new HashSet<>(); if (destination.contains(SingularityEmailDestination.OWNERS) && request.getOwners().isPresent() && !request.getOwners().get().isEmpty()) { toList.addAll(request.getOwners().get()); } if (destination.contains(SingularityEmailDestination.ADMINS) && !smtpConfiguration.getAdmins().isEmpty()) { if (toList.isEmpty()) { toList.addAll(smtpConfiguration.getAdmins()); } else { ccList.addAll(smtpConfiguration.getAdmins()); } } if (actionTaker.isPresent() && !Strings.isNullOrEmpty(actionTaker.get())) { if (destination.contains(SingularityEmailDestination.ACTION_TAKER)) { toList.add(actionTaker.get()); } else { final Iterator<String> i = toList.iterator(); while (i.hasNext()) { if (actionTaker.get().equalsIgnoreCase(i.next())) { i.remove(); } } } } Set<String> emailBlacklist = Sets.newHashSet(notificationsManager.getBlacklist()); toList.removeAll(emailBlacklist); ccList.removeAll(emailBlacklist); smtpSender.queueMail(Lists.newArrayList(toList), Lists.newArrayList(ccList), subject, body); }