Example usage for javax.mail FolderNotFoundException FolderNotFoundException

List of usage examples for javax.mail FolderNotFoundException FolderNotFoundException

Introduction

In this page you can find the example usage for javax.mail FolderNotFoundException FolderNotFoundException.

Prototype

public FolderNotFoundException(String s, Folder folder) 

Source Link

Document

Constructs a FolderNotFoundException with the specified detail message and the specified folder.

Usage

From source file:com.sun.mail.pop3.POP3Folder.java

/**
 * Throws <code>FolderNotFoundException</code> unless this
 * folder is named "INBOX"./*from  ww w. j  a v  a2 s . c  o  m*/
 *
 * @exception   FolderNotFoundException   if not INBOX
 * @exception   AuthenticationException   authentication failures
 * @exception   MessagingException   other open failures
 */
public synchronized void open(int mode) throws MessagingException {
    checkClosed();
    if (!exists)
        throw new FolderNotFoundException(this, "folder is not INBOX");

    try {
        port = ((POP3Store) store).getPort(this);
        Status s = port.stat();
        total = s.total;
        size = s.size;
        this.mode = mode;
        opened = true;
    } catch (IOException ioex) {
        try {
            if (port != null)
                port.quit();
        } catch (IOException ioex2) {
            // ignore
        } finally {
            port = null;
            ((POP3Store) store).closePort(this);
        }
        throw new MessagingException("Open failed", ioex);
    }

    // Create the message cache vector of appropriate size
    message_cache = new Vector(total);
    message_cache.setSize(total);
    doneUidl = false;

    notifyConnectionListeners(ConnectionEvent.OPENED);
}

From source file:org.apache.camel.component.mail.MailConsumer.java

private void ensureIsConnected() throws MessagingException {
    MailConfiguration config = getEndpoint().getConfiguration();

    boolean connected = false;
    try {//w  w  w . j ava2 s. c o m
        if (store != null && store.isConnected()) {
            connected = true;
        }
    } catch (Exception e) {
        LOG.debug("Exception while testing for is connected to MailStore: "
                + getEndpoint().getConfiguration().getMailStoreLogInformation() + ". Caused by: "
                + e.getMessage(), e);
    }

    if (!connected) {
        // ensure resources get recreated on reconnection
        store = null;
        folder = null;

        if (LOG.isDebugEnabled()) {
            LOG.debug("Connecting to MailStore: "
                    + getEndpoint().getConfiguration().getMailStoreLogInformation());
        }
        store = sender.getSession().getStore(config.getProtocol());
        store.connect(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
    }

    if (folder == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Getting folder " + config.getFolderName());
        }
        folder = store.getFolder(config.getFolderName());
        if (folder == null || !folder.exists()) {
            throw new FolderNotFoundException(folder, "Folder not found or invalid: " + config.getFolderName());
        }
    }
}