EmailAction.java
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:23k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.oa.module.email.action;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.io.PrintWriter;
  7. import java.lang.reflect.InvocationTargetException;
  8. import java.util.Enumeration;
  9. import java.util.HashSet;
  10. import java.util.Hashtable;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Set;
  14. import javax.servlet.http.HttpServletRequest;
  15. import javax.servlet.http.HttpServletResponse;
  16. import javax.servlet.http.HttpSession;
  17. import org.apache.commons.beanutils.BeanUtils;
  18. import org.apache.struts.action.ActionForm;
  19. import org.apache.struts.action.ActionForward;
  20. import org.apache.struts.action.ActionMapping;
  21. import org.apache.struts.actions.DispatchAction;
  22. import org.apache.struts.upload.FormFile;
  23. import com.oa.module.email.bean.ReceiveLetterBean;
  24. import com.oa.module.email.blacklist.mapping.Tblacklist;
  25. import com.oa.module.email.company.Tcompany;
  26. import com.oa.module.email.company.TcompanyDao;
  27. import com.oa.module.email.dao.IEmailDao;
  28. import com.oa.module.email.form.EmailForm;
  29. import com.oa.module.email.fujian.mapping.Tfujian;
  30. import com.oa.module.email.mapping.Tmailinfo;
  31. import com.oa.module.office.user.Tuser;
  32. import com.oa.util.PubUtil;
  33. import com.oa.util.XPage;
  34. /**
  35.  * 邮件处理ACtion
  36.  * @author admin
  37.  *
  38.  */
  39. public class EmailAction extends DispatchAction {
  40. // --------------------------------------------------------- Instance
  41. // Variables
  42. private IEmailDao emaildao;
  43. // --------------------------------------------------------- Methods
  44. /**
  45.  * Method execute
  46.  * 收件箱
  47.  * @param mapping
  48.  * @param form
  49.  * @param request
  50.  * @param response
  51.  * @return ActionForward
  52.  */
  53. public ActionForward receiveBox(ActionMapping mapping, ActionForm form,
  54. HttpServletRequest request, HttpServletResponse response) {
  55. EmailForm emailForm = (EmailForm) form;
  56. String cpage = request.getParameter("currentPage");
  57. int currentPage = 0;
  58. try {
  59. currentPage = Integer.parseInt(cpage);
  60. } catch (Exception e) {
  61. currentPage = 1;
  62. }
  63. int count = 10;
  64. ReceiveLetterBean bean = new ReceiveLetterBean();
  65. try {
  66. BeanUtils.copyProperties(bean, emailForm);
  67. HttpSession session = request.getSession();
  68. Tuser user =  (Tuser)session.getAttribute("user");
  69. bean.setReceiveid(user.getUno());
  70. } catch (IllegalAccessException e) {
  71. // TODO 自动生成 catch 块
  72. e.printStackTrace();
  73. } catch (InvocationTargetException e) {
  74. // TODO 自动生成 catch 块
  75. e.printStackTrace();
  76. }
  77. XPage page = emaildao.getEmailList(currentPage, count, bean);
  78. request.setAttribute("letterpage", page);
  79. return mapping.findForward("letterList");
  80. }
  81. /**
  82.  * 写信
  83.  * @param mapping
  84.  * @param form
  85.  * @param request
  86.  * @param response
  87.  * @return
  88.  */
  89. public ActionForward writeEmail(ActionMapping mapping, ActionForm form,
  90. HttpServletRequest request, HttpServletResponse response) {
  91. EmailForm emailForm = (EmailForm) form;
  92. if(emailForm.getSendid()!=null){
  93. String[] check=emailForm.getCheckeduserList();
  94. check[0] = check[0]+","+ emailForm.getSendid();
  95. emailForm.setCheckeduserList(check);
  96. System.out.println(check[0]);
  97. }
  98. TcompanyDao dao = new TcompanyDao();
  99. Tcompany company = dao.getCompany();
  100. request.setAttribute("company",company);
  101. return mapping.findForward("writeEmail");
  102. }
  103. /**
  104.  * 发信
  105.  * @param mapping
  106.  * @param form
  107.  * @param request
  108.  * @param response
  109.  * @return
  110.  */
  111. public ActionForward sendEmail(ActionMapping mapping, ActionForm form,
  112. HttpServletRequest request, HttpServletResponse response) {
  113. EmailForm emailForm = (EmailForm) form;
  114. emailForm.setIsfujian("0");
  115. String[] checked = emailForm.getCheckeduserList();
  116. Tmailinfo mail = null;
  117. boolean flag = false;
  118. boolean xxxx = false;
  119. boolean temps = false;
  120. Set set = new HashSet();
  121. for (int i = 0; i < checked.length; i++) {
  122. int temp = checked[i].indexOf(",");
  123. String username = checked[i].substring(0,temp);
  124. String uno = checked[i].substring(temp+1,checked[i].length());
  125. if(username!=null && uno!=null){
  126. emailForm.setReceiveid(uno);
  127. emailForm.setReceivename(username);
  128. }else{
  129. continue;
  130. }
  131. emailForm.setSendtime(PubUtil.getNowDate());
  132. HttpSession session = request.getSession();
  133. Tuser user = (Tuser)session.getAttribute("user");
  134. emailForm.setSendid(user.getUno());
  135. emailForm.setSendname(user.getUname());
  136. emailForm.setEmailtype("0");
  137. //对方是否把邮件放入黑名单
  138. List list = emaildao.getBlackListById(uno);
  139. for (Iterator iter = list.iterator(); iter.hasNext();) {
  140. Tblacklist element = (Tblacklist) iter.next();
  141. /*
  142.  *这里换成登录用户 
  143.  */
  144. if(element.getBlackuserid().equals("1")){
  145. emailForm.setEmailtype("3");
  146. break;
  147. }
  148. }
  149. mail = new Tmailinfo(); 
  150. try {
  151. BeanUtils.copyProperties(mail , emailForm);
  152. //上传文件
  153. Hashtable fileh = emailForm.getMultipartRequestHandler().getFileElements();
  154. //判断每个文件的大小
  155. for (Enumeration e = fileh.keys(); e.hasMoreElements();) {
  156. String key = (String) e.nextElement();
  157. FormFile file = (FormFile) fileh.get(key);
  158. if(file.getFileSize()>5*1024*1024){
  159. PrintWriter out = response.getWriter();
  160. out.print("<script>");
  161. out.print("alert('上传文件不能超过5M');");
  162. out.print("history.back();");
  163. out.print("</script>");
  164. return null;
  165. }
  166. }
  167. //
  168. for (Enumeration e = fileh.keys(); e.hasMoreElements();) {
  169. String key = (String) e.nextElement();
  170. FormFile file = (FormFile) fileh.get(key);
  171. String filename = file.getFileName().trim(); // 文件名
  172. if(filename!= null && !(filename.equals("")) ){
  173. String extendname = filename.substring(filename.lastIndexOf('.'), filename.length()-1);
  174. String realpath = request.getSession().getServletContext()
  175. .getRealPath("");
  176. realpath = realpath.replace('\', '/');
  177. String filepath = "/upload/emailfile";  ;
  178. String newFile = realpath  + filepath+"/"+filename;
  179. Tfujian fuj = new Tfujian();
  180. fuj.setFilename(filename);
  181. fuj.setFilepath(filepath);
  182. fuj.setMail(mail);
  183. mail.getFujian().add(fuj);
  184. mail.setIsfujian("1");
  185. if(temps==false)
  186. set.add(fuj);
  187. emailForm.setIsfujian("1");
  188. xxxx = true;
  189. InputStream input = file.getInputStream();
  190. OutputStream output = new FileOutputStream(newFile);
  191. byte[] b = new byte[1024];
  192. int j = 0;
  193. while ((j = input.read(b, 0, b.length)) != -1) {
  194. output.write(b, 0, j);
  195. }
  196. output.flush();
  197. output.close();
  198. input.close();
  199. }
  200. }
  201. temps = true;
  202. } catch (IllegalAccessException e) {
  203. // TODO 自动生成 catch 块
  204. e.printStackTrace();
  205. } catch (InvocationTargetException e) {
  206. // TODO 自动生成 catch 块
  207. e.printStackTrace();
  208. } catch (IOException e) {
  209. // TODO 自动生成 catch 块
  210. e.printStackTrace();
  211. }
  212. emaildao.addEamil(mail);
  213. }
  214. //保存发送记录
  215. String checkedusername="";
  216. String checkeduserid = "";
  217. for(int i=0; i<checked.length; i++){
  218. int temp = checked[i].indexOf(",");
  219. String username = checked[i].substring(0,temp);
  220. String uno = checked[i].substring(temp+1,checked[i].length());
  221. checkedusername += username+",";
  222. checkeduserid += uno+",";
  223. }
  224. checkedusername = checkedusername.substring(0, checkedusername.length()-1);
  225. checkeduserid = checkeduserid.substring(0, checkeduserid.length()-1);
  226. mail = new Tmailinfo();
  227. try {
  228. BeanUtils.copyProperties(mail, emailForm);
  229. mail.setReceiveid(checkeduserid);
  230. mail.setReceivename(checkedusername);
  231. mail.setEmailtype("2");
  232. if(xxxx==true){
  233. mail.setIsfujian("1");
  234. }
  235. } catch (IllegalAccessException e) {
  236. // TODO 自动生成 catch 块
  237. e.printStackTrace();
  238. } catch (InvocationTargetException e) {
  239. // TODO 自动生成 catch 块
  240. e.printStackTrace();
  241. }
  242. for (Iterator iter = set.iterator(); iter.hasNext();) {
  243. Tfujian element = (Tfujian) iter.next();
  244. Tfujian ss = new Tfujian();
  245. ss.setFilename(element.getFilename());
  246. ss.setFilepath(element.getFilepath());
  247. mail.getFujian().add(ss);
  248. ss.setMail(mail);
  249. }
  250. flag = emaildao.addEamil(mail);
  251. if(flag ==true){
  252. //成功
  253. request.setAttribute("task","sendsuc");
  254. return mapping.findForward("suc");
  255. }else{
  256. request.setAttribute("task","senderror");
  257. return mapping.findForward("error");
  258. }
  259. }
  260. /**
  261.  * 转发给其他用户
  262.  * @param mapping
  263.  * @param form
  264.  * @param request
  265.  * @param response
  266.  * @return
  267.  */
  268. public ActionForward sendToOther(ActionMapping mapping, ActionForm form,
  269. HttpServletRequest request, HttpServletResponse response) {
  270. EmailForm emailForm = (EmailForm) form;
  271. Tmailinfo info = emaildao.getEmailByEmailid(emailForm.getEmailid());
  272. String[] sendUser = emailForm.getSenduser();
  273. String id = "";
  274. String name="";
  275. boolean flag = false;
  276. for(int i = 0 ; i < sendUser.length; i++){
  277. int j = sendUser[i].indexOf(",");
  278. id = sendUser[i].substring(0, j);
  279. name = sendUser[i].substring(j+1,sendUser[i].length());
  280. info.setReceiveid(id);
  281. info.setReceivename(name);
  282. flag = emaildao.addEamil(info);
  283. }
  284. if(flag ==true){
  285. //成功
  286. request.setAttribute("task","sendtoorhersuc");
  287. return mapping.findForward("suc");
  288. }else{
  289. request.setAttribute("task","sendtoothererror");
  290. return mapping.findForward("error");
  291. }
  292. }
  293. /**
  294.  * 读取信件
  295.  * @param mapping
  296.  * @param form
  297.  * @param request
  298.  * @param response
  299.  * @return
  300.  */
  301. public ActionForward readEmail(ActionMapping mapping, ActionForm form,
  302. HttpServletRequest request, HttpServletResponse response) {
  303. EmailForm emailForm = (EmailForm) form;
  304. emailForm.setEmailtype("0");
  305. Tmailinfo mail  = emaildao.getEmailByEmailid(emailForm.getEmailid());
  306. //如果邮件是未读的,则修改状态
  307. if(emailForm.getIsread().equals("0")){
  308. boolean flag = emaildao.UpdateEmail(emailForm, 0);
  309. if(flag==false)
  310. System.out.println("修改email状态出错");
  311. }
  312. try {
  313. BeanUtils.copyProperties(emailForm, mail);
  314. } catch (IllegalAccessException e) {
  315. // TODO 自动生成 catch 块
  316. e.printStackTrace();
  317. } catch (InvocationTargetException e) {
  318. // TODO 自动生成 catch 块
  319. e.printStackTrace();
  320. }
  321. /**
  322.  * 获取登陆用户
  323.  */
  324. HttpSession session = request.getSession();
  325. Tuser user = (Tuser)session.getAttribute("user");
  326. String id = user.getUno();
  327. /*String id = "1";*/
  328. List list = emaildao.getUserList(id);
  329. request.setAttribute("userList", list);
  330. return mapping.findForward("readEmail");
  331. }
  332. /**
  333.  * 读取草稿
  334.  */
  335. public ActionForward readEmailCaoGao(ActionMapping mapping, ActionForm form,
  336. HttpServletRequest request, HttpServletResponse response) {
  337. EmailForm emailForm = (EmailForm) form;
  338. Tmailinfo mail  = emaildao.getEmailByEmailid(emailForm.getEmailid());
  339. try {
  340. BeanUtils.copyProperties(emailForm, mail);
  341. } catch (IllegalAccessException e) {
  342. // TODO 自动生成 catch 块
  343. e.printStackTrace();
  344. } catch (InvocationTargetException e) {
  345. // TODO 自动生成 catch 块
  346. e.printStackTrace();
  347. }
  348. return mapping.findForward("readEmailcaogao");
  349. }
  350. /**
  351.  * 存草稿
  352.  * @param mapping
  353.  * @param form
  354.  * @param request
  355.  * @param response
  356.  * @return
  357.  */
  358. public ActionForward saveletter(ActionMapping mapping, ActionForm form,
  359. HttpServletRequest request, HttpServletResponse response) {
  360. EmailForm emailForm = (EmailForm) form;
  361. emailForm.setEmailtype("1");
  362. emailForm.setSendtime(PubUtil.getNowDate());
  363. HttpSession session = request.getSession();
  364. Tuser user = (Tuser)session.getAttribute("user");
  365. emailForm.setSendid(user.getUno());
  366. emailForm.setSendname(user.getUname());
  367. String[] checked = emailForm.getCheckeduserList();
  368. String checkedusername="";
  369. String checkeduserid = "";
  370. for(int i=0; i<checked.length; i++){
  371. int temp = checked[i].indexOf(",");
  372. String username = checked[i].substring(0,temp);
  373. String uno = checked[i].substring(temp+1,checked[i].length());
  374. checkedusername += username+",";
  375. checkeduserid += uno+",";
  376. }
  377. checkedusername = checkedusername.substring(0, checkedusername.length()-1);
  378. checkeduserid = checkeduserid.substring(0, checkeduserid.length()-1);
  379. Tmailinfo mail = new Tmailinfo();
  380. try {
  381. BeanUtils.copyProperties(mail, emailForm);
  382. } catch (IllegalAccessException e) {
  383. // TODO 自动生成 catch 块
  384. e.printStackTrace();
  385. } catch (InvocationTargetException e) {
  386. // TODO 自动生成 catch 块
  387. e.printStackTrace();
  388. }
  389. mail.setReceiveid(checkeduserid);
  390. mail.setReceivename(checkedusername);
  391. boolean flag = false;
  392. flag = emaildao.addEamil(mail);
  393.  
  394. if(flag ==true){
  395. //成功
  396. request.setAttribute("task","savesuc");
  397. return mapping.findForward("suc");
  398. }else{
  399. request.setAttribute("task","saveerror");
  400. return mapping.findForward("error");
  401. }
  402. }
  403. /**
  404.  * 发件箱
  405.  * @param mapping
  406.  * @param form
  407.  * @param request
  408.  * @param response
  409.  * @return
  410.  */
  411. public ActionForward sendedBox(ActionMapping mapping, ActionForm form,
  412. HttpServletRequest request, HttpServletResponse response) {
  413. EmailForm emailForm = (EmailForm) form;
  414. HttpSession session  = request.getSession();
  415. Tuser user = (Tuser)session.getAttribute("user");
  416. String cpage = request.getParameter("currentPage");
  417. int currentPage = 0;
  418. try {
  419. currentPage = Integer.parseInt(cpage);
  420. } catch (Exception e) {
  421. currentPage = 1;
  422. }
  423. int count = 10;
  424. ReceiveLetterBean bean = new ReceiveLetterBean();
  425. try {
  426. BeanUtils.copyProperties(bean, emailForm);
  427. bean.setSendid(user.getUno());
  428. } catch (IllegalAccessException e) {
  429. // TODO 自动生成 catch 块
  430. e.printStackTrace();
  431. } catch (InvocationTargetException e) {
  432. // TODO 自动生成 catch 块
  433. e.printStackTrace();
  434. }
  435. XPage page = emaildao.getEmailList(currentPage, count, bean);
  436. request.setAttribute("letterpage", page);
  437. return mapping.findForward("sendList");
  438. }
  439. /**
  440.  * 草稿箱
  441.  * @param mapping
  442.  * @param form
  443.  * @param request
  444.  * @param response
  445.  * @return
  446.  */
  447. public ActionForward caogaobox(ActionMapping mapping, ActionForm form,
  448. HttpServletRequest request, HttpServletResponse response) {
  449. EmailForm emailForm = (EmailForm) form;
  450. HttpSession session  = request.getSession();
  451. Tuser user = (Tuser)session.getAttribute("user");
  452. emailForm.setEmailtype(request.getParameter("emailtype"));
  453. ReceiveLetterBean bean = null;
  454. String cpage = request.getParameter("currentPage");
  455. int currentPage = 1;
  456. try {
  457. currentPage = Integer.parseInt(cpage);
  458. } catch (Exception e) {
  459. // TODO: handle exception
  460. currentPage =1;
  461. }
  462. int count =10;
  463. bean = new ReceiveLetterBean();
  464. try {
  465. BeanUtils.copyProperties(bean, emailForm);
  466. bean.setSendid(user.getUno());
  467. } catch (IllegalAccessException e) {
  468. // TODO 自动生成 catch 块
  469. e.printStackTrace();
  470. } catch (InvocationTargetException e) {
  471. // TODO 自动生成 catch 块
  472. e.printStackTrace();
  473. }
  474. XPage page = emaildao.getEmailList(currentPage, count, bean);
  475. request.setAttribute("letterpage", page);
  476. return mapping.findForward("caogaobox");
  477. }
  478. /**
  479.  * 编辑邮件
  480.  * @param mapping
  481.  * @param form
  482.  * @param request
  483.  * @param response
  484.  * @return
  485.  */
  486. public ActionForward Edit(ActionMapping mapping, ActionForm form,
  487. HttpServletRequest request, HttpServletResponse response) {
  488. EmailForm emailForm = (EmailForm) form;
  489. String receiveid = emailForm.getReceiveid();
  490. String receivename = emailForm.getReceivename();
  491. int temp1 = receiveid.indexOf(",", 0);
  492. int temp2 = receivename.indexOf(",", 0);
  493. int i = 0;
  494. int j = 0;
  495. String id = "";
  496. String name = "";
  497. String[]  value =  new String[receiveid.length()];
  498. int next = 0;
  499. while(temp1 != -1){
  500. id = receiveid.substring(i,temp1);
  501. name= receivename.substring(j, temp2);
  502. value[next] = name+","+id;
  503. next ++;
  504. i= temp1+1;
  505. j= temp2+1;
  506. temp1 = receiveid.indexOf(",", i);
  507. temp2 = receivename.indexOf(",", j);
  508. }
  509. id = receiveid.substring(i, receiveid.length());
  510. name = receivename.substring(j, receivename.length());
  511. value[next] = name+","+id;
  512. emailForm.setCheckeduserList(value);
  513. TcompanyDao dao = new TcompanyDao();
  514. Tcompany company = dao.getCompany();
  515. request.setAttribute("company",company);
  516. return mapping.findForward("writeEmail");
  517. }
  518. /**
  519.  * 垃圾箱
  520.  * @param mapping
  521.  * @param form
  522.  * @param request
  523.  * @param response
  524.  * @return
  525.  */
  526. public ActionForward rublishbox(ActionMapping mapping, ActionForm form,
  527. HttpServletRequest request, HttpServletResponse response) {
  528. EmailForm emailForm = (EmailForm) form;
  529. ReceiveLetterBean bean = null;
  530. emailForm.setEmailtype(request.getParameter("emailtype"));
  531. String cpage = request.getParameter("currentPage");
  532. HttpSession session  = request.getSession();
  533. Tuser user = (Tuser)session.getAttribute("user");
  534. int currentPage = 1;
  535. try {
  536. currentPage = Integer.parseInt(cpage);
  537. } catch (Exception e) {
  538. currentPage  = 1;
  539. }
  540. int count = 10;
  541. bean = new ReceiveLetterBean();
  542. try {
  543. BeanUtils.copyProperties(bean, emailForm);
  544. bean.setReceiveid(user.getUno());
  545. } catch (IllegalAccessException e) {
  546. // TODO 自动生成 catch 块
  547. e.printStackTrace();
  548. } catch (InvocationTargetException e) {
  549. // TODO 自动生成 catch 块
  550. e.printStackTrace();
  551. }
  552. XPage page = emaildao.getEmailList(currentPage, count, bean);
  553. request.setAttribute("rublishList", page);
  554. return mapping.findForward("rublishbox");
  555. }
  556. /**
  557.  * 删除到垃圾箱
  558.  * @param mapping
  559.  * @param form
  560.  * @param request
  561.  * @param response
  562.  * @return
  563.  */
  564. public ActionForward delToRublish(ActionMapping mapping, ActionForm form,
  565. HttpServletRequest request, HttpServletResponse response) {
  566. EmailForm emailForm = (EmailForm) form;
  567. String id = request.getParameter("emailid");
  568. emailForm.setEmailtype("3");
  569. emailForm.setEmailid(id);
  570. boolean flag = false;
  571. //修改成已读
  572. emaildao.UpdateEmail(emailForm, 0);
  573. //放到垃圾箱
  574. flag = emaildao.UpdateEmail(emailForm, 1);
  575. if(flag == true){
  576. request.setAttribute("task","deltorubsuc");
  577. return mapping.findForward("suc");
  578. }else{
  579. request.setAttribute("task","deltoruberror");
  580. return mapping.findForward("error");
  581. }
  582. }
  583. /**
  584.  * 彻底删除
  585.  * @param mapping
  586.  * @param form
  587.  * @param request
  588.  * @param response
  589.  * @return
  590.  */
  591. public ActionForward delForever(ActionMapping mapping, ActionForm form,
  592. HttpServletRequest request, HttpServletResponse response) {
  593. EmailForm emailForm = (EmailForm) form;
  594. boolean flag = emaildao.delemail(emailForm.getEmailid());
  595. if(flag == true){
  596. request.setAttribute("task","delforeversuc");
  597. return mapping.findForward("suc");
  598. }else{
  599. request.setAttribute("task","delforevererror");
  600. return mapping.findForward("error");
  601. }
  602. }
  603. /**
  604.  * 批量移到垃圾箱
  605.  * @param mapping
  606.  * @param form
  607.  * @param request
  608.  * @param response
  609.  * @return
  610.  */
  611. public ActionForward removesToRublish(ActionMapping mapping, ActionForm form,
  612. HttpServletRequest request, HttpServletResponse response) {
  613. EmailForm emailForm = (EmailForm) form;
  614. String[] check = emailForm.getCheck();
  615. boolean flag = false;
  616. if(check==null || check.length<=0){
  617. try {
  618. PrintWriter out = response.getWriter();
  619. out.print("<script>");
  620. out.print("alert('你还没有选择');");
  621. out.print("history.back();");
  622. out.print("</script>");
  623. return null;
  624. } catch (IOException e) {
  625. // TODO 自动生成 catch 块
  626. e.printStackTrace();
  627. }
  628. }
  629. for(int i=0; i<check.length; i++){
  630. emailForm.setEmailtype("3");
  631. emailForm.setEmailid(check[i]);
  632. //放到垃圾箱
  633. flag = emaildao.UpdateEmail(emailForm, 1);
  634. }
  635. if(flag == true){
  636. request.setAttribute("task","deltorubsuc");
  637. return mapping.findForward("suc");
  638. }else{
  639. request.setAttribute("task","deltoruberror");
  640. return mapping.findForward("error");
  641. }
  642. }
  643. /**
  644.  * 批量彻底删除
  645.  * @param mapping
  646.  * @param form
  647.  * @param request
  648.  * @param response
  649.  * @return
  650.  */
  651. public ActionForward delsForever(ActionMapping mapping, ActionForm form,
  652. HttpServletRequest request, HttpServletResponse response) {
  653. EmailForm emailForm = (EmailForm) form;
  654. String[] checked = emailForm.getCheck();
  655. boolean flag = false;
  656. for(int i=0; i<checked.length; i++){
  657. flag = emaildao.delemail(checked[i]);
  658. }
  659. if(flag == true){
  660. request.setAttribute("task","delforeversuc");
  661. return mapping.findForward("suc");
  662. }else{
  663. request.setAttribute("task","delforevererror");
  664. return mapping.findForward("error");
  665. }
  666. }
  667. /**
  668.  * 移动到收件箱
  669.  * @param mapping
  670.  * @param form
  671.  * @param request
  672.  * @param response
  673.  * @return
  674.  */
  675. public ActionForward moveToReceiverBox(ActionMapping mapping, ActionForm form,
  676. HttpServletRequest request, HttpServletResponse response) {
  677. EmailForm emailForm = (EmailForm) form;
  678. String[] check = emailForm.getCheck();
  679. boolean flag = false;
  680. for(int i=0; i<check.length; i++){
  681. emailForm.setEmailtype("0");
  682. emailForm.setEmailid(check[i]);
  683. //放到收件箱
  684. flag = emaildao.UpdateEmail(emailForm, 1);
  685. }
  686. if(flag == true){
  687. request.setAttribute("task","toService");
  688. return mapping.findForward("suc");
  689. }else{
  690. request.setAttribute("task","toServiceerror");
  691. return mapping.findForward("error");
  692. }
  693. }
  694. /**
  695.  * 根据查询条件(是否已读) 得到邮件
  696.  * @param mapping
  697.  * @param form
  698.  * @param request
  699.  * @param response
  700.  * @return
  701.  */
  702. public ActionForward isRead(ActionMapping mapping, ActionForm form,
  703. HttpServletRequest request, HttpServletResponse response) {
  704. EmailForm emailForm = (EmailForm) form;
  705. String cpage = request.getParameter("currentPage");
  706. int currentpage  = 1;
  707. try {
  708. currentpage = Integer.parseInt(cpage);
  709. } catch (Exception e) {
  710. currentpage = 1;
  711. }
  712. int count = 10;
  713. ReceiveLetterBean bean = new ReceiveLetterBean();
  714. try {
  715. BeanUtils.copyProperties(bean , emailForm);
  716. } catch (IllegalAccessException e) {
  717. // TODO 自动生成 catch 块
  718. e.printStackTrace();
  719. } catch (InvocationTargetException e) {
  720. // TODO 自动生成 catch 块
  721. e.printStackTrace();
  722. }
  723. XPage  page = emaildao.getIsReadList(currentpage, count, bean);
  724. request.setAttribute("letterpage", page);
  725. return mapping.findForward("letterList");
  726. }
  727. public IEmailDao getEmaildao() {
  728. return emaildao;
  729. }
  730. public void setEmaildao(IEmailDao emaildao) {
  731. this.emaildao = emaildao;
  732. }
  733. }