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

📄 mail1.java

📁 这是一个用Java 写成的查看邮件程序
💻 JAVA
字号:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Mail1{
	
	static Scanner sc, in;
	static BufferedWriter out;
	static String message="", line = "";
	static int newest;
	static boolean con = false, start=false;
	static Socket soc;
	static StringBuffer sb = new StringBuffer();
	
	public static int stat(){
		sb.setLength(0);
		message = "STAT";
		try{
		sendmessage(message);
		line = in.nextLine();
		String abc = "";
		System.out.println(line);
		abc = line.substring(line.indexOf(" ")+1, line.indexOf(" ", line.indexOf(" ")+1));
		System.out.println(abc);
		newest = Integer.parseInt(abc);
		}catch (Exception e){e.printStackTrace();};

		return newest;
	}
	
	public static boolean viewm(String no){
		start = false;
		sb.setLength(0);
		sendmessage("retr " + no);
		
		while(!(line = in.nextLine()).equals(".")){
			if (line.startsWith("-ERR")){
				sb.append("Mail no is not correct!!!\nPlease re-enter.");
				return false;
			}
			if (line.startsWith("Date:")){
				start = true;
			}
			if (start == true)
				sb.append(line + "\n");	
		}
		return true;
	}
	
	public static boolean delem(String no){
		sb.setLength(0);
		sendmessage("dele " + no);
			if (line.startsWith("-ERR")){
				sb.append("Mail no is not correct!!!\nPlease re-enter.");
				return false;
			}
			line = in.nextLine();
			sb.append("The mail is deleted.");
		return true;
		
	}
	public static void connect(String hostname, String username, String password, JLabel change, FirstMail p){

		try{
			soc = new Socket(hostname, 110);
			
			sc = new Scanner(System.in);
			in = new Scanner(soc.getInputStream());
			out = new BufferedWriter(new OutputStreamWriter(soc.getOutputStream()));
			
			System.out.println("SERVER>" + in.nextLine());
			
			message = "USER " + username;
			sendmessage(message);
			line = in.nextLine();
			if (line.startsWith("+OK") == false){
				change.setText("<html><font color=red>Connection failed!!!</font></html>");
				return;
			}

			message = "PASS " + password;
			sendmessage(message);	
			line = in.nextLine();
			if (line.startsWith("+OK") == false){
				change.setText("<html><font color=red>Connection failed!!!</font></html>");
				return;
			}

			change.setText("Connection is successful!!");
			con = true;			
		}
		catch (UnknownHostException uhe){
			change.setText("Host cannot be found!!!");
		}
		catch (SocketException se){
			System.out.println("Socket cannot be created!!!");
		}
		catch (IOException ioe){
			System.out.println("I/O Error!!");
		}
		catch (Exception e){
			System.out.println(e);
			Mail1.con = false;
		}
	}
	
	public static void disconnect(){
		try{
			in.close();
			out.close();
			soc.close();
			con = false;
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	
	public static void sendmessage(String message){
		try{
			out.write(message + "\r\n");
			out.flush();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}

⌨️ 快捷键说明

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