Search in sources :

Example 1 with Folder

use of i2p.susi.util.Folder 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;
}
Also used : I2PAppContext(net.i2p.I2PAppContext) IOException(java.io.IOException) Folder(i2p.susi.util.Folder) POP3MailBox(i2p.susi.webmail.pop3.POP3MailBox)

Aggregations

Folder (i2p.susi.util.Folder)1 POP3MailBox (i2p.susi.webmail.pop3.POP3MailBox)1 IOException (java.io.IOException)1 I2PAppContext (net.i2p.I2PAppContext)1