From f040421848f7ac3f28f4a991f87645d6aebc5b6f Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 19 Apr 2018 21:20:58 +0000 Subject: [PATCH] SusiMail: Fix reply/forward filling in compose form Better formatting of addresses in forwarded mail --- .../src/src/i2p/susi/webmail/Mail.java | 27 +++++++++++++ .../src/src/i2p/susi/webmail/WebMail.java | 39 ++++++++----------- history.txt | 8 ++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/apps/susimail/src/src/i2p/susi/webmail/Mail.java b/apps/susimail/src/src/i2p/susi/webmail/Mail.java index 84660e0b4..08b962be5 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/Mail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/Mail.java @@ -37,6 +37,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.PrintWriter; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -341,6 +342,7 @@ class Mail { /** * Adds all items from the list * to the builder, separated by tabs. + * This is for SMTP/POP. * * @param buf out param * @param prefix prepended to the addresses @@ -357,6 +359,31 @@ class Mail { } } + /** + * Adds all items from the array + * to the builder, separated by commas + * This is for display of a forwarded email. + * + * @param prefix prepended to the addresses, includes trailing ": " + * @since 0.9.35 + */ + public static void appendRecipients(PrintWriter out, String[] recipients, String prefix) + { + StringBuilder buf = new StringBuilder(120); + buf.append(prefix); + for (int i = 0; i < recipients.length; i++) { + buf.append(recipients[i]); + if (i < recipients.length - 1) + buf.append(", "); + if (buf.length() > 75) { + out.println(buf); + buf.setLength(0); + } + } + if (buf.length() > 0) + out.println(buf); + } + private static final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); private static final DateFormat localDateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); private static final DateFormat longLocalDateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 6afbd039a..57c0e6fce 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -1220,6 +1220,7 @@ public class WebMail extends HttpServlet */ StringBuilder buf = new StringBuilder(); String pad = ""; + // TODO original recipients should be in the To: line, not the CC: line if( mail.to != null ) { for( int i = 0; i < mail.to.length; i++ ) { buf.append( pad ); @@ -1262,22 +1263,10 @@ public class WebMail extends HttpServlet pw.println(); pw.println( "---- " + _t("begin forwarded mail") + " ----" ); pw.println( "From: " + sender ); - if( mail.to != null ) { - String pad = "To: "; - for( int i = 0; i < mail.to.length; i++ ) { - pw.println( pad ); - pw.println(mail.to[i]); - pad = " "; - } - } - if( mail.cc != null ) { - String pad = "Cc: "; - for( int i = 0; i < mail.cc.length; i++ ) { - pw.println( pad ); - pw.println(mail.cc[i]); - pad = " "; - } - } + if (mail.to != null && mail.to.length > 0) + Mail.appendRecipients(pw, mail.to, "To: "); + if (mail.cc != null && mail.cc.length > 0) + Mail.appendRecipients(pw, mail.cc, "Cc: "); if( mail.dateString != null ) pw.print( "Date: " + mail.dateString ); pw.println(); @@ -1286,13 +1275,14 @@ public class WebMail extends HttpServlet pw.flush(); sessionObject.body = text.toString(); } + // TODO store as draft here, then P-R-G state = State.NEW; } else { sessionObject.error += _t("Could not fetch mail body.") + '\n'; - } - } - } + } // part != null + } // uidl != null + } // reply/fwd // Set state if unknown if (state == null) { @@ -2099,7 +2089,12 @@ public class WebMail extends HttpServlet } if (state == State.NEW) { - if (isPOST) { + // TODO we can't P-R-G for reply/fwd or we lose the form data; + // must store immediately as draft in PCSB above, before enabling P-R-G + if (isPOST && + !(buttonPressed(request, REPLY) || + buttonPressed(request, REPLYALL) || + buttonPressed(request, FORWARD))) { String q = '?' + NEW_UIDL; String newUIDL = request.getParameter(NEW_UIDL); if (newUIDL != null) @@ -2400,7 +2395,7 @@ public class WebMail extends HttpServlet * @param q starting with '?' or null * @since 0.9.33 adapted from I2PSnarkServlet */ - private static void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String q) throws IOException { + private void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String q) throws IOException { String url = req.getRequestURL().toString(); StringBuilder buf = new StringBuilder(128); int qq = url.indexOf('?'); @@ -2412,7 +2407,7 @@ public class WebMail extends HttpServlet resp.setHeader("Location", buf.toString()); resp.setStatus(303); resp.getOutputStream().close(); - //if (_log.shouldDebug()) _log.debug("P-R-G to " + q); + if (_log.shouldDebug()) _log.debug("P-R-G to " + q); } /** diff --git a/history.txt b/history.txt index 6437afe02..3932ed68b 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,11 @@ +2018-04-19 zzz + * SusiMail: + - Fix reply/forward filling in compose form + - Better formatting of addresses in forwarded mail + +2018-04-18 zzz + * SusiMail: Fix unhandled decoding exception + 2018-04-17 zzz * Console: Fix sidebar status when updating plugin (ticket #2137) * Reseed, NTP: Use DNSoverHTTPS (ticket #2201) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index f6e6df3a5..4e28a2c8d 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 4; + public final static long BUILD = 5; /** for example "-test" */ public final static String EXTRA = "";