From 4e94a6e326b8000c118633ea6fbc8ecedf8bafa0 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Mon, 7 Apr 2025 10:18:10 -0400 Subject: [PATCH 1/4] SAK-51126 Remove legacy SamigoEmailService and related code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SamigoEmailService, EmailBean, and related email functionality was a legacy feature that has been replaced by the simpler mailto links approach in the current UI. This commit removes these unused components since they are no longer referenced in the UI flow. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../sakaiproject/jsf/util/SamigoJsfTool.java | 10 +- .../assessment/ui/bean/util/EmailBean.java | 339 ---------------- .../evaluation/TotalScoreListener.java | 8 +- .../ui/listener/util/EmailListener.java | 43 +- .../assessment/util/SamigoEmailService.java | 379 ------------------ .../jsf/evaluation/confirmEmailSent.jsp | 54 --- .../webapp/jsf/evaluation/createNewEmail.jsp | 105 ----- .../webapp/jsf/evaluation/emailAttachment.jsp | 58 --- .../src/webapp/jsf/evaluation/emailError.jsp | 53 --- 9 files changed, 9 insertions(+), 1040 deletions(-) delete mode 100644 samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/util/EmailBean.java delete mode 100644 samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java delete mode 100644 samigo/samigo-app/src/webapp/jsf/evaluation/confirmEmailSent.jsp delete mode 100644 samigo/samigo-app/src/webapp/jsf/evaluation/createNewEmail.jsp delete mode 100644 samigo/samigo-app/src/webapp/jsf/evaluation/emailAttachment.jsp delete mode 100644 samigo/samigo-app/src/webapp/jsf/evaluation/emailError.jsp diff --git a/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java b/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java index 1d16fd103a59..97841e8c838a 100644 --- a/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java +++ b/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java @@ -59,7 +59,6 @@ import org.sakaiproject.tool.assessment.ui.bean.evaluation.StudentScoresBean; import org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean; import org.sakaiproject.tool.assessment.ui.bean.authz.AuthorizationBean; -import org.sakaiproject.tool.assessment.ui.bean.util.EmailBean; import org.sakaiproject.tool.assessment.ui.listener.evaluation.StudentScoreListener; import org.sakaiproject.tool.assessment.ui.listener.evaluation.SubmissionNavListener; @@ -331,14 +330,7 @@ else if (target.indexOf("/jsf/author/publishedSettings") > -1 toolSession.removeAttribute("SENT_TO_FILEPICKER_HELPER"); } - // case 4: create new mail, then set - // emailBean.attachmentList = filepicker list - else if (target.indexOf("/jsf/evaluation/createNewEmail") > -1 - && ("true").equals(toolSession.getAttribute("SENT_TO_FILEPICKER_HELPER"))) { - EmailBean bean = (EmailBean) ContextUtil.lookupBeanFromExternalServlet("email", req, res); - bean.prepareAttachment(); - toolSession.removeAttribute("SENT_TO_FILEPICKER_HELPER"); - } + // case 4: removed legacy email functionality else if (target.indexOf("/jsf/evaluation/questionScore") > -1 && ("true").equals(toolSession.getAttribute("SENT_TO_FILEPICKER_HELPER"))) { diff --git a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/util/EmailBean.java b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/util/EmailBean.java deleted file mode 100644 index 6f5d84c0a88c..000000000000 --- a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/util/EmailBean.java +++ /dev/null @@ -1,339 +0,0 @@ -/********************************************************************************** - * $URL$ - * $Id$ - *********************************************************************************** - * - * Copyright (c) 2006, 2007, 2008, 2009 The Sakai Foundation - * - * Licensed under the Educational Community License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.opensource.org/licenses/ECL-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - **********************************************************************************/ - -package org.sakaiproject.tool.assessment.ui.bean.util; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import javax.faces.application.FacesMessage; -import javax.faces.bean.ManagedBean; -import javax.faces.bean.SessionScoped; -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; - -import lombok.extern.slf4j.Slf4j; - -import org.sakaiproject.component.cover.ServerConfigurationService; -import org.sakaiproject.content.api.ContentResource; -import org.sakaiproject.content.api.FilePickerHelper; -import org.sakaiproject.entity.api.Reference; -import org.sakaiproject.entity.cover.EntityManager; -import org.sakaiproject.event.cover.EventTrackingService; -import org.sakaiproject.exception.IdUnusedException; -import org.sakaiproject.exception.PermissionException; -import org.sakaiproject.exception.TypeException; -import org.sakaiproject.samigo.util.SamigoConstants; -import org.sakaiproject.tool.api.ToolSession; -import org.sakaiproject.tool.assessment.data.dao.assessment.AttachmentData; -import org.sakaiproject.tool.assessment.data.ifc.assessment.AttachmentIfc; -import org.sakaiproject.tool.assessment.facade.AgentFacade; -import org.sakaiproject.tool.assessment.services.assessment.AssessmentService; -import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil; -import org.sakaiproject.tool.assessment.util.SamigoEmailService; -import org.sakaiproject.tool.cover.SessionManager; - -/* For util Email backing bean. */ -@Slf4j -@ManagedBean(name="email") -@SessionScoped -public class EmailBean implements Serializable { - - private String fromName; - - private String fromEmailAddress; - - private String toName; - - private String toEmailAddress; - - private String toFirstName; - - private String assessmentName; - - private String subject; - - private String ccMe = "no"; - - private String message; - - private List attachmentList; - - private boolean hasAttachment = false; - - private String outcome; - - private HashMap resourceHash = new HashMap(); - - /** - * Creates a new TotalScoresBean object. - */ - public EmailBean() { - log.debug("Creating a new EmailBean"); - } - - public String getFromName() { - return fromName; - } - - public void setFromName(String fromName) { - this.fromName = fromName; - } - - public String getFromEmailAddress() { - return fromEmailAddress; - } - - public void setFromEmailAddress(String fromEmailAddress) { - this.fromEmailAddress = fromEmailAddress; - } - - public String getToName() { - return toName; - } - - public void setToName(String toName) { - this.toName = toName; - } - - public String getToEmailAddress() { - return toEmailAddress; - } - - public void setToEmailAddress(String toEmailAddress) { - this.toEmailAddress = toEmailAddress; - } - - public String getToFirstName() { - return toFirstName; - } - - public void setToFirstName(String toFirstName) { - this.toFirstName = toFirstName; - } - - public String getAssessmentName() { - return assessmentName; - } - - public void setAssessmentName(String assessmentName) { - this.assessmentName = assessmentName; - } - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - public String getCcMe() { - return ccMe; - } - - public void setCcMe(String ccMe) { - this.ccMe = ccMe; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public List getAttachmentList() { - return attachmentList; - } - - public void setAttachmentList(List attachmentList) { - this.attachmentList = attachmentList; - } - - public boolean getHasAttachment() { - return this.hasAttachment; - } - - public void setHasAttachment(boolean hasAttachment) { - this.hasAttachment = hasAttachment; - } - - public String getOutcome() { - return outcome; - } - - public void setOutcome(String outcome) { - this.outcome = outcome; - } - public void prepareAttachment() { - ToolSession session = SessionManager.getCurrentToolSession(); - ArrayList newAttachmentList = new ArrayList(); - if (session.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) { - List refs = (List) session.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS); - Reference ref; - if (refs.size() == 0) { - hasAttachment = false; - } - else { - HashMap map = getResourceIdHash(attachmentList); - for (int i = 0; i < refs.size(); i++) { - ref = (Reference) refs.get(i); - String resourceId = ref.getId(); - if (map.get(resourceId) == null) { - AssessmentService assessmentService = new AssessmentService(); - AttachmentData attach = assessmentService.createEmailAttachment( - resourceId, - ref.getProperties().getProperty(ref.getProperties().getNamePropDisplayName()), - ServerConfigurationService.getServerUrl()); - - newAttachmentList.add(attach); - - } - else { - newAttachmentList.add((AttachmentData)map.get(resourceId)); - map.remove(resourceId); - } - - hasAttachment = true; - } - } - session.removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS); - session.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL); - } - else { - hasAttachment = false; - } - attachmentList = newAttachmentList; - } - - - private HashMap getResourceIdHash(List attachmentList) { - HashMap map = new HashMap(); - if (attachmentList != null) { - Iterator iter = attachmentList.iterator(); - while (iter.hasNext()) { - AttachmentData attach = (AttachmentData) iter.next(); - map.put(attach.getResourceId(), attach); - } - } - return map; - } - - public String addAttachmentsRedirect() { - try { - List filePickerList = new ArrayList(); - if (attachmentList != null){ - filePickerList = prepareReferenceList(attachmentList); - } - log.debug("**filePicker list="+filePickerList.size()); - ToolSession currentToolSession = SessionManager.getCurrentToolSession(); - currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList); - ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); - context.redirect("sakai.filepicker.helper/tool"); - } - catch(Exception e){ - log.error("fail to redirect to attachment page: " + e.getMessage()); - } - return "email"; - } - - private List prepareReferenceList(List attachmentList) { - List list = new ArrayList(); - for (int i = 0; i < attachmentList.size(); i++) { - ContentResource cr = null; - AttachmentIfc attach = (AttachmentIfc) attachmentList.get(i); - try { - cr = AssessmentService.getContentHostingService().getResource(attach.getResourceId()); - } catch (PermissionException e) { - log.warn("PermissionException from ContentHostingService:" - + e.getMessage()); - } catch (IdUnusedException e) { - log.warn("IdUnusedException from ContentHostingService:" - + e.getMessage()); - } catch (TypeException e) { - log.warn("TypeException from ContentHostingService:" - + e.getMessage()); - } - if (cr != null) { - if (this.resourceHash == null) { - this.resourceHash = new HashMap(); - } - this.resourceHash.put(attach.getResourceId(), cr); - Reference ref = EntityManager.newReference(cr.getReference()); - if (ref != null) { - list.add(ref); - } - } - } - return list; - } - - public HashMap getResourceHash() { - return resourceHash; - } - - public void setResourceHash(HashMap resourceHash) - { - this.resourceHash = resourceHash; - } - - public String send() { - log.debug("send()"); - log.debug("fromName: " + fromName); - log.debug("fromEmailAddress: " + fromEmailAddress); - log.debug("toName: " + toName); - log.debug("toEmailAddress: " + toEmailAddress); - log.debug("subject: " + subject); - log.debug("ccMe: " + ccMe); - log.debug("message: " + message); - - SamigoEmailService samigoEmailService = new SamigoEmailService( - fromName, fromEmailAddress, toName, toEmailAddress, ccMe, - subject, message); - String result = samigoEmailService.send(); - - if ("send".equals(result)) { - String msgSent = ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.EvaluationMessages","sent_email_confirmation"); - FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(msgSent)); - EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_EMAIL, "siteId=" + AgentFacade.getCurrentSiteId() + ", Email sent ok: toName=" + toName + ", toEmail=" + toEmailAddress, true)); - return "confirmEmailSent"; - } - else { - String msgError = ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.EvaluationMessages","sent_email_error"); - FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(msgError)); - EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_EMAIL, "siteId=" + AgentFacade.getCurrentSiteId() + ", Email sent error: toName=" + toName + ", toEmail=" + toEmailAddress, true)); - return "emailError"; - } - } - - public void cancel() { - log.debug("cancel"); - setMessage(null); - setAttachmentList(null); - setHasAttachment(false); - } - -} diff --git a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/TotalScoreListener.java b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/TotalScoreListener.java index b3800bf244a1..d3345714fc42 100755 --- a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/TotalScoreListener.java +++ b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/TotalScoreListener.java @@ -77,7 +77,6 @@ import org.sakaiproject.tool.assessment.ui.bean.evaluation.QuestionScoresBean; import org.sakaiproject.tool.assessment.ui.bean.evaluation.SubmissionStatusBean; import org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean; -import org.sakaiproject.tool.assessment.ui.bean.util.EmailBean; import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil; import org.sakaiproject.tool.assessment.util.BeanSort; import org.sakaiproject.user.api.User; @@ -124,7 +123,6 @@ public void processAction(ActionEvent ae) throws QuestionScoresBean questionbean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores"); HistogramScoresBean histobean = (HistogramScoresBean) ContextUtil.lookupBean("histogramScores"); SubmissionStatusBean submissionbean = (SubmissionStatusBean) ContextUtil.lookupBean("submissionStatus"); - EmailBean emailBean = (EmailBean) ContextUtil.lookupBean("email"); // we probably want to change the poster to be consistent String publishedId = ContextUtil.lookupParam("publishedId"); @@ -166,12 +164,8 @@ public void processAction(ActionEvent ae) throws sb.append(" "); sb.append(agent.getLastName()); bean.setGraderName(sb.toString()); - emailBean.setFromName(agent.getEmail()); - // Set from email here. We need it to decide if the Email link should be displayed or not. - // (if from email is null, we don't display the Email link) - // as well. + // Set grader email info to be used to determine if mailto links should be shown bean.setGraderEmailInfo(agent.getEmail()); - emailBean.setFromEmailAddress(agent.getEmail()); // checking for permission first FacesContext context = FacesContext.getCurrentInstance(); diff --git a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java index f703521baf5e..56a1fbc423dc 100644 --- a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java +++ b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java @@ -27,49 +27,20 @@ import lombok.extern.slf4j.Slf4j; -import org.sakaiproject.tool.assessment.facade.AgentFacade; -import org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean; -import org.sakaiproject.tool.assessment.ui.bean.util.EmailBean; - +/** + * Deprecated class for the legacy email functionality that has been replaced by mailto links. + * Maintained as a placeholder for compatibility. + */ @Slf4j public class EmailListener implements ActionListener { /** - * Standard process action method. + * Legacy email action listener - no longer used * - * @param ae - * ActionEvent + * @param ae ActionEvent * @throws AbortProcessingException */ public void processAction(ActionEvent ae) throws AbortProcessingException { - log.debug("Email Action Listener."); - EmailBean emailBean = (EmailBean) ContextUtil.lookupBean("email"); - TotalScoresBean totalScoreBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores"); - - emailBean.setMessage(null); - emailBean.setAttachmentList(null); - emailBean.setHasAttachment(false); - emailBean.setCcMe("no"); - - // From Name and email are set in TotalScoreListener - - // To - String toUserId = ContextUtil.lookupParam("toUserId"); - AgentFacade agent = new AgentFacade(toUserId); - String toFirstName = agent.getFirstName(); - String toName = toFirstName + " " + agent.getLastName(); - String toEmailAddress = agent.getEmail(); - emailBean.setToFirstName(toFirstName); - emailBean.setToName(toName); - emailBean.setToEmailAddress(toEmailAddress); - - // AssessmentName - emailBean.setAssessmentName(totalScoreBean.getAssessmentName()); - - // Subject - StringBuilder sb = new StringBuilder(totalScoreBean.getAssessmentName()); - sb.append(" "); - sb.append(ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.EvaluationMessages", "feedback")); - emailBean.setSubject(sb.toString()); + log.debug("Email Action Listener - deprecated functionality"); } } diff --git a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java deleted file mode 100644 index dd4f0d715aee..000000000000 --- a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/util/SamigoEmailService.java +++ /dev/null @@ -1,379 +0,0 @@ -/********************************************************************************** - * $URL$ - * $Id$ - *********************************************************************************** - * - * Copyright (c) 2006, 2007, 2008, 2009 The Sakai Foundation - * - * Licensed under the Educational Community License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.opensource.org/licenses/ECL-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - **********************************************************************************/ - -package org.sakaiproject.tool.assessment.util; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.Vector; - -import javax.activation.DataHandler; -import javax.activation.FileDataSource; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Multipart; -import javax.mail.SendFailedException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.sakaiproject.component.cover.ServerConfigurationService; -import org.sakaiproject.content.api.ContentResource; -import org.sakaiproject.exception.IdUnusedException; -import org.sakaiproject.exception.PermissionException; -import org.sakaiproject.exception.ServerOverloadException; -import org.sakaiproject.exception.TypeException; -import org.sakaiproject.tool.assessment.data.dao.assessment.AttachmentData; -import org.sakaiproject.tool.assessment.services.assessment.AssessmentService; -import org.sakaiproject.tool.assessment.ui.bean.util.EmailBean; -import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil; - -/** - * The ItemService calls persistent service locator to reach the - * manager on the back end. - */ -@Slf4j -public class SamigoEmailService { - - private String fromName; - private String fromEmailAddress; - private String toName; - private String toEmailAddress; - private ArrayList toEmailAddressList; - private String ccMe; - private String subject; - private String message; - private String smtpServer; - private String smtpPort; - private String prefixedPath; - - /** - * Creates a new SamigoEmailService object. - */ - public SamigoEmailService(String fromName, String fromEmailAddress, String toName, String toEmailAddress, - ArrayList toEmailAddressList, String ccMe, String subject, String message) { - this.fromName = fromName; - this.fromEmailAddress = fromEmailAddress; - this.toName = toName; - this.toEmailAddress = toEmailAddress; - this.toEmailAddressList = toEmailAddressList; - this.ccMe = ccMe; - this.subject = subject; - this.message = message; - this.smtpServer = ServerConfigurationService.getSmtpServer(); - this.smtpPort = ServerConfigurationService.getSmtpPort(); - this.prefixedPath = ServerConfigurationService.getString("samigo.email.prefixedPath"); - } - - public SamigoEmailService(String fromName, String fromEmailAddress, - String toName, String toEmailAddress, String ccMe, String subject, String message) { - this(fromName, fromEmailAddress, toName, toEmailAddress, null, ccMe, subject, message); - } - - public SamigoEmailService(String fromEmailAddress, ArrayList toEmailAddressList, String ccMe, String subject, String message) { - this(null, fromEmailAddress, null, null, toEmailAddressList, ccMe, subject, message); - } - - // Not sure if we are going to obsolete/change this email flow. I keep this here and make a new one sendMail() - public String send() { - List attachmentList = null; - AttachmentData a = null; - try { - Properties props = new Properties(); - - // Server - if (StringUtils.isBlank(this.smtpServer)) { - log.error("Please configure the SMTP email server in your instance properties"); - return "error"; - } - props.setProperty("mail.smtp.host", this.smtpServer); - - // Port - if (StringUtils.isBlank(smtpPort)) { - log.warn("The SMTP port is not set. The default port 25 will be used."); - } else { - props.setProperty("mail.smtp.port", smtpPort); - } - - Session session; - session = Session.getInstance(props); - session.setDebug(true); - MimeMessage msg = new MimeMessage(session); - - InternetAddress fromIA = new InternetAddress(fromEmailAddress, fromName); - msg.setFrom(fromIA); - InternetAddress[] toIA = { new InternetAddress(toEmailAddress, toName) }; - msg.setRecipients(Message.RecipientType.TO, toIA); - - if ("yes".equals(ccMe)) { - InternetAddress[] ccIA = { new InternetAddress(fromEmailAddress, fromName) }; - msg.setRecipients(Message.RecipientType.CC, ccIA); - } - msg.setSubject(subject); - - EmailBean emailBean = (EmailBean) ContextUtil.lookupBean("email"); - attachmentList = emailBean.getAttachmentList(); - StringBuilder content = new StringBuilder(message); - ArrayList fileList = new ArrayList(); - ArrayList fileNameList = new ArrayList(); - if (attachmentList != null) { - if (prefixedPath == null || prefixedPath.equals("")) { - log.error("samigo.email.prefixedPath is not set"); - return "error"; - } - Iterator iter = attachmentList.iterator(); - while (iter.hasNext()) { - a = (AttachmentData) iter.next(); - if (a.getIsLink().booleanValue()) { - log.debug("send(): url"); - content.append("
\n\r"); - content.append("
"); // give a new line - content.append(a.getFilename()); - } - else { - log.debug("send(): file"); - File attachedFile = getAttachedFile(a.getResourceId()); - fileList.add(attachedFile); - fileNameList.add(a.getFilename()); - } - } - } - - Multipart multipart = new MimeMultipart(); - MimeBodyPart messageBodyPart = new MimeBodyPart(); - messageBodyPart.setContent(content.toString(), "text/html"); - multipart.addBodyPart(messageBodyPart); - msg.setContent(multipart); - - for (int i = 0; i < fileList.size(); i++) { - messageBodyPart = new MimeBodyPart(); - FileDataSource source = new FileDataSource((File)fileList.get(i)); - messageBodyPart.setDataHandler(new DataHandler(source)); - messageBodyPart.setFileName((String)fileNameList.get(i)); - multipart.addBodyPart(messageBodyPart); - } - msg.setContent(multipart); - - Transport.send(msg); - } catch (UnsupportedEncodingException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (MessagingException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (ServerOverloadException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (PermissionException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (IdUnusedException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (TypeException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } catch (IOException e) { - log.error("Exception throws from send()" + e.getMessage()); - return "error"; - } finally { - if (attachmentList != null) { - if (prefixedPath != null && !prefixedPath.equals("")) { - StringBuilder sbPrefixedPath; - Iterator iter = attachmentList.iterator(); - while (iter.hasNext()) { - sbPrefixedPath = new StringBuilder(prefixedPath); - sbPrefixedPath.append("/email_tmp/"); - a = (AttachmentData) iter.next(); - if (!a.getIsLink().booleanValue()) { - deleteAttachedFile(sbPrefixedPath.append(a.getResourceId()).toString()); - } - } - } - } - } - return "send"; - } - - public String sendMail() { - try { - Properties props = new Properties(); - - // Server - if (StringUtils.isBlank(this.smtpServer)) { - log.error("Please configure the SMTP email server in your instance properties"); - return "error"; - } - props.setProperty("mail.smtp.host", this.smtpServer); - - // Port - if (StringUtils.isBlank(this.smtpPort)) { - log.warn("The SMTP port is not set. The default port 25 will be used."); - } else { - props.setProperty("mail.smtp.port", smtpPort); - } - - props.put("mail.smtp.sendpartial", "true"); - - Session session = Session.getInstance(props, null); - session.setDebug(true); - MimeMessage msg = new MimeMessage(session); - - InternetAddress fromIA = new InternetAddress(fromEmailAddress, fromName); - msg.setFrom(fromIA); - - //msg.addHeaderLine("Subject: " + subject); - msg.setSubject(subject, "UTF-8"); - String noReplyEmailAddress = ServerConfigurationService.getSmtpFrom(); - msg.addHeaderLine("To: " + noReplyEmailAddress); - msg.setText(message, "UTF-8"); - msg.addHeaderLine("Content-Type: text/html"); - - ArrayList toIAList = new ArrayList(); - String email = ""; - Iterator iter = toEmailAddressList.iterator(); - while (iter.hasNext()) { - try { - email = (String) iter.next(); - toIAList.add(new InternetAddress(email)); - } catch (AddressException ae) { - log.error("invalid email address: " + email); - } - } - - InternetAddress[] toIA = new InternetAddress[toIAList.size()]; - int count = 0; - Iterator iter2 = toIAList.iterator(); - while (iter2.hasNext()) { - toIA[count++] = (InternetAddress) iter2.next(); - } - - try - { - Transport transport = session.getTransport("smtp"); - msg.saveChanges(); - transport.connect(); - - try { - transport.sendMessage(msg, toIA); - } - catch (SendFailedException e) - { - log.debug("SendFailedException: " + e); - return "error"; - } - catch (MessagingException e) - { - log.warn("1st MessagingException: " + e); - return "error"; - } - transport.close(); - } - catch (MessagingException e) - { - log.warn("2nd MessagingException:" + e); - return "error"; - } - - } catch (UnsupportedEncodingException ue) { - log.warn("UnsupportedEncodingException:" + ue); - - } catch (MessagingException me) { - log.warn("3rd MessagingException:" + me); - return "error"; - } - return "send"; - } - - private File getAttachedFile(String resourceId) throws PermissionException, IdUnusedException, TypeException, ServerOverloadException, IOException { - ContentResource cr = AssessmentService.getContentHostingService().getResource(resourceId); - log.debug("getAttachedFile(): resourceId = " + resourceId); - byte[] data = cr.getContent(); - StringBuilder sbPrefixedPath = new StringBuilder(prefixedPath); - sbPrefixedPath.append("/email_tmp/"); - sbPrefixedPath.append(resourceId); - String filename = sbPrefixedPath.toString().replace(" ", ""); - log.debug("getAttachedFile(): filename = " + filename); - String path = filename.substring(0, filename.lastIndexOf("/")); - log.debug("getAttachedFile(): path = " + path); - File dir = new File(path); - boolean success = dir.mkdirs(); - // Shouldn't come to here because resourceId is unique - if (!success) { - log.error("getAttachedFile(): File exists already! This should not heppen. Please check for resourceId."); - } - File file = new File(filename); - success = file.createNewFile(); - // Shouldn't come to here because resourceId is unique - if (!success) { - log.error("getAttachedFile(): File exists already! This should not heppen. Please check for resourceId."); - } - FileOutputStream fileOutputStream = null; - try { - fileOutputStream = new FileOutputStream(file); - fileOutputStream.write(data); - } catch (FileNotFoundException e) { - throw e; - } catch (IOException e) { - throw e; - } - finally { - if (fileOutputStream != null) { - fileOutputStream.close(); - } - } - return file; - } - - private void deleteAttachedFile(String filename) { - log.debug("deleteAttachedFile(): filename = " + filename); - // delete the file - String tunedFilename = filename.replace(" ", ""); - log.debug("deleteAttachedFile(): tunedFilename = " + tunedFilename); - File file = new File(tunedFilename); - boolean success = file.delete(); - if (!success) { - log.error("Fail to delete file: " + tunedFilename); - } - // delete the last directory - String directoryName = tunedFilename.substring(0, tunedFilename.lastIndexOf("/")); - log.debug("deleteAttachedFile(): directoryName = " + directoryName); - File dir = new File(directoryName); - success = dir.delete(); - if (!success) { - log.error("Fail to delete directory: " + directoryName); - } - } - -} diff --git a/samigo/samigo-app/src/webapp/jsf/evaluation/confirmEmailSent.jsp b/samigo/samigo-app/src/webapp/jsf/evaluation/confirmEmailSent.jsp deleted file mode 100644 index 7ceb16f82593..000000000000 --- a/samigo/samigo-app/src/webapp/jsf/evaluation/confirmEmailSent.jsp +++ /dev/null @@ -1,54 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> -<%@ taglib uri="http://sakaiproject.org/jsf2/sakai" prefix="sakai"%> -<%@ taglib uri="http://www.sakaiproject.org/samigo" prefix="samigo" %> - - - - - - - -<%= request.getAttribute("html.head") %> -<h:outputText value="#{evaluationMessages.sent}" /> - -"> -
-

- -

- -

- -

- - - -
- - - -
diff --git a/samigo/samigo-app/src/webapp/jsf/evaluation/createNewEmail.jsp b/samigo/samigo-app/src/webapp/jsf/evaluation/createNewEmail.jsp deleted file mode 100644 index 755ecf8d549a..000000000000 --- a/samigo/samigo-app/src/webapp/jsf/evaluation/createNewEmail.jsp +++ /dev/null @@ -1,105 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> -<%@ taglib uri="http://sakaiproject.org/jsf2/sakai" prefix="sakai"%> -<%@ taglib uri="http://www.sakaiproject.org/samigo" prefix="samigo" %> - - - - - - - -<%= request.getAttribute("html.head") %> - -<h:outputText value="#{evaluationMessages.title_create_new_email}#{evaluationMessages.colon} #{param.assessmentName} #{commonMessages.feedback}" rendered="#{param.fromEmailLinkClick == 'true'}"/> -<h:outputText value="#{evaluationMessages.title_create_new_email}#{evaluationMessages.colon} #{email.subject}" rendered="#{param.fromEmailLinkClick != 'true'}"/> - - -"> - -
- - -

- -

- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <%@ include file="/jsf/evaluation/emailAttachment.jsp" %> - - - - - - - - - - -
-
- - - -
diff --git a/samigo/samigo-app/src/webapp/jsf/evaluation/emailAttachment.jsp b/samigo/samigo-app/src/webapp/jsf/evaluation/emailAttachment.jsp deleted file mode 100644 index 91869c1f9868..000000000000 --- a/samigo/samigo-app/src/webapp/jsf/evaluation/emailAttachment.jsp +++ /dev/null @@ -1,58 +0,0 @@ - - -
- - - - <%@ include file="/jsf/shared/mimeicon.jsp" %> - - -      - - - - - - - - -      - - - - - - - - - - - - - - - -
- diff --git a/samigo/samigo-app/src/webapp/jsf/evaluation/emailError.jsp b/samigo/samigo-app/src/webapp/jsf/evaluation/emailError.jsp deleted file mode 100644 index 6308f27689f5..000000000000 --- a/samigo/samigo-app/src/webapp/jsf/evaluation/emailError.jsp +++ /dev/null @@ -1,53 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> -<%@ taglib uri="http://sakaiproject.org/jsf2/sakai" prefix="sakai"%> -<%@ taglib uri="http://www.sakaiproject.org/samigo" prefix="samigo" %> - - - - - - - -<%= request.getAttribute("html.head") %> -<h:outputText value="#{evaluationMessages.error}" /> - -"> - -
-

- -

- -

-

- - -
- - - -
From 0b35d1a81d8e1ebbbb3e7f929538e4b68e267d57 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Mon, 7 Apr 2025 10:19:40 -0400 Subject: [PATCH 2/4] SAK-51126 Remove EmailListener.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the remaining EmailListener class which is no longer used in the codebase. The email function has been superseded by the simpler mailto links in totalScores.jsp. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../ui/listener/util/EmailListener.java | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java diff --git a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java b/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java deleted file mode 100644 index 56a1fbc423dc..000000000000 --- a/samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/EmailListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/********************************************************************************** - * $URL: https://source.sakaiproject.org/svn/sam/trunk/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/TotalScoreListener.java $ - * $Id: EmailListener.java 17372 2006-10-25 02:27:49Z daisyf@stanford.edu $ - *********************************************************************************** - * - * Copyright (c) 2006, 2007, 2008 The Sakai Foundation - * - * Licensed under the Educational Community License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.osedu.org/licenses/ECL-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - **********************************************************************************/ - -package org.sakaiproject.tool.assessment.ui.listener.util; - -import javax.faces.event.AbortProcessingException; -import javax.faces.event.ActionEvent; -import javax.faces.event.ActionListener; - -import lombok.extern.slf4j.Slf4j; - -/** - * Deprecated class for the legacy email functionality that has been replaced by mailto links. - * Maintained as a placeholder for compatibility. - */ -@Slf4j -public class EmailListener implements ActionListener { - - /** - * Legacy email action listener - no longer used - * - * @param ae ActionEvent - * @throws AbortProcessingException - */ - public void processAction(ActionEvent ae) throws AbortProcessingException { - log.debug("Email Action Listener - deprecated functionality"); - } -} From eede5845de8cbec2381a7306a88df0c1be026c16 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Mon, 7 Apr 2025 10:20:07 -0400 Subject: [PATCH 3/4] SAK-51126 Remove email-related navigation rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the navigation rules for createNewEmail, confirmEmailSent, and emailError from faces-config.xml since the corresponding JSP files have been deleted. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../samigo-app/src/webapp/WEB-INF/faces-config.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/samigo/samigo-app/src/webapp/WEB-INF/faces-config.xml b/samigo/samigo-app/src/webapp/WEB-INF/faces-config.xml index 08d1687d34f3..7cd3c3331d58 100755 --- a/samigo/samigo-app/src/webapp/WEB-INF/faces-config.xml +++ b/samigo/samigo-app/src/webapp/WEB-INF/faces-config.xml @@ -827,22 +827,10 @@ exportZip /jsf/test/stub.jsp - - - createNewEmail - /jsf/evaluation/createNewEmail.jsp - - - confirmEmailSent - /jsf/evaluation/confirmEmailSent.jsp confirmRetake /jsf/evaluation/confirmRetake.jsp - - - emailError - /jsf/evaluation/emailError.jsp From dc500ec0c4eead8b26cda4e2d8a60a098a2a395b Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Tue, 8 Apr 2025 14:01:34 -0400 Subject: [PATCH 4/4] remove comment --- .../src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java b/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java index 97841e8c838a..2e4bf911e1ac 100644 --- a/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java +++ b/samigo/samigo-app/src/java/org/sakaiproject/jsf/util/SamigoJsfTool.java @@ -329,9 +329,6 @@ else if (target.indexOf("/jsf/author/publishedSettings") > -1 bean.setAssessmentAttachment(); toolSession.removeAttribute("SENT_TO_FILEPICKER_HELPER"); } - - // case 4: removed legacy email functionality - else if (target.indexOf("/jsf/evaluation/questionScore") > -1 && ("true").equals(toolSession.getAttribute("SENT_TO_FILEPICKER_HELPER"))) { QuestionScoresBean bean = (QuestionScoresBean) ContextUtil.lookupBeanFromExternalServlet("questionScores", req, res);