@Override
	public void run() {
		// TODO Auto-generated method stub
		startLinkOk();
		//ѭжݡ
		while(true){
			try {
				String mess = br.readLine();
				if(mess == null){
					Util.saveLog(Util.getClientInfo(client)+"POPжϡ");
					return ;
				}
				//תΪСд޳ո
				mess = mess.toLowerCase().trim();
				System.err.println(mess);
				if(mess.equalsIgnoreCase("noop")){
					//ղ
					doOk();
				}else if(mess.equalsIgnoreCase("quit")){
					//˳
					doOk();
					Util.saveLog(Util.getClientInfo(client)+"˳POP");
					//˳
					return ;
				}else if(mess.equalsIgnoreCase("ehlo") || mess.equalsIgnoreCase("helo") || mess.equalsIgnoreCase("ehlo "+Util.getLocalHostName())){
					//
					doEhlo();
				}else if(mess.equalsIgnoreCase("auth login")){
					//û¼
					ps.println("334 VXNlcm5hbWU6");
					String userNameBASE64 = br.readLine();
					if(userNameBASE64 == null){
						Util.saveLog(Util.getClientInfo(client)+"ȡûʱPOPжϡ");
						return;
					}
					System.out.println("userNameBASE64"+userNameBASE64);
					//¼ɹ
					ps.println("334 UGFzc3dvcmQ6");
					String userPassBASE64 = br.readLine().toLowerCase().trim();
					if(userPassBASE64 == null){
						Util.saveLog(Util.getClientInfo(client)+"ȡûʱPOPжϡ");
						return ;
					}
					String userName = Base64Coder.deCoder(userNameBASE64);
					String userPass = Base64Coder.deCoder(userPassBASE64);
					once = OnceClass.getOnce();
					userMap = once.getUserMap();
					if(userMap.containsKey(userName) && userMap.get(userName).getUserPass().equals(userPass)){
						//¼ɹ
						ps.println("235 authentication successfully");
						Util.saveLog(userName+Util.getClientInfo(client)+"¼ɹPOP");
						//¼ɹز//ʼĲ
						if(!receiveMail(userName)){
							Util.saveLog(Util.getClientInfo(client)+"쳣ж˳POP");
							return ;
						}else{
							Util.saveLog(Util.getClientInfo(client)+"˳POP");
							return ;
						}
					}else{
						//¼ʧ
						ps.println("535 authentication failed");
					}
				}else if(mess.startsWith("user ")){
					//ȡû
					String userName = mess.replace("user ", "");
					String mailName = Util.getMailName(userName);
					//ɹ
					doOk();
					//ȡ
					String passMess = br.readLine();
					if(passMess == null){
						Util.saveLog(Util.getClientInfo(client)+"ڻȡʱжPOP");
						return ;
					}
					//ȡ
					int index = passMess.indexOf(" ");
					String userPass = passMess.substring(index+1);
					
					once = OnceClass.getOnce();
					userMap = once.getUserMap();
					//ûͬʱƥ
					if(userMap.containsKey(mailName) && userMap.get(mailName).getUserPass().equals(userPass)){
						//֤ɹ
						ps.println("+OK 2 messages");
						Util.saveLog(userName+Util.getClientInfo(client)+"ɹ¼POP");
						//֤ɹز
						if(!receiveMail(mailName)){
							Util.saveLog(userName+Util.getClientInfo(client)+"POP쳣жϡ");
							return ;
						}else{
							//˳
							Util.saveLog(userName+Util.getClientInfo(client)+"˳POP");
							return ;
						}
					}else{
						ps.println("-ERR authorization failed");//롣
					}
				}else{
					ps.println("-ERR command not recognized");
//					System.out.println("wrong Command.");
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
//				e.printStackTrace();
				Util.saveLog(Util.getClientInfo(client)+"POPжϡ");
				return ;
			}
		}
	}