forked from I2P_Developers/i2p.i2p
* SusiMail:
- Load all mails from disk at startup - Add offline mode - MailCache now has the total UIDL view - Copy silk folder icon from snark to console for use by susimail
This commit is contained in:
@ -32,8 +32,10 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author user
|
||||
@ -62,11 +64,36 @@ class MailCache {
|
||||
PersistentMailCache pmc = null;
|
||||
try {
|
||||
pmc = new PersistentMailCache(host, port, user, pass);
|
||||
// TODO pmc.getMails()
|
||||
} catch (IOException ioe) {
|
||||
Debug.debug(Debug.ERROR, "Error creating disk cache: " + ioe);
|
||||
}
|
||||
disk = pmc;
|
||||
if (disk != null)
|
||||
loadFromDisk();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 0.9.13
|
||||
*/
|
||||
private void loadFromDisk() {
|
||||
Collection<Mail> dmails = disk.getMails();
|
||||
for (Mail mail : dmails) {
|
||||
mails.put(mail.uidl, mail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The ones known locally, which will include any known on the server, if connected.
|
||||
*
|
||||
* @since 0.9.13
|
||||
*/
|
||||
public String[] getUIDLs() {
|
||||
List<String> uidls = new ArrayList<String>(mails.size());
|
||||
synchronized(mails) {
|
||||
uidls.addAll(mails.keySet());
|
||||
}
|
||||
return uidls.toArray(new String[uidls.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +123,8 @@ class MailCache {
|
||||
}
|
||||
if (mail.markForDeletion)
|
||||
return null;
|
||||
if(mail.getSize() <= FETCH_ALL_SIZE)
|
||||
int sz = mail.getSize();
|
||||
if (sz > 0 && sz <= FETCH_ALL_SIZE)
|
||||
headerOnly = false;
|
||||
|
||||
if( headerOnly ) {
|
||||
@ -148,7 +176,8 @@ class MailCache {
|
||||
if (mail.markForDeletion)
|
||||
continue;
|
||||
mr.setMail(mail);
|
||||
if(mail.getSize() <= FETCH_ALL_SIZE)
|
||||
int sz = mail.getSize();
|
||||
if (sz > 0 && sz <= FETCH_ALL_SIZE)
|
||||
headerOnly = false;
|
||||
if( headerOnly ) {
|
||||
if(!mail.hasHeader()) {
|
||||
|
@ -69,7 +69,7 @@ class PersistentMailCache {
|
||||
/**
|
||||
* Fetch all mails from disk.
|
||||
*
|
||||
* @return An e-mail or null
|
||||
* @return a new collection
|
||||
*/
|
||||
public Collection<Mail> getMails() {
|
||||
List<Mail> rv = new ArrayList<Mail>();
|
||||
|
@ -98,6 +98,7 @@ public class WebMail extends HttpServlet
|
||||
* form keys on login page
|
||||
*/
|
||||
private static final String LOGIN = "login";
|
||||
private static final String OFFLINE = "offline";
|
||||
private static final String USER = "user";
|
||||
private static final String PASS = "pass";
|
||||
private static final String HOST = "host";
|
||||
@ -610,7 +611,8 @@ public class WebMail extends HttpServlet
|
||||
/*
|
||||
* security :(
|
||||
*/
|
||||
if( buttonPressed( request, LOGIN ) ) {
|
||||
boolean offline = buttonPressed(request, OFFLINE);
|
||||
if (buttonPressed(request, LOGIN) || offline) {
|
||||
|
||||
if( user == null || user.length() == 0 ) {
|
||||
sessionObject.error += _("Need username for authentication.") + "<br>";
|
||||
@ -664,7 +666,7 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
if( doContinue ) {
|
||||
POP3MailBox mailbox = new POP3MailBox( host, pop3PortNo, user, pass );
|
||||
if (mailbox.isConnected() ) {
|
||||
if (offline || mailbox.connectToServer()) {
|
||||
sessionObject.mailbox = mailbox;
|
||||
sessionObject.user = user;
|
||||
sessionObject.pass = pass;
|
||||
@ -674,10 +676,10 @@ public class WebMail extends HttpServlet
|
||||
MailCache mc = new MailCache(mailbox, host, pop3PortNo, user, pass);
|
||||
sessionObject.mailCache = mc;
|
||||
sessionObject.folder = new Folder<String>();
|
||||
// TODO get through cache so we have the disk-only ones too
|
||||
String[] uidls = mailbox.getUIDLs();
|
||||
// get through cache so we have the disk-only ones too
|
||||
String[] uidls = mc.getUIDLs();
|
||||
sessionObject.folder.setElements(uidls);
|
||||
if (uidls.length > 0) {
|
||||
if (uidls.length > 0 && !offline) {
|
||||
// prime the cache, request all headers at once
|
||||
// otherwise they are pulled one at a time by sortBy() below
|
||||
List<MailCache.MailRequest> reqs = new ArrayList<MailCache.MailRequest>(uidls.length);
|
||||
@ -696,7 +698,10 @@ public class WebMail extends HttpServlet
|
||||
sessionObject.folder.setSortingDirection(Folder.SortOrder.UP);
|
||||
sessionObject.folder.sortBy(SORT_DATE);
|
||||
sessionObject.reallyDelete = false;
|
||||
Debug.debug(Debug.DEBUG, "CONNECTED, YAY");
|
||||
if (offline)
|
||||
Debug.debug(Debug.DEBUG, "OFFLINE MODE");
|
||||
else
|
||||
Debug.debug(Debug.DEBUG, "CONNECTED, YAY");
|
||||
}
|
||||
else {
|
||||
sessionObject.error += mailbox.lastError();
|
||||
@ -1031,8 +1036,8 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
if( buttonPressed( request, REFRESH ) ) {
|
||||
sessionObject.mailbox.refresh();
|
||||
// TODO get through cache so we have the disk-only ones too
|
||||
String[] uidls = sessionObject.mailbox.getUIDLs();
|
||||
// get through cache so we have the disk-only ones too
|
||||
String[] uidls = sessionObject.mailCache.getUIDLs();
|
||||
if (uidls != null)
|
||||
sessionObject.folder.setElements(uidls);
|
||||
sessionObject.pageChanged = true;
|
||||
@ -1454,8 +1459,8 @@ public class WebMail extends HttpServlet
|
||||
* update folder content
|
||||
*/
|
||||
if( sessionObject.state != STATE_AUTH ) {
|
||||
// TODO get through cache so we have the disk-only ones too
|
||||
String[] uidls = sessionObject.mailbox.getUIDLs();
|
||||
// get through cache so we have the disk-only ones too
|
||||
String[] uidls = sessionObject.mailCache.getUIDLs();
|
||||
if (uidls != null)
|
||||
sessionObject.folder.setElements(uidls);
|
||||
}
|
||||
@ -1846,7 +1851,9 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
out.println(
|
||||
"<tr><td colspan=\"2\"> </td></tr>\n" +
|
||||
"<tr><td></td><td align=\"left\">" + button( LOGIN, _("Login") ) + spacer + " <input class=\"cancel\" type=\"reset\" value=\"" + _("Reset") + "\"></td></tr>\n" +
|
||||
"<tr><td></td><td align=\"left\">" + button( LOGIN, _("Login") ) + spacer +
|
||||
button(OFFLINE, _("View Mail Offline") ) + spacer +
|
||||
" <input class=\"cancel\" type=\"reset\" value=\"" + _("Reset") + "\"></td></tr>\n" +
|
||||
"<tr><td colspan=\"2\"> </td></tr>\n" +
|
||||
"<tr><td></td><td align=\"left\"><a href=\"http://hq.postman.i2p/?page_id=14\">" + _("Learn about I2P mail") + "</a></td></tr>\n" +
|
||||
"<tr><td></td><td align=\"left\"><a href=\"http://hq.postman.i2p/?page_id=16\">" + _("Create Account") + "</a></td></tr>\n" +
|
||||
@ -1927,7 +1934,7 @@ public class WebMail extends HttpServlet
|
||||
link + mail.shortSender + "</a></td><td> </td><td>" + link + mail.shortSubject + "</a></td><td> </td><td>" +
|
||||
// don't let date get split across lines
|
||||
mail.localFormattedDate.replace(" ", " ") + "</td><td> </td><td align=\"right\">" +
|
||||
DataHelper.formatSize2(mail.getSize()) + "B</td></tr>" );
|
||||
((mail.getSize() > 0) : (DataHelper.formatSize2(mail.getSize()) + 'B') : "???") + "</td></tr>" );
|
||||
bg = 1 - bg;
|
||||
i++;
|
||||
}
|
||||
|
@ -67,6 +67,8 @@ public class POP3MailBox {
|
||||
private final Object synchronizer;
|
||||
|
||||
/**
|
||||
* Does not connect. Caller must call connectToServer() if desired.
|
||||
*
|
||||
* @param host
|
||||
* @param port
|
||||
* @param user
|
||||
@ -85,7 +87,6 @@ public class POP3MailBox {
|
||||
synchronizer = new Object();
|
||||
// this appears in the UI so translate
|
||||
lastLine = _("No response from server");
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -484,6 +485,22 @@ public class POP3MailBox {
|
||||
mails = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to pop3 server if not connected.
|
||||
* Does nothing if already connected.
|
||||
*
|
||||
* @return true if connected
|
||||
* @since 0.9.13
|
||||
*/
|
||||
public boolean connectToServer() {
|
||||
synchronized( synchronizer ) {
|
||||
if (isConnected())
|
||||
return true;
|
||||
connect();
|
||||
return isConnected();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* connect to pop3 server, login with USER and PASS and try STAT then
|
||||
*
|
||||
|
@ -7,6 +7,8 @@
|
||||
- Add HTML escaping of '&'
|
||||
- Fix Folder sorting so UP is up and DOWN is down
|
||||
- Fix capture by show page after back button
|
||||
- Load all mails from disk at startup
|
||||
- Add offline mode
|
||||
|
||||
2014-04-21 zzz
|
||||
* SusiMail:
|
||||
|
BIN
installer/resources/themes/console/images/folder.png
Normal file
BIN
installer/resources/themes/console/images/folder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 537 B |
@ -193,11 +193,16 @@ input.download, input.lastpage {
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.firstpage, input.list {
|
||||
input.firstpage {
|
||||
background: #000 url('/themes/console/images/arrow_up.png') no-repeat 2px center;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.list, input.offline {
|
||||
background: #000 url('/themes/console/images/folder.png') no-repeat 2px center;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.forward, input.login, input.nextpage, input.send, input.next {
|
||||
background: #000 url('/themes/console/images/arrow_right.png') no-repeat 2px center;
|
||||
min-height: 22px;
|
||||
|
@ -182,12 +182,18 @@ input.download, input.lastpage {
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.firstpage, input.list {
|
||||
input.firstpage {
|
||||
background: #ddf url('/themes/console/images/arrow_up.png') no-repeat 1px center;
|
||||
padding: 2px 3px 2px 19px;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.list, input.offline {
|
||||
background: #ddf url('/themes/console/images/folder.png') no-repeat 4px center;
|
||||
padding: 2px 3px 2px 24px;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
input.forward, input.login, input.nextpage, input.send, input.next {
|
||||
background: #ddf url('/themes/console/images/arrow_right.png') no-repeat 4px center;
|
||||
padding: 2px 3px 2px 24px;
|
||||
|
Reference in New Issue
Block a user