SusiMail:

- Initializer cleanup, finals
   - Escape "--" inside HTML comments
   - Log errors to router log too
   - Notes on ticket #508 header line issues
This commit is contained in:
zzz
2014-04-17 18:48:07 +00:00
parent 5ec659513b
commit 3f35e927dd
12 changed files with 58 additions and 41 deletions

View File

@ -23,6 +23,8 @@
*/
package i2p.susi.debug;
import net.i2p.I2PAppContext;
/**
* @author susi23
*/
@ -31,13 +33,17 @@ 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 );
if (msgLevel <= ERROR)
I2PAppContext.getGlobalContext().logManager().getLog(Debug.class).error(msg);
}
}

View File

@ -37,8 +37,8 @@ import net.i2p.I2PAppContext;
*/
public class Config {
private static Properties properties = null, config = null;
private static String configPrefix = null;
private static Properties properties, config;
private static String configPrefix;
/**
*
* @param name

View File

@ -51,19 +51,16 @@ public class Folder<O extends Object> {
private int pages, pageSize, currentPage;
private O[] unsortedElements, elements;
private Hashtable<String, Comparator<O>> sorter;
private final Hashtable<String, Comparator<O>> sorter;
private boolean sortingDirection;
Comparator<O> currentSorter;
public Folder()
{
pages = 1;
pageSize = 0;
currentPage = 1;
unsortedElements = null;
sorter = new Hashtable<String, Comparator<O>>();
sortingDirection = UP;
currentSorter = null;
}
/**

View File

@ -28,10 +28,9 @@ package i2p.susi.util;
*/
public class HexTable {
public static String[] table = null;
public static final String[] table = new String[256];
static {
table = new String[256];
for( int i = 0; i < 256; i++ ) {
String str = intToHex( i );
if( str.length() == 1 )
@ -39,6 +38,7 @@ public class HexTable {
table[i] = "=" + str;
}
}
private static String intToHex( int b )
{
if( b == 0 )

View File

@ -65,8 +65,6 @@ public class Mail {
public boolean deleted;
public Mail() {
id = 0;
size = 0;
formattedSender = unknown;
formattedSubject = unknown;
formattedDate = unknown;

View File

@ -35,9 +35,9 @@ public class MailCache {
public static final boolean FETCH_HEADER = true;
public static final boolean FETCH_ALL = false;
private POP3MailBox mailbox;
private Hashtable<String, Mail> mails;
private Object synchronizer;
private final POP3MailBox mailbox;
private final Hashtable<String, Mail> mails;
private final Object synchronizer;
MailCache( POP3MailBox mailbox ) {
this.mailbox = mailbox;

View File

@ -37,9 +37,9 @@ public class MailPart {
public String headerLines[], type, boundary, encoding, name,
filename, description, disposition, charset, version;
public int beginBody, begin, end;
public ArrayList<MailPart> parts = null;
public boolean multipart = false, message = false;
public ReadBuffer buffer = null;
public ArrayList<MailPart> parts;
public boolean multipart, message;
public ReadBuffer buffer;
public void parse( ReadBuffer readBuffer )
{

View File

@ -53,16 +53,11 @@ import org.mortbay.servlet.MultiPartRequest;
*/
public class RequestWrapper {
private HttpServletRequest httpRequest = null;
private MultiPartRequest multiPartRequest = null;
private Hashtable<String, String> cache;
private final HttpServletRequest httpRequest;
private MultiPartRequest multiPartRequest;
private final Hashtable<String, String> cache;
private Hashtable<String, Integer> cachedParameterNames;
/**
* do not call
*/
private RequestWrapper()
{
}
/**
* @param httpRequest
*/

View File

@ -403,9 +403,10 @@ public class WebMail extends HttpServlet
if( html ) {
out.println( "<!-- " );
for( int i = 0; i < mailPart.headerLines.length; i++ )
out.println( mailPart.headerLines[i] );
for( int i = 0; i < mailPart.headerLines.length; i++ ) {
// fix Content-Type: multipart/alternative; boundary="----------8CDE39ECAF2633"
out.println( mailPart.headerLines[i].replace("--", "&mdash;") );
}
out.println( "-->" );
}
@ -1742,6 +1743,7 @@ public class WebMail extends HttpServlet
}
if( !RELEASE ) {
out.println( "<!--" );
// FIXME encoding, escaping --, etc... but disabled.
out.println( quoteHTML( new String( mail.body.content, mail.body.offset, mail.body.length ) ) );
out.println( "-->" );
}

View File

@ -35,9 +35,9 @@ import java.util.Set;
*/
public class EncodingFactory {
public static final String CONFIG_ENCODING = "encodings";
private static final String CONFIG_ENCODING = "encodings";
private static Hashtable<String, Encoding> encodings = null;
private static final Hashtable<String, Encoding> encodings;
static {
encodings = new Hashtable<String, Encoding>();

View File

@ -31,6 +31,10 @@ import java.io.IOException;
import java.io.InputStream;
/**
* Ref:
* http://en.wikipedia.org/wiki/MIME#Encoded-Word
* http://tools.ietf.org/html/rfc2047
*
* @author susi
*/
public class HeaderLine implements Encoding {
@ -167,6 +171,7 @@ public class HeaderLine implements Encoding {
if( in[offset] == '?' ) {
// System.err.println( "=? found at " + ( offset -1 ) );
int f2 = offset + 1;
// FIXME save charset here ticket #508
for( ; f2 < end && in[f2] != '?'; f2++ );
if( f2 < end ) {
/*
@ -196,6 +201,7 @@ public class HeaderLine implements Encoding {
try {
// System.err.println( "decode(" + (f3 + 1) + "," + ( f4 - f3 - 1 ) + ")" );
tmp = e.decode( in, f3 + 1, f4 - f3 - 1 );
// FIXME use saved charset here ticket #508
for( int j = 0; j < tmp.length; j++ ) {
byte d = tmp.content[ tmp.offset + j ];
out[written++] = ( d == '_' ? 32 : d );
@ -287,6 +293,8 @@ public class HeaderLine implements Encoding {
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örebröd <smoerebroed@mail.i2p>\r\n" +
@ -296,4 +304,5 @@ public class HeaderLine implements Encoding {
System.out.println( hl.encode( "test ÄÖÜ" ) );
System.out.println( hl.encode( "Здравствуйте" ) );
}
****/
}

View File

@ -24,6 +24,7 @@
package i2p.susi.webmail.pop3;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.Messages;
import i2p.susi.util.ReadBuffer;
import java.io.IOException;
@ -40,24 +41,26 @@ public class POP3MailBox {
private static final int DEFAULT_BUFSIZE = 4096;
private String host = null, user = null, pass = null;
private final String host, user, pass;
private String lastLine = "-ERR No response from server", lastError = null;
private static final String ERR = "-ERR ";
private String lastLine, lastError;
private int port = 0, mails = 0, read = 0;
private final int port;
private int mails, read;
private boolean connected = false;
private boolean connected;
private Hashtable<Integer, ReadBuffer> headerList = null, bodyList = null;
private Hashtable<Integer, Integer> sizes = null;
private Hashtable<String, Integer> uidlToID = null;
private ArrayList<String> uidlList = null;
private final Hashtable<Integer, ReadBuffer> headerList, bodyList;
private Hashtable<Integer, Integer> sizes;
private final Hashtable<String, Integer> uidlToID;
private final ArrayList<String> uidlList;
private Socket socket = null;
private Socket socket;
private byte[] buffer = new byte[DEFAULT_BUFSIZE];
private final byte[] buffer = new byte[DEFAULT_BUFSIZE];
private Object synchronizer = null;
private final Object synchronizer;
/**
* @param host
@ -79,6 +82,8 @@ public class POP3MailBox {
uidlToID = new Hashtable<String, Integer>();
sizes = new Hashtable<Integer, Integer>();
synchronizer = new Object();
// this appears in the UI so translate
lastLine = ERR + _("No response from server");
connect();
}
@ -687,4 +692,9 @@ public class POP3MailBox {
close();
connect();
}
/** translate */
private static String _(String s) {
return Messages.getString(s);
}
}