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(" <");
sb.append(UserManager.getInstance().getUserDisplayEmail(fromIdentity, getLocale()));
sb.append("> ");
}
}
}
sb.append("</li></ul>");
return sb.toString();
}
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(" <");
sb.append(UserManager.getInstance().getUserDisplayEmail(recipient.getRecipient(), getLocale()));
sb.append(">");
}
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("<");
sb.append(UserManager.getInstance().getUserDisplayEmail(recipient.getEmailAddress(), getLocale()));
sb.append("></li>");
groupCounter++;
}
}
}
sb.append("</ul>");
return sb.toString();
}
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);
}
}
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);
}
}
}
}
}
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);
}
}
}
Aggregations