Search in sources :

Example 76 with ContactList

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;
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList)

Example 77 with ContactList

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);
                }
            }
        }
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) IdentityImpl(org.olat.basesecurity.IdentityImpl) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 78 with ContactList

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;
}
Also used : ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity)

Example 79 with ContactList

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;
}
Also used : ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 80 with ContactList

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;
}
Also used : ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity)

Aggregations

ContactList (org.olat.core.util.mail.ContactList)92 Identity (org.olat.core.id.Identity)66 ContactMessage (org.olat.core.util.mail.ContactMessage)28 MailBundle (org.olat.core.util.mail.MailBundle)26 ContactFormController (org.olat.modules.co.ContactFormController)22 MailContextImpl (org.olat.core.util.mail.MailContextImpl)18 MailerResult (org.olat.core.util.mail.MailerResult)18 MailContext (org.olat.core.util.mail.MailContext)16 ArrayList (java.util.ArrayList)14 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)14 RepositoryEntry (org.olat.repository.RepositoryEntry)10 HashSet (java.util.HashSet)8 Test (org.junit.Test)8 BusinessGroup (org.olat.group.BusinessGroup)7 Locale (java.util.Locale)6 WindowControl (org.olat.core.gui.control.WindowControl)6 Translator (org.olat.core.gui.translator.Translator)6 File (java.io.File)4 Date (java.util.Date)4 Address (javax.mail.Address)4