forked from I2P_Developers/i2p.i2p
* SusiMail:
- Don't fetch headers from folder sorters - Update debug setting when saving config
This commit is contained in:
@@ -43,8 +43,9 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
class MailCache {
|
class MailCache {
|
||||||
|
|
||||||
public static final boolean FETCH_HEADER = true;
|
public enum FetchMode {
|
||||||
public static final boolean FETCH_ALL = false;
|
HEADER, ALL, CACHE_ONLY
|
||||||
|
}
|
||||||
|
|
||||||
private final POP3MailBox mailbox;
|
private final POP3MailBox mailbox;
|
||||||
private final Hashtable<String, Mail> mails;
|
private final Hashtable<String, Mail> mails;
|
||||||
@@ -105,10 +106,10 @@ class MailCache {
|
|||||||
* Fetch any needed data from pop3 server.
|
* Fetch any needed data from pop3 server.
|
||||||
*
|
*
|
||||||
* @param uidl message id to get
|
* @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
|
* @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;
|
Mail mail = null, newMail = null;
|
||||||
|
|
||||||
@@ -129,13 +130,13 @@ class MailCache {
|
|||||||
if (mail.markForDeletion)
|
if (mail.markForDeletion)
|
||||||
return null;
|
return null;
|
||||||
int sz = mail.getSize();
|
int sz = mail.getSize();
|
||||||
if (sz > 0 && sz <= FETCH_ALL_SIZE)
|
if (mode == FetchMode.HEADER && sz > 0 && sz <= FETCH_ALL_SIZE)
|
||||||
headerOnly = false;
|
mode = FetchMode.ALL;
|
||||||
|
|
||||||
if( headerOnly ) {
|
if (mode == FetchMode.HEADER) {
|
||||||
if(!mail.hasHeader())
|
if(!mail.hasHeader())
|
||||||
mail.setHeader(mailbox.getHeader(uidl));
|
mail.setHeader(mailbox.getHeader(uidl));
|
||||||
} else {
|
} else if (mode == FetchMode.ALL) {
|
||||||
if(!mail.hasBody()) {
|
if(!mail.hasBody()) {
|
||||||
ReadBuffer rb = mailbox.getBody(uidl);
|
ReadBuffer rb = mailbox.getBody(uidl);
|
||||||
if (rb != null) {
|
if (rb != null) {
|
||||||
@@ -146,6 +147,8 @@ class MailCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// else if it wasn't in cache, too bad
|
||||||
}
|
}
|
||||||
return mail;
|
return mail;
|
||||||
}
|
}
|
||||||
@@ -156,10 +159,14 @@ class MailCache {
|
|||||||
* After this, call getUIDLs() to get all known mail UIDLs.
|
* After this, call getUIDLs() to get all known mail UIDLs.
|
||||||
* MUST already be connected, otherwise returns false.
|
* MUST already be connected, otherwise returns false.
|
||||||
*
|
*
|
||||||
|
* @param mode HEADER or ALL only
|
||||||
* @return true if any were fetched
|
* @return true if any were fetched
|
||||||
* @since 0.9.13
|
* @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();
|
Collection<String> popKnown = mailbox.getUIDLs();
|
||||||
if (popKnown == null)
|
if (popKnown == null)
|
||||||
|
@@ -251,8 +251,8 @@ public class WebMail extends HttpServlet
|
|||||||
* Gets mail from the cache, checks for null, then compares
|
* Gets mail from the cache, checks for null, then compares
|
||||||
*/
|
*/
|
||||||
public int compare(String arg0, String arg1) {
|
public int compare(String arg0, String arg1) {
|
||||||
Mail a = mailCache.getMail( arg0, MailCache.FETCH_HEADER );
|
Mail a = mailCache.getMail( arg0, MailCache.FetchMode.CACHE_ONLY );
|
||||||
Mail b = mailCache.getMail( arg1, MailCache.FETCH_HEADER );
|
Mail b = mailCache.getMail( arg1, MailCache.FetchMode.CACHE_ONLY );
|
||||||
if (a == null)
|
if (a == null)
|
||||||
return (b == null) ? 0 : 1;
|
return (b == null) ? 0 : 1;
|
||||||
if (b == null)
|
if (b == null)
|
||||||
@@ -440,10 +440,8 @@ public class WebMail extends HttpServlet
|
|||||||
MailCache mc = mailCache;
|
MailCache mc = mailCache;
|
||||||
Folder<String> f = folder;
|
Folder<String> f = folder;
|
||||||
if (mc != null && f != null) {
|
if (mc != null && f != null) {
|
||||||
if (MailCache.FETCH_HEADER) {
|
String[] uidls = mc.getUIDLs();
|
||||||
String[] uidls = mc.getUIDLs();
|
f.setElements(uidls);
|
||||||
f.setElements(uidls);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -775,7 +773,7 @@ public class WebMail extends HttpServlet
|
|||||||
if (!offline) {
|
if (!offline) {
|
||||||
// prime the cache, request all headers at once
|
// prime the cache, request all headers at once
|
||||||
// otherwise they are pulled one at a time by sortBy() below
|
// 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
|
// get through cache so we have the disk-only ones too
|
||||||
String[] uidls = mc.getUIDLs();
|
String[] uidls = mc.getUIDLs();
|
||||||
@@ -976,7 +974,7 @@ public class WebMail extends HttpServlet
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( uidl != null ) {
|
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:
|
* 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?
|
// TODO how to do a "No new mail" message?
|
||||||
sessionObject.mailbox.refresh();
|
sessionObject.mailbox.refresh();
|
||||||
sessionObject.error += sessionObject.mailbox.lastError();
|
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
|
// get through cache so we have the disk-only ones too
|
||||||
String[] uidls = sessionObject.mailCache.getUIDLs();
|
String[] uidls = sessionObject.mailCache.getUIDLs();
|
||||||
if (uidls != null)
|
if (uidls != null)
|
||||||
@@ -1281,7 +1279,7 @@ public class WebMail extends HttpServlet
|
|||||||
if( str != null ) {
|
if( str != null ) {
|
||||||
try {
|
try {
|
||||||
int hashCode = Integer.parseInt( str );
|
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;
|
MailPart part = mail != null ? getMailPartFromHashCode( mail.getPart(), hashCode ) : null;
|
||||||
if( part != null ) {
|
if( part != null ) {
|
||||||
if (sendAttachment(sessionObject, part, response, isRaw))
|
if (sendAttachment(sessionObject, part, response, isRaw))
|
||||||
@@ -1443,6 +1441,8 @@ public class WebMail extends HttpServlet
|
|||||||
sessionObject.folder.setPageSize( pageSize );
|
sessionObject.folder.setPageSize( pageSize );
|
||||||
} catch( NumberFormatException nfe ) {}
|
} 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.state = sessionObject.folder != null ? STATE_LIST : STATE_AUTH;
|
||||||
sessionObject.info = _("Configuration saved");
|
sessionObject.info = _("Configuration saved");
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@@ -1608,7 +1608,7 @@ public class WebMail extends HttpServlet
|
|||||||
processSortingButtons( sessionObject, request );
|
processSortingButtons( sessionObject, request );
|
||||||
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||||
String uidl = it.next();
|
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 ) {
|
if( mail != null && mail.error.length() > 0 ) {
|
||||||
sessionObject.error += mail.error;
|
sessionObject.error += mail.error;
|
||||||
mail.error = "";
|
mail.error = "";
|
||||||
@@ -1629,7 +1629,7 @@ public class WebMail extends HttpServlet
|
|||||||
// sessionObject.state = STATE_LIST and
|
// sessionObject.state = STATE_LIST and
|
||||||
// sessionObject.showUIDL = null
|
// sessionObject.showUIDL = null
|
||||||
if ( 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 ) {
|
if( mail != null && mail.error.length() > 0 ) {
|
||||||
sessionObject.error += mail.error;
|
sessionObject.error += mail.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.mailbox.getNumMails());
|
||||||
subtitle = ngettext("1 Message", "{0} Messages", sessionObject.folder.getSize());
|
subtitle = ngettext("1 Message", "{0} Messages", sessionObject.folder.getSize());
|
||||||
} else if( sessionObject.state == STATE_SHOW ) {
|
} 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)
|
if (mail != null && mail.shortSubject != null)
|
||||||
subtitle = mail.shortSubject;
|
subtitle = mail.shortSubject;
|
||||||
else
|
else
|
||||||
@@ -2121,7 +2121,7 @@ public class WebMail extends HttpServlet
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||||
String uidl = it.next();
|
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) {
|
if (mail == null) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
@@ -2235,7 +2235,7 @@ public class WebMail extends HttpServlet
|
|||||||
if( sessionObject.reallyDelete ) {
|
if( sessionObject.reallyDelete ) {
|
||||||
out.println( "<p class=\"error\">" + _("Really delete this message?") + " " + button( REALLYDELETE, _("Yes, really delete it!") ) + "</p>" );
|
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()) {
|
if(!RELEASE && mail != null && mail.hasBody()) {
|
||||||
out.println( "<!--" );
|
out.println( "<!--" );
|
||||||
out.println( "Debug: Mail header and body follow");
|
out.println( "Debug: Mail header and body follow");
|
||||||
|
Reference in New Issue
Block a user