Created
March 31, 2016 21:20
-
-
Save ehlertjd/6b954ec5f393114edadcf8d233d0db1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <curl/curl.h> | |
#include <unistd.h> | |
#define USERNAME "username" | |
#define PASSWORD "password" | |
#define SERVER_URL "imap://mail.example.org/" | |
static __inline CURLcode send(CURL *curl, const char *cmd) { | |
size_t len = 0; | |
printf("%s", cmd); | |
CURLcode ret = curl_easy_send(curl, cmd, strlen(cmd), &len); | |
sleep(1); | |
return ret; | |
} | |
static __inline void recv(CURL *curl) { | |
char buffer[8192]; | |
size_t len = 0; | |
CURLcode ret = CURLE_OK; | |
do { | |
ret = curl_easy_recv(curl, buffer, sizeof(buffer)-1, &len); | |
if( ret == CURLE_OK ) { | |
buffer[len] = '\0'; | |
printf("%s", buffer); | |
} else if( ret != CURLE_AGAIN) { | |
printf("recv error: %d\n", ret); | |
} | |
} while(ret == CURLE_OK); | |
} | |
int main(void) { | |
CURL *curl; | |
CURLcode res; | |
curl = curl_easy_init(); | |
if( curl ) { | |
curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME); | |
curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD); | |
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | |
curl_easy_setopt(curl, CURLOPT_URL, SERVER_URL "INBOX"); | |
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); | |
curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 1L); | |
// Do the request | |
res = curl_easy_perform(curl); | |
if( res != CURLE_OK ) { | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); | |
} | |
send(curl, "A10 SELECT \"INBOX\"\r\n"); | |
recv(curl); | |
send(curl, "A11 IDLE\r\n"); | |
recv(curl); | |
send(curl, "DONE\r\n"); | |
printf("curl_easy_cleanup\n"); | |
curl_easy_cleanup(curl); | |
} | |
return res; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment