From f4d22b0c8ea0b23f683bbe24dc904465b08ee2b0 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 6 Dec 2023 09:27:43 -0500 Subject: [PATCH] SusiMail fixes: - Flush output to fix truncated mails - Close output for attachments - Fix setting encoding for attachments - Set length for binary encoding --- apps/susimail/src/src/i2p/susi/webmail/MailPart.java | 5 +++-- apps/susimail/src/src/i2p/susi/webmail/WebMail.java | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/susimail/src/src/i2p/susi/webmail/MailPart.java b/apps/susimail/src/src/i2p/susi/webmail/MailPart.java index 1bbb5b3f0..205293040 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/MailPart.java +++ b/apps/susimail/src/src/i2p/susi/webmail/MailPart.java @@ -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) diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 7f4ad59e4..b2c04c58f 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -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;