diff --git a/mozilla/grendel/storage/nntp/Makefile b/mozilla/grendel/storage/nntp/Makefile deleted file mode 100644 index 245a28e67bb..00000000000 --- a/mozilla/grendel/storage/nntp/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the Grendel mail/news client. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1997 -# Netscape Communications Corporation. All Rights Reserved. - -SUBDIRS= \ - dog \ - $(NULL) - -include ../../rules.mk diff --git a/mozilla/grendel/storage/nntp/dog/mail/Makefile b/mozilla/grendel/storage/nntp/dog/mail/Makefile deleted file mode 100644 index ce9bde0738b..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the Grendel mail/news client. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1997 -# Netscape Communications Corporation. All Rights Reserved. - -SUBDIRS= \ - nntp \ - util \ - $(NULL) - - -include ../../../../rules.mk diff --git a/mozilla/grendel/storage/nntp/dog/mail/nntp/Article.java b/mozilla/grendel/storage/nntp/dog/mail/nntp/Article.java deleted file mode 100644 index 677b46ac9a9..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/nntp/Article.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Article.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.mail.nntp; - -import java.io.*; -import java.util.*; -import javax.activation.DataHandler; -import javax.mail.*; -import javax.mail.internet.*; - -/** - * The message class implementing the NNTP mail protocol. - * - * @author dog@dog.net.uk - * @version 0.3 - */ -public class Article extends MimeMessage { - - /** - * The unique message-id of this message. - */ - protected String messageId; - - // Whether the headers for this article were retrieved using xover. - boolean xoverHeaders = false; - - /** - * Creates an NNTP message with the specified article number. - */ - protected Article(Newsgroup folder, int msgnum) throws MessagingException { - super(folder, msgnum); - checkNewsrc(folder.newsrcline); - } - - /** - * Creates an NNTP message with the specified message-id. - */ - protected Article(Newsgroup folder, String messageId) throws MessagingException { - super(folder, 0); - this.messageId = messageId; - checkNewsrc(folder.newsrcline); - } - - // Adds headers retrieved by an xover call to this article. - void addXoverHeaders(InternetHeaders headers) { - if (headers==null) { - this.headers = headers; - xoverHeaders = true; - } - } - - void checkNewsrc(String newsrcline) throws MessagingException { - if (newsrcline!=null) { - int articlenum = getArticleNumber(); - StringTokenizer st = new StringTokenizer(newsrcline, ","); - while (st.hasMoreTokens()) { - String token = st.nextToken(); - int hyphenIndex = token.indexOf('-'); - if (hyphenIndex>-1) { // range - try { - int lo = Integer.parseInt(token.substring(0, hyphenIndex)); - int hi = Integer.parseInt(token.substring(hyphenIndex+1)); - if (articlenum>=lo && articlenum<=hi) { - setFlag(Flags.Flag.SEEN, true); - return; - } - } catch (NumberFormatException e) { - } - } else { // single number - try { - int num = Integer.parseInt(token); - if (articlenum==num) { - setFlag(Flags.Flag.SEEN, true); - return; - } - } catch (NumberFormatException e) { - } - } - } - } - } - - int getArticleNumber() { - return getMessageNumber(); - } - - /** - * Returns the message content. - */ - public Object getContent() throws IOException, MessagingException { - if (content==null) content = ((NNTPStore)folder.getStore()).getContent(this); - - /* - // check for embedded uuencoded content - BufferedReader reader = new BufferedReader(new InputStreamReader(ByteArrayInputStream(content))); - Hashtable parts = null; - try { - StringBuffer buffer = new StringBuffer(); - int count = 1; - for (String line = reader.readLine(); line!=null; line = reader.readLine()) { - if (line.startsWith("begin")) { - StringTokenizer st = new StringTokenizer(line, " "); - if (st.countTokens()==3) { - String ignore = st.nextToken(); - int lines = Integer.parseInt(st.nextToken()); - String name = st.nextToken(); - String contentType = guessContentType(name, count++); - if (contentType!=null) { - parts = new Hashtable(); - if (buffer.length>0) { - parts.put("text/plain; partid="+(count++), buffer.toString()); - buffer = new StringBuffer(); - } - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - - } - } - } else - buffer.append(line); - } - } catch (NumberFormatException e) { - } finally { - reader.close(); - } - */ - return super.getContent(); - } - - String guessContentType(String name, int count) { - String lname = name.toLowerCase(); - if (lname.indexOf(".jpg")>-1 || lname.indexOf(".jpeg")>-1) - return "image/jpeg; name=\""+name+"\", partid="+count; - if (lname.indexOf(".gif")>-1) - return "image/gif; name=\""+name+"\", partid="+count; - if (lname.indexOf(".au")>-1) - return "audio/basic; name=\""+name+"\", partid="+count; - return null; - } - - /** - * Returns the from address. - */ - public Address[] getFrom() throws MessagingException { - NNTPStore s = (NNTPStore)folder.getStore(); - if (xoverHeaders && !s.validateOverviewHeader("From")) headers = null; - if (headers==null) headers = s.getHeaders(this); - - Address[] a = getAddressHeader("From"); - if (a==null) a = getAddressHeader("Sender"); - return a; - } - - /** - * Returns the recipients' addresses for the specified RecipientType. - */ - public Address[] getRecipients(RecipientType type) throws MessagingException { - NNTPStore s = (NNTPStore)folder.getStore(); - if (xoverHeaders && ! s.validateOverviewHeader(getHeaderKey(type))) headers = null; - if (headers==null) headers = s.getHeaders(this); - - if (type==RecipientType.NEWSGROUPS) { - String key = getHeader("Newsgroups", ","); - if (key==null) return null; - return NewsAddress.parse(key); - } else { - return getAddressHeader(getHeaderKey(type)); - } - } - - /** - * Returns all the recipients' addresses. - */ - public Address[] getAllRecipients() throws MessagingException { - if (headers==null || xoverHeaders) headers = ((NNTPStore)folder.getStore()).getHeaders(this); - - return super.getAllRecipients(); - } - - /** - * Returns the reply-to address. - */ - public Address[] getReplyTo() throws MessagingException { - NNTPStore s = (NNTPStore)folder.getStore(); - if (xoverHeaders && !s.validateOverviewHeader("Reply-To")) headers = null; - if (headers==null) headers = s.getHeaders(this); - - Address[] a = getAddressHeader("Reply-To"); - if (a==null) a = getFrom(); - return a; - } - - /** - * Returns the subject line. - */ - public String getSubject() throws MessagingException { - NNTPStore s = (NNTPStore)folder.getStore(); - if (xoverHeaders && !s.validateOverviewHeader("Subject")) headers = null; - if (headers==null) headers = s.getHeaders(this); - - return super.getSubject(); - } - - /** - * Returns the sent date. - */ - public Date getSentDate() throws MessagingException { - NNTPStore s = (NNTPStore)folder.getStore(); - if (xoverHeaders && !s.validateOverviewHeader("Date")) headers = null; - if (headers==null) headers = s.getHeaders(this); - - return super.getSentDate(); - } - - /** - * Returns the received date. - */ - public Date getReceivedDate() throws MessagingException { - if (headers==null || xoverHeaders) headers = ((NNTPStore)folder.getStore()).getHeaders(this); - - return super.getReceivedDate(); - } - - /** - * Returns an array of addresses for the specified header key. - */ - protected Address[] getAddressHeader(String key) throws MessagingException { - String header = getHeader(key, ","); - if (header==null) return null; - try { - return InternetAddress.parse(header); - } catch (AddressException e) { - String message = e.getMessage(); - if (message!=null && message.indexOf("@domain")>-1) - try { - return parseAddress(header, ((NNTPStore)folder.getStore()).getHostName()); - } catch (AddressException e2) { - throw new MessagingException("Invalid address: "+header, e); - } - throw e; - } - } - - /** - * Makes a pass at parsing internet addresses. - */ - protected Address[] parseAddress(String in, String defhost) throws AddressException { - Vector v = new Vector(); - for (StringTokenizer st = new StringTokenizer(in, ","); st.hasMoreTokens(); ) { - String s = st.nextToken().trim(); - try { - v.addElement(new InternetAddress(s)); - } catch (AddressException e) { - int index = s.indexOf('>'); - if (index>-1) { // name
- StringBuffer buffer = new StringBuffer(); - buffer.append(s.substring(0, index)); - buffer.append('@'); - buffer.append(defhost); - buffer.append(s.substring(index)); - v.addElement(new InternetAddress(buffer.toString())); - } else { - index = s.indexOf(" ("); - if (index>-1) { // address (name) - StringBuffer buffer = new StringBuffer(); - buffer.append(s.substring(0, index)); - buffer.append('@'); - buffer.append(defhost); - buffer.append(s.substring(index)); - v.addElement(new InternetAddress(buffer.toString())); - } else // address - v.addElement(new InternetAddress(s+"@"+defhost)); - } - - } - } - Address[] a = new Address[v.size()]; v.copyInto(a); - return a; - } - - /** - * Returns the header key for the specified RecipientType. - */ - protected String getHeaderKey(RecipientType type) throws MessagingException { - if (type==RecipientType.TO) - return "To"; - if (type==RecipientType.CC) - return "Cc"; - if (type==RecipientType.BCC) - return "Bcc"; - if (type==RecipientType.NEWSGROUPS) - return "Newsgroups"; - throw new MessagingException("Invalid recipient type: "+type); - } - - // -- Need to override these since we are read-only -- - - /** - * NNTP messages are read-only. - */ - public void setFrom(Address address) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void addFrom(Address a[]) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setRecipients(javax.mail.Message.RecipientType recipienttype, Address a[]) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void addRecipients(javax.mail.Message.RecipientType recipienttype, Address a[]) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setReplyTo(Address a[]) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setSubject(String s, String s1) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setSentDate(Date date) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setDisposition(String s) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setContentID(String s) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setContentMD5(String s) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setDescription(String s, String s1) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - - /** - * NNTP messages are read-only. - */ - public void setDataHandler(DataHandler datahandler) throws MessagingException { - throw new IllegalWriteException("Article is read-only"); - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/mail/nntp/Makefile b/mozilla/grendel/storage/nntp/dog/mail/nntp/Makefile deleted file mode 100644 index efc4f962ee8..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/nntp/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the Grendel mail/news client. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1997 -# Netscape Communications Corporation. All Rights Reserved. - -SUBDIRS= \ - $(NULL) - -SRCS= \ - Article.java \ - Newsgroup.java \ - NNTPStore.java \ - $(NULL) - - -include ../../../../../rules.mk diff --git a/mozilla/grendel/storage/nntp/dog/mail/nntp/NNTPStore.java b/mozilla/grendel/storage/nntp/dog/mail/nntp/NNTPStore.java deleted file mode 100644 index 5be049be5df..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/nntp/NNTPStore.java +++ /dev/null @@ -1,1021 +0,0 @@ -/* - * NNTPStore.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): Mario Camou . - */ - -package dog.mail.nntp; - -import java.io.*; -import java.net.*; -import java.util.*; -import javax.mail.*; -import javax.mail.event.*; -import javax.mail.internet.*; -import dog.mail.util.*; -import dog.util.*; - -/** - * The storage class implementing the NNTP Usenet news protocol. - * - * @author dog@dog.net.uk - * @version 0.3 - */ -public class NNTPStore extends Store implements StatusSource { - - /** - * The default NNTP port. - */ - public static final int DEFAULT_PORT = 119; - - static int fetchsize = 1024; - - Socket socket; - CRLFInputStream in; - CRLFOutputStream out; - String hostname; - - String response; - - static final int HELP = 100; - static final int READY = 200; - static final int READ_ONLY = 201; - static final int STREAMING_OK = 203; - static final int CLOSING = 205; - static final int GROUP_SELECTED = 211; // or list of article numbers follows - static final int LISTING = 215; // list of newsgroups follows - static final int ARTICLE_RETRIEVED_BOTH = 220; - static final int ARTICLE_RETRIEVED_HEAD = 221; // or header follows - static final int ARTICLE_RETRIEVED_BODY = 222; - static final int ARTICLE_RETRIEVED = 223; - static final int LISTING_OVERVIEW = 224; - static final int LISTING_ARTICLES = 230; // list of new articles by message-id follows - static final int LISTING_NEW = 231; // list of new newsgroups follows - static final int ARTICLE_POSTED = 240; // article posted ok - static final int PASSWORD_OK = 281; // Authentication OK - static final int SEND_ARTICLE = 340; // send article to be posted. End with . - static final int PASS_REQ = 381; // PASS required (after sending user) - static final int SERVICE_DISCONTINUED = 400; - static final int NO_SUCH_GROUP = 411; - static final int NO_GROUP_SELECTED = 412; // no newsgroup has been selected - static final int NO_ARTICLE_SELECTED = 420; // no current article has been selected - static final int NO_SUCH_ARTICLE_IN_GROUP = 423; // no such article number in this group - static final int NO_SUCH_ARTICLE = 430; // no such article found - static final int POSTING_NOT_ALLOWED = 440; // posting not allowed - static final int POSTING_FAILED = 441; // posting failed - static final int COMMAND_NOT_RECOGNIZED = 500; - static final int COMMAND_SYNTAX_ERROR = 501; - static final int PERMISSION_DENIED = 502; - static final int SERVER_ERROR = 503; - - boolean postingAllowed = false; - Root root; - Newsgroup current; - Date lastNewGroup; - - Hashtable newsgroups = new Hashtable(); // hashtable of newsgroups by name - Hashtable articles = new Hashtable(); // hashtable of articles by message-id - - Vector statusListeners = new Vector(); - - /** - * Constructor. - */ - public NNTPStore(Session session, URLName urlname) { - super(session, urlname); - String ccs = session.getProperty("mail.nntp.fetchsize"); - if (ccs!=null) try { fetchsize = Math.max(Integer.parseInt(ccs), 1024); } catch (NumberFormatException e) {} - } - - /** - * Connects to the NNTP server and authenticates with the specified parameters. - */ - protected boolean protocolConnect(String host, int port, String username, String password) throws MessagingException { - if (port<0) port = DEFAULT_PORT; - if (host==null) - return false; - try { - hostname = host; - socket = new Socket(host, port); - in = new CRLFInputStream(new BufferedInputStream(socket.getInputStream())); - out = new CRLFOutputStream(new BufferedOutputStream(socket.getOutputStream())); - - switch (getResponse()) { - case READY: - postingAllowed = true; - case READ_ONLY: - //StringTokenizer st = new StringTokenizer(response); - //if (st.hasMoreTokens()) hostname = st.nextToken(); - break; - default: - throw new MessagingException("unexpected server response: "+response); - } - - send("MODE READER"); // newsreader extension - switch (getResponse()) { - case READY: - postingAllowed = true; - case READ_ONLY: - break; - } - - // -- authentication, added by mario -- - if (username != null && password != null) { - send ("AUTHINFO USER "+username); - if (getResponse() == PASS_REQ) { - send ("AUTHINFO PASS "+password); - if (getResponse() != PASSWORD_OK) { - throw new AuthenticationFailedException(); - } - } - } - // -- end authentication -- - - readNewsrc(); - - return true; - } catch(UnknownHostException e) { - throw new MessagingException("unknown host", e); - } catch(IOException e) { - throw new MessagingException("I/O error", e); - } - } - - /** - * Closes the connection. - */ - public synchronized void close() throws MessagingException { - if (socket!=null) - try { - send("QUIT"); - switch (getResponse()) { - case CLOSING: - break; - case SERVER_ERROR: - if (response.toLowerCase().indexOf("timeout")>-1) - break; - default: - throw new MessagingException("unexpected server response: "+response); - } - socket.close(); - socket = null; - } catch (IOException e) { - // socket.close() seems to throw an exception! - //throw new MessagingException("Close failed", e); - } - super.close(); - } - - /** - * Returns the hostname of the server. - */ - public String getHostName() { return hostname; } - - int getResponse() throws IOException { - response = in.readLine(); - try { - int index = response.indexOf(' '); - int code = Integer.parseInt(response.substring(0, index)); - response = response.substring(index+1); - return code; - } catch (StringIndexOutOfBoundsException e) { - throw new ProtocolException("NNTP protocol exception: "+response); - } catch (NumberFormatException e) { - throw new ProtocolException("NNTP protocol exception: "+response); - } - } - - void send(String command) throws IOException { - out.write(command.getBytes()); - out.writeln(); - out.flush(); - } - - // Opens a newsgroup. - synchronized void open(Newsgroup group) throws MessagingException { - if (current!=null) { - if (current.equals(group)) - return; - else - close(current); - } - String name = group.getName(); - try { - send("GROUP "+name); - int r = getResponse(); - switch (r) { - case GROUP_SELECTED: - try { - updateGroup(group, response); - group.open = true; - current = group; - } catch (NumberFormatException e) { - throw new MessagingException("NNTP protocol exception: "+response, e); - } - break; - case NO_SUCH_GROUP: - throw new MessagingException(response); - case SERVER_ERROR: - if (response.toLowerCase().indexOf("timeout")>-1) { - close(); - connect(); - open(group); - break; - } - default: - throw new MessagingException("unexpected server response ("+r+"): "+response); - } - } catch (IOException e) { - throw new MessagingException("I/O error", e); - } - } - - // Updates a newsgroup with the most recent article counts. - void updateGroup(Newsgroup newsgroup, String response) throws IOException { - try { - StringTokenizer st = new StringTokenizer(response, " "); - newsgroup.count = Integer.parseInt(st.nextToken()); - newsgroup.first = Integer.parseInt(st.nextToken()); - newsgroup.last = Integer.parseInt(st.nextToken()); - } catch (NumberFormatException e) { - throw new ProtocolException("NNTP protocol exception"); - } catch (NoSuchElementException e) { - throw new ProtocolException("NNTP protocol exception"); - } - } - - // Closes a newsgroup. - synchronized void close(Newsgroup group) throws MessagingException { - if (current!=null && !current.equals(group)) close(current); - group.open = false; - } - - // Returns the (approximate) number of articles in a newsgroup. - synchronized int getMessageCount(Newsgroup group) throws MessagingException { - String name = group.getName(); - try { - send("GROUP "+name); - switch (getResponse()) { - case GROUP_SELECTED: - try { - updateGroup(group, response); - current = group; - return group.count; - } catch(NumberFormatException e) { - throw new MessagingException("NNTP protocol exception: "+response, e); - } - case NO_SUCH_GROUP: - throw new MessagingException("No such group"); - case SERVER_ERROR: - if (response.toLowerCase().indexOf("timeout")>-1) { - close(); - connect(); - return getMessageCount(group); - } - default: - throw new MessagingException("unexpected server response: "+response); - } - } catch (IOException e) { - throw new MessagingException("I/O error", e); - } - } - - // Returns the headers for an article. - synchronized InternetHeaders getHeaders(Article article) throws MessagingException { - String mid = article.messageId; - if (mid==null) { - Newsgroup group = (Newsgroup)article.getFolder(); - if (!current.equals(group)) open(group); - mid = Integer.toString(article.getMessageNumber()); - } - try { - send("HEAD "+mid); - switch (getResponse()) { - case ARTICLE_RETRIEVED_HEAD: - return new InternetHeaders(new MessageInputStream(in)); - case NO_GROUP_SELECTED: - throw new MessagingException("No group selected"); - case NO_ARTICLE_SELECTED: - throw new MessagingException("No article selected"); - case NO_SUCH_ARTICLE_IN_GROUP: - throw new MessagingException("No such article in group"); - case NO_SUCH_ARTICLE: - throw new MessagingException("No such article"); - case SERVER_ERROR: - if (response.toLowerCase().indexOf("timeout")>-1) { - close(); - connect(); - return getHeaders(article); - } - default: - throw new MessagingException("unexpected server response: "+response); - } - } catch (IOException e) { - throw new MessagingException("I/O error", e); - } - } - - // Returns the content for an article. - synchronized byte[] getContent(Article article) throws MessagingException { - String mid = article.messageId; - if (mid==null) { - Newsgroup group = (Newsgroup)article.getFolder(); - if (!current.equals(group)) open(group); - mid = Integer.toString(article.getMessageNumber()); - } - try { - send("BODY "+mid); - switch (getResponse()) { - case ARTICLE_RETRIEVED_BODY: - int max = fetchsize, len; - byte b[] = new byte[max]; - MessageInputStream min = new MessageInputStream(in); - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - while ((len = min.read(b, 0, max))!=-1) - bout.write(b, 0, len); - return bout.toByteArray(); - case NO_GROUP_SELECTED: - throw new MessagingException("No group selected"); - case NO_ARTICLE_SELECTED: - throw new MessagingException("No article selected"); - case NO_SUCH_ARTICLE_IN_GROUP: - throw new MessagingException("No such article in group"); - case NO_SUCH_ARTICLE: - throw new MessagingException("No such article"); - case SERVER_ERROR: - if (response.toLowerCase().indexOf("timeout")>-1) { - close(); - connect(); - return getContent(article); - } - default: - throw new MessagingException("unexpected server response: "+response); - } - } catch (IOException e) { - throw new MessagingException("I/O error", e); - } - } - - /** - * Post an article. - * @param article the article - * @param addresses the addresses to post to. - * @exception MessagingException if a messaging exception occurred or there were no newsgroup recipients - */ - public void postArticle(Message article, Address[] addresses) throws MessagingException { - Vector v = new Vector(); - for (int i=0; i-1) { - connect(); - post(article, address); - break; - } - default: - throw new MessagingException("unexpected server response: "+response); - } - } catch (IOException e) { - throw new MessagingException("I/O error", e); - } - } - - // Attempts to discover which newsgroups exist and which articles have been read. - void readNewsrc() { - try { - File newsrc = new File(System.getProperty("user.home")+File.separator+".newsrc-"+getHostName()); - if (!newsrc.exists()) - newsrc = new File(System.getProperty("user.home")+File.separator+".newsrc"); - - BufferedReader reader = new BufferedReader(new FileReader(newsrc)); - String line; - while ((line = reader.readLine())!=null) { - StringTokenizer st = new StringTokenizer(line, ":!", true); - try { - String name = st.nextToken(); - Newsgroup group = new Newsgroup(this, name); - group.subscribed = ":".equals(st.nextToken()); - if (st.hasMoreTokens()) - group.newsrcline = st.nextToken().trim(); - newsgroups.put(name, group); - } catch (NoSuchElementException e) {} - } - } catch (FileNotFoundException e) { - } catch (IOException e) { - } catch (SecurityException e) { // not allowed to read file - } - } - - // Returns the newsgroups available in this store via the specified listing command. - Newsgroup[] getNewsgroups(String command, boolean retry) throws MessagingException { - Vector vector = new Vector(); - try { - send(command); - switch (getResponse()) { - case LISTING: - String line; - for (line=in.readLine(); line!=null && !".".equals(line); line = in.readLine()) { - StringTokenizer st = new StringTokenizer(line, " "); - String name = st.nextToken(); - int last = Integer.parseInt(st.nextToken()); - int first = Integer.parseInt(st.nextToken()); - boolean posting = ("y".equals(st.nextToken().toLowerCase())); - Newsgroup group = (Newsgroup)getFolder(name); - group.first = first; - group.last = last; - group.postingAllowed = posting; - vector.addElement(group); - } - break; - case SERVER_ERROR: - if (!retry) { - if (response.toLowerCase().indexOf("timeout")>-1) { - close(); - connect(); - return getNewsgroups(command, true); - } else - return getNewsgroups("LIST", false); // backward compatibility with rfc977 - } - default: - throw new MessagingException(command+" failed: "+response); - } - } catch (IOException e) { - throw new MessagingException(command+" failed", e); - } catch (NumberFormatException e) { - throw new MessagingException(command+" failed", e); - } - Newsgroup[] groups = new Newsgroup[vector.size()]; vector.copyInto(groups); - return groups; - } - - // Returns the articles for a newsgroup. - Article[] getArticles(Newsgroup newsgroup) throws MessagingException { - try { - return getOverview(newsgroup); - } catch (MessagingException e) { // try rfc977 - return getNewArticles(newsgroup, new Date(0L)); - } - } - - /** - * Returns the newsgroups added to this store since the specified date. - * @exception MessagingException if a messaging error occurred - */ - Newsgroup[] getNewFolders(Date date) throws MessagingException { - String datetime = getDateTimeString(date); - Vector vector = new Vector(); - try { - send("NEWGROUPS "+datetime); - switch (getResponse()) { - case LISTING_NEW: - String line; - for (line=in.readLine(); line!=null && !".".equals(line); line = in.readLine()) { - StringTokenizer st = new StringTokenizer(line, " "); - String name = st.nextToken(); - int last = Integer.parseInt(st.nextToken()); - int first = Integer.parseInt(st.nextToken()); - boolean posting = ("y".equals(st.nextToken().toLowerCase())); - Newsgroup group = (Newsgroup)getFolder(name); - group.first = first; - group.last = last; - group.postingAllowed = posting; - vector.addElement(group); - } - break; - default: - throw new MessagingException("Listing failed: "+response); - } - } catch (IOException e) { - throw new MessagingException("Listing failed", e); - } catch (NumberFormatException e) { - throw new MessagingException("Listing failed", e); - } - Newsgroup[] groups = new Newsgroup[vector.size()]; vector.copyInto(groups); - return groups; - } - - // Returns the articles added to the specified newsgroup since the specified date. - Article[] getNewArticles(Newsgroup newsgroup, Date date) throws MessagingException { - String command = "NEWNEWS "+newsgroup.getName()+" "+getDateTimeString(date); - Vector vector = new Vector(); - try { - send(command); - switch (getResponse()) { - case LISTING_ARTICLES: - String line; - for (line=in.readLine(); line!=null && !".".equals(line); line = in.readLine()) { - Message article = getArticle(newsgroup, line); - vector.addElement(article); - } - break; - default: - throw new MessagingException(command+" failed: "+response); - } - } catch (IOException e) { - throw new MessagingException(command+" failed", e); - } catch (NumberFormatException e) { - throw new MessagingException(command+" failed", e); - } - Article[] articles = new Article[vector.size()]; vector.copyInto(articles); - return articles; - } - - // Returns a GMT date-time formatted string for the specified date, - // suitable as an argument to NEWGROUPS and NEWNEWS commands. - String getDateTimeString(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - StringBuffer buffer = new StringBuffer(); - int field; - String ZERO = "0"; // leading zero - field = calendar.get(Calendar.YEAR)%100; buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - field = calendar.get(Calendar.MONTH)+1; buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - field = calendar.get(Calendar.DAY_OF_MONTH); buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - buffer.append(" "); - field = calendar.get(Calendar.HOUR_OF_DAY); buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - field = calendar.get(Calendar.MINUTE); buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - field = calendar.get(Calendar.SECOND); buffer.append((field<10) ? ZERO+field : Integer.toString(field)); - buffer.append(" GMT"); - return buffer.toString(); - } - - /** - * Returns the root folder. - */ - public Folder getDefaultFolder() throws MessagingException { - synchronized (this) { - if (root==null) root = new Root(this); - } - return root; - } - - /** - * Returns the newsgroup with the specified name. - */ - public Folder getFolder(String name) throws MessagingException { - return getNewsgroup(name); - } - - /** - * Returns the newsgroup specified as part of a URLName. - */ - public Folder getFolder(URLName urlname) throws MessagingException { - String group = urlname.getFile(); - int hashIndex = group.indexOf('#'); - if (hashIndex>-1) group = group.substring(0, hashIndex); - return getNewsgroup(group); - } - - Newsgroup getNewsgroup(String name) { - Newsgroup newsgroup = (Newsgroup)newsgroups.get(name); - if (newsgroup==null) { - newsgroup = new Newsgroup(this, name); - newsgroups.put(name, newsgroup); - } - return newsgroup; - } - - // Returns the article with the specified message-id for the newsgroup. - Article getArticle(Newsgroup newsgroup, String mid) throws MessagingException { - Article article = (Article)articles.get(mid); - if (article==null) { - article = new Article(newsgroup, mid); - articles.put(mid, article); - } - return article; - } - - // -- NNTP extensions -- - - int[] getArticleNumbers(Newsgroup newsgroup) throws MessagingException { - String command = "LISTGROUP "+newsgroup.getName(); - Vector vector = new Vector(); - synchronized (this) { - try { - send(command); - switch (getResponse()) { - case GROUP_SELECTED: - String line; - for (line=in.readLine(); line!=null && !".".equals(line); line = in.readLine()) { - vector.addElement(line); - } - break; - case NO_GROUP_SELECTED: - case PERMISSION_DENIED: - default: - throw new MessagingException(command+" failed: "+response); - } - } catch (IOException e) { - throw new MessagingException(command+" failed", e); - } catch (NumberFormatException e) { - throw new MessagingException(command+" failed", e); - } - } - int[] numbers = new int[vector.size()]; - for (int i=0; i-1) { - close(); - connect(); - return getOverview(newsgroup); - } - default: - throw new MessagingException(command+" failed: "+response); - } - } catch (IOException e) { - throw new MessagingException(command+" failed", e); - } - } - } - command = "XOVER "+newsgroup.first+"-"+newsgroup.last; - Vector av = new Vector(Math.max(newsgroup.last-newsgroup.first, 10)); - synchronized (this) { - try { - send(command); - switch (getResponse()) { - case LISTING_OVERVIEW: - processStatusEvent(new StatusEvent(this, StatusEvent.OPERATION_START, command)); - String line; - int count = 0; - for (line=in.readLine(); line!=null && !".".equals(line); line = in.readLine()) { - int tabIndex = line.indexOf('\t'); - if (tabIndex>-1) { - int msgnum = Integer.parseInt(line.substring(0, tabIndex)); - Article article = new Article(newsgroup, msgnum); - article.addXoverHeaders(getOverviewHeaders(format, line, tabIndex)); - av.addElement(article); - count++; - if ((count%20)==0) - processStatusEvent(new StatusEvent(this, StatusEvent.OPERATION_UPDATE, command, newsgroup.first, newsgroup.last, msgnum)); - } else - throw new ProtocolException("Invalid overview line format"); - } - processStatusEvent(new StatusEvent(this, StatusEvent.OPERATION_END, command)); - break; - case NO_ARTICLE_SELECTED: - case PERMISSION_DENIED: - break; - case NO_GROUP_SELECTED: - case SERVER_ERROR: - default: - throw new MessagingException(command+" failed: "+response); - } - } catch (IOException e) { - throw new MessagingException(command+" failed", e); - } catch (NumberFormatException e) { - throw new MessagingException(command+" failed", e); - } - } - Article[] articles = new Article[av.size()]; av.copyInto(articles); - return articles; - } - - // Returns an InternetHeaders object representing the headers stored in an xover response line. - InternetHeaders getOverviewHeaders(String[] format, String line, int startIndex) { - InternetHeaders headers = new InternetHeaders(); - for (int i=0; i. All Rights Reserved. - * - * Contributor(s): n/a. - */ - -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 0.3 - */ -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"); - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/mail/util/CRLFInputStream.java b/mozilla/grendel/storage/nntp/dog/mail/util/CRLFInputStream.java deleted file mode 100644 index fbf614d2fe8..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/util/CRLFInputStream.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * CRLFInputStream.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.mail.util; - -import java.io.*; - -/** - * An input stream that filters out CR/LF pairs into LFs. - * - * @author dog@dog.net.uk - * @version 0.1 - */ -public class CRLFInputStream extends PushbackInputStream { - - /** - * The CR octet. - */ - public static final int CR = 13; - - /** - * The LF octet. - */ - public static final int LF = 10; - - /** - * Constructs a CR/LF input stream connected to the specified input stream. - */ - public CRLFInputStream(InputStream in) { - super(in); - } - - /** - * Reads the next byte of data from this input stream. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read() throws IOException { - int c = super.read(); - if (c==CR) // skip CR - return super.read(); - return c; - } - - /** - * Reads up to b.length bytes of data from this input stream into - * an array of bytes. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - /** - * Reads up to len bytes of data from this input stream into an - * array of bytes, starting at the specified offset. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b, int off, int len) throws IOException { - int l = super.read(b, off, len); - return removeCRs(b, off, l); - } - - /** - * Reads a line of input terminated by LF. - * @exception IOException if an I/O error occurs - */ - public String readLine() throws IOException { - byte[] acc = new byte[4096]; - int count = 0; - for (byte b=(byte)read(); b!=LF && b!=-1; b=(byte)read()) - acc[count++] = b; - if (count>0) { - byte[] bytes = new byte[count]; - System.arraycopy(acc, 0, bytes, 0, count); - return new String(bytes); - } else - return null; - } - - int removeCRs(byte[] b, int off, int len) { - for (int index = indexOfCR(b, off, len); index>-1; index = indexOfCR(b, off, len)) { - for (int i=index; i. All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.mail.util; - -import java.io.*; - -/** - * An output stream that filters LFs into CR/LF pairs. - * - * @author dog@dog.net.uk - * @version 0.1 - */ -public class CRLFOutputStream extends FilterOutputStream { - - /** - * The CR octet. - */ - public static final int CR = 13; - - /** - * The LF octet. - */ - public static final int LF = 10; - - /** - * The CR/LF pair. - */ - public static final byte[] CRLF = { CR, LF }; - - /** - * The last byte read. - */ - protected int last; - - /** - * Constructs a CR/LF output stream connected to the specified output stream. - */ - public CRLFOutputStream(OutputStream out) { - super(out); - last = -1; - } - - /** - * Writes a character to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(int ch) throws IOException { - if (ch==CR) - out.write(CRLF); - else - if (ch==LF) { - if (last!=CR) - out.write(CRLF); - } else { - out.write(ch); - } - last = ch; - } - - /** - * Writes a byte array to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(byte b[]) throws IOException { - write(b, 0, b.length); - } - - /** - * Writes a portion of a byte array to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(byte b[], int off, int len) throws IOException { - int d = off; - len += off; - for (int i=off; i0) - out.write(b, d, len-d); - } - - /** - * Writes a newline to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void writeln() throws IOException { - out.write(CRLF); - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/mail/util/Makefile b/mozilla/grendel/storage/nntp/dog/mail/util/Makefile deleted file mode 100644 index 346295b6d60..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/util/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the Grendel mail/news client. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1997 -# Netscape Communications Corporation. All Rights Reserved. - -SUBDIRS= \ - $(NULL) - -SRCS= \ - CRLFInputStream.java \ - CRLFOutputStream.java \ - MessageInputStream.java \ - MessageOutputStream.java \ - $(NULL) - -include ../../../../../rules.mk diff --git a/mozilla/grendel/storage/nntp/dog/mail/util/MessageInputStream.java b/mozilla/grendel/storage/nntp/dog/mail/util/MessageInputStream.java deleted file mode 100644 index 8a162afe3ac..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/util/MessageInputStream.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * MessageInputStream.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.mail.util; - -import java.io.*; - -/** - * A utility class for feeding message contents to messages. - * - * @author dog@dog.net.uk - * @version 0.1 - */ -public class MessageInputStream extends FilterInputStream { - - /** - * The stream termination octet. - */ - public static final int END = 46; - - /** - * The line termination octet. - */ - public static final int LF = 10; - - boolean done = false; - int last = -1; // register for the last octet read - - /** - * Constructs a message input stream connected to the specified pushback input stream. - */ - public MessageInputStream(PushbackInputStream in) { - super(in); - } - - /** - * Reads the next byte of data from this message input stream. - * Returns -1 if the end of the message stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read() throws IOException { - if (done) return -1; - int ch = in.read(); - if (ch==END && last==LF) { - int ch2 = in.read(); // look ahead for LF - if (ch2==LF) { - done = true; - return -1; // swallow the END and LF - } else - ((PushbackInputStream)in).unread(ch2); - } - last = ch; - return ch; - } - - /** - * Reads up to b.length bytes of data from this input stream into - * an array of bytes. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - /** - * Reads up to len bytes of data from this input stream into an - * array of bytes, starting at the specified offset. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b, int off, int len) throws IOException { - if (done) return -1; - int l = in.read(b, off, len); - int i = indexOfEnd(b, off, l); - if (i>-1) { - ((PushbackInputStream)in).unread(b, i+2, (l-(off+i+2))); - done = true; - return i-off; - } - return l; - } - - // Discover the index of END in a byte array. - int indexOfEnd(byte[] b, int off, int len) { - for (int i=off+2; i<(off+len); i++) - if (b[i]==LF && b[i-1]==END && b[i-2]==LF) - return i-1; - return -1; - } - -} \ No newline at end of file diff --git a/mozilla/grendel/storage/nntp/dog/mail/util/MessageOutputStream.java b/mozilla/grendel/storage/nntp/dog/mail/util/MessageOutputStream.java deleted file mode 100644 index 2a324ebe487..00000000000 --- a/mozilla/grendel/storage/nntp/dog/mail/util/MessageOutputStream.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * MessageOutputStream.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.mail.util; - -import java.io.*; - -/** - * An output stream that escapes any dots on a line by themself with - * another dot, for the purposes of sending messages to SMTP and NNTP servers. - * - * @author dog@dog.net.uk - * @version 0.1 - */ -public class MessageOutputStream extends FilterOutputStream { - - /** - * The stream termination octet. - */ - public static final int END = 46; - - /** - * The line termination octet. - */ - public static final int LF = 10; - - int last = -1; // the last character written to the stream - - /** - * Constructs a message output stream connected to the specified output stream. - * @param out the target output stream - */ - public MessageOutputStream(OutputStream out) { - super(out); - } - - /** - * Writes a character to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(int ch) throws IOException { - if ((last==LF || last==-1) && ch==END) - out.write(END); // double any lonesome dots - super.write(ch); - } - - /** - * Writes a portion of a byte array to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(byte b[], int off, int len) throws IOException { - int k = last != -1 ? last : LF; - int l = off; - len += off; - for (int i = off; i < len; i++) { - if (k==LF && b[i]==END) { - super.write(b, l, i-l); - out.write(END); - l = i; - } - k = b[i]; - } - if (len-l > 0) - super.write(b, l, len-l); - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/Makefile b/mozilla/grendel/storage/nntp/dog/util/Makefile deleted file mode 100644 index eb3fae53961..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the Grendel mail/news client. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1997 -# Netscape Communications Corporation. All Rights Reserved. - -SUBDIRS= \ - $(NULL) - -SRCS= \ - ObjectCollator.java \ - Referential.java \ - StatusEvent.java \ - StatusListener.java \ - StatusSource.java \ - Timer.java \ - TimerEvent.java \ - TimerListener.java \ - Tree.java \ - TreeCollator.java \ - TreeEvent.java \ - $(NULL) - - -include ../../../../rules.mk diff --git a/mozilla/grendel/storage/nntp/dog/util/ObjectCollator.java b/mozilla/grendel/storage/nntp/dog/util/ObjectCollator.java deleted file mode 100644 index 2ad3ec0be3d..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/ObjectCollator.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * ObjectCollator.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.text.CollationKey; -import java.text.Collator; -import java.util.Date; -import java.util.Locale; - -/** - * A class for comparing objects in a tree. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public class ObjectCollator extends Collator { - - protected Collator collator; - - protected boolean descending = false; - - /** - * Constructs a ObjectCollator for the default locale. - */ - public ObjectCollator() { - collator = Collator.getInstance(); - } - - /** - * Constructs a ObjectCollator for the specified locale. - */ - public ObjectCollator(Locale locale) { - collator = Collator.getInstance(locale); - } - - /** - * Indicates whether this collator returns the opposite of any comparison. - * @see #setDescending - */ - public boolean isDescending() { return descending; } - - /** - * Sets whether this collator returns the opposite of any comparison. - * @param descending true if this collator returns the opposite of any comparison, false otherwise - * @see #setDescending - */ - public void setDescending(boolean descending) { this.descending = descending; } - - /** - * Utility method to return the opposite of a comparison if descending is true. - */ - protected int applyDescending(int comparison) { - return (!descending ? comparison : -comparison); - } - - /** - * Utility method to return the opposite of a comparison if descending is true. - */ - protected int applyDescending(double comparison) { - return (!descending ? (int)Math.rint(comparison) : (int)Math.rint(comparison*(-1.0))); - } - - /** - * Compares the source string to the target string according to the collation rules for this Collator. - * Returns an integer less than, equal to or greater than zero depending on whether the source String - * is less than, equal to or greater than the target string. - * @param source the source string. - * @param target the target string. - * @see java.text.CollationKey - */ - public int compare(String source, String target) { - return applyDescending(collator.compare(source, target)); - } - - /** - * Compares the source object to the target object according to the collation rules for this Collator. - * Returns an integer less than, equal to or greater than zero depending on whether the source object - * is less than, equal to or greater than the target object. - * Objects that can validly be compared by such means include:
    - *
  • Boolean - false is less than true, can only be compared with another Boolean - *
  • Byte - *
  • Date - before is less than after, can only be compared with another Date - *
  • Double - *
  • Float - *
  • Long - *
  • Integer - *
  • Short - *
  • String - * @param source the source object. - * @param target the target object. - */ - public int compare(Object source, Object target) { - if (source instanceof String) { - if (target instanceof String) - return applyDescending(collator.compare((String)source, (String)target)); - else if (target instanceof Number) - return applyDescending(collator.compare((String)source, target.toString())); - } else if (source instanceof Integer) { - if (target instanceof Number) - return applyDescending(((Number)target).intValue()-((Integer)source).intValue()); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Double) { - if (target instanceof Number) - return applyDescending((double)(((Number)target).doubleValue()-((Double)source).doubleValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Long) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).longValue()-((Long)source).longValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Float) { - if (target instanceof Number) - return applyDescending((double)(((Number)target).floatValue()-((Float)source).floatValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Byte) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).byteValue()-((Byte)source).byteValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Short) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).shortValue()-((Short)source).shortValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Boolean) { - if (target instanceof Boolean) { - boolean s = ((Boolean)source).booleanValue(), t = ((Boolean)target).booleanValue(); - if (!s && t) return applyDescending(-1); else if (s && !t) return applyDescending(1); - } - } else if (source instanceof Date) { - if (target instanceof Date) { - Date s = (Date)source, t = (Date)target; - if (s.before(t)) return applyDescending(-1); else if (s.after(t)) return applyDescending(1); - } - } - return 0; - } - - /** - * Transforms the String into a series of bits that can be compared bitwise to other CollationKeys. - * CollationKeys provide better performance than Collator.compare when Strings are involved in multiple comparisons. - * @param source the string to be transformed into a collation key. - * @return the CollationKey for the given String based on this Collator's collation rules. If the source String is null, a null CollationKey is returned. - * @see java.text.CollationKey - * @see #compare - */ - public CollationKey getCollationKey(String source) { - return collator.getCollationKey(source); - } - - /** - * Convenience method for comparing the equality of two strings based on this Collator's collation rules. - * @param source the source string to be compared with. - * @param target the target string to be compared with. - * @return true if the strings are equal according to the collation rules, false otherwise. - * @see #compare - */ - public boolean equals(String source, String target) { - return collator.equals(source, target); - } - - /** - * Returns this Collator's strength property. - * The strength property determines the minimum level of difference considered significant during comparison. - * See the Collator class description for an example of use. - * @return this Collator's current strength property. - * @see #setStrength - */ - public int getStrength() { return collator.getStrength(); } - - /** - * Sets this Collator's strength property. - * The strength property determines the minimum level of difference considered significant during comparison. - * See the Collator class description for an example of use. - * @param newStrength the new strength value. - * @exception IllegalArgumentException if the new strength value is not one of PRIMARY, SECONDARY, TERTIARY or IDENTICAL. - * @see #getStrength - */ - public void setStrength(int newStrength) { collator.setStrength(newStrength); } - - /** - * Get the decomposition mode of this Collator. - * Decomposition mode determines how Unicode composed characters are handled. - * Adjusting decomposition mode allows the user to select between faster and more complete collation behavior. - * The three values for decomposition mode are:
      - *
    • NO_DECOMPOSITION, - *
    • CANONICAL_DECOMPOSITION - *
    • FULL_DECOMPOSITION. - *
    See the documentation for these three constants for a description of their meaning. - * @return the decomposition mode - * @see #setDecomposition - */ - public int getDecomposition() { return collator.getDecomposition(); } - - /** - * Set the decomposition mode of this Collator. - * See getDecomposition for a description of decomposition mode. - * @param decompositionMode the new decomposition mode - * @throws IllegalArgumentException if the given value is not a valid decomposition mode. - * @see #getDecomposition - */ - public void setDecomposition(int decompositionMode) { collator.setDecomposition(decompositionMode); } - - public int hashCode() { return collator.hashCode(); } - - public boolean equals(Object other) { - if (other instanceof ObjectCollator) { - ObjectCollator oc = (ObjectCollator)other; - return (collator.equals(oc.collator)); - } - return false; - } - - /** - * Provides a string description of this object. - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append(getClass().getName()); - buffer.append("["); - buffer.append(paramString().toString()); - buffer.append("]"); - return buffer.toString(); - } - - protected StringBuffer paramString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("strength="); - switch (getStrength()) { - case PRIMARY: - buffer.append("PRIMARY"); - break; - case SECONDARY: - buffer.append("SECONDARY"); - break; - case TERTIARY: - buffer.append("TERTIARY"); - break; - case IDENTICAL: - buffer.append("IDENTICAL"); - break; - default: - buffer.append("unknown"); - } - buffer.append(",decomposition="); - switch (getDecomposition()) { - case NO_DECOMPOSITION: - buffer.append("NO_DECOMPOSITION"); - break; - case CANONICAL_DECOMPOSITION: - buffer.append("CANONICAL_DECOMPOSITION"); - break; - case FULL_DECOMPOSITION: - buffer.append("FULL_DECOMPOSITION"); - break; - default: - buffer.append("unknown"); - } - if (descending) buffer.append(",descending"); - return buffer; - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/Referential.java b/mozilla/grendel/storage/nntp/dog/util/Referential.java deleted file mode 100644 index 9370ef58d99..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/Referential.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Referential.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -/** - * An interface implemented by objects that maintain an external object reference. - *

    - * This reference can be used to tag objects with a datasource id or store a hashtable of associated values. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public interface Referential { - - /** - * Returns the object reference. - */ - public Object getReference(); - - /** - * Sets the object reference. - * @param reference the object reference to store. - */ - public void setReference(Object reference); - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/StatusEvent.java b/mozilla/grendel/storage/nntp/dog/util/StatusEvent.java deleted file mode 100644 index 806ddf40904..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/StatusEvent.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * StatusEvent.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.util.*; - -/** - * A status message. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public class StatusEvent extends EventObject { - - public static final int OPERATION_START = 0; - - public static final int OPERATION_UPDATE = 1; - - public static final int OPERATION_END = 2; - - public static final int UNKNOWN = -1; - - protected int type; - - protected String operation; - - protected int minimum = UNKNOWN; - - protected int maximum = UNKNOWN; - - protected int value = UNKNOWN; - - /** - * Creates a new status event with the specified type and operation. - */ - public StatusEvent(Object source, int type, String operation) { - super(source); - switch (type) { - case OPERATION_START: - case OPERATION_UPDATE: - case OPERATION_END: - this.type = type; - break; - default: - throw new IllegalArgumentException("Illegal event type: "+type); - } - this.operation = operation; - } - - /** - * Creates a new status event representing an update of the specified operation. - */ - public StatusEvent(Object source, int type, String operation, int minimum, int maximum, int value) { - super(source); - switch (type) { - case OPERATION_START: - case OPERATION_UPDATE: - case OPERATION_END: - this.type = type; - break; - default: - throw new IllegalArgumentException("Illegal event type: "+type); - } - this.operation = operation; - this.minimum = minimum; - this.maximum = maximum; - this.value = value; - } - - /** - * Returns the type of event (OPERATION_START, OPERATION_UPDATE, or OPERATION_END). - */ - public int getType() { return type; } - - /** - * Returns a string describing the operation being performed. - */ - public String getOperation() { return operation; } - - /** - * Returns the start point of the operation. - */ - public int getMinimum() { return minimum; } - - /** - * Returns the end point of the operation. - */ - public int getMaximum() { return maximum; } - - /** - * Returns the current point in the operation. - */ - public int getValue() { return value; } - -} \ No newline at end of file diff --git a/mozilla/grendel/storage/nntp/dog/util/StatusListener.java b/mozilla/grendel/storage/nntp/dog/util/StatusListener.java deleted file mode 100644 index 6f2ff33a71d..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/StatusListener.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * StatusListener.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.util.*; - -/** - * A callback interface for passing status messages. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public interface StatusListener extends EventListener { - - /** - * An operation started. - */ - public void statusOperationStarted(StatusEvent event); - - /** - * A progress update occurred. - */ - public void statusProgressUpdate(StatusEvent event); - - /** - * An operation completed. - */ - public void statusOperationEnded(StatusEvent event); - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/StatusSource.java b/mozilla/grendel/storage/nntp/dog/util/StatusSource.java deleted file mode 100644 index f74926d1c7b..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/StatusSource.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * StatusSource.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -/** - * An interface for defining that an object can pass status messages. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public interface StatusSource { - - /** - * Adds a status listener to this source. - * @param l the listener - */ - public void addStatusListener(StatusListener l); - - /** - * Removes a status listener from this source. - * @param l the listener - */ - public void removeStatusListener(StatusListener l); - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/Timer.java b/mozilla/grendel/storage/nntp/dog/util/Timer.java deleted file mode 100644 index cf3e691d5e5..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/Timer.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Timer.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -/** - * A timer class that wakes up listeners after a specified number of milliseconds. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public final class Timer extends Thread { - - long time; - long interval = 0; - TimerListener listener; - - /** - * Constructs a timer. - */ - public Timer(TimerListener listener) { - this(listener, 0, false); - } - - /** - * Constructs a timer with the specified interval, and starts it. - */ - public Timer(TimerListener listener, long interval) { - this(listener, interval, true); - } - - /** - * Constructs a timer with the specified interval, indicating whether or not to start it. - */ - public Timer(TimerListener listener, long interval, boolean start) { - this.listener = listener; - this.interval = interval; - time = System.currentTimeMillis(); - setDaemon(true); - setPriority(Thread.MIN_PRIORITY); - if (start) - start(); - } - - // -- Accessor methods -- - - /** - * Returns this timer's interval. - */ - public long getInterval() { - return interval; - } - - /** - * Sets this timer's interval. - */ - public void setInterval(long interval) { - this.interval = interval; - } - - /** - * Runs this timer. - */ - public void run() { - boolean interrupt = false; - while (!interrupt) { - synchronized (this) { - try { - wait(interval); - } catch (InterruptedException e) { - interrupt = true; - } - listener.timerFired(new TimerEvent(this, interval)); - } - } - } - -} \ No newline at end of file diff --git a/mozilla/grendel/storage/nntp/dog/util/TimerEvent.java b/mozilla/grendel/storage/nntp/dog/util/TimerEvent.java deleted file mode 100644 index 7559c6cb615..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/TimerEvent.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * TimerEvent.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.util.EventObject; - -/** - * A timer event. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public class TimerEvent extends EventObject { - - protected long ms; - - // Creates a new timer event. - TimerEvent(Timer timer, long ms) { - super(timer); - this.ms = ms; - } - - /** - * Returns the timer that generated this event. - */ - public Timer getTimer() { - return (Timer)source; - } - - /** - * Returns the number of milliseconds since this timer last activated the listener. - */ - public long getMilliseconds() { - return ms; - } - -} \ No newline at end of file diff --git a/mozilla/grendel/storage/nntp/dog/util/TimerListener.java b/mozilla/grendel/storage/nntp/dog/util/TimerListener.java deleted file mode 100644 index 50c9ee650e2..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/TimerListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * TimerListener.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.util.EventListener; - -/** - * Interface for classes that wnat to recieve timer events. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public interface TimerListener extends EventListener { - - public void timerFired(TimerEvent event); - -} \ No newline at end of file diff --git a/mozilla/grendel/storage/nntp/dog/util/Tree.java b/mozilla/grendel/storage/nntp/dog/util/Tree.java deleted file mode 100644 index fa989be6de7..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/Tree.java +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Tree.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - * - * You may retrieve the latest version of this package at the knife home page, - * located at http://www.dog.net.uk/knife/ - */ - -package dog.util; - -import java.util.Vector; - -/** - * A utility class for manipulating objects in a tree structure. - *

    - * This class provides a way to associate arbitrary objects with one another in a hierarchy. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public final class Tree { - - int nparents = 0; - Object[] parents; - int[] nchildren; - Object[][] children; - int nelements = 0; - Object[] elements; - int[] depths; - - int increment; - Object LOCK = new Object(); - - /** - * Constructs an empty tree. - */ - public Tree() { - this(10); - } - - /** - * Constructs an empty tree with the specified capacity increment. - * @param increment the amount by which the capacity is increased when an array overflows. - */ - public Tree(int increment) { - super(); - this.increment = (increment>0) ? increment : 1; - clear(); - } - - // Returns the elements index of the specified object, or -1 if no such element exists. - private int elementIndex(Object object) { - for (int i=0; i-1) { - Object[] c = new Object[nchildren[p]]; - System.arraycopy(children[p], 0, c, 0, nchildren[p]); - return c; - } - } - return new Object[0]; - } - - /** - * Returns the number of children of the specified object. - */ - public int getChildCount(Object parent) { - synchronized (LOCK) { - int p = parentIndex(parent); - if (p>-1) - return nchildren[p]; - } - return 0; - } - - /** - * Indicates whether the specified object is contained in the tree. - */ - public boolean contains(Object object) { - synchronized (LOCK) { - return (elementIndex(object)>-1); - } - } - - private void ensureRootCapacity(int amount) { - // calculate the amount by which to increase arrays - int block = ((int)(Math.max(Math.ceil((double)amount/(double)increment), 1)))*increment; - // ensure capacity of elements - if (elements.length-1) // if we already have the object - removeElement(e); // remove it - ensureRootCapacity(1); - elements[nelements] = object; - depths[nelements] = 1; - nelements++; - } - } - - /** - * Adds roots to the tree. - */ - public void add(Object[] objects) { - synchronized (LOCK) { - for (int i=0; i-1) // if we already have the object - removeElement(e); // remove it - } - ensureRootCapacity(objects.length); - System.arraycopy(objects, 0, elements, nelements, objects.length); - for (int i=nelements; i-1) // if the child is already an element - removeElement(e); - - if (p<0) { // add the parent to parents - p = nparents; - ensureParentCapacity(1); - parents[p] = parent; - children[p] = new Object[increment]; - nchildren[p] = 0; - nparents++; - } - ensureChildCapacity(1, p); - children[p][nchildren[p]] = child; - - // insert the child into elements and set its depth - int depth = depth(parent); - int off = pe+nchildren[p]+1; - int len = nelements-off; - Object[] buffer = new Object[len]; - System.arraycopy(elements, off, buffer, 0, len); - elements[off] = child; - System.arraycopy(buffer, 0, elements, off+1, len); - int[] dbuffer = new int[len]; - System.arraycopy(depths, off, dbuffer, 0, len); - depths[off] = depth+1; - System.arraycopy(dbuffer, 0, depths, off+1, len); - nelements++; - - nchildren[p]++; - } - } - - /** - * Adds children to the specified parent in the tree. - * @throws IllegalArgumentException if the parent does not exist in the tree or one of the children is the parent. - */ - public void add(Object parent, Object[] children) { - if (parent==null) - throw new NullPointerException("null parent specified"); - synchronized (LOCK) { - int p = parentIndex(parent), pe = -1; - if (p<0) { // does it exist in the tree? - if ((pe = elementIndex(parent))<0) - throw new IllegalArgumentException("parent does not exist"); - } // so we'll add it to parents - for (int i=0; i-1) // if we already have the object - removeElement(e); // remove it - } - if (p<0) { // add the parent to parents - p = nparents; - ensureParentCapacity(1); - parents[p] = parent; - this.children[p] = new Object[Math.max(increment, (children.length/increment)*increment)]; - nchildren[p] = 0; - nparents++; - } - ensureChildCapacity(children.length, p); - System.arraycopy(children, 0, this.children[p], nchildren[p], children.length); - - // insert the children into elements and set their depths - int depth = depth(parent); - int off = pe+nchildren[p]+1; - int len = nelements-off; - Object[] buffer = new Object[len]; - System.arraycopy(elements, off, buffer, 0, len); - System.arraycopy(children, 0, elements, off, children.length); - System.arraycopy(buffer, 0, elements, off+children.length, len); - - int[] dbuffer = new int[len]; - System.arraycopy(depths, off, dbuffer, 0, len); - for (int i=off; i-1) - removeElement(e); - } - } - - void removeElement(int e) { - int len = 0; - boolean removed = false; - for (int p=0; p0) { - System.arraycopy(parents, p+1, parents, p, len); - System.arraycopy(children, p+1, children, p, len); - System.arraycopy(nchildren, p+1, nchildren, p, len); - } - nparents--; - //printArray("parents", parents, nparents); - //printArray("elements", elements, nelements); - if ((len = nelements-e-1)>0) { - System.arraycopy(elements, e+1+nc, elements, e, len-nc); - System.arraycopy(depths, e+1+nc, depths, e, len-nc); - } - nelements-=(nc+1); - //printArray("elements", elements, nelements); - removed = true; - } catch (ArrayIndexOutOfBoundsException x) { - System.out.println("arrayindexoutofboundsexception in tree:"); - System.out.println("p="+p+": "+parents[p]); - System.out.println("e="+e+", nelements="+nelements+", elements.length="+elements.length+", nc="+nc+", len="+len); - } - break; - } - } - for (int p=0; p0) { - System.arraycopy(children[p], c+1, children[p], c, len); - } - nchildren[p]--; - if ((len = nelements-e-1)>0) { - System.arraycopy(elements, e+1, elements, e, len); - System.arraycopy(depths, e+1, depths, e, len); - } - nelements--; - removed = true; - break; - } - } - } - if (!removed) { - if ((len = nelements-e-1)>0) { - System.arraycopy(elements, e+1, elements, e, len); - System.arraycopy(depths, e+1, depths, e, len); - } - nelements--; - } - //printElements(); - } - - /** - * Removes the specified objects and all their children from the tree. - * @throws NullPointerException if an object does not exist in the tree. - */ - public void remove(Object[] objects) { - for (int i=0; i-1) { - for (int c=0; c0) - return true; - } - return false; - } - - /** - * Sorts the objects in the tree according to the specified object collator. - * This has no effect if a collator has not been defined. - */ - public void sort(ObjectCollator collator) { - if (collator==null) throw new NullPointerException("null collator"); - synchronized (LOCK) { - Sorter sorter = this.new Sorter(collator); - elements = sorter.newelements; - depths = sorter.newdepths; - } - } - - class Sorter { - - Object[] newelements; - int[] newdepths; - int count = 0; - - Sorter(ObjectCollator collator) { - // first sort the roots - Vector v = new Vector(); - for (int i=0; ifirst) { - mid = objects[(first+last)/2]; - while (lo<=hi) { - while (lofirst && collator.compare(objects[hi], mid)>0) - hi -= 1; - if (lo<=hi) { // swap - Object tmp = objects[lo]; - objects[lo] = objects[hi]; - objects[hi] = tmp; - lo += 1; - hi -= 1; - } - } - if (first - * - * 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. - */ - -package dog.util; - -import java.text.CollationKey; -import java.text.Collator; -import java.util.Date; -import java.util.Locale; - -/** - * A class for comparing objects in a tree. - * - * @author dog@dog.net.uk - * @version 2.0alpha - */ -public class TreeCollator extends Collator { - - protected Collator collator; - - protected boolean descending = false; - - /** - * Constructs a TreeCollator for the default locale. - */ - public TreeCollator() { - collator = Collator.getInstance(); - } - - /** - * Constructs a TreeCollator for the specified locale. - */ - public TreeCollator(Locale locale) { - collator = Collator.getInstance(locale); - } - - /** - * Indicates whether this collator returns the opposite of any comparison. - * @see #setDescending - */ - public boolean isDescending() { return descending; } - - /** - * Sets whether this collator returns the opposite of any comparison. - * @param descending true if this collator returns the opposite of any comparison, false otherwise - * @see #setDescending - */ - public void setDescending(boolean descending) { this.descending = descending; } - - /** - * Utility method to return the opposite of a comparison if descending is true. - */ - protected int applyDescending(int comparison) { - return (!descending ? comparison : -comparison); - } - - /** - * Compares the source string to the target string according to the collation rules for this Collator. - * Returns an integer less than, equal to or greater than zero depending on whether the source String - * is less than, equal to or greater than the target string. - * @param source the source string. - * @param target the target string. - * @see java.text.CollationKey - */ - public int compare(String source, String target) { - return applyDescending(collator.compare(source, target)); - } - - /** - * Compares the source object to the target object according to the collation rules for this Collator. - * Returns an integer less than, equal to or greater than zero depending on whether the source object - * is less than, equal to or greater than the target object. - * Objects that can validly be compared by such means include:

      - *
    • Boolean - false is less than true, can only be compared with another Boolean - *
    • Byte - *
    • Date - before is less than after, can only be compared with another Date - *
    • Double - *
    • Float - *
    • Long - *
    • Integer - *
    • Short - *
    • String - * @param source the source object. - * @param target the target object. - */ - public int compare(Object source, Object target) { - if (source instanceof String) { - if (target instanceof String) - return applyDescending(collator.compare((String)source, (String)target)); - else if (target instanceof Number) - return applyDescending(collator.compare((String)source, target.toString())); - } else if (source instanceof Integer) { - if (target instanceof Number) - return applyDescending(((Number)target).intValue()-((Integer)source).intValue()); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Double) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).doubleValue()-((Double)source).doubleValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Long) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).longValue()-((Long)source).longValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Float) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).floatValue()-((Float)source).floatValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Byte) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).byteValue()-((Byte)source).byteValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Short) { - if (target instanceof Number) - return applyDescending((int)(((Number)target).shortValue()-((Short)source).shortValue())); - else if (target instanceof String) - return applyDescending(collator.compare(source.toString(), (String)target)); - } else if (source instanceof Boolean) { - if (target instanceof Boolean) { - boolean s = ((Boolean)source).booleanValue(), t = ((Boolean)target).booleanValue(); - if (!s && t) return applyDescending(-1); else if (s && !t) return applyDescending(1); - } - } else if (source instanceof Date) { - if (target instanceof Date) { - Date s = (Date)source, t = (Date)target; - if (s.before(t)) return applyDescending(-1); else if (s.after(t)) return applyDescending(1); - } - } - return 0; - } - - /** - * Transforms the String into a series of bits that can be compared bitwise to other CollationKeys. - * CollationKeys provide better performance than Collator.compare when Strings are involved in multiple comparisons. - * @param source the string to be transformed into a collation key. - * @return the CollationKey for the given String based on this Collator's collation rules. If the source String is null, a null CollationKey is returned. - * @see java.text.CollationKey - * @see #compare - */ - public CollationKey getCollationKey(String source) { - return collator.getCollationKey(source); - } - - /** - * Convenience method for comparing the equality of two strings based on this Collator's collation rules. - * @param source the source string to be compared with. - * @param target the target string to be compared with. - * @return true if the strings are equal according to the collation rules, false otherwise. - * @see #compare - */ - public boolean equals(String source, String target) { - return collator.equals(source, target); - } - - /** - * Returns this Collator's strength property. - * The strength property determines the minimum level of difference considered significant during comparison. - * See the Collator class description for an example of use. - * @return this Collator's current strength property. - * @see #setStrength - */ - public int getStrength() { return collator.getStrength(); } - - /** - * Sets this Collator's strength property. - * The strength property determines the minimum level of difference considered significant during comparison. - * See the Collator class description for an example of use. - * @param newStrength the new strength value. - * @exception IllegalArgumentException if the new strength value is not one of PRIMARY, SECONDARY, TERTIARY or IDENTICAL. - * @see #getStrength - */ - public void setStrength(int newStrength) { collator.setStrength(newStrength); } - - /** - * Get the decomposition mode of this Collator. - * Decomposition mode determines how Unicode composed characters are handled. - * Adjusting decomposition mode allows the user to select between faster and more complete collation behavior. - * The three values for decomposition mode are:
        - *
      • NO_DECOMPOSITION, - *
      • CANONICAL_DECOMPOSITION - *
      • FULL_DECOMPOSITION. - *
      See the documentation for these three constants for a description of their meaning. - * @return the decomposition mode - * @see #setDecomposition - */ - public int getDecomposition() { return collator.getDecomposition(); } - - /** - * Set the decomposition mode of this Collator. - * See getDecomposition for a description of decomposition mode. - * @param decompositionMode the new decomposition mode - * @throws IllegalArgumentException if the given value is not a valid decomposition mode. - * @see #getDecomposition - */ - public void setDecomposition(int decompositionMode) { collator.setDecomposition(decompositionMode); } - - public int hashCode() { return collator.hashCode(); } - - public boolean equals(Object other) { return (other instanceof TreeCollator) ? collator.equals(((TreeCollator)other).collator) : false; } - - /** - * Provides a string description of this object. - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append(getClass().getName()); - buffer.append("["); - buffer.append(paramString().toString()); - buffer.append("]"); - return buffer.toString(); - } - - protected StringBuffer paramString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("strength="); - switch (getStrength()) { - case PRIMARY: - buffer.append("PRIMARY"); - break; - case SECONDARY: - buffer.append("SECONDARY"); - break; - case TERTIARY: - buffer.append("TERTIARY"); - break; - case IDENTICAL: - buffer.append("IDENTICAL"); - break; - default: - buffer.append("unknown"); - } - buffer.append(",decomposition="); - switch (getDecomposition()) { - case NO_DECOMPOSITION: - buffer.append("NO_DECOMPOSITION"); - break; - case CANONICAL_DECOMPOSITION: - buffer.append("CANONICAL_DECOMPOSITION"); - break; - case FULL_DECOMPOSITION: - buffer.append("FULL_DECOMPOSITION"); - break; - default: - buffer.append("unknown"); - } - if (descending) buffer.append(",descending"); - return buffer; - } - -} diff --git a/mozilla/grendel/storage/nntp/dog/util/TreeEvent.java b/mozilla/grendel/storage/nntp/dog/util/TreeEvent.java deleted file mode 100644 index 7e036ee02c2..00000000000 --- a/mozilla/grendel/storage/nntp/dog/util/TreeEvent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * TreeEvent.java - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Knife. - * - * The Initial Developer of the Original Code is dog. - * Portions created by dog are Copyright (C) 1998 dog . All Rights Reserved. - * - * Contributor(s): n/a. - */ - -package dog.util; - -import java.awt.*; -import java.awt.event.*; -import java.util.EventObject; - -/** - * A tree event. - * - * @author dog@dog.net.uk - * @version 1.0final - */ -public class TreeEvent extends ItemEvent { - - /** - * The item collapsed state change type. - */ - public static final int COLLAPSED = 3; - - /** - * The item expanded state change type. - */ - public static final int EXPANDED = 4; - - /** - * Constructs a TreeEvent object with the specified ItemSelectable source, - * type, item, and item select state. - * @param source the ItemSelectable object where the event originated - * @id the event type - * @item the item where the event occurred - * @stateChange the state change type which caused the event - */ - public TreeEvent(ItemSelectable source, int id, Object item, int stateChange) { - super(source, id, item, stateChange); - } - - public String paramString() { - Object item = getItem(); - int stateChange = getStateChange(); - - String typeStr; - switch (id) { - case ITEM_STATE_CHANGED: - typeStr = "ITEM_STATE_CHANGED"; - break; - default: - typeStr = "unknown type"; - } - - String stateStr; - switch (stateChange) { - case SELECTED: - stateStr = "SELECTED"; - break; - case DESELECTED: - stateStr = "DESELECTED"; - break; - case COLLAPSED: - stateStr = "COLLAPSED"; - break; - case EXPANDED: - stateStr = "EXPANDED"; - break; - default: - stateStr = "unknown type"; - } - return typeStr + ",item="+item + ",stateChange="+stateStr; - } - -} \ No newline at end of file