Search in sources :

Example 1 with DBMailRecipient

use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.

the class MailController method getFrom.

private String getFrom() {
    StringBuilder sb = new StringBuilder();
    DBMailRecipient from = mail.getFrom();
    sb.append("<ul class='list-inline'><li>");
    if (from != null) {
        sb.append(getFullName(from));
        if (showMailAdresses()) {
            Identity fromIdentity = from.getRecipient();
            if (fromIdentity != null) {
                sb.append(" &lt;");
                sb.append(UserManager.getInstance().getUserDisplayEmail(fromIdentity, getLocale()));
                sb.append("&gt; ");
            }
        }
    }
    sb.append("</li></ul>");
    return sb.toString();
}
Also used : Identity(org.olat.core.id.Identity) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 2 with DBMailRecipient

use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.

the class MailController method getRecipients.

private String getRecipients() {
    StringBuilder sb = new StringBuilder();
    Set<String> groups = new HashSet<>();
    int recipientsCounter = 0;
    int groupCounter = 0;
    sb.append("<ul class='list-inline'>");
    for (DBMailRecipient recipient : mail.getRecipients()) {
        if (recipient == null)
            continue;
        if (recipientsCounter >= maxRecipients && !showAllRecipients) {
            sb.append("<li class='o_more'>").append(translate("recipients.more", (mail.getRecipients().size() - recipientsCounter) + "")).append("<span>");
            break;
        }
        recipientsCounter++;
        String group = recipient.getGroup();
        if (StringHelper.containsNonWhitespace(group) && !groups.contains(group)) {
            // recipient is the entire group
            if (sb.length() > 0) {
                sb.append("</ul>");
                sb.append("<ul class='list-inline'>");
            }
            sb.append("<li class='o_group'><i class='o_icon o_icon_group o_icon-fw'> </i><span>");
            sb.append(group);
            sb.append("</span></li>");
            groups.add(group);
            groupCounter = 0;
        }
        if (showRecipientNames()) {
            if (recipient.getRecipient() != null) {
                sb.append("<li class='o_recipient'>");
                if (groupCounter > 0)
                    sb.append(", ");
                sb.append("<span>").append(getFullName(recipient)).append("</span>");
                if (showMailAdresses()) {
                    sb.append(" &lt;");
                    sb.append(UserManager.getInstance().getUserDisplayEmail(recipient.getRecipient(), getLocale()));
                    sb.append("&gt;");
                }
                sb.append("</li>");
                groupCounter++;
            }
        }
        if (showMailAdresses()) {
            if (recipient.getEmailAddress() != null) {
                // recipient is not an OpenOLAT identity but an external email
                sb.append("<li class='o_mail'>");
                if (groupCounter > 0)
                    sb.append(", ");
                sb.append("&lt;");
                sb.append(UserManager.getInstance().getUserDisplayEmail(recipient.getEmailAddress(), getLocale()));
                sb.append("&gt;</li>");
                groupCounter++;
            }
        }
    }
    sb.append("</ul>");
    return sb.toString();
}
Also used : HashSet(java.util.HashSet) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 3 with DBMailRecipient

use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.

the class MailListController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            int rowid = te.getRowId();
            DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(rowid);
            if (CMD_READ.equals(actionid)) {
                if (outbox && StringHelper.containsNonWhitespace(mail.getMetaId()) && !mail.getMetaId().equals(metaId)) {
                    selectMetaMail(ureq, mail.getMetaId());
                } else {
                    selectMail(ureq, mail.getKey());
                }
            } else if (CMD_PROFILE.equals(actionid)) {
                DBMailRecipient from = mail.getFrom();
                if (from != null && from.getRecipient() != null) {
                    contextResolver.open(ureq, getWindowControl(), "[Identity:" + from.getRecipient().getKey() + "]");
                }
            } else if (CMD_MARK_TOGGLE.equals(actionid)) {
                mail = mailManager.toggleMarked(mail, getIdentity());
                replaceInModel(mail);
            } else if (CMD_READ_TOGGLE.equals(actionid)) {
                mail = mailManager.toggleRead(mail, getIdentity());
                replaceInModel(mail);
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            BitSet selectedMails = tmse.getSelection();
            if (selectedMails.isEmpty()) {
                tableVC.setDirty(true);
                showWarning("mail.action.emtpy");
                return;
            }
            String actionid = tmse.getAction();
            if (CMD_DELETE.equals(actionid)) {
                String title = translate("mail.confirm.delete.title");
                int selected = selectedMails.cardinality();
                String text;
                if (selected == 1) {
                    text = translate("mail.confirm.delete.single.text");
                } else {
                    text = translate("mail.confirm.delete.multi.text", selected + "");
                }
                deleteConfirmationBox = activateYesNoDialog(ureq, title, text, deleteConfirmationBox);
                deleteConfirmationBox.setUserObject(selectedMails);
            } else if (CMD_SEND_REAL_MAIL.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    MailerResult result = forwardToMyRealMail(mail);
                    if (result.getReturnCode() != MailerResult.OK) {
                        MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
                    } else {
                        showInfo("mail.action.send.real.success", mail.getSubject());
                    }
                }
                reloadModel();
            } else if (CMD_MARK_MARKED.equals(actionid) || CMD_MARK_UNMARKED.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    mailManager.setMarked(mail, CMD_MARK_MARKED.equals(actionid), getIdentity());
                }
                reloadModel();
            } else if (CMD_MARK_READ.equals(actionid) || CMD_MARK_UNREAD.equals(actionid)) {
                for (int i = selectedMails.nextSetBit(0); i >= 0; i = selectedMails.nextSetBit(i + 1)) {
                    DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                    mailManager.setRead(mail, CMD_MARK_READ.equals(actionid), getIdentity());
                }
                reloadModel();
            }
        } else if (TableController.EVENT_FILTER_SELECTED == event) {
            MailDataModel dataModel = (MailDataModel) tableCtr.getTableDataModel();
            MailContextShortName filter = (MailContextShortName) tableCtr.getActiveFilter();
            dataModel.filter(filter);
            tableCtr.setTableDataModel(dataModel);
        } else if (TableController.EVENT_NOFILTER_SELECTED == event) {
            MailDataModel dataModel = (MailDataModel) tableCtr.getTableDataModel();
            dataModel.filter(null);
            tableCtr.setTableDataModel(dataModel);
        }
    } else if (source == mailCtr) {
        backFromMail();
    } else if (source == metaMailCtr) {
        removeAsListenerAndDispose(metaMailCtr);
        metaMailCtr = null;
        mainVC.put(MAIN_CMP, tableVC);
    } else if (source == deleteConfirmationBox) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            BitSet deleteMails = (BitSet) deleteConfirmationBox.getUserObject();
            for (int i = deleteMails.nextSetBit(0); i >= 0; i = deleteMails.nextSetBit(i + 1)) {
                DBMailLight mail = (DBMailLight) tableCtr.getTableDataModel().getObject(i);
                // reload the message
                mail = mailManager.getMessageByKey(mail.getKey());
                boolean deleteMetaMail = outbox && !StringHelper.containsNonWhitespace(metaId);
                mailManager.delete(mail, getIdentity(), deleteMetaMail);
            // Do not remove from model to prevent concurrent modification
            // exception, instead just reload model afterwards
            }
            reloadModel();
        }
    } else {
        super.event(ureq, source, event);
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) MailerResult(org.olat.core.util.mail.MailerResult) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) BitSet(java.util.BitSet) DBMailLight(org.olat.core.util.mail.model.DBMailLight) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 4 with DBMailRecipient

use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.

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 5 with DBMailRecipient

use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.

the class MailManagerImpl method deleteMail.

private void deleteMail(DBMailLight mail, Identity identity, boolean forceRemoveRecipient) {
    boolean delete = true;
    List<DBMailRecipient> updates = new ArrayList<DBMailRecipient>();
    if (mail.getFrom() != null && mail.getFrom().getRecipient() != null) {
        if (identity.equalsByPersistableKey(mail.getFrom().getRecipient())) {
            DBMailRecipient from = mail.getFrom();
            from.setDeleted(Boolean.TRUE);
            if (forceRemoveRecipient) {
                from.setRecipient(null);
            }
            updates.add(from);
        }
        if (mail.getFrom().getDeleted() != null) {
            delete &= mail.getFrom().getDeleted().booleanValue();
        }
    }
    for (DBMailRecipient recipient : mail.getRecipients()) {
        if (recipient == null)
            continue;
        if (recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
            recipient.setDeleted(Boolean.TRUE);
            if (forceRemoveRecipient) {
                recipient.setRecipient(null);
            }
            updates.add(recipient);
        }
        if (recipient.getDeleted() != null) {
            delete &= recipient.getDeleted().booleanValue();
        }
    }
    if (delete) {
        Set<String> paths = new HashSet<String>();
        // all marked as deleted -> delete the mail
        List<DBMailAttachment> attachments = getAttachments(mail);
        for (DBMailAttachment attachment : attachments) {
            // reload from the hibernate session
            mail = attachment.getMail();
            dbInstance.deleteObject(attachment);
            if (StringHelper.containsNonWhitespace(attachment.getPath())) {
                paths.add(attachment.getPath());
            }
        }
        dbInstance.deleteObject(mail);
        // try to remove orphans file
        for (String path : paths) {
            int count = countAttachment(path);
            if (count == 0) {
                VFSItem item = mailModule.getRootForAttachments().resolve(path);
                if (item instanceof VFSLeaf) {
                    ((VFSLeaf) item).delete();
                }
            }
        }
    } else {
        for (DBMailRecipient update : updates) {
            dbInstance.updateObject(update);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) DBMailAttachment(org.olat.core.util.mail.model.DBMailAttachment) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient) HashSet(java.util.HashSet)

Aggregations

DBMailRecipient (org.olat.core.util.mail.model.DBMailRecipient)22 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)4 Address (javax.mail.Address)4 InternetAddress (javax.mail.internet.InternetAddress)4 IdentityImpl (org.olat.basesecurity.IdentityImpl)4 Identity (org.olat.core.id.Identity)4 MailerResult (org.olat.core.util.mail.MailerResult)4 DBMailAttachment (org.olat.core.util.mail.model.DBMailAttachment)4 DBMailLight (org.olat.core.util.mail.model.DBMailLight)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BitSet (java.util.BitSet)2 Date (java.util.Date)2 Set (java.util.Set)2 Adler32 (java.util.zip.Adler32)2 AddressException (javax.mail.internet.AddressException)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2