getattach.jsp
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html; charset=utf-8" language="java"%>
  2. <%@ page import="cn.js.fan.mail.GetMail"%>
  3. <%@ page import="cn.js.fan.mail.MailMsg"%>
  4. <%@ page import="cn.js.fan.mail.Attachment"%>
  5. <%@page import="java.util.*"%>
  6. <%@page import="cn.js.fan.util.*"%>
  7. <%@page import="com.redmoon.oa.emailpop3.*"%>
  8. <%@page import="java.io.*"%>
  9. <%@page import="java.net.*"%>
  10. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  11. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  12. <jsp:useBean id="userservice" scope="page" class="com.redmoon.oa.person.UserService"/>
  13. <%
  14. String priv = request.getParameter("priv");
  15. if (priv==null)
  16. priv = "read";
  17. if (!privilege.isUserPrivValid(request,priv))
  18. {
  19. out.println(fchar.makeErrMsg("权限非法"));
  20. return;
  21. }
  22. String username = privilege.getUser(request);
  23. String email = ParamUtil.get(request, "email");
  24. UserPop3Setup userpop3setup = new UserPop3Setup();
  25. userpop3setup.getUserPop3Setup(username, email);
  26. String mailserver = userpop3setup.getMailServer();
  27. String email_name = userpop3setup.getUser();
  28. String email_pwd_raw = userpop3setup.getPwd();
  29. System.out.println("getattach.jsp mailserver=" + mailserver + " email_name=" + email_name + " email_pwd_raw=" + email_pwd_raw);
  30. GetMail getmail = new GetMail(mailserver,email_name,email_pwd_raw);
  31. String mailid="",attachnum="";
  32. mailid = request.getParameter("mailid");
  33. String errmsg = "";
  34. if (mailid==null)
  35. errmsg += "mailid不能为空!\n";
  36. if (!fchar.isNumeric(mailid))
  37. errmsg += "mailid必须为数字!\n";
  38. attachnum = request.getParameter("attachnum");
  39. if (attachnum==null)
  40. errmsg += "附件标识不能为空!\n";
  41. if (!fchar.isNumeric(attachnum))
  42. errmsg += "附件标识必须为数字!\n";
  43. if (!errmsg.equals(""))
  44. {
  45. out.println(fchar.Alert_Back(errmsg));
  46. return;
  47. }
  48. int intmailid = Integer.parseInt(mailid);
  49. int intattachnum = Integer.parseInt(attachnum);
  50. Attachment a = getmail.getAttachment(intmailid, intattachnum);
  51. if (a==null)
  52. {
  53. out.println("取附件失败!");
  54. return;
  55. }
  56. //cfgparser.parse("config.xml");
  57. //Properties props = cfgparser.getProps();
  58. //String documentpath = props.getProperty("documentpath");
  59. String ext = a.getExt();
  60. MIMEMap m = new MIMEMap();
  61. response.setContentType((String)m.get(ext));
  62. BufferedInputStream bis = null;
  63. BufferedOutputStream bos = null;
  64. try {
  65. bis = new BufferedInputStream(a.getInputStream());
  66. bos = new BufferedOutputStream(response.getOutputStream());
  67. byte[] buff = new byte[2048];
  68. int bytesRead;
  69. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  70. bos.write(buff,0,bytesRead);
  71. }
  72. } catch(final IOException e) {
  73. System.out.println ( "  IOException." + e );
  74. } finally {
  75. if (bis != null)
  76. bis.close();
  77. if (bos != null)
  78. bos.close();
  79. }
  80. %>