无法从Gmail收件箱中删除电子邮件

时间:2019-04-23 09:03:08

标签: c++ curl libcurl

你好,我写了以下代码

    string fetchdata;

size_t write_data(char* buf, size_t size, size_t nmemb, void* up) {
    fetchdata.append((char*)buf, size*nmemb);
    return size*nmemb;
}

void main()
{
    CURL *curl;
    CURLcode res = CURLE_OK;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_USERNAME, "ghtyyuu3@gmail.com");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "xxxxxxx");
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

        curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com:993/INBOX;UID=1");
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "UID STORE 1 +Flags \DELETE");

        res = curl_easy_perform(curl);

        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",

        curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }

    std::ofstream outfile("/home/ilia/Desktop/fetched.txt", std::ios_base::app);
    outfile << fetchdata;
    outfile.close();
}

我设法将邮件读入文本文件,但是无法删除邮件(通过Gmail设置删除已设置的邮件)

我可能有一个错误:

    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "UID STORE 1 +Flags \DELETE");

尽管CURL本身没有给我一个错误,但邮件仍未删除 请帮助

0 个答案:

没有答案