Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: Ensure unique email when sendEmail OFBIZ-13170 #850

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,45 +165,35 @@ public static Map<String, Object> sendCommEventAsEmail(DispatchContext ctx, Map<
return ServiceUtil.returnError(errMsg + " " + communicationEventId);
}

// add other parties from roles
String sendCc = null;
String sendBcc = null;
// add other parties from roles, collect all email on map to parse it after
List<String> alreadyLoaded = UtilMisc.toList(sendTo);
List<String> availableRoleTypeIds = UtilMisc.toList("ADDRESSEE", "CC", "BCC");
Map<String, Object> emailsCollector = UtilMisc.toMap("ADDRESSEE", UtilMisc.toList(sendTo));
List<GenericValue> commRoles = communicationEvent.getRelated("CommunicationEventRole", null, null, false);
if (UtilValidate.isNotEmpty(commRoles)) {
for (GenericValue commRole : commRoles) { // 'from' and 'to' already defined on communication event
if (commRole.getString("partyId").equals(communicationEvent.getString("partyIdFrom"))
|| commRole.getString("partyId").equals(communicationEvent.getString("partyIdTo"))) {
continue;
}
GenericValue contactMech = commRole.getRelatedOne("ContactMech", false);
if (contactMech != null && UtilValidate.isNotEmpty(contactMech.getString("infoString"))) {
if ("ADDRESSEE".equals(commRole.getString("roleTypeId"))) {
sendTo += "," + contactMech.getString("infoString");
} else if ("CC".equals(commRole.getString("roleTypeId"))) {
if (sendCc != null) {
sendCc += "," + contactMech.getString("infoString");
} else {
sendCc = contactMech.getString("infoString");
}
} else if ("BCC".equals(commRole.getString("roleTypeId"))) {
if (sendBcc != null) {
sendBcc += "," + contactMech.getString("infoString");
} else {
sendBcc = contactMech.getString("infoString");
}
String infoString = contactMech.getString("infoString");
String roleTypeId = commRole.getString("roleTypeId");
if (alreadyLoaded.contains(infoString)
&& !availableRoleTypeIds.contains(roleTypeId)) {
continue;
}
alreadyLoaded.add(infoString);
UtilMisc.addToListInMap(infoString, emailsCollector, roleTypeId);
}
}
}
sendMailParams.put("sendTo", String.join(",", UtilMisc.getListFromMap(emailsCollector, "ADDRESSEE")));
sendMailParams.put("sendCc", emailsCollector.containsKey("CC")
? String.join(",", UtilMisc.getListFromMap(emailsCollector, "CC"))
: null);
sendMailParams.put("sendBcc", emailsCollector.containsKey("BCC")
? String.join(",", UtilMisc.getListFromMap(emailsCollector, "BCC"))
: null);

sendMailParams.put("communicationEventId", communicationEventId);
sendMailParams.put("sendTo", sendTo);
if (sendCc != null) {
sendMailParams.put("sendCc", sendCc);
}
if (sendBcc != null) {
sendMailParams.put("sendBcc", sendBcc);
}
sendMailParams.put("partyId", communicationEvent.getString("partyIdTo")); // who it's going to

// send it - using a new transaction
Expand Down
Loading