use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class MailManagerImpl method createMimeMessage.
private MimeMessage createMimeMessage(Identity fromId, String mailFrom, Identity toId, String to, Identity ccId, List<ContactList> bccLists, MailContent content, MailerResult result) {
try {
Address from;
if (StringHelper.containsNonWhitespace(mailFrom)) {
from = createFromAddress(mailFrom, result);
} else if (fromId != null) {
from = createFromAddress(fromId, result);
} else {
// fxdiff: change from/replyto, see FXOLAT-74 . if no from is set, use default sysadmin-address (adminemail).
from = createAddress(WebappHelper.getMailConfig("mailReplyTo"));
if (from == null) {
log.error("MailConfigError: mailReplyTo is not set", null);
}
}
List<Address> toList = new ArrayList<Address>();
if (StringHelper.containsNonWhitespace(to)) {
Address[] toAddresses = InternetAddress.parse(to);
for (Address toAddress : toAddresses) {
toList.add(toAddress);
}
} else if (toId != null) {
Address toAddress = createAddress(toId, result, true);
if (toAddress != null) {
toList.add(toAddress);
}
}
List<Address> ccList = new ArrayList<Address>();
if (ccId != null) {
Address ccAddress = createAddress(ccId, result, true);
if (ccAddress != null) {
ccList.add(ccAddress);
}
}
// add bcc contact lists
List<Address> bccList = new ArrayList<Address>();
if (bccLists != null) {
for (ContactList contactList : bccLists) {
if (StringHelper.containsNonWhitespace(contactList.getName())) {
Address[] groupNames = InternetAddress.parse(contactList.getRFC2822Name() + ";");
for (Address groupName : groupNames) {
toList.add(groupName);
}
}
Address[] members = contactList.getEmailsAsAddresses();
for (Address member : members) {
bccList.add(member);
}
}
}
Address[] tos = toList.toArray(new Address[toList.size()]);
Address[] ccs = ccList.toArray(new Address[ccList.size()]);
Address[] bccs = bccList.toArray(new Address[bccList.size()]);
return createMimeMessage(from, tos, ccs, bccs, content.getSubject(), content.getBody(), content.getAttachments(), result);
} catch (MessagingException e) {
log.error("", e);
return null;
}
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class MailManagerImpl method appendRecipients.
private void appendRecipients(DBMailImpl mail, List<ContactList> ccLists, List<Address> toAddress, List<Address> ccAddress, boolean visible, boolean makeRealMail, MailerResult result) throws AddressException {
// append cc/bcc recipients
if (ccLists != null && !ccLists.isEmpty()) {
for (ContactList contactList : ccLists) {
if (makeRealMail && StringHelper.containsNonWhitespace(contactList.getName())) {
Address[] groupAddress = InternetAddress.parse(contactList.getRFC2822Name() + ";");
if (groupAddress != null && groupAddress.length > 0) {
for (Address groupAdd : groupAddress) {
toAddress.add(groupAdd);
}
}
}
for (String email : contactList.getStringEmails().values()) {
DBMailRecipient recipient = new DBMailRecipient();
recipient.setEmailAddress(email);
recipient.setGroup(contactList.getName());
recipient.setVisible(visible);
recipient.setDeleted(Boolean.FALSE);
recipient.setMarked(Boolean.FALSE);
recipient.setRead(Boolean.FALSE);
mail.getRecipients().add(recipient);
if (makeRealMail) {
createAddress(ccAddress, recipient, false, result, false);
}
}
for (Identity identityEmail : contactList.getIdentiEmails().values()) {
DBMailRecipient recipient = new DBMailRecipient();
if (identityEmail instanceof IdentityImpl) {
recipient.setRecipient(identityEmail);
} else {
recipient.setEmailAddress(identityEmail.getUser().getProperty(UserConstants.EMAIL, null));
}
recipient.setGroup(contactList.getName());
recipient.setVisible(visible);
recipient.setDeleted(Boolean.FALSE);
recipient.setMarked(Boolean.FALSE);
recipient.setRead(Boolean.FALSE);
mail.getRecipients().add(recipient);
if (makeRealMail) {
createAddress(ccAddress, recipient, false, result, false);
}
}
}
}
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class CORunController method retrieveCoachesFromCourse.
private ContactList retrieveCoachesFromCourse() {
List<Identity> coaches = cgm.getCoaches();
ContactList cl = new ContactList(translate("form.message.chckbx.partips"));
cl.addAllIdentites(coaches);
return cl;
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class CORunController method retrieveCoachesFromAreas.
private ContactList retrieveCoachesFromAreas(List<Long> areaKeys) {
List<Identity> coaches = cgm.getCoachesFromAreas(areaKeys);
Set<Identity> coachesWithoutDuplicates = new HashSet<Identity>(coaches);
coaches = new ArrayList<Identity>(coachesWithoutDuplicates);
ContactList cl = new ContactList(translate("form.message.chckbx.coaches"));
cl.addAllIdentites(coaches);
return cl;
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class CORunController method retrieveCoachesFromGroups.
private ContactList retrieveCoachesFromGroups(List<Long> groupKeys) {
List<Identity> coaches = new ArrayList<Identity>(new HashSet<Identity>(cgm.getCoachesFromBusinessGroups(groupKeys)));
ContactList cl = new ContactList(translate("form.message.chckbx.coaches"));
cl.addAllIdentites(coaches);
return cl;
}
Aggregations