2
0

imap-multi.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /* <DESC>
  23. * IMAP example using the multi interface
  24. * </DESC>
  25. */
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <curl/curl.h>
  29. /* This is a simple example showing how to fetch mail using libcurl's IMAP
  30. * capabilities. It builds on the imap-fetch.c example to demonstrate how to
  31. * use libcurl's multi interface.
  32. */
  33. int main(void)
  34. {
  35. CURL *curl;
  36. CURLM *mcurl;
  37. int still_running = 1;
  38. curl_global_init(CURL_GLOBAL_DEFAULT);
  39. curl = curl_easy_init();
  40. if(!curl)
  41. return 1;
  42. mcurl = curl_multi_init();
  43. if(!mcurl)
  44. return 2;
  45. /* Set username and password */
  46. curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
  47. curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
  48. /* This will fetch message 1 from the user's inbox */
  49. curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1");
  50. /* Tell the multi stack about our easy handle */
  51. curl_multi_add_handle(mcurl, curl);
  52. do {
  53. CURLMcode mc = curl_multi_perform(mcurl, &still_running);
  54. if(still_running)
  55. /* wait for activity, timeout or "nothing" */
  56. mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
  57. if(mc)
  58. break;
  59. } while(still_running);
  60. /* Always cleanup */
  61. curl_multi_remove_handle(mcurl, curl);
  62. curl_multi_cleanup(mcurl);
  63. curl_easy_cleanup(curl);
  64. curl_global_cleanup();
  65. return 0;
  66. }