From 2a7dc6b797628cab55356c6dc41df46fde60a5bd Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 30 Nov 2012 16:09:16 +0100 Subject: [PATCH] OO-436: enhance the method which check if a real email must be send. The method test the single CC too. --- .../core/util/mail/manager/MailManager.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/olat/core/util/mail/manager/MailManager.java b/src/main/java/org/olat/core/util/mail/manager/MailManager.java index a86147b3a72..cd20e7bcfde 100644 --- a/src/main/java/org/olat/core/util/mail/manager/MailManager.java +++ b/src/main/java/org/olat/core/util/mail/manager/MailManager.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; @@ -49,6 +50,7 @@ import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.mail.util.ByteArrayDataSource; +import org.apache.commons.io.IOUtils; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBQuery; import org.olat.core.commons.persistence.PersistentObject; @@ -525,7 +527,7 @@ public class MailManager extends BasicManager { result = new MailerResult(); } - boolean makeRealMail = makeRealMail(toId, ccLists, bccLists); + boolean makeRealMail = makeRealMail(toId, cc, ccLists, bccLists); Address fromAddress = null; List<Address> toAddress = new ArrayList<Address>(); List<Address> ccAddress = new ArrayList<Address>(); @@ -666,9 +668,10 @@ public class MailManager extends BasicManager { data.setMimetype(WebappHelper.getMimeType(attachment.getName())); data.setMail(mail); + InputStream fis = null; try { byte[] datas = new byte[(int)attachment.length()]; - FileInputStream fis = new FileInputStream(attachment); + fis = new FileInputStream(attachment); fis.read(datas); data.setDatas(datas); dbInstance.saveObject(data); @@ -676,6 +679,8 @@ public class MailManager extends BasicManager { logError("File attachment not found: " + attachment, e); } catch (IOException e) { logError("Error with file attachment: " + attachment, e); + } finally { + IOUtils.closeQuietly(fis); } } } @@ -753,16 +758,20 @@ public class MailManager extends BasicManager { } } - private boolean makeRealMail(Identity toId, List<ContactList> ccLists, List<ContactList> bccLists) { + private boolean makeRealMail(Identity toId, Identity cc, List<ContactList> ccLists, List<ContactList> bccLists) { //need real mail to??? boolean makeRealMail = false; // can occur on self-registration - if (toId == null && ccLists == null && bccLists == null) return true; + if (toId == null && cc == null && ccLists == null && bccLists == null) return true; if(toId != null) { makeRealMail |= wantRealMailToo(toId); } + if(cc != null) { + makeRealMail |= wantRealMailToo(cc); + } + //add bcc recipients if(bccLists != null && !bccLists.isEmpty()) { for(ContactList contactList:bccLists) { -- GitLab