forked from I2P_Developers/i2p.i2p
SusiMail: Fix unhandled decoding exception
Trim leading whitespace from charset
This commit is contained in:
@@ -2,6 +2,7 @@ package i2p.susi.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
@@ -28,11 +29,18 @@ public class DecodingOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* @param out UTF-8
|
||||
* @throws UnsupportedEncodingException (an IOException) on unknown charset
|
||||
*/
|
||||
public DecodingOutputStream(Writer out, String charset) {
|
||||
public DecodingOutputStream(Writer out, String charset) throws UnsupportedEncodingException {
|
||||
super();
|
||||
_out = out;
|
||||
_dc = Charset.forName(charset).newDecoder();
|
||||
try {
|
||||
_dc = Charset.forName(charset).newDecoder();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
UnsupportedEncodingException uee = new UnsupportedEncodingException("Unsupported charset \"" + charset + '"');
|
||||
uee.initCause(iae);
|
||||
throw uee;
|
||||
}
|
||||
_bb = ByteBuffer.allocate(1024);
|
||||
_cb = CharBuffer.allocate(1024);
|
||||
}
|
||||
|
@@ -472,7 +472,7 @@ class MailPart {
|
||||
/*
|
||||
* no " found and no ;
|
||||
*/
|
||||
result = line.substring( j + 1 );
|
||||
result = line.substring( j + 1 ).trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2898,8 +2898,8 @@ public class WebMail extends HttpServlet
|
||||
cc = arrayToCSV(draft.cc);
|
||||
bcc = arrayToCSV(draft.getBcc());
|
||||
StringWriter body = new StringWriter(1024);
|
||||
Buffer ob = new OutputStreamBuffer(new DecodingOutputStream(body, "UTF-8"));
|
||||
try {
|
||||
Buffer ob = new OutputStreamBuffer(new DecodingOutputStream(body, "UTF-8"));
|
||||
draft.getPart().decode(0, ob);
|
||||
} catch (IOException ioe) {
|
||||
sessionObject.error += "Draft decode error: " + ioe.getMessage() + '\n';
|
||||
|
Reference in New Issue
Block a user