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

📄 message.java

📁 自己写的java版的mailclient
💻 JAVA
字号:
import java.util.*;
import java.text.*;
/**
 * Mail message 
 * format the mail message which consist of several parts
 * @author zyp03
 *
 */
public class Message {

	/* header and body*/
	public String headers;
	public String subject;
	public String body;
	/* sender and recipient*/
	private String from;
	private String to;
	/* static const data*/
	private static final String CRLF = "\r\n";
	
	/* create the message object */
	public Message(String from,String to,String subject,String text){
		/* construct the headers*/
		this.from = from.trim();
		this.to = to.trim();
		this.subject = subject;
		headers = "From: " + this.from + CRLF;
		headers += "To: " + this.to + CRLF;
		headers += "Subject: " + subject.trim() + CRLF;
		
		/* get the data info*/
		SimpleDateFormat format = new SimpleDateFormat(
				"EEE,dd MMM yyy HH:mm:ss 'GMT'" );
		String dateString = format.format(new Date());
		headers += "Date: " + dateString + CRLF;
		body = text;
	}
	/**
	 * get from ,client info
	 * @return address
	 */
	public String getFrom(){
		return from;
	}
	/**
	 * get to ,server info
	 * @return address 
	 */
	public String getTo(){
		return to;
	}
	/**
	 * to check whether the message is valid
	 * @return
	 */
	public boolean isValid(){
		int fromat = from.indexOf('@');
		int toat = to.indexOf('@');
		if(fromat<1||(from.length()-fromat)<=1){
			System.out.println("发送者地址错误");
			return false;
		}
		if(toat<1||(to.length()-toat)<1){
			System.out.println("接收者地址错误");
			return false;
		}
		if(fromat!= from.lastIndexOf('@')){
			System.out.println("发送者地址错误");
			return false;
		}
		if(toat!= to.lastIndexOf('@')){
			System.out.println("接收者地址错误");
			return false;
		}		
		return true;
	}
	/**
	 * over write the toString()
	 */
	public String toString(){
		String res;
		res = headers + CRLF;
		res += body;
		return res;
	}
   
	
	
}

⌨️ 快捷键说明

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