01: package org.claros.mini.actions;
02:
03: import java.util.ArrayList;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07: import org.apache.struts.action.ActionForm;
08: import org.apache.struts.action.ActionForward;
09: import org.apache.struts.action.ActionMapping;
10:
11: import org.claros.commons.mail.models.Email;
12: import org.claros.commons.mail.models.EmailPart;
13: import org.claros.mini.common.BaseLoggedAction;
14: import org.claros.mini.models.ComposeFormBean;
15:
16: /**
17: * @version 1.0
18: * @author Umut Gökbayrak
19: */
20: public class ForwardAction extends BaseLoggedAction {
21:
22: public ActionForward myExecute(ActionMapping mapping,
23: ActionForm form, HttpServletRequest request,
24: HttpServletResponse response) throws Exception {
25: // delete the previoue values
26: request.getSession().setAttribute("ComposeFormBean", null);
27: request.getSession().setAttribute("attachments", null);
28:
29: // now create a new one.
30: ComposeFormBean bean = new ComposeFormBean();
31: Email email = (Email) request.getSession()
32: .getAttribute("email");
33: bean.setSubject("Fw: " + email.getBaseHeader().getSubject());
34:
35: String bd = email.getBodyText();
36: bd = "\n\n\nOn " + email.getBaseHeader().getDate().toString()
37: + ", " + email.getFrom() + " wrote\n" + bd;
38: bean.setMessageBody(bd);
39:
40: request.getSession().setAttribute("ComposeFormBean", bean);
41: request.getSession().setAttribute("attachments",
42: organizeParts(email.getParts()));
43:
44: return mapping.findForward("success");
45: }
46:
47: private ArrayList organizeParts(ArrayList parts) {
48: if (parts != null) {
49: EmailPart tmp = null;
50: int pos = -1;
51: for (int i = 0; i < parts.size(); i++) {
52: tmp = (EmailPart) parts.get(i);
53: if (tmp.getContentType() == null) {
54: tmp.setContentType("application/octet-stream");
55: } else {
56: pos = tmp.getContentType().indexOf(";");
57: if (pos > 0) {
58: tmp.setContentType(tmp.getContentType()
59: .substring(0, pos));
60: }
61: }
62: }
63: }
64: return parts;
65: }
66: }
|