01: package org.claros.intouch.webmail.services;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.io.PrintWriter;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: import org.claros.commons.mail.models.EmailPart;
14: import org.claros.intouch.common.services.BaseService;
15:
16: public class DeleteAttachmentService extends BaseService {
17:
18: /**
19: *
20: */
21: private static final long serialVersionUID = 7436101802848885384L;
22:
23: /**
24: * The doPost method of the servlet. <br>
25: *
26: * This method is called when a form has its tag value method equals to post.
27: *
28: * @param request the request send by the client to the server
29: * @param response the response send by the server to the client
30: * @throws ServletException if an error occurred
31: * @throws IOException if an error occurred
32: */
33: public void doPost(HttpServletRequest request,
34: HttpServletResponse response) throws ServletException,
35: IOException {
36:
37: response.setHeader("Expires", "-1");
38: response.setHeader("Pragma", "no-cache");
39: response.setHeader("Cache-control", "no-cache");
40: response.setHeader("Content-Type", "text/html; charset=utf-8");
41:
42: PrintWriter out = response.getWriter();
43:
44: List parts = (List) request.getSession().getAttribute(
45: "attachments");
46: List newLst = new ArrayList();
47: if (parts != null) {
48: EmailPart tmp = null;
49: for (int i = 0; i < parts.size(); i++) {
50: tmp = (EmailPart) parts.get(i);
51: if (tmp.getFilename().equals(request.getParameter("f"))) {
52: File f = new File(tmp.getDisposition());
53: f.delete();
54: } else {
55: newLst.add(tmp);
56: }
57: }
58: }
59: request.getSession().setAttribute("attachments", newLst);
60: out.print("ok");
61:
62: }
63:
64: }
|