⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewmail.java

📁 JAVA邮件系统
💻 JAVA
字号:
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import java.util .Vector ;
import javax.servlet.*;
import javax.servlet.http.*;

public class ViewMail extends HttpServlet 
{
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException
    {
		doGet(request,response);
	}
	
	public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException
    {
		
		// 得到名字和口令
		String name="",pass;

		Person person = new Person();
		person.setName (CommonMethods.GetUserName(request));
		pass = CommonMethods.GetUserPass (request);
		if( person.getName ()==null || (!person.checkPassword(pass)) )
		{
			return;
		}
		String sAttach = request.getParameter("attach");
		int nAttach = CommonMethods.GetInt (sAttach,0);
		GetEmailInfo GM = new GetEmailInfo ();
		String sMail = request.getParameter("mail");
		String sFolder = CommonMethods.getParameterValue (
									request,"FOLDER");
		String sPage = request.getParameter("PAGENO");
		if(sFolder!=null)
			sMail +=("&FOLDER="+sFolder);
		if(sPage!=null)
			sMail +=("&PAGENO="+sPage);
		if(sMail==null)
			return;
		Email EM = GM.getEmailContentFromPerlCGI ( person.getName (),
															 pass
															,sMail ) ;

		if( sAttach!=null ){
			MailItem MI= EM.GetItemAt (nAttach);	
			response.setContentType ("application/octet-stream;");
			//输出流:
			if(MI!=null){
				ServletOutputStream sos= response.getOutputStream ();			
				sos.write (MI.GetContentOut() );	
			}
			return;
		}

		HtmlOut htmlOut = new HtmlOut (response);
		
		if( EM==null ){
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE  ,"",
								"没有此邮件!",
								"");
			htmlOut.outHtml();
			return;
		}
		
		
		//get template and ...
		TemplateList tempList = CommonMethods.getViewMailTemplate ();
		if(tempList!=null){
			SingleTemplate st = tempList.searchTemplate ("ROOT");
			for(int i=0;i<st.getKeyNum ();i++){
				String sKey = st.getKeyAt (i);
				htmlOut.addString (st.getStringAt (i));
				if( sKey .compareTo("cgi-path")==0 )
					htmlOut.addString (CommonMethods.sHostNameCGI);
				if(sKey.compareTo ("subject")==0)
					htmlOut.addStringPlain (EM.GetMailHeader ().GetSubject() );
				if(sKey.compareTo ("from")==0)
					htmlOut.addStringPlain 
						( EM.GetMailHeader ().GetFrom () );
				if(sKey.compareTo ("to")==0)
					htmlOut.addStringPlain (EM.GetMailHeader ().GetTo() );
				if(sKey.compareTo ("cc")==0)
					htmlOut.addStringPlain(EM.GetMailHeader ().GetCc() );
				if(sKey.compareTo ("info")==0){
					if( EM.GetItemNum()>0 ){
						MailItem EItem = EM.GetItemAt (0);
						if(EItem.GetContentType ()==MailItem.CONTENT_TYPE_PLAIN ){
							htmlOut.addStringPlain ( new String (EItem.GetContentOut () ));	
						}
					}
				}
				if(sKey.compareTo ("mail")==0){
					htmlOut.addString(sMail);
				}
				if(sKey.compareTo ("folder")==0){
					htmlOut.addString(sFolder);
				}
				if(sKey.compareTo ("page")==0){
					htmlOut.addString(sPage);
				}
				
				if(sKey.compareTo ("folders")==0){
					Vector fs= GM.ListMailFolder(person.getName (),pass);
					for( int f=0;f<fs.size ();f++ ){
						MailFolder MF = (MailFolder)fs.elementAt (f);
						if( MF.sName .compareTo (sFolder)!=0 )
							htmlOut.addString("<option value="+
										  MF.sID +">"+MF.sName
										  +"</option>");
					}
				}
				
				if(sKey.compareTo ("allfolders")==0){
					Vector fs= GM.ListMailFolder(person.getName (),pass);
					for( int f=0;f<fs.size ();f++ ){
						MailFolder MF = (MailFolder)fs.elementAt (f);
						htmlOut.addString("<option value="+
										  MF.sName +">"+MF.sName
										  +"</option>");
					}
				}
				
				if(sKey.compareTo ("curFolder")==0){
					Vector fs= GM.ListMailFolder(person.getName (),pass);
					htmlOut.addString(sFolder);
				}
					
				if(sKey.compareTo ("attach")==0){
					nAttach= EM.GetItemNum();
					for(int j=0;j<nAttach;j++){
						MailItem EItem = EM.GetItemAt (j);
						if(EItem.GetContentType ()==MailItem.CONTENT_TYPE_ATTCH  ){
							String aName= EItem.GetContentName ();
							if(aName==null )
								aName="noname";
							htmlOut.addString ( "<BR>"+"<A href="+"ViewMail/"
											    + EItem.GetContentName()+"?" 
											    +"&mail="+sMail
												+"&attach="+j+">"+"附件"+aName
												+"</A>");	
						}
					}
				}
			}
			htmlOut.addString (st.getEndString ());
		}
		else
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"","模版错误.","");

		htmlOut.outHtml ();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -