From b0db4e4fff1b9f35bd239512cc5b81116b8f95f5 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Wed, 7 May 2014 14:34:51 +0000 Subject: [PATCH] * SusiMail: - Don't fetch headers from folder sorters - Update debug setting when saving config --- .../src/src/i2p/susi/webmail/MailCache.java | 25 ++++++++++------ .../src/src/i2p/susi/webmail/WebMail.java | 30 +++++++++---------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/apps/susimail/src/src/i2p/susi/webmail/MailCache.java b/apps/susimail/src/src/i2p/susi/webmail/MailCache.java index 0c0dd3fc13..fd2d80d44f 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/MailCache.java +++ b/apps/susimail/src/src/i2p/susi/webmail/MailCache.java @@ -43,8 +43,9 @@ import java.util.Set; */ class MailCache { - public static final boolean FETCH_HEADER = true; - public static final boolean FETCH_ALL = false; + public enum FetchMode { + HEADER, ALL, CACHE_ONLY + } private final POP3MailBox mailbox; private final Hashtable<String, Mail> mails; @@ -105,10 +106,10 @@ class MailCache { * Fetch any needed data from pop3 server. * * @param uidl message id to get - * @param headerOnly fetch only header lines? + * @param mode CACHE_ONLY to not pull from pop server * @return An e-mail or null */ - public Mail getMail( String uidl, boolean headerOnly ) { + public Mail getMail(String uidl, FetchMode mode) { Mail mail = null, newMail = null; @@ -129,13 +130,13 @@ class MailCache { if (mail.markForDeletion) return null; int sz = mail.getSize(); - if (sz > 0 && sz <= FETCH_ALL_SIZE) - headerOnly = false; + if (mode == FetchMode.HEADER && sz > 0 && sz <= FETCH_ALL_SIZE) + mode = FetchMode.ALL; - if( headerOnly ) { + if (mode == FetchMode.HEADER) { if(!mail.hasHeader()) mail.setHeader(mailbox.getHeader(uidl)); - } else { + } else if (mode == FetchMode.ALL) { if(!mail.hasBody()) { ReadBuffer rb = mailbox.getBody(uidl); if (rb != null) { @@ -146,6 +147,8 @@ class MailCache { } } } + } else { + // else if it wasn't in cache, too bad } return mail; } @@ -156,10 +159,14 @@ class MailCache { * After this, call getUIDLs() to get all known mail UIDLs. * MUST already be connected, otherwise returns false. * + * @param mode HEADER or ALL only * @return true if any were fetched * @since 0.9.13 */ - public boolean getMail(boolean hOnly) { + public boolean getMail(FetchMode mode) { + if (mode == FetchMode.CACHE_ONLY) + throw new IllegalArgumentException(); + boolean hOnly = mode == FetchMode.HEADER; Collection<String> popKnown = mailbox.getUIDLs(); if (popKnown == null) diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 5e8454aa67..8cbaa4de4d 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -251,8 +251,8 @@ public class WebMail extends HttpServlet * Gets mail from the cache, checks for null, then compares */ public int compare(String arg0, String arg1) { - Mail a = mailCache.getMail( arg0, MailCache.FETCH_HEADER ); - Mail b = mailCache.getMail( arg1, MailCache.FETCH_HEADER ); + Mail a = mailCache.getMail( arg0, MailCache.FetchMode.CACHE_ONLY ); + Mail b = mailCache.getMail( arg1, MailCache.FetchMode.CACHE_ONLY ); if (a == null) return (b == null) ? 0 : 1; if (b == null) @@ -440,10 +440,8 @@ public class WebMail extends HttpServlet MailCache mc = mailCache; Folder<String> f = folder; if (mc != null && f != null) { - if (MailCache.FETCH_HEADER) { - String[] uidls = mc.getUIDLs(); - f.setElements(uidls); - } + String[] uidls = mc.getUIDLs(); + f.setElements(uidls); } } } @@ -775,7 +773,7 @@ public class WebMail extends HttpServlet if (!offline) { // prime the cache, request all headers at once // otherwise they are pulled one at a time by sortBy() below - mc.getMail(MailCache.FETCH_HEADER); + mc.getMail(MailCache.FetchMode.HEADER); } // get through cache so we have the disk-only ones too String[] uidls = mc.getUIDLs(); @@ -976,7 +974,7 @@ public class WebMail extends HttpServlet } if( uidl != null ) { - Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_ALL ); + Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FetchMode.ALL ); /* * extract original sender from Reply-To: or From: */ @@ -1140,7 +1138,7 @@ public class WebMail extends HttpServlet // TODO how to do a "No new mail" message? sessionObject.mailbox.refresh(); sessionObject.error += sessionObject.mailbox.lastError(); - sessionObject.mailCache.getMail(MailCache.FETCH_HEADER); + sessionObject.mailCache.getMail(MailCache.FetchMode.HEADER); // get through cache so we have the disk-only ones too String[] uidls = sessionObject.mailCache.getUIDLs(); if (uidls != null) @@ -1281,7 +1279,7 @@ public class WebMail extends HttpServlet if( str != null ) { try { int hashCode = Integer.parseInt( str ); - Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FETCH_ALL ); + Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FetchMode.ALL ); MailPart part = mail != null ? getMailPartFromHashCode( mail.getPart(), hashCode ) : null; if( part != null ) { if (sendAttachment(sessionObject, part, response, isRaw)) @@ -1443,6 +1441,8 @@ public class WebMail extends HttpServlet sessionObject.folder.setPageSize( pageSize ); } catch( NumberFormatException nfe ) {} } + boolean release = !Boolean.parseBoolean(props.getProperty(CONFIG_DEBUG)); + Debug.setLevel( release ? Debug.ERROR : Debug.DEBUG ); sessionObject.state = sessionObject.folder != null ? STATE_LIST : STATE_AUTH; sessionObject.info = _("Configuration saved"); } catch (IOException ioe) { @@ -1608,7 +1608,7 @@ public class WebMail extends HttpServlet processSortingButtons( sessionObject, request ); for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { String uidl = it.next(); - Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER ); + Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FetchMode.HEADER ); if( mail != null && mail.error.length() > 0 ) { sessionObject.error += mail.error; mail.error = ""; @@ -1629,7 +1629,7 @@ public class WebMail extends HttpServlet // sessionObject.state = STATE_LIST and // sessionObject.showUIDL = null if ( sessionObject.showUIDL != null ) { - Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FETCH_ALL ); + Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FetchMode.ALL ); if( mail != null && mail.error.length() > 0 ) { sessionObject.error += mail.error; mail.error = ""; @@ -1662,7 +1662,7 @@ public class WebMail extends HttpServlet //subtitle = ngettext("1 Message", "{0} Messages", sessionObject.mailbox.getNumMails()); subtitle = ngettext("1 Message", "{0} Messages", sessionObject.folder.getSize()); } else if( sessionObject.state == STATE_SHOW ) { - Mail mail = sessionObject.mailCache.getMail(sessionObject.showUIDL, MailCache.FETCH_HEADER); + Mail mail = sessionObject.mailCache.getMail(sessionObject.showUIDL, MailCache.FetchMode.HEADER); if (mail != null && mail.shortSubject != null) subtitle = mail.shortSubject; else @@ -2121,7 +2121,7 @@ public class WebMail extends HttpServlet int i = 0; for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) { String uidl = it.next(); - Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER ); + Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FetchMode.HEADER ); if (mail == null) { i++; continue; @@ -2235,7 +2235,7 @@ public class WebMail extends HttpServlet if( sessionObject.reallyDelete ) { out.println( "<p class=\"error\">" + _("Really delete this message?") + " " + button( REALLYDELETE, _("Yes, really delete it!") ) + "</p>" ); } - Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FETCH_ALL ); + Mail mail = sessionObject.mailCache.getMail( sessionObject.showUIDL, MailCache.FetchMode.ALL ); if(!RELEASE && mail != null && mail.hasBody()) { out.println( "<!--" ); out.println( "Debug: Mail header and body follow"); -- GitLab