Search in sources :

Example 6 with DBMailRecipient

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

the class MailDataModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    DBMailLight mail = filteredMails == null ? mails.get(row) : filteredMails.get(row);
    Columns[] cols = Columns.values();
    if (col < cols.length) {
        switch(cols[col]) {
            case read:
                {
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
                            return recipient.getRead();
                        }
                    }
                    return Boolean.FALSE;
                }
            case marked:
                {
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
                            return recipient.getMarked();
                        }
                    }
                    return Boolean.FALSE;
                }
            case context:
                {
                    String businessPath = mail.getContext().getBusinessPath();
                    if (StringHelper.containsNonWhitespace(businessPath)) {
                        String contextName = bpToContexts.get(businessPath);
                        if (StringHelper.containsNonWhitespace(businessPath) && StringHelper.containsNonWhitespace(contextName)) {
                            return new ContextPair(contextName, businessPath);
                        }
                    }
                    return null;
                }
            case subject:
                return mail.getSubject();
            case receivedDate:
            case sendDate:
                {
                    return mail.getCreationDate();
                }
            case from:
                {
                    DBMailRecipient from = mail.getFrom();
                    if (from != null) {
                        if (from.getRecipient() != null) {
                            return from.getRecipient();
                        } else if (StringHelper.containsNonWhitespace(from.getGroup())) {
                            return from.getGroup();
                        } else {
                            return UserManager.getInstance().getUserDisplayEmail(from.getEmailAddress(), translator.getLocale());
                        }
                    }
                    return "-";
                }
            case recipients:
                {
                    if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                        return translator.translate("mail.from.miscellaneous");
                    }
                    StringBuilder sb = new StringBuilder();
                    Set<String> groupSet = new HashSet<>();
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getGroup() != null) {
                            String group = recipient.getGroup();
                            if (!groupSet.contains(group)) {
                                if (sb.length() > 0)
                                    sb.append(", ");
                                sb.append(group);
                                groupSet.add(group);
                            }
                        }
                    }
                    return sb.toString();
                }
        }
    }
    return mail;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DBMailLight(org.olat.core.util.mail.model.DBMailLight) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 7 with DBMailRecipient

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

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)

Example 8 with DBMailRecipient

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

the class MailManagerImpl method toggleMarked.

@Override
public DBMailLight toggleMarked(DBMailLight mail, Identity identity) {
    Boolean marked = null;
    for (DBMailRecipient recipient : mail.getRecipients()) {
        if (recipient == null)
            continue;
        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
            if (marked == null) {
                marked = recipient.getMarked() == null ? Boolean.FALSE : recipient.getMarked();
            }
            recipient.setMarked(marked.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
            dbInstance.updateObject(recipient);
        }
    }
    return mail;
}
Also used : DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 9 with DBMailRecipient

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

the class MailDataModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    DBMailLight mail = filteredMails == null ? mails.get(row) : filteredMails.get(row);
    Columns[] cols = Columns.values();
    if (col < cols.length) {
        switch(cols[col]) {
            case read:
                {
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
                            return recipient.getRead();
                        }
                    }
                    return Boolean.FALSE;
                }
            case marked:
                {
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
                            return recipient.getMarked();
                        }
                    }
                    return Boolean.FALSE;
                }
            case context:
                {
                    String businessPath = mail.getContext().getBusinessPath();
                    if (StringHelper.containsNonWhitespace(businessPath)) {
                        String contextName = bpToContexts.get(businessPath);
                        if (StringHelper.containsNonWhitespace(businessPath) && StringHelper.containsNonWhitespace(contextName)) {
                            return new ContextPair(contextName, businessPath);
                        }
                    }
                    return null;
                }
            case subject:
                return mail.getSubject();
            case receivedDate:
            case sendDate:
                {
                    return mail.getCreationDate();
                }
            case from:
                {
                    DBMailRecipient from = mail.getFrom();
                    if (from != null) {
                        if (from.getRecipient() != null) {
                            return from.getRecipient();
                        } else if (StringHelper.containsNonWhitespace(from.getGroup())) {
                            return from.getGroup();
                        } else {
                            return UserManager.getInstance().getUserDisplayEmail(from.getEmailAddress(), translator.getLocale());
                        }
                    }
                    return "-";
                }
            case recipients:
                {
                    if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                        return translator.translate("mail.from.miscellaneous");
                    }
                    StringBuilder sb = new StringBuilder();
                    Set<String> groupSet = new HashSet<>();
                    for (DBMailRecipient recipient : mail.getRecipients()) {
                        if (recipient != null && recipient.getGroup() != null) {
                            String group = recipient.getGroup();
                            if (!groupSet.contains(group)) {
                                if (sb.length() > 0)
                                    sb.append(", ");
                                sb.append(group);
                                groupSet.add(group);
                            }
                        }
                    }
                    return sb.toString();
                }
        }
    }
    return mail;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DBMailLight(org.olat.core.util.mail.model.DBMailLight) DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

Example 10 with DBMailRecipient

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

the class MailManagerImpl method toggleMarked.

@Override
public DBMailLight toggleMarked(DBMailLight mail, Identity identity) {
    Boolean marked = null;
    for (DBMailRecipient recipient : mail.getRecipients()) {
        if (recipient == null)
            continue;
        if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
            if (marked == null) {
                marked = recipient.getMarked() == null ? Boolean.FALSE : recipient.getMarked();
            }
            recipient.setMarked(marked.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
            dbInstance.updateObject(recipient);
        }
    }
    return mail;
}
Also used : DBMailRecipient(org.olat.core.util.mail.model.DBMailRecipient)

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