1 7 package org.contineo.actions.communication; 8 9 import java.io.BufferedInputStream ; 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.InputStream ; 13 import java.util.Collection ; 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpServletResponse ; 16 import javax.servlet.http.HttpSession ; 17 import org.apache.log4j.Level; 18 import org.apache.log4j.Logger; 19 import org.apache.struts.action.Action; 20 import org.apache.struts.action.ActionForm; 21 import org.apache.struts.action.ActionForward; 22 import org.apache.struts.action.ActionMapping; 23 import org.contineo.communication.EMail; 24 import org.contineo.communication.dao.EMailDAO; 25 import org.contineo.core.LoggingManager; 26 import org.contineo.core.SessionManagement; 27 import org.contineo.core.config.SettingConfigurator; 28 29 35 public class SelectMailAction extends Action { 36 37 41 private Logger logger; 42 43 46 public SelectMailAction() { 47 logger = LoggingManager.getLogger(this.getClass()); 48 } 49 50 public ActionForward execute(ActionMapping mapping, 51 ActionForm form, HttpServletRequest request, 52 HttpServletResponse response) { 53 ActionForward actionForward = new ActionForward(); 54 HttpSession session = request.getSession(); 55 if (SessionManagement.isValid(session)) { 56 try { 57 session.setAttribute("helppage", "showemail"); 58 String username = (String )session.getAttribute("authuser"); 59 String messageid = request.getParameter("messageid"); 60 EMailDAO emailDao = new EMailDAO(); 61 EMail email = emailDao.findByPrimaryKey(Integer.parseInt(messageid)); 62 if (email.getRead() == 0) { 63 email.setRead(1); 64 emailDao.store(email); 65 } 66 Collection attachments = email.getAttachments(); 67 StringBuffer text = new StringBuffer (); 68 SettingConfigurator conf = new SettingConfigurator(); 69 String userdir = conf.getValue("userdir") + "/" + username + "/mails/" + String.valueOf(email.getMessageId()); 70 File file = new File (userdir + "/email.mail"); 71 InputStream is = new FileInputStream (file); 72 BufferedInputStream bis = new BufferedInputStream (is); 73 int letter = 0; 74 while ((letter = bis.read()) != -1) { 75 text.append((char)letter); 76 } 77 bis.close(); 78 String author = ""; 79 if (email.getAuthor() != null && !email.getAuthor().equals("")) 80 author = email.getAuthor(); 81 else 82 author = email.getAuthorAddress(); 83 request.setAttribute("author", author); 84 request.setAttribute("subject", email.getSubject()); 85 request.setAttribute("text",text.toString()); 86 request.setAttribute("attachments", attachments); 87 actionForward = mapping.findForward("selectemail"); 88 } catch (Exception e) { 89 if (logger.isEnabledFor(Level.ERROR)) 90 logger.error(e.getMessage()); 91 actionForward = mapping.findForward("error"); 92 } 93 } else 94 actionForward = mapping.findForward("invalid"); 95 return actionForward; 96 } 97 } 98
| Popular Tags
|