1 import java.io.IOException;
2 import java.io.InputStream;
3 import java.io.UnsupportedEncodingException;
4 import java.util.HashMap;
5 import javax.mail.Folder;
6 import javax.mail.Message;
7 import javax.mail.MessagingException;
8 import javax.mail.Multipart;
9 import javax.mail.Part;
10 import javax.mail.Store;
11 import javax.mail.internet.InternetAddress;
12 import javax.mail.internet.MimeUtility;
13 import javax.servlet.ServletException;
14 import javax.servlet.ServletOutputStream;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 import javax.servlet.http.HttpSession;
18 import chunwei.mail.Login;
19 import chunwei.mail.MailUserData;
20 /**21 * Servlet implementation class for Servlet: MailServlet22 * Author: luchunwei Email: luchunwei@gmail.com23 */
24 public class MailNode extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
25 private static final long serialVersionUID = 1L;
26 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27 nodeid="";
28 node="0";
29 currentnodeid=0;
30 url=request.getRequestURL().toString();
31 HttpSession ses=request.getSession();
32 MailUserData mud=(MailUserData)ses.getAttribute("mud");
33 ServletOutputStream out=response.getOutputStream();
34 response.setContentType("text/html;charset=GB2312");
35 int msgid=-1,partid=-1;//msgdi:邮件编号;partid:MultiPart Message中part的编号。36 String partname=null; //图片或附件的文件名37 String nodepara=null;//节点编号,如1-2-1-0, 他以便层层剥入38 if (request.getParameter("msgid")!=null)
39 msgid=Integer.parseInt(request.getParameter("msgid"));
40 msgidStr="msgid="+msgid;
41 if (request.getParameter("partid")!=null)
42 partid=Integer.parseInt(request.getParameter("partid"));
43 if (request.getParameter("partname")!=null)
44 partname=new String(request.getParameter("partname").getBytes("ISO-8859-1"),"GB2312");
45 if (request.getParameter("node")!=null)
46 nodepara=request.getParameter("node");
47 System.out.println(nodepara);
48 //System.out.println(msgid+":"+partid+":"+partname);49 if (partname!=null){
50 //displayImages51 try {
52 displayPart(partname,response,out);
53 } catch (MessagingException e) {
54 e.printStackTrace();
55 } catch (IOException e) {
56 e.printStackTrace();
57 }
58 return;
59 }
60 //--------------------------61 if (mud==null){
62 Login login=new Login("imap","mail.server.com",-1,"user","password