SusiMail fixes:

- Flush output to fix truncated mails
- Close output for attachments
- Fix setting encoding for attachments
- Set length for binary encoding
This commit is contained in:
zzz
2023-12-06 09:27:43 -05:00
parent bdb89581c8
commit f4d22b0c8e
2 changed files with 11 additions and 3 deletions
@@ -250,7 +250,7 @@ class MailPart {
tmpEnd = (int) counter.getRead();
}
end = tmpEnd;
if (encoding == null || encoding.equals("7bit") || encoding.equals("8bit")) {
if (encoding == null || encoding.equals("7bit") || encoding.equals("8bit") || encoding.equals("binary")) {
decodedLength = end - beginBody;
}
//if (Debug.getLevel() >= Debug.DEBUG)
@@ -332,7 +332,6 @@ class MailPart {
dout = out;
}
enc.decode(lin, dout);
//dout.getOutputStream().flush();
} catch (IOException ioe) {
if (lin != null)
if (_log.shouldDebug()) _log.debug("Decode IOE at in position " + lin.getRead()
@@ -346,6 +345,8 @@ class MailPart {
} finally {
if (lin != null) try { lin.close(); } catch (IOException ioe) {};
buffer.readComplete(true);
if (dout != null)
dout.getOutputStream().flush();
// let the servlet do this
//if (cos != null) try { cos.close(); } catch (IOException ioe) {};
//if (dout != null)
@@ -2516,18 +2516,25 @@ public class WebMail extends HttpServlet
String name3 = FilenameUtil.encodeFilenameRFC5987(name);
response.setHeader("Cache-Control", "public, max-age=604800");
if (isRaw) {
OutputStream out = null;
try {
response.addHeader("Content-Disposition", "inline; filename=\"" + name2 + "\"; " +
"filename*=" + name3);
if (part.type != null)
response.setContentType(part.type);
if (part.charset != null)
response.setCharacterEncoding(part.charset);
if (part.decodedLength >= 0)
response.setContentLength(part.decodedLength);
if (log.shouldDebug()) log.debug("Sending raw attachment " + name + " length " + part.decodedLength);
part.decode(0, new OutputStreamBuffer(response.getOutputStream()));
out = response.getOutputStream();
part.decode(0, new OutputStreamBuffer(out));
shown = true;
} catch (IOException e) {
log.error("Error sending raw attachment " + name + " length " + part.decodedLength, e);
} finally {
if (out != null)
try { out.close(); } catch (IOException ioe) {}
}
} else {
ZipOutputStream zip = null;