forked from I2P_Developers/i2p.i2p
susimail: UTF-8 support from wockenfuss (ticket #508)
This commit is contained in:
@@ -177,7 +177,7 @@ public class Mail {
|
||||
|
||||
try {
|
||||
ReadBuffer decoded = hl.decode( header );
|
||||
BufferedReader reader = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( decoded.content, decoded.offset, decoded.length ), "ISO-8859-1" ) );
|
||||
BufferedReader reader = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( decoded.content, decoded.offset, decoded.length ), "UTF-8" ) );
|
||||
String line;
|
||||
while( ( line = reader.readLine() ) != null ) {
|
||||
if( line.length() == 0 )
|
||||
|
||||
@@ -1333,7 +1333,7 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
out.println( "</head>\n<body>\n" +
|
||||
"<div class=\"page\"><p><img src=\"" + sessionObject.imgPath + "susimail.png\" alt=\"Susimail\"><br> </p>\n" +
|
||||
"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"" + myself + "\">" );
|
||||
"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"" + myself + "\" accept-charset=\"UTF-8\">" );
|
||||
|
||||
if( sessionObject.error != null && sessionObject.error.length() > 0 ) {
|
||||
out.println( "<p class=\"error\">" + sessionObject.error + "</p>" );
|
||||
@@ -1509,11 +1509,11 @@ public class WebMail extends HttpServlet
|
||||
body.append( "\r\nMIME-Version: 1.0\r\nContent-type: multipart/mixed; boundary=\"" + boundary + "\"\r\n\r\n" );
|
||||
}
|
||||
else {
|
||||
body.append( "\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" );
|
||||
body.append( "\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=\"utf-8\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" );
|
||||
}
|
||||
try {
|
||||
if( multipart )
|
||||
body.append( "--" + boundary + "\r\nContent-type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" );
|
||||
body.append( "--" + boundary + "\r\nContent-type: text/plain; charset=\"utf-8\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" );
|
||||
body.append( qp.encode( text ) );
|
||||
} catch (EncodingException e) {
|
||||
ok = false;
|
||||
|
||||
@@ -45,26 +45,24 @@ public class HeaderLine implements Encoding {
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(java.lang.String)
|
||||
*/
|
||||
public String encode(String text) throws EncodingException {
|
||||
try {
|
||||
return encode( new ByteArrayInputStream( text.getBytes() ) );
|
||||
} catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
return encode( text.getBytes() );
|
||||
}
|
||||
private static final int BUFSIZE = 2;
|
||||
private String encode(InputStream in) throws IOException
|
||||
{
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int l = 0, buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
boolean quoting = false;
|
||||
boolean quote = false;
|
||||
boolean linebreak = false;
|
||||
String quotedSequence = null;
|
||||
int rest = 0;
|
||||
int rest = in.length;
|
||||
int index = 0;
|
||||
while( true ) {
|
||||
rest = in.available();
|
||||
while( rest > 0 && buffered < BUFSIZE ) {
|
||||
tmp[buffered++] = in.read();
|
||||
tmp[buffered++] = in[index++];
|
||||
rest--;
|
||||
}
|
||||
if( rest == 0 && buffered == 0 )
|
||||
@@ -95,10 +93,10 @@ public class HeaderLine implements Encoding {
|
||||
}
|
||||
if( quote ) {
|
||||
if( ! quoting ) {
|
||||
quotedSequence = "=?iso-8859-1?Q?";
|
||||
quotedSequence = "=?utf-8?Q?";
|
||||
quoting = true;
|
||||
}
|
||||
quotedSequence += HexTable.table[ c ];
|
||||
quotedSequence += HexTable.table[ c < 0 ? 256 + c : c ];
|
||||
}
|
||||
else {
|
||||
if( quoting ) {
|
||||
@@ -144,19 +142,6 @@ public class HeaderLine implements Encoding {
|
||||
}
|
||||
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)
|
||||
*/
|
||||
@@ -174,6 +159,7 @@ public class HeaderLine implements Encoding {
|
||||
throw new DecodingException( "Index out of bound." );
|
||||
boolean linebreak = false;
|
||||
boolean lastCharWasQuoted = false;
|
||||
int lastSkip = 0;
|
||||
while( length-- > 0 ) {
|
||||
byte c = in[offset++];
|
||||
if( c == '=' ) {
|
||||
@@ -250,6 +236,7 @@ public class HeaderLine implements Encoding {
|
||||
*/
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
lastSkip = 0;
|
||||
}
|
||||
else {
|
||||
if( !lastCharWasQuoted )
|
||||
@@ -257,9 +244,17 @@ public class HeaderLine implements Encoding {
|
||||
/*
|
||||
* skip whitespace
|
||||
*/
|
||||
int skipped = 1;
|
||||
while( length > 0 && ( in[offset] == ' ' || in[offset] == '\t' ) ) {
|
||||
if( lastSkip > 0 && skipped >= lastSkip ) {
|
||||
break;
|
||||
}
|
||||
offset++;
|
||||
length--;
|
||||
skipped++;
|
||||
}
|
||||
if( lastSkip == 0 && skipped > 0 ) {
|
||||
lastSkip = skipped;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -273,6 +268,7 @@ public class HeaderLine implements Encoding {
|
||||
if( linebreak ) {
|
||||
out[written++] = '\r';
|
||||
out[written++] = '\n';
|
||||
lastSkip = 0;
|
||||
}
|
||||
|
||||
ReadBuffer readBuffer = new ReadBuffer();
|
||||
@@ -298,5 +294,6 @@ public class HeaderLine implements Encoding {
|
||||
HeaderLine hl = new HeaderLine();
|
||||
System.out.println( hl.encode( text ) );
|
||||
System.out.println( hl.encode( "test ÄÖÜ" ) );
|
||||
System.out.println( hl.encode( "Здравствуйте" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,25 +41,11 @@ public class QuotedPrintable implements Encoding {
|
||||
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 ByteArrayInputStream( text.getBytes() ) );
|
||||
}catch (IOException e) {
|
||||
throw new EncodingException( "IOException occured." );
|
||||
}
|
||||
return encode( text.getBytes() );
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -67,13 +53,17 @@ public class QuotedPrintable implements Encoding {
|
||||
* @return
|
||||
*/
|
||||
private static int BUFSIZE = 2;
|
||||
private String encode( InputStream in ) throws EncodingException, IOException {
|
||||
/* (non-Javadoc)
|
||||
* @see i2p.susi.webmail.encoding.Encoding#encode(byte[])
|
||||
*/
|
||||
public String encode( byte in[] ) throws EncodingException {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int read = 0, buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
int buffered = 0, tmp[] = new int[BUFSIZE];
|
||||
int read = in.length;
|
||||
int index = 0;
|
||||
while( true ) {
|
||||
read = in.available();
|
||||
while( read > 0 && buffered < BUFSIZE ) {
|
||||
tmp[buffered++] = in.read();
|
||||
tmp[buffered++] = in[index++];
|
||||
read--;
|
||||
}
|
||||
if( read == 0 && buffered == 0 )
|
||||
@@ -105,10 +95,7 @@ public class QuotedPrintable implements Encoding {
|
||||
tmp[j-1] = tmp[j];
|
||||
}
|
||||
else {
|
||||
if( c < 0 || c > 255 ) {
|
||||
throw new EncodingException( "Encoding supports only values of 0..255." );
|
||||
}
|
||||
out.append( HexTable.table[ c ] );
|
||||
out.append( HexTable.table[ c < 0 ? 256 + c : c ] );
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
|
||||
@@ -92,7 +92,7 @@ public class MultiPartRequest
|
||||
value(content_type.substring(content_type.indexOf("boundary=")));
|
||||
|
||||
//if(log.isDebugEnabled())log.debug("Boundary="+_boundary);
|
||||
_byteBoundary= (_boundary+"--").getBytes("ISO-8859-1");
|
||||
_byteBoundary= (_boundary+"--").getBytes("UTF-8");
|
||||
|
||||
loadAllParts();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
2014-01-09 str4d
|
||||
* susimail: UTF-8 support from wockenfuss (ticket #508)
|
||||
* Console: Fixed overlapping text issue in midnight theme
|
||||
|
||||
2014-01-04 zzz
|
||||
|
||||
Reference in New Issue
Block a user