From 8a2308b411b8842e100edc60b7c3c6d7428c931f Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 25 Apr 2014 18:47:47 +0000 Subject: [PATCH] * SusiMail: - Send delete to server for mails already downloaded - Fix idle closer waiting for deletions - Add tooltips for icons - Add new options to properties resource - Add feedback when reload config button pushed (ticket #1158) - Reset page size when config reloaded - Remove max page size limit - Show page nav buttons on bottom too if page is big - Set title to subject on message view - Log tweaks --- .../src/src/i2p/susi/webmail/MailCache.java | 22 ++++++ .../src/src/i2p/susi/webmail/WebMail.java | 78 +++++++++++++------ .../i2p/susi/webmail/pop3/DelayedDeleter.java | 2 +- .../src/i2p/susi/webmail/pop3/IdleCloser.java | 2 +- .../i2p/susi/webmail/pop3/POP3MailBox.java | 1 + apps/susimail/src/susimail.properties | 9 ++- 6 files changed, 85 insertions(+), 29 deletions(-) diff --git a/apps/susimail/src/src/i2p/susi/webmail/MailCache.java b/apps/susimail/src/src/i2p/susi/webmail/MailCache.java index 058fda1e8b..0c0dd3fc13 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/MailCache.java +++ b/apps/susimail/src/src/i2p/susi/webmail/MailCache.java @@ -195,22 +195,44 @@ class MailCache { if (disk != null) { if (disk.getMail(mail, true)) { Debug.debug(Debug.DEBUG, "Loaded header from disk cache: " + uidl); + // note that disk loaded the full body if it had it + if (mail.hasBody() && + !Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) { + // we already have it, send delete + mailbox.queueForDeletion(mail.uidl); + } continue; // found on disk, woo } } POP3Request pr = new POP3Request(mail, true); fetches.add(pr); + } else { + if (mail.hasBody() && + !Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) { + // we already have it, send delete + mailbox.queueForDeletion(mail.uidl); + } } } else { if(!mail.hasBody()) { if (disk != null) { if (disk.getMail(mail, false)) { Debug.debug(Debug.DEBUG, "Loaded body from disk cache: " + uidl); + // note that disk loaded the full body if it had it + if (!Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) { + // we already have it, send delete + mailbox.queueForDeletion(mail.uidl); + } continue; // found on disk, woo } } POP3Request pr = new POP3Request(mail, false); fetches.add(pr); + } else { + if (!Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) { + // we already have it, send delete + mailbox.queueForDeletion(mail.uidl); + } } } } diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index df029284d6..97f429006d 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -91,7 +91,10 @@ public class WebMail extends HttpServlet private static final int STATE_LIST = 2; private static final int STATE_SHOW = 3; private static final int STATE_NEW = 4; + // TODO + private static final int STATE_CONFIG = 5; + // TODO generate from servlet name to allow for renaming or multiple instances private static final String myself = "/susimail/susimail"; /* @@ -477,14 +480,14 @@ public class WebMail extends HttpServlet buf.append("<img src=\"").append(imgPath).append("3up.png\" border=\"0\" alt=\"^\">\n"); } else { buf.append("<a href=\"").append(myself).append('?').append(name).append("=up\">"); - buf.append("<img src=\"").append(imgPath).append("3up.png\" border=\"0\" alt=\"^\" style=\"opacity: 0.6;\">"); + buf.append("<img src=\"").append(imgPath).append("3up.png\" border=\"0\" alt=\"^\" style=\"opacity: 0.4;\">"); buf.append("</a>\n"); } if (name.equals(currentName) && currentOrder == Folder.SortOrder.DOWN) { buf.append("<img src=\"").append(imgPath).append("3down.png\" border=\"0\" alt=\"v\">"); } else { buf.append("<a href=\"").append(myself).append('?').append(name).append("=down\">"); - buf.append("<img src=\"").append(imgPath).append("3down.png\" border=\"0\" alt=\"v\" style=\"opacity: 0.6;\">"); + buf.append("<img src=\"").append(imgPath).append("3down.png\" border=\"0\" alt=\"v\" style=\"opacity: 0.4;\">"); buf.append("</a>"); } return buf.toString(); @@ -1098,10 +1101,17 @@ public class WebMail extends HttpServlet */ private static void processGenericButtons(SessionObject sessionObject, RequestWrapper request) { + // these two buttons are only on the folder view now if( buttonPressed( request, RELOAD ) ) { Config.reloadConfiguration(); + int oldPageSize = sessionObject.folder.getPageSize(); + int pageSize = Config.getProperty( Folder.PAGESIZE, Folder.DEFAULT_PAGESIZE ); + if( pageSize != oldPageSize ) + sessionObject.folder.setPageSize( pageSize ); + sessionObject.info = _("Configuration reloaded"); } if( buttonPressed( request, REFRESH ) ) { + // TODO how to do a "No new mail" message? sessionObject.mailbox.refresh(); sessionObject.error += sessionObject.mailbox.lastError(); sessionObject.mailCache.getMail(MailCache.FETCH_HEADER); @@ -1295,11 +1305,9 @@ public class WebMail extends HttpServlet /* * process paging buttons */ - String str = request.getParameter( PAGESIZE ); - if( str != null && str.length() > 0 ) { + if (buttonPressed(request, PAGESIZE) && !buttonPressed(request, RELOAD)) { try { - // limit max to 100 as it makes the startup really slow - int pageSize = Math.min(100, Math.max(5, Integer.parseInt( str ))); + int pageSize = Math.max(5, Integer.parseInt(request.getParameter(PAGESIZE))); int oldPageSize = sessionObject.folder.getPageSize(); if( pageSize != oldPageSize ) sessionObject.folder.setPageSize( pageSize ); @@ -1571,8 +1579,15 @@ public class WebMail extends HttpServlet // Not only does it slow things down, but a failure causes all our messages to "vanish" //subtitle = ngettext("1 Message", "{0} Messages", sessionObject.mailbox.getNumMails()); subtitle = ngettext("1 Message", "{0} Messages", sessionObject.folder.getSize()); - } else if( sessionObject.state == STATE_SHOW ) - subtitle = _("Show Message"); + } else if( sessionObject.state == STATE_SHOW ) { + Mail mail = sessionObject.mailCache.getMail(sessionObject.showUIDL, MailCache.FETCH_HEADER); + if (mail != null && mail.shortSubject != null) + subtitle = mail.shortSubject; + else + subtitle = _("Show Message"); + } else if( sessionObject.state == STATE_NEW ) { + subtitle = _("New Message"); + } response.setContentType( "text/html" ); @@ -1987,20 +2002,8 @@ public class WebMail extends HttpServlet out.println(button( RELOAD, _("Reload Config") ) + spacer); out.println(button( LOGOUT, _("Logout") )); - if (sessionObject.folder.getPages() > 1) { - out.println( - "<br>" + - ( sessionObject.folder.isFirstPage() ? - button2( FIRSTPAGE, _("First") ) + " " + button2( PREVPAGE, _("Previous") ) : - button( FIRSTPAGE, _("First") ) + " " + button( PREVPAGE, _("Previous") ) ) + - " " + - _("Page {0} of {1}", sessionObject.folder.getCurrentPage(), sessionObject.folder.getPages()) + - " " + - ( sessionObject.folder.isLastPage() ? - button2( NEXTPAGE, _("Next") ) + " " + button2( LASTPAGE, _("Last") ) : - button( NEXTPAGE, _("Next") ) + " " + button( LASTPAGE, _("Last") ) ) - ); - } + if (sessionObject.folder.getPages() > 1) + showPageButtons(out, sessionObject.folder); String curSort = sessionObject.folder.getCurrentSortBy(); Folder.SortOrder curOrder = sessionObject.folder.getCurrentSortingDirection(); @@ -2050,11 +2053,11 @@ public class WebMail extends HttpServlet // ", clear=" + sessionObject.clear ); out.println( "<tr class=\"list" + bg + "\"><td><input type=\"checkbox\" class=\"optbox\" name=\"check" + i + "\" value=\"1\"" + ( idChecked ? "checked" : "" ) + ">" + "</td><td>" + - (mail.isNew() ? "<img src=\"/susimail/icons/flag_green.png\" alt=\"\">" : " ") + "</td><td>" + + (mail.isNew() ? "<img src=\"/susimail/icons/flag_green.png\" alt=\"\" title=\"" + _("Message is new") + "\">" : " ") + "</td><td>" + link + mail.shortSender + "</a></td><td>" + - (mail.hasAttachment() ? "<img src=\"/susimail/icons/attach.png\" alt=\"\">" : " ") + "</td><td>" + + (mail.hasAttachment() ? "<img src=\"/susimail/icons/attach.png\" alt=\"\" title=\"" + _("Message has an attachment") + "\">" : " ") + "</td><td>" + link + mail.shortSubject + "</a></td><td>" + - (mail.isSpam() ? "<img src=\"/susimail/icons/flag_red.png\" alt=\"\">" : " ") + "</td><td>" + + (mail.isSpam() ? "<img src=\"/susimail/icons/flag_red.png\" alt=\"\" title=\"" + _("Message is spam") + "\">" : " ") + "</td><td>" + // don't let date get split across lines mail.localFormattedDate.replace(" ", " ") + "</td><td> </td><td align=\"right\">" + ((mail.getSize() > 0) ? (DataHelper.formatSize2(mail.getSize()) + 'B') : "???") + "</td></tr>" ); @@ -2065,6 +2068,12 @@ public class WebMail extends HttpServlet out.println("<tr><td colspan=\"9\" align=\"center\"><i>" + _("No messages") + "</i></td></tr>\n</table>"); if (i > 0) { out.println( "<tr><td colspan=\"9\"><hr></td></tr>"); + if (sessionObject.folder.getPages() > 1 && i > 30) { + // show the buttons again if page is big + out.println("<tr><td colspan=\"9\" align=\"center\">"); + showPageButtons(out, sessionObject.folder); + out.println("</td></tr>"); + } out.println("<tr><td colspan=\"5\" align=\"left\">"); if( sessionObject.reallyDelete ) { // TODO ngettext @@ -2091,6 +2100,25 @@ public class WebMail extends HttpServlet } out.println( "</table>"); } + + /** + * first prev next last + */ + private static void showPageButtons(PrintWriter out, Folder folder) { + out.println( + "<br>" + + ( folder.isFirstPage() ? + button2( FIRSTPAGE, _("First") ) + " " + button2( PREVPAGE, _("Previous") ) : + button( FIRSTPAGE, _("First") ) + " " + button( PREVPAGE, _("Previous") ) ) + + " " + + _("Page {0} of {1}", folder.getCurrentPage(), folder.getPages()) + + " " + + ( folder.isLastPage() ? + button2( NEXTPAGE, _("Next") ) + " " + button2( LASTPAGE, _("Last") ) : + button( NEXTPAGE, _("Next") ) + " " + button( LASTPAGE, _("Last") ) ) + ); + } + /** * * @param out diff --git a/apps/susimail/src/src/i2p/susi/webmail/pop3/DelayedDeleter.java b/apps/susimail/src/src/i2p/susi/webmail/pop3/DelayedDeleter.java index 62c3c2eaf7..6cf69bf8e7 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/pop3/DelayedDeleter.java +++ b/apps/susimail/src/src/i2p/susi/webmail/pop3/DelayedDeleter.java @@ -74,7 +74,7 @@ class DelayedDeleter { isDeleting = true; t.start(); } else { - Debug.debug(Debug.DEBUG, "Not deleting, only idle " + idle); + Debug.debug(Debug.DEBUG, "Not deleting " + toDelete.size() + ", only idle " + idle); } } else { Debug.debug(Debug.DEBUG, "Nothing to delete"); diff --git a/apps/susimail/src/src/i2p/susi/webmail/pop3/IdleCloser.java b/apps/susimail/src/src/i2p/susi/webmail/pop3/IdleCloser.java index fad7326a9e..238c2d35ef 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/pop3/IdleCloser.java +++ b/apps/susimail/src/src/i2p/susi/webmail/pop3/IdleCloser.java @@ -101,7 +101,7 @@ class IdleCloser { // If we have items to delete, wait for the response code, // otherwise the DelayedDeleter thread will have to run later. // Since we are threaded we can do that here. - boolean shouldWait = !mailbox.hasQueuedDeletions(); + boolean shouldWait = mailbox.hasQueuedDeletions(); mailbox.close(shouldWait); isDead = true; } else { diff --git a/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java b/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java index dc671e157d..1b750993e1 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java +++ b/apps/susimail/src/src/i2p/susi/webmail/pop3/POP3MailBox.java @@ -1115,6 +1115,7 @@ public class POP3MailBox implements NewMailListener { } else { sendCmd1a("QUIT"); } + Debug.debug( Debug.DEBUG, "close() with wait complete"); } else { if (!sendDelete.isEmpty()) { // spray and pray the deletions, don't remove from delete queue diff --git a/apps/susimail/src/susimail.properties b/apps/susimail/src/susimail.properties index 82dc7c376e..45b5f0fe90 100644 --- a/apps/susimail/src/susimail.properties +++ b/apps/susimail/src/susimail.properties @@ -13,6 +13,11 @@ susimail.pager.pagesize=30 susimail.composer.cols=80 susimail.composer.rows=15 -susimail.composer.bcc.to.self=true +susimail.composer.bcc.to.self=false -susimail.date.format=MM/dd/yyyy HH:mm:ss +susimail.pop3.leave.on.server=false +susimail.pop3.check.enable=false +susimail.pop3.check.interval.minutes=180 +susimail.pop3.idle.timeout.seconds=240 + +susimail.debug=false -- GitLab