Search in sources :

Example 16 with DBMailLight

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

the class MailManagerTest method testDeleteUserData_groupedMail.

@Test
public void testDeleteUserData_groupedMail() {
    // send a mail to three ids
    String metaId = UUID.randomUUID().toString();
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
    Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
    Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
    Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
    ContactList ccs = new ContactList("unit-test-cc");
    ccs.add(toId_1);
    ccs.add(toId_2);
    ccs.add(toId_3);
    ccs.add(fromId);
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setContactList(ccs);
    bundle.setMetaId(metaId);
    bundle.setContent("Hello delList", "Content of delList");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // delete the 4 users datas
    mailBoxExtension.deleteUserData(toId_1, "lalala", null);
    mailBoxExtension.deleteUserData(toId_2, "lalala", null);
    mailBoxExtension.deleteUserData(toId_3, "lalala", null);
    mailBoxExtension.deleteUserData(fromId, "lalala", null);
    dbInstance.commitAndCloseSession();
    // check inbox / outbox
    List<DBMailLight> deletedMails_1 = mailManager.getInbox(toId_1, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_1);
    Assert.assertTrue(deletedMails_1.isEmpty());
    List<DBMailLight> deletedMails_2 = mailManager.getInbox(toId_2, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_2);
    Assert.assertTrue(deletedMails_2.isEmpty());
    List<DBMailLight> deletedMails_3 = mailManager.getInbox(toId_3, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_3);
    Assert.assertTrue(deletedMails_3.isEmpty());
    List<DBMailLight> deletedMails_4 = mailManager.getOutbox(fromId, 0, -1, true);
    Assert.assertNotNull(deletedMails_4);
    Assert.assertTrue(deletedMails_4.isEmpty());
    // check mail by meta id
    List<DBMailLight> deletedMails = mailManager.getEmailsByMetaId(metaId);
    Assert.assertNotNull(deletedMails);
    Assert.assertTrue(deletedMails.isEmpty());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 17 with DBMailLight

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

the class MailNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    if (!mailModule.isInternSystem()) {
        return notificationsManager.getNoSubscriptionInfo();
    }
    String realMail = subscriber.getIdentity().getUser().getPreferences().getReceiveRealMail();
    if ("true".equals(realMail)) {
        // receive real e-mails
        return notificationsManager.getNoSubscriptionInfo();
    } else if (!StringHelper.containsNonWhitespace(realMail) && mailModule.isReceiveRealMailUserDefaultSetting()) {
        // user has no settings, check the default setting
        return notificationsManager.getNoSubscriptionInfo();
    }
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            List<DBMailLight> inbox = mailManager.getInbox(subscriber.getIdentity(), Boolean.TRUE, Boolean.FALSE, compareDate, 0, -1);
            if (!inbox.isEmpty()) {
                Translator translator = Util.createPackageTranslator(MailModule.class, locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("mail.notification.type"), "o_co_icon"), null);
                for (DBMailLight mail : inbox) {
                    String subject = mail.getSubject();
                    String businessPath = "[Inbox:0][Inbox:0][DBMail:" + mail.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    SubscriptionListItem subListItem = new SubscriptionListItem(subject, urlToSend, businessPath, mail.getCreationDate(), "o_co_icon");
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } catch (Exception ex) {
            logError("", ex);
        }
    }
    if (si == null) {
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) DBMailLight(org.olat.core.util.mail.model.DBMailLight)

Example 18 with DBMailLight

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

the class MailManagerTest method testSend_BCC.

@Test
public void testSend_BCC() {
    // send a mail to three ids
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
    Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
    Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
    Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
    ContactList ccs = new ContactList("unit-test-cc");
    ccs.add(toId_1);
    ccs.add(toId_2);
    ccs.add(toId_3);
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setContactList(ccs);
    bundle.setContent("Hello ccList", "Content of ccList");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the inbox of 1
    List<DBMailLight> incomingsMails = mailManager.getInbox(toId_1, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails);
    Assert.assertEquals(1, incomingsMails.size());
    DBMailLight incomingMail = incomingsMails.get(0);
    Assert.assertNotNull(incomingMail);
    Assert.assertEquals("Hello ccList", incomingMail.getSubject());
    // retrieve the inbox of 2
    List<DBMailLight> incomingsMails_2 = mailManager.getInbox(toId_2, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails_2);
    Assert.assertEquals(1, incomingsMails_2.size());
    Assert.assertEquals(incomingMail, incomingsMails_2.get(0));
    // retrieve the inbox of 3
    List<DBMailLight> incomingsMails_3 = mailManager.getInbox(toId_2, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingsMails_3);
    Assert.assertEquals(1, incomingsMails_3.size());
    Assert.assertEquals(incomingMail, incomingsMails_3.get(0));
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 19 with DBMailLight

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

the class MailManagerTest method testGetOutbox.

@Test
public void testGetOutbox() {
    // send a mail
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-5-" + UUID.randomUUID().toString());
    Identity toId = JunitTestHelper.createAndPersistIdentityAsUser("mail-6-" + UUID.randomUUID().toString());
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setToId(toId);
    bundle.setContent("Hello outbox", "Content of outbox");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the outbox of toId (with lazy loading)
    List<DBMailLight> sendedMails = mailManager.getOutbox(fromId, 0, -1, false);
    Assert.assertNotNull(sendedMails);
    Assert.assertEquals(1, sendedMails.size());
    DBMailLight sendedMail = sendedMails.get(0);
    Assert.assertNotNull(sendedMail);
    Assert.assertEquals("Hello outbox", sendedMail.getSubject());
    dbInstance.commitAndCloseSession();
    // retrieve the outbox of toId (with fetch)
    List<DBMailLight> sendedMailsWithFetch = mailManager.getOutbox(fromId, 0, -1, true);
    Assert.assertNotNull(sendedMailsWithFetch);
    Assert.assertEquals(1, sendedMailsWithFetch.size());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 20 with DBMailLight

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

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)

Aggregations

DBMailLight (org.olat.core.util.mail.model.DBMailLight)22 MailerResult (org.olat.core.util.mail.MailerResult)14 Test (org.junit.Test)12 Identity (org.olat.core.id.Identity)12 MailBundle (org.olat.core.util.mail.MailBundle)12 HashSet (java.util.HashSet)6 ContactList (org.olat.core.util.mail.ContactList)4 DBMailRecipient (org.olat.core.util.mail.model.DBMailRecipient)4 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)2 ShortName (org.olat.core.gui.ShortName)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2