• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 /* <DESC>
24  * POP3 example using the multi interface
25  * </DESC>
26  */
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <curl/curl.h>
31 
32 /* This is a simple example showing how to retrieve mail using libcurl's POP3
33  * capabilities. It builds on the pop3-retr.c example to demonstrate how to use
34  * libcurl's multi interface.
35  */
36 
main(void)37 int main(void)
38 {
39   CURL *curl;
40   CURLM *mcurl;
41   int still_running = 1;
42 
43   curl_global_init(CURL_GLOBAL_DEFAULT);
44 
45   curl = curl_easy_init();
46   if(!curl)
47     return 1;
48 
49   mcurl = curl_multi_init();
50   if(!mcurl)
51     return 2;
52 
53   /* Set username and password */
54   curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
55   curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
56 
57   /* This will retrieve message 1 from the user's mailbox */
58   curl_easy_setopt(curl, CURLOPT_URL, "pop3://pop.example.com/1");
59 
60   /* Tell the multi stack about our easy handle */
61   curl_multi_add_handle(mcurl, curl);
62 
63   do {
64     CURLMcode mc = curl_multi_perform(mcurl, &still_running);
65 
66     if(still_running)
67       /* wait for activity, timeout or "nothing" */
68       mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
69 
70     if(mc)
71       break;
72 
73   } while(still_running);
74 
75   /* Always cleanup */
76   curl_multi_remove_handle(mcurl, curl);
77   curl_multi_cleanup(mcurl);
78   curl_easy_cleanup(curl);
79   curl_global_cleanup();
80 
81   return 0;
82 }
83