SusiMail: Fix unhandled decoding exception

Trim leading whitespace from charset
This commit is contained in:
zzz
2018-04-18 15:45:43 +00:00
parent ea9a3320a3
commit 75c20c9b1a
3 changed files with 12 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -472,7 +472,7 @@ class MailPart {
/*
* no " found and no ;
*/
result = line.substring( j + 1 );
result = line.substring( j + 1 ).trim();
}
}
}

View File

@@ -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';