From cb5cdbe00f9fdaaa039eb01f5f4ed0f1f71d874a Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 23 Dec 2023 07:19:15 -0500 Subject: [PATCH] Susimail: Show size and thumbnail of draft attachments --- .../src/src/i2p/susi/webmail/WebMail.java | 57 ++++++++++++++++++- apps/susimail/src/themes/dark/susimail.css | 6 ++ apps/susimail/src/themes/light/susimail.css | 6 ++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 885d0e897..44dbd2747 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -166,6 +166,7 @@ public class WebMail extends HttpServlet private static final String SHOW = "show"; private static final String DOWNLOAD = "download"; private static final String RAW_ATTACHMENT = "att"; + private static final String DRAFT_ATTACHMENT = "datt"; private static final String MARKALL = "markall"; private static final String CLEAR = "clearselection"; @@ -1616,6 +1617,50 @@ public class WebMail extends HttpServlet } + /** + * Process thumbnail link in compose view + * Draft attachments are stored in the SessionObject and identified by hashcode only. + * + * @since 0.9.62 + */ + private static void processDraftAttachmentLink(SessionObject sessionObject, + RequestWrapper request, HttpServletResponse response) + { + String str = request.getParameter(DRAFT_ATTACHMENT); + if (str != null) { + InputStream in = null; + OutputStream out = null; + try { + if (sessionObject.attachments != null) { + int hc = Integer.parseInt(str); + for (Attachment att : sessionObject.attachments) { + if (hc == att.hashCode()) { + String ct = att.getContentType(); + if (ct != null) + response.setContentType(ct); + response.setContentLength((int) att.getSize()); + response.setHeader("Cache-Control", "public, max-age=3600"); + in = att.getData(); + out = response.getOutputStream(); + DataHelper.copy(in, out); + return; + } + } + } + } catch (NumberFormatException nfe ) { + } catch (IOException ioe ) { + } finally { + if (in != null) try { in.close(); } catch (IOException ioe) {} + if (out != null) try { out.close(); } catch (IOException ioe) {} + } + } + // error if we get here + try { + response.sendError(404, _t("Attachment not found.")); + } catch (IOException ioe) {} + } + + /** * Process save-as link in message view * @@ -2183,6 +2228,10 @@ public class WebMail extends HttpServlet sendRedirect(httpRequest, response, q); return; } + if (request.getParameter(DRAFT_ATTACHMENT) != null) { + processDraftAttachmentLink(sessionObject, request, response); + return; + } } // ?show= links - this forces State.SHOW @@ -3101,7 +3150,13 @@ public class WebMail extends HttpServlet } else { out.println(" "); } - out.println(""); + out.println(""); + out.println(DataHelper.formatSize2(attachment.getSize()) + 'B'); + String type = attachment.getContentType(); + if (type != null && type.startsWith("image/")) { + out.println("