forked from I2P_Developers/i2p.i2p
Compare commits
48 Commits
i2p_0_5_po
...
i2p_0_5_0_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49d6f5018f | ||
|
|
4a830e422a | ||
|
|
df6c52fe75 | ||
|
|
01979c08b3 | ||
|
|
7928ef83cc | ||
|
|
10afe0a060 | ||
|
|
ef230cfa3d | ||
|
|
2d15a42137 | ||
|
|
57d6a2f645 | ||
|
|
469a0852d7 | ||
|
|
7983bb1490 | ||
|
|
2e7eac02ed | ||
|
|
238389fc7f | ||
|
|
4cec9da0a6 | ||
|
|
00f27d4400 | ||
|
|
f61618e4a4 | ||
|
|
265d5e306e | ||
|
|
10ed058c2e | ||
|
|
8a21f0efec | ||
|
|
b8291ac5a4 | ||
|
|
c17433cb93 | ||
|
|
35fe7f8203 | ||
|
|
21f13dba43 | ||
|
|
0db239a3fe | ||
|
|
4745d61f9b | ||
|
|
b9a4c3ba52 | ||
|
|
cbf6a70a1a | ||
|
|
7d4e093b58 | ||
|
|
d27feabcb3 | ||
|
|
0d9efa17de | ||
|
|
b125b04c8d | ||
|
|
0539f1d794 | ||
|
|
a4b6709f02 | ||
|
|
f2db143a6f | ||
|
|
b615f54d41 | ||
|
|
db2328e03e | ||
|
|
e2071935ad | ||
|
|
1c40ff773f | ||
|
|
37a3645663 | ||
|
|
eb8accd1e0 | ||
|
|
3af97894b4 | ||
|
|
15a0dcf4d8 | ||
|
|
aa3a44c42a | ||
|
|
40f4b47b87 | ||
|
|
dca09d96b3 | ||
|
|
dd10747460 | ||
|
|
77176162af | ||
|
|
8b9ee4dfd7 |
@@ -21,7 +21,8 @@
|
||||
<target name="distclean" depends="clean" />
|
||||
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="${src}" destdir="${build}" classpath="${servlet}"/>
|
||||
<javac debug="true" deprecation="on" source="1.3" target="1.3"
|
||||
srcdir="${src}" destdir="${build}" classpath="${servlet}"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
|
||||
@@ -65,7 +65,8 @@ public class Daemon {
|
||||
master.merge((AddressBook) iter.next(), log);
|
||||
}
|
||||
master.write(new File(routerLocation));
|
||||
master.write(published);
|
||||
if (published != null)
|
||||
master.write(published);
|
||||
subscriptions.write();
|
||||
}
|
||||
|
||||
@@ -82,7 +83,9 @@ public class Daemon {
|
||||
.get("master_addressbook"));
|
||||
File routerFile = new File(home, (String) settings
|
||||
.get("router_addressbook"));
|
||||
File published = new File(home, (String) settings
|
||||
File published = null;
|
||||
if ("true".equals(settings.get("should_publish")))
|
||||
published = new File(home, (String) settings
|
||||
.get("published_addressbook"));
|
||||
File subscriptionFile = new File(home, (String) settings
|
||||
.get("subscriptions"));
|
||||
@@ -95,8 +98,7 @@ public class Daemon {
|
||||
AddressBook router = new AddressBook(routerFile);
|
||||
|
||||
List defaultSubs = new LinkedList();
|
||||
defaultSubs.add("http://dev.i2p/i2p/hosts.txt");
|
||||
defaultSubs.add("http://duck.i2p/hosts.txt");
|
||||
defaultSubs.add("http://i2p/NF2RLVUxVulR3IqK0sGJR0dHQcGXAzwa6rEO4WAWYXOHw-DoZhKnlbf1nzHXwMEJoex5nFTyiNMqxJMWlY54cvU~UenZdkyQQeUSBZXyuSweflUXFqKN-y8xIoK2w9Ylq1k8IcrAFDsITyOzjUKoOPfVq34rKNDo7fYyis4kT5bAHy~2N1EVMs34pi2RFabATIOBk38Qhab57Umpa6yEoE~rbyR~suDRvD7gjBvBiIKFqhFueXsR2uSrPB-yzwAGofTXuklofK3DdKspciclTVzqbDjsk5UXfu2nTrC1agkhLyqlOfjhyqC~t1IXm-Vs2o7911k7KKLGjB4lmH508YJ7G9fLAUyjuB-wwwhejoWqvg7oWvqo4oIok8LG6ECR71C3dzCvIjY2QcrhoaazA9G4zcGMm6NKND-H4XY6tUWhpB~5GefB3YczOqMbHq4wi0O9MzBFrOJEOs3X4hwboKWANf7DT5PZKJZ5KorQPsYRSq0E3wSOsFCSsdVCKUGsAAAA/i2p/hosts.txt");
|
||||
|
||||
SubscriptionList subscriptions = new SubscriptionList(subscriptionFile,
|
||||
etagsFile, lastModifiedFile, defaultSubs);
|
||||
@@ -131,6 +133,7 @@ public class Daemon {
|
||||
defaultSettings.put("master_addressbook", "../userhosts.txt");
|
||||
defaultSettings.put("router_addressbook", "../hosts.txt");
|
||||
defaultSettings.put("published_addressbook", "../eepsite/docroot/hosts.txt");
|
||||
defaultSettings.put("should_publish", "false");
|
||||
defaultSettings.put("log", "log.txt");
|
||||
defaultSettings.put("subscriptions", "subscriptions.txt");
|
||||
defaultSettings.put("etags", "etags");
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
</war>
|
||||
</target>
|
||||
<target name="precompilejsp">
|
||||
<delete dir="../jsp/WEB-INF/" />
|
||||
<delete file="../jsp/web-fragment.xml" />
|
||||
<delete file="../jsp/web-out.xml" />
|
||||
<mkdir dir="../jsp/WEB-INF/" />
|
||||
<mkdir dir="../jsp/WEB-INF/classes" />
|
||||
<!-- there are various jspc ant tasks, but they all seem a bit flakey -->
|
||||
@@ -53,7 +56,8 @@
|
||||
<arg value="-webapp" />
|
||||
<arg value="../jsp/" />
|
||||
</java>
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<javac debug="true" deprecation="on" source="1.3" target="1.3"
|
||||
destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<classpath>
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
package net.i2p.i2ptunnel;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2005 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.Iterator;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Simple stream for delivering an HTTP response to
|
||||
* the client, trivially filtered to make sure "Connection: close"
|
||||
* is always in the response.
|
||||
*
|
||||
*/
|
||||
class HTTPResponseOutputStream extends FilterOutputStream {
|
||||
private static final Log _log = new Log(HTTPResponseOutputStream.class);
|
||||
private ByteCache _cache;
|
||||
protected ByteArray _headerBuffer;
|
||||
private boolean _headerWritten;
|
||||
private byte _buf1[];
|
||||
private static final int CACHE_SIZE = 8*1024;
|
||||
|
||||
public HTTPResponseOutputStream(OutputStream raw) {
|
||||
super(raw);
|
||||
_cache = ByteCache.getInstance(8, CACHE_SIZE);
|
||||
_headerBuffer = _cache.acquire();
|
||||
_headerWritten = false;
|
||||
_buf1 = new byte[1];
|
||||
}
|
||||
|
||||
public void write(int c) throws IOException {
|
||||
_buf1[0] = (byte)c;
|
||||
write(_buf1, 0, 1);
|
||||
}
|
||||
public void write(byte buf[]) throws IOException {
|
||||
write(buf, 0, buf.length);
|
||||
}
|
||||
public void write(byte buf[], int off, int len) throws IOException {
|
||||
if (_headerWritten) {
|
||||
out.write(buf, off, len);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
ensureCapacity();
|
||||
_headerBuffer.getData()[_headerBuffer.getValid()] = buf[off+i];
|
||||
_headerBuffer.setValid(_headerBuffer.getValid()+1);
|
||||
|
||||
if (headerReceived()) {
|
||||
writeHeader();
|
||||
_headerWritten = true;
|
||||
if (i + 1 < len) // write out the remaining
|
||||
out.write(buf, off+i+1, len-i-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* filter any headers (adding or removing as necessary), and tweak
|
||||
* the first response line as necessary.
|
||||
*
|
||||
* @return response line ("200 OK", etc)
|
||||
*/
|
||||
protected String filterHeaders(String responseLine, Properties props) {
|
||||
props.setProperty("Connection", "close");
|
||||
props.setProperty("Proxy-Connection", "close");
|
||||
return responseLine;
|
||||
}
|
||||
|
||||
|
||||
/** grow (and free) the buffer as necessary */
|
||||
private void ensureCapacity() {
|
||||
if (_headerBuffer.getValid() + 1 >= _headerBuffer.getData().length) {
|
||||
int newSize = (int)(_headerBuffer.getData().length * 1.5);
|
||||
ByteArray newBuf = new ByteArray(new byte[newSize]);
|
||||
System.arraycopy(_headerBuffer.getData(), 0, newBuf.getData(), 0, _headerBuffer.getValid());
|
||||
newBuf.setValid(_headerBuffer.getValid());
|
||||
newBuf.setOffset(0);
|
||||
if (_headerBuffer.getData().length == CACHE_SIZE)
|
||||
_cache.release(_headerBuffer);
|
||||
_headerBuffer = newBuf;
|
||||
}
|
||||
}
|
||||
|
||||
/** are the headers finished? */
|
||||
private boolean headerReceived() {
|
||||
if (_headerBuffer.getValid() < 3) return false;
|
||||
byte first = _headerBuffer.getData()[_headerBuffer.getValid()-3];
|
||||
byte second = _headerBuffer.getData()[_headerBuffer.getValid()-2];
|
||||
byte third = _headerBuffer.getData()[_headerBuffer.getValid()-1];
|
||||
return (isNL(second) && isNL(third)) || // \n\n
|
||||
(isNL(first) && isNL(third)); // \n\r\n
|
||||
}
|
||||
|
||||
/** we ignore any potential \r, since we trim it on write anyway */
|
||||
private static final byte NL = '\n';
|
||||
private boolean isNL(byte b) { return (b == NL); }
|
||||
|
||||
/** ok, received, now munge & write it */
|
||||
private void writeHeader() throws IOException {
|
||||
Properties props = new Properties();
|
||||
String responseLine = null;
|
||||
|
||||
int lastEnd = -1;
|
||||
for (int i = 0; i < _headerBuffer.getValid(); i++) {
|
||||
if (isNL(_headerBuffer.getData()[i])) {
|
||||
if (lastEnd == -1) {
|
||||
responseLine = new String(_headerBuffer.getData(), 0, i+1); // includes NL
|
||||
} else {
|
||||
for (int j = lastEnd+1; j < i; j++) {
|
||||
if (_headerBuffer.getData()[j] == ':') {
|
||||
String key = new String(_headerBuffer.getData(), lastEnd+1, j-(lastEnd+1));
|
||||
String val = new String(_headerBuffer.getData(), j+2, i-(j+2));
|
||||
props.setProperty(key, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastEnd = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (responseLine == null)
|
||||
throw new IOException("No HTTP response line, with props=" + props);
|
||||
|
||||
responseLine = filterHeaders(responseLine, props);
|
||||
responseLine = (responseLine.trim() + "\n");
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer msg = new StringBuffer(responseLine.length() + props.size() * 64);
|
||||
msg.append("HTTP response: first line [").append(responseLine.trim());
|
||||
msg.append("] options: \n");
|
||||
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = (String)iter.next();
|
||||
String val = props.getProperty(key);
|
||||
msg.append('[').append(key.trim()).append("]=[").append(val.trim()).append("]\n");
|
||||
}
|
||||
|
||||
_log.debug(msg.toString());
|
||||
}
|
||||
|
||||
out.write(responseLine.getBytes());
|
||||
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = (String)iter.next();
|
||||
String val = props.getProperty(key);
|
||||
String line = key.trim() + ": " + val.trim() + "\n";
|
||||
out.write(line.getBytes());
|
||||
}
|
||||
out.write("\n".getBytes()); // end of the headers
|
||||
|
||||
// done, shove off
|
||||
if (_headerBuffer.getData().length == CACHE_SIZE)
|
||||
_cache.release(_headerBuffer);
|
||||
else
|
||||
_headerBuffer = null;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
String simple = "HTTP/1.1 200 OK\n" +
|
||||
"foo: bar\n" +
|
||||
"baz: bat\n" +
|
||||
"\n" +
|
||||
"hi ho, this is the body";
|
||||
String filtered = "HTTP/1.1 200 OK\n" +
|
||||
"Connection: keep-alive\n" +
|
||||
"foo: bar\n" +
|
||||
"baz: bat\n" +
|
||||
"\n" +
|
||||
"hi ho, this is the body";
|
||||
String winfilter= "HTTP/1.1 200 OK\r\n" +
|
||||
"Connection: keep-alive\r\n" +
|
||||
"foo: bar\r\n" +
|
||||
"baz: bat\r\n" +
|
||||
"\r\n" +
|
||||
"hi ho, this is the body";
|
||||
String minimal = "HTTP/1.1 200 OK\n" +
|
||||
"\n" +
|
||||
"hi ho, this is the body";
|
||||
String winmin = "HTTP/1.1 200 OK\r\n" +
|
||||
"\r\n" +
|
||||
"hi ho, this is the body";
|
||||
String invalid1 = "HTTP/1.1 200 OK\n";
|
||||
String invalid2 = "HTTP/1.1 200 OK";
|
||||
String invalid3 = "HTTP 200 OK\r\n";
|
||||
String invalid4 = "HTTP 200 OK\r";
|
||||
String large = "HTTP/1.1 200 OK\n" +
|
||||
"Last-modified: Tue, 25 Nov 2003 12:05:38 GMT\n" +
|
||||
"Expires: Tue, 25 Nov 2003 12:05:38 GMT\n" +
|
||||
"Content-length: 32\n" +
|
||||
"\n" +
|
||||
"hi ho, this is the body";
|
||||
/* */
|
||||
test("Simple", simple);
|
||||
test("Filtered", filtered);
|
||||
test("Filtered windows", winfilter);
|
||||
test("Minimal", minimal);
|
||||
test("Windows", winmin);
|
||||
test("Large", large);
|
||||
test("Invalid (short headers)", invalid1);
|
||||
test("Invalid (no headers)", invalid2);
|
||||
test("Invalid (windows with short headers)", invalid3);
|
||||
test("Invalid (windows no headers)", invalid4);
|
||||
/* */
|
||||
}
|
||||
|
||||
private static void test(String name, String orig) {
|
||||
System.out.println("====Testing: " + name + "\n" + orig + "\n------------");
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
||||
HTTPResponseOutputStream resp = new HTTPResponseOutputStream(baos);
|
||||
resp.write(orig.getBytes());
|
||||
resp.flush();
|
||||
String received = new String(baos.toByteArray());
|
||||
System.out.println(received);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,12 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.I2PSessionException;
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketManager;
|
||||
import net.i2p.client.streaming.I2PSocketManagerFactory;
|
||||
@@ -104,11 +101,17 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
||||
this.l = l;
|
||||
this.handlerName = handlerName + _clientId;
|
||||
|
||||
synchronized (sockLock) {
|
||||
if (ownDest) {
|
||||
sockMgr = buildSocketManager();
|
||||
} else {
|
||||
sockMgr = getSocketManager();
|
||||
while (sockMgr == null) {
|
||||
synchronized (sockLock) {
|
||||
if (ownDest) {
|
||||
sockMgr = buildSocketManager();
|
||||
} else {
|
||||
sockMgr = getSocketManager();
|
||||
}
|
||||
}
|
||||
if (sockMgr == null) {
|
||||
_log.log(Log.CRIT, "Unable to create socket manager");
|
||||
try { Thread.sleep(10*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
if (sockMgr == null) {
|
||||
|
||||
@@ -22,9 +22,7 @@ import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketOptions;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@@ -418,7 +416,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
|
||||
I2PSocket i2ps = createI2PSocket(dest, getDefaultOptions(opts));
|
||||
byte[] data = newRequest.toString().getBytes("ISO-8859-1");
|
||||
Runnable onTimeout = new OnTimeout(s, s.getOutputStream(), targetRequest, usingWWWProxy, currentProxy, requestId);
|
||||
I2PTunnelRunner runner = new I2PTunnelRunner(s, i2ps, sockLock, data, mySockets, onTimeout);
|
||||
I2PTunnelRunner runner = new I2PTunnelHTTPClientRunner(s, i2ps, sockLock, data, mySockets, onTimeout);
|
||||
} catch (SocketException ex) {
|
||||
_log.info(getPrefix(requestId) + "Error trying to connect", ex);
|
||||
l.log(ex.getMessage());
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* I2PTunnel is GPL'ed (with the exception mentioned in I2PTunnel.java)
|
||||
* (c) 2003 - 2004 mihi
|
||||
*/
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Override the response with a stream filtering the HTTP headers
|
||||
* received. Specifically, this makes sure we get Connection: close,
|
||||
* so the browser knows they really shouldn't try to use persistent
|
||||
* connections. The HTTP server *should* already be setting this,
|
||||
* since the HTTP headers sent by the browser specify Connection: close,
|
||||
* and the server should echo it. However, both broken and malicious
|
||||
* servers could ignore that, potentially confusing the user.
|
||||
*
|
||||
*/
|
||||
public class I2PTunnelHTTPClientRunner extends I2PTunnelRunner {
|
||||
public I2PTunnelHTTPClientRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List sockList, Runnable onTimeout) {
|
||||
super(s, i2ps, slock, initialI2PData, sockList, onTimeout);
|
||||
}
|
||||
|
||||
protected OutputStream getSocketOut() throws IOException {
|
||||
OutputStream raw = super.getSocketOut();
|
||||
return new HTTPResponseOutputStream(raw);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
@@ -17,7 +16,6 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.streaming.I2PServerSocket;
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketManager;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.I2PThread;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
@@ -31,7 +30,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
|
||||
* Sun's impl of BufferedOutputStream), but that is the streaming
|
||||
* api's job...
|
||||
*/
|
||||
static int MAX_PACKET_SIZE = 1024 * 32;
|
||||
static int MAX_PACKET_SIZE = 1024 * 4;
|
||||
|
||||
static final int NETWORK_BUFFER_SIZE = MAX_PACKET_SIZE;
|
||||
|
||||
@@ -112,10 +111,13 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
|
||||
return startedOn;
|
||||
}
|
||||
|
||||
protected InputStream getSocketIn() throws IOException { return s.getInputStream(); }
|
||||
protected OutputStream getSocketOut() throws IOException { return s.getOutputStream(); }
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
InputStream in = s.getInputStream();
|
||||
OutputStream out = s.getOutputStream(); // = new BufferedOutputStream(s.getOutputStream(), NETWORK_BUFFER_SIZE);
|
||||
InputStream in = getSocketIn();
|
||||
OutputStream out = getSocketOut(); // = new BufferedOutputStream(s.getOutputStream(), NETWORK_BUFFER_SIZE);
|
||||
i2ps.setSocketErrorListener(this);
|
||||
InputStream i2pin = i2ps.getInputStream();
|
||||
OutputStream i2pout = i2ps.getOutputStream(); //new BufferedOutputStream(i2ps.getOutputStream(), MAX_PACKET_SIZE);
|
||||
@@ -216,7 +218,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
|
||||
this.out = out;
|
||||
_toI2P = toI2P;
|
||||
direction = (toI2P ? "toI2P" : "fromI2P");
|
||||
_cache = ByteCache.getInstance(256, NETWORK_BUFFER_SIZE);
|
||||
_cache = ByteCache.getInstance(32, NETWORK_BUFFER_SIZE);
|
||||
setName("StreamForwarder " + _runnerId + "." + (++__forwarderId));
|
||||
start();
|
||||
}
|
||||
@@ -281,6 +283,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
|
||||
//else
|
||||
// _log.warn("You may ignore this", ex);
|
||||
} finally {
|
||||
_cache.release(ba);
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
_log.info(direction + ": done forwarding between "
|
||||
+ from + " and " + to);
|
||||
@@ -302,7 +305,6 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
|
||||
finishLock.notifyAll();
|
||||
// the main thread will close sockets etc. now
|
||||
}
|
||||
_cache.release(ba);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,16 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
Properties props = new Properties();
|
||||
props.putAll(getTunnel().getClientOptions());
|
||||
synchronized (slock) {
|
||||
sockMgr = I2PSocketManagerFactory.createManager(privData, getTunnel().host, Integer.parseInt(getTunnel().port),
|
||||
props);
|
||||
while (sockMgr == null) {
|
||||
synchronized (slock) {
|
||||
sockMgr = I2PSocketManagerFactory.createManager(privData, getTunnel().host, Integer.parseInt(getTunnel().port),
|
||||
props);
|
||||
|
||||
}
|
||||
if (sockMgr == null) {
|
||||
_log.log(Log.CRIT, "Unable to create socket manager");
|
||||
try { Thread.sleep(10*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
sockMgr.setName("Server");
|
||||
getTunnel().addSession(sockMgr.getSession());
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
@@ -63,6 +61,8 @@ class WebEditPageFormGenerator {
|
||||
buf.append("value=\"squid.i2p\" ");
|
||||
buf.append("/><br />\n");
|
||||
|
||||
addStreamingOptions(buf, controller);
|
||||
|
||||
buf.append("<hr />Note: the following options are shared across all client tunnels and");
|
||||
buf.append(" HTTP proxies<br />\n");
|
||||
|
||||
@@ -86,6 +86,8 @@ class WebEditPageFormGenerator {
|
||||
buf.append("value=\"").append(controller.getTargetDestination()).append("\" ");
|
||||
buf.append(" /> (either the hosts.txt name or the full base64 destination)<br />\n");
|
||||
|
||||
addStreamingOptions(buf, controller);
|
||||
|
||||
buf.append("<hr />Note: the following options are shared across all client tunnels and");
|
||||
buf.append(" HTTP proxies<br />\n");
|
||||
|
||||
@@ -124,6 +126,8 @@ class WebEditPageFormGenerator {
|
||||
buf.append("<input type=\"hidden\" name=\"privKeyGenerate\" value=\"true\" />");
|
||||
}
|
||||
|
||||
addStreamingOptions(buf, controller);
|
||||
|
||||
addOptions(buf, controller);
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Save\">\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Remove\">\n");
|
||||
@@ -166,6 +170,8 @@ class WebEditPageFormGenerator {
|
||||
buf.append("<input type=\"hidden\" name=\"privKeyGenerate\" value=\"true\" />");
|
||||
}
|
||||
|
||||
addStreamingOptions(buf, controller);
|
||||
|
||||
addOptions(buf, controller);
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Save\">\n");
|
||||
buf.append("<input type=\"submit\" name=\"action\" value=\"Remove\">\n");
|
||||
@@ -206,8 +212,9 @@ class WebEditPageFormGenerator {
|
||||
buf.append(" checked=\"true\" />\n<br />\n");
|
||||
else
|
||||
buf.append(" />\n<br />\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the fields asking for what port and interface the tunnel should
|
||||
* listen on.
|
||||
@@ -245,6 +252,46 @@ class WebEditPageFormGenerator {
|
||||
buf.append("\"><br />\n");
|
||||
}
|
||||
|
||||
private static void addStreamingOptions(StringBuffer buf, TunnelController controller) {
|
||||
int connectDelay = 0;
|
||||
int maxWindowSize = -1;
|
||||
|
||||
Properties opts = getOptions(controller);
|
||||
if (opts != null) {
|
||||
String delay = opts.getProperty("i2p.streaming.connectDelay");
|
||||
if (delay != null) {
|
||||
try {
|
||||
connectDelay = Integer.parseInt(delay);
|
||||
} catch (NumberFormatException nfe) {
|
||||
connectDelay = 0;
|
||||
}
|
||||
}
|
||||
String max = opts.getProperty("i2p.streaming.maxWindowSize");
|
||||
if (max != null) {
|
||||
try {
|
||||
maxWindowSize = Integer.parseInt(max);
|
||||
} catch (NumberFormatException nfe) {
|
||||
maxWindowSize = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("<b>Delay connection briefly? </b> ");
|
||||
buf.append("<input type=\"checkbox\" name=\"connectDelay\" value=\"");
|
||||
buf.append((connectDelay > 0 ? connectDelay : 1000)).append("\" ");
|
||||
if (connectDelay > 0)
|
||||
buf.append("checked=\"true\" ");
|
||||
buf.append("/> (useful for brief request/response connections)<br />\n");
|
||||
|
||||
buf.append("<b>Communication profile:</b>");
|
||||
buf.append("<select name=\"profile\">");
|
||||
if (maxWindowSize <= 0)
|
||||
buf.append("<option value=\"interactive\">Interactive</option><option value=\"bulk\" selected=\"true\">Bulk</option>");
|
||||
else
|
||||
buf.append("<option value=\"interactive\" selected=\"true\">Interactive</option><option value=\"bulk\">Bulk</option>");
|
||||
buf.append("</select><br />\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fields for customizing the I2PSession options, including helpers for
|
||||
* tunnel depth and count, as well as I2CP host and port.
|
||||
@@ -255,8 +302,6 @@ class WebEditPageFormGenerator {
|
||||
private static void addOptions(StringBuffer buf, TunnelController controller) {
|
||||
int tunnelDepth = 2;
|
||||
int numTunnels = 2;
|
||||
int connectDelay = 0;
|
||||
int maxWindowSize = -1;
|
||||
Properties opts = getOptions(controller);
|
||||
if (opts != null) {
|
||||
String depth = opts.getProperty("inbound.length");
|
||||
@@ -275,22 +320,6 @@ class WebEditPageFormGenerator {
|
||||
numTunnels = 2;
|
||||
}
|
||||
}
|
||||
String delay = opts.getProperty("i2p.streaming.connectDelay");
|
||||
if (delay != null) {
|
||||
try {
|
||||
connectDelay = Integer.parseInt(delay);
|
||||
} catch (NumberFormatException nfe) {
|
||||
connectDelay = 0;
|
||||
}
|
||||
}
|
||||
String max = opts.getProperty("i2p.streaming.maxWindowSize");
|
||||
if (max != null) {
|
||||
try {
|
||||
maxWindowSize = Integer.parseInt(max);
|
||||
} catch (NumberFormatException nfe) {
|
||||
maxWindowSize = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("<b>Tunnel depth:</b> ");
|
||||
@@ -330,21 +359,6 @@ class WebEditPageFormGenerator {
|
||||
}
|
||||
buf.append("</select><br />\n");
|
||||
|
||||
buf.append("<b>Delay connection briefly? </b> ");
|
||||
buf.append("<input type=\"checkbox\" name=\"connectDelay\" value=\"");
|
||||
buf.append((connectDelay > 0 ? connectDelay : 1000)).append("\" ");
|
||||
if (connectDelay > 0)
|
||||
buf.append("checked=\"true\" ");
|
||||
buf.append("/> (useful for brief request/response connections)<br />\n");
|
||||
|
||||
buf.append("<b>Communication profile:</b>");
|
||||
buf.append("<select name=\"profile\">");
|
||||
if (maxWindowSize <= 0)
|
||||
buf.append("<option value=\"interactive\">Interactive</option><option value=\"bulk\" selected=\"true\">Bulk</option>");
|
||||
else
|
||||
buf.append("<option value=\"interactive\" selected=\"true\">Interactive</option><option value=\"bulk\">Bulk</option>");
|
||||
buf.append("</select><br />\n");
|
||||
|
||||
buf.append("<b>I2CP host:</b> ");
|
||||
buf.append("<input type=\"text\" name=\"clientHost\" size=\"20\" value=\"");
|
||||
if ( (controller != null) && (controller.getI2CPHost() != null) )
|
||||
|
||||
@@ -296,6 +296,10 @@ public class WebEditPageHelper {
|
||||
cOpt.setProperty("option.inbound.length", _tunnelDepth);
|
||||
cOpt.setProperty("option.outbound.length", _tunnelDepth);
|
||||
}
|
||||
// these are per-proxy settings, not per-session settings, and
|
||||
// as such don't need to be shared. the values are propogated
|
||||
// to the current tunnel's settings via cur.setConfig above
|
||||
/*
|
||||
if (_connectDelay)
|
||||
cOpt.setProperty("option.i2p.streaming.connectDelay", "1000");
|
||||
else
|
||||
@@ -304,6 +308,7 @@ public class WebEditPageHelper {
|
||||
cOpt.setProperty("option.i2p.streaming.maxWindowSize", "1");
|
||||
else
|
||||
cOpt.remove("option.i2p.streaming.maxWindowSize");
|
||||
*/
|
||||
if (_name != null) {
|
||||
cOpt.setProperty("option.inbound.nickname", _name);
|
||||
cOpt.setProperty("option.outbound.nickname", _name);
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.i2p.I2PException;
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketManager;
|
||||
import net.i2p.client.streaming.I2PSocketManagerFactory;
|
||||
import net.i2p.client.streaming.I2PSocketOptions;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.i2ptunnel.I2PTunnel;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@@ -4,27 +4,16 @@
|
||||
*/
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.I2PSessionException;
|
||||
import net.i2p.client.I2PSessionListener;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Define the configuration for streaming and verifying data on the socket.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,8 +8,6 @@ import java.io.OutputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
@@ -122,11 +122,12 @@ public class StreamSinkServer {
|
||||
long written = 0;
|
||||
int read = 0;
|
||||
while ( (read = in.read(buf)) != -1) {
|
||||
_fos.write(buf, 0, read);
|
||||
//_fos.write(buf, 0, read);
|
||||
written += read;
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("read and wrote " + read);
|
||||
}
|
||||
_fos.write(("written: [" + written + "]\n").getBytes());
|
||||
long lifetime = System.currentTimeMillis() - start;
|
||||
_log.error("Got EOF from client socket [written=" + written + " lifetime=" + lifetime + "]");
|
||||
} catch (IOException ioe) {
|
||||
@@ -150,7 +151,7 @@ public class StreamSinkServer {
|
||||
StreamSinkServer server = null;
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
server = new StreamSinkServer("dataDir", "server.key", "localhost", 10001);
|
||||
server = new StreamSinkServer("dataDir", "server.key", "localhost", 7654);
|
||||
break;
|
||||
case 2:
|
||||
server = new StreamSinkServer(args[0], args[1]);
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.I2PThread;
|
||||
|
||||
@@ -74,7 +74,9 @@
|
||||
<arg value="../jsp/" />
|
||||
</java>
|
||||
|
||||
<javac destdir="../jsp/WEB-INF/classes/" srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<javac debug="true" deprecation="on" source="1.3" target="1.3"
|
||||
destdir="../jsp/WEB-INF/classes/"
|
||||
srcdir="../jsp/WEB-INF/classes" includes="**/*.java">
|
||||
<classpath>
|
||||
<pathelement location="../../jetty/jettylib/jasper-runtime.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
|
||||
@@ -17,11 +17,6 @@ public class ConfigAdvancedHandler extends FormHandler {
|
||||
private boolean _shouldSave;
|
||||
private String _config;
|
||||
|
||||
public void ConfigNetHandler() {
|
||||
_shouldSave = false;
|
||||
_forceRestart = false;
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
if (_shouldSave) {
|
||||
saveChanges();
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Properties;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the logging config form and act
|
||||
@@ -21,10 +18,6 @@ public class ConfigLoggingHandler extends FormHandler {
|
||||
private String _dateFormat;
|
||||
private String _fileSize;
|
||||
|
||||
public void ConfigNetHandler() {
|
||||
_shouldSave = false;
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
if (_shouldSave) {
|
||||
saveChanges();
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
|
||||
public class ConfigLoggingHelper {
|
||||
|
||||
@@ -13,15 +13,10 @@ import java.net.URLConnection;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.time.Timestamper;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the main config form and act
|
||||
* upon the values.
|
||||
@@ -41,13 +36,6 @@ public class ConfigNetHandler extends FormHandler {
|
||||
private String _reseedFrom;
|
||||
private String _sharePct;
|
||||
|
||||
public void ConfigNetHandler() {
|
||||
_guessRequested = false;
|
||||
_reseedRequested = false;
|
||||
_saveRequested = false;
|
||||
_timeSyncEnabled = false;
|
||||
}
|
||||
|
||||
protected void processForm() {
|
||||
if (_guessRequested) {
|
||||
guessHostname();
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.time.Timestamper;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
|
||||
public class ConfigNetHelper {
|
||||
private RouterContext _context;
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.apps.systray.SysTray;
|
||||
import net.i2p.apps.systray.UrlLauncher;
|
||||
@@ -20,7 +19,6 @@ import org.tanukisoftware.wrapper.WrapperManager;
|
||||
*
|
||||
*/
|
||||
public class ConfigServiceHandler extends FormHandler {
|
||||
public void ConfigNetHandler() {}
|
||||
|
||||
private class UpdateWrapperManagerTask implements Runnable {
|
||||
private int _exitCode;
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
@@ -49,9 +42,11 @@ public class ConfigTunnelsHelper {
|
||||
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash());
|
||||
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash());
|
||||
|
||||
String name = (in != null ? in.getDestinationNickname() : null);
|
||||
if ( (in == null) || (out == null) ) continue;
|
||||
|
||||
String name = in.getDestinationNickname();
|
||||
if (name == null)
|
||||
name = (out != null ? out.getDestinationNickname() : null);
|
||||
name = out.getDestinationNickname();
|
||||
if (name == null)
|
||||
name = dest.calculateHash().toBase64().substring(0,6);
|
||||
|
||||
@@ -110,7 +105,7 @@ public class ConfigTunnelsHelper {
|
||||
buf.append("</tr>\n");
|
||||
|
||||
// tunnel depth variance
|
||||
buf.append("<tr><td>Variance</td>\n");
|
||||
buf.append("<tr><td>Randomization</td>\n");
|
||||
buf.append("<td><select name=\"").append(index).append(".varianceInbound\">\n");
|
||||
buf.append("<option value=\"0\" ");
|
||||
if (in.getLengthVariance() == 0) buf.append(" selected=\"true\" ");
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.FileUtil;
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ package net.i2p.router.web;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.ClientTunnelSettings;
|
||||
|
||||
/**
|
||||
* Simple form handler base class - does not depend on servlets or jsp,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
@@ -41,6 +39,22 @@ public class LogsHelper {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getCriticalLogs() {
|
||||
List msgs = _context.logManager().getBuffer().getMostRecentCriticalMessages();
|
||||
StringBuffer buf = new StringBuffer(16*1024);
|
||||
buf.append("<ul>");
|
||||
buf.append("<code>\n");
|
||||
for (int i = msgs.size(); i > 0; i--) {
|
||||
String msg = (String)msgs.get(i - 1);
|
||||
buf.append("<li>");
|
||||
buf.append(msg);
|
||||
buf.append("</li>\n");
|
||||
}
|
||||
buf.append("</code></ul>\n");
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getServiceLogs() {
|
||||
String str = FileUtil.readTextFile("wrapper.log", 500, false);
|
||||
if (str == null)
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.admin.StatsGenerator;
|
||||
|
||||
|
||||
@@ -8,14 +8,12 @@ import java.io.OutputStream;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Handler to deal with reseed requests. This reseed from the URL
|
||||
@@ -100,11 +98,12 @@ public class ReseedHandler {
|
||||
URL url = new URL(seedURL + (seedURL.endsWith("/") ? "" : "/") + "routerInfo-" + peer + ".dat");
|
||||
|
||||
byte data[] = readURL(url);
|
||||
//System.out.println("read: " + (data != null ? data.length : -1));
|
||||
writeSeed(peer, data);
|
||||
}
|
||||
|
||||
private static byte[] readURL(URL url) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
|
||||
String hostname = url.getHost();
|
||||
int port = url.getPort();
|
||||
if (port < 0)
|
||||
@@ -113,9 +112,28 @@ public class ReseedHandler {
|
||||
OutputStream out = s.getOutputStream();
|
||||
InputStream in = s.getInputStream();
|
||||
String request = getRequest(url);
|
||||
System.out.println("Sending to " + hostname +":"+ port + ": " + request);
|
||||
//System.out.println("Sending to " + hostname +":"+ port + ": " + request);
|
||||
out.write(request.getBytes());
|
||||
out.flush();
|
||||
// skip the HTTP response headers
|
||||
// (if we were smart, we'd check for HTTP 200, content-length, etc)
|
||||
int consecutiveNL = 0;
|
||||
while (true) {
|
||||
int cur = in.read();
|
||||
switch (cur) {
|
||||
case -1:
|
||||
return null;
|
||||
case '\n':
|
||||
case '\r':
|
||||
consecutiveNL++;
|
||||
break;
|
||||
default:
|
||||
consecutiveNL = 0;
|
||||
}
|
||||
if (consecutiveNL == 4)
|
||||
break;
|
||||
}
|
||||
// ok, past the headers, grab the goods
|
||||
byte buf[] = new byte[1024];
|
||||
while (true) {
|
||||
int read = in.read(buf);
|
||||
@@ -155,6 +173,6 @@ public class ReseedHandler {
|
||||
|
||||
public static void main(String args[]) {
|
||||
reseed();
|
||||
System.out.println("Done reseeding");
|
||||
//System.out.println("Done reseeding");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import org.mortbay.jetty.servlet.WebApplicationContext;
|
||||
import org.mortbay.http.DigestAuthenticator;
|
||||
import org.mortbay.http.handler.SecurityHandler;
|
||||
import org.mortbay.http.HashUserRealm;
|
||||
import org.mortbay.http.HttpRequest;
|
||||
import org.mortbay.http.SecurityConstraint;
|
||||
import org.mortbay.http.Authenticator;
|
||||
import org.mortbay.util.MultiException;
|
||||
|
||||
public class RouterConsoleRunner {
|
||||
private Server _server;
|
||||
@@ -78,7 +75,7 @@ public class RouterConsoleRunner {
|
||||
private void initialize(WebApplicationContext context) {
|
||||
String password = getPassword();
|
||||
if (password != null) {
|
||||
HashUserRealm realm = new HashUserRealm();
|
||||
HashUserRealm realm = new HashUserRealm("i2prouter");
|
||||
realm.put("admin", password);
|
||||
realm.addUserToRole("admin", "routerAdmin");
|
||||
context.setRealm(realm);
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.i2p.router.web;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Writer;
|
||||
|
||||
import net.i2p.data.Hash;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
@@ -70,7 +70,32 @@ public class SummaryHelper {
|
||||
else
|
||||
return DataHelper.formatDuration(router.getUptime());
|
||||
}
|
||||
|
||||
|
||||
private static final DateFormat _fmt = new java.text.SimpleDateFormat("HH:mm:ss", Locale.UK);
|
||||
public String getTime() {
|
||||
if (_context == null) return "";
|
||||
|
||||
String now = null;
|
||||
synchronized (_fmt) {
|
||||
now = _fmt.format(new Date(_context.clock().now()));
|
||||
}
|
||||
|
||||
long ms = _context.clock().getOffset();
|
||||
|
||||
if (ms < 60 * 1000) {
|
||||
return now + " (" + (ms / 1000) + "s)";
|
||||
} else if (ms < 60 * 1000) {
|
||||
return now + " (" + (ms / (60 * 1000)) + "m)";
|
||||
} else if (ms < 24 * 60 * 60 * 1000) {
|
||||
return now + " (" + (ms / (60 * 60 * 1000)) + "h)";
|
||||
} else {
|
||||
return now + " (" + (ms / (24 * 60 * 60 * 1000)) + "d)";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean allowReseed() {
|
||||
return (_context.netDb().getKnownRouters() < 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve amount of used memory.
|
||||
|
||||
@@ -34,7 +34,11 @@ by their binary code license. This product includes software developed by the A
|
||||
|
||||
<p>Another application you can see on this webpage is <a href="http://www.i2p.net/i2ptunnel">I2PTunnel</a>
|
||||
(your <a href="i2ptunnel/" target="_blank">web interface</a>) - a GPL'ed application written by mihi that
|
||||
lets you tunnel normal TCP/IP traffic over I2P (such as the eepproxy and the irc proxy).</p>
|
||||
lets you tunnel normal TCP/IP traffic over I2P (such as the eepproxy and the irc proxy). There is also a
|
||||
<a href="http://susi.i2p/">susimail</a> web based mail client <a href="susimail/susimail">available</a> on
|
||||
the console, which is a GPL'ed application written by susi23. The addressbook application, written by
|
||||
<a href="http://ragnarok.i2p/">Ragnarok</a> helps maintain your hosts.txt files (see ./addressbook/ for
|
||||
more information).</p>
|
||||
|
||||
<p>The router by default also includes human's public domain <a href="http://www.i2p.net/sam">SAM</a> bridge,
|
||||
which other client applications (such the <a href="http://duck.i2p/i2p-bt/">bittorrent port</a>) can use.
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
<h4>Connection logs:</h4><a name="connectionlogs"> </a>
|
||||
<jsp:getProperty name="logsHelper" property="connectionLogs" />
|
||||
<hr />
|
||||
<h4>Critical logs:</h4><a name="criticallogs"> </a>
|
||||
<jsp:getProperty name="logsHelper" property="criticalLogs" />
|
||||
<hr />
|
||||
<h4>Service logs:</h4><a name="servicelogs"> </a>
|
||||
<jsp:getProperty name="logsHelper" property="serviceLogs" />
|
||||
</div>
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
<h4>
|
||||
<a href="tunnels.jsp">Tunnels</a> |
|
||||
<a href="profiles.jsp">Profiles</a> |
|
||||
<a href="netdb.jsp">Network Database</a> |
|
||||
<a href="netdb.jsp">NetDB</a> |
|
||||
<a href="logs.jsp">Logs</a> |
|
||||
<a href="oldconsole.jsp">Old console</a> |
|
||||
<a href="oldconsole.jsp">Internals</a> |
|
||||
<a href="oldstats.jsp">Stats</a> |
|
||||
<a href="i2ptunnel/" target="_blank">I2PTunnel</a>
|
||||
<a href="i2ptunnel/" target="_blank">I2PTunnel</a> |
|
||||
<a href="susimail/susimail" target="_blank">Susimail</a>
|
||||
<jsp:useBean class="net.i2p.router.web.NavHelper" id="navhelper" scope="request" />
|
||||
<jsp:setProperty name="navhelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
|
||||
<jsp:getProperty name="navhelper" property="clientAppLinks" />
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<b>Ident:</b> <jsp:getProperty name="helper" property="ident" /><br />
|
||||
<b>Version:</b> <jsp:getProperty name="helper" property="version" /><br />
|
||||
<b>Uptime:</b> <jsp:getProperty name="helper" property="uptime" /><br />
|
||||
<b>Now:</b> <jsp:getProperty name="helper" property="time" /><br />
|
||||
<b>Memory:</b> <jsp:getProperty name="helper" property="memory" /><br />
|
||||
<hr />
|
||||
|
||||
@@ -23,7 +24,7 @@
|
||||
if (helper.getActivePeers() <= 0) {
|
||||
%><b><a href="config.jsp">check your NAT/firewall</a></b><br /><%
|
||||
}
|
||||
if (helper.getActiveProfiles() <= 10) { // 10 is the min fallback
|
||||
if (helper.allowReseed()) {
|
||||
if ("true".equals(System.getProperty("net.i2p.router.web.ReseedHandler.reseedInProgress", "false"))) {
|
||||
out.print(" <i>reseeding</i>");
|
||||
} else {
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@@ -221,7 +220,7 @@ public class SAMBridge implements Runnable {
|
||||
SAMBridge bridge = new SAMBridge(host, port, opts, keyfile);
|
||||
I2PThread t = new I2PThread(bridge, "SAMListener");
|
||||
if (Boolean.valueOf(System.getProperty("sam.shutdownOnOOM", "false")).booleanValue()) {
|
||||
t.addOOMEventListener(new I2PThread.OOMEventListener() {
|
||||
I2PThread.addOOMEventListener(new I2PThread.OOMEventListener() {
|
||||
public void outOfMemory(OutOfMemoryError err) {
|
||||
err.printStackTrace();
|
||||
System.err.println("OOMed, die die die");
|
||||
|
||||
@@ -8,9 +8,7 @@ package net.i2p.sam;
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
|
||||
@@ -132,6 +132,8 @@ public class SAMStreamSession {
|
||||
if (socketMgr == null) {
|
||||
throw new SAMException("Error creating I2PSocketManager");
|
||||
}
|
||||
|
||||
socketMgr.addDisconnectListener(new DisconnectListener());
|
||||
|
||||
forceFlush = Boolean.valueOf(allprops.getProperty(PROP_FORCE_FLUSH, DEFAULT_FORCE_FLUSH)).booleanValue();
|
||||
|
||||
@@ -156,6 +158,12 @@ public class SAMStreamSession {
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
private class DisconnectListener implements I2PSocketManager.DisconnectListener {
|
||||
public void sessionDisconnected() {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SAM STREAM session Destination.
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.Socket;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.i2p.sam.client;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
package net.i2p.sam.client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.I2PThread;
|
||||
|
||||
import net.i2p.sam.client.SAMEventHandler;
|
||||
import net.i2p.sam.client.SAMClientEventListenerImpl;
|
||||
import net.i2p.sam.client.SAMReader;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
package net.i2p.sam.client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.I2PThread;
|
||||
|
||||
import net.i2p.sam.client.SAMEventHandler;
|
||||
import net.i2p.sam.client.SAMClientEventListenerImpl;
|
||||
import net.i2p.sam.client.SAMReader;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,19 +2,15 @@ package net.i2p.client.streaming;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.SessionTag;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
|
||||
@@ -57,7 +53,7 @@ public class Connection {
|
||||
private I2PSocketFull _socket;
|
||||
/** set to an error cause if the connection could not be established */
|
||||
private String _connectionError;
|
||||
private boolean _disconnectScheduled;
|
||||
private long _disconnectScheduledOn;
|
||||
private long _lastReceivedOn;
|
||||
private ActivityTimer _activityTimer;
|
||||
/** window size when we last saw congestion */
|
||||
@@ -76,7 +72,7 @@ public class Connection {
|
||||
private long _lifetimeDupMessageReceived;
|
||||
|
||||
public static final long MAX_RESEND_DELAY = 60*1000;
|
||||
public static final long MIN_RESEND_DELAY = 30*1000;
|
||||
public static final long MIN_RESEND_DELAY = 10*1000;
|
||||
|
||||
/** wait up to 5 minutes after disconnection so we can ack/close packets */
|
||||
public static int DISCONNECT_TIMEOUT = 5*60*1000;
|
||||
@@ -113,7 +109,7 @@ public class Connection {
|
||||
_connectionManager = manager;
|
||||
_resetReceived = false;
|
||||
_connected = true;
|
||||
_disconnectScheduled = false;
|
||||
_disconnectScheduledOn = -1;
|
||||
_lastReceivedOn = -1;
|
||||
_activityTimer = new ActivityTimer();
|
||||
_ackSinceCongestion = true;
|
||||
@@ -181,9 +177,15 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
}
|
||||
void windowAdjusted() {
|
||||
synchronized (_outboundPackets) {
|
||||
_outboundPackets.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
void ackImmediately() {
|
||||
_receiver.send(null, 0, 0);
|
||||
PacketLocal packet = _receiver.send(null, 0, 0);
|
||||
//packet.releasePayload();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,6 +193,10 @@ public class Connection {
|
||||
*
|
||||
*/
|
||||
void sendReset() {
|
||||
if (_disconnectScheduledOn < 0) {
|
||||
_disconnectScheduledOn = _context.clock().now();
|
||||
SimpleTimer.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
|
||||
}
|
||||
_resetSent = true;
|
||||
if (_resetSentOn <= 0)
|
||||
_resetSentOn = _context.clock().now();
|
||||
@@ -382,6 +388,10 @@ public class Connection {
|
||||
}
|
||||
|
||||
void resetReceived() {
|
||||
if (_disconnectScheduledOn < 0) {
|
||||
_disconnectScheduledOn = _context.clock().now();
|
||||
SimpleTimer.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
|
||||
}
|
||||
_resetReceived = true;
|
||||
MessageOutputStream mos = _outputStream;
|
||||
MessageInputStream mis = _inputStream;
|
||||
@@ -398,6 +408,7 @@ public class Connection {
|
||||
public boolean getHardDisconnected() { return _hardDisconnected; }
|
||||
public boolean getResetSent() { return _resetSent; }
|
||||
public long getResetSentOn() { return _resetSentOn; }
|
||||
public long getDisconnectScheduledOn() { return _disconnectScheduledOn; }
|
||||
|
||||
void disconnect(boolean cleanDisconnect) {
|
||||
disconnect(cleanDisconnect, true);
|
||||
@@ -424,8 +435,8 @@ public class Connection {
|
||||
killOutstandingPackets();
|
||||
}
|
||||
if (removeFromConMgr) {
|
||||
if (!_disconnectScheduled) {
|
||||
_disconnectScheduled = true;
|
||||
if (_disconnectScheduledOn < 0) {
|
||||
_disconnectScheduledOn = _context.clock().now();
|
||||
SimpleTimer.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
@@ -445,8 +456,8 @@ public class Connection {
|
||||
SimpleTimer.getInstance().removeEvent(_activityTimer);
|
||||
_activityTimer = null;
|
||||
|
||||
if (!_disconnectScheduled) {
|
||||
_disconnectScheduled = true;
|
||||
if (_disconnectScheduledOn < 0) {
|
||||
_disconnectScheduledOn = _context.clock().now();
|
||||
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Connection disconnect complete from dead, drop the con "
|
||||
@@ -573,15 +584,23 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
/** how many packets have we sent and the other side has ACKed? */
|
||||
public long getAckedPackets() { return _ackedPackets; }
|
||||
public long getCreatedOn() { return _createdOn; }
|
||||
public long getCloseSentOn() { return _closeSentOn; }
|
||||
public void setCloseSentOn(long when) { _closeSentOn = when; }
|
||||
public void setCloseSentOn(long when) {
|
||||
_closeSentOn = when;
|
||||
if (_disconnectScheduledOn < 0) {
|
||||
_disconnectScheduledOn = _context.clock().now();
|
||||
SimpleTimer.getInstance().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
public long getCloseReceivedOn() { return _closeReceivedOn; }
|
||||
public void setCloseReceivedOn(long when) { _closeReceivedOn = when; }
|
||||
|
||||
public void incrementUnackedPacketsReceived() { _unackedPacketsReceived++; }
|
||||
public int getUnackedPacketsReceived() { return _unackedPacketsReceived; }
|
||||
/** how many packets have we sent but not yet received an ACK for? */
|
||||
public int getUnackedPacketsSent() {
|
||||
synchronized (_outboundPackets) {
|
||||
return _outboundPackets.size();
|
||||
@@ -850,7 +869,10 @@ public class Connection {
|
||||
_log.warn("Congestion resending packet " + _packet.getSequenceNum() + ": new windowSize " + newWindowSize
|
||||
+ ") for " + Connection.this.toString());
|
||||
|
||||
// setRTT has its own ceiling
|
||||
getOptions().setRTT(getOptions().getRTT() + 10*1000);
|
||||
getOptions().setWindowSize(newWindowSize);
|
||||
windowAdjusted();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.IOException;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@@ -131,13 +130,19 @@ class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
|
||||
}
|
||||
|
||||
private PacketLocal buildPacket(Connection con, byte buf[], int off, int size, boolean forceIncrement) {
|
||||
if (size > Packet.MAX_PAYLOAD_SIZE) throw new IllegalArgumentException("size is too large (" + size + ")");
|
||||
boolean ackOnly = isAckOnly(con, size);
|
||||
boolean isFirst = (con.getAckedPackets() <= 0) && (con.getUnackedPacketsSent() <= 0);
|
||||
|
||||
PacketLocal packet = new PacketLocal(_context, con.getRemotePeer(), con);
|
||||
byte data[] = new byte[size];
|
||||
//ByteArray data = packet.acquirePayload();
|
||||
ByteArray data = new ByteArray(new byte[size]);
|
||||
if (size > 0)
|
||||
System.arraycopy(buf, off, data, 0, size);
|
||||
System.arraycopy(buf, off, data.getData(), 0, size);
|
||||
data.setValid(size);
|
||||
data.setOffset(0);
|
||||
packet.setPayload(data);
|
||||
if (ackOnly && !forceIncrement)
|
||||
if ( (ackOnly && !forceIncrement) && (!isFirst) )
|
||||
packet.setSequenceNum(0);
|
||||
else
|
||||
packet.setSequenceNum(con.getNextOutboundPacketNum());
|
||||
@@ -155,7 +160,8 @@ class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
|
||||
|
||||
packet.setFlag(Packet.FLAG_SIGNATURE_REQUESTED, con.getOptions().getRequireFullySigned());
|
||||
|
||||
if ( (!ackOnly) && (packet.getSequenceNum() <= 0) ) {
|
||||
//if ( (!ackOnly) && (packet.getSequenceNum() <= 0) ) {
|
||||
if (isFirst) {
|
||||
packet.setFlag(Packet.FLAG_SYNCHRONIZE);
|
||||
packet.setOptionalFrom(con.getSession().getMyDestination());
|
||||
packet.setOptionalMaxSize(con.getOptions().getMaxMessageSize());
|
||||
|
||||
@@ -328,6 +328,7 @@ public class ConnectionManager {
|
||||
}
|
||||
|
||||
_outboundQueue.enqueue(packet);
|
||||
packet.releasePayload();
|
||||
|
||||
if (blocking) {
|
||||
synchronized (req) {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
super.init(opts);
|
||||
setConnectDelay(getInt(opts, PROP_CONNECT_DELAY, -1));
|
||||
setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK));
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, 16*1024));
|
||||
setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, 4*1024));
|
||||
setRTT(getInt(opts, PROP_INITIAL_RTT, 30*1000));
|
||||
setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
|
||||
setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 1000));
|
||||
@@ -160,6 +160,8 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
|
||||
public void setWindowSize(int numMsgs) {
|
||||
if (numMsgs > _maxWindowSize)
|
||||
numMsgs = _maxWindowSize;
|
||||
else if (numMsgs <= 0)
|
||||
numMsgs = 1;
|
||||
_windowSize = numMsgs;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class ConnectionPacketHandler {
|
||||
if (!ok) {
|
||||
if ( (!packet.isFlagSet(Packet.FLAG_RESET)) && (_log.shouldLog(Log.ERROR)) )
|
||||
_log.error("Packet does NOT verify: " + packet);
|
||||
packet.releasePayload();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ public class ConnectionPacketHandler {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Received a packet after hard disconnect, ignoring: " + packet + " on " + con);
|
||||
}
|
||||
packet.releasePayload();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,6 +74,7 @@ public class ConnectionPacketHandler {
|
||||
+ ": dropping " + packet);
|
||||
ack(con, packet.getAckThrough(), packet.getNacks(), null, false);
|
||||
con.getOptions().setChoke(5*1000);
|
||||
packet.releasePayload();
|
||||
return;
|
||||
}
|
||||
con.getOptions().setChoke(0);
|
||||
@@ -91,6 +94,7 @@ public class ConnectionPacketHandler {
|
||||
con.closeReceived();
|
||||
|
||||
boolean fastAck = false;
|
||||
boolean ackOnly = false;
|
||||
|
||||
if (isNew) {
|
||||
con.incrementUnackedPacketsReceived();
|
||||
@@ -127,11 +131,19 @@ public class ConnectionPacketHandler {
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("ACK only packet received: " + packet);
|
||||
ackOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fastAck = fastAck || ack(con, packet.getAckThrough(), packet.getNacks(), packet, isNew);
|
||||
|
||||
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE) &&
|
||||
((packet.getSendStreamId() == null) ||
|
||||
DataHelper.eq(packet.getSendStreamId(), Packet.STREAM_ID_UNKNOWN) ) ) {
|
||||
// don't honor the ACK 0 in SYN packets received when the other side
|
||||
// has obviously not seen our messages
|
||||
} else {
|
||||
fastAck = fastAck || ack(con, packet.getAckThrough(), packet.getNacks(), packet, isNew);
|
||||
}
|
||||
con.eventOccurred();
|
||||
if (fastAck) {
|
||||
if (con.getLastSendTime() + 2000 < _context.clock().now()) {
|
||||
@@ -140,6 +152,11 @@ public class ConnectionPacketHandler {
|
||||
con.ackImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
if (ackOnly || !isNew) {
|
||||
// non-ack message payloads are queued in the MessageInputStream
|
||||
packet.releasePayload();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ack(Connection con, long ackThrough, long nacks[], Packet packet, boolean isNew) {
|
||||
@@ -199,6 +216,8 @@ public class ConnectionPacketHandler {
|
||||
+ con.getLastCongestionSeenAt() + " (#resends: " + numResends
|
||||
+ ") for " + con);
|
||||
|
||||
// setRTT has its own ceiling
|
||||
con.getOptions().setRTT(con.getOptions().getRTT() + 10*1000);
|
||||
con.getOptions().setWindowSize(oldSize);
|
||||
|
||||
congested = true;
|
||||
@@ -224,6 +243,9 @@ public class ConnectionPacketHandler {
|
||||
newWindowSize += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (newWindowSize <= 0)
|
||||
newWindowSize = 1;
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("New window size " + newWindowSize + "/" + oldWindow + " congestionSeenAt: "
|
||||
@@ -233,6 +255,7 @@ public class ConnectionPacketHandler {
|
||||
con.setCongestionWindowEnd(newWindowSize + lowest);
|
||||
}
|
||||
|
||||
con.windowAdjusted();
|
||||
return congested;
|
||||
}
|
||||
|
||||
@@ -255,11 +278,15 @@ public class ConnectionPacketHandler {
|
||||
con.setRemotePeer(packet.getOptionalFrom());
|
||||
return true;
|
||||
} else {
|
||||
// neither RST nor SYN and we dont have the stream id yet? nuh uh
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Packet without RST or SYN where we dont know stream ID: "
|
||||
+ packet);
|
||||
return false;
|
||||
// neither RST nor SYN and we dont have the stream id yet?
|
||||
if (packet.getSequenceNum() <= 2) {
|
||||
return true;
|
||||
} else {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Packet without RST or SYN where we dont know stream ID: "
|
||||
+ packet);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!DataHelper.eq(con.getSendStreamId(), packet.getReceiveStreamId())) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import net.i2p.I2PException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -17,7 +10,6 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.I2PSessionException;
|
||||
import net.i2p.client.I2PSessionListener;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@@ -105,7 +97,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
}
|
||||
|
||||
public I2PSocket receiveSocket() throws I2PException {
|
||||
if (_session.isClosed()) throw new I2PException("Session closed");
|
||||
verifySession();
|
||||
Connection con = _connectionManager.getConnectionHandler().accept(-1);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("receiveSocket() called: " + con);
|
||||
@@ -149,6 +141,12 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
return _serverSocket;
|
||||
}
|
||||
|
||||
private void verifySession() throws I2PException {
|
||||
if (!_connectionManager.getSession().isClosed())
|
||||
return;
|
||||
_connectionManager.getSession().connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new connected socket (block until the socket is created)
|
||||
*
|
||||
@@ -160,8 +158,7 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
*/
|
||||
public I2PSocket connect(Destination peer, I2PSocketOptions options)
|
||||
throws I2PException, NoRouteToHostException {
|
||||
if (_connectionManager.getSession().isClosed())
|
||||
throw new I2PException("Session is closed");
|
||||
verifySession();
|
||||
if (options == null)
|
||||
options = _defaultOptions;
|
||||
ConnectionOptions opts = null;
|
||||
|
||||
@@ -92,7 +92,9 @@ public class MessageHandler implements I2PSessionListener {
|
||||
*/
|
||||
public void errorOccurred(I2PSession session, String message, Throwable error) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("error occurred: " + message, error);
|
||||
_log.error("error occurred: " + message + "- " + error.getMessage());
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("cause", error);
|
||||
//_manager.disconnectAllHard();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package net.i2p.client.streaming;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -13,6 +11,7 @@ import java.util.Map;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@@ -52,6 +51,7 @@ public class MessageInputStream extends InputStream {
|
||||
private int _readTimeout;
|
||||
private IOException _streamError;
|
||||
private long _readTotal;
|
||||
private ByteCache _cache;
|
||||
|
||||
private byte[] _oneByte = new byte[1];
|
||||
|
||||
@@ -70,6 +70,7 @@ public class MessageInputStream extends InputStream {
|
||||
_dataLock = new Object();
|
||||
_closeReceived = false;
|
||||
_locallyClosed = false;
|
||||
_cache = ByteCache.getInstance(128, Packet.MAX_PAYLOAD_SIZE);
|
||||
}
|
||||
|
||||
/** What is the highest block ID we've completely received through? */
|
||||
@@ -166,7 +167,7 @@ public class MessageInputStream extends InputStream {
|
||||
buf.append("Close received, ready bytes: ");
|
||||
long available = 0;
|
||||
for (int i = 0; i < _readyDataBlocks.size(); i++)
|
||||
available += ((ByteArray)_readyDataBlocks.get(i)).getData().length;
|
||||
available += ((ByteArray)_readyDataBlocks.get(i)).getValid();
|
||||
available -= _readyDataBlockIndex;
|
||||
buf.append(available);
|
||||
buf.append(" blocks: ").append(_readyDataBlocks.size());
|
||||
@@ -178,8 +179,8 @@ public class MessageInputStream extends InputStream {
|
||||
ByteArray ba = (ByteArray)_notYetReadyBlocks.get(id);
|
||||
buf.append(id).append(" ");
|
||||
|
||||
if (ba.getData() != null)
|
||||
notAvailable += ba.getData().length;
|
||||
if (ba != null)
|
||||
notAvailable += ba.getValid();
|
||||
}
|
||||
|
||||
buf.append("not ready bytes: ").append(notAvailable);
|
||||
@@ -198,10 +199,10 @@ public class MessageInputStream extends InputStream {
|
||||
*
|
||||
* @return true if this is a new packet, false if it is a dup
|
||||
*/
|
||||
public boolean messageReceived(long messageId, byte payload[]) {
|
||||
public boolean messageReceived(long messageId, ByteArray payload) {
|
||||
synchronized (_dataLock) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("received " + messageId + " with " + payload.length);
|
||||
_log.debug("received " + messageId + " with " + payload.getValid());
|
||||
if (messageId <= _highestReadyBlockId) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("ignoring dup message " + messageId);
|
||||
@@ -212,17 +213,17 @@ public class MessageInputStream extends InputStream {
|
||||
_highestBlockId = messageId;
|
||||
|
||||
if (_highestReadyBlockId + 1 == messageId) {
|
||||
if (!_locallyClosed && payload.length > 0) {
|
||||
if (!_locallyClosed && payload.getValid() > 0) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("accepting bytes as ready: " + payload.length);
|
||||
_readyDataBlocks.add(new ByteArray(payload));
|
||||
_log.debug("accepting bytes as ready: " + payload.getValid());
|
||||
_readyDataBlocks.add(payload);
|
||||
}
|
||||
_highestReadyBlockId = messageId;
|
||||
long cur = _highestReadyBlockId + 1;
|
||||
// now pull in any previously pending blocks
|
||||
while (_notYetReadyBlocks.containsKey(new Long(cur))) {
|
||||
ByteArray ba = (ByteArray)_notYetReadyBlocks.remove(new Long(cur));
|
||||
if ( (ba != null) && (ba.getData() != null) && (ba.getData().length > 0) ) {
|
||||
if ( (ba != null) && (ba.getData() != null) && (ba.getValid() > 0) ) {
|
||||
_readyDataBlocks.add(ba);
|
||||
}
|
||||
|
||||
@@ -238,7 +239,7 @@ public class MessageInputStream extends InputStream {
|
||||
if (_locallyClosed) // dont need the payload, just the msgId in order
|
||||
_notYetReadyBlocks.put(new Long(messageId), new ByteArray(null));
|
||||
else
|
||||
_notYetReadyBlocks.put(new Long(messageId), new ByteArray(payload));
|
||||
_notYetReadyBlocks.put(new Long(messageId), payload);
|
||||
_dataLock.notifyAll();
|
||||
}
|
||||
}
|
||||
@@ -324,21 +325,25 @@ public class MessageInputStream extends InputStream {
|
||||
} else {
|
||||
// either was already ready, or we wait()ed and it arrived
|
||||
ByteArray cur = (ByteArray)_readyDataBlocks.get(0);
|
||||
byte rv = cur.getData()[_readyDataBlockIndex];
|
||||
byte rv = cur.getData()[cur.getOffset()+_readyDataBlockIndex];
|
||||
_readyDataBlockIndex++;
|
||||
if (cur.getData().length <= _readyDataBlockIndex) {
|
||||
boolean removed = false;
|
||||
if (cur.getValid() <= _readyDataBlockIndex) {
|
||||
_readyDataBlockIndex = 0;
|
||||
_readyDataBlocks.remove(0);
|
||||
removed = true;
|
||||
}
|
||||
_readTotal++;
|
||||
target[offset + i] = rv; // rv < 0 ? rv + 256 : rv
|
||||
if ( (_readyDataBlockIndex <= 3) || (_readyDataBlockIndex >= cur.getData().length - 5) ) {
|
||||
if ( (_readyDataBlockIndex <= 3) || (_readyDataBlockIndex >= cur.getValid() - 5) ) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("read(...," + offset+", " + length+ ")[" + i
|
||||
+ "] after ready data: readyDataBlockIndex=" + _readyDataBlockIndex
|
||||
+ " readyBlocks=" + _readyDataBlocks.size()
|
||||
+ " readTotal=" + _readTotal);
|
||||
}
|
||||
//if (removed)
|
||||
// _cache.release(cur);
|
||||
}
|
||||
} // for (int i = 0; i < length; i++) {
|
||||
} // synchronized (_dataLock)
|
||||
@@ -357,9 +362,9 @@ public class MessageInputStream extends InputStream {
|
||||
for (int i = 0; i < _readyDataBlocks.size(); i++) {
|
||||
ByteArray cur = (ByteArray)_readyDataBlocks.get(i);
|
||||
if (i == 0)
|
||||
numBytes += cur.getData().length - _readyDataBlockIndex;
|
||||
numBytes += cur.getValid() - _readyDataBlockIndex;
|
||||
else
|
||||
numBytes += cur.getData().length;
|
||||
numBytes += cur.getValid();
|
||||
}
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@@ -380,13 +385,13 @@ public class MessageInputStream extends InputStream {
|
||||
for (int i = 0; i < _readyDataBlocks.size(); i++) {
|
||||
ByteArray cur = (ByteArray)_readyDataBlocks.get(i);
|
||||
if (i == 0)
|
||||
numBytes += cur.getData().length - _readyDataBlockIndex;
|
||||
numBytes += cur.getValid() - _readyDataBlockIndex;
|
||||
else
|
||||
numBytes += cur.getData().length;
|
||||
numBytes += cur.getValid();
|
||||
}
|
||||
for (Iterator iter = _notYetReadyBlocks.values().iterator(); iter.hasNext(); ) {
|
||||
ByteArray cur = (ByteArray)iter.next();
|
||||
numBytes += cur.getData().length;
|
||||
numBytes += cur.getValid();
|
||||
}
|
||||
return numBytes;
|
||||
}
|
||||
@@ -399,9 +404,9 @@ public class MessageInputStream extends InputStream {
|
||||
for (int i = 0; i < _readyDataBlocks.size(); i++) {
|
||||
ByteArray cur = (ByteArray)_readyDataBlocks.get(i);
|
||||
if (i == 0)
|
||||
numBytes += cur.getData().length - _readyDataBlockIndex;
|
||||
numBytes += cur.getValid() - _readyDataBlockIndex;
|
||||
else
|
||||
numBytes += cur.getData().length;
|
||||
numBytes += cur.getValid();
|
||||
}
|
||||
return numBytes;
|
||||
}
|
||||
@@ -409,6 +414,8 @@ public class MessageInputStream extends InputStream {
|
||||
|
||||
public void close() {
|
||||
synchronized (_dataLock) {
|
||||
//while (_readyDataBlocks.size() > 0)
|
||||
// _cache.release((ByteArray)_readyDataBlocks.remove(0));
|
||||
_readyDataBlocks.clear();
|
||||
|
||||
// we don't need the data, but we do need to keep track of the messageIds
|
||||
@@ -416,6 +423,7 @@ public class MessageInputStream extends InputStream {
|
||||
for (Iterator iter = _notYetReadyBlocks.values().iterator(); iter.hasNext(); ) {
|
||||
ByteArray ba = (ByteArray)iter.next();
|
||||
ba.setData(null);
|
||||
//_cache.release(ba);
|
||||
}
|
||||
_locallyClosed = true;
|
||||
_dataLock.notifyAll();
|
||||
|
||||
@@ -3,11 +3,13 @@ package net.i2p.client.streaming;
|
||||
import java.util.Arrays;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Signature;
|
||||
import net.i2p.data.SigningPrivateKey;
|
||||
import net.i2p.util.ByteCache;
|
||||
|
||||
/**
|
||||
* Contain a single packet transferred as part of a streaming connection.
|
||||
@@ -56,12 +58,13 @@ public class Packet {
|
||||
private long _nacks[];
|
||||
private int _resendDelay;
|
||||
private int _flags;
|
||||
private byte _payload[];
|
||||
private ByteArray _payload;
|
||||
// the next four are set only if the flags say so
|
||||
private Signature _optionSignature;
|
||||
private Destination _optionFrom;
|
||||
private int _optionDelay;
|
||||
private int _optionMaxSize;
|
||||
private ByteCache _cache;
|
||||
|
||||
/**
|
||||
* The receiveStreamId will be set to this when the packet doesn't know
|
||||
@@ -135,6 +138,10 @@ public class Packet {
|
||||
|
||||
public static final int DEFAULT_MAX_SIZE = 32*1024;
|
||||
private static final int MAX_DELAY_REQUEST = 65535;
|
||||
|
||||
public Packet() {
|
||||
_cache = ByteCache.getInstance(128, MAX_PAYLOAD_SIZE);
|
||||
}
|
||||
|
||||
/** what stream is this packet a part of? */
|
||||
public byte[] getSendStreamId() {
|
||||
@@ -200,14 +207,28 @@ public class Packet {
|
||||
public static final int MAX_PAYLOAD_SIZE = 32*1024;
|
||||
|
||||
/** get the actual payload of the message. may be null */
|
||||
public byte[] getPayload() { return _payload; }
|
||||
public void setPayload(byte payload[]) {
|
||||
public ByteArray getPayload() { return _payload; }
|
||||
public void setPayload(ByteArray payload) {
|
||||
//if ( (_payload != null) && (_payload != payload) )
|
||||
// _cache.release(_payload);
|
||||
_payload = payload;
|
||||
if ( (payload != null) && (payload.length > MAX_PAYLOAD_SIZE) )
|
||||
throw new IllegalArgumentException("Too large payload: " + payload.length);
|
||||
if ( (payload != null) && (payload.getValid() > MAX_PAYLOAD_SIZE) )
|
||||
throw new IllegalArgumentException("Too large payload: " + payload.getValid());
|
||||
}
|
||||
public int getPayloadSize() {
|
||||
return (_payload == null ? 0 : _payload.length);
|
||||
return (_payload == null ? 0 : _payload.getValid());
|
||||
}
|
||||
public void releasePayload() {
|
||||
//if (_payload != null)
|
||||
// _cache.release(_payload);
|
||||
_payload = null;
|
||||
}
|
||||
public ByteArray acquirePayload() {
|
||||
ByteArray old = _payload;
|
||||
_payload = new ByteArray(new byte[Packet.MAX_PAYLOAD_SIZE]); //_cache.acquire();
|
||||
//if (old != null)
|
||||
// _cache.release(old);
|
||||
return _payload;
|
||||
}
|
||||
|
||||
/** is a particular flag set on this packet? */
|
||||
@@ -340,12 +361,12 @@ public class Packet {
|
||||
|
||||
if (_payload != null) {
|
||||
try {
|
||||
System.arraycopy(_payload, 0, buffer, cur, _payload.length);
|
||||
System.arraycopy(_payload.getData(), _payload.getOffset(), buffer, cur, _payload.getValid());
|
||||
} catch (ArrayIndexOutOfBoundsException aioobe) {
|
||||
System.err.println("payload.length: " + _payload.length + " buffer.length: " + buffer.length + " cur: " + cur);
|
||||
System.err.println("payload.length: " + _payload.getValid() + " buffer.length: " + buffer.length + " cur: " + cur);
|
||||
throw aioobe;
|
||||
}
|
||||
cur += _payload.length;
|
||||
cur += _payload.getValid();
|
||||
}
|
||||
|
||||
return cur - offset;
|
||||
@@ -382,7 +403,7 @@ public class Packet {
|
||||
size += 2; // option size
|
||||
|
||||
if (_payload != null) {
|
||||
size += _payload.length;
|
||||
size += _payload.getValid();
|
||||
}
|
||||
|
||||
return size;
|
||||
@@ -445,8 +466,10 @@ public class Packet {
|
||||
throw new IllegalArgumentException("length: " + length + " offset: " + offset + " begin: " + payloadBegin);
|
||||
|
||||
// skip ahead to the payload
|
||||
_payload = new byte[payloadSize];
|
||||
System.arraycopy(buffer, payloadBegin, _payload, 0, payloadSize);
|
||||
_payload = new ByteArray(new byte[payloadSize]); //_cache.acquire();
|
||||
System.arraycopy(buffer, payloadBegin, _payload.getData(), 0, payloadSize);
|
||||
_payload.setValid(payloadSize);
|
||||
_payload.setOffset(0);
|
||||
|
||||
// ok now lets go back and deal with the options
|
||||
if (isFlagSet(FLAG_DELAY_REQUESTED)) {
|
||||
@@ -545,8 +568,8 @@ public class Packet {
|
||||
buf.append(" ").append(_nacks[i]);
|
||||
}
|
||||
}
|
||||
if ( (_payload != null) && (_payload.length > 0) )
|
||||
buf.append(" data: ").append(_payload.length);
|
||||
if ( (_payload != null) && (_payload.getValid() > 0) )
|
||||
buf.append(" data: ").append(_payload.getValid());
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -106,12 +106,12 @@ public class PacketHandler {
|
||||
|
||||
private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
void displayPacket(Packet packet, String prefix, String suffix) {
|
||||
if (!_log.shouldLog(Log.DEBUG)) return;
|
||||
String msg = null;
|
||||
synchronized (_fmt) {
|
||||
msg = _fmt.format(new Date()) + ": " + prefix + " " + packet.toString() + (suffix != null ? " " + suffix : "");
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
System.out.println(msg);
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
private void receiveKnownCon(Connection con, Packet packet) {
|
||||
@@ -137,28 +137,33 @@ public class PacketHandler {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Received forged reset for " + con, ie);
|
||||
}
|
||||
} else if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) {
|
||||
} else {
|
||||
if ( (con.getSendStreamId() == null) ||
|
||||
(DataHelper.eq(con.getSendStreamId(), packet.getReceiveStreamId())) ) {
|
||||
byte oldId[] =con.getSendStreamId();
|
||||
// con fully established, w00t
|
||||
con.setSendStreamId(packet.getReceiveStreamId());
|
||||
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) // con fully established, w00t
|
||||
con.setSendStreamId(packet.getReceiveStreamId());
|
||||
|
||||
try {
|
||||
con.getPacketHandler().receivePacket(packet, con);
|
||||
} catch (I2PException ie) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Received forged syn for " + con, ie);
|
||||
_log.warn("Received forged packet for " + con + ": " + packet, ie);
|
||||
con.setSendStreamId(oldId);
|
||||
}
|
||||
} else {
|
||||
} else if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Receive a syn packet with the wrong IDs, sending reset: " + packet);
|
||||
sendReset(packet);
|
||||
packet.releasePayload();
|
||||
} else {
|
||||
if (!con.getResetSent()) {
|
||||
// someone is sending us a packet on the wrong stream
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Received a packet on the wrong stream: " + packet + " connection: " + con);
|
||||
}
|
||||
packet.releasePayload();
|
||||
}
|
||||
} else {
|
||||
// someone is sending us a packet on the wrong stream
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Received a packet on the wrong stream: " + packet + " connection: " + con);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,6 +189,7 @@ public class PacketHandler {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Echo packet received with no stream IDs: " + packet);
|
||||
}
|
||||
packet.releasePayload();
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Packet received on an unknown stream (and not an ECHO): " + packet);
|
||||
@@ -218,6 +224,7 @@ public class PacketHandler {
|
||||
+ buf.toString() + " sendId: "
|
||||
+ (sendId != null ? Base64.encode(sendId) : " unknown"));
|
||||
}
|
||||
packet.releasePayload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Set;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
|
||||
@@ -26,6 +27,7 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
private long _ackOn;
|
||||
private long _cancelledOn;
|
||||
private SimpleTimer.TimedEvent _resendEvent;
|
||||
private ByteCache _cache = ByteCache.getInstance(128, MAX_PAYLOAD_SIZE);
|
||||
|
||||
public PacketLocal(I2PAppContext ctx, Destination to) {
|
||||
this(ctx, to, null);
|
||||
@@ -79,10 +81,11 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
_numSends++;
|
||||
_lastSend = _context.clock().now();
|
||||
}
|
||||
public void ackReceived() {
|
||||
public void ackReceived() {
|
||||
synchronized (this) {
|
||||
if (_ackOn <= 0)
|
||||
_ackOn = _context.clock().now();
|
||||
_ackOn = _context.clock().now();
|
||||
releasePayload();
|
||||
notifyAll();
|
||||
}
|
||||
SimpleTimer.getInstance().removeEvent(_resendEvent);
|
||||
@@ -90,6 +93,7 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
public void cancelled() {
|
||||
synchronized (this) {
|
||||
_cancelledOn = _context.clock().now();
|
||||
releasePayload();
|
||||
notifyAll();
|
||||
}
|
||||
SimpleTimer.getInstance().removeEvent(_resendEvent);
|
||||
@@ -131,10 +135,12 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
int window = _connection.getOptions().getWindowSize();
|
||||
boolean accepted = _connection.packetSendChoke(maxWaitMs);
|
||||
long after = _context.clock().now();
|
||||
if (accepted)
|
||||
if (accepted) {
|
||||
_acceptedOn = after;
|
||||
else
|
||||
} else {
|
||||
_acceptedOn = -1;
|
||||
releasePayload();
|
||||
}
|
||||
int afterQueued = _connection.getUnackedPacketsSent();
|
||||
if ( (after - before > 1000) && (_log.shouldLog(Log.DEBUG)) )
|
||||
_log.debug("Took " + (after-before) + "ms to get "
|
||||
@@ -149,11 +155,12 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
long expiration = _context.clock().now()+maxWaitMs;
|
||||
while (true) {
|
||||
long timeRemaining = expiration - _context.clock().now();
|
||||
if ( (timeRemaining <= 0) && (maxWaitMs > 0) ) return;
|
||||
if ( (timeRemaining <= 0) && (maxWaitMs > 0) ) break;
|
||||
try {
|
||||
synchronized (this) {
|
||||
if (_ackOn > 0) return;
|
||||
if (_cancelledOn > 0) return;
|
||||
if (_ackOn > 0) break;
|
||||
if (_cancelledOn > 0) break;
|
||||
if (!_connection.getIsConnected()) break;
|
||||
if (timeRemaining > 60*1000)
|
||||
timeRemaining = 60*1000;
|
||||
else if (timeRemaining <= 0)
|
||||
@@ -162,6 +169,8 @@ public class PacketLocal extends Packet implements MessageOutputStream.WriteStat
|
||||
}
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
if (!writeSuccessful())
|
||||
releasePayload();
|
||||
}
|
||||
|
||||
public boolean writeAccepted() { return _acceptedOn > 0 && _cancelledOn <= 0; }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -49,12 +48,16 @@ class PacketQueue {
|
||||
tagsSent = new HashSet(0);
|
||||
|
||||
// cache this from before sendMessage
|
||||
String conStr = (packet.getConnection() != null ? packet.getConnection().toString() : "");
|
||||
String conStr = null;
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
conStr = (packet.getConnection() != null ? packet.getConnection().toString() : "");
|
||||
if (packet.getAckTime() > 0) {
|
||||
_log.debug("Not resending " + packet);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Not resending " + packet);
|
||||
return;
|
||||
} else {
|
||||
_log.debug("Sending... " + packet);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Sending... " + packet);
|
||||
}
|
||||
|
||||
ByteArray ba = _cache.acquire();
|
||||
@@ -125,6 +128,17 @@ class PacketQueue {
|
||||
String suffix = (c != null ? "wsize " + c.getOptions().getWindowSize() : null);
|
||||
_connectionManager.getPacketHandler().displayPacket(packet, "SEND", suffix);
|
||||
}
|
||||
|
||||
if ( (packet.getSequenceNum() == 0) && (!packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) ) {
|
||||
// ack only, so release it asap
|
||||
packet.releasePayload();
|
||||
} else if (packet.isFlagSet(Packet.FLAG_ECHO) && !packet.isFlagSet(Packet.FLAG_SIGNATURE_INCLUDED) ) {
|
||||
// pong
|
||||
packet.releasePayload();
|
||||
} else if (packet.isFlagSet(Packet.FLAG_RESET)) {
|
||||
// reset
|
||||
packet.releasePayload();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class SchedulerConnectedBulk extends SchedulerImpl {
|
||||
|
||||
public boolean accept(Connection con) {
|
||||
boolean ok = (con != null) &&
|
||||
(con.getAckedPackets() > 0) &&
|
||||
(con.getHighestAckedThrough() >= 0) &&
|
||||
(con.getOptions().getProfile() == ConnectionOptions.PROFILE_BULK) &&
|
||||
(!con.getResetReceived()) &&
|
||||
( (con.getCloseSentOn() <= 0) || (con.getCloseReceivedOn() <= 0) );
|
||||
|
||||
@@ -39,7 +39,7 @@ class SchedulerConnecting extends SchedulerImpl {
|
||||
boolean notYetConnected = (con.getIsConnected()) &&
|
||||
//(con.getSendStreamId() == null) && // not null on recv
|
||||
(con.getLastSendId() >= 0) &&
|
||||
(con.getAckedPackets() <= 0) &&
|
||||
(con.getHighestAckedThrough() < 0) &&
|
||||
(!con.getResetReceived());
|
||||
return notYetConnected;
|
||||
}
|
||||
|
||||
@@ -32,19 +32,13 @@ class SchedulerDead extends SchedulerImpl {
|
||||
|
||||
public boolean accept(Connection con) {
|
||||
if (con == null) return false;
|
||||
long timeSinceClose = _context.clock().now() - con.getCloseSentOn();
|
||||
if (con.getResetSent())
|
||||
timeSinceClose = _context.clock().now() - con.getResetSentOn();
|
||||
boolean nothingLeftToDo = (con.getCloseSentOn() > 0) &&
|
||||
(con.getCloseReceivedOn() > 0) &&
|
||||
(con.getUnackedPacketsReceived() <= 0) &&
|
||||
(con.getUnackedPacketsSent() <= 0) &&
|
||||
(con.getResetSent()) &&
|
||||
long timeSinceClose = _context.clock().now() - con.getDisconnectScheduledOn();
|
||||
boolean nothingLeftToDo = (con.getDisconnectScheduledOn() > 0) &&
|
||||
(timeSinceClose >= Connection.DISCONNECT_TIMEOUT);
|
||||
boolean timedOut = (con.getOptions().getConnectTimeout() < con.getLifetime()) &&
|
||||
con.getSendStreamId() == null &&
|
||||
con.getLifetime() >= Connection.DISCONNECT_TIMEOUT;
|
||||
return con.getResetReceived() || nothingLeftToDo || timedOut;
|
||||
return nothingLeftToDo || timedOut;
|
||||
}
|
||||
|
||||
public void eventOccurred(Connection con) {
|
||||
|
||||
@@ -38,7 +38,7 @@ class SchedulerHardDisconnected extends SchedulerImpl {
|
||||
timeSinceClose = _context.clock().now() - con.getResetSentOn();
|
||||
boolean ok = (con.getHardDisconnected() || con.getResetSent()) &&
|
||||
(timeSinceClose < Connection.DISCONNECT_TIMEOUT);
|
||||
return ok;
|
||||
return ok || con.getResetReceived();
|
||||
}
|
||||
|
||||
public void eventOccurred(Connection con) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@@ -29,7 +30,7 @@ public class MessageInputStreamTest {
|
||||
for (int i = 0; i < orig.length / 1024; i++) {
|
||||
byte msg[] = new byte[1024];
|
||||
System.arraycopy(orig, i*1024, msg, 0, 1024);
|
||||
in.messageReceived(i, msg);
|
||||
in.messageReceived(i, new ByteArray(msg));
|
||||
}
|
||||
|
||||
byte read[] = new byte[orig.length];
|
||||
@@ -59,7 +60,7 @@ public class MessageInputStreamTest {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), msg);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ public class MessageInputStreamTest {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), msg);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +127,7 @@ public class MessageInputStreamTest {
|
||||
byte msg[] = new byte[1024];
|
||||
Integer cur = (Integer)order.get(i);
|
||||
System.arraycopy(orig, cur.intValue()*1024, msg, 0, 1024);
|
||||
in.messageReceived(cur.intValue(), msg);
|
||||
in.messageReceived(cur.intValue(), new ByteArray(msg));
|
||||
_log.debug("Injecting " + cur);
|
||||
|
||||
try {
|
||||
|
||||
44
apps/susimail/build.xml
Normal file
44
apps/susimail/build.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="susimail">
|
||||
<target name="all" depends="clean, build" />
|
||||
<target name="build" depends="builddep, jar" />
|
||||
<target name="builddep">
|
||||
<ant dir="../jetty/" target="build" />
|
||||
</target>
|
||||
<target name="compile" depends="clean">
|
||||
<javac
|
||||
srcdir="./src/src"
|
||||
debug="true" deprecation="off" source="1.3" target="1.3"
|
||||
destdir="./src/WEB-INF/classes">
|
||||
<classpath>
|
||||
<pathelement location="../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../jetty/jettylib/org.mortbay.jetty.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="jar" depends="compile, war" />
|
||||
<target name="war" depends="compile">
|
||||
<war destfile="susimail.war" webxml="src/WEB-INF/web.xml"
|
||||
basedir="src/" excludes="WEB-INF/web.xml">
|
||||
</war>
|
||||
</target>
|
||||
<target name="javadoc">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/javadoc" />
|
||||
<javadoc
|
||||
sourcepath="./src/src/" destdir="./build/javadoc"
|
||||
packagenames="*"
|
||||
use="true"
|
||||
splitindex="true"
|
||||
windowtitle="susimail" />
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete>
|
||||
<fileset dir="src/WEB-INF/classes/" includes="**/*.class" />
|
||||
</delete>
|
||||
<delete dir="src/WEB-INF/classes/i2p"/>
|
||||
<delete file="susimail.war"/>
|
||||
</target>
|
||||
<target name="cleandep" depends="clean" />
|
||||
<target name="distclean" depends="clean" />
|
||||
</project>
|
||||
2
apps/susimail/readme.txt
Normal file
2
apps/susimail/readme.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
The src/ dir contains susimail 0.13 retrieved from http://susi.i2p/ on 2005/02/17
|
||||
The contents are released under GPL. Please see http://susi.i2p/ for more info
|
||||
BIN
apps/susimail/src/3down.png
Normal file
BIN
apps/susimail/src/3down.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 415 B |
BIN
apps/susimail/src/3up.png
Normal file
BIN
apps/susimail/src/3up.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 406 B |
340
apps/susimail/src/LICENSE
Normal file
340
apps/susimail/src/LICENSE
Normal file
@@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
20
apps/susimail/src/WEB-INF/classes/susimail.properties
Normal file
20
apps/susimail/src/WEB-INF/classes/susimail.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
susimail.encodings=i2p.susi.webmail.encoding.HeaderLine;i2p.susi.webmail.encoding.QuotedPrintable;i2p.susi.webmail.encoding.Base64;i2p.susi.webmail.encoding.SevenBit;i2p.susi.webmail.encoding.EightBit;i2p.susi.webmail.encoding.HTML
|
||||
|
||||
susimail.host=localhost
|
||||
|
||||
susimail.ports.fixed=true
|
||||
susimail.ports.pop3=7660
|
||||
susimail.ports.smtp=7659
|
||||
|
||||
susimail.fast.start=true
|
||||
|
||||
susimail.sender.fixed=true
|
||||
susimail.sender.domain=mail.i2p
|
||||
|
||||
susimail.pager.pagesize=10
|
||||
|
||||
susimail.composer.cols=80
|
||||
susimail.composer.rows=15
|
||||
susimail.composer.bcc.to.self=true
|
||||
|
||||
susimail.date.format=MM/dd/yyyy HH:mm:ss
|
||||
18
apps/susimail/src/WEB-INF/web.xml
Normal file
18
apps/susimail/src/WEB-INF/web.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
|
||||
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
|
||||
<web-app>
|
||||
<display-name>susimail</display-name>
|
||||
<servlet>
|
||||
<servlet-name>SusiMail</servlet-name>
|
||||
<servlet-class>i2p.susi.webmail.WebMail</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>SusiMail</servlet-name>
|
||||
<url-pattern>/susimail</url-pattern>
|
||||
</servlet-mapping>
|
||||
<session-config>
|
||||
<session-timeout>15</session-timeout>
|
||||
</session-config>
|
||||
</web-app>
|
||||
96
apps/susimail/src/css.css
Normal file
96
apps/susimail/src/css.css
Normal file
@@ -0,0 +1,96 @@
|
||||
body {
|
||||
background-color:white;
|
||||
}
|
||||
|
||||
li {
|
||||
font-family:Verdana,Tahoma,Arial,Helvetica;
|
||||
color:black;
|
||||
line-height:12pt;
|
||||
font-size:10pt;
|
||||
margin-left:5mm;
|
||||
margin-right:5mm;
|
||||
}
|
||||
|
||||
p {
|
||||
font-family:Verdana,Tahoma,Arial,Helvetica;
|
||||
color:black;
|
||||
line-height:12pt;
|
||||
margin-left:5mm;
|
||||
margin-right:5mm;
|
||||
font-size:10pt;
|
||||
}
|
||||
|
||||
p.hl {
|
||||
font-size:12pt;
|
||||
letter-spacing:2pt;
|
||||
line-height:18pt;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
p.text {
|
||||
margin-left:10mm;
|
||||
margin-right:10mm;
|
||||
}
|
||||
|
||||
p.error {
|
||||
color:#ff0000;
|
||||
}
|
||||
|
||||
p.info {
|
||||
color:#327BBF;
|
||||
}
|
||||
|
||||
span.coloured {
|
||||
color:#327BBF;
|
||||
}
|
||||
|
||||
p.footer {
|
||||
margin-left:10mm;
|
||||
margin-right:10mm;
|
||||
font-size:8pt;
|
||||
line-height:10pt;
|
||||
}
|
||||
|
||||
p.mailbody {
|
||||
font-family:Courier-Fixed;
|
||||
margin-left:1cm;
|
||||
margin-right:1cm;
|
||||
}
|
||||
|
||||
a {
|
||||
color:#327BBF;
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
td {
|
||||
font-family:Verdana,Tahoma,Arial,Helvetica;
|
||||
color:black;
|
||||
line-height:12pt;
|
||||
margin-left:5mm;
|
||||
margin-right:5mm;
|
||||
font-size:10pt;
|
||||
}
|
||||
|
||||
tr.list0 {
|
||||
background-color:#e0e0e0;
|
||||
}
|
||||
|
||||
tr.list1 {
|
||||
background-color:#ffffff;
|
||||
}
|
||||
|
||||
table.noborder {
|
||||
margin-left:0mm;
|
||||
margin-top:0mm;
|
||||
margin-right:0mm;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family:Courier-Fixed;
|
||||
margin-left:1cm;
|
||||
margin-right:1cm;
|
||||
}
|
||||
10
apps/susimail/src/index.html
Normal file
10
apps/susimail/src/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;url=susimail" />
|
||||
<title>Susimail</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="susimail">Enter</a>
|
||||
</body>
|
||||
</html>
|
||||
43
apps/susimail/src/src/i2p/susi/debug/Debug.java
Normal file
43
apps/susimail/src/src/i2p/susi/debug/Debug.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Created on Nov 4, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.debug;
|
||||
|
||||
/**
|
||||
* @author susi23
|
||||
*/
|
||||
public class Debug {
|
||||
|
||||
public static final int ERROR = 1;
|
||||
public static final int DEBUG = 2;
|
||||
private static int level = ERROR;
|
||||
public static void setLevel( int newLevel )
|
||||
{
|
||||
level = newLevel;
|
||||
}
|
||||
public static void debug( int msgLevel, String msg )
|
||||
{
|
||||
if( msgLevel <= level )
|
||||
System.err.println( msg );
|
||||
}
|
||||
}
|
||||
128
apps/susimail/src/src/i2p/susi/util/Config.java
Normal file
128
apps/susimail/src/src/i2p/susi/util/Config.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
private static Properties properties = null, config = null;
|
||||
private static String configPrefix = null;
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty( String name )
|
||||
{
|
||||
if( configPrefix != null )
|
||||
name = configPrefix + name;
|
||||
|
||||
String result = null;
|
||||
|
||||
if( properties == null ) {
|
||||
reloadConfiguration();
|
||||
}
|
||||
|
||||
result = System.getProperty( name );
|
||||
|
||||
if( result != null )
|
||||
return result;
|
||||
|
||||
result = config.getProperty( name );
|
||||
|
||||
if( result != null )
|
||||
return result;
|
||||
|
||||
result = properties.getProperty( name );
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static void reloadConfiguration()
|
||||
{
|
||||
properties = new Properties();
|
||||
config = new Properties();
|
||||
try {
|
||||
properties.load( Config.class.getResourceAsStream( "/susimail.properties" ) );
|
||||
} catch (Exception e) {
|
||||
Debug.debug( Debug.DEBUG, "Could not open WEB-INF/classes/susimail.properties (possibly in jar), reason: " + e.getMessage() );
|
||||
}
|
||||
try {
|
||||
config.load( new FileInputStream( "susimail.config" ) );
|
||||
} catch (Exception e) {
|
||||
Debug.debug( Debug.DEBUG, "Could not open susimail.config, reason: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty( String name, String defaultValue )
|
||||
{
|
||||
String result = getProperty( name );
|
||||
return result != null ? result : defaultValue;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static int getProperty( String name, int defaultValue )
|
||||
{
|
||||
int result = defaultValue;
|
||||
|
||||
String str = getProperty( name );
|
||||
|
||||
if( str != null ) {
|
||||
try {
|
||||
result = Integer.parseInt( str );
|
||||
}
|
||||
catch( NumberFormatException nfe ) {
|
||||
result = defaultValue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param prefix
|
||||
*/
|
||||
public static void setPrefix( String prefix )
|
||||
{
|
||||
configPrefix = prefix.endsWith( "." ) ? prefix : prefix + ".";
|
||||
}
|
||||
}
|
||||
452
apps/susimail/src/src/i2p/susi/util/Folder.java
Normal file
452
apps/susimail/src/src/i2p/susi/util/Folder.java
Normal file
@@ -0,0 +1,452 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Folder object manages a array Object[] to support
|
||||
* paging and sorting.
|
||||
*
|
||||
* You create a folder object, set the contents with setElements(),
|
||||
* add Comparators with addSorter(), choose one with sortBy() and
|
||||
* and then fetch the content of the current page with
|
||||
* currentPageIterator().
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public class Folder {
|
||||
|
||||
public static final String PAGESIZE = "pager.pagesize";
|
||||
public static final int DEFAULT_PAGESIZE = 10;
|
||||
|
||||
public static final boolean DOWN = false;
|
||||
public static final boolean UP = true;
|
||||
|
||||
private int pages, pageSize, currentPage;
|
||||
private Object[] unsortedElements, elements;
|
||||
private Hashtable sorter;
|
||||
private boolean sortingDirection;
|
||||
Comparator currentSorter;
|
||||
|
||||
public Folder()
|
||||
{
|
||||
pages = 1;
|
||||
pageSize = 0;
|
||||
currentPage = 1;
|
||||
unsortedElements = null;
|
||||
sorter = new Hashtable();
|
||||
sortingDirection = UP;
|
||||
currentSorter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current page.
|
||||
*
|
||||
* @return Returns the current page.
|
||||
*/
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current page to the given parameter.
|
||||
*
|
||||
* @param currentPage The current page to set.
|
||||
*/
|
||||
public void setCurrentPage(int currentPage) {
|
||||
if( currentPage >= 1 && currentPage <= pages )
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the folder.
|
||||
*
|
||||
* @return Returns the size of the folder.
|
||||
*/
|
||||
public int getSize() {
|
||||
return elements != null ? elements.length : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of pages in the folder.
|
||||
* @return Returns the number of pages.
|
||||
*/
|
||||
public int getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns page size. If no page size has been set, it returns property @link PAGESIZE.
|
||||
* If no property is set @link DEFAULT_PAGESIZE is returned.
|
||||
*
|
||||
* @return Returns the pageSize.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize > 0 ? pageSize : Config.getProperty( PAGESIZE, DEFAULT_PAGESIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page size.
|
||||
*
|
||||
* @param pageSize The page size to set.
|
||||
*/
|
||||
public void setPageSize(int pageSize) {
|
||||
if( pageSize > 0 )
|
||||
this.pageSize = pageSize;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of an array by copying its elements.
|
||||
*
|
||||
* @param source Array to copy.
|
||||
* @return Copy of source.
|
||||
*/
|
||||
private Object[] copyArray( Object[] source )
|
||||
{
|
||||
Object[] destination = new Object[source.length];
|
||||
for( int i = 0; i < source.length; i++ )
|
||||
destination[i] = source[i];
|
||||
return destination;
|
||||
}
|
||||
/**
|
||||
* Recalculates variables.
|
||||
*/
|
||||
private void update() {
|
||||
if( elements != null ) {
|
||||
pages = elements.length / getPageSize();
|
||||
if( pages * getPageSize() < elements.length )
|
||||
pages++;
|
||||
if( currentPage > pages )
|
||||
currentPage = pages;
|
||||
}
|
||||
else {
|
||||
pages = 1;
|
||||
currentPage = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the elements according the order given by @link addSorter()
|
||||
* and @link sortBy().
|
||||
*/
|
||||
private void sort()
|
||||
{
|
||||
if( currentSorter != null ) {
|
||||
elements = copyArray( unsortedElements );
|
||||
Arrays.sort( elements, currentSorter );
|
||||
}
|
||||
else {
|
||||
elements = unsortedElements;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the array of objects the folder should manage.
|
||||
*
|
||||
* @param elements Array of Objects.
|
||||
*/
|
||||
public void setElements( Object[] elements )
|
||||
{
|
||||
this.unsortedElements = elements;
|
||||
if( currentSorter != null )
|
||||
sort();
|
||||
else
|
||||
this.elements = elements;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator containing the elements on the current page.
|
||||
* @return Iterator containing the elements on the current page.
|
||||
*/
|
||||
public Iterator currentPageIterator()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
int step = 1;
|
||||
if( sortingDirection == DOWN ) {
|
||||
offset = elements.length - offset - 1;
|
||||
step = -1;
|
||||
}
|
||||
for( int i = 0; i < pageSize && offset >= 0 && offset < elements.length; i++ ) {
|
||||
list.add( elements[offset] );
|
||||
offset += step;
|
||||
}
|
||||
}
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns folder to next page.
|
||||
*/
|
||||
public void nextPage()
|
||||
{
|
||||
currentPage++;
|
||||
if( currentPage > pages )
|
||||
currentPage = pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns folder to previous page.
|
||||
*/
|
||||
public void previousPage()
|
||||
{
|
||||
currentPage--;
|
||||
if( currentPage < 1 )
|
||||
currentPage = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets folder to display first page.
|
||||
*/
|
||||
public void firstPage()
|
||||
{
|
||||
currentPage = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets folder to display last page.
|
||||
*/
|
||||
public void lastPage()
|
||||
{
|
||||
currentPage = pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new sorter to the folder. You can sort the folder by
|
||||
* calling sortBy() and choose the given id there.
|
||||
*
|
||||
* @param id ID to identify the Comparator with @link sortBy()
|
||||
* @param sorter a Comparator to sort the Array given by @link setElements()
|
||||
*/
|
||||
public void addSorter( String id, Comparator sorter )
|
||||
{
|
||||
this.sorter.put( id, sorter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates sorting by the choosen Comparator. The id must
|
||||
* match the one, which the Comparator has been stored in the
|
||||
* folder with @link addSorter().
|
||||
*
|
||||
* @param id ID to identify the Comparator stored with @link addSorter()
|
||||
*/
|
||||
public void sortBy( String id )
|
||||
{
|
||||
currentSorter = (Comparator)sorter.get( id );
|
||||
sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element on the current page on the given position.
|
||||
*
|
||||
* @param Position of the element on the current page.
|
||||
* @return Element on the current page on the given position.
|
||||
*/
|
||||
public Object getElementAtPosXonCurrentPage( int x )
|
||||
{
|
||||
Object result = null;
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
int step = 1;
|
||||
if( sortingDirection == DOWN ) {
|
||||
offset = elements.length - offset - 1;
|
||||
step = -1;
|
||||
}
|
||||
offset += x * step;
|
||||
if( offset >= 0 && offset < elements.length )
|
||||
result = elements[offset];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting direction of the folder.
|
||||
*
|
||||
* @param direction @link UP or @link DOWN
|
||||
*/
|
||||
public void setSortingDirection( boolean direction )
|
||||
{
|
||||
sortingDirection = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element of the sorted folder.
|
||||
*
|
||||
* @return First element.
|
||||
*/
|
||||
public Object getFirstElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
*/
|
||||
return elements == null ? null : getElement( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of the sorted folder.
|
||||
*
|
||||
* @return Last element.
|
||||
*/
|
||||
public Object getLastElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
*/
|
||||
return elements == null ? null : getElement( elements.length - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets index of an element in the array regardless of sorting direction.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
private int getIndexOf( Object element )
|
||||
{
|
||||
if( elements != null ) {
|
||||
for( int i = 0; i < elements.length; i++ )
|
||||
if( elements[i].equals( element ) )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the next element in the sorted array.
|
||||
* Sorting direction is taken into account.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public Object getNextElement( Object element )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
if( i != -1 && elements != null ) {
|
||||
i += sortingDirection == UP ? 1 : -1;
|
||||
if( i >= 0 && i < elements.length )
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the previous element in the sorted array.
|
||||
* Sorting direction is taken into account.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public Object getPreviousElement( Object element )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
if( i != -1 && elements != null ) {
|
||||
i += sortingDirection == DOWN ? 1 : -1;
|
||||
if( i >= 0 && i < elements.length )
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Retrieves element at index i. Depends on sorting direction.
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
private Object getElement( int i )
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
if( elements != null ) {
|
||||
if( sortingDirection == DOWN )
|
||||
i = elements.length - i - 1;
|
||||
result = elements[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if folder shows points to the last page.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isLastPage()
|
||||
{
|
||||
return currentPage == pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if folder shows points to the first page.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isFirstPage()
|
||||
{
|
||||
return currentPage == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if elements.equals( lastElementOfTheSortedArray ).
|
||||
* The sorting direction influences which element is taken for comparison.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public boolean isLastElement( Object element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
return elements[ sortingDirection == DOWN ? 0 : elements.length - 1 ].equals( element );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if elements.equals( firstElementOfTheSortedArray ).
|
||||
* The sorting direction influences which element is taken for comparison.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public boolean isFirstElement( Object element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
return elements[ sortingDirection == UP ? 0 : elements.length - 1 ].equals( element );
|
||||
}
|
||||
}
|
||||
60
apps/susimail/src/src/i2p/susi/util/HexTable.java
Normal file
60
apps/susimail/src/src/i2p/susi/util/HexTable.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class HexTable {
|
||||
|
||||
public static String[] table = null;
|
||||
|
||||
static {
|
||||
table = new String[256];
|
||||
for( int i = 0; i < 256; i++ ) {
|
||||
String str = intToHex( i );
|
||||
if( str.length() == 1 )
|
||||
str = "0" + str;
|
||||
table[i] = "=" + str;
|
||||
}
|
||||
}
|
||||
private static String intToHex( int b )
|
||||
{
|
||||
if( b == 0 )
|
||||
return "0";
|
||||
else {
|
||||
String str = "";
|
||||
while( b > 0 ) {
|
||||
byte c = (byte)(b % 16);
|
||||
if( c < 10 )
|
||||
c += '0';
|
||||
else
|
||||
c += 'A' - 10;
|
||||
str = "" + (char)c + str;
|
||||
b = (byte)(b / 16);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
apps/susimail/src/src/i2p/susi/util/ReadBuffer.java
Normal file
38
apps/susimail/src/src/i2p/susi/util/ReadBuffer.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.util;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class ReadBuffer {
|
||||
|
||||
public byte content[];
|
||||
public int length, offset;
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return content != null ? new String( content, offset, length ) : "";
|
||||
}
|
||||
}
|
||||
97
apps/susimail/src/src/i2p/susi/webmail/Attachment.java
Normal file
97
apps/susimail/src/src/i2p/susi/webmail/Attachment.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Created on 01.12.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class Attachment {
|
||||
private String fileName, contentType, transferEncoding;
|
||||
private ReadBuffer buffer;
|
||||
private String data;
|
||||
/**
|
||||
* @return Returns the fileName.
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* @param fileName The fileName to set.
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
/**
|
||||
* @return Returns the buffer.
|
||||
*/
|
||||
public ReadBuffer getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
/**
|
||||
* @param buffer The buffer to set.
|
||||
*/
|
||||
public void setBuffer(ReadBuffer buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getTransferEncoding() {
|
||||
// TODO Auto-generated method stub
|
||||
return transferEncoding;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getContentType() {
|
||||
// TODO Auto-generated method stub
|
||||
return contentType;
|
||||
}
|
||||
/**
|
||||
* @param contentType The contentType to set.
|
||||
*/
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
/**
|
||||
* @param transferEncoding The transferEncoding to set.
|
||||
*/
|
||||
public void setTransferEncoding(String transferEncoding) {
|
||||
this.transferEncoding = transferEncoding;
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
public void setData(String data ) {
|
||||
this.data = data;
|
||||
}
|
||||
/**
|
||||
* @return Returns the data.
|
||||
*/
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
239
apps/susimail/src/src/i2p/susi/webmail/Mail.java
Normal file
239
apps/susimail/src/src/i2p/susi/webmail/Mail.java
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Created on Nov 9, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.util.Config;
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
import i2p.susi.webmail.encoding.Encoding;
|
||||
import i2p.susi.webmail.encoding.EncodingFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* data structure to hold a single message, mostly used with folder view and sorting
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public class Mail {
|
||||
|
||||
public static final String DATEFORMAT = "date.format";
|
||||
|
||||
public static final String unknown = "unknown";
|
||||
|
||||
public int id, size;
|
||||
public String sender, reply, subject, dateString,
|
||||
formattedSender, formattedSubject, formattedDate,
|
||||
shortSender, shortSubject, quotedDate, uidl;
|
||||
public Date date;
|
||||
public ReadBuffer header, body;
|
||||
public MailPart part;
|
||||
Object[] to, cc;
|
||||
|
||||
public String error;
|
||||
|
||||
public boolean markForDeletion;
|
||||
|
||||
public boolean deleted;
|
||||
|
||||
public Mail() {
|
||||
id = 0;
|
||||
size = 0;
|
||||
formattedSender = unknown;
|
||||
formattedSubject = unknown;
|
||||
formattedDate = unknown;
|
||||
shortSender = unknown;
|
||||
shortSubject = unknown;
|
||||
quotedDate = unknown;
|
||||
error = "";
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static boolean validateAddress( String address )
|
||||
{
|
||||
if( address == null || address.length() == 0 )
|
||||
return false;
|
||||
|
||||
address = address.trim();
|
||||
|
||||
if( address.indexOf( "\n" ) != -1 ||
|
||||
address.indexOf( "\r" ) != -1 )
|
||||
return false;
|
||||
|
||||
String[] tokens = address.split( "[ \t]+" );
|
||||
|
||||
int addresses = 0;
|
||||
|
||||
for( int i = 0; i < tokens.length; i++ ) {
|
||||
if( tokens[i].matches( "^[^@< \t]+@[^> \t]+$" ) ||
|
||||
tokens[i].matches( "^<[^@< \t]+@[^> \t]+>$" ) )
|
||||
addresses++;
|
||||
}
|
||||
return addresses == 1;
|
||||
}
|
||||
/**
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static String getAddress(String address )
|
||||
{
|
||||
String[] tokens = address.split( "[ \t]+" );
|
||||
|
||||
for( int i = 0; i < tokens.length; i++ ) {
|
||||
if( tokens[i].matches( "^[^@< \t]+@[^> \t]+$" ) )
|
||||
return "<" + tokens[i] + ">";
|
||||
if( tokens[i].matches( "^<[^@< \t]+@[^> \t]+>$" ) )
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static boolean getRecipientsFromList( ArrayList recipients, String text, boolean ok )
|
||||
{
|
||||
if( text != null && text.length() > 0 ) {
|
||||
String[] ccs = text.split( "," );
|
||||
for( int i = 0; i < ccs.length; i++ ) {
|
||||
String recipient = ccs[i].trim();
|
||||
if( validateAddress( recipient ) ) {
|
||||
String str = getAddress( recipient );
|
||||
if( str != null && str.length() > 0 ) {
|
||||
recipients.add( str );
|
||||
}
|
||||
else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
public static void appendRecipients( StringBuffer buf, ArrayList recipients, String prefix )
|
||||
{
|
||||
for( Iterator it = recipients.iterator(); it.hasNext(); ) {
|
||||
buf.append( prefix );
|
||||
prefix ="\t";
|
||||
buf.append( (String)it.next() );
|
||||
buf.append( "\r\n" );
|
||||
}
|
||||
}
|
||||
public void parseHeaders()
|
||||
{
|
||||
DateFormat dateFormatter = new SimpleDateFormat( Config.getProperty( DATEFORMAT, "mm/dd/yyyy HH:mm:ss" ) );
|
||||
DateFormat mailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH );
|
||||
|
||||
error = "";
|
||||
if( header != null ) {
|
||||
|
||||
boolean ok = true;
|
||||
|
||||
Encoding html = EncodingFactory.getEncoding( "HTML" );
|
||||
|
||||
if( html == null ) {
|
||||
error += "HTML encoder not found.<br>";
|
||||
ok = false;
|
||||
}
|
||||
|
||||
Encoding hl = EncodingFactory.getEncoding( "HEADERLINE" );
|
||||
|
||||
if( hl == null ) {
|
||||
error += "Header line encoder not found.<br>";
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if( ok ) {
|
||||
|
||||
try {
|
||||
ReadBuffer decoded = hl.decode( header );
|
||||
BufferedReader reader = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( decoded.content, decoded.offset, decoded.length ), "ISO-8859-1" ) );
|
||||
String line;
|
||||
while( ( line = reader.readLine() ) != null ) {
|
||||
if( line.length() == 0 )
|
||||
break;
|
||||
|
||||
if( line.startsWith( "From:" ) ) {
|
||||
sender = line.substring( 5 ).trim();
|
||||
formattedSender = getAddress( sender );
|
||||
shortSender = formattedSender.trim();
|
||||
if( shortSender.length() > 40 ) {
|
||||
shortSender = shortSender.substring( 0, 37 ).trim() + "...";
|
||||
}
|
||||
shortSender = html.encode( shortSender );
|
||||
}
|
||||
else if( line.startsWith( "Date:" ) ) {
|
||||
dateString = line.substring( 5 ).trim();
|
||||
try {
|
||||
date = mailDateFormatter.parse( dateString );
|
||||
formattedDate = dateFormatter.format( date );
|
||||
quotedDate = html.encode( dateString );
|
||||
}
|
||||
catch (ParseException e) {
|
||||
date = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if( line.startsWith( "Subject:" ) ) {
|
||||
subject = line.substring( 8 ).trim();
|
||||
formattedSubject = subject;
|
||||
shortSubject = formattedSubject;
|
||||
if( formattedSubject.length() > 60 )
|
||||
shortSubject = formattedSubject.substring( 0, 57 ).trim() + "...";
|
||||
shortSubject = html.encode( shortSubject );
|
||||
}
|
||||
else if( line.toLowerCase().startsWith( "Reply-To:" ) ) {
|
||||
reply = Mail.getAddress( line.substring( 9 ).trim() );
|
||||
}
|
||||
else if( line.startsWith( "To:" ) ) {
|
||||
ArrayList list = new ArrayList();
|
||||
Mail.getRecipientsFromList( list, line.substring( 3 ).trim(), true );
|
||||
to = list.toArray();
|
||||
}
|
||||
else if( line.startsWith( "Cc:" ) ) {
|
||||
ArrayList list = new ArrayList();
|
||||
Mail.getRecipientsFromList( list, line.substring( 3 ).trim(), true );
|
||||
cc = list.toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e ) {
|
||||
error += "Error parsing mail header: " + e.getClass().getName() + "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
apps/susimail/src/src/i2p/susi/webmail/MailCache.java
Normal file
102
apps/susimail/src/src/i2p/susi/webmail/MailCache.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import i2p.susi.webmail.pop3.POP3MailBox;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class MailCache {
|
||||
|
||||
public static final boolean FETCH_HEADER = true;
|
||||
public static final boolean FETCH_ALL = false;
|
||||
|
||||
private POP3MailBox mailbox;
|
||||
private String error;
|
||||
private Hashtable mails;
|
||||
private Object synchronizer;
|
||||
|
||||
MailCache( POP3MailBox mailbox ) {
|
||||
this.mailbox = mailbox;
|
||||
mails = new Hashtable();
|
||||
synchronizer = new Object();
|
||||
}
|
||||
/**
|
||||
* Fetch any needed data from pop3 server.
|
||||
*
|
||||
* @param id message id to get
|
||||
* @param headerOnly fetch only header lines?
|
||||
* @return
|
||||
*/
|
||||
public Mail getMail( String uidl, boolean headerOnly ) {
|
||||
|
||||
Mail mail = null, newMail = null;
|
||||
|
||||
if( mailbox != null ) {
|
||||
/*
|
||||
* synchronize update to hashtable
|
||||
*/
|
||||
synchronized( synchronizer ) {
|
||||
|
||||
mail = (Mail)mails.get( uidl );
|
||||
|
||||
if( mail == null ) {
|
||||
newMail = new Mail();
|
||||
mails.put( uidl, newMail );
|
||||
}
|
||||
}
|
||||
if( mail == null ) {
|
||||
mail = newMail;
|
||||
mail.uidl = uidl;
|
||||
mail.size = mailbox.getSize( uidl );
|
||||
}
|
||||
if( mail.size < 1024 )
|
||||
headerOnly = false;
|
||||
|
||||
boolean parseHeaders = mail.header == null;
|
||||
|
||||
if( headerOnly ) {
|
||||
if( mail.header == null )
|
||||
mail.header = mailbox.getHeader( uidl );
|
||||
}
|
||||
else {
|
||||
if( mail.body == null ) {
|
||||
mail.body = mailbox.getBody( uidl );
|
||||
if( mail.body != null ) {
|
||||
mail.header = mail.body;
|
||||
MailPart.parse( mail );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( parseHeaders && mail.header != null )
|
||||
mail.parseHeaders();
|
||||
}
|
||||
if( mail != null && mail.deleted )
|
||||
mail = null;
|
||||
return mail;
|
||||
}
|
||||
}
|
||||
260
apps/susimail/src/src/i2p/susi/webmail/MailPart.java
Normal file
260
apps/susimail/src/src/i2p/susi/webmail/MailPart.java
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Created on 07.11.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
import i2p.susi.webmail.encoding.EncodingFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author susi23
|
||||
*/
|
||||
public class MailPart {
|
||||
|
||||
public String headerLines[], type, boundary, encoding, name,
|
||||
filename, description, disposition, charset, version;
|
||||
public int beginBody, begin, end;
|
||||
public ArrayList parts = null;
|
||||
public boolean multipart = false, message = false;
|
||||
public ReadBuffer buffer = null;
|
||||
|
||||
public void parse( ReadBuffer readBuffer )
|
||||
{
|
||||
parse( readBuffer, readBuffer.offset, readBuffer.length );
|
||||
}
|
||||
|
||||
public void parse( ReadBuffer readBuffer, int offset, int length )
|
||||
{
|
||||
begin = offset;
|
||||
end = offset + length;
|
||||
buffer = readBuffer;
|
||||
|
||||
if( parts == null )
|
||||
parts = new ArrayList();
|
||||
else
|
||||
parts.clear();
|
||||
|
||||
/*
|
||||
* parse header lines
|
||||
*/
|
||||
beginBody = end;
|
||||
for( int i = begin; i < end - 4; i++ )
|
||||
if( buffer.content[i] == '\r' &&
|
||||
buffer.content[i+1] == '\n' &&
|
||||
buffer.content[i+2] == '\r' &&
|
||||
buffer.content[i+3] == '\n' ) {
|
||||
beginBody = i + 2;
|
||||
break;
|
||||
}
|
||||
|
||||
ReadBuffer decodedHeaders = null;
|
||||
try {
|
||||
decodedHeaders = EncodingFactory.getEncoding( "HEADERLINE" ).decode( buffer.content, begin, beginBody - begin );
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
headerLines = new String( decodedHeaders.content, decodedHeaders.offset, decodedHeaders.length ).split( "\r\n" );
|
||||
|
||||
for( int i = 0; i < headerLines.length; i++ )
|
||||
{
|
||||
if( headerLines[i].toLowerCase().startsWith( "content-transfer-encoding: " ) ) {
|
||||
encoding = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-disposition: " ) ) {
|
||||
disposition = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
String str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "filename" );
|
||||
if( str != null )
|
||||
name = str;
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-type: " ) ) {
|
||||
type = getFirstAttribute( headerLines[i] ).toLowerCase();
|
||||
/*
|
||||
* extract boundary, name and charset from content type
|
||||
*/
|
||||
String str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "boundary" );
|
||||
if( str != null )
|
||||
boundary = str;
|
||||
if( type != null && type.startsWith( "multipart" ) && boundary != null )
|
||||
multipart = true;
|
||||
if( type != null && type.startsWith( "message" ) )
|
||||
message = true;
|
||||
str = getHeaderLineAttribute( headerLines[i], "name" );
|
||||
if( str != null )
|
||||
name = str;
|
||||
str = getHeaderLineAttribute( headerLines[i], "charset" );
|
||||
if( str != null )
|
||||
charset = str.toUpperCase();
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "content-description: " ) ) {
|
||||
description = getFirstAttribute( headerLines[i] );
|
||||
}
|
||||
else if( headerLines[i].toLowerCase().startsWith( "mime-version: " ) ) {
|
||||
version = getFirstAttribute( headerLines[i] );
|
||||
}
|
||||
}
|
||||
/*
|
||||
* parse body
|
||||
*/
|
||||
int beginLastPart = -1;
|
||||
if( multipart ) {
|
||||
byte boundaryArray[] = boundary.getBytes();
|
||||
for( int i = beginBody; i < end - 4; i++ ) {
|
||||
if( buffer.content[i] == '\r' &&
|
||||
buffer.content[i+1] == '\n' &&
|
||||
buffer.content[i+2] == '-' &&
|
||||
buffer.content[i+3] == '-' ) {
|
||||
/*
|
||||
* begin of possible boundary line
|
||||
*/
|
||||
int j = 0;
|
||||
for( ; j < boundaryArray.length && i + 4 + j < end; j++ )
|
||||
if( buffer.content[ i + 4 + j ] != boundaryArray[j] )
|
||||
break;
|
||||
if( j == boundaryArray.length ) {
|
||||
int k = i + 4 + j;
|
||||
if( k < end - 2 &&
|
||||
buffer.content[k] == '-' &&
|
||||
buffer.content[k+1] == '-' )
|
||||
k += 2;
|
||||
|
||||
if( k < end - 2 &&
|
||||
buffer.content[k] == '\r' &&
|
||||
buffer.content[k+1] == '\n' ) {
|
||||
|
||||
k += 2;
|
||||
|
||||
int endLastPart = i + 2;
|
||||
if( beginLastPart != -1 ) {
|
||||
MailPart newPart = new MailPart();
|
||||
newPart.parse( buffer, beginLastPart, endLastPart - beginLastPart );
|
||||
parts.add( newPart );
|
||||
}
|
||||
beginLastPart = k;
|
||||
}
|
||||
i = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( message ) {
|
||||
MailPart newPart = new MailPart();
|
||||
newPart.parse( buffer, beginBody, end );
|
||||
parts.add( newPart );
|
||||
}
|
||||
}
|
||||
public static String getFirstAttribute( String line )
|
||||
{
|
||||
String result = null;
|
||||
int i = line.indexOf( ": " );
|
||||
if( i != - 1 ) {
|
||||
int j = line.indexOf( ";", i + 2 );
|
||||
if( j == -1 )
|
||||
result = line.substring( i + 2 );
|
||||
else
|
||||
result = line.substring( i + 2, j );
|
||||
result = result.trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String getHeaderLineAttribute( String line, String attributeName )
|
||||
{
|
||||
String result = null;
|
||||
int h = 0;
|
||||
int l = attributeName.length();
|
||||
while( true ) {
|
||||
int i = line.indexOf( attributeName, h );
|
||||
// System.err.println( "i=" + i );
|
||||
if( i == -1 )
|
||||
break;
|
||||
h = i + l;
|
||||
int j = line.indexOf( "=", i + l );
|
||||
// System.err.println( "j=" + j );
|
||||
if( j != -1 ) {
|
||||
int k = line.indexOf( "\"", j + 1 );
|
||||
int m = line.indexOf( ";", j + 1 );
|
||||
// System.err.println( "k=" + k );
|
||||
if( k != -1 && ( m == -1 || k < m ) ) {
|
||||
/*
|
||||
* we found a " before a possible ;
|
||||
*
|
||||
* now we look for the 2nd (not quoted) "
|
||||
*/
|
||||
m = -1;
|
||||
int k2 = k + 1;
|
||||
while( true ) {
|
||||
m = line.indexOf( "\"", k2 );
|
||||
// System.err.println( "m=" + m + " '" + line.substring( m ) + "'" );
|
||||
if( m == -1 ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* found one
|
||||
*/
|
||||
if( line.charAt( m - 1 ) != '\\' ) {
|
||||
/*
|
||||
* its not quoted, so it is the one we look for
|
||||
*/
|
||||
result = line.substring( k + 1, m );
|
||||
break;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* this is quoted, so we extract the quote and continue the search
|
||||
*/
|
||||
line = line.substring( 0, m - 1 ) + line.substring( m );
|
||||
// System.err.println( "quoting found, line='" + line + "'" );
|
||||
k2 = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( m != -1 ) {
|
||||
/*
|
||||
* no " found, but a ;
|
||||
*/
|
||||
result = line.substring( j + 1, m ).trim();
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* no " found and no ;
|
||||
*/
|
||||
result = line.substring( j + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param mail
|
||||
*/
|
||||
public static void parse(Mail mail) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
214
apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java
Normal file
214
apps/susimail/src/src/i2p/susi/webmail/RequestWrapper.java
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Created on Dec 8, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.mortbay.servlet.MultiPartRequest;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class RequestWrapper {
|
||||
|
||||
private HttpServletRequest httpRequest = null;
|
||||
private MultiPartRequest multiPartRequest = null;
|
||||
private Hashtable cache;
|
||||
private Hashtable cachedParameterNames;
|
||||
/**
|
||||
* do not call
|
||||
*/
|
||||
private RequestWrapper()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param httpRequest
|
||||
*/
|
||||
public RequestWrapper(HttpServletRequest httpRequest) {
|
||||
cache = new Hashtable();
|
||||
this.httpRequest = httpRequest;
|
||||
String contentType = httpRequest.getContentType();
|
||||
if( contentType != null && contentType.toLowerCase().startsWith( "multipart/form-data" ) ) {
|
||||
try {
|
||||
multiPartRequest = new MultiPartRequest( httpRequest );
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public HttpSession getSession(boolean b) {
|
||||
return httpRequest.getSession( b );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public String getParameter(String name ) {
|
||||
return getParameter( name, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public HttpSession getSession() {
|
||||
return httpRequest.getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Enumeration getParameterNames() {
|
||||
if( multiPartRequest != null ) {
|
||||
if( cachedParameterNames == null ) {
|
||||
cachedParameterNames = new Hashtable();
|
||||
String[] partNames = multiPartRequest.getPartNames();
|
||||
for( int i = 0; i < partNames.length; i++ )
|
||||
cachedParameterNames.put( partNames[i], new Integer( i ) );
|
||||
}
|
||||
return cachedParameterNames.keys();
|
||||
}
|
||||
else
|
||||
return httpRequest.getParameterNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getContentLength() {
|
||||
return httpRequest.getContentLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getContentType() {
|
||||
return httpRequest.getContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param partName
|
||||
* @return
|
||||
*/
|
||||
public String getContentType( String partName )
|
||||
{
|
||||
String result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
Hashtable params = multiPartRequest.getParams( partName );
|
||||
for( Enumeration e = params.keys(); e.hasMoreElements(); ) {
|
||||
String key = (String)e.nextElement();
|
||||
if( key.toLowerCase().compareToIgnoreCase( "content-type") == 0 ) {
|
||||
String value = (String)params.get( key );
|
||||
int i = value.indexOf( ";" );
|
||||
if( i != -1 )
|
||||
result = value.substring( 0, i );
|
||||
else
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public Object getAttribute(String string) {
|
||||
return httpRequest.getAttribute( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param new_subject
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public String getParameter( String name, String defaultValue )
|
||||
{
|
||||
String result = defaultValue;
|
||||
if( multiPartRequest != null ) {
|
||||
String str = (String)cache.get( name );
|
||||
if( str != null ) {
|
||||
result = str;
|
||||
}
|
||||
else {
|
||||
String[] partNames = multiPartRequest.getPartNames();
|
||||
for( int i = 0; i < partNames.length; i++ )
|
||||
if( partNames[i].compareToIgnoreCase( name ) == 0 ) {
|
||||
str = multiPartRequest.getString( partNames[i] );
|
||||
if( str != null ) {
|
||||
result = str;
|
||||
cache.put( name, result );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
String str = httpRequest.getParameter( name );
|
||||
if( str != null )
|
||||
result = str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param new_filename
|
||||
* @return
|
||||
*/
|
||||
public String getFilename(String partName )
|
||||
{
|
||||
String result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
String str = multiPartRequest.getFilename( partName );
|
||||
if( str != null )
|
||||
result = str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param new_filename
|
||||
* @return
|
||||
*/
|
||||
public InputStream getInputStream(String partName )
|
||||
{
|
||||
InputStream result = null;
|
||||
if( multiPartRequest != null ) {
|
||||
result = multiPartRequest.getInputStream( partName );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
1703
apps/susimail/src/src/i2p/susi/webmail/WebMail.java
Normal file
1703
apps/susimail/src/src/i2p/susi/webmail/WebMail.java
Normal file
File diff suppressed because it is too large
Load Diff
237
apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java
Normal file
237
apps/susimail/src/src/i2p/susi/webmail/encoding/Base64.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Created on 09.11.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.6 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class Base64 implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "base64";
|
||||
}
|
||||
/**
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException
|
||||
{
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( in ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) throws EncodingException {
|
||||
try {
|
||||
return encode( new StringBufferInputStream( str ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
private String encode( InputStream in ) throws IOException, EncodingException
|
||||
{
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
int buf[] = new int[3];
|
||||
int out[] = new int[4];
|
||||
int l = 0;
|
||||
while( true ) {
|
||||
int read = in.available();
|
||||
if( read == 0 )
|
||||
break;
|
||||
int i = 0;
|
||||
buf[0] = buf[1] = buf[2] = 0;
|
||||
while( read > 0 && i < 3 ) {
|
||||
buf[i] = in.read();
|
||||
if( buf[i] < 0 || buf[i] > 255 )
|
||||
throw new EncodingException( "Encoding supports only values 0..255 (" + buf[i] + ")" );
|
||||
i++;
|
||||
read--;
|
||||
}
|
||||
out[0] = encodeByte( ( buf[0] >> 2 ) & 63 );
|
||||
out[1] = encodeByte( ( ( buf[0] & 3 ) << 4 ) | ( ( buf[1] >> 4 ) & 15 ) );
|
||||
out[2] = encodeByte( ( ( buf[1] & 15 ) << 2 ) | ( ( buf[2] >> 6 ) & 3 ) );
|
||||
out[3] = encodeByte( buf[2] & 63 );
|
||||
strBuf.append( (char)out[0] );
|
||||
strBuf.append( (char)out[1] );
|
||||
if( i > 1 ) {
|
||||
strBuf.append( (char)out[2] );
|
||||
}
|
||||
else
|
||||
strBuf.append( "=" );
|
||||
if( i > 2 )
|
||||
strBuf.append( (char)out[3] );
|
||||
else
|
||||
strBuf.append( "=" );
|
||||
i += 3;
|
||||
l += 4;
|
||||
if( l >= 76 ) {
|
||||
strBuf.append( "\r\n" );
|
||||
l -= 76;
|
||||
}
|
||||
}
|
||||
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
private static int encodeByte(int b) {
|
||||
/*
|
||||
0 A 17 R 34 i 51 z
|
||||
1 B 18 S 35 j 52 0
|
||||
2 C 19 T 36 k 53 1
|
||||
3 D 20 U 37 l 54 2
|
||||
4 E 21 V 38 m 55 3
|
||||
5 F 22 W 39 n 56 4
|
||||
6 G 23 X 40 o 57 5
|
||||
7 H 24 Y 41 p 58 6
|
||||
8 I 25 Z 42 q 59 7
|
||||
9 J 26 a 43 r 60 8
|
||||
10 K 27 b 44 s 61 9
|
||||
11 L 28 c 45 t 62 +
|
||||
12 M 29 d 46 u 63 /
|
||||
13 N 30 e 47 v
|
||||
14 O 31 f 48 w (pad) =
|
||||
15 P 32 g 49 x
|
||||
16 Q 33 h 50 y
|
||||
*/
|
||||
if( b < 26 )
|
||||
b += 'A';
|
||||
else if( b < 52 )
|
||||
b += 'a' - 26;
|
||||
else if( b < 62 )
|
||||
b += '0' - 52;
|
||||
else if( b == 62 )
|
||||
b = '+';
|
||||
else
|
||||
b = '/';
|
||||
return b;
|
||||
}
|
||||
|
||||
private static byte decodeByte( byte b ) throws DecodingException {
|
||||
byte a = b;
|
||||
if( b >= 'A' && b <= 'Z' )
|
||||
b -= 'A';
|
||||
else if( b >= 'a' && b <= 'z' )
|
||||
b = (byte) (b - 'a' + 26);
|
||||
else if( b >= '0' && b <= '9' )
|
||||
b = (byte) (b - '0' + 52);
|
||||
else if( b == '+' )
|
||||
b = 62;
|
||||
else if( b == '/' )
|
||||
b = 63;
|
||||
else if( b == '=' )
|
||||
b = 0;
|
||||
else
|
||||
throw new DecodingException( "Decoding base64 failed (invalid data)." );
|
||||
// System.err.println( "decoded " + (char)a + " to " + b );
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode(String text) throws DecodingException {
|
||||
return text != null ? decode( text.getBytes() ) : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length) throws DecodingException {
|
||||
byte out[] = new byte[length * 3 / 4 + 1 ];
|
||||
int written = 0;
|
||||
while( length > 0 ) {
|
||||
if( in[offset] == '\r' || in[offset] == '\n' ||
|
||||
in[offset] == ' ' || in[offset] == '\t' ) {
|
||||
offset++;
|
||||
length--;
|
||||
continue;
|
||||
}
|
||||
if( length >= 4 ) {
|
||||
// System.out.println( "decode: " + (char)in[offset] + (char)in[offset+1]+ (char)in[offset+2]+ (char)in[offset+3] );
|
||||
byte b1 = decodeByte( in[offset++] );
|
||||
byte b2 = decodeByte( in[offset++] );
|
||||
out[written++] = (byte) (( b1 << 2 ) | ( ( b2 >> 4 ) & 3 ) );
|
||||
byte b3 = in[offset++];
|
||||
if( b3 != '=' ) {
|
||||
b3 = decodeByte( b3 );
|
||||
out[written++] = (byte)( ( ( b2 & 15 ) << 4 ) | ( ( b3 >> 2 ) & 15 ) );
|
||||
}
|
||||
byte b4 = in[offset++];
|
||||
if( b4 != '=' ) {
|
||||
b4 = decodeByte( b4 );
|
||||
out[written++] = (byte)( ( ( b3 & 3 ) << 6 ) | b4 & 63 );
|
||||
}
|
||||
length -= 4;
|
||||
}
|
||||
else {
|
||||
System.err.println( "" );
|
||||
throw new DecodingException( "Decoding base64 failed (trailing garbage)." );
|
||||
}
|
||||
}
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = out;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.util.Encoding#decode(i2p.susi23.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Created on Nov 15, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class DecodingException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
DecodingException( String msg ) {
|
||||
super( msg );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Created on Nov 16, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class EightBit implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "8bit";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode(byte[] in) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length)
|
||||
throws DecodingException {
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = in;
|
||||
readBuffer.offset = offset;
|
||||
readBuffer.length = length;
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String str) throws DecodingException {
|
||||
return decode( str.getBytes() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* Interface to encode/decode content transfer encodings like quoted-printable, base64 etc.
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public interface Encoding {
|
||||
public String getName();
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException;
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public String encode( String str ) throws EncodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( byte in[] ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( String str ) throws DecodingException;
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer decode( ReadBuffer in ) throws DecodingException;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Created on Nov 17, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class EncodingException extends Exception {
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
EncodingException( String msg )
|
||||
{
|
||||
super( msg );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.util.Config;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Manager class to handle content transfer encodings.
|
||||
* @author susi
|
||||
*/
|
||||
public class EncodingFactory {
|
||||
|
||||
public static String CONFIG_ENCODING = "encodings";
|
||||
|
||||
private static Hashtable encodings = null;
|
||||
|
||||
static {
|
||||
encodings = new Hashtable();
|
||||
String list = Config.getProperty( CONFIG_ENCODING );
|
||||
if( list != null ) {
|
||||
String[] classNames = list.split( ";" );
|
||||
for( int i = 0; i < classNames.length; i++ ) {
|
||||
try {
|
||||
Class c = Class.forName( classNames[i] );
|
||||
Encoding e = (Encoding)c.newInstance();
|
||||
encodings.put( e.getName(), e );
|
||||
Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() );
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.debug( Debug.ERROR, "Error loading class '" + classNames[i] + "', reason: " + e.getClass().getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve instance of an encoder for a supported encoding (or null).
|
||||
*
|
||||
* @param name name of encoding (e.g. quoted-printable)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Encoding getEncoding( String name )
|
||||
{
|
||||
return name != null && name.length() > 0 ? (Encoding)encodings.get( name ) : null;
|
||||
}
|
||||
/**
|
||||
* Returns list of available encodings;
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Set availableEncodings()
|
||||
{
|
||||
return encodings.keySet();
|
||||
}
|
||||
}
|
||||
89
apps/susimail/src/src/i2p/susi/webmail/encoding/HTML.java
Normal file
89
apps/susimail/src/src/i2p/susi/webmail/encoding/HTML.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
*/
|
||||
public class HTML implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "HTML";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode(byte[] in) throws EncodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) throws EncodingException
|
||||
{
|
||||
return str.replaceAll( "<", "<" ).replaceAll( ">", ">" ).replaceAll( "\r{0,1}\n", "<br>\r\n" );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length)
|
||||
throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String str) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
303
apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java
Normal file
303
apps/susimail/src/src/i2p/susi/webmail/encoding/HeaderLine.java
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
import i2p.susi.util.HexTable;
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class HeaderLine implements Encoding {
|
||||
public static final String NAME = "HEADERLINE";
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String text) throws EncodingException {
|
||||
try {
|
||||
return encode( new StringBufferInputStream( text ) );
|
||||
} catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
private static final int BUFSIZE = 2;
|
||||
private String encode(InputStream in) throws IOException
|
||||
{
|
||||
StringBuffer out = new StringBuffer();
|
||||
int l = 0, buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
boolean quoting = false;
|
||||
boolean quote = false;
|
||||
boolean linebreak = false;
|
||||
String quotedSequence = null;
|
||||
int rest = 0;
|
||||
while( true ) {
|
||||
rest = in.available();
|
||||
while( rest > 0 && buffered < BUFSIZE ) {
|
||||
tmp[buffered++] = in.read();
|
||||
rest--;
|
||||
}
|
||||
if( rest == 0 && buffered == 0 )
|
||||
break;
|
||||
|
||||
int c = tmp[0];
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
|
||||
quote = true;
|
||||
if( c > 32 && c < 127 && c != 61 ) {
|
||||
quote = false;
|
||||
}
|
||||
else if( ( c == 32 || c == 9 ) ) {
|
||||
quote = false;
|
||||
if( rest == 0 && buffered == 1 )
|
||||
quote = true;
|
||||
if( buffered > 0 && ( tmp[0] == '\r' || tmp[0] == '\n' ) )
|
||||
quote = true;
|
||||
}
|
||||
else if( c == 13 && buffered > 0 && tmp[0] == 10 ) {
|
||||
quote = false;
|
||||
linebreak = true;
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
}
|
||||
if( quote ) {
|
||||
if( ! quoting ) {
|
||||
quotedSequence = "=?iso-8859-1?Q?";
|
||||
quoting = true;
|
||||
}
|
||||
quotedSequence += HexTable.table[ c ];
|
||||
}
|
||||
else {
|
||||
if( quoting ) {
|
||||
quotedSequence += "?=";
|
||||
int sl = quotedSequence.length();
|
||||
if( l + sl > 76 ) {
|
||||
/*
|
||||
* wrap line
|
||||
*/
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( quotedSequence );
|
||||
l += sl;
|
||||
quoting = false;
|
||||
}
|
||||
if( linebreak ) {
|
||||
out.append( "\r\n" );
|
||||
linebreak = false;
|
||||
l = 0;
|
||||
}
|
||||
else {
|
||||
if( l > 76 ) {
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( (char)c );
|
||||
l++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( quoting ) {
|
||||
quotedSequence += "?=";
|
||||
int sl = quotedSequence.length();
|
||||
if( l + sl > 76 ) {
|
||||
/*
|
||||
* wrap line
|
||||
*/
|
||||
out.append( "\r\n\t" );
|
||||
l = 0;
|
||||
}
|
||||
out.append( quotedSequence );
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException {
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( in ) );
|
||||
} catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode( byte in[] ) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException {
|
||||
byte[] out = new byte[length];
|
||||
int written = 0;
|
||||
int end = offset + length;
|
||||
if( end > in.length )
|
||||
throw new DecodingException( "Index out of bound." );
|
||||
boolean linebreak = false;
|
||||
boolean lastCharWasQuoted = false;
|
||||
while( length-- > 0 ) {
|
||||
byte c = in[offset++];
|
||||
if( c == '=' ) {
|
||||
if( length > 0 ) {
|
||||
if( in[offset] == '?' ) {
|
||||
// System.err.println( "=? found at " + ( offset -1 ) );
|
||||
int f2 = offset + 1;
|
||||
for( ; f2 < end && in[f2] != '?'; f2++ );
|
||||
if( f2 < end ) {
|
||||
/*
|
||||
* 2nd question mark found
|
||||
*/
|
||||
// System.err.println( "2nd ? found at " + f2 );
|
||||
int f3 = f2 + 1;
|
||||
for( ; f3 < end && in[f3] != '?'; f3++ );
|
||||
if( f3 < end ) {
|
||||
/*
|
||||
* 3rd question mark found
|
||||
*/
|
||||
// System.err.println( "3rd ? found at " + f3 );
|
||||
int f4 = f3 + 1;
|
||||
for( ; f4 < end && in[f4] != '?'; f4++ );
|
||||
if( f4 < end - 1 && in[f4+1] == '=' ) {
|
||||
/*
|
||||
* 4th question mark found, we are complete, so lets start
|
||||
*/
|
||||
String enc = ( in[f2+1] == 'Q' || in[f2+1] == 'q' ) ? "quoted-printable" : ( ( in[f2+1] == 'B' || in[f2+1] == 'b' ) ? "base64" : null );
|
||||
// System.err.println( "4th ? found at " + f4 + ", encoding=" + enc );
|
||||
if( enc != null ) {
|
||||
Encoding e = EncodingFactory.getEncoding( enc );
|
||||
if( e != null ) {
|
||||
// System.err.println( "encoder found" );
|
||||
ReadBuffer tmp = null;
|
||||
try {
|
||||
// System.err.println( "decode(" + (f3 + 1) + "," + ( f4 - f3 - 1 ) + ")" );
|
||||
tmp = e.decode( in, f3 + 1, f4 - f3 - 1 );
|
||||
for( int j = 0; j < tmp.length; j++ ) {
|
||||
byte d = tmp.content[ tmp.offset + j ];
|
||||
out[written++] = ( d == '_' ? 32 : d );
|
||||
}
|
||||
int distance = f4 + 2 - offset;
|
||||
offset += distance;
|
||||
length -= distance;
|
||||
lastCharWasQuoted = true;
|
||||
continue;
|
||||
}
|
||||
catch (Exception e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( c == '\r' ) {
|
||||
if( length > 0 && in[offset] == '\n' ) {
|
||||
/*
|
||||
* delay linebreak in case of long line
|
||||
*/
|
||||
linebreak = true;
|
||||
length--;
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if( linebreak ) {
|
||||
linebreak = false;
|
||||
if( c != ' ' && c != '\t' ) {
|
||||
/*
|
||||
* new line does not start with whitespace, so its not a new part of a
|
||||
* long line
|
||||
*/
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
}
|
||||
else {
|
||||
if( !lastCharWasQuoted )
|
||||
out[written++] = ' ';
|
||||
/*
|
||||
* skip whitespace
|
||||
*/
|
||||
while( length > 0 && ( in[offset] == ' ' || in[offset] == '\t' ) ) {
|
||||
offset++;
|
||||
length--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* print out everything else literally
|
||||
*/
|
||||
out[written++] = c;
|
||||
lastCharWasQuoted = false;
|
||||
}
|
||||
if( linebreak ) {
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
}
|
||||
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = out;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
public ReadBuffer decode(String text) throws DecodingException {
|
||||
return text != null ? decode( text.getBytes() ) : null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
public static void main( String[] args ) throws EncodingException {
|
||||
String text = "Subject: test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test \r\n" +
|
||||
"From: Sm<53>rebr<62>d <smoerebroed@mail.i2p>\r\n" +
|
||||
"To: <20><><EFBFBD><EFBFBD> <lalala@mail.i2p>\r\n";
|
||||
HeaderLine hl = new HeaderLine();
|
||||
System.out.println( hl.encode( text ) );
|
||||
System.out.println( hl.encode( "test <20><><EFBFBD>" ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Created on Nov 12, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
import i2p.susi.util.HexTable;
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class QuotedPrintable implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "quoted-printable";
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException {
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( in ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String text) throws EncodingException {
|
||||
try {
|
||||
return encode( new StringBufferInputStream( text ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
private static int BUFSIZE = 2;
|
||||
private String encode( InputStream in ) throws EncodingException, IOException {
|
||||
StringBuffer out = new StringBuffer();
|
||||
int l = 0;
|
||||
int read = 0, buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
while( true ) {
|
||||
read = in.available();
|
||||
while( read > 0 && buffered < BUFSIZE ) {
|
||||
tmp[buffered++] = in.read();
|
||||
read--;
|
||||
}
|
||||
if( read == 0 && buffered == 0 )
|
||||
break;
|
||||
|
||||
int c = tmp[0];
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
|
||||
if( c > 32 && c < 127 && c != 61 ) {
|
||||
out.append( (char)c );
|
||||
l++;
|
||||
}
|
||||
else if( ( c == 32 || c == 9 ) ) {
|
||||
if( buffered > 0 && ( tmp[0] == 10 || tmp[0] == 13 ) ) {
|
||||
/*
|
||||
* whitespace at end of line
|
||||
*/
|
||||
out.append( c == 32 ? "=20" : "=09" );
|
||||
l += 3;
|
||||
}
|
||||
else {
|
||||
out.append( (char)c );
|
||||
l++;
|
||||
}
|
||||
}
|
||||
else if( c == 13 && buffered > 0 && tmp[0] == 10 ) {
|
||||
out.append( "\r\n" );
|
||||
buffered--;
|
||||
for( int j = 1; j < BUFSIZE; j++ )
|
||||
tmp[j-1] = tmp[j];
|
||||
l = 0;
|
||||
}
|
||||
else {
|
||||
if( c < 0 || c > 255 ) {
|
||||
throw new EncodingException( "Encoding supports only values of 0..255." );
|
||||
}
|
||||
out.append( HexTable.table[ c ] );
|
||||
l += 3;
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode( byte in[] ) {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String text) {
|
||||
return text != null ? decode( text.getBytes() ) : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length) {
|
||||
byte[] out = new byte[length];
|
||||
int written = 0;
|
||||
while( length-- > 0 ) {
|
||||
byte c = in[offset++];
|
||||
if( c == '=' ) {
|
||||
if( length >= 2 ) {
|
||||
byte a = in[offset];
|
||||
byte b = in[offset + 1];
|
||||
if( ( ( a >= '0' && a <= '9' ) || ( a >= 'A' && a <= 'F' ) ) &&
|
||||
( ( b >= '0' && b <= '9' ) || ( b >= 'A' && b <= 'F' ) ) ) {
|
||||
/*
|
||||
* decode sequence
|
||||
*/
|
||||
// System.err.println( "decoding 0x" + (char)a + "" + (char)b );
|
||||
length -= 2 ;
|
||||
offset += 2;
|
||||
|
||||
if( a >= '0' && a <= '9' )
|
||||
a -= '0';
|
||||
else if( a >= 'A' && a <= 'F' )
|
||||
a = (byte) (a - 'A' + 10);
|
||||
|
||||
if( b >= '0' && b <= '9' )
|
||||
b -= '0';
|
||||
else if( b >= 'A' && b <= 'F' )
|
||||
b = (byte) (b - 'A' + 10);
|
||||
|
||||
out[written++]=(byte) (a*16 + b);
|
||||
continue;
|
||||
}
|
||||
else if( a == '\r' && b == '\n' ) {
|
||||
/*
|
||||
* softbreak, simply ignore it
|
||||
*/
|
||||
length -= 2;
|
||||
offset += 2;
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* no correct encoded sequence found, ignore it and print it literally
|
||||
*/
|
||||
}
|
||||
}
|
||||
/*
|
||||
* print out everything else literally
|
||||
*/
|
||||
out[written++] = c;
|
||||
}
|
||||
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = out;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
}
|
||||
101
apps/susimail/src/src/i2p/susi/webmail/encoding/SevenBit.java
Normal file
101
apps/susimail/src/src/i2p/susi/webmail/encoding/SevenBit.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Created on 15.11.2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.encoding;
|
||||
|
||||
import i2p.susi.util.ReadBuffer;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class SevenBit implements Encoding {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "7bit";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode(byte[] in) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String str) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#decode(byte[])
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in) throws DecodingException {
|
||||
return decode( in, 0, in.length );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#decode(byte[], int, int)
|
||||
*/
|
||||
public ReadBuffer decode(byte[] in, int offset, int length)
|
||||
throws DecodingException {
|
||||
int backupLength = length;
|
||||
int backupOffset = offset;
|
||||
while( length-- > 0 ) {
|
||||
byte b = in[offset++];
|
||||
if( b > 32 && b < 127 )
|
||||
continue;
|
||||
if( b == ' ' || b == '\t' )
|
||||
continue;
|
||||
if( b == '\r' || b == '\n' )
|
||||
continue;
|
||||
throw new DecodingException( "No 8bit Data allowed (" + b + ")" );
|
||||
}
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
readBuffer.content = in;
|
||||
readBuffer.offset = backupOffset;
|
||||
readBuffer.length = backupLength;
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#decode(java.lang.String)
|
||||
*/
|
||||
public ReadBuffer decode(String str) throws DecodingException {
|
||||
return decode( str.getBytes() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi23.mail.encoding.Encoding#decode(i2p.susi.webmail.util.ReadBuffer)
|
||||
*/
|
||||
public ReadBuffer decode(ReadBuffer in) throws DecodingException {
|
||||
return decode( in.content, in.offset, in.length );
|
||||
}
|
||||
|
||||
}
|
||||
725
apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java
Normal file
725
apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java
Normal file
@@ -0,0 +1,725 @@
|
||||
/*
|
||||
* Created on Nov 4, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.8 $
|
||||
*/
|
||||
package i2p.susi.webmail.pop3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.util.*;
|
||||
|
||||
/**
|
||||
* @author susi23
|
||||
*/
|
||||
public class POP3MailBox {
|
||||
|
||||
private static final int DEFAULT_BUFSIZE = 4096;
|
||||
|
||||
private String host = null, user = null, pass = null;
|
||||
|
||||
private String lastLine = "-ERR", lastError = null;
|
||||
|
||||
private int port = 0, mails = 0, read = 0;
|
||||
|
||||
private boolean connected = false;
|
||||
|
||||
private Hashtable headerList = null, bodyList = null, sizes = null, uidlToID = null;
|
||||
private ArrayList uidlList = null;
|
||||
|
||||
private Socket socket = null;
|
||||
|
||||
private byte[] buffer = new byte[DEFAULT_BUFSIZE];
|
||||
|
||||
private Object synchronizer = null;
|
||||
|
||||
private Object[] uidls = null;
|
||||
|
||||
/**
|
||||
* @param host
|
||||
* @param port
|
||||
* @param user
|
||||
* @param pass
|
||||
*/
|
||||
public POP3MailBox(String host, int port, String user, String pass) {
|
||||
Debug.debug(
|
||||
Debug.DEBUG,
|
||||
"Mailbox(" + host + "," + port + "," + user + ",password)");
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
headerList = new Hashtable();
|
||||
bodyList = new Hashtable();
|
||||
uidlList = new ArrayList();
|
||||
uidlToID = new Hashtable();
|
||||
sizes = new Hashtable();
|
||||
synchronizer = new Object();
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uidl
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer getHeader( String uidl ) {
|
||||
synchronized( synchronizer ) {
|
||||
return getHeader( getIDfromUIDL( uidl ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves header from pop3 server (with TOP command and RETR as fallback)
|
||||
*
|
||||
* @param id message id
|
||||
* @return byte buffer containing data
|
||||
*/
|
||||
private ReadBuffer getHeader( int id ) {
|
||||
synchronized( synchronizer ) {
|
||||
Debug.debug(Debug.DEBUG, "getHeader(" + id + ")");
|
||||
Integer idObj = new Integer(id);
|
||||
ReadBuffer header = null;
|
||||
if (id >= 1 && id <= mails) {
|
||||
/*
|
||||
* is data already cached?
|
||||
*/
|
||||
header = (ReadBuffer)headerList.get(idObj);
|
||||
if (header == null) {
|
||||
/*
|
||||
* try 'TOP n 0' command
|
||||
*/
|
||||
header = sendCmdN("TOP " + id + " 0" );
|
||||
}
|
||||
if( header == null) {
|
||||
/*
|
||||
* try 'RETR n' command
|
||||
*/
|
||||
header = sendCmdN("RETR " + id );
|
||||
}
|
||||
if( header != null ) {
|
||||
/*
|
||||
* store result in hashtable
|
||||
*/
|
||||
headerList.put(idObj, header);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastError = "Message id out of range.";
|
||||
}
|
||||
return header;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uidl
|
||||
* @return
|
||||
*/
|
||||
public ReadBuffer getBody( String uidl ) {
|
||||
synchronized( synchronizer ) {
|
||||
return getBody( getIDfromUIDL( uidl ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve message body from pop3 server (via RETR command)
|
||||
*
|
||||
* @param id message id
|
||||
* @return byte buffer containing data
|
||||
*/
|
||||
private ReadBuffer getBody(int id) {
|
||||
synchronized( synchronizer ) {
|
||||
Debug.debug(Debug.DEBUG, "getBody(" + id + ")");
|
||||
Integer idObj = new Integer(id);
|
||||
ReadBuffer body = null;
|
||||
if (id >= 1 && id <= mails) {
|
||||
body = (ReadBuffer)bodyList.get(idObj);
|
||||
if( body == null ) {
|
||||
body = sendCmdN( "RETR " + id );
|
||||
if (body != null) {
|
||||
bodyList.put(idObj, body);
|
||||
}
|
||||
else {
|
||||
Debug.debug( Debug.DEBUG, "sendCmdN returned null" );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastError = "Message id out of range.";
|
||||
}
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uidl
|
||||
* @return
|
||||
*/
|
||||
public boolean delete( String uidl )
|
||||
{
|
||||
Debug.debug(Debug.DEBUG, "delete(" + uidl + ")");
|
||||
synchronized( synchronizer ) {
|
||||
return delete( getIDfromUIDL( uidl ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete message on pop3 server
|
||||
*
|
||||
* @param id message id
|
||||
* @return true if successful
|
||||
*/
|
||||
private boolean delete(int id)
|
||||
{
|
||||
Debug.debug(Debug.DEBUG, "delete(" + id + ")");
|
||||
|
||||
boolean result = false;
|
||||
|
||||
synchronized( synchronizer ) {
|
||||
|
||||
try {
|
||||
result = sendCmd1a( "DELE " + id );
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uidl
|
||||
* @return
|
||||
*/
|
||||
public int getSize( String uidl ) {
|
||||
synchronized( synchronizer ) {
|
||||
return getSize( getIDfromUIDL( uidl ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get size of a message (via LIST command)
|
||||
*
|
||||
* @param id message id
|
||||
* @return message size in bytes
|
||||
*/
|
||||
private int getSize(int id) {
|
||||
synchronized( synchronizer ) {
|
||||
Debug.debug(Debug.DEBUG, "getSize(" + id + ")");
|
||||
int result = 0;
|
||||
/*
|
||||
* find value in hashtable
|
||||
*/
|
||||
Integer resultObj = (Integer) sizes.get(new Integer(id));
|
||||
if (resultObj != null)
|
||||
result = resultObj.intValue();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether connection is still alive
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
Debug.debug(Debug.DEBUG, "isConnected()");
|
||||
|
||||
if (socket == null
|
||||
|| !socket.isConnected()
|
||||
|| socket.isInputShutdown()
|
||||
|| socket.isOutputShutdown()
|
||||
|| socket.isClosed()) {
|
||||
connected = false;
|
||||
}
|
||||
return connected;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void updateUIDLs() throws IOException
|
||||
{
|
||||
synchronized (synchronizer) {
|
||||
|
||||
ReadBuffer readBuffer = null;
|
||||
|
||||
uidlToID.clear();
|
||||
uidlList.clear();
|
||||
uidls = null;
|
||||
|
||||
readBuffer = sendCmdNa( "UIDL", DEFAULT_BUFSIZE );
|
||||
if( readBuffer != null ) {
|
||||
String[] lines = new String( readBuffer.toString() ).split( "\r\n" );
|
||||
|
||||
for( int i = 0; i < lines.length; i++ ) {
|
||||
int j = lines[i].indexOf( " " );
|
||||
if( j != -1 ) {
|
||||
try {
|
||||
int n = Integer.parseInt( lines[i].substring( 0, j ) );
|
||||
String uidl = lines[i].substring( j+1 );
|
||||
uidlToID.put( uidl, new Integer( n ) );
|
||||
uidlList.add( n-1, uidl );
|
||||
}
|
||||
catch( NumberFormatException nfe ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
uidls = uidlList.toArray();
|
||||
}
|
||||
else {
|
||||
System.err.println( "Error getting UIDL list from pop3 server.");
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void updateSizes() throws IOException {
|
||||
/*
|
||||
* try LIST
|
||||
*/
|
||||
sizes.clear();
|
||||
ReadBuffer readBuffer = sendCmdNa("LIST", DEFAULT_BUFSIZE );
|
||||
if(readBuffer != null) {
|
||||
String[] lines = new String( readBuffer.content, 0, readBuffer.length ).split( "\r\n" );
|
||||
if (lines != null) {
|
||||
sizes = new Hashtable();
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
int j = lines[i].indexOf(" ");
|
||||
if (j != -1) {
|
||||
int key = Integer.parseInt(lines[i].substring(0, j));
|
||||
int value = Integer.parseInt(lines[i].substring(j + 1));
|
||||
sizes.put(new Integer(key), new Integer(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.err.println( "Error getting size LIST from pop3 server.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void refresh() {
|
||||
synchronized( synchronizer ) {
|
||||
close();
|
||||
connect();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private void clear()
|
||||
{
|
||||
uidlList.clear();
|
||||
uidlToID.clear();
|
||||
sizes.clear();
|
||||
uidls = null;
|
||||
mails = 0;
|
||||
}
|
||||
/**
|
||||
* connect to pop3 server, login with USER and PASS and try STAT then
|
||||
*/
|
||||
private void connect() {
|
||||
Debug.debug(Debug.DEBUG, "connect()");
|
||||
|
||||
clear();
|
||||
|
||||
if (socket != null && socket.isConnected())
|
||||
close();
|
||||
|
||||
try {
|
||||
socket = new Socket(host, port);
|
||||
} catch (UnknownHostException e) {
|
||||
lastError = e.getMessage();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
lastError = e.getMessage();
|
||||
return;
|
||||
}
|
||||
if (socket != null) {
|
||||
try {
|
||||
if (sendCmd1a("")
|
||||
&& sendCmd1a("USER " + user)
|
||||
&& sendCmd1a("PASS " + pass)
|
||||
&& sendCmd1a("STAT") ) {
|
||||
|
||||
int i = lastLine.indexOf(" ", 5);
|
||||
mails =
|
||||
Integer.parseInt(
|
||||
i != -1
|
||||
? lastLine.substring(4, i)
|
||||
: lastLine.substring(4));
|
||||
|
||||
connected = true;
|
||||
updateUIDLs();
|
||||
updateSizes();
|
||||
}
|
||||
else {
|
||||
lastError = new String( lastLine );
|
||||
close();
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e1) {
|
||||
lastError = "Error getting number of messages: " + e1.getCause();
|
||||
}
|
||||
catch (IOException e1) {
|
||||
lastError = "Error while opening mailbox: " + e1.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send command to pop3 server (and expect single line answer), if any
|
||||
* exception occurs, reconnect and try again
|
||||
*
|
||||
* @param cmd command to send
|
||||
* @return true if command was successful (+OK)
|
||||
*/
|
||||
private boolean sendCmd1(String cmd) {
|
||||
boolean result = false;
|
||||
|
||||
synchronized (synchronizer) {
|
||||
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
result = sendCmd1a(cmd);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.debug(Debug.ERROR, "Exception: " + e.getCause());
|
||||
Debug.debug(Debug.ERROR, "trying to reconnect" );
|
||||
connect();
|
||||
try {
|
||||
result = sendCmd1a(cmd);
|
||||
} catch (IOException e2) {
|
||||
Debug.debug(Debug.ERROR, "reconnect failed: " + e2.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* send command to pop3 server (and expect single line answer)
|
||||
*
|
||||
* @param cmd command to send
|
||||
* @return true if command was successful (+OK)
|
||||
* @throws IOException
|
||||
*/
|
||||
private boolean sendCmd1a(String cmd) throws IOException {
|
||||
/*
|
||||
* dont log password
|
||||
*/
|
||||
boolean result = false;
|
||||
String msg = cmd;
|
||||
if (msg.startsWith("PASS"))
|
||||
msg = "PASS provided";
|
||||
Debug.debug(Debug.DEBUG, "sendCmd1a(" + msg + ")");
|
||||
|
||||
cmd += "\r\n";
|
||||
socket.getOutputStream().write(cmd.getBytes());
|
||||
read = socket.getInputStream().read(buffer);
|
||||
// Debug.debug(Debug.DEBUG, "sendCmd1a: read " + read + " bytes");
|
||||
if (read > 0) {
|
||||
lastLine = new String(buffer, 0, read);
|
||||
// Debug.debug( Debug.DEBUG, "sendCmd1a: READBUFFER: '" + lastLine + "'" );
|
||||
if (lastLine.startsWith("+OK")) {
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
lastError = lastLine;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cmd
|
||||
* @return
|
||||
*/
|
||||
private ReadBuffer sendCmdN(String cmd )
|
||||
{
|
||||
return sendCmdN( cmd, DEFAULT_BUFSIZE );
|
||||
}
|
||||
/**
|
||||
* @param cmd
|
||||
* @return
|
||||
*/
|
||||
private ReadBuffer sendCmdN(String cmd, int bufSize )
|
||||
{
|
||||
ReadBuffer result = null;
|
||||
|
||||
synchronized (synchronizer) {
|
||||
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
result = sendCmdNa(cmd, bufSize);
|
||||
}
|
||||
catch (IOException e) {
|
||||
lastError = e.getMessage();
|
||||
Debug.debug( Debug.DEBUG, "sendCmdNa throws IOException: " + lastError );
|
||||
result = null;
|
||||
}
|
||||
|
||||
if( result == null ) {
|
||||
connect();
|
||||
if (connected) {
|
||||
try {
|
||||
result = sendCmdNa(cmd, bufSize);
|
||||
}
|
||||
catch (IOException e2) {
|
||||
lastError = e2.getMessage();
|
||||
Debug.debug( Debug.DEBUG, "2nd sendCmdNa throws IOException: " + lastError );
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Debug.debug( Debug.DEBUG, "not connected after reconnect" );
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param newSize
|
||||
* @return
|
||||
*/
|
||||
private byte[] resizeArray( byte src[], int newSize )
|
||||
{
|
||||
byte dest[] = new byte[newSize];
|
||||
for( int i = 0; i < src.length; i++ )
|
||||
dest[i] = src[i];
|
||||
return dest;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param srcOffset
|
||||
* @param len
|
||||
* @param dest
|
||||
* @param destOffset
|
||||
*/
|
||||
private void copy( byte[] src, int srcOffset, int len, byte[] dest, int destOffset )
|
||||
{
|
||||
while( len-- > 0 ) {
|
||||
dest[destOffset++] = src[srcOffset++];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param id
|
||||
* @return @throws
|
||||
* IOException
|
||||
*/
|
||||
private ReadBuffer sendCmdNa(String cmd, int bufSize ) throws IOException
|
||||
{
|
||||
Debug.debug(Debug.DEBUG, "sendCmdNa(" + cmd + ")");
|
||||
|
||||
ReadBuffer readBuffer = null;
|
||||
long timeOut = 60000;
|
||||
byte result[] = new byte[bufSize];
|
||||
int written = 0;
|
||||
|
||||
if (sendCmd1a(cmd)) {
|
||||
int offset = 0;
|
||||
while( offset < read - 1 && buffer[offset] != '\r' && buffer[offset+1] != '\n' )
|
||||
offset++;
|
||||
offset += 2;
|
||||
if( read - offset > result.length )
|
||||
result = resizeArray( result, result.length + result.length );
|
||||
if( read - offset > 0 )
|
||||
copy( buffer, offset, read - offset, result, 0 );
|
||||
written = read - offset;
|
||||
boolean doRead = true;
|
||||
// Debug.debug( Debug.DEBUG, "READBUFFER: '" + new String( result, 0, written ) + "'" );
|
||||
if( written >= 5 && result[ written - 5 ] == '\r' &&
|
||||
result[ written - 4 ] == '\n' &&
|
||||
result[ written - 3 ] == '.' &&
|
||||
result[ written - 2 ] == '\r' &&
|
||||
result[ written - 1 ] == '\n' ) {
|
||||
written -= 3;
|
||||
doRead = false;
|
||||
}
|
||||
InputStream input = socket.getInputStream();
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (doRead) {
|
||||
int len = input.available();
|
||||
if( len == 0 ) {
|
||||
if( System.currentTimeMillis() - startTime > timeOut )
|
||||
throw new IOException( "Timeout while waiting on server response." );
|
||||
try {
|
||||
Thread.sleep( 500 );
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (len > 0) {
|
||||
read = socket.getInputStream().read(buffer, 0, len > buffer.length ? buffer.length : len );
|
||||
// Debug.debug(Debug.DEBUG, "read " + read + " bytes");
|
||||
if( written + read > result.length )
|
||||
result = resizeArray( result, result.length + result.length );
|
||||
copy( buffer, 0, read, result, written );
|
||||
written += read;
|
||||
// Debug.debug( Debug.DEBUG, "READBUFFER: '" + new String( result, 0, written ) + "'" );
|
||||
if( result[ written - 5 ] == '\r' &&
|
||||
result[ written - 4 ] == '\n' &&
|
||||
result[ written - 3 ] == '.' &&
|
||||
result[ written - 2 ] == '\r' &&
|
||||
result[ written - 1 ] == '\n' ) {
|
||||
written -= 3;
|
||||
doRead = false;
|
||||
}
|
||||
len -= read;
|
||||
}
|
||||
}
|
||||
}
|
||||
readBuffer = new ReadBuffer();
|
||||
readBuffer.content = result;
|
||||
readBuffer.offset = 0;
|
||||
readBuffer.length = written;
|
||||
}
|
||||
else {
|
||||
Debug.debug( Debug.DEBUG, "sendCmd1a returned false" );
|
||||
}
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getNumMails() {
|
||||
synchronized( synchronizer ) {
|
||||
Debug.debug(Debug.DEBUG, "getNumMails()");
|
||||
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
return connected ? mails : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String lastError() {
|
||||
Debug.debug(Debug.DEBUG, "lastError()");
|
||||
return this.lastError;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
synchronized( synchronizer ) {
|
||||
Debug.debug(Debug.DEBUG, "close()");
|
||||
if (socket != null && socket.isConnected()) {
|
||||
try {
|
||||
sendCmd1a("QUIT");
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(
|
||||
"Error while closing connection: " + e.getCause());
|
||||
}
|
||||
}
|
||||
socket = null;
|
||||
connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns number of message with given UIDL
|
||||
*
|
||||
* @param uidl
|
||||
* @return
|
||||
*/
|
||||
private int getIDfromUIDL( String uidl )
|
||||
{
|
||||
int result = -1;
|
||||
Integer intObject = (Integer)uidlToID.get( uidl );
|
||||
if( intObject != null ) {
|
||||
result = intObject.intValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public String getUIDLfromID( int id )
|
||||
{
|
||||
return (String)uidlList.get( id );
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object[] getUIDLs()
|
||||
{
|
||||
return uidls;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Debug.setLevel( Debug.DEBUG );
|
||||
POP3MailBox mailbox = new POP3MailBox( "localhost", 7660 , "test", "test");
|
||||
ReadBuffer readBuffer = mailbox.sendCmdN( "LIST" );
|
||||
System.out.println( "list='" + readBuffer + "'" );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void performDelete()
|
||||
{
|
||||
close();
|
||||
connect();
|
||||
}
|
||||
}
|
||||
176
apps/susimail/src/src/i2p/susi/webmail/smtp/SMTPClient.java
Normal file
176
apps/susimail/src/src/i2p/susi/webmail/smtp/SMTPClient.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Created on Nov 9, 2004
|
||||
*
|
||||
* This file is part of susimail project, see http://susi.i2p/
|
||||
*
|
||||
* Copyright (C) 2004-2005 <susi23@mail.i2p>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
package i2p.susi.webmail.smtp;
|
||||
|
||||
import i2p.susi.debug.Debug;
|
||||
import i2p.susi.webmail.encoding.Encoding;
|
||||
import i2p.susi.webmail.encoding.EncodingException;
|
||||
import i2p.susi.webmail.encoding.EncodingFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* @author susi
|
||||
*/
|
||||
public class SMTPClient {
|
||||
|
||||
Socket socket;
|
||||
byte buffer[];
|
||||
public String error;
|
||||
String lastResponse;
|
||||
|
||||
private static Encoding base64 = null;
|
||||
|
||||
static {
|
||||
base64 = EncodingFactory.getEncoding( "base64" );
|
||||
}
|
||||
public SMTPClient()
|
||||
{
|
||||
socket = null;
|
||||
buffer = new byte[10240];
|
||||
error = "";
|
||||
lastResponse = "";
|
||||
}
|
||||
|
||||
public int sendCmd( String cmd )
|
||||
{
|
||||
Debug.debug( Debug.DEBUG, "sendCmd(" + cmd +")" );
|
||||
|
||||
if( socket == null )
|
||||
return 0;
|
||||
|
||||
int result = 0;
|
||||
lastResponse = "";
|
||||
|
||||
try {
|
||||
InputStream in = socket.getInputStream();
|
||||
OutputStream out = socket.getOutputStream();
|
||||
|
||||
if( cmd != null ) {
|
||||
cmd += "\r\n";
|
||||
out.write( cmd.getBytes() );
|
||||
}
|
||||
String str = "";
|
||||
boolean doContinue = true;
|
||||
while( doContinue ) {
|
||||
if( in.available() > 0 ) {
|
||||
int read = in.read( buffer );
|
||||
str += new String( buffer, 0, read );
|
||||
lastResponse += str;
|
||||
while( true ) {
|
||||
int i = str.indexOf( "\r\n" );
|
||||
if( i == -1 )
|
||||
break;
|
||||
if( result == 0 ) {
|
||||
try {
|
||||
result = Integer.parseInt( str.substring( 0, 3 ) );
|
||||
}
|
||||
catch( NumberFormatException nfe ) {
|
||||
result = 0;
|
||||
doContinue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( str.substring( 3, 4 ).compareTo( " " ) == 0 ) {
|
||||
doContinue = false;
|
||||
break;
|
||||
}
|
||||
str = str.substring( i + 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
error += "IOException occured.<br>";
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public boolean sendMail( String host, int port, String user, String pass, String sender, Object[] recipients, String body )
|
||||
{
|
||||
boolean mailSent = false;
|
||||
boolean ok = true;
|
||||
|
||||
try {
|
||||
socket = new Socket( host, port );
|
||||
}
|
||||
catch (Exception e) {
|
||||
error += "Cannot connect: " + e.getMessage() + "<br>";
|
||||
ok = false;
|
||||
}
|
||||
try {
|
||||
if( ok && sendCmd( null ) == 220 &&
|
||||
sendCmd( "EHLO localhost" ) == 250 &&
|
||||
sendCmd( "AUTH LOGIN" ) == 334 &&
|
||||
sendCmd( base64.encode( user ) ) == 334 &&
|
||||
sendCmd( base64.encode( pass ) ) == 235 &&
|
||||
sendCmd( "MAIL FROM: " + sender ) == 250 ) {
|
||||
|
||||
for( int i = 0; i < recipients.length; i++ ) {
|
||||
if( sendCmd( "RCPT TO: " + recipients[i] ) != 250 ) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if( ok ) {
|
||||
if( sendCmd( "DATA" ) == 354 ) {
|
||||
if( body.indexOf( "\r\n.\r\n" ) != -1 )
|
||||
body = body.replaceAll( "\r\n.\r\n", "\r\n..\r\n" );
|
||||
body += "\r\n.\r\n";
|
||||
try {
|
||||
socket.getOutputStream().write( body.getBytes() );
|
||||
if( sendCmd( null ) == 250 ) {
|
||||
mailSent = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
ok = false;
|
||||
error += "Error while sending mail: " + e.getMessage() + "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (EncodingException e) {
|
||||
ok = false;
|
||||
error += e.getMessage();
|
||||
}
|
||||
if( !mailSent && lastResponse.length() > 0 ) {
|
||||
String[] lines = lastResponse.split( "\r\n" );
|
||||
for( int i = 0; i < lines.length; i++ )
|
||||
error += lines[i] + "<br>";
|
||||
}
|
||||
sendCmd( "QUIT" );
|
||||
if( socket != null ) {
|
||||
try {
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e1) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return mailSent;
|
||||
}
|
||||
}
|
||||
BIN
apps/susimail/src/susimail.png
Normal file
BIN
apps/susimail/src/susimail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
20
apps/susimail/src/susimail.properties
Normal file
20
apps/susimail/src/susimail.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
susimail.encodings=i2p.susi.webmail.encoding.HeaderLine;i2p.susi.webmail.encoding.QuotedPrintable;i2p.susi.webmail.encoding.Base64;i2p.susi.webmail.encoding.SevenBit;i2p.susi.webmail.encoding.EightBit;i2p.susi.webmail.encoding.HTML
|
||||
|
||||
susimail.host=localhost
|
||||
|
||||
susimail.ports.fixed=true
|
||||
susimail.ports.pop3=7660
|
||||
susimail.ports.smtp=7659
|
||||
|
||||
susimail.fast.start=true
|
||||
|
||||
susimail.sender.fixed=true
|
||||
susimail.sender.domain=mail.i2p
|
||||
|
||||
susimail.pager.pagesize=20
|
||||
|
||||
susimail.composer.cols=80
|
||||
susimail.composer.rows=15
|
||||
susimail.composer.bcc.to.self=true
|
||||
|
||||
susimail.date.format=MM/dd/yyyy HH:mm:ss
|
||||
@@ -10,8 +10,6 @@
|
||||
package net.i2p.apps.systray;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.io.File;
|
||||
|
||||
import snoozesoft.systray4j.SysTrayMenu;
|
||||
import snoozesoft.systray4j.SysTrayMenuEvent;
|
||||
import snoozesoft.systray4j.SysTrayMenuIcon;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user