зеркало из https://github.com/mozilla/pjs.git
Upgrade to version 1.0 of the knife NNTP provider
This commit is contained in:
Родитель
c9a41210b4
Коммит
ce174877d1
|
@ -31,7 +31,7 @@ import javax.mail.internet.*;
|
|||
* The message class implementing the NNTP mail protocol.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 0.3
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Article extends MimeMessage {
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
* The Initial Developer of the Original Code is dog.
|
||||
* Portions created by dog are Copyright (C) 1998 dog <dog@dog.net.uk>. All Rights Reserved.
|
||||
*
|
||||
* Contributors: Mario Camou <mcamou@workmail.com>.
|
||||
* Edwin Woudt <edwin@woudt.nl>
|
||||
* Contributor(s): n/a.
|
||||
*/
|
||||
|
||||
package dog.mail.nntp;
|
||||
|
@ -35,7 +34,7 @@ import dog.util.*;
|
|||
* The storage class implementing the NNTP Usenet news protocol.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 0.3
|
||||
* @version 1.0
|
||||
*/
|
||||
public class NNTPStore extends Store implements StatusSource {
|
||||
|
||||
|
@ -68,9 +67,7 @@ public class NNTPStore extends Store implements StatusSource {
|
|||
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 <CR-LF>.<CR-LF>
|
||||
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
|
||||
|
@ -135,18 +132,6 @@ public class NNTPStore extends Store implements StatusSource {
|
|||
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;
|
||||
|
@ -426,20 +411,9 @@ public class NNTPStore extends Store implements StatusSource {
|
|||
// Attempts to discover which newsgroups exist and which articles have been read.
|
||||
void readNewsrc() {
|
||||
try {
|
||||
String osname = System.getProperties().getProperty("os.name");
|
||||
File newsrc;
|
||||
if (osname.startsWith("Windows") ||
|
||||
osname.startsWith("Win32") ||
|
||||
osname.startsWith("Win16") ||
|
||||
osname.startsWith("16-bit Windows")) {
|
||||
newsrc = new File(System.getProperty("user.home")+File.separator+"news-"+getHostName()+".rc");
|
||||
if (!newsrc.exists())
|
||||
newsrc = new File(System.getProperty("user.home")+File.separator+"news.rc");
|
||||
} else {
|
||||
newsrc = new File(System.getProperty("user.home")+File.separator+".newsrc-"+getHostName());
|
||||
if (!newsrc.exists())
|
||||
newsrc = new File(System.getProperty("user.home")+File.separator+".newsrc");
|
||||
}
|
||||
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;
|
||||
|
@ -742,9 +716,7 @@ public class NNTPStore extends Store implements StatusSource {
|
|||
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) {
|
||||
|
@ -752,13 +724,9 @@ public class NNTPStore extends Store implements StatusSource {
|
|||
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:
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* The Initial Developer of the Original Code is dog.
|
||||
* Portions created by dog are Copyright (C) 1998 dog <dog@dog.net.uk>. All Rights Reserved.
|
||||
*
|
||||
* Contributors: Edwin Woudt <edwin@woudt.nl>
|
||||
* Contributor(s): n/a.
|
||||
*/
|
||||
|
||||
package dog.mail.nntp;
|
||||
|
@ -30,7 +30,7 @@ import javax.mail.event.*;
|
|||
* The folder class implementing the NNTP mail protocol.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 0.3
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Newsgroup extends Folder {
|
||||
|
||||
|
@ -114,8 +114,8 @@ public class Newsgroup extends 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");
|
||||
if (mode!=READ_ONLY)
|
||||
throw new MessagingException("Newsgroup is read-only");
|
||||
((NNTPStore)store).open(this);
|
||||
open = true;
|
||||
notifyConnectionListeners(ConnectionEvent.OPENED);
|
||||
|
@ -174,18 +174,18 @@ public class Newsgroup extends Folder {
|
|||
if (!open)
|
||||
throw new MessagingException("Newsgroup is not open");
|
||||
NNTPStore s = (NNTPStore)store;
|
||||
//if (articles==null)
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.Locale;
|
|||
* A class for comparing objects in a tree.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.3
|
||||
*/
|
||||
public class ObjectCollator extends Collator {
|
||||
|
||||
|
@ -75,13 +75,6 @@ public class ObjectCollator extends Collator {
|
|||
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
|
||||
|
@ -124,7 +117,7 @@ public class ObjectCollator extends Collator {
|
|||
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()));
|
||||
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) {
|
||||
|
@ -134,7 +127,7 @@ public class ObjectCollator extends Collator {
|
|||
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()));
|
||||
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) {
|
||||
|
|
|
@ -30,7 +30,7 @@ package dog.util;
|
|||
* 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
|
||||
* @version 0.3
|
||||
*/
|
||||
public interface Referential {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.*;
|
|||
* A status message.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.1
|
||||
*/
|
||||
public class StatusEvent extends EventObject {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.*;
|
|||
* A callback interface for passing status messages.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.1
|
||||
*/
|
||||
public interface StatusListener extends EventListener {
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ package dog.util;
|
|||
* An interface for defining that an object can pass status messages.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.1
|
||||
*/
|
||||
public interface StatusSource {
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ package dog.util;
|
|||
* A timer class that wakes up listeners after a specified number of milliseconds.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.3
|
||||
*/
|
||||
public final class Timer extends Thread {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.EventObject;
|
|||
* A timer event.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.3
|
||||
*/
|
||||
public class TimerEvent extends EventObject {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.EventListener;
|
|||
* Interface for classes that wnat to recieve timer events.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 0.3
|
||||
*/
|
||||
public interface TimerListener extends EventListener {
|
||||
|
||||
|
|
|
@ -365,61 +365,43 @@ public final class Tree {
|
|||
|
||||
void removeElement(int e) {
|
||||
int len = 0;
|
||||
boolean removed = false;
|
||||
// does this element have children?
|
||||
for (int p=0; p<nparents; p++) {
|
||||
if (parents[p]==elements[e]) {
|
||||
int nc = nchildren[p];
|
||||
try {
|
||||
//System.out.println("Removing "+elements[e]);
|
||||
//printArray("parents", parents, nparents);
|
||||
if ((len = nparents-p-1)>0) {
|
||||
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);
|
||||
// remove the children of this parent first
|
||||
Object[] pchildren = new Object[nc];
|
||||
System.arraycopy(children[p], 0, pchildren, 0, nc);
|
||||
for (int c=0; c<nc; c++) {
|
||||
int ce = elementIndex(pchildren[c]);
|
||||
if (ce>-1)
|
||||
removeElement(ce);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int p=0; p<nparents && !removed; p++) {
|
||||
for (int c = 0; c<nchildren[p] && !removed; c++) {
|
||||
if (children[p][c]==elements[e]) {
|
||||
if ((len = nchildren[p]-c-1)>0) {
|
||||
System.arraycopy(children[p], c+1, children[p], c, len);
|
||||
// remove the parent
|
||||
if ((len = nparents-p-1)>0) {
|
||||
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--; p--;
|
||||
} else {
|
||||
// is this element a child of another parent?
|
||||
for (int c=0; c<nchildren[p]; c++) {
|
||||
if (children[p][c]==elements[e]) {
|
||||
// remove this element from the children array
|
||||
if ((len = nchildren[p]-c-1)>0) {
|
||||
System.arraycopy(children[p], c+1, children[p], c, len);
|
||||
}
|
||||
nchildren[p]--; c--;
|
||||
}
|
||||
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--;
|
||||
if ((len = nelements-e-1)>0) {
|
||||
System.arraycopy(elements, e+1, elements, e, len);
|
||||
System.arraycopy(depths, e+1, depths, e, len);
|
||||
}
|
||||
//printElements();
|
||||
nelements--;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.EventObject;
|
|||
* A tree event.
|
||||
*
|
||||
* @author dog@dog.net.uk
|
||||
* @version 1.0final
|
||||
* @version 2.0alpha
|
||||
*/
|
||||
public class TreeEvent extends ItemEvent {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче