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

📄 viewfolder.java

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

public class ViewFolder extends HttpServlet 
{
	String newMailImg = "<img src=\"/img/icon_email_new.gif\" width=14 height=14>";
	String oldMailImg = "<img src=\"/img/icon_email_read.gif\" width=14 height=14>";
	String attachImg = "<img src=\"/img/icon_email_att.gif\" width=14 height=14>";
	String noImg = "&nbsp;";
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException
    {
		doGet(request,response);
	}
	
	public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException
    {
		HtmlOut htmlOut = new HtmlOut (response);
		
		// 得到名字和口令
		String name="",pass;

		Person person = new Person();
		person.setName (CommonMethods.GetUserName(request));
		pass = CommonMethods.GetUserPass (request);
		if( person.getName ()==null || (!person.checkPassword(pass)) )
		{
	    	htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请先登录!","Login?action=reLog");
			htmlOut.outHtml();
			return;
		}
		
		String sFolder = CommonMethods.getParameterValue (request,"FOLDER");
		String sGetNew = CommonMethods.getParameterValue (request,"GETNEW");
		if( sFolder==null )
		{
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE  ,"",
								"没有此文件夹!",
								"");
			htmlOut.outHtml();
			return;
		}
		GetEmailInfo GM= new GetEmailInfo ();
		Vector fs= GM.ListMailFolder(person.getName (),pass);
		String sFID = getFolderID(fs,sFolder);

		//delete mail;
		String sDelMail = CommonMethods.getParameterValue (request,"Deletemail");
		if( sDelMail!=null ){
			GM.DelMail (person.getName (),pass,
						getRMailID(sDelMail)+"&FOLDER="+sFID );
		}
		
		//delete some mails ;
		String sDelMails = CommonMethods.getParameterValue (request,"DELETEMARKED");
		if( sDelMails!=null ){
			String[] smails = request.getParameterValues ("mailcheck");
			if( smails!=null)
				for( int i=0;i<smails.length;i++)
					GM.DelMail (person.getName (),pass,
								getRMailID(smails[i])+"&FOLDER="+sFID);
		}
		
		//move mails;
		String sMovMails = CommonMethods.getParameterValue (request,"MOVEMARKED");
		if( sMovMails!=null ){
			String sMFolder = CommonMethods.getParameterValue (request,"FOLDERTRANSFERLIST" );
			if( sMFolder!=null ){
				sMFolder = this.getFolderID(fs,sMFolder);
				String[] smails = request.getParameterValues ("mailcheck");
				if( smails!=null ){
					for( int i=0;i<smails.length;i++)
						GM.MoveMail( person.getName (),pass,
									 getRMailID(smails[i]),sMFolder);
				}
			}
		}
		
		Vector mails;
		
		if( sGetNew!=null ){
			mails=GM.getEmailInfoFromPerlCGI (person.getName (),pass);
		}
		else{
			mails=GM.ListMailsInFolder ( person.getName (),pass,sFID );
		}
		
		TemplateList tempList = CommonMethods.getViewFolderTemplate ();
		if(tempList!=null){
			SingleTemplate st = tempList.searchTemplate ("ROOT");
			String sKey;
			for( int i=0;i<st.getKeyNum ();i++){
				sKey=st.getKeyAt (i);
				htmlOut.addString(st.getStringAt (i));
				if( sKey .compareTo("cgi-path")==0 )
					htmlOut.addString (CommonMethods.sHostNameCGI);
				if( sKey.compareTo ("allfolders")==0 ){
					for( int j=0;j<fs.size ();j++){
						MailFolder mf = (MailFolder)fs.elementAt (j);
						htmlOut.addString( "<option value="+mf.sName+
										   ">"+mf.sName +"</option>");
					}
				}
				if( sKey.compareTo ("curFolder")==0 ){
					htmlOut.addString(sFolder);
				}
				if( sKey.compareTo ("folderID")==0 ){
					htmlOut.addString(sFID);
				}
				if( sKey.compareTo ("mails")==0 ){
					SingleTemplate st1 = tempList.searchTemplate ("folder");
					String sKey1;
					for(int j=0;j<mails.size ();j++){
						EmailInfo EM= (EmailInfo)mails.elementAt (j);
						for( int m=0;m<st1.getKeyNum ();m++){
							sKey1=st1.getKeyAt (m);
							htmlOut.addString(st1.getStringAt (m));
							if( sKey1 .compareTo("cgi-path")==0 )
								htmlOut.addString (CommonMethods.sHostNameCGI);
							if( sKey1.compareTo ("mailfrom")==0 )
								htmlOut.addString( EM.getFrom ());
							if( sKey1.compareTo ("maildate")==0 )
								htmlOut.addString( EM.getDate ());
							if( sKey1.compareTo ("mailbody")==0 )
								htmlOut.addString( EM.getSubject ());
							if( sKey1.compareTo ("mailsize")==0 )
								htmlOut.addString( EM.getSize ());
							if( sKey1.compareTo ("mailurl")==0 )
								htmlOut.addString( EM.getUrl () );
							if( sKey1.compareTo ("mailopenurl")==0 )
								htmlOut.addString( "ViewMail?mail="+
												   EM.getUrl () );
							if( sKey1.compareTo ("EmailImg")==0 ){
								if(EM.getNew() )
									htmlOut.addString (newMailImg);
								else
									htmlOut.addString (oldMailImg);
							}
							if( sKey1.compareTo ("AttachImg")==0 )
								if(EM.hasAttach() )
									htmlOut.addString (attachImg);
								else
									htmlOut.addString (noImg);	
							if( sKey1.compareTo ("mailFolder")==0 )
								htmlOut.addString (sFolder);
						}
						htmlOut.addString(st1.getEndString ());
					}
				}
				if( sKey.compareTo ("movefolders")==0 ){
					for( int j=0;j<fs.size ();j++){
						MailFolder mf = (MailFolder)fs.elementAt (j);
						if( mf.sName .compareTo (sFolder)!=0 )
							htmlOut.addString( "<option value="+mf.sName+
										   ">"+mf.sName +"</option>");
					}
				}
			}
			htmlOut.addString(st.getEndString ());
		}
		htmlOut.outHtml ();
				
	}

	String getFolderID( Vector allF , String sFolderName )
	{
		for( int i=0;i<allF.size ();i++)
			if( ((MailFolder)(allF.elementAt(i))).sName .compareTo (sFolderName)==0 )
				return ((MailFolder)(allF.elementAt(i))).sID ;
		return null;
	}

	String getRMailID( String sMail )
	{
		int nRealB = sMail.indexOf ("JAVAMAIL2:")+10;
		if( nRealB<10 ){
			return null;
		}
		return sMail.substring (nRealB,sMail.length ());
	}

}

⌨️ 快捷键说明

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