@Override
	public void run() {
		/**
		 * ͨtelnetʱṩصʴϢ
		 */
		startLinkOk();
		int time = 0; 
		//ʹѭʾʾỰ
		while(true){
			/////////////////////foxmailϿʱرSocketException:Connection reset
			String mess;
			try {
				mess = br.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
//				e.printStackTrace();
				Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
				return ;
			}
			//Ϊnullʱ쳣Ϊʾ
			if(mess == null){
				//ϵͳδ֪ж///////////д־ļý
				Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
				return ;
			}
			//ȡһַתΪСдʽ޳ͷͽβĿմ
			mess = mess.toLowerCase().trim();
				System.err.println(mess);
			if(mess.equalsIgnoreCase("noop")){
				//ղokӦ
				doOk();
			}else if(mess.startsWith("ehlo") || mess.startsWith("helo")){//ehloheloͷ
				//ESMTPЭ
				if(mess.equals("ehlo")){
					Util.println(ps, "501 #5.0.0 EHLO requires domain address");
				}else{
					//ȡϢ
					String connectServer = mess.split(" ")[1];
					once = OnceClass.getOnce();
					localService = once.getLocalServiceInfo();
					//ȡuserMap
					userMap = once.getUserMap();
					//ͨͻͨš
					if(!connectServer.contains(".")){
						Util.println(ps, "250-"+Util.getLocalHostName());
						Util.println(ps, "250-mail");
						Util.println(ps, "250-8BITMIME");
						Util.println(ps, "250-SIZE "+Util.getFileSize());//ļеĴС
						Util.println(ps, "250-AUTH PLAIN LOGIN");
						Util.println(ps, "250 AUTH=PLAIN LOGIN");
									
						//ȡָ
						String subMess;
						try {
							subMess = br.readLine();
						} catch (IOException e) {
							// TODO Auto-generated catch block
//							e.printStackTrace();
							Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
							return ;
						}
						if(subMess == null){
							//ϵͳδ֪ж///////////д־ļý
							Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
							return ;
						}
						subMess = subMess.toLowerCase().trim();
    							System.err.println(subMess);
						if(subMess.equals("auth login")){
							//û
							Util.println(ps, "334 VXNlcm5hbWU6");
							String userNameBase64 = Util.getInput(br);
							if(userNameBase64 == null){
								//ϵͳδ֪ж///////////д־ļý
								Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
								return ;
							}
							//ܺû
							String userName = Base64Coder.deCoder(userNameBase64);
//								System.err.println(userName);
							//
							Util.println(ps, "334 UGFzc3dvcmQ6");
							String userPassBase64 = Util.getInput(br);
							if(userPassBase64 == null){
								//ϵͳδ֪ж///////////д־ļý
								Util.saveLog(Util.getClientInfo(client)+"SMTP쳣жϡ");
								return ;
							}
							//ܺû
							String userPass = Base64Coder.deCoder(userPassBase64);
//								System.err.println(userPass);
							//жûǷƥ
							if(userMap.containsKey(userName) && userMap.get(userName).getUserPass().equals(userPass)){
								//¼ɹ
								doLoginOK();
								Util.saveLog(userName+Util.getClientInfo(client)+"¼SMTPɹ");
								doOk();
								//¼ɹͨûʼ
								sendLocalMail(userName);
							}else{//ûƥʱ
								//û
								Util.println(ps, "535 #5.7.0 Authentication failed");
							}
						//auth loginָͬ
						}else if(subMess.equals("noop")){
							//ղ
							doOk();
						}else if(subMess.equals("quit")){
							//ֹʼỰý̡
							doQuit();
							Util.saveLog(Util.getClientInfo(client)+"SMTP˳");
							return ;
						}else{
							//ָ
							doWrongCommand();
						}
					}else{
						//ͻ˵ͨš
						receForeignMail(connectServer);
					}
				}//ehloͷ
			}else if(mess.equals("quit")){
				//ֹʼỰý̡
				doQuit();
				Util.saveLog(Util.getClientInfo(client)+"SMTP˳");
				return ;
			}else{
				doWrongCommand();
			}
		}
	}