Skip to content

Commit

Permalink
SusiMail fixes:
Browse files Browse the repository at this point in the history
- Flush output to fix truncated mails
- Close output for attachments
- Fix setting encoding for attachments
- Set length for binary encoding
  • Loading branch information
zzzi2p committed Dec 6, 2023
1 parent bdb8958 commit f4d22b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions apps/susimail/src/src/i2p/susi/webmail/MailPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ else if( message ) {
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)
Expand Down Expand Up @@ -332,7 +332,6 @@ public synchronized void decode(int offset, Buffer out) throws IOException {
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()
Expand All @@ -346,6 +345,8 @@ else if (cos != null)
} 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)
Expand Down
9 changes: 8 additions & 1 deletion apps/susimail/src/src/i2p/susi/webmail/WebMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -2516,18 +2516,25 @@ private static boolean sendAttachment(SessionObject sessionObject, MailPart part
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;
Expand Down

0 comments on commit f4d22b0

Please sign in to comment.