1e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET/***************************************************************************
2e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *                                  _   _ ____  _
3e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *  Project                     ___| | | |  _ \| |
4e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *                             / __| | | | |_) | |
5e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *                            | (__| |_| |  _ <| |___
6e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *                             \___|\___/|_| \_\_____|
7e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
8d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
9e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
10e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * This software is licensed as described in the file COPYING, which
11e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * you should have received as part of this distribution. The terms
12d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo * are also available at https://curl.haxx.se/docs/copyright.html.
13e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
14e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * copies of the Software, and permit persons to whom the Software is
16e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * furnished to do so, under the terms of the COPYING file.
17e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
18e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * KIND, either express or implied.
20e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
21e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET ***************************************************************************/
22d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo
23d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo/* <DESC>
24d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo * IMAP example to list the folders within a mailbox
25d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo * </DESC>
26d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo */
27d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo
28e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET#include <stdio.h>
29e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET#include <curl/curl.h>
30e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
31e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET/* This is a simple example showing how to list the folders within an IMAP
32e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * mailbox.
33e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET *
34e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * Note that this example requires libcurl 7.30.0 or above.
35e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET */
36e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
37e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNETint main(void)
38e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET{
39e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  CURL *curl;
40e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  CURLcode res = CURLE_OK;
41e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
42e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  curl = curl_easy_init();
43e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  if(curl) {
44e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    /* Set username and password */
45e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
46e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
47e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
48e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    /* This will list the folders within the user's mailbox. If you want to
49e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET     * list the folders within a specific folder, for example the inbox, then
50e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET     * specify the folder as a path in the URL such as /INBOX */
51e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com");
52e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
53e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    /* Perform the list */
54e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    res = curl_easy_perform(curl);
55e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
56e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    /* Check for errors */
57e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    if(res != CURLE_OK)
58e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET      fprintf(stderr, "curl_easy_perform() failed: %s\n",
59e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET              curl_easy_strerror(res));
60e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
61e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    /* Always cleanup */
62e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    curl_easy_cleanup(curl);
63e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  }
64e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET
65e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET  return (int)res;
66e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET}
67