use of i2p.susi.webmail.pop3.POP3MailBox in project i2p.i2p by i2p.
the class WebMail method processLogout.
/**
* @param sessionObject
* @param request
* @return new state, or null if unknown
*/
private static State processLogout(SessionObject sessionObject, RequestWrapper request, boolean isPOST, State state) {
if (buttonPressed(request, LOGOUT) && isPOST) {
Debug.debug(Debug.DEBUG, "LOGOUT, REMOVING SESSION");
HttpSession session = request.getSession();
session.removeAttribute("sessionObject");
session.invalidate();
POP3MailBox mailbox = sessionObject.mailbox;
if (mailbox != null) {
mailbox.destroy();
sessionObject.mailbox = null;
sessionObject.mailCache = null;
}
sessionObject.info += _t("User logged out.") + '\n';
state = State.AUTH;
} else if (state == State.AUTH && !buttonPressed(request, CANCEL) && !buttonPressed(request, SAVE)) {
// AUTH will be passed in if mailbox is null
// Check previous state
Debug.debug(Debug.DEBUG, "Lost conn, prev. state was " + request.getParameter(DEBUG_STATE));
sessionObject.error += _t("Internal error, lost connection.") + '\n' + _t("User logged out.") + '\n';
}
return state;
}
use of i2p.susi.webmail.pop3.POP3MailBox in project i2p.i2p by i2p.
the class WebMail method threadedStartup.
/**
* Starts one thread to load the emails from disk,
* and in parallel starts a second thread to connect to the POP3 server
* (unless user clicked the 'read mail offline' at login).
* Either could finish first, but unless the local disk cache is really big,
* the loading will probably finish first.
*
* Once the POP3 connects, it waits for the disk loader to finish, and then
* does the fetching of new emails.
*
* The user may view the local folder once the first (loader) thread is done.
*
* @since 0.9.34
*/
private static State threadedStartup(SessionObject sessionObject, boolean offline, State state, String host, int pop3PortNo, String user, String pass) {
POP3MailBox mailbox = new POP3MailBox(host, pop3PortNo, user, pass);
I2PAppContext ctx = I2PAppContext.getGlobalContext();
MailCache mc;
try {
mc = new MailCache(ctx, mailbox, host, pop3PortNo, user, pass);
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Error creating disk cache", ioe);
sessionObject.error += ioe.toString() + '\n';
return State.AUTH;
}
Folder<String> folder = new Folder<String>();
// setElements() sorts, so configure the sorting first
// sessionObject.folder.addSorter( SORT_ID, new IDSorter( sessionObject.mailCache ) );
folder.addSorter(SORT_SENDER, new SenderSorter(mc));
folder.addSorter(SORT_SUBJECT, new SubjectSorter(mc));
folder.addSorter(SORT_DATE, new DateSorter(mc));
folder.addSorter(SORT_SIZE, new SizeSorter(mc));
// reverse sort, latest mail first
// TODO get user defaults from config
folder.setSortBy(SORT_DEFAULT, SORT_ORDER_DEFAULT);
sessionObject.folder = folder;
sessionObject.mailbox = mailbox;
sessionObject.user = user;
sessionObject.pass = pass;
sessionObject.host = host;
sessionObject.reallyDelete = false;
// Thread the loading and the server connection.
// Either could finish first.
// With a mix of email (10KB median, 100KB average size),
// about 20 emails per second per thread loaded.
// thread 1: mc.loadFromDisk()
sessionObject.mailCache = mc;
sessionObject.isLoading = true;
boolean ok = mc.loadFromDisk(new LoadWaiter(sessionObject));
if (!ok)
sessionObject.isLoading = false;
// thread 2: mailbox.connectToServer()
if (offline) {
Debug.debug(Debug.DEBUG, "OFFLINE MODE");
} else {
sessionObject.isFetching = true;
if (!mailbox.connectToServer(new ConnectWaiter(sessionObject))) {
sessionObject.error += _t("Cannot connect") + '\n';
sessionObject.isFetching = false;
}
}
// wait a little while so we avoid the loading page if we can
if (sessionObject.isLoading) {
try {
sessionObject.wait(5000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for load", ie);
}
}
state = sessionObject.isLoading ? State.LOADING : State.LIST;
return state;
}
use of i2p.susi.webmail.pop3.POP3MailBox in project i2p.i2p by i2p.
the class WebMail method processGenericButtons.
/**
* @param sessionObject
* @param request
* @return new state
*/
private static State processGenericButtons(SessionObject sessionObject, RequestWrapper request, State state) {
/**
** All RELOAD buttons are commented out
* 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 = _t("Configuration reloaded");
* }
***
*/
if (buttonPressed(request, REFRESH)) {
POP3MailBox mailbox = sessionObject.mailbox;
if (mailbox == null) {
sessionObject.error += _t("Internal error, lost connection.") + '\n';
return State.AUTH;
}
if (sessionObject.isFetching) {
// shouldn't happen, button disabled
return state;
}
sessionObject.isFetching = true;
ConnectWaiter cw = new ConnectWaiter(sessionObject);
if (mailbox.connectToServer(cw)) {
// Start a thread to wait for results
Debug.debug(Debug.DEBUG, "Already connected, running CW");
Thread t = new I2PAppThread(cw, "Email fetcher");
t.start();
} else {
sessionObject.error += _t("Cannot connect") + '\n';
sessionObject.isFetching = false;
}
// wait if it's going to be quick
try {
sessionObject.wait(3000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for connect", ie);
}
}
return state;
}
Aggregations