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

📄 newsgroup.java

📁 这是个JAVA开发的WEB邮箱
💻 JAVA
字号:
/* * Newsgroup.java * Copyright (C) 1999 dog <dog@dog.net.uk> *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. *  * This library 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 * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *  * You may retrieve the latest version of this library from * http://www.dog.net.uk/knife/ */package dog.mail.nntp;import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.event.*;/** * The folder class implementing the NNTP mail protocol. * * @author dog@dog.net.uk * @version 1.2 */public class Newsgroup extends Folder {	String name;	int count = -1;	int first = -1;	int last = -1;	boolean postingAllowed = false;	boolean subscribed = false;	String newsrcline;	boolean open = false;	Article[] articles;	Date checkpoint;	/**	 * Constructor.	 */	protected Newsgroup(Store store, String name) {		super(store);		this.name = name;	}	/**	 * Constructor.	 */	protected Newsgroup(Store store, String name, int count, int first, int last) {		super(store);		this.name = name;		this.count = count;		this.first = first;		this.last = last;	}	/**	 * Returns the name of this folder.	 */	public String getName() {		return name;	}	/**	 * Returns the full name of this folder.	 */	public String getFullName() {		return getName();	}	/**	 * Returns the type of this folder.	 */	public int getType() throws MessagingException {		return HOLDS_MESSAGES;	}	/**	 * Indicates whether this folder exists.	 */	public boolean exists() throws MessagingException {		if (open) return true;		try {			open(READ_ONLY);			close(false);			return true;		} catch (MessagingException e) {			return false;		}	}	/**	 * Indicates whether this folder contains any new articles.	 */	public boolean hasNewMessages() throws MessagingException {		return getNewMessageCount()>0;	}	/**	 * Opens this folder.	 */	public void open(int mode) throws MessagingException {		if (open)			throw new MessagingException("Newsgroup is already open");		if (mode!=READ_ONLY)			throw new MessagingException("Newsgroup is read-only");		((NNTPStore)store).open(this);		open = true;		notifyConnectionListeners(ConnectionEvent.OPENED);			}	/**	 * Closes this folder.	 */	public void close(boolean expunge) throws MessagingException {		if (!open)			throw new MessagingException("Newsgroup is not open");        if (expunge) expunge();		((NNTPStore)store).close(this);		open = false;		notifyConnectionListeners(ConnectionEvent.CLOSED);	}	/**	 * Expunges this folder.	 */	public Message[] expunge() throws MessagingException {        throw new MessagingException("Newsgroup is read-only");		}	/**	 * Indicates whether this folder is open.	 */	public boolean isOpen() {		return open;	}	/**	 * Indicates whether this folder is subscribed.	 */	public boolean isSubscribed() {		return subscribed;	}	/**	 * Returns the permanent flags for this folder.	 */	public Flags getPermanentFlags() { return new Flags(); }		/**	 * Returns the number of articles in this folder.	 */	public int getMessageCount() throws MessagingException {		return getMessages().length;	}	/**	 * Returns the articles in this folder.	 */	public Message[] getMessages() throws MessagingException {		if (!open)			throw new MessagingException("Newsgroup is not open");        NNTPStore s = (NNTPStore)store;		if (articles==null)			articles = s.getArticles(this);		else { // check for new articles			Article[] nm = s.getNewArticles(this, checkpoint);			if (nm.length>0) {				Article[] m2 = new Article[articles.length+nm.length];				System.arraycopy(articles, 0, m2, 0, articles.length);				System.arraycopy(nm, 0, m2, articles.length, nm.length);				articles = m2;			}		}		checkpoint = new Date();        return articles;	}		/**	 * Returns the specified article in this folder.	 * Since NNTP articles are not stored in sequential order,	 * the effect is just to reference articles returned by getMessages().	 */	public Message getMessage(int msgnum) throws MessagingException {		return getMessages()[msgnum-1];	}		/**	 * NNTP folders are read-only.	 */	public void appendMessages(Message articles[]) throws MessagingException {		throw new MessagingException("Folder is read-only");	}	/**	 * Does nothing.	 */	public void fetch(Message articles[], FetchProfile fetchprofile) throws MessagingException {	}	// -- These must be overridden to throw exceptions --	/**	 * NNTP folders can't have parents.	 */	public Folder getParent() throws MessagingException {		throw new MessagingException("Newsgroup can't have a parent");	}	/**	 * NNTP folders can't contain subfolders.	 */	public Folder[] list(String s) throws MessagingException {		throw new MessagingException("Newsgroups can't contain subfolders");	}	/**	 * NNTP folders can't contain subfolders.	 */	public Folder getFolder(String s) throws MessagingException {		throw new MessagingException("Newsgroups can't contain subfolders");	}	/**	 * NNTP folders can't contain subfolders.	 */	public char getSeparator() throws MessagingException {		throw new MessagingException("Newsgroups can't contain subfolders");	}	/**	 * NNTP folders can't be created, deleted, or renamed.	 */	public boolean create(int i) throws MessagingException {		throw new MessagingException("Newsgroups can't be created");	}	/**	 * NNTP folders can't be created, deleted, or renamed.	 */	public boolean delete(boolean flag) throws MessagingException {		throw new MessagingException("Newsgroups can't be deleted");	}	/**	 * NNTP folders can't be created, deleted, or renamed.	 */	public boolean renameTo(Folder folder) throws MessagingException {		throw new MessagingException("Newsgroups can't be renamed");	}}

⌨️ 快捷键说明

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