KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > actions > communication > SelectMailAction


1 /*
2  * Created on 29.03.2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.contineo.actions.communication;
8
9 import java.io.BufferedInputStream JavaDoc;
10 import java.io.File JavaDoc;
11 import java.io.FileInputStream JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.util.Collection JavaDoc;
14 import javax.servlet.http.HttpServletRequest JavaDoc;
15 import javax.servlet.http.HttpServletResponse JavaDoc;
16 import javax.servlet.http.HttpSession JavaDoc;
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 /**
30  * @author Michael Scholz
31  *
32  * To change the template for this generated type comment go to
33  * Window>Preferences>Java>Code Generation>Code and Comments
34  */

35 public class SelectMailAction extends Action {
36
37     /**
38      * @uml.property name="logger"
39      * @uml.associationEnd
40      */

41     private Logger logger;
42
43     /**
44      *
45      */

46     public SelectMailAction() {
47         logger = LoggingManager.getLogger(this.getClass());
48     }
49
50     public ActionForward execute(ActionMapping mapping,
51                     ActionForm form, HttpServletRequest JavaDoc request,
52                     HttpServletResponse JavaDoc response) {
53         ActionForward actionForward = new ActionForward();
54         HttpSession JavaDoc session = request.getSession();
55         if (SessionManagement.isValid(session)) {
56             try {
57                 session.setAttribute("helppage", "showemail");
58                 String JavaDoc username = (String JavaDoc)session.getAttribute("authuser");
59                 String JavaDoc 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 JavaDoc attachments = email.getAttachments();
67                 StringBuffer JavaDoc text = new StringBuffer JavaDoc();
68                 SettingConfigurator conf = new SettingConfigurator();
69                 String JavaDoc userdir = conf.getValue("userdir") + "/" + username + "/mails/" + String.valueOf(email.getMessageId());
70                 File JavaDoc file = new File JavaDoc(userdir + "/email.mail");
71                 InputStream JavaDoc is = new FileInputStream JavaDoc(file);
72                 BufferedInputStream JavaDoc bis = new BufferedInputStream JavaDoc(is);
73                 int letter = 0;
74                 while ((letter = bis.read()) != -1) {
75                     text.append((char)letter);
76                 }
77                 bis.close();
78                 String JavaDoc 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 JavaDoc 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