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

📄 folderview.java

📁 mail sent and revesive system jsp+mysql
💻 JAVA
字号:
package fengyun.Fastmail.beans;

import javax.servlet.http.HttpSession;
import java.util.Hashtable;
import fengyun.Fastmail.Maildir.*;
import javax.mail.*;

/**
 * 邮件夹相关信息存储
 * @author sanware & fengyun
 * @version 1.01
 */

public class FolderView {

	private static BeansConstants CONST = BeansConstants.getInstance();
	
	public static final int BYTE = 0;
	public static final int KBYTE = 1;
	public static final int MBYTE = 2;
	public static final int SUITEK = 3;
	public static final int SUITEM = 4;
	
	/**
	 * 邮件夹摘要视图集
	 */
	public Hashtable views = new Hashtable();
	
	/**
	 * 邮件夹列表
	 */
	public FolderList folderlist = null;

	/**
	 * 构造邮件夹视图
	 * @param folderlist 邮件夹列表
	 */
	public FolderView(HttpSession httpsession,FolderList folderlist) throws MessagingException {
		this.folderlist = folderlist;
		Store store = (MaildirStore)httpsession.getAttribute(CONST.FastmailStore);
		for(int i = 0;i < folderlist.lists.size();i++) {
			FolderSummary fs = (FolderSummary)folderlist.lists.get(i);
			MaildirFolder mf = (MaildirFolder)store.getFolder(fs.getName());
			if (!mf.isOpen()) mf.open(0);
			MaildirFolderSummary mfs = mf.getSummary();
			views.put(new Integer(fs.getIndex()),mfs);
		}
	}
	/**
	 * 返回消息数
	 * @param index 邮件夹索引
	 * @return int 消息数
	 */
	public int getMessageCount(int index) {
		MaildirFolderSummary mfs = (MaildirFolderSummary)views.get(new Integer(index));
		if (mfs != null) {
			return mfs.getMessageCount();
		}
		else {
			return 0;
		}
	}
	/**
	 * 返回新消息数
	 * @param index 邮件夹索引
	 * @return int 新消息数
	 */
	public int getNewMessageCount(int index) {
		MaildirFolderSummary mfs = (MaildirFolderSummary)views.get(new Integer(index));
		if (mfs != null) {
			return mfs.getNewMessageCount();
		}
		else {
			return 0;
		}
	}
	/**
	 * 返回总消息数
	 * @return int 总消息数
	 */
	public int getTotalMessageCount() {	
		int total = 0;
		for(int i = 0; i < folderlist.lists.size(); i++) {
			FolderSummary fs = (FolderSummary)folderlist.lists.get(i);
			MaildirFolderSummary mfs = (MaildirFolderSummary)views.get(new Integer(fs.getIndex()));
			if (mfs != null) {
				total += mfs.getMessageCount();
			}
		}
		return total;
	}
	/**
	 * 返回总新消息数
	 * @return int 总新消息数
	 */
	public int getTotalNewMessageCount() {
		int total = 0;
		for(int i = 0; i < folderlist.lists.size(); i++) {
			FolderSummary fs = (FolderSummary)folderlist.lists.get(i);
			MaildirFolderSummary mfs = (MaildirFolderSummary)views.get(new Integer(fs.getIndex()));
			if (mfs != null) {
				total += mfs.getNewMessageCount();
			}
		}
		return total;
	}
	/**
	 * 返回邮件夹大小
	 * @param index 邮件夹索引
	 * @return int 邮件夹大小(字符表示)
	 */
	public int getFolderSize(int index) {
		MaildirFolderSummary mfs = (MaildirFolderSummary)views.get(new Integer(index));
		if (mfs != null) {
			return (int)mfs.getSize();
		}
		else {
			return 0;
		}
	}
	/**
	 * 将邮件夹大小转换成适合的格式
	 * @param size 大小
	 * @param type 格式类型
	 * @return 字符表示的邮件夹大小
	 */
	public static String getSuitedSize(int size,int type) { //选择返回类型
		switch (type) {
		case BYTE : {
						return size + "Byte";
					}
		case KBYTE :{
						return (size / 1024) + "KB";
					}
		case MBYTE: {
						return (size / (1024 *1024)) + "MB";
					}
		case SUITEK:{
						return (size >= 1024) ? (size /1024) + "KB" : size + "Byte";
					}
		case SUITEM:{
						return (size >= 1024*1024) ? (size /(1024*1024)) + "MB" : ((size >= 1024) ? (size /1024) + "KB" : size + "Byte");
					}
		default: return String.valueOf(size);
		}
	}
	/**
	 * 邮件夹总使用
	 * @return int 信箱使用大小
	 */
	public int getTotalDiskUsed() {
		FolderSummary[] first = folderlist.getFolderSummarys(1);
		if (first == null) return 0;
		int total = 0;
		for(int i = 0; i < first.length; i++) {
			total += getFolderSize(first[i].getIndex());
		}
		return total;
	}
	/**
	 * 返回信箱可使用大小
	 * @return int 信箱可使用大小
	 */
	public int getTotalSize() {
		return folderlist.quotasize;
	}
}

⌨️ 快捷键说明

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