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

📄 messagecompose.java

📁 jsp全部邮件系统 jsp全部邮件系统
💻 JAVA
字号:
package fengyun.Fastmail.beans;

import javax.mail.*;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import java.sql.ResultSet;
import fengyun.Fastmail.util.ToolKit;

/**
 * 发送消息
 */

public class MessageCompose {
	
	private static BeansConstants CONST = BeansConstants.getInstance();
	
	private int FolderIndex = CONST.sntbox;
	private String FolderName = null;
	private String action = null;
	private String to = null;
	private String cc = null;
	private String bcc = null;
	private String subject = null;
	private String body = null;
	private boolean save = false;
	private String sign = null;

	/**
	 * 构造
	 */
	public MessageCompose(HttpServletRequest request) throws MessagingException {
		action = request.getParameter(CONST.action);
		HttpSession httpsession = request.getSession(false);
		if (action == null) action = CONST.send;

		try {
			String userid = (String) httpsession.getAttribute(CONST.FastmailUserid);
			String sql = "select signature from profile where userid = '" + userid + "'";
			Mysql mysql = new Mysql();
			ResultSet RS = mysql.executeQuery(sql);
			if (RS != null && RS.next()) {
				sign = RS.getString(1);
				if (sign == null) sign = "";
				else {
					sign = ToolKit.Replace(sign,'\"',"\\\"");
					sign = ToolKit.Replace(sign,'\'',"\\\'");
					sign = ToolKit.Replace(sign,'\n',"\\n");
					sign = ToolKit.Replace(sign,'\r',"\\r");
				}
			}
			RS = null;
			mysql.close();
			mysql = null;
		}
		catch(Exception e) {
			System.out.println(e.getMessage());
			sign = "";
		}
		if (CONST.send.equals(action)) {	//发送
			to = "";
			cc = "";
			bcc = "";
			subject = "";
			body = "";
			FolderIndex = CONST.sntbox;
			FolderName = CONST.sntname;
		}
		else if (CONST.address.equals(action)) {	//发送
			to = request.getParameter(CONST.to);
			if (to == null) to = "";
			cc = "";
			bcc = "";
			subject = "";
			body = "";
			FolderIndex = CONST.sntbox;
			FolderName = CONST.sntname;
		}
		else if (CONST.attach.equals(action) || CONST.save.equals(action)) {
			to = (String)httpsession.getAttribute(CONST.to);
			if (to == null) to = "";
			httpsession.removeAttribute(CONST.to);
			cc = (String)httpsession.getAttribute(CONST.cc);
			if (cc == null) cc = "";
			httpsession.removeAttribute(CONST.cc);
			bcc = (String)httpsession.getAttribute(CONST.bcc);
			if (bcc == null) bcc = "";
			httpsession.removeAttribute(CONST.bcc);
			subject = (String)httpsession.getAttribute(CONST.subject);
			if (subject == null) subject = "";
			httpsession.removeAttribute(CONST.subject);
			body = (String)httpsession.getAttribute(CONST.body);
			if (body == null) body = "";
			httpsession.removeAttribute(CONST.body);
			String strTemp = (String)httpsession.getAttribute(CONST.save);
			if ("true".equals(strTemp)) save = true;
			else save = false;
			httpsession.removeAttribute(CONST.save);
			if (!CONST.save.equals(action)) {
				strTemp = (String)httpsession.getAttribute(CONST.folderid);
				if (strTemp != null) {
					FolderIndex = Integer.parseInt(strTemp);
					FolderView folderview = (FolderView)httpsession.getAttribute(CONST.FastmailFolderView);
					FolderName = folderview.folderlist.getViewName(FolderIndex);				
				}
				else { 
					FolderIndex = CONST.sntbox;
					FolderName = CONST.sntname;
				}
			}
			else {
				FolderIndex = CONST.srcbox;
				FolderName = CONST.sntname;
			}
		}
		else {
			MessageView mv = new MessageView(request);

			FolderIndex = mv.getFolderIndex();
			FolderName = mv.getFolderName();
			subject = mv.getSubject();
			body = mv.getBody();

			if (CONST.reply.equals(action)) {
				subject = CONST.wordreply + subject;
				to = mv.getFrom();
				cc = "";
				bcc = "";
				body = fengyun.Fastmail.util.ToolKit.Replace(body,'\n',"\n> ");
				body = "> " + body;
			}
			else if (CONST.forward.equals(action)) {
				subject = CONST.wordforward + subject;
				to = "";
				cc = "";
				bcc = "";
				try {
					MessageForward forward = new MessageForward(request);
					forward = null;
				}
				catch(IOException ioe) {
					ioe.printStackTrace();
					throw new MessagingException("IO ERROR");
				}
			}
			else if (CONST.replyall.equals(action)) {
				subject = CONST.wordreply + subject;
				to = mv.getFrom();
			        cc = mv.getCC();		
				bcc = "";
				body = fengyun.Fastmail.util.ToolKit.Replace(body,'\n',"\n> ");
				body = "> " + body;
			}
			mv = null;
		}
	}
	public String getTo() {
		return to;
	}
	public String getCC() {
		return cc;
	}
	public String getBCC() {
		return bcc;
	}
	public String getBody() {
		return body;
	}
	public boolean isSave() {
		return save;
	}
	public String getSubject() {
		return subject;
	}
	public String getAction() {
		return action;
	}
	public int getFolderIndex() {
		return FolderIndex;
	}
	public String getFolderName() {
		return FolderName;
	}
	public String getSign() {
		return sign;
	}
	/**
	 * 返回附件信息
	 */
	public String getAttachment(HttpSession httpsession) {
		if (CONST.save.equals(action) || CONST.attach.equals(action) || CONST.forward.equals(action)) {
		    int size = 0;
		    Object obj = httpsession.getAttribute(CONST.FastmailAttach);
		    if (obj != null) {
		        Vector aVector = (Vector)obj;
		        String strAttachment = "";
		        for(int i = 0;i < aVector.size();i++) {
		            Attachment ai = (Attachment)aVector.elementAt(i);
		            if (!ai.isAttached()) continue;
					size += ai.getSize();
		            strAttachment = strAttachment + ";" + ai.getFileName();
		        }
		        if (size > 0) strAttachment = CONST.wordattach  + FolderView.getSuitedSize(size,FolderView.SUITEK) + " " + strAttachment;
		        return strAttachment;
		    }
			else return "";
		}
		else return "";
	}
}

⌨️ 快捷键说明

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