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

📄 pop3message.java

📁 mywork是rcp开发的很好的例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * POP3Message.java
 *
 * Copyright (C) 1998-2000 FreeBeans <freebeans@mub.biglobe.ne.jp>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Copyright (C) 1998-2000ꆼ FreeBeans <freebeans@mub.biglobe.ne.jp>
 *
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼFree Software Foundation 
 * ꆼꆼꆼꆼꆼGNU ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * GNU ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 *
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼGNU ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼFree Software Foundation, Inc., 675 Mass Ave,
 * Cambridge, MA 02139, USA ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
 */

package jp.gr.java_conf.roadster.net.pop;

import java.io.IOException;
import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Date;
import java.util.Enumeration;
import java.util.StringTokenizer;

import javax.activation.DataHandler;
import javax.mail.Address;
import javax.mail.Flags;
import javax.mail.IllegalWriteException;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.MimeMessage;

/**
 * POP3ꆼꆼꆼꆼꆼꆼꆼꆼ.
 * ꆼꆼꆼꆼꆼꆼ Read-only ꆼꆼꆼꆼsetXXX()ꆼꆼꆼꆼꆼꆼꆼ addXXX()
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.<BR>
 *
 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ{@link javax.mail.internet.MimeMessage MimeMessage}ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
 */
public class POP3Message extends MimeMessage {
	/**
	 * POP3Message ꆼ Read-only ꆼꆼꆼꆼsetXXX(), addXXX() 
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼMethodNotSupportedException
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 */
	private static final String READ_ONLY_ERROR_MESSAGE = "POP3Message is read-only";

	/**
	 * DateParser
	 */
	private static final DateParser dateParser = new DateParser();

	/**
	 * MessageIndex ꆼꆼꆼꆼꆼ
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ Object ꆼꆼꆼꆼꆼꆼ
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
	 */
	private Object internalID;
	
	/**
	 * MimeMessage ꆼꆼꆼꆼꆼꆼ flags ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
	 */
	private final Flags flags = null;
	
	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	private Date receivedDate;
	
	/**
	 * Contentꆼꆼꆼꆼ
	 */
	private int lineCount = -1;

	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 *
	 * @param	folder	POP3Folderꆼꆼꆼꆼꆼꆼꆼ.
	 * @param	msgnum	ꆼꆼꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	protected POP3Message(POP3Folder folder, int msgnum) throws MessagingException {
		super(folder, msgnum);
	}

	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 *
	 * @param	folder	POP3Folderꆼꆼꆼꆼꆼꆼꆼ.
	 * @param	in		ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 * @param	msgnum	ꆼꆼꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	protected POP3Message(POP3Folder folder, InputStream in, int msgnum) throws MessagingException {
		super(folder, in, msgnum);
	}
	
	/**
	 * From ꆼꆼꆼꆼꆼꆼꆼꆼ.
	 *
	 * @return	Fromꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	public Address[] getFrom() throws MessagingException {
		loadHeaders();
		return super.getFrom();
	}
	
	/**
	 * From ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param address	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setFrom(Address address) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * From ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setFrom() throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * From ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void addFrom(Address[] addresses) throws MessagingException {
		throw new javax.mail.IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * ꆼꆼꆼꆼꆼ.
	 *
	 * @param	type	ꆼꆼꆼꆼꆼ.(RecipientType.CC or RecipientType.BCC)
	 * @return	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	public Address[] getRecipients(Message.RecipientType type) throws MessagingException {
		loadHeaders();
		return super.getRecipients(type);
	}
	
	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 *
	 * @return	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	public Address[] getAllRecipients() throws MessagingException {
		loadHeaders();
		return super.getAllRecipients();
	}

	/**
	 * Recipients ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param type	ꆼꆼꆼꆼꆼ.
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setRecipients(Message.RecipientType type,
								Address[] addresses) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * Recipients ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param type	ꆼꆼꆼꆼꆼ.
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setRecipient(Message.RecipientType type, Address address) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * Recipients ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param type	ꆼꆼꆼꆼꆼ.
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * Recipient ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param type	ꆼꆼꆼꆼꆼ.
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void addRecipient(Message.RecipientType type, Address address) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}

	/**
	 * Reply-to ꆼꆼꆼ.
	 *
	 * @return	Reply-to
	 */
	public Address[] getReplyTo() throws MessagingException {
		loadHeaders();
		return super.getReplyTo();
	}
	
	/**
	 * Reply-To ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param addresses	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setReplyTo(Address[] addresses) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * Subject ꆼꆼꆼ.
	 *
	 * @return Subject.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public String getSubject() throws MessagingException {
		loadHeaders();
		return super.getSubject();
	}
	
	/**
	 * Subject ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param subject	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setSubject(String subject) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * Subject ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param subject	ꆼꆼꆼꆼꆼ.
	 * @param charset	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setSubject(String subject, String charset) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * ꆼꆼꆼꆼꆼꆼꆼ.
	 *
	 * @return	ꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	public Date getSentDate() throws MessagingException {
		loadHeaders();
		return super.getSentDate();
	}
	
	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param date	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setSentDate(Date date) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	/**
	 * ꆼꆼꆼꆼꆼꆼꆼꆼ
	 *
	 * @return	ꆼꆼꆼꆼ.ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ null.
	 * @throws	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ.
	 */
	public Date getReceivedDate() throws MessagingException {
		loadHeaders();
		if (receivedDate == null) {
			String rcvd[] = getHeader("Received");	// ꆼꆼꆼꆼꆼ Received: ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
			if (rcvd != null && rcvd.length > 0) {
				StringTokenizer st = new StringTokenizer(rcvd[0], ";");
				if (st.countTokens() >= 2) {
					st.nextToken();
					String date = st.nextToken();
					receivedDate = dateParser.parse(date);
				}
			}
		}
		return receivedDate;
	}
	
	public int getSize() throws MessagingException {
		loadData();
		return super.getSize();
	}
	
	/**
	 * Contentꆼꆼꆼꆼꆼꆼꆼ
	 *
	 * @return	ꆼꆼꆼꆼꆼꆼꆼꆼꆼ -1ꆼ
	 * @throws	javax.mail.MessagingException	ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
	 */
	public int getLineCount() throws MessagingException {
		loadData();
		try {
			if (lineCount == -1) {
				Object o = super.getContent();
				// ꆼꆼꆼ this.getContent() ꆼꆼꆼꆼꆼꆼꆼSEEN ꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼꆼ
				if (o instanceof String) {
					lineCount = 0;
					LineNumberReader lcr = new LineNumberReader(new StringReader((String) o));
					while (lcr.readLine() != null) {
						lineCount++;
					}
					lcr.close();
				}
			}
		} catch (IOException ioe) {
			throw new MessagingException("IOException", ioe);
		}
		return lineCount;
	}
	
	/**
	 * Content-type ꆼꆼꆼ.
	 * "text" ꆼꆼꆼꆼꆼꆼꆼꆼ "text/plain" ꆼꆼꆼ.
	 *
	 * @return	Content-type. "text" ꆼ "text/plain" ꆼꆼꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.MessagingException	
	 */
	public String getContentType() throws MessagingException {
		loadData();
		String ctype = super.getContentType();
		if (ctype.equals("text")) {
			ctype = "text/plain";
		}
		return ctype;
	}
	
	public boolean isMimeType(String mimeType) throws MessagingException {
		loadData();
		return super.isMimeType(mimeType);
	}
	
	public String getDisposition() throws MessagingException {
		loadData();
		return super.getDisposition();
	}
	
	/**
	 * Content-Disposition ꆼꆼꆼꆼꆼ.
	 * POP3MessageꆼRead-only ꆼꆼꆼꆼꆼꆼꆼꆼꆼ throw ꆼꆼꆼ.
	 *
	 * @param disposition	ꆼꆼꆼꆼꆼ.
	 * @exception	javax.mail.IllegalWriteException	ꆼꆼ throw ꆼꆼꆼ.
	 */
	public void setDisposition(String disposition) throws MessagingException {
		throw new IllegalWriteException(READ_ONLY_ERROR_MESSAGE);
	}
	
	public String getEncoding() throws MessagingException {
		loadData();
		return super.getEncoding();
	}
	
	/**
	 * Content-ID ꆼꆼꆼ.
	 *

⌨️ 快捷键说明

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