Example usage for org.apache.commons.net.imap IMAPClient list

List of usage examples for org.apache.commons.net.imap IMAPClient list

Introduction

In this page you can find the example usage for org.apache.commons.net.imap IMAPClient list.

Prototype

public boolean list(String refName, String mailboxName) throws IOException 

Source Link

Document

Send a LIST command to the server.

Usage

From source file:org.apache.commons.net.examples.mail.IMAPMail.java

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("Usage: IMAPMail imap[s]://username:password@server/");
        System.err.println("Connects to server; lists capabilities and shows Inbox status");
        System.exit(1);//from   w ww.j av a2  s  . c  o m
    }

    URI uri = URI.create(args[0]);

    // Connect and login
    final IMAPClient imap = IMAPUtils.imapLogin(uri, 10000, null);

    // suppress login details
    imap.addProtocolCommandListener(new PrintCommandListener(System.out, true));

    try {
        imap.setSoTimeout(6000);

        imap.capability();

        imap.select("inbox");

        imap.examine("inbox");

        imap.status("inbox", new String[] { "MESSAGES" });

        imap.list("", "*"); // Show the folders

    } catch (IOException e) {
        System.out.println(imap.getReplyString());
        e.printStackTrace();
        System.exit(10);
        return;
    } finally {
        imap.logout();
        imap.disconnect();
    }
}

From source file:org.apache.james.ESReporterTest.java

@Test
public void timeMetricsShouldBeReportedWhenImapCommandsReceived() throws Exception {
    IMAPClient client = new IMAPClient();
    client.connect(InetAddress.getLocalHost(), IMAP_PORT);
    client.login(USERNAME, PASSWORD);//www.  ja v  a  2s  .  c  o  m

    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            try {
                client.list("", "*");
            } catch (Exception e) {
                LOGGER.error("Error while sending LIST command", e);
            }
        }
    };
    timer.schedule(timerTask, DELAY_IN_MS, PERIOD_IN_MS);

    await().atMost(Duration.TEN_MINUTES).until(() -> checkMetricRecordedInElasticSearch());
}